[repo] purge the repo to reduce its scope to the Fluksometer v1 firmware

develop
Bart Van Der Meerssche 11 years ago
parent f1cfba46bd
commit 1fb5d7f4f9
  1. 0
      avr/Makefile
  2. 0
      avr/calibration.c
  3. 0
      avr/main.c
  4. 0
      avr/main.h
  5. 0
      avr/wiring/binary.h
  6. 0
      avr/wiring/serial.c
  7. 0
      avr/wiring/wiring.h
  8. 0
      avr/wiring/wiring_private.h
  9. 0
      eagle/prj/flukso.sensor.board.v1.1/flukso.sensor.board.v1.1.brd
  10. 0
      eagle/prj/flukso.sensor.board.v1.1/flukso.sensor.board.v1.1.sch
  11. 0
      eagle/prj/flukso.sensor.board.v1.2/flukso.sensor.board.v1.2.bom.xls
  12. 0
      eagle/prj/flukso.sensor.board.v1.2/flukso.sensor.board.v1.2.brd
  13. 0
      eagle/prj/flukso.sensor.board.v1.2/flukso.sensor.board.v1.2.sch
  14. 0
      eagle/prj/flukso.sensor.board.v1/flukso.sensor.board.v1.brd
  15. 0
      eagle/prj/flukso.sensor.board.v1/flukso.sensor.board.v1.sch
  16. 83
      mote/v2/avr/avrlibdefs.h
  17. 84
      mote/v2/avr/avrlibtypes.h
  18. 269
      mote/v2/avr/basiciotest.c
  19. 153
      mote/v2/avr/buffer.c
  20. 73
      mote/v2/avr/buffer.h
  21. 468
      mote/v2/avr/ctrl.c
  22. 153
      mote/v2/avr/ctrl.h
  23. 20
      mote/v2/avr/debug.h
  24. 18
      mote/v2/avr/encode.h
  25. 54
      mote/v2/avr/global.h
  26. 433
      mote/v2/avr/main.c
  27. 101
      mote/v2/avr/main.h
  28. 568
      mote/v2/avr/makefile
  29. 74
      mote/v2/avr/spi.c
  30. 94
      mote/v2/avr/spi.h
  31. 310
      mote/v2/avr/uart.c
  32. 231
      mote/v2/avr/uart.h
  33. 68
      mote/v2/docs/manual/commands.tex
  34. 76
      mote/v2/docs/manual/deploying.tex
  35. 47
      mote/v2/docs/manual/introduction.tex
  36. 28
      mote/v2/docs/manual/makefile
  37. 31
      mote/v2/docs/manual/manual.tex
  38. 87
      mote/v2/docs/manual/pastie.sty
  39. 49
      mote/v2/docs/manual/preamble.tex
  40. 3
      mote/v2/docs/manual/preface.tex
  41. 154
      mote/v2/eagle/cam/flukso-gerb274x.cam
  42. 72
      mote/v2/eagle/dru/flukso.10mil.dru
  43. 72
      mote/v2/eagle/dru/flukso.8mil.dru
  44. BIN
      mote/v2/eagle/lbr/flukso.lbr
  45. BIN
      mote/v2/eagle/prj/flukso.sensor.board.v2.0/flukso.bom.v2.0.xls
  46. BIN
      mote/v2/eagle/prj/flukso.sensor.board.v2.0/flukso.sensor.board.v2.0.brd
  47. BIN
      mote/v2/eagle/prj/flukso.sensor.board.v2.0/flukso.sensor.board.v2.0.sch
  48. BIN
      mote/v2/eagle/prj/flukso.sensor.board.v2.1/.DS_Store
  49. BIN
      mote/v2/eagle/prj/flukso.sensor.board.v2.1/flukso.bom.v2.1.xls
  50. BIN
      mote/v2/eagle/prj/flukso.sensor.board.v2.1/flukso.sensor.board.v2.1.brd
  51. BIN
      mote/v2/eagle/prj/flukso.sensor.board.v2.1/flukso.sensor.board.v2.1.pdf
  52. BIN
      mote/v2/eagle/prj/flukso.sensor.board.v2.1/flukso.sensor.board.v2.1.sch
  53. 1648
      mote/v2/openwrt/.config
  54. 2
      mote/v2/openwrt/INSTALL
  55. 14
      mote/v2/openwrt/files/etc/avahi/services/flukso.service
  56. 10
      mote/v2/openwrt/files/etc/avahi/services/http.service
  57. 23
      mote/v2/openwrt/files/etc/config/dhcp
  58. 3
      mote/v2/openwrt/files/etc/config/dropbear
  59. 113
      mote/v2/openwrt/files/etc/config/firewall
  60. 17
      mote/v2/openwrt/files/etc/config/network
  61. 22
      mote/v2/openwrt/files/etc/config/system
  62. 83
      mote/v2/openwrt/files/etc/config/uhttpd
  63. 18
      mote/v2/openwrt/files/etc/config/wireless
  64. 3
      mote/v2/openwrt/files/etc/group
  65. 2
      mote/v2/openwrt/files/etc/hosts
  66. 2
      mote/v2/openwrt/files/etc/inittab
  67. 4
      mote/v2/openwrt/files/etc/passwd
  68. 11
      mote/v2/openwrt/files/etc/rc.local
  69. 21
      mote/v2/openwrt/files/etc/ssl/certs/flukso.ca.crt
  70. 28
      mote/v2/openwrt/files/etc/sysctl.conf
  71. 87
      mote/v2/openwrt/install.sh
  72. 68
      mote/v2/openwrt/package/avahi/.svn/entries
  73. 13
      mote/v2/openwrt/package/avahi/.svn/prop-base/Makefile.svn-base
  74. 196
      mote/v2/openwrt/package/avahi/.svn/text-base/Makefile.svn-base
  75. 196
      mote/v2/openwrt/package/avahi/Makefile
  76. 164
      mote/v2/openwrt/package/avahi/files/.svn/entries
  77. 5
      mote/v2/openwrt/package/avahi/files/.svn/prop-base/avahi-daemon.conf.svn-base
  78. 5
      mote/v2/openwrt/package/avahi/files/.svn/prop-base/avahi-daemon.init.svn-base
  79. 5
      mote/v2/openwrt/package/avahi/files/.svn/prop-base/service-http.svn-base
  80. 5
      mote/v2/openwrt/package/avahi/files/.svn/prop-base/service-ssh.svn-base
  81. 28
      mote/v2/openwrt/package/avahi/files/.svn/text-base/avahi-daemon.conf.svn-base
  82. 23
      mote/v2/openwrt/package/avahi/files/.svn/text-base/avahi-daemon.init.svn-base
  83. 10
      mote/v2/openwrt/package/avahi/files/.svn/text-base/service-http.svn-base
  84. 9
      mote/v2/openwrt/package/avahi/files/.svn/text-base/service-ssh.svn-base
  85. 28
      mote/v2/openwrt/package/avahi/files/avahi-daemon.conf
  86. 23
      mote/v2/openwrt/package/avahi/files/avahi-daemon.init
  87. 10
      mote/v2/openwrt/package/avahi/files/service-http
  88. 9
      mote/v2/openwrt/package/avahi/files/service-ssh
  89. 62
      mote/v2/openwrt/package/avahi/patches/.svn/entries
  90. 80
      mote/v2/openwrt/package/avahi/patches/.svn/text-base/010-step_back_autotools-no-gettext.patch.svn-base
  91. 80
      mote/v2/openwrt/package/avahi/patches/010-step_back_autotools-no-gettext.patch
  92. 58
      mote/v2/openwrt/package/avrdude/Makefile
  93. 1954
      mote/v2/openwrt/package/avrdude/patches/100-automake_1.10.2.patch
  94. 389
      mote/v2/openwrt/package/avrdude/patches/110-gpio_dev.patch
  95. 771
      mote/v2/openwrt/package/avrdude/patches/120-remove_non_gpio_programmers.patch
  96. 5437
      mote/v2/openwrt/package/avrdude/patches/130-remove_small_and_old_AVRs.patch
  97. 95
      mote/v2/openwrt/package/avrdude/patches/140-allow_GPIO0_as_pin.patch
  98. 197
      mote/v2/openwrt/package/avrdude/patches/150-add_atmega168P_support.patch
  99. 13
      mote/v2/openwrt/package/avrdude/patches/160-invert_logic_on_RST_and_SCK_lines.patch
  100. 38
      mote/v2/openwrt/package/button/Makefile
  101. Some files were not shown because too many files have changed in this diff Show More

