changeset 1:be930b34fcd3

Make it compile, no testing yet.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 26 Jan 2015 23:04:09 +1030
parents 93d4ddff7dd0
children ae8fb85a4949
files 1wire-config.h Makefile sprink.c
diffstat 3 files changed, 67 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/1wire-config.h	Wed Jan 04 23:19:12 2012 +1030
+++ b/1wire-config.h	Mon Jan 26 23:04:09 2015 +1030
@@ -1,10 +1,10 @@
 /*
- * 1 wire header
+ * Example configuration header for 1-wire bus code.
  *
  * This is the user servicable stuff - how to do delays and how to
  * frob the IO pins.
  *
- * Copyright (c) 2004-2009
+ * Copyright (c) 2009
  *      Daniel O'Connor <darius@dons.net.au>.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,42 +31,45 @@
 
 /*
  * Alter these for your configuration
+ *
+ * The configuration described here has the 1-wire read on D3,
+ * a pulldown transistor on D4 and VPP controlled by D5.
  */
 
-#define OWBUSINIT()
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include <util/delay.h>
+#include "cons.h"
 
-/* Set the IO to input */
+/* Initialise the DDR pins if necessary */
+#define OWBUSINIT()		do {			\
+	                            DDRD |= _BV(4);	\
+				    DDRD &= ~_BV(3);	\
+                                } while (0)
+
+/* Set the port up to allow reading from the 1 wire bus */
 #define OWSETREAD() \
-    do {					\
-	__asm__ volatile ("" ::: "memory");	\
-	DDRB &= ~_BV(0);			\
-	PORTB &= ~_BV(0);			\
-	__asm__ volatile ("" ::: "memory");	\
+        do {	                                        \
     } while (0)
 
+
 /* Read the 1-wire bus, non-inverting logic */
-#define OWREADBUS()		(PINB & _BV(0) ? 1 : 0)
+#define OWREADBUS()		(PIND & _BV(3) ? 1 : 0)
 
 /* Set the 1-wire bus to 0
- * Drive output low
+ * Turns a transistor on to pull it low
  */
-#define OWSETBUSLOW() \
-    do {					\
-	__asm__ volatile ("" ::: "memory");	\
-	DDRB |= _BV(0);				\
-	PORTB &= ~_BV(0);			\
-    __asm__ volatile ("" ::: "memory");		\
-    } while (0)
+#define OWSETBUSLOW()		PORTD |= _BV(4)
 
 /* Set the 1-wire bus to 1
- * Allow to float, use pullup
+ * Turn the transistor off to let the pullup do its job
  */
-#define OWSETBUSHIGH() \
-    do {					\
-    __asm__ volatile ("" ::: "memory");		\
-	DDRB &= ~_BV(0);			\
-    __asm__ volatile ("" ::: "memory");		\
-    } while (0)
+#define OWSETBUSHIGH()		PORTD &= ~_BV(4)
+
+/* Turn Vpp on (ie put +12V on the bus
+ * This is optional, if it is undefined OWProgROM always fails */
+#define OWSETVPPON()		PORTD |= _BV(5)
+#define OWSETVPPOFF()		PORTD &= ~_BV(5)
 
 /* _delay_us can only do a delay of 768/clock_freq */
 #if F_CPU > 16000000
@@ -84,6 +87,9 @@
 	_delay_us(48);	_delay_us(48);  _delay_us(48);  _delay_us(48);  \
 	_delay_us(48);_delay_us(48);  _delay_us(48); } while (0)	/* 480 usec */
 #define OWDELAY_I do { _delay_us(48); _delay_us(22); } while (0)	/* 70 usec */
+#define OWDELAY_J do { _delay_us(41); _delay_us(41);  _delay_us(41); 	\
+	_delay_us(41);	_delay_us(41);  _delay_us(41);  _delay_us(41);  \
+	_delay_us(41);_delay_us(41);  _delay_us(41); } while (0)	/* 410 usec */
 
 #ifdef OW_DEBUG
 #define OWPUTS(x)		puts_P(x)
@@ -94,4 +100,3 @@
 #define OWPUTSP(x)
 #define OWPRINTFP(fmt, ...)
 #endif
-
--- a/Makefile	Wed Jan 04 23:19:12 2012 +1030
+++ b/Makefile	Mon Jan 26 23:04:09 2015 +1030
@@ -1,7 +1,7 @@
 PROG=	sprink
-SRCS=	sprink.c cons.c ds1307.c 1wire.c
+SRCS=	sprink.c cons.c ds1307.c 1wire.c water.c
 
-TPREFIX=	/usr/local/CrossPack-AVR/bin
+#TPREFIX=	/usr/local/CrossPack-AVR/bin/
 
 # Should be 324A but that doesn't work (broken avr-gcc?)
 PART=324p
@@ -11,7 +11,7 @@
 # Clock frequency
 CFLAGS+=-DF_CPU=8000000
 
-CFLAGS+=--param inline-call-cost=2
+#CFLAGS+=--param inline-call-cost=2
 
 # Enable optimisation & debugging
 CFLAGS+=-Os -Wall -g
@@ -26,11 +26,11 @@
 # Allow linker relaxation - optimise after linking
 #LDFLAGS+=-Wl,-relax
 
-#PROGTYPE=dragon_isp
-#PROGPORT=usb
+PROGTYPE=dragon_isp
+PROGPORT=usb
 
-PROGTYPE=buspirate
-PROGPORT=/dev/cu.usbserial-BP1
+#PROGTYPE=buspirate
+#PROGPORT=/dev/cu.usbserial-BP1
 
 # Holds cons, ds1307 & 1wire
 LIBDIR=	../avr-lib
