root/flukso/trunk/uc/main.h

Revision 122, 2.5 KB (checked in by icarus75, 2 years ago)

uc: add support for US split-phase supplies

  • Property svn:keywords set to Id
Line 
1//
2// main.h : AVR uC header file for flukso sensor board
3// Copyright (c) 2008-2009 jokamajo.org
4// Copyright (c) 2010      flukso.net
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU General Public License
8// as published by the Free Software Foundation; either version 2
9// of the License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19//
20// $Id$
21//
22
23# define PULSE 0
24# define POWER 1
25
26# define WATT 1000000000
27# define SECOND 624 // 625Hz - 1
28
29#ifndef SENSOR0 
30  #error "SENSOR0 not defined"
31#endif
32
33#ifndef SENSOR1
34  #error "SENSOR1 not defined"
35#endif
36
37#ifndef SENSOR2
38  #error "SENSOR2 not defined"
39#endif
40
41#ifndef SENSOR3
42  #error "SENSOR3 not defined"
43#endif
44
45#ifndef PHASE
46  #error "PHASE not defined"
47#endif
48
49#ifndef METERCONST
50  #error "METERCONST not defined"
51#endif
52
53#define START 0
54#define END3 0xffffffff
55#define END2 0xeeeeeeee
56#define END1 0xdddddddd
57#define END0 0xcccccccc
58
59
60// This macro performs a 16x16 -> 32 unsigned MAC in 37 cycles with operands and results in memory
61// based on http://www2.ife.ee.ethz.ch/~roggend/publications/wear/DSPMic_v1.1.pdf par 3.4 and table 31.
62#define MacU16X16to32(uint_32Acc, uint_16In1, uint_16In2) \
63asm volatile ( \
64  "clr r2 \n\t" \
65  "mul %B2, %B1 \n\t" \
66  "movw r4, r0 \n\t" \
67  "mul %A2, %A1 \n\t" \
68  "add %A0, r0 \n\t" \
69  "adc %B0, r1 \n\t" \
70  "adc %C0, r4 \n\t" \
71  "adc %D0, r5 \n\t" \
72  "mul %B2, %A1 \n\t" \
73  "add %B0, r0 \n\t" \
74  "adc %C0, r1 \n\t" \
75  "adc %D0, r2 \n\t" \
76  "mul %A2, %B1 \n\t" \
77  "add %B0, r0 \n\t" \
78  "adc %C0, r1 \n\t" \
79  "adc %D0, r2 \n\t" \
80  "clr r1 \n\t" \
81  : \
82  "+r" (uint_32Acc) \
83  : \
84  "a" (uint_16In1), \
85  "a" (uint_16In2) \
86  : \
87  "r2", "r4", "r5" \
88)
89
90// datastructures
91struct state {
92  boolean pulse;
93  boolean toggle;
94  uint32_t nano;
95  uint16_t adc;
96
97  boolean  power;
98  uint32_t nano_start;
99  uint32_t nano_end;
100  uint8_t  pulse_count;
101  uint8_t  pulse_count_final;
102};
103
104struct sensor {
105  char id[33];
106  uint32_t value;
107};
108
109// prototypes
110void WDT_off(void);
111void WDT_on(void);
112void send(uint8_t msg_type, const struct sensor *measurement, const struct state *aux);
Note: See TracBrowser for help on using the browser.