@ -1,83 +0,0 @@
//
// avrlibdefs.h : AVRlib global defines and macros include file
//
// Copyright (c) 2001-2002 Pascal Stang
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifndef AVRLIBDEFS_H
#define AVRLIBDEFS_H
// Code compatibility to new AVR-libc
// outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli()
#ifndef outb
#define outb(addr, data) addr = (data)
#endif
#ifndef inb
#define inb(addr) (addr)
#endif
#ifndef outw
#define outw(addr, data) addr = (data)
#endif
#ifndef inw
#define inw(addr) (addr)
#endif
#ifndef BV
#define BV(bit) (1<<(bit))
#endif
#ifndef cbi
#define cbi(reg,bit) reg &= ~(BV(bit))
#endif
#ifndef sbi
#define sbi(reg,bit) reg |= (BV(bit))
#endif
#ifndef cli
#define cli() __asm__ __volatile__ ("cli" ::)
#endif
#ifndef sei
#define sei() __asm__ __volatile__ ("sei" ::)
#endif
// support for individual port pin naming in the mega128
// see port128.h for details
#ifdef __AVR_ATmega128__
// not currently necessary due to inclusion
// of these defines in newest AVR-GCC
// do a quick test to see if include is needed
#ifndef PD0
#include "port128.h"
#endif
#endif
// use this for packed structures
// (this is seldom necessary on an 8-bit architecture like AVR,
// but can assist in code portability to AVR)
#define GNUC_PACKED __attribute__((packed))
// port address helpers
#define DDR(x) ((x)-1) // address of data direction register of port x
#define PIN(x) ((x)-2) // address of input register of port x
// MIN/MAX/ABS macros
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a>b)?(a):(b))
#define ABS(x) ((x>0)?(x):(-x))
// constants
#define PI 3.14159265359
#endif