--- a/sprink.c	Wed Jan 04 23:19:12 2012 +1030
+++ b/sprink.c	Mon Jan 26 23:04:09 2015 +1030
@@ -40,6 +40,7 @@
 #include "cons.h"
 #include "ds1307.h"
 #include "1wire.h"
+#include "water.h"
 
 /*
 ** Fuse bits should be set as follows
@@ -58,40 +59,6 @@
 ** LFUSE - 0x62 - 01100010 - CLKDIV8, no CKOUT, long SUT, CKSEL3/2/0 (internal 8Mhz)
 */
 
-#define NUMSPRINKS 6
-
-/* Holds all the settings needed */
-typedef struct {
-    bitstr_t	bit_decl(mon[NUMSPRINKS], 24);
-    bitstr_t	bit_decl(tue[NUMSPRINKS], 24);
-    bitstr_t	bit_decl(wed[NUMSPRINKS], 24);
-    bitstr_t	bit_decl(thu[NUMSPRINKS], 24);
-    bitstr_t	bit_decl(fri[NUMSPRINKS], 24);
-    bitstr_t	bit_decl(sat[NUMSPRINKS], 24);
-    bitstr_t	bit_decl(sun[NUMSPRINKS], 24);
-    
-} __attribute__((packed)) settings_t;
-
-/* Current settings in RAM */
-static settings_t	settings;
-
-/* Our map of EEPROM */
-struct {
-    settings_t	settings;
-    uint16_t	crc;
-} ee_area __attribute__((section(".eeprom")));
-
-/* Defaults that are shoved into EEPROM if it fails checksum */
-const PROGMEM settings_t	default_settings = {
-    /* XXX: no handy macro for this */
-    .mon[0] = {0, 0, 0},
-    .mon[1] = {0, 0, 0},
-    .mon[2] = {0, 0, 0},
-    .mon[3] = {0, 0, 0},
-    .mon[4] = {0, 0, 0},
-    .mon[5] = {0, 0, 0}
-};
-
 /*
  * Mirror of the MCUCSR register, taken early during startup.
  */
@@ -132,12 +99,15 @@
     /* Set up the one wire stuff */
     OWInit();
     
+    /* Init water control state machine */
+    water_init();
+    
     /* Analogue input is PA0:7 */
     DDRA = 0x00;
     PORTA = 0x00;
     DIDR0 = 0xff; /* Disable digital input buffers */
 #ifdef PRR
-    PRR &= ~_BV(PRADC);		/* Power ADV on - note that the
+    PRR &= ~_BV(PRADC);		/* Power ADC on - note that the
 				 * datasheet says this is already 0 at
 				 * power on.. */
 #endif
@@ -193,6 +163,8 @@
     while (1) {
 	wdt_reset();
 
+	water_update();
+	
 	if (cmd.state == 255) {
 	    process_cmd();
 	    printf_P(PSTR("> "));
@@ -210,24 +182,27 @@
 	     
     if (!strcasecmp_P((char *)cmd.buf, PSTR("?")) ||
 	!strcasecmp_P((char *)cmd.buf, PSTR("help"))) {
-        printf_P(PSTR("help             This help\r\n"
-                      "gc               Get time of day\r\n"
-                      "sc time          Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n"
-                      "in port          Read from a port\r\n"
-                      "ou port val      Write to a port (val in hex)\r\n"
-                      "dd port val      Set DDR on port\r\n"
-                      "an pin           Sample from pin\r\n"
-                      "sr               Search for 1-wire devices\r\n"
-                      "te ID            Sample temperature from ID\r\n"
-                      "re               Reset 1-wire bus\r\n"
-                      "rb               Read bit from 1-wire bus\r\n"
-                      "rc               Read byte from 1-wire bus\r\n"
-                      "wb bit           Write bit to 1-wire bus\r\n"
-                      "wc byte          Write byte to 1-wire bus\r\n"
-                      "zz               Reset micro\r\n"));
+        puts_P(PSTR("help               This help\r\n"
+		    "wa dly time        Water for time minutes after dly minutes\r\n"
+		    "gc                 Get time of day\r\n"
+		    "sc time            Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n"
+		    "in port            Read from a port\r\n"
+		    "ou port val        Write to a port (val in hex)\r\n"
+		    "dd port val        Set DDR on port\r\n"
+		    "an pin             Sample from pin\r\n"
+		    "sr                 Search for 1-wire devices\r\n"
+		    "te ID              Sample temperature from ID\r\n"
+		    "re                 Reset 1-wire bus\r\n"
+		    "rb                 Read bit from 1-wire bus\r\n"
+		    "rc                 Read byte from 1-wire bus\r\n"
+		    "wb bit             Write bit to 1-wire bus\r\n"
+		    "wc byte            Write byte to 1-wire bus\r\n"
+		    "zz                 Reset micro\r\n"));
 	return;
+    } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wa"), 2)) {
+	water_cmd((char *)cmd.buf);
     } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) {
-	ds1307_printtime(PSTR(""), PSTR("\r\n"));
+	ds1307_printnow(PSTR(""), PSTR("\r\n"));
     } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) {
 	if (cmd.len < 17) {
 	    printf_P(PSTR("Invalid TOD\r\n"));
@@ -273,9 +248,9 @@
 		return;
 	}
 
-	/* Select desired pin, use VCC reference */
-	ADMUX = _BV(REFS0) | pin;
-
+	/* Select desired pin, use AVREF */
+	ADMUX = _BV(pin);
+	
 	/* Enable ADC, start conversion, set divisor to 64
 	 * (8e6 / 64 => 125kHz (max is 200kHz)
 	 */