annotate sprink.c @ 7:78983502a4e9

Use base 16 for IO port values
author Daniel O'Connor <darius@dons.net.au>
date Sun, 15 Feb 2015 17:47:25 +1030
parents 951277329ee6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 * Sprinkler relay control
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 *
7
78983502a4e9 Use base 16 for IO port values
Daniel O'Connor <darius@dons.net.au>
parents: 5
diff changeset
4 * Copyright (c) 2015
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 *
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 * are met:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 *
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 * SUCH DAMAGE.
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 #include <avr/io.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 #include <avr/interrupt.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 #include <avr/pgmspace.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 #include <stdio.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 #include <string.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 #include <ctype.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 #include <stdlib.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 #include <util/delay.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 #include <avr/wdt.h>
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
39 #include "1wire.h"
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 #include "bitstring.h"
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 #include "cons.h"
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 #include "ds1307.h"
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
43 #include "splitargv.h"
1
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
44 #include "water.h"
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
46 #define MAXARGS 10
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
47
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 ** Fuse bits should be set as follows
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 **
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 ** EFUSE - BOD 4.3V -> xxxxx100 -> 0xfc
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 ** HFUSE - SPIEN, EESAVE
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 ** BOOTSZ1/0 -> 11010001 -> 0xd1
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 ** LFUSE - SUT1, CKSEL1 (low XTAL) -> 11011101 -> 0xdd
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 **
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 ** http://www.engbedded.com/fusecalc/
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 **
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 ** From Ateml the fuses were..
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 ** EFUSE - 0xff - 11111111 - BOD disabled
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 ** HFUSE - 0x99 - 10011001 - OCD disabled, JTAG enabled, SPI enabled, WDT disabled,
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 ** - EESAVE off, BOOTSZ0/1, BOOTRST off
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 ** LFUSE - 0x62 - 01100010 - CLKDIV8, no CKOUT, long SUT, CKSEL3/2/0 (internal 8Mhz)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 * Mirror of the MCUCSR register, taken early during startup.
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 uint8_t mcucsr __attribute__((section(".noinit")));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 void process_cmd(void);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 * Read out and reset MCUCSR early during startup.
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 void handle_mcucsr(void)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 __attribute__((section(".init3")))
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 __attribute__((naked));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 void handle_mcucsr(void) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 wdt_disable();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 #ifdef MCUSR
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 mcucsr = MCUSR;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 MCUSR = 0;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 #else
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 mcucsr = MCUCSR;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 MCUCSR = 0;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 #endif
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 consbuf_t cmd;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 int
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 main(void) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 /* Disable interrupts while we frob stuff */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 cli();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
96 /* Disable watchdog in case it was previously on */
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
97 wdt_disable();
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
98
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 /* Init UART */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 cons_init();
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
101
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
102 printf_P(PSTR("\r\n\r\n===============\r\n"));
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
103
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 /* Init TWI etc */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 ds1307_init();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 /* Set up the one wire stuff */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 OWInit();
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
109
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 /* Analogue input is PA0:7 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 DDRA = 0x00;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 PORTA = 0x00;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 DIDR0 = 0xff; /* Disable digital input buffers */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 #ifdef PRR
1
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
115 PRR &= ~_BV(PRADC); /* Power ADC on - note that the
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 * datasheet says this is already 0 at
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 * power on.. */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 #endif
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
119
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 /* PB0 Used for 1-wire bus
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 * PB4:7 Used for relay board */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 DDRB = 0xf0;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 PORTB = 0x00;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 /* TWI (0:1) */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 DDRC = 0x03;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 PORTC = 0x03;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 /* USART (0:1) */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 DDRD = 0x03;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131 PORTD = 0x03;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
133 fputs_P(PSTR("Reset cause: "), stdout);
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134 if ((mcucsr & _BV(PORF)) == _BV(PORF))
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 printf_P(PSTR("Power on\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137 if ((mcucsr & _BV(EXTRF)) == _BV(EXTRF))
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 printf_P(PSTR("External\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
139
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 if ((mcucsr & _BV(BORF)) == _BV(BORF))
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 printf_P(PSTR("Brown-out\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143 if ((mcucsr & _BV(WDRF)) == _BV(WDRF))
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 printf_P(PSTR("Watchdog\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 #ifdef JTRF
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147 if ((mcucsr & _BV(JTRF)) == _BV(JTRF))
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148 printf_P(PSTR("JTAG\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 #endif
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
151 /* Ready to go! */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 sei();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
154 /* Init water control state machine */
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
155 water_init();
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
156
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158 * Enable the watchdog with the largest prescaler. Will cause a
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159 * watchdog reset after approximately 2 s @ Vcc = 5 V
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 wdt_enable(WDTO_2S);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163 printf_P(PSTR("> "));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 cmd.state = 0;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
165
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166 /* Wait for user input or an "interrupt" */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167 while (1) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168 wdt_reset();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169
1
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
170 water_update();
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
171
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
172 if (cmd.state == 255) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
173 process_cmd();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
174 printf_P(PSTR("> "));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
175 /* Allow new characters to be processed */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
176 cmd.state = 0;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
177 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
178 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
179 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
180
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
181 void
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182 process_cmd(void) {
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
183 int argc;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
184 char *argv[MAXARGS];
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
185
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186 /* User just pressed enter */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
187 if (cmd.len == 0)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
188 return;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
189
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
190 /* Split buffer into argv/argc (and de-volatilise) */
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
191 splitargv((char *)cmd.buf, 0, argv, MAXARGS, &argc);
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
192
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
193 if (argc == 0)
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
194 return;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
195
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
196 if (!strcasecmp_P(argv[0], PSTR("?")) ||
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
197 !strcasecmp_P(argv[0], PSTR("help"))) {
1
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
198 puts_P(PSTR("help This help\r\n"
4
1188042ddc2f update usage
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
199 "wa all dly time Water all regions for time minutes after dly minutes\r\n"
1
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
200 "gc Get time of day\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
201 "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
202 "in port Read from a port\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
203 "ou port val Write to a port (val in hex)\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
204 "dd port val Set DDR on port\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
205 "an pin Sample from pin\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
206 "sr Search for 1-wire devices\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
207 "te ID Sample temperature from ID\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
208 "re Reset 1-wire bus\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
209 "rb Read bit from 1-wire bus\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
210 "rc Read byte from 1-wire bus\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
211 "wb bit Write bit to 1-wire bus\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
212 "wc byte Write byte to 1-wire bus\r\n"
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
213 "zz Reset micro\r\n"));
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
214 return;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
215 } else if (!strcasecmp_P(argv[0], PSTR("wa"))) {
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
216 water_cmd(argc - 1, argv + 1);
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
217 } else if (!strcasecmp_P(argv[0], PSTR("an"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
218 uint16_t res;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
219 int pin;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
220 char *eptr;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
221
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
222 if (argc != 2) {
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
223 printf_P(PSTR("Bad usage\r\n"));
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
224 return;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
225 }
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
226
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
227 pin = strtol(argv[1], &eptr, 0);
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
228 if (eptr == argv[1]) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
229 printf_P(PSTR("Unable to parse\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
230 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
231 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
232 if (pin < 0 || pin > 7) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
233 printf_P(PSTR("Unknown pin\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
234 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
235 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
236
1
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
237 /* Select desired pin, use AVREF */
be930b34fcd3 Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
238 ADMUX = _BV(pin);
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
239
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
240 /* Enable ADC, start conversion, set divisor to 64
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
241 * (8e6 / 64 => 125kHz (max is 200kHz)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
242 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
243 ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADPS2) | _BV(ADPS1);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
244
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
245 /* Spin waiting for result */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
246 while ((ADCSRA & _BV(ADIF)) == 0)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
247 ;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
248 res = ADCL | (ADCH << 8);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
249 printf_P(PSTR("Pin %d <= %hhd\r\n"), pin, res);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
250
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
251 /* Disable ADC */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
252 ADCSRA = 0;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
253 } else if (!strcasecmp_P(argv[0], PSTR("ou"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
254 int val;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
255 char *eptr;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
256
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
257 if (argc != 3) {
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
258 printf_P(PSTR("Bad usage\r\n"));
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
259 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
260 }
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
261
7
78983502a4e9 Use base 16 for IO port values
Daniel O'Connor <darius@dons.net.au>
parents: 5
diff changeset
262 val = strtol(argv[2], &eptr, 16);
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
263 if (eptr == argv[2]) {
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
264 printf_P(PSTR("Unable to parse val\r\n"));
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
265 return;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
266 }
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
267
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
268 switch (argv[1][0]) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
269 case 'a':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
270 PORTA = val & 0xff;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
271 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
272
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
273 case 'b':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
274 PORTB = val & 0xff;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
275 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
276
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
277 case 'c':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
278 PORTC = val & 0xff;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
279 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
280
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
281 case 'd':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
282 PORTD = val & 0xff;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
283 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
284
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
285 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
286 printf_P(PSTR("Unknown port\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
287 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
288 }
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
289 printf_P(PSTR("PORT%c <= 0x%02x\r\n"), toupper(argv[1][0]), val);
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
290 } else if (!strcasecmp_P(argv[0], PSTR("dd"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
291 uint8_t val;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
292 char *eptr;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
293
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
294 if (argc != 2 && argc != 3) {
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
295 printf_P(PSTR("Bad usage\r\n"));
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
296 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
297 }
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
298
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
299 if (argc == 1) {
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
300 switch (argv[1][0]) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
301 case 'a':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
302 DDRA = val;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
303 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
304
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
305 case 'b':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
306 DDRB = val;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
307 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
308
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
309 case 'c':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
310 DDRC = val;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
311 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
312
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
313 case 'd':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
314 DDRD = val;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
315 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
316
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
317 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
318 printf_P(PSTR("Unknown port\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
319 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
320 }
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
321 printf_P(PSTR("DDR%c => 0x%02x\r\n"), toupper(argv[1][0]), val);
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
322 } else {
7
78983502a4e9 Use base 16 for IO port values
Daniel O'Connor <darius@dons.net.au>
parents: 5
diff changeset
323 val = strtol(argv[2], &eptr, 16);
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
324 if (eptr == argv[2]) {
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
325 printf_P(PSTR("Unable to parse val\r\n"));
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
326 return;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
327 }
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
328
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
329 switch (argv[1][0]) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
330 case 'a':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
331 DDRA = val & 0xff;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
332 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
333
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
334 case 'b':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
335 DDRB = val & 0xff;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
336 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
337
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
338 case 'c':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
339 DDRC = val & 0xff;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
340 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
341
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
342 case 'd':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
343 DDRD = val & 0xff;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
344 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
345
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
346 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
347 printf_P(PSTR("Unknown port\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
348 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
349 }
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
350 printf_P(PSTR("DDR%c <= 0x%02x\r\n"), toupper(argv[1][0]), val);
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
351 }
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
352 } else if (!strcasecmp_P(argv[0], PSTR("zz"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
353 cli();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
354 wdt_enable(WDTO_15MS);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
355 for (;;)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
356 ;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
357 } else if (!strcasecmp_P(argv[0], PSTR("sr"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
358 uint8_t ROM[8];
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
359 int8_t i;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
360
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
361 i = OWFirst(ROM, 1, 0);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
362 do {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
363 switch (i) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
364 case OW_NOMODULES:
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
365 return;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
366
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
367 case OW_FOUND:
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
368 for (i = 0; i < 8; i++)
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
369 printf_P(PSTR("%02x%S"), ROM[i], i == 7 ? PSTR("\r\n") : PSTR(":"));
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
370 break;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
371
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
372 case OW_BADWIRE:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
373 case OW_NOPRESENCE:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
374 case OW_BADCRC:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
375 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
376 printf_P(PSTR("Err %d\r\n"), i);
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
377 return;
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
378 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
379 i = OWNext(ROM, 1, 0);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
380 } while (1);
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
381 } else if (!strcasecmp_P(argv[0], PSTR("te"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
382 uint8_t ROM[8];
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
383 int16_t t;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
384
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
385 if (sscanf_P(argv[1], PSTR("%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"),
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
386 &ROM[0], &ROM[1], &ROM[2], &ROM[3],
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
387 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
388 printf_P(PSTR("Unable to parse ROM ID\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
389 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
390 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
391
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
392 t = OWGetTemp(ROM);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
393 switch (t) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
394 case OW_TEMP_WRONG_FAM:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
395 printf_P(PSTR("ROM specified isn't a temperature sensor\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
396 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
397
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
398 case OW_TEMP_CRC_ERR:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
399 printf_P(PSTR("CRC mismatch\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
400 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
401
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
402 case OW_TEMP_NO_ROM:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
403 printf_P(PSTR("No ROM found\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
404 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
405
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
406 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
407 printf_P(PSTR("%d.%02d\r\n"), GETWHOLE(t), GETFRAC(t));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
408 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
409 }
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
410 } else if (!strcasecmp_P(argv[0], PSTR("re"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
411 printf_P(PSTR("Reset = %d\r\n"), OWTouchReset());
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
412 } else if (!strcasecmp_P(argv[0], PSTR("rb"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
413 printf_P(PSTR("Read %d\r\n"), OWReadBit());
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
414 } else if (!strcasecmp_P(argv[0], PSTR("rc"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
415 printf_P(PSTR("Read 0x%02x\r\n"), OWReadByte());
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
416 } else if (!strcasecmp_P(argv[0], PSTR("wb"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
417 uint8_t d;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
418
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
419 if (sscanf_P((char *)cmd.buf, PSTR("wb %hhu"), &d) != 1) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
420 printf_P(PSTR("Can't parse bit\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
421 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
422 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
423 OWWriteBit(d);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
424 printf_P(PSTR("Wrote %d\r\n"), d);
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
425 } else if (!strcasecmp_P(argv[0], PSTR("wc"))) {
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
426 uint8_t d;
5
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
427 char *eptr;
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
428
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
429 d = strtol(argv[1], &eptr, 16);
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
430 if (eptr == argv[1]) {
951277329ee6 Use splitargv instead of rolling our own.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
431 printf_P(PSTR("Unable to parse byte\r\n"));
0
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
432 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
433 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
434
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
435 OWWriteByte(d);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
436 printf_P(PSTR("Wrote 0x%02x\r\n"), d);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
437 } else {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
438 printf_P(PSTR("Unknown command, help for a list\r\n"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
439 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
440 }