@ -1,84 +0,0 @@
//
// avrlibtypes.h : AVRlib global types and typedefines include file
//
// Copyright (c) 2001-2002 Pascal Stang
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifndef AVRLIBTYPES_H
#define AVRLIBTYPES_H
#ifndef WIN32
// true/false defines
#define FALSE 0
#define TRUE -1
#endif
// datatype definitions macros
typedef unsigned char u08;
typedef signed char s08;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned long u32;
typedef signed long s32;
typedef unsigned long long u64;
typedef signed long long s64;
/* use inttypes.h instead
// C99 standard integer type definitions
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned long uint32_t;
typedef signed long int32_t;
typedef unsigned long uint64_t;
typedef signed long int64_t;
*/
// maximum value that can be held
// by unsigned data types (8,16,32bits)
#define MAX_U08 255
#define MAX_U16 65535
#define MAX_U32 4294967295
// maximum values that can be held
// by signed data types (8,16,32bits)
#define MIN_S08 -128
#define MAX_S08 127
#define MIN_S16 -32768
#define MAX_S16 32767
#define MIN_S32 -2147483648
#define MAX_S32 2147483647
#ifndef WIN32
// more type redefinitions
typedef unsigned char BOOL;
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;
typedef unsigned char UCHAR;
typedef unsigned int UINT;
typedef unsigned short USHORT;
typedef unsigned long ULONG;
typedef char CHAR;
typedef int INT;
typedef long LONG;
#endif
#endif

@ -1,269 +0,0 @@
//
// basiciotest.c : test code for the io and buffer ops of the UART and SPI ports
//
// Copyright (c) 2010 flukso.net
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include "uart.h"
#include "spi.h"
#include "ctrl.h"
#define NO_OP_1 1
#define NO_OP_2 2
#define START_TX 4
#define TRANSMIT 8
#define HIGH_HEX 16
#define TO_FROM_UART 32
#define NEW_CTRL_MSG 64
#define SPI_END_OF_TX 0x00
#define SPI_END_OF_MESSAGE '.'
#define SPI_FORWARD_TO_UART_PORT 'u'
#define SPI_FORWARD_TO_CTRL_PORT 'l' // 'l'ocal port
volatile uint8_t spi_status, high_hex;
// hex to binary/byte decoding
uint8_t htob(uint16_t hex)
{
uint8_t low_hex = (uint8_t) hex;
uint8_t high_hex = (uint8_t) (hex >> 8);
uint8_t byte;
byte = (high_hex > 0x40) ? (high_hex & 0x0F) + 9 : high_hex & 0x0F;
byte = byte << 4;
byte |= (low_hex > 0x40) ? (low_hex & 0x0F) + 9 : low_hex & 0x0F;
return byte;
}
// binary/byte to hex encoding
uint16_t btoh(uint8_t byte)
{
uint8_t low_nibble = (byte & 0x0F);
uint8_t high_nibble = (byte & 0xF0) >> 4;
uint16_t hex;
hex = (high_nibble > 0x09) ? high_nibble - 9 + 0x60 : high_nibble + 0x30;
hex = hex << 8;
hex |= (low_nibble > 0x09) ? low_nibble - 9 + 0x60 : low_nibble + 0x30;
return hex;
}
ISR(SPI_STC_vect)
{
uint8_t spi_rx, rx, tx;
uint16_t spi_tx;
// the SPI is double-buffered, requiring two NO_OPs when switching from Tx to Rx
if (spi_status & (NO_OP_1 | NO_OP_2)) {
spi_status--;
return;
}
// do we have to transmit the first byte?
if (spi_status & START_TX) {
received_from_spi(SPI_FORWARD_TO_CTRL_PORT);
spi_status &= ~START_TX;
return;
}
// are we in Tx mode?
if (spi_status & TRANSMIT) {
if (spi_status & HIGH_HEX) {
received_from_spi(high_hex);
spi_status &= ~HIGH_HEX;
return;
}
if (spi_status & TO_FROM_UART) {
if (!uartReceiveByte(&tx)) {
received_from_spi(SPI_END_OF_TX);
spi_status &= ~TRANSMIT;
spi_status |= NO_OP_2;
return;
}
}
else {
if (ctrlGetFromTxBuffer(&tx)) {
if (tx == SPI_END_OF_MESSAGE) {
received_from_spi(tx);
return;
}
}
else {
received_from_spi(SPI_FORWARD_TO_UART_PORT);
spi_status |= TO_FROM_UART;
return;
}
}
spi_tx = btoh(tx);
high_hex = (uint8_t)spi_tx;
spi_status |= HIGH_HEX;
received_from_spi((uint8_t)(spi_tx >> 8));
return;
}
// we're in Rx mode
switch (spi_rx = received_from_spi(0x00)) {
case SPI_END_OF_TX:
spi_status |= TRANSMIT | START_TX;
spi_status &= ~(HIGH_HEX | TO_FROM_UART);
break;
case SPI_END_OF_MESSAGE:
if (!(spi_status & TO_FROM_UART)) {
ctrlAddToRxBuffer(spi_rx);
spi_status |= NEW_CTRL_MSG;
}
break;
case SPI_FORWARD_TO_UART_PORT:
spi_status |= TO_FROM_UART;
break;
case SPI_FORWARD_TO_CTRL_PORT:
spi_status &= ~TO_FROM_UART;
break;
default:
if (spi_status & HIGH_HEX) {
rx = htob(((uint16_t)high_hex << 8) + spi_rx);
if (spi_status & TO_FROM_UART) {
uartAddToTxBuffer(rx);
}
else {
ctrlAddToRxBuffer(rx);
}
}
else {
high_hex = spi_rx;
}
// toggle the HEX bit in spi_status
spi_status ^= HIGH_HEX;
}
}
ISR(TIMER1_COMPA_vect)
{
/* void */
}
ISR(ANALOG_COMP_vect)
{
uint8_t i;
PORTB |= (1<<PB0);
//disable uC sections to consume less power while writing to EEPROM
//disable UART Tx and Rx:
UCSR0B &= ~((1<<RXEN0) | (1<<TXEN0));
//disable ADC:
ADCSRA &= ~(1<<ADEN);
for (i=0; i<128; i++)
eeprom_write_byte((uint8_t *)i, i);
//enable UART Tx and Rx:
UCSR0B |= (1<<RXEN0) | (1<<TXEN0);
// enable ADC and start a first ADC conversion
ADCSRA |= (1<<ADEN) | (1<<ADSC);
PORTB &= ~(1<<PB0);
}
void setup_pulse_input(void)
{
// PD2=INT0 and PD3=INT1 configuration
// set as input pin with 20k pull-up enabled
PORTD |= (1<<PD2) | (1<<PD3);
// INT0 and INT1 to trigger an interrupt on a falling edge
EICRA = (1<<ISC01) | (1<<ISC11);
// enable INT0 and INT1 interrupts
EIMSK = (1<<INT0) | (1<<INT1);
}
void setup_timer1(void)
{
// Timer1 clock prescaler set to 1 => fTOV1 = 3686.4kHz / 65536 = 56.25Hz (DS p.134)
TCCR1B |= (1<<CS10);
// Increase sampling frequency to 2kHz (= 667Hz per channel) with an error of 0.01% (DS p.122)
OCR1A = 0x0732;
// Timer1 set to CTC mode (DS p.133)
TCCR1B |= 1<<WGM12;
// Enable output compare match interrupt for timer1 (DS p.136)
TIMSK1 |= (1<<OCIE1A);
#if DBG > 0
// Set PB1=OC1A as output pin
DDRB |= (1<<DDB1);
// Toggle pin OC1A=PB1 on compare match
TCCR1A |= 1<<COM1A0;
#endif
}
void setup_analog_comparator(void)
{
// analog comparator setup for brown-out detection
// PD7=AIN1 configured by default as input to obtain high impedance
// disable digital input cicuitry on AIN0 and AIN1 pins to reduce leakage current
DIDR1 |= (1<<AIN1D) | (1<<AIN0D);
// comparing AIN1 (Vcc/4.4) to bandgap reference (1.1V)
// bandgap select | AC interrupt enable | AC interrupt on rising edge (DS p.243)
ACSR |= (1<<ACBG) | (1<<ACIE) | (1<<ACIS1) | (1<<ACIS0);
}
int main(void)
{
// RS-485: Configure PD5=DE as output pin with low as default
DDRD |= (1<<DDD5);
// set high to transmit
//PORTD |= (1<<PD5);
setup_timer1();
setup_pulse_input();
setup_analog_comparator();
// initialize the CTRL buffers
ctrlInit();
// initialize the UART hardware and buffers
uartInit();
// initialize the SPI in slave mode
setup_spi(SPI_MODE_0, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE);
for(;;) {
if (spi_status & NEW_CTRL_MSG) {
ctrlRxToTxLoop();
spi_status &= ~NEW_CTRL_MSG;
}
// toggle the LED=PB0 pin
_delay_ms(50);
DDRB ^= (1<<PB0);
}
return 0;
}

