annotate sprink.c @ 0:93d4ddff7dd0

Jumbo commit since I appear to have forgotten to do this before..
author Daniel O'Connor <darius@dons.net.au>
date Wed, 04 Jan 2012 23:19:12 +1030
parents
children be930b34fcd3
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 *
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 * Copyright (c) 2009
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
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 #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
40 #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
41 #include "ds1307.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 "1wire.h"
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 ** 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
46 **
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 ** 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
48 ** 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
49 ** 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
50 ** 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
51 **
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 ** 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
53 **
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 ** 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
55 ** 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
56 ** 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
57 ** - 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
58 ** 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
59 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 #define NUMSPRINKS 6
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 /* Holds all the settings needed */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 typedef struct {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 bitstr_t bit_decl(mon[NUMSPRINKS], 24);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 bitstr_t bit_decl(tue[NUMSPRINKS], 24);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 bitstr_t bit_decl(wed[NUMSPRINKS], 24);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 bitstr_t bit_decl(thu[NUMSPRINKS], 24);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 bitstr_t bit_decl(fri[NUMSPRINKS], 24);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 bitstr_t bit_decl(sat[NUMSPRINKS], 24);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 bitstr_t bit_decl(sun[NUMSPRINKS], 24);
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 } __attribute__((packed)) settings_t;
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 /* Current settings in RAM */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 static settings_t settings;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 /* Our map of EEPROM */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 struct {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 settings_t settings;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 uint16_t crc;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 } ee_area __attribute__((section(".eeprom")));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 /* Defaults that are shoved into EEPROM if it fails checksum */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 const PROGMEM settings_t default_settings = {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 /* XXX: no handy macro for this */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 .mon[0] = {0, 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
88 .mon[1] = {0, 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
89 .mon[2] = {0, 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
90 .mon[3] = {0, 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
91 .mon[4] = {0, 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
92 .mon[5] = {0, 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
93 };
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 * 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
97 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 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
99
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 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
101
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 * 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
104 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 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
106 __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
107 __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
108 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
109 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
110 #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
111 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
112 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
113 #else
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 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
115 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
116 #endif
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 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
120
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 int
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 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
123 /* 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
124 cli();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 /* 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
127 cons_init();
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 /* 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
130 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
131
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 /* 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
133 OWInit();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 /* 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
136 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
137 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
138 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
139 #ifdef PRR
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 PRR &= ~_BV(PRADC); /* Power ADV on - note that the
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 * 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
142 * 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
143 #endif
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 /* 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
146 * 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
147 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
148 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
149
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150 /* 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
151 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
152 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
153
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 /* 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
155 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
156 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
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 printf_P(PSTR("\r\n\r\n===============\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
159 "Inited!\r\n\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
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 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
162 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
163
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 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
165 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
166
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167 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
168 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
169
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
170 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
171 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
172
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
173 #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
174 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
175 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
176 #endif
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 /* 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
179 sei();
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 /*
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182 * 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
183 * 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
184 *
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
185 * Gets reset in the loop below and in the tempctrl.c timer IRQ
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
187 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
188
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
189 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
190 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
191
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
192 /* 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
193 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
194 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
195
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
196 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
197 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
198 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
199 /* 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
200 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
201 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
202 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
203 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
204
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
205 void
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
206 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
207 /* 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
208 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
209 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
210
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
211 if (!strcasecmp_P((char *)cmd.buf, PSTR("?")) ||
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
212 !strcasecmp_P((char *)cmd.buf, PSTR("help"))) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
213 printf_P(PSTR("help This help\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
214 "gc Get time of day\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
215 "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\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
216 "in port Read from a 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
217 "ou port val Write to a port (val in hex)\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
218 "dd port val Set DDR on 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
219 "an pin Sample from 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
220 "sr Search for 1-wire devices\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
221 "te ID Sample temperature from 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
222 "re Reset 1-wire bus\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
223 "rb Read bit from 1-wire bus\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
224 "rc Read byte from 1-wire bus\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
225 "wb bit Write bit to 1-wire bus\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
226 "wc byte Write byte to 1-wire bus\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
227 "zz Reset micro\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
228 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
229 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
230 ds1307_printtime(PSTR(""), PSTR("\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
231 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) {
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 (cmd.len < 17) {
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("Invalid TOD\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 } else {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
235 if (ds1307_settod((char *)cmd.buf + 3) != 1)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
236 printf_P(PSTR("Unable to set TOD\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
237 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
238 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("in"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
239 uint8_t inp;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
240
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
241 switch (tolower(cmd.buf[3])) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
242 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
243 inp = PINA;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
244 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
245
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
246 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
247 inp = PINB;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
248 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
249
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
250 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
251 inp = PINC;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
252 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
253
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
254 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
255 inp = PIND;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
256 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
257
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
258 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
259 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
260 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
261 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
262 printf_P(PSTR("PORT %c <= 0x%02x\r\n"), toupper(cmd.buf[3]), inp);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
263 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("an"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
264 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
265 int pin;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
266
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
267 if (sscanf_P((char *)cmd.buf, PSTR("an %d"), &pin) != 1) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
268 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
269 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
270 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
271 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
272 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
273 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
274 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
275
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
276 /* Select desired pin, use VCC reference */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
277 ADMUX = _BV(REFS0) | pin;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
278
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
279 /* 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
280 * (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
281 */
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
282 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
283
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
284 /* 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
285 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
286 ;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
287 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
288 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
289
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
290 /* 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
291 ADCSRA = 0;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
292 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("ou"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
293 char port;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
294 int val;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
295
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
296 if (sscanf_P((char *)cmd.buf, PSTR("ou %c %x"), &port, &val) != 2) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
297 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
298 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
299 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
300
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
301 switch (port) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
302 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
303 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
304 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
305
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
306 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
307 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
308 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
309
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
310 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
311 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
312 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
313
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
314 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
315 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
316 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
317
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
318 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
319 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
320 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
321 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
322 printf_P(PSTR("PORT%c <= 0x%02x\r\n"), toupper(port), val);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
323 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("dd"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
324 char port;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
325 uint8_t val;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
326 int num;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
327
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
328 num = sscanf_P((char *)cmd.buf, PSTR("dd %c %x"), &port, &val);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
329
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
330 if (num != 1 && num != 2) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
331 printf_P(PSTR("Unable to parse dd arguments\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
332 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
333 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
334
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
335 if (num == 1) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
336 switch (port) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
337 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
338 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
339 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
340
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
341 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
342 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
343 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
344
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
345 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
346 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
347 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
348
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
349 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
350 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
351 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
352
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
353 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
354 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
355 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
356 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
357 printf_P(PSTR("DDR%c => 0x%02x\r\n"), toupper(port), val);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
358 } else {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
359 switch (port) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
360 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
361 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
362 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
363
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 'b':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
365 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
366 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
367
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
368 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
369 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
370 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
371
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 'd':
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
373 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
374 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
375
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
376 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
377 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
378 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
379 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
380 printf_P(PSTR("DDR%c <= 0x%02x\r\n"), toupper(port), val);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
381 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
382 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
383 cli();
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
384 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
385 for (;;)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
386 ;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
387 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sr"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
388 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
389 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
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 memset(ROM, 0, 8);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
392
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
393 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
394 do {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
395 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
396 case OW_NOMODULES:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
397 case OW_FOUND:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
398 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
399
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
400 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
401 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
402 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
403 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
404 printf_P(PSTR("Err %d\r\n"), i);
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
405 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
406 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
407
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
408 if (i != OW_FOUND)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
409 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
410
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
411 for (i = 0; i < 8; i++)
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
412 printf_P(PSTR("%02x%S"), ROM[i], i == 7 ? PSTR("\r\n") : PSTR(":"));
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
413
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
414 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
415 } 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
416 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("te"), 2)) {
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 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
418 int16_t t;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
419
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
420 if (sscanf_P((char *)cmd.buf, PSTR("te %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"),
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
421 &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
422 &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
423 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
424 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
425 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
426
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
427 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
428 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
429 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
430 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
431 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
432
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
433 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
434 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
435 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
436
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
437 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
438 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
439 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
440
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
441 default:
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
442 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
443 break;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
444 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
445 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("re"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
446 printf_P(PSTR("Reset = %d\r\n"), OWTouchReset());
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
447 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rb"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
448 printf_P(PSTR("Read %d\r\n"), OWReadBit());
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
449 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rc"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
450 printf_P(PSTR("Read 0x%02x\r\n"), OWReadByte());
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
451 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wb"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
452 uint8_t d;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
453
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
454 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
455 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
456 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
457 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
458 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
459 printf_P(PSTR("Wrote %d\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
460 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wc"), 2)) {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
461 uint8_t d;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
462
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
463 if (sscanf_P((char *)cmd.buf, PSTR("wc %hhx"), &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
464 printf_P(PSTR("Can't parse byte\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
465 return;
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
466 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
467
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
468 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
469 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
470 } else {
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
471 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
472 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
473 }
93d4ddff7dd0 Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
474