From 830f17246cf81df91407379921ea634d6f31bffd Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 9 Dec 2010 13:24:24 +0100 Subject: [PATCH] [Chronos] * changed display driver interface from uint8_t* to char* * fixed hardware timer interrupt * ported cc1100 driver * added simple test application for radio [msb430] * fixex config and flashrom [cc110x_ng] * removed dependency from sysconfig --- board/chronos/drivers/cc430-cc1100.c | 31 ++++-- board/chronos/drivers/display.c | 18 ++- board/chronos/drivers/display.h | 4 +- board/msb-430-common/Jamfile | 2 +- .../{config.c => board_config.c} | 10 ++ board/msb-430h/Jamfile | 2 +- board/msb-430h/driver_cc1100.c | 3 +- cpu/cc430/hwtimer_cc430.c | 34 ++---- cpu/msp430-common/Jamfile | 2 +- cpu/msp430-common/flashrom.c | 2 + cpu/msp430-common/hwtimer_cpu.c | 5 +- cpu/msp430-common/include/cpu-conf.h | 4 +- drivers/cc110x_ng/Jamfile | 2 +- drivers/cc110x_ng/cc1100.c | 35 ++++-- projects/chronos_cc110x_ng/Jamfile | 5 + projects/chronos_cc110x_ng/main.c | 103 ++++++++++++++++++ projects/chronos_cc110x_ng/tests/hello-world | 13 +++ 17 files changed, 209 insertions(+), 66 deletions(-) rename board/msb-430-common/{config.c => board_config.c} (55%) create mode 100644 projects/chronos_cc110x_ng/Jamfile create mode 100644 projects/chronos_cc110x_ng/main.c create mode 100755 projects/chronos_cc110x_ng/tests/hello-world diff --git a/board/chronos/drivers/cc430-cc1100.c b/board/chronos/drivers/cc430-cc1100.c index 9ca689036..6c36e7e6d 100644 --- a/board/chronos/drivers/cc430-cc1100.c +++ b/board/chronos/drivers/cc430-cc1100.c @@ -2,13 +2,15 @@ #include #include +#include #include -#warning CC430_CC1100 NOT WORKING -/* TODO: defines... */ -#define CC1100_GDO0 (0) -#define CC1100_GDO1 (1) -#define CC1100_GDO2 (2) +#include +#include + +#define CC1100_GDO0 IOCFG0 +#define CC1100_GDO1 IOCFG1 +#define CC1100_GDO2 IOCFG2 int cc1100_get_gdo0(void) { return CC1100_GDO0; @@ -35,15 +37,23 @@ void cc1100_after_send(void) } void cc1100_gdo0_enable(void) { + RF1AIFG &= ~RF1AIV_RFIFG0; + RF1AIE |= RF1AIV_RFIFG0; } void cc1100_gdo0_disable(void) { + RF1AIE &= ~RF1AIV_RFIFG0; + RF1AIFG &= ~RF1AIV_RFIFG0; } void cc1100_gdo2_disable(void) { + RF1AIFG &= ~RF1AIV_RFIFG2; + RF1AIE &= ~RF1AIV_RFIFG2; } void cc1100_gdo2_enable(void) { + RF1AIE &= ~RF1AIV_RFIFG2; + RF1AIFG |= RF1AIV_RFIFG2; } void cc1100_init_interrupts(void) { @@ -51,16 +61,17 @@ void cc1100_init_interrupts(void) { restoreIRQ(state); /* Enable all interrupts */ } -interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ +interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ __enter_isr(); /* Check IFG */ - if (1 == 1) { + if (RF1AIFG & RF1AIV_RFIFG2) { + RF1AIFG &= ~RF1AIV_RFIFG2; cc1100_gdo2_irq(); } - else if (2 == 2) { + if (RF1AIFG & RF1AIV_RFIFG0) { + RF1AIFG &= ~RF1AIV_RFIFG0; + RF1AIE &= ~RF1AIV_RFIFG0; cc1100_gdo0_irq(); - } else { - puts("cc1100_isr(): unexpected IFG!"); } __exit_isr(); } diff --git a/board/chronos/drivers/display.c b/board/chronos/drivers/display.c index c0418f544..1473703e4 100644 --- a/board/chronos/drivers/display.c +++ b/board/chronos/drivers/display.c @@ -43,18 +43,15 @@ #include // driver -#include "cc430x613x.h" -#include "display.h" +#include +#include // ************************************************************************************************* // Prototypes section -void write_lcd_mem(uint8_t * lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); +void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); void clear_line(uint8_t line); void display_symbol(uint8_t symbol, uint8_t mode); -void display_char(uint8_t segment, uint8_t chr, uint8_t mode); -void display_chars(uint8_t segments, uint8_t * str, uint8_t mode); - // ************************************************************************************************* // Defines section @@ -285,12 +282,12 @@ uint8_t * itoa(uint32_t n, uint8_t digits, uint8_t blanks) // ************************************************************************************************* void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) { - uint8_t * str; + uint8_t* str; str = itoa(value, digits, blanks); // Display string in blink mode - display_chars(segments, str, disp_mode); + display_chars(segments, (char*) str, disp_mode); } @@ -332,7 +329,7 @@ void display_symbol(uint8_t symbol, uint8_t mode) // uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK // @return none // ************************************************************************************************* -void display_char(uint8_t segment, uint8_t chr, uint8_t mode) +void display_char(uint8_t segment, char chr, uint8_t mode) { uint8_t * lcdmem; // Pointer to LCD memory uint8_t bitmask; // Bitmask for character @@ -393,8 +390,7 @@ void display_char(uint8_t segment, uint8_t chr, uint8_t mode) // uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK // @return none // ************************************************************************************************* -void display_chars(uint8_t segments, uint8_t * str, uint8_t mode) -{ +void display_chars(uint8_t segments, char *str, uint8_t mode) { uint8_t i; uint8_t length = 0; // Write length uint8_t char_start = 0; // Starting point for consecutive write diff --git a/board/chronos/drivers/display.h b/board/chronos/drivers/display.h index 993814ce7..a4fbde92b 100644 --- a/board/chronos/drivers/display.h +++ b/board/chronos/drivers/display.h @@ -337,8 +337,8 @@ void clear_blink_mem(void); void set_blink_rate(uint8_t bits); // Character / symbol draw functions -void display_char(uint8_t segment, uint8_t chr, uint8_t mode); -void display_chars(uint8_t segments, uint8_t * str, uint8_t mode); +void display_char(uint8_t segment, char chr, uint8_t mode); +void display_chars(uint8_t segments, char* str, uint8_t mode); void display_symbol(uint8_t symbol, uint8_t mode); // Time display function diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile index 29cd73df0..17bf86c9b 100644 --- a/board/msb-430-common/Jamfile +++ b/board/msb-430-common/Jamfile @@ -28,7 +28,7 @@ SubDir TOP board msb-430-common ; Module board : board_init.c debug_uart.c ; -Module config : config.c ; +Module board_config : board_config.c ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/board/msb-430-common/config.c b/board/msb-430-common/board_config.c similarity index 55% rename from board/msb-430-common/config.c rename to board/msb-430-common/board_config.c index 3e752592c..f22e513b2 100644 --- a/board/msb-430-common/config.c +++ b/board/msb-430-common/board_config.c @@ -1,8 +1,18 @@ #include +#include #include #include #include +void config_load(void) { + if (*((uint16_t*) INFOMEM) == CONFIG_KEY) { + memcpy(&sysconfig, (char*) (INFOMEM + sizeof(CONFIG_KEY)), sizeof(sysconfig)); + } + else { + config_save(); + } +} + uint8_t config_save(void) { configmem_t mem = { CONFIG_KEY, sysconfig }; return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem))); diff --git a/board/msb-430h/Jamfile b/board/msb-430h/Jamfile index 15f7ba97f..588fede19 100644 --- a/board/msb-430h/Jamfile +++ b/board/msb-430h/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430h ; -Module board_cc1100 : driver_cc1100.c ; +Module board_cc1100 : driver_cc1100.c : cc110x_spi ; SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; diff --git a/board/msb-430h/driver_cc1100.c b/board/msb-430h/driver_cc1100.c index 9575bee6a..1e5af6e9f 100644 --- a/board/msb-430h/driver_cc1100.c +++ b/board/msb-430h/driver_cc1100.c @@ -23,7 +23,7 @@ Boston, MA 02111-1307, USA. */ #include #include -#include +#include #include #define CC1100_GDO0 (P2IN & 0x02) // read serial I/O (GDO0) @@ -340,4 +340,3 @@ puts("cc1100_isr()"); // if (system_state.POWERDOWN != 0) END_LPM3; __exit_isr(); } - diff --git a/cpu/cc430/hwtimer_cc430.c b/cpu/cc430/hwtimer_cc430.c index b5843ca23..64a7a9bb0 100644 --- a/cpu/cc430/hwtimer_cc430.c +++ b/cpu/cc430/hwtimer_cc430.c @@ -4,6 +4,9 @@ #include #include +// #define ENABLE_DEBUG (1) +#include + static uint32_t ticks = 0; extern void (*int_handler)(int); @@ -41,30 +44,13 @@ interrupt(TIMER0_A1_VECTOR) __attribute__ ((naked)) timer0_a1_5_isr(void) { short taiv = TA0IV; short timer; - if (!(taiv & TAIFG)) { -// case TAIFG: - timer = (taiv/2); - TA0_unset(timer); - int_handler(timer); - /* break; - - // Timer0_A3 Configurable periodic IRQ (used by button_repeat and buzzer) - case 0x06: // Disable IE - TA0CCTL3 &= ~CCIE; - // Reset IRQ flag - TA0CCTL3 &= ~CCIFG; - // Enable timer interrupt - TA0CCTL3 |= CCIE; - // Call function handler - // TODO - break; - - // Timer0_A4 One-time delay - case 0x08: // Disable IE - TA0CCTL4 &= ~CCIE; - // Reset IRQ flag - TA0CCTL4 &= ~CCIFG; - break;*/ + if (taiv & TAIFG) { + DEBUG("Overflow\n"); + } + else { + timer = (taiv/2); + TA0_unset(timer); + int_handler(timer); } __exit_isr(); diff --git a/cpu/msp430-common/Jamfile b/cpu/msp430-common/Jamfile index 19e40bb30..540398c72 100644 --- a/cpu/msp430-common/Jamfile +++ b/cpu/msp430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP cpu msp430-common ; -Module cpu : msp430-main.c cpu.c atomic.c irq.c ; +Module cpu : msp430-main.c cpu.c atomic.c irq.c flashrom.c ; Module hwtimer_msp430 : hwtimer_cpu.c ; UseModule cpu ; diff --git a/cpu/msp430-common/flashrom.c b/cpu/msp430-common/flashrom.c index dff02c053..94d2e023f 100644 --- a/cpu/msp430-common/flashrom.c +++ b/cpu/msp430-common/flashrom.c @@ -1,4 +1,6 @@ #include +#include +#include #include #include diff --git a/cpu/msp430-common/hwtimer_cpu.c b/cpu/msp430-common/hwtimer_cpu.c index 3d193c28e..ffb07fc32 100644 --- a/cpu/msp430-common/hwtimer_cpu.c +++ b/cpu/msp430-common/hwtimer_cpu.c @@ -31,7 +31,8 @@ and the mailinglist (subscription via web site) #include #include -#include "debug.h" +// #define ENABLE_DEBUG (1) +#include void (*int_handler)(int); @@ -55,7 +56,7 @@ static void TA0_set_nostart(unsigned long value, short timer) { } static void TA0_set(unsigned long value, short timer) { -// printf("Setting timer %u to %lu\n", timer, value); + DEBUG("Setting timer %u to %lu\n", timer, value); TA0_set_nostart(value, timer); TA0_enable_interrupt(timer); } diff --git a/cpu/msp430-common/include/cpu-conf.h b/cpu/msp430-common/include/cpu-conf.h index 9f9e114f1..cc7cc1efe 100644 --- a/cpu/msp430-common/include/cpu-conf.h +++ b/cpu/msp430-common/include/cpu-conf.h @@ -38,8 +38,8 @@ and the mailinglist (subscription via web site) #define KERNEL_CONF_STACKSIZE_IDLE 64 #define MSP430_ISR_STACK_SIZE 256 -#define RX_BUF_SIZE (4) -#define TRANSCEIVER_BUFFER_SIZE (4) +#define RX_BUF_SIZE (2) +#define TRANSCEIVER_BUFFER_SIZE (2) /** @} */ #endif /* CPUCONF_H_ */ diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index c6497672f..f3c0bc934 100755 --- a/drivers/cc110x_ng/Jamfile +++ b/drivers/cc110x_ng/Jamfile @@ -29,6 +29,6 @@ SubDir TOP drivers cc110x_ng ; HDRS += $(TOP)/drivers/cc110x_ng ; -Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : hwtimer board_cc1100 config ; +Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : hwtimer board_cc1100 ; Module cc110x_spi : cc1100_spi.c ; Module cc110x_cc430 : cc1100_cc430.c ; diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index e16150d29..fd3048d8a 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -23,6 +23,9 @@ cc1100_statistic_t cc1100_statistic; volatile cc1100_flags rflags; ///< Radio control flags volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state +static radio_address_t radio_address; ///< Radio address +static uint8_t radio_channel; ///< Radio channel + int transceiver_pid; ///< the transceiver thread pid /* internal function prototypes */ @@ -66,8 +69,12 @@ void cc1100_init(int tpid) { rflags.WOR_RST = 0; /* Set default channel number */ - cc1100_set_channel(sysconfig.radio_channel); - DEBUG("CC1100 initialized and set to channel %i\n", sysconfig.radio_channel); +#ifdef MODULE_CONFIG + cc1100_set_config_channel(sysconfig.radio_channel); +#else + cc1100_set_channel(CC1100_DEFAULT_CHANNR); +#endif + DEBUG("CC1100 initialized and set to channel %i\n", radio_channel); // Switch to desired mode (WOR or RX) rd_set_mode(RADIO_MODE_ON); @@ -94,7 +101,7 @@ uint8_t cc1100_get_buffer_pos(void) { } radio_address_t cc1100_get_address() { - return sysconfig.radio_address; + return radio_address; } radio_address_t cc1100_set_address(radio_address_t address) { @@ -107,15 +114,20 @@ radio_address_t cc1100_set_address(radio_address_t address) { write_register(CC1100_ADDR, id); } - sysconfig.radio_address = id; - return sysconfig.radio_address; + radio_address = id; + return radio_address; } +#ifdef MODULE_CONFIG radio_address_t cc1100_set_config_address(radio_address_t address) { radio_address_t a = cc1100_set_address(address); + if (a) { + sysconfig.radio_address = a; + } config_save(); return a; } +#endif void cc1100_set_monitor(uint8_t mode) { if (mode) { @@ -213,7 +225,7 @@ char* cc1100_state_to_text(uint8_t state) { void cc1100_print_config(void) { printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); - printf("Current channel number: %u\r\n", sysconfig.radio_channel); + printf("Current channel number: %u\r\n", radio_channel); } void cc1100_switch_to_pwd(void) { @@ -230,18 +242,23 @@ int16_t cc1100_set_channel(uint8_t channr) { return -1; } write_register(CC1100_CHANNR, channr*10); - sysconfig.radio_channel = channr; - return sysconfig.radio_channel; + radio_channel = channr; + return radio_channel; } +#ifdef MODULE_CONFIG int16_t cc1100_set_config_channel(uint8_t channr) { int16_t c = cc1100_set_channel(channr); + if (c) { + sysconfig.radio_channel = c; + } config_save(); return c; } +#endif int16_t cc1100_get_channel(void) { - return sysconfig.radio_channel; + return radio_channel; } diff --git a/projects/chronos_cc110x_ng/Jamfile b/projects/chronos_cc110x_ng/Jamfile new file mode 100644 index 000000000..8085574cb --- /dev/null +++ b/projects/chronos_cc110x_ng/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects chronos_cc110x_ng ; + +Module chronos_cc110x_ng : main.c : cc110x_ng transceiver auto_init board_display ; + +UseModule chronos_cc110x_ng ; diff --git a/projects/chronos_cc110x_ng/main.c b/projects/chronos_cc110x_ng/main.c new file mode 100644 index 000000000..87a9024ce --- /dev/null +++ b/projects/chronos_cc110x_ng/main.c @@ -0,0 +1,103 @@ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define RADIO_STACK_SIZE (1024) +#define SEND_SIZE CC1100_MAX_DATA_LENGTH + +#define SND_BUFFER_SIZE (3) +#define RCV_BUFFER_SIZE (4) + +#define SENDING_DELAY (5 * 1000) + +char radio_stack_buffer[RADIO_STACK_SIZE]; + +uint8_t snd_buffer[SND_BUFFER_SIZE][SEND_SIZE]; + +msg msg_q[RCV_BUFFER_SIZE]; + +static msg mesg; +static transceiver_command_t tcmd; +static radio_packet_t p; + +void sender(char *count); + +void sender(char *count) { + unsigned int c = 3; + unsigned int i; + + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + + p.length = CC1100_MAX_DATA_LENGTH; + p.dst = 0; + + for (i = 0; i < c; i++) { + display_chars(LCD_SEG_L1_3_0, ".....", SEG_OFF); + display_chars(LCD_SEG_L1_3_0, (char*) itoa(i, 1, 0), SEG_ON); + p.data = snd_buffer[i % SND_BUFFER_SIZE]; + msg_send(&mesg, transceiver_pid, 1); + hwtimer_wait(SENDING_DELAY); + } +} + + +void radio(void) { + msg m; + radio_packet_t *p; + + msg_init_queue(msg_q, RCV_BUFFER_SIZE); + + while (1) { + msg_receive(&m); + if (m.type == PKT_PENDING) { + p = (radio_packet_t*) m.content.ptr; + display_chars(LCD_SEG_L2_5_0, (char*) itoa(p->length, 2, 0), SEG_ON); + p->processing--; + } + else if (m.type == ENOBUFFER) { + } + else { + } + } +} + +int main(void) { + int radio_pid; + uint8_t addr = 43; + uint8_t i; + for (i = 0; i < SND_BUFFER_SIZE; i++) { + memset(snd_buffer[i], i, SEND_SIZE); + } + radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); + transceiver_init(TRANSCEIVER_CC1100); + transceiver_start(); + transceiver_register(TRANSCEIVER_CC1100, radio_pid); + + lcd_init(); + clear_display_all(); + mesg.type = SET_ADDRESS; + mesg.content.ptr = (char*) &tcmd; + + display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_ON); + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &addr; + msg_send(&mesg, transceiver_pid, 1); + + sender(NULL); + + while (1) { + } +} diff --git a/projects/chronos_cc110x_ng/tests/hello-world b/projects/chronos_cc110x_ng/tests/hello-world new file mode 100755 index 000000000..acde8265f --- /dev/null +++ b/projects/chronos_cc110x_ng/tests/hello-world @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "Hello World!" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" +