@ -1,153 +0,0 @@
//
// buffer.c : Multipurpose byte buffer structure and methods
//
// Copyright (c) 2001 Pascal Stang
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#include "buffer.h"
#include "global.h"
#include "avr/io.h"
#ifndef CRITICAL_SECTION_START
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli()
#define CRITICAL_SECTION_END SREG = _sreg
#endif
// global variables
// initialization
void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size)
{
// begin critical section
CRITICAL_SECTION_START;
// set start pointer of the buffer
buffer->dataptr = start;
buffer->size = size;
// initialize index and length
buffer->dataindex = 0;
buffer->datalength = 0;
// end critical section
CRITICAL_SECTION_END;
}
// access routines
unsigned char bufferGetFromFront(cBuffer* buffer)
{
unsigned char data = 0;
// begin critical section
CRITICAL_SECTION_START;
// check to see if there's data in the buffer
if(buffer->datalength)
{
// get the first character from buffer
data = buffer->dataptr[buffer->dataindex];
// move index down and decrement length
buffer->dataindex++;
if(buffer->dataindex >= buffer->size)
{
buffer->dataindex -= buffer->size;
}
buffer->datalength--;
}
// end critical section
CRITICAL_SECTION_END;
// return
return data;
}
void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes)
{
// begin critical section
CRITICAL_SECTION_START;
// dump numbytes from the front of the buffer
// are we dumping less than the entire buffer?
if(numbytes < buffer->datalength)
{
// move index down by numbytes and decrement length by numbytes
buffer->dataindex += numbytes;
if(buffer->dataindex >= buffer->size)
{
buffer->dataindex -= buffer->size;
}
buffer->datalength -= numbytes;
}
else
{
// flush the whole buffer
buffer->datalength = 0;
}
// end critical section
CRITICAL_SECTION_END;
}
unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index)
{
// begin critical section
CRITICAL_SECTION_START;
// return character at index in buffer
unsigned char data = buffer->dataptr[(buffer->dataindex+index)%(buffer->size)];
// end critical section
CRITICAL_SECTION_END;
return data;
}
unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data)
{
// begin critical section
CRITICAL_SECTION_START;
// make sure the buffer has room
if(buffer->datalength < buffer->size)
{
// save data byte at end of buffer
buffer->dataptr[(buffer->dataindex + buffer->datalength) % buffer->size] = data;
// increment the length
buffer->datalength++;
// end critical section
CRITICAL_SECTION_END;
// return success
return -1;
}
// end critical section
CRITICAL_SECTION_END;
// return failure
return 0;
}
unsigned short bufferIsNotFull(cBuffer* buffer)
{
// begin critical section
CRITICAL_SECTION_START;
// check to see if the buffer has room
// return true if there is room
unsigned short bytesleft = (buffer->size - buffer->datalength);
// end critical section
CRITICAL_SECTION_END;
return bytesleft;
}
void bufferFlush(cBuffer* buffer)
{
// begin critical section
CRITICAL_SECTION_START;
// flush contents of the buffer
buffer->datalength = 0;
// end critical section
CRITICAL_SECTION_END;
}

@ -1,73 +0,0 @@
//
// buffer.h : Multipurpose byte buffer structure and methods
//
// This byte-buffer structure provides an easy and efficient way to store
// and process a stream of bytes. You can create as many buffers as you
// like (within memory limits), and then use this common set of functions to
// access each buffer. The buffers are designed for FIFO operation (first
// in, first out). This means that the first byte you put in the buffer
// will be the first one you get when you read out the buffer. Supported
// functions include buffer initialize, get byte from front of buffer, add
// byte to end of buffer, check if buffer is full, and flush buffer. The
// buffer uses a circular design so no copying of data is ever necessary.
// This buffer is not dynamically allocated, it has a user-defined fixed
// maximum size. This buffer is used in many places in the avrlib code.
//
// Copyright (c) 2001-2002 Pascal Stang
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifndef BUFFER_H
#define BUFFER_H
// structure/typdefs
//! cBuffer structure
typedef struct struct_cBuffer
{
unsigned char *dataptr; ///< the physical memory address where the buffer is stored
unsigned short size; ///< the allocated size of the buffer
unsigned short datalength; ///< the length of the data currently in the buffer
unsigned short dataindex; ///< the index into the buffer where the data starts
} cBuffer;
// function prototypes
//! initialize a buffer to start at a given address and have given size
void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size);
//! get the first byte from the front of the buffer
unsigned char bufferGetFromFront(cBuffer* buffer);
//! dump (discard) the first numbytes from the front of the buffer
void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes);
//! get a byte at the specified index in the buffer (kind of like array access)
// ** note: this does not remove the byte that was read from the buffer
unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index);
//! add a byte to the end of the buffer
unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data);
//! check if the buffer is full/not full (returns zero value if full)
unsigned short bufferIsNotFull(cBuffer* buffer);
//! flush (clear) the contents of the buffer
void bufferFlush(cBuffer* buffer);
#endif

@ -1,468 +0,0 @@
//
// ctrl.c : AVR uC code for ctrl buffer initialisation and put/get ops
//
// Copyright (c) 2010 flukso.net
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#include <avr/eeprom.h>
#include <util/crc16.h>
#include "global.h"
#include "main.h"
#include "buffer.h"
#include "ctrl.h"
#include "encode.h"
cBuffer ctrlRxBuffer; // ctrl receive buffer
cBuffer ctrlTxBuffer; // ctrl transmit buffer
static char ctrlRxData[CTRL_RX_BUFFER_SIZE];
static char ctrlTxData[CTRL_TX_BUFFER_SIZE];
extern struct version_struct EEMEM EEPROM_version;
extern struct version_struct version;
extern struct event_struct EEMEM EEPROM_event;
extern struct event_struct event;
extern uint8_t EEMEM EEPROM_enabled;
extern uint8_t enabled;
extern uint8_t EEMEM EEPROM_phy_to_log[MAX_SENSORS];
extern uint8_t phy_to_log[MAX_SENSORS];
extern struct sensor_struct EEMEM EEPROM_sensor[MAX_SENSORS];
extern struct sensor_struct sensor[MAX_SENSORS];
extern struct state_struct state[MAX_SENSORS];
void ctrlInit(void)
{
// initialize the CTRL receive buffer
bufferInit(&ctrlRxBuffer, (u08*) ctrlRxData, CTRL_RX_BUFFER_SIZE);
// initialize the CTRL transmit buffer
bufferInit(&ctrlTxBuffer, (u08*) ctrlTxData, CTRL_TX_BUFFER_SIZE);
}
uint8_t ctrlTxBufferIsEmpty(void)
{
if(ctrlTxBuffer.datalength == 0) {
return TRUE;
}
else {
return FALSE;
}
}
uint8_t ctrlAddToTxBuffer(uint8_t data)
{
return bufferAddToEnd(&ctrlTxBuffer, data);
}
uint8_t ctrlGetFromTxBuffer(uint8_t* data) {
// make sure we have data in the Tx buffer
if(ctrlTxBuffer.datalength) {
// get byte from beginning of buffer
*data = bufferGetFromFront(&ctrlTxBuffer);
return TRUE;
}
else {
// no data
return FALSE;
}
}
uint8_t ctrlRxBufferIsEmpty(void)
{
if(ctrlRxBuffer.datalength == 0) {
return TRUE;
}
else {
return FALSE;
}
}
uint8_t ctrlAddToRxBuffer(uint8_t data)
{
return bufferAddToEnd(&ctrlRxBuffer, data);
}
uint8_t ctrlGetFromRxBuffer(uint8_t* pdata)
{
// make sure we have data in the Rx buffer
if(ctrlRxBuffer.datalength) {
// get byte from beginning of buffer
*pdata = bufferGetFromFront(&ctrlRxBuffer);
return TRUE;
}
else {
// no data
return FALSE;
}
}
void ctrlFlushRxBuffer(void)
{
ctrlRxBuffer.datalength = 0;
}
void ctrlFlushTxBuffer(void)
{
ctrlTxBuffer.datalength = 0;
}
uint8_t ctrlReadCharFromRxBuffer(uint8_t* pdata)
{
uint8_t high_hex, low_hex;
if (ctrlGetFromRxBuffer(&high_hex) && ctrlGetFromRxBuffer(&low_hex)) {
htob(high_hex, low_hex, pdata);
return TRUE;
}
else {
return FALSE;
}
}
uint8_t ctrlReadShortFromRxBuffer(uint16_t* pdata)
{
uint8_t high_char, low_char;
if(ctrlReadCharFromRxBuffer(&high_char) && ctrlReadCharFromRxBuffer(&low_char)) {
*pdata = ((uint16_t)high_char << 8) + low_char;
return TRUE;
}
else {
return FALSE;
}
}
uint8_t ctrlReadLongFromRxBuffer(uint32_t* pdata)
{
uint16_t high_short, low_short;
if(ctrlReadShortFromRxBuffer(&high_short) && ctrlReadShortFromRxBuffer(&low_short)) {
*pdata = ((uint32_t)high_short << 16) + low_short;
return TRUE;
}
else {
return FALSE;
}
}
uint8_t ctrlWriteCharToTxBuffer(uint8_t data)
{
uint8_t high_hex, low_hex;
btoh(data, &high_hex, &low_hex);
if (ctrlAddToTxBuffer(high_hex) && ctrlAddToTxBuffer(low_hex)) {
return TRUE;
}
else {
return FALSE;
}
}
uint8_t ctrlWriteShortToTxBuffer(uint16_t data)
{
if (ctrlWriteCharToTxBuffer((uint8_t)(data >> 8)) && ctrlWriteCharToTxBuffer((uint8_t)data)) {
return TRUE;
}
else {
return FALSE;
}
}
uint8_t ctrlWriteLongToTxBuffer(uint32_t data)
{
if (ctrlWriteShortToTxBuffer((uint16_t)(data >> 16)) && ctrlWriteShortToTxBuffer((uint16_t)data)) {
return TRUE;
}
else {
return FALSE;
}
}
void ctrlRxToTxLoop(void)
{
uint8_t data;
while (ctrlGetFromRxBuffer(&data)) {
ctrlAddToTxBuffer(data);
}
}
uint8_t ctrlCalcCrc8(cBuffer* buffer, uint8_t chop)
{
uint8_t i, crc = 0;
for (i = 0; i < buffer->datalength - chop; i++) {
crc = _crc_ibutton_update(crc, bufferGetAtIndex(buffer, i));
}
return crc;
}
uint8_t ctrlExtractCrc8fromMessage(cBuffer* buffer)
{
uint8_t crc, high_hex, low_hex;
high_hex = bufferGetAtIndex(buffer, buffer->datalength - 2);
low_hex = bufferGetAtIndex(buffer, buffer->datalength - 1);
htob(high_hex, low_hex, &crc);
return crc;
}
void ctrlDecode(void)
{
uint8_t cmd[2], crc;
ctrlFlushTxBuffer();
crc = ctrlExtractCrc8fromMessage(&ctrlRxBuffer);
if (ctrlCalcCrc8(&ctrlRxBuffer, 2) != crc) {
ctrlAddToTxBuffer('z');
ctrlAddToTxBuffer('z');
}
else if (ctrlGetFromRxBuffer(cmd) && ctrlGetFromRxBuffer(cmd+1)) {
ctrlAddToTxBuffer(cmd[0]);
ctrlAddToTxBuffer(cmd[1]);
switch (cmd[0]) {
case 'g': /* get */
ctrlCmdGet(cmd[1]);
break;
case 's': /* set */
ctrlCmdSet(cmd[1]);
break;
case 'c': /* commit */
if (cmd[1] == 't') ctrlCmdCommit();
break;
}
}
else {
ctrlAddToTxBuffer('z');
ctrlAddToTxBuffer('y');
}
crc = ctrlCalcCrc8(&ctrlTxBuffer, 0);
ctrlWriteCharToTxBuffer(crc);
ctrlAddToTxBuffer('.');
ctrlFlushRxBuffer();
}
void ctrlCmdGet(uint8_t cmd)
{
uint8_t i = 0;
uint32_t tmp32, tmp32_bis;
switch (cmd) {
case 'h': /* hardware {major,minor} version */
ctrlWriteShortToTxBuffer(version.hw_major);
ctrlWriteCharToTxBuffer(version.hw_minor);
break;
case 's': /* software {major,minor} version */
ctrlWriteCharToTxBuffer(version.sw_major);
ctrlWriteCharToTxBuffer(version.sw_minor);
break;
case 'e': /* sensor enabled | disabled */
ctrlReadCharFromRxBuffer(&i);
if (i < MAX_SENSORS) {
ctrlWriteCharToTxBuffer(i);
ctrlWriteCharToTxBuffer((enabled >> i) & 0x01);
}
break;
case 'p': /* phy-to-logical mapping */
for (i = 0 ; i < MAX_SENSORS; i++) {
ctrlWriteCharToTxBuffer(phy_to_log[i]);
}
break;
case 'c': /* sensor counter value */
ctrlReadCharFromRxBuffer(&i);
if (i < MAX_SENSORS) {
cli();
tmp32 = sensor[i].counter;
sei();
ctrlWriteCharToTxBuffer(i);
ctrlWriteLongToTxBuffer(tmp32);
}
break;
case 'm': /* sensor meterconstant */
ctrlReadCharFromRxBuffer(&i);
if (i < MAX_SENSORS) {
ctrlWriteCharToTxBuffer(i);
ctrlWriteShortToTxBuffer(sensor[i].meterconst);
}
break;
case 'w': /* watchdog counter */
ctrlWriteShortToTxBuffer(event.wdt);
break;
case 'b': /* brown-out counter */
ctrlWriteShortToTxBuffer(event.brown_out);
break;
case 'd': /* delta: all changes since last gd */
for (i = 0 ; i < MAX_SENSORS; i++) {
if (state[i].flags & (STATE_PULSE | STATE_POWER)) {
ctrlWriteCharToTxBuffer(i);
cli();
tmp32 = sensor[i].counter;
tmp32_bis = (i < MAX_ANALOG_SENSORS) ? state[i].power : state[i].timestamp;
state[i].flags &= ~(STATE_PULSE | STATE_POWER);
sei();
ctrlWriteLongToTxBuffer(tmp32);
ctrlWriteLongToTxBuffer(tmp32_bis);
}
}
break;
}
}
void ctrlCmdSet(uint8_t cmd)
{
uint8_t i = 0, tmp8 = 0;
uint16_t tmp16 = 0;
uint32_t tmp32 = 0;
switch (cmd) {
case 'h': /* hardware {major,minor} version */
ctrlReadShortFromRxBuffer(&version.hw_major);
ctrlReadCharFromRxBuffer(&version.hw_minor);
ctrlWriteShortToTxBuffer(version.hw_major);
ctrlWriteCharToTxBuffer(version.hw_minor);
break;
case 's': /* software {major,minor} version */
ctrlReadCharFromRxBuffer(&version.sw_major);
ctrlReadCharFromRxBuffer(&version.sw_minor);
ctrlWriteCharToTxBuffer(version.sw_major);
ctrlWriteCharToTxBuffer(version.sw_minor);
break;
case 'e': /* sensor enabled | disabled */
ctrlReadCharFromRxBuffer(&i);
if (i < MAX_SENSORS) {
ctrlReadCharFromRxBuffer(&tmp8);
if (tmp8) {
enabled |= (1 << i);
}
else {
enabled &= ~(1 << i);
}
ctrlWriteCharToTxBuffer(i);
ctrlWriteCharToTxBuffer((enabled >> i) & 0x01);
}
break;
case 'p': /* phy-to-logical mapping */
for (i = 0 ; i < MAX_SENSORS; i++) {
ctrlReadCharFromRxBuffer(&tmp8);
cli();
phy_to_log[i] = tmp8;
sei();
ctrlWriteCharToTxBuffer(phy_to_log[i]);
}
break;
case 'c': /* sensor counter value */
ctrlReadCharFromRxBuffer(&i);
if (i < MAX_SENSORS) {
ctrlReadLongFromRxBuffer(&tmp32);
cli();
sensor[i].counter = tmp32;
sei();
ctrlWriteCharToTxBuffer(i);
ctrlWriteLongToTxBuffer(tmp32);
}
break;
case 'm': /* sensor meterconstant */
ctrlReadCharFromRxBuffer(&i);
if (i < MAX_SENSORS) {
ctrlReadShortFromRxBuffer(&tmp16);
cli();
sensor[i].meterconst = tmp16;
sei();
ctrlWriteCharToTxBuffer(i);
ctrlWriteShortToTxBuffer(sensor[i].meterconst);
}
break;
case 'w': /* watchdog counter */
ctrlReadShortFromRxBuffer(&tmp16);
cli();
event.wdt = tmp16;
sei();
ctrlWriteShortToTxBuffer(event.wdt);
break;
case 'b': /* brown-out counter */
ctrlReadShortFromRxBuffer(&tmp16);
cli();
event.brown_out = tmp16;
sei();
ctrlWriteShortToTxBuffer(event.brown_out);
break;
}
}
void ctrlCmdCommit(void)
{
cli();
eeprom_update_block((const void*)&version, (void*)&EEPROM_version, sizeof(version));
eeprom_update_block((const void*)&event, (void*)&EEPROM_event, sizeof(event));
eeprom_update_block((const void*)&enabled, (void*)&EEPROM_enabled, sizeof(enabled));
eeprom_update_block((const void*)&phy_to_log, (void*)&EEPROM_phy_to_log, sizeof(phy_to_log));
eeprom_update_block((const void*)&sensor, (void*)&EEPROM_sensor, sizeof(sensor));
sei();
}

@ -1,153 +0,0 @@
//
// ctrl.h : AVR uC code for ctrl buffer initialisation and put/get ops
//
// Copyright (c) 2010 flukso.net
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifndef CTRL_H
#define CTRL_H
#endif
#include <inttypes.h>
#include "buffer.h"
#ifndef CTRL_RX_BUFFER_SIZE
#define CTRL_RX_BUFFER_SIZE 32
#endif
#ifndef CTRL_TX_BUFFER_SIZE
#define CTRL_TX_BUFFER_SIZE 32
#endif
/**
* Initialize the ctrl receive and transmit buffers.
*
* Overrule the default Rx and Tx ctrl buffer size (32 bytes) in the makefile.
*/
void ctrlInit(void);
/**
* Check whether the ctrl Tx buffer is empty.
*
* @return TRUE/FALSE if empty/not empty
*/
uint8_t ctrlTxBufferIsEmpty(void);
/**
* Add a byte to the ctrl Tx buffer's tail.
*
* @param data the byte to be added to the buffer's tail
* @return TRUE/FALSE if byte could/could not be written
*/
uint8_t ctrlAddToTxBuffer(uint8_t data);
/**
* Fetch a byte from the ctrl Tx buffer's head.
*
* @param data pointer where the byte has to be written
* @return TRUE/FALSE if a byte could be fetched/not fetched
*/
uint8_t ctrlGetFromTxBuffer(uint8_t* data);
/**
* Check whether the ctrl Rx buffer is empty.
*
* @return TRUE/FALSE if empty/not empty
*/
uint8_t ctrlRxBufferIsEmpty(void);
/**
* Add a byte to the ctrl Rx buffer.
*
* @param data the byte to be added to the buffer's tail
* @return TRUE/FALSE if empty/not empty
*/
uint8_t ctrlAddToRxBuffer(uint8_t data);
/**
* Fetch a byte from the ctrl Rx buffer's head.
*
* @param data pointer where the byte has to be written
* @return TRUE/FALSE if a byte could be fetched/not fetched
*/
uint8_t ctrlGetFromRxBuffer(uint8_t* data);
/**
* Flush the ctrl Rx buffer.
*
*/
void ctrlFlushRxBuffer(void);
/**
* Flush the ctrl Tx buffer.
*
*/
void ctrlFlushTxBuffer(void);
/**
* Loop all bytes from the ctrl Rx to Tx buffer.
*
*/
void ctrlRxToTxLoop(void);
/**
* Calculate the CRC-8 checksum over the bytes in the buffer.
*
* @param buffer pointer to the buffer containing the data
* @param chop chop number of bytes from end of buffer for crc calc
* @return CRC-8 checksum
*/
uint8_t ctrlCalcCrc8(cBuffer* buffer, uint8_t chop);
/**
* Extract the CRC-8 checksum out of the message in the buffer.
*
* @param buffer pointer to the buffer containing the message
* @return CRC-8 checksum
*/
uint8_t ctrlExtractCrc8fromMessage(cBuffer* buffer);
/**
* Decode the message in the ctrl Rx buffer and dispatch to either ctrlCmdGet,
* ctrlCmdSet or ctrlCmdCommit.
*
*/
void ctrlDecode(void);
/**
* Execute the get command with parameters present in the ctrl Rx buffer.
* The command's reply is written to the ctrl Tx buffer.
*
* @param cmd get command issued
*/
void ctrlCmdGet(uint8_t cmd);
/**
* Execute the set command with parameters present in the ctrl Rx buffer.
* The command's reply is written to the ctrl Tx buffer. In case of a set
* command this will typically only be the two-letter command ID issued.
*
* @param cmd set command issued
*/
void ctrlCmdSet(uint8_t cmd);
/**
* Commit all previous changes by writing the datastructures to EEPROM.
*
*/
void ctrlCmdCommit(void);

@ -1,20 +0,0 @@
#if DBG > 0
/* set LED pin high/low at the start/end of an ISR */
#define DBG_ISR_BEGIN() PORTB |= (1<<PB0)
#define DBG_ISR_END() PORTB &= ~(1<<PB0)
/* Set PB1=OC1A as output pin and toggle this pin on TIMER1 compare match */
#define DBG_OC1A_TOGGLE() DDRB |= (1<<DDB1); \
TCCR1A |= 1<<COM1A0
#define DBG_LED_ON() /* nothing */
#define DBG_LED_OFF() /* nothing */
#else
#define DBG_ISR_BEGIN() /* nothing */
#define DBG_ISR_END() /* nothing */
#define DBG_OC1A_TOGGLE() /* nothing */
/* LED behaviour in non-debugging mode */
#define DBG_LED_ON() PORTB &= ~(1<<PB0)
#define DBG_LED_OFF() PORTB |= (1<<PB0)
#endif

@ -1,18 +0,0 @@
#include <stdint.h>
// hex to binary/byte decoding
static inline void htob(uint8_t high_hex, uint8_t low_hex, uint8_t *pbyte)
{
*pbyte = (high_hex > 0x40) ? (high_hex & 0x0F) + 9 : high_hex & 0x0F;
*pbyte = *pbyte << 4;
*pbyte |= (low_hex > 0x40) ? (low_hex & 0x0F) + 9 : low_hex & 0x0F;
}
// binary/byte to hex encoding
static inline void btoh(uint8_t byte, uint8_t *phigh_hex, uint8_t *plow_hex)
{
*plow_hex = byte & 0x0F;
*plow_hex = (*plow_hex > 0x09) ? *plow_hex - 9 + 0x60 : *plow_hex + 0x30;
*phigh_hex = (byte & 0xF0) >> 4;
*phigh_hex = (*phigh_hex > 0x09) ? *phigh_hex - 9 + 0x60 : *phigh_hex + 0x30;
}

@ -1,54 +0,0 @@
//
// global.h : AVR project global include
//
// Copyright (c) 2001-2002 Pascal Stang
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifndef GLOBAL_H
#define GLOBAL_H
// global AVRLIB defines
#include "avrlibdefs.h"
// global AVRLIB types definitions
#include "avrlibtypes.h"
// project/system dependent defines
// CPU clock speed
//#define F_CPU 16000000 // 16MHz processor
//#define F_CPU 14745000 // 14.745MHz processor
//#define F_CPU 8000000 // 8MHz processor