From eb88673aa5af90a695e00162522714d1845abbbd Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 13 Dec 2010 21:19:58 +0100 Subject: [PATCH 01/38] [board/chronos/drivers] * simple buzzer driver --- board/chronos/Jamrules.chronos | 2 ++ board/chronos/drivers/Jamfile | 3 +++ board/chronos/drivers/buzzer.c | 27 +++++++++++++++++++ board/chronos/drivers/include/buzzer.h | 6 +++++ board/chronos/drivers/{ => include}/display.h | 0 5 files changed, 38 insertions(+) create mode 100644 board/chronos/drivers/buzzer.c create mode 100644 board/chronos/drivers/include/buzzer.h rename board/chronos/drivers/{ => include}/display.h (100%) diff --git a/board/chronos/Jamrules.chronos b/board/chronos/Jamrules.chronos index 4c975ae1f9..4c17a9a9ae 100644 --- a/board/chronos/Jamrules.chronos +++ b/board/chronos/Jamrules.chronos @@ -7,6 +7,8 @@ BOARD = chronos ; CPU = cc430 ; MCU = cc430x6137 ; +HDRS += [ FPath $(TOP) board chronos drivers include ] ; + FLASHER ?= mspdebug ; FLASHFLAGS ?= rf2500 ; diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index 4b2a0d0a85..d89390029d 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -1,4 +1,7 @@ SubDir TOP board chronos drivers ; +HDRS += $(TOP)/board/$(CPU)/drivers/include ; + Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; +Module board_buzzer : buzzer.c : hwtimer ; diff --git a/board/chronos/drivers/buzzer.c b/board/chronos/drivers/buzzer.c new file mode 100644 index 0000000000..79002f992c --- /dev/null +++ b/board/chronos/drivers/buzzer.c @@ -0,0 +1,27 @@ +#include +#include +#include + +void buzzer_beep(uint8_t pitch, uint16_t duration) { + // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK + TA1CTL = TACLR | MC_1 | TASSEL__ACLK; + + // Set PWM frequency + TA1CCR0 = pitch; + + // Enable IRQ, set output mode "toggle" + TA1CCTL0 = OUTMOD_4; + + // Allow buzzer PWM output on P2.7 + P2SEL |= BIT7; + + hwtimer_wait(duration); + + // Stop PWM timer + TA1CTL &= ~(BIT4 | BIT5); + + // Reset and disable buzzer PWM output + P2OUT &= ~BIT7; + P2SEL &= ~BIT7; + TA1CCTL0 &= ~CCIE; +} diff --git a/board/chronos/drivers/include/buzzer.h b/board/chronos/drivers/include/buzzer.h new file mode 100644 index 0000000000..1786b0c513 --- /dev/null +++ b/board/chronos/drivers/include/buzzer.h @@ -0,0 +1,6 @@ +#ifndef BUZZER_H +#define BUZZER_H + +void buzzer_beep(uint8_t pitch, uint16_t duration); + +#endif /* BUZZER_H */ diff --git a/board/chronos/drivers/display.h b/board/chronos/drivers/include/display.h similarity index 100% rename from board/chronos/drivers/display.h rename to board/chronos/drivers/include/display.h From 13767043e7c9020ab41f2b8aef06b13e6414bd23 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 14 Dec 2010 00:24:42 +0100 Subject: [PATCH 02/38] [cpu/cc430/gpioint] * introduced gpioint to make buttons usable --- board/chronos/drivers/buzzer.c | 1 + board/chronos/include/buttons.h | 11 + cpu/cc430/Jamfile | 1 + cpu/cc430/cc430-gpioint.c | 270 +++++++++++++++++++++ projects/chronos_default/Jamfile | 5 + projects/chronos_default/main.c | 138 +++++++++++ projects/chronos_default/tests/hello-world | 13 + projects/default/Jamfile | 2 +- 8 files changed, 440 insertions(+), 1 deletion(-) create mode 100644 board/chronos/include/buttons.h create mode 100644 cpu/cc430/cc430-gpioint.c create mode 100644 projects/chronos_default/Jamfile create mode 100644 projects/chronos_default/main.c create mode 100755 projects/chronos_default/tests/hello-world diff --git a/board/chronos/drivers/buzzer.c b/board/chronos/drivers/buzzer.c index 79002f992c..5e0bc2ca34 100644 --- a/board/chronos/drivers/buzzer.c +++ b/board/chronos/drivers/buzzer.c @@ -1,5 +1,6 @@ #include #include +#include #include void buzzer_beep(uint8_t pitch, uint16_t duration) { diff --git a/board/chronos/include/buttons.h b/board/chronos/include/buttons.h new file mode 100644 index 0000000000..4e7ab28dca --- /dev/null +++ b/board/chronos/include/buttons.h @@ -0,0 +1,11 @@ +#ifndef BUTTONS_H +#define BUTTONS_H + +// Button ports +#define BUTTON_STAR_PIN (BIT2) +#define BUTTON_NUM_PIN (BIT1) +#define BUTTON_UP_PIN (BIT4) +#define BUTTON_DOWN_PIN (BIT0) +#define BUTTON_BACKLIGHT_PIN (BIT3) + +#endif diff --git a/cpu/cc430/Jamfile b/cpu/cc430/Jamfile index 1614d4fbce..dafac6212a 100644 --- a/cpu/cc430/Jamfile +++ b/cpu/cc430/Jamfile @@ -29,5 +29,6 @@ SubDir TOP cpu cc430 ; Module hwtimer_cpu : hwtimer_cc430.c : hwtimer_msp430 ; Module rtc : cc430-rtc.c ; +Module gpioint : cc430-gpioint.c ; SubInclude TOP cpu msp430-common ; diff --git a/cpu/cc430/cc430-gpioint.c b/cpu/cc430/cc430-gpioint.c new file mode 100644 index 0000000000..ec21879640 --- /dev/null +++ b/cpu/cc430/cc430-gpioint.c @@ -0,0 +1,270 @@ +/****************************************************************************** +Copyright 2010, Freie Universität Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of µkleos. + +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 3 of the License, or (at your option) any later +version. + +FeuerWare 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, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/** min and max portnumber to generate interrupts */ +#define PORTINT_MIN (1) +#define PORTINT_MAX (2) + +/** amount of interrupt capable ports */ +#define INT_PORTS (2) + +/** number of bits per port */ +#define BITMASK_SIZE (8) + +/** debouncing port interrupts */ +#define DEBOUNCE_TIMEOUT (50) + +/** interrupt callbacks */ +fp_irqcb cb[INT_PORTS][BITMASK_SIZE]; + +static int8_t calc_log2(uint8_t power); + +void gpioint_init(void) { + uint8_t i, j; + for (i = 0; i < INT_PORTS; i++) { + for (j = 0; j < BITMASK_SIZE; j++) { + cb[i][j] = NULL; + } + } +} + +bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { + int8_t base; + + if ((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) { + /* set the callback function */ + base = calc_log2(bitmask); + if (base >= 0) { + cb[port - PORTINT_MIN][calc_log2(bitmask)] = callback; + } + else { + return false; + } + } + + switch (port) { + case 1: + /* set port to input */ + P1DIR &= ~bitmask; + /* enable internal pull-down */ + P1OUT &= ~bitmask; + P1REN |= bitmask; + + /* reset IRQ flag */ + P1IFG &= ~bitmask; + + /* trigger on rising... */ + if (flags == GPIOINT_RISING_EDGE) { + P1IES &= bitmask; + } + /* ...or falling edge */ + else if (flags == GPIOINT_FALLING_EDGE) { + P1IES |= bitmask; + } + /* or disable interrupt */ + else { + P1IE &= ~bitmask; + } + /* enable interrupt */ + P1IE |= bitmask; + break; + case 2: + /* set port to input */ + P2DIR &= ~bitmask; + /* enable internal pull-down */ + P2OUT &= ~bitmask; + P2REN |= bitmask; + + /* reset IRQ flag */ + P2IFG &= ~bitmask; + + /* trigger on rising... */ + if (flags == GPIOINT_RISING_EDGE) { + P2IES &= bitmask; + } + /* ...or falling edge */ + else if (flags == GPIOINT_FALLING_EDGE) { + P2IES |= bitmask; + } + /* or disable interrupt */ + else { + P2IE &= ~bitmask; + } + /* enable interrupt */ + P2IE |= bitmask; + break; + default: + return false; + } + return 1; +} + +static int8_t calc_log2(uint8_t power) { + int8_t i; + for (i = 7; i >= 0; i--) { + if ((power >> i) & 1) { + return i; + } + } + return -1; +} + +interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { + uint8_t int_enable, istate; + uint16_t p1iv; + __enter_isr(); + + /* Debounce + * Disable PORT1 IRQ + */ + p1iv = P1IV; + istate = disableIRQ(); + int_enable = P1IE; + restoreIRQ(istate); + P1IE = 0x00; + hwtimer_wait(DEBOUNCE_TIMEOUT); + + switch (p1iv) { + case P1IV_P1IFG0: + if ((P1IN & P1IV_P1IFG0) & P1IV_P1IFG0) { + cb[0][0](); + } + break; + case P1IV_P1IFG1: + if ((P1IN & P1IV_P1IFG1) & P1IV_P1IFG1) { + cb[0][1](); + } + break; + case P1IV_P1IFG2: + if ((P1IN & P1IV_P1IFG2) & P1IV_P1IFG2) { + cb[0][2](); + } + break; + case P1IV_P1IFG3: + if ((P1IN & P1IV_P1IFG3) & P1IV_P1IFG3) { + cb[0][3](); + } + break; + case P1IV_P1IFG4: + if ((P1IN & P1IV_P1IFG4) & P1IV_P1IFG4) { + cb[0][4](); + } + break; + case P1IV_P1IFG5: + if ((P1IN & P1IV_P1IFG5) & P1IV_P1IFG5) { + cb[0][5](); + } + break; + case P1IV_P1IFG6: + if ((P1IN & P1IV_P1IFG6) & P1IV_P1IFG6) { + cb[0][6](); + } + break; + case P1IV_P1IFG7: + if ((P1IN & P1IV_P1IFG7) & P1IV_P1IFG7) { + cb[0][7](); + } + break; + } + P1IFG = 0x00; + istate = disableIRQ(); + P1IE = int_enable; + restoreIRQ(istate); + __exit_isr(); +} + +interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { + uint8_t int_enable, istate; + uint16_t p2iv; + __enter_isr(); + + /* Debounce + * Disable PORT2 IRQ + */ + p2iv = P2IV; + istate = disableIRQ(); + int_enable = P2IE; + restoreIRQ(istate); + P2IE = 0x00; + hwtimer_wait(DEBOUNCE_TIMEOUT); + + switch (p2iv) { + case P2IV_P2IFG0: + if ((P2IN & P2IV_P2IFG0) & P2IV_P2IFG0) { + cb[1][0](); + } + break; + case P2IV_P2IFG1: + if ((P2IN & P2IV_P2IFG1) & P2IV_P2IFG1) { + cb[1][1](); + } + break; + case P2IV_P2IFG2: + if ((P2IN & P2IV_P2IFG2) & P2IV_P2IFG2) { + cb[1][2](); + } + break; + case P2IV_P2IFG3: + if ((P2IN & P2IV_P2IFG3) & P2IV_P2IFG3) { + cb[1][3](); + } + break; + case P2IV_P2IFG4: + if ((P2IN & P2IV_P2IFG4) & P2IV_P2IFG4) { + cb[1][4](); + } + break; + case P2IV_P2IFG5: + if ((P2IN & P2IV_P2IFG5) & P2IV_P2IFG5) { + cb[1][5](); + } + break; + case P2IV_P2IFG6: + if ((P2IN & P2IV_P2IFG6) & P2IV_P2IFG6) { + cb[1][6](); + } + break; + case P2IV_P2IFG7: + if ((P2IN & P2IV_P2IFG7) & P2IV_P2IFG7) { + cb[1][7](); + } + break; + } + P2IFG = 0x00; + istate = disableIRQ(); + P2IE = int_enable; + restoreIRQ(istate); + __exit_isr(); +} + diff --git a/projects/chronos_default/Jamfile b/projects/chronos_default/Jamfile new file mode 100644 index 0000000000..515f822190 --- /dev/null +++ b/projects/chronos_default/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects chronos_default ; + +Module chronos_default : main.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint ; + +UseModule chronos_default ; diff --git a/projects/chronos_default/main.c b/projects/chronos_default/main.c new file mode 100644 index 0000000000..3894f4ae69 --- /dev/null +++ b/projects/chronos_default/main.c @@ -0,0 +1,138 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define RADIO_STACK_SIZE (512) +#define SEND_SIZE CC1100_MAX_DATA_LENGTH + +#define RCV_BUFFER_SIZE (4) + +#define SENDING_DELAY (5 * 1000) + +char radio_stack_buffer[RADIO_STACK_SIZE]; + +uint8_t snd_buffer[SEND_SIZE]; + +msg msg_q[RCV_BUFFER_SIZE]; + +static msg mesg; +static transceiver_command_t tcmd; +static radio_packet_t p; + +static uint8_t mode = 0; + +void send(radio_address_t dst, uint8_t len, uint8_t *data); + +void send(radio_address_t dst, uint8_t len, uint8_t *data) { + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + + p.length = len; + p.dst = dst; + display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); + display_chars(LCD_SEG_L2_5_0, (char*) itoa(p.dst, 6, 0), SEG_ON); + + p.data = data; + msg_send(&mesg, transceiver_pid, 1); +} + +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, "CC1100", SEG_OFF); + display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON); + send(p->src, p->length, p->data); + + + p->processing--; + } + else if (m.type == ENOBUFFER) { + } + else { + } + } +} + +void change_mode(void) { + buzzer_beep(15, 5000); + if (mode) { + mode = 0; + } + else { + mode = 1; + } +} + +int main(void) { + int radio_pid; + struct tm now; + + now.tm_min = 5; + now.tm_sec = 42; + + rtc_set_localtime(&now); + + now.tm_min = 6; + + rtc_set_alarm(&now, RTC_ALARM_MIN); + + gpioint_set(2, BUTTON_STAR_PIN, GPIOINT_RISING_EDGE, change_mode); + + radio_address_t addr = 43; + memset(snd_buffer, 43, 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); + + send(12, SEND_SIZE, snd_buffer); + + while (1) { + hwtimer_wait(SENDING_DELAY); + rtc_get_localtime(&now); + + switch (mode) { + case 0: + display_chars(LCD_SEG_L1_3_0, (char*) itoa(now.tm_sec, 4, 0), SEG_ON); + break; + case 1: + display_chars(LCD_SEG_L1_3_0, (char*) itoa(now.tm_min, 4, 0), SEG_ON); + break; + } + } +} diff --git a/projects/chronos_default/tests/hello-world b/projects/chronos_default/tests/hello-world new file mode 100755 index 0000000000..acde8265fe --- /dev/null +++ b/projects/chronos_default/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" + diff --git a/projects/default/Jamfile b/projects/default/Jamfile index 1acfc711c9..a428e72118 100644 --- a/projects/default/Jamfile +++ b/projects/default/Jamfile @@ -6,6 +6,6 @@ SubDir TOP projects default ; -Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 cc110x_ng transceiver gpioint auto_init ; +Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 cc110x_ng transceiver gpioint auto_init config ; UseModule default_project ; From ed0e2bc2fa0aa42f181dbb8b02bee02f2aa77bd1 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 11:39:52 +0100 Subject: [PATCH 03/38] * minor file rename --- board/msb-430-common/Jamfile | 2 +- board/msb-430-common/{debug_uart.c => uart1.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename board/msb-430-common/{debug_uart.c => uart1.c} (100%) diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile index 17bf86c9bb..b59f8c4748 100644 --- a/board/msb-430-common/Jamfile +++ b/board/msb-430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430-common ; -Module board : board_init.c debug_uart.c ; +Module board : board_init.c uart1.c ; Module board_config : board_config.c ; UseModule board ; diff --git a/board/msb-430-common/debug_uart.c b/board/msb-430-common/uart1.c similarity index 100% rename from board/msb-430-common/debug_uart.c rename to board/msb-430-common/uart1.c From 99b4dd7314964ee016a595c1c5e45c4646bcdf45 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 16:40:47 +0100 Subject: [PATCH 04/38] * chronos display putchar included --- board/chronos/Jamfile | 2 +- board/chronos/drivers/Jamfile | 2 + board/chronos/drivers/display_putchar.c | 42 ++++++++++++++ .../chronos/drivers/include/display_putchar.h | 6 ++ board/chronos/putchar.c | 11 ++++ board/msb-430-common/putchar.c | 7 +++ projects/hi_earth/Jamfile | 2 +- projects/hi_earth/main.c | 56 +------------------ sys/auto_init.c | 10 ++++ 9 files changed, 82 insertions(+), 56 deletions(-) create mode 100644 board/chronos/drivers/display_putchar.c create mode 100644 board/chronos/drivers/include/display_putchar.h create mode 100644 board/chronos/putchar.c create mode 100644 board/msb-430-common/putchar.c diff --git a/board/chronos/Jamfile b/board/chronos/Jamfile index bf3341d785..0899e4631b 100644 --- a/board/chronos/Jamfile +++ b/board/chronos/Jamfile @@ -2,7 +2,7 @@ SubDir TOP board chronos ; HDRS += $(TOP)/board/$(CPU)/include ; -Module board : debug_uart.c board_init.c ; +Module board : putchar.c board_init.c ; UseModule board ; SubInclude TOP board $(BOARD) drivers ; diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index d89390029d..54d2fb4e7b 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -5,3 +5,5 @@ HDRS += $(TOP)/board/$(CPU)/drivers/include ; Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; + +Module display_putchar : display_putchar.c : board_display ; diff --git a/board/chronos/drivers/display_putchar.c b/board/chronos/drivers/display_putchar.c new file mode 100644 index 0000000000..2f1d9468af --- /dev/null +++ b/board/chronos/drivers/display_putchar.c @@ -0,0 +1,42 @@ +#include +#include +#include + +extern int toupper(int c); +extern void (*_putchar)(int c); + +static char display_buf[11]; + +void putchar_to_display(); + +void init_display_putchar() { + memset(display_buf, '\0', 11); + _putchar = putchar_to_display; +} + +void putchar_to_display(int c) { + if (c == '\n') { + display_buf[4] = 1; + return; + } + + if (display_buf[4]) { + memset(display_buf, '\0', 11); + } else { + display_buf[0] = display_buf[1]; + display_buf[1] = display_buf[2]; + display_buf[2] = display_buf[3]; + display_buf[3] = display_buf[5]; + display_buf[5] = display_buf[6]; + display_buf[6] = display_buf[7]; + display_buf[7] = display_buf[8]; + display_buf[8] = display_buf[9]; + } + + display_buf[9] = toupper(c); + + clear_display_all(); + + display_chars(LCD_SEG_L1_3_0, display_buf, SEG_ON); + display_chars(LCD_SEG_L2_5_0, display_buf+4, SEG_ON); +} diff --git a/board/chronos/drivers/include/display_putchar.h b/board/chronos/drivers/include/display_putchar.h new file mode 100644 index 0000000000..6adbb9c9c0 --- /dev/null +++ b/board/chronos/drivers/include/display_putchar.h @@ -0,0 +1,6 @@ +#ifndef __DISPLAY_PUTCHAR_H +#define __DISPLAY_PUTCHAR_H + +void init_display_putchar(); + +#endif /* __DISPLAY_PUTCHAR_H */ diff --git a/board/chronos/putchar.c b/board/chronos/putchar.c new file mode 100644 index 0000000000..436d350f51 --- /dev/null +++ b/board/chronos/putchar.c @@ -0,0 +1,11 @@ +static void _dummy(int c) { +} + +void (*_putchar)(int c) = _dummy; + +int putchar(int c) +{ + _putchar(c); + return c; +} + diff --git a/board/msb-430-common/putchar.c b/board/msb-430-common/putchar.c new file mode 100644 index 0000000000..4193c0db42 --- /dev/null +++ b/board/msb-430-common/putchar.c @@ -0,0 +1,7 @@ +#include + +void (_putchar(int)) = uart1_putchar; + +void putchar(int c) { + _putchar(c); +} diff --git a/projects/hi_earth/Jamfile b/projects/hi_earth/Jamfile index b59a2a7d33..812f2c9127 100644 --- a/projects/hi_earth/Jamfile +++ b/projects/hi_earth/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects hi_earth ; -Module hi_earth : main.c : board_display hwtimer auto_init ; +Module hi_earth : main.c : auto_init display_putchar ; UseModule hi_earth ; diff --git a/projects/hi_earth/main.c b/projects/hi_earth/main.c index a335d450eb..fa70601b9d 100644 --- a/projects/hi_earth/main.c +++ b/projects/hi_earth/main.c @@ -1,61 +1,9 @@ -//****************************************************************************** -// eZ430 chronos hello world -// Description: initializes lcd module and shows the string 'hi earth' on the -// lcd display becuase 'hello world' is too long -// Author: Felix Genicio -//****************************************************************************** - -#include -#include -#include -#include - -void display1(void); -void display2(void); +#include int main(void) { - lcd_init(); - - clear_display_all(); - - uint8_t i = 0; - uint16_t j; + printf("Hi Earth\n"); while(1) { - if (i) { - i = 0; - display1(); - } - else { - i = 1; - display2(); - } - for (j = 1; j < 10; j++) { - hwtimer_wait(3333); - } - display_symbol(5, SEG_ON); -/* - for (j = 1; j != 0; j++) { - if (i) { - display_symbol(LCD_ICON_BEEPER1, SEG_ON); - } - else { - display_symbol(5, SEG_OFF); - } - } -*/ } } - -void display1(void) { - display_chars(LCD_SEG_L1_3_0, "HI", SEG_ON); - display_chars(LCD_SEG_L2_5_0, " EARTH", SEG_OFF); -} - -void display2(void) { - display_chars(LCD_SEG_L1_3_0, "HI", SEG_OFF); - display_chars(LCD_SEG_L2_5_0, (char*) itoa(TA0R, 6, 0), SEG_ON); -// display_chars(LCD_SEG_L2_5_0, (uint8_t*) " EARTH", SEG_ON); -} - diff --git a/sys/auto_init.c b/sys/auto_init.c index 2dc5338b9b..071ad1836c 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #define ENABLE_DEBUG @@ -10,6 +12,14 @@ extern void main(void); void auto_init(void) { +#ifdef MODULE_BOARD_DISPLAY + lcd_init(); + DEBUG("DISP OK"); +#endif +#ifdef MODULE_DISPLAY_PUTCHAR + init_display_putchar(); + DEBUG("DISP OK"); +#endif #ifdef MODULE_HWTIMER DEBUG("Auto init hwtimer module.\n"); hwtimer_init(); From 3b99c3955e0ba2f8ed4f2b490dcb2909f6be7310 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 16:41:06 +0100 Subject: [PATCH 05/38] file obsoleted --- board/chronos/debug_uart.c | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 board/chronos/debug_uart.c diff --git a/board/chronos/debug_uart.c b/board/chronos/debug_uart.c deleted file mode 100644 index d80c9c6e83..0000000000 --- a/board/chronos/debug_uart.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include "board.h" - -#define UART1_TX TXBUF1 -#define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); } - - -int putchar(int c) -{ -// UART1_TX = c; -// UART1_WAIT_TXDONE(); -// -// if (c == 10) { -// UART1_TX = 13; -// UART1_WAIT_TXDONE(); -// } - - return c; -} - - From 33b68f374468d93e3235ce45a68e48512a52e44b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 14 Dec 2010 16:44:32 +0100 Subject: [PATCH 06/38] * moved flashrom from msp430-common to msb430x16x --- board/msb-430-common/Jamfile | 2 +- cpu/msp430x16x/flashrom.c | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 cpu/msp430x16x/flashrom.c diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile index 17bf86c9bb..147e49ea23 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 board_config : board_config.c ; +Module board_config : board_config.c : flashrom ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/cpu/msp430x16x/flashrom.c b/cpu/msp430x16x/flashrom.c new file mode 100644 index 0000000000..686e0cc3dd --- /dev/null +++ b/cpu/msp430x16x/flashrom.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include + +uint8_t ie1, ie2; + +static uint8_t prepare(void); +static void finish(uint8_t istate); +static inline void busy_wait(void); + +/*---------------------------------------------------------------------------*/ +uint8_t flashrom_erase(uint8_t *addr) { + uint8_t istate = prepare(); + + FCTL3 = FWKEY; /* Lock = 0 */ + busy_wait(); + FCTL1 = FWKEY | ERASE; + *addr = 0; /* erase Flash segment */ + busy_wait(); + FCTL1 = FWKEY; /* ERASE = 0 */ + FCTL3 = FWKEY | LOCK; + finish(istate); + return 1; +} + +void flashrom_write(uint8_t *dst, uint8_t *src, size_t size) { + unsigned int i; + FCTL3 = FWKEY; /* Lock = 0 */ + busy_wait(); + for (i = size; i > 0; i--) { + FCTL1 = FWKEY | WRT; + *dst = *src; /* program Flash word */ + while (!(FCTL3 & WAIT)) { + nop(); + } + } + busy_wait(); + FCTL1 = FWKEY; /* WRT = 0 */ + FCTL3 = FWKEY | LOCK; /* Lock = 1 */ +} + +/*---------------------------------------------------------------------------*/ +static uint8_t prepare(void) { + uint8_t istate; + + /* Disable all interrupts. */ + + /* Clear interrupt flag1. */ + IFG1 = 0; + + /* DCO(SMCLK) is 2,4576MHz, /6 = 409600 Hz + select SMCLK for flash timing, divider 4+1 */ + FCTL2 = FWKEY | FSSEL_3 | FN2 | FN0; + + /* disable all interrupts to protect CPU + during programming from system crash */ + istate = disableIRQ(); + + /* disable all NMI-Interrupt sources */ + ie1 = IE1; + ie2 = IE2; + IE1 = 0x00; + IE2 = 0x00; + return istate; +} +/*---------------------------------------------------------------------------*/ +void finish(uint8_t istate) { + /* Enable interrupts. */ + IE1 = ie1; + IE2 = ie2; + restoreIRQ(istate); +} + +static inline void busy_wait(void) { + /* Wait for BUSY = 0, not needed unless run from RAM */ + while(FCTL3 & 0x0001) { + nop(); + } +} From 3c343560e9b9ad1504fd77d9fffa3e30cad0aa22 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 15 Dec 2010 12:43:15 +0100 Subject: [PATCH 07/38] * fix auto init --- sys/auto_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/auto_init.c b/sys/auto_init.c index 071ad1836c..e9e7a4d486 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -2,8 +2,6 @@ #include #include #include -#include -#include #include #define ENABLE_DEBUG @@ -13,10 +11,12 @@ extern void main(void); void auto_init(void) { #ifdef MODULE_BOARD_DISPLAY + extern void lcd_init(); lcd_init(); DEBUG("DISP OK"); #endif #ifdef MODULE_DISPLAY_PUTCHAR + extern void init_display_putchar(); init_display_putchar(); DEBUG("DISP OK"); #endif From d499b5d2c8ca972c8c95c415ac83153f366cff6f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 15 Dec 2010 15:48:50 +0100 Subject: [PATCH 08/38] [cpu/cc430/ drivers/gpioint] * refactored port interrupt handling --- cpu/cc430/cc430-gpioint.c | 149 +++++++++--------------------- cpu/msp430-common/Jamfile | 2 +- cpu/msp430x16x/Jamfile | 1 + drivers/include/gpioint.h | 1 + projects/chronos_cc110x_ng/main.c | 14 +-- projects/chronos_default/Jamfile | 2 +- projects/chronos_default/main.c | 18 ++-- 7 files changed, 63 insertions(+), 124 deletions(-) diff --git a/cpu/cc430/cc430-gpioint.c b/cpu/cc430/cc430-gpioint.c index ec21879640..bceb3587b1 100644 --- a/cpu/cc430/cc430-gpioint.c +++ b/cpu/cc430/cc430-gpioint.c @@ -27,6 +27,7 @@ and the mailinglist (subscription via web site) #include #include #include +#include #include #include #include @@ -48,13 +49,18 @@ and the mailinglist (subscription via web site) /** interrupt callbacks */ fp_irqcb cb[INT_PORTS][BITMASK_SIZE]; -static int8_t calc_log2(uint8_t power); +/** debounce interrupt flags */ +uint8_t debounce_flags[INT_PORTS]; + +/** debounce interrupt times */ +uint16_t debounce_time[INT_PORTS][BITMASK_SIZE]; void gpioint_init(void) { uint8_t i, j; for (i = 0; i < INT_PORTS; i++) { for (j = 0; j < BITMASK_SIZE; j++) { cb[i][j] = NULL; + debounce_time[i][j] = 0; } } } @@ -64,13 +70,19 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { if ((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) { /* set the callback function */ - base = calc_log2(bitmask); + base = number_of_highest_bit(bitmask); if (base >= 0) { - cb[port - PORTINT_MIN][calc_log2(bitmask)] = callback; + cb[port - PORTINT_MIN][base] = callback; } else { return false; } + if (flags & GPIOINT_DEBOUNCE) { + debounce_flags[port - PORTINT_MIN] |= bitmask; + } + else { + debounce_flags[port - PORTINT_MIN] &= ~bitmask; + } } switch (port) { @@ -85,15 +97,16 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { P1IFG &= ~bitmask; /* trigger on rising... */ - if (flags == GPIOINT_RISING_EDGE) { + if (flags & GPIOINT_RISING_EDGE) { P1IES &= bitmask; } /* ...or falling edge */ - else if (flags == GPIOINT_FALLING_EDGE) { + if (flags & GPIOINT_FALLING_EDGE) { P1IES |= bitmask; } - /* or disable interrupt */ - else { + + /* disable interrupt */ + if (flags == GPIOINT_DISABLE) { P1IE &= ~bitmask; } /* enable interrupt */ @@ -130,18 +143,8 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { return 1; } -static int8_t calc_log2(uint8_t power) { - int8_t i; - for (i = 7; i >= 0; i--) { - if ((power >> i) & 1) { - return i; - } - } - return -1; -} - interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { - uint8_t int_enable, istate; + uint8_t int_enable, istate, ifg_num; uint16_t p1iv; __enter_isr(); @@ -153,50 +156,20 @@ interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { int_enable = P1IE; restoreIRQ(istate); P1IE = 0x00; - hwtimer_wait(DEBOUNCE_TIMEOUT); - switch (p1iv) { - case P1IV_P1IFG0: - if ((P1IN & P1IV_P1IFG0) & P1IV_P1IFG0) { - cb[0][0](); - } - break; - case P1IV_P1IFG1: - if ((P1IN & P1IV_P1IFG1) & P1IV_P1IFG1) { - cb[0][1](); - } - break; - case P1IV_P1IFG2: - if ((P1IN & P1IV_P1IFG2) & P1IV_P1IFG2) { - cb[0][2](); - } - break; - case P1IV_P1IFG3: - if ((P1IN & P1IV_P1IFG3) & P1IV_P1IFG3) { - cb[0][3](); - } - break; - case P1IV_P1IFG4: - if ((P1IN & P1IV_P1IFG4) & P1IV_P1IFG4) { - cb[0][4](); - } - break; - case P1IV_P1IFG5: - if ((P1IN & P1IV_P1IFG5) & P1IV_P1IFG5) { - cb[0][5](); - } - break; - case P1IV_P1IFG6: - if ((P1IN & P1IV_P1IFG6) & P1IV_P1IFG6) { - cb[0][6](); - } - break; - case P1IV_P1IFG7: - if ((P1IN & P1IV_P1IFG7) & P1IV_P1IFG7) { - cb[0][7](); - } - break; + /* check interrupt source */ + if (debounce_flags[0] & P1IFG) { + ifg_num = (p1iv >> 1) - 1; + /* check if bouncing */ + if ((hwtimer_now() - debounce_time[0][ifg_num]) > DEBOUNCE_TIMEOUT) { + debounce_time[0][ifg_num] = hwtimer_now(); + cb[0][ifg_num](); + } + else { + /* TODO: check for long duration irq */ + } } + P1IFG = 0x00; istate = disableIRQ(); P1IE = int_enable; @@ -205,7 +178,7 @@ interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { } interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { - uint8_t int_enable, istate; + uint8_t int_enable, istate, ifg_num; uint16_t p2iv; __enter_isr(); @@ -217,50 +190,20 @@ interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { int_enable = P2IE; restoreIRQ(istate); P2IE = 0x00; - hwtimer_wait(DEBOUNCE_TIMEOUT); - switch (p2iv) { - case P2IV_P2IFG0: - if ((P2IN & P2IV_P2IFG0) & P2IV_P2IFG0) { - cb[1][0](); - } - break; - case P2IV_P2IFG1: - if ((P2IN & P2IV_P2IFG1) & P2IV_P2IFG1) { - cb[1][1](); - } - break; - case P2IV_P2IFG2: - if ((P2IN & P2IV_P2IFG2) & P2IV_P2IFG2) { - cb[1][2](); - } - break; - case P2IV_P2IFG3: - if ((P2IN & P2IV_P2IFG3) & P2IV_P2IFG3) { - cb[1][3](); - } - break; - case P2IV_P2IFG4: - if ((P2IN & P2IV_P2IFG4) & P2IV_P2IFG4) { - cb[1][4](); - } - break; - case P2IV_P2IFG5: - if ((P2IN & P2IV_P2IFG5) & P2IV_P2IFG5) { - cb[1][5](); - } - break; - case P2IV_P2IFG6: - if ((P2IN & P2IV_P2IFG6) & P2IV_P2IFG6) { - cb[1][6](); - } - break; - case P2IV_P2IFG7: - if ((P2IN & P2IV_P2IFG7) & P2IV_P2IFG7) { - cb[1][7](); - } - break; + /* check interrupt source */ + if (debounce_flags[1] & P1IFG) { + ifg_num = (p2iv >> 1) - 1; + /* check if bouncing */ + if ((hwtimer_now() - debounce_time[1][ifg_num]) > DEBOUNCE_TIMEOUT) { + debounce_time[1][ifg_num] = hwtimer_now(); + cb[1][ifg_num](); + } + else { + /* TODO: check for long duration irq */ + } } + P2IFG = 0x00; istate = disableIRQ(); P2IE = int_enable; diff --git a/cpu/msp430-common/Jamfile b/cpu/msp430-common/Jamfile index 540398c723..19e40bb30f 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 flashrom.c ; +Module cpu : msp430-main.c cpu.c atomic.c irq.c ; Module hwtimer_msp430 : hwtimer_cpu.c ; UseModule cpu ; diff --git a/cpu/msp430x16x/Jamfile b/cpu/msp430x16x/Jamfile index a110170676..14aa4df136 100644 --- a/cpu/msp430x16x/Jamfile +++ b/cpu/msp430x16x/Jamfile @@ -27,6 +27,7 @@ SubDir TOP cpu msp430x16x ; +Module flashrom : flashrom.c ; Module hwtimer_cpu : hwtimer_msp430.c : hwtimer_msp430 ; SubInclude TOP cpu msp430-common ; diff --git a/drivers/include/gpioint.h b/drivers/include/gpioint.h index 66cf138a65..8d5d30f1e4 100644 --- a/drivers/include/gpioint.h +++ b/drivers/include/gpioint.h @@ -68,6 +68,7 @@ and the mailinglist (subscription via web site) #define GPIOINT_DISABLE 0x00 #define GPIOINT_RISING_EDGE 0x01 ///< interrupt is generated on rising edge #define GPIOINT_FALLING_EDGE 0x02 ///< interrupt is generated on falling edge +#define GPIOINT_DEBOUNCE 0x04 ///< debounce this interrupt /** * @brief GPIO IRQ callback function type diff --git a/projects/chronos_cc110x_ng/main.c b/projects/chronos_cc110x_ng/main.c index b259b07334..4e14c50d1a 100644 --- a/projects/chronos_cc110x_ng/main.c +++ b/projects/chronos_cc110x_ng/main.c @@ -1,12 +1,12 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -56,12 +56,12 @@ void radio(void) { while (1) { msg_receive(&m); if (m.type == PKT_PENDING) { + p = (radio_packet_t*) m.content.ptr; display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON); send(p->src, p->length, p->data); - hwtimer_wait(50000); - send(p->src, sizeof(p->length), &(p->length)); + p->processing--; } @@ -74,6 +74,7 @@ void radio(void) { int main(void) { int radio_pid; + radio_address_t addr = 43; memset(snd_buffer, 43, SEND_SIZE); radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); @@ -91,11 +92,10 @@ int main(void) { tcmd.data = &addr; msg_send(&mesg, transceiver_pid, 1); - send(12, SEND_SIZE, snd_buffer); + send(0, SEND_SIZE, snd_buffer); while (1) { - hwtimer_wait(SENDING_DELAY); - display_chars(LCD_SEG_L1_3_0, ".....", SEG_OFF); - display_chars(LCD_SEG_L1_3_0, (char*) itoa(TA0R, 6, 0), SEG_ON); + hwtimer_wait(SENDING_DELAY); + display_chars(LCD_SEG_L1_3_0, itoa(hwtimer_now(), 4, 0), SEG_ON); } } diff --git a/projects/chronos_default/Jamfile b/projects/chronos_default/Jamfile index 515f822190..0198f8ae66 100644 --- a/projects/chronos_default/Jamfile +++ b/projects/chronos_default/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects chronos_default ; -Module chronos_default : main.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint ; +Module chronos_default : main.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint display_putchar ; UseModule chronos_default ; diff --git a/projects/chronos_default/main.c b/projects/chronos_default/main.c index 3894f4ae69..f521910d7f 100644 --- a/projects/chronos_default/main.c +++ b/projects/chronos_default/main.c @@ -46,8 +46,6 @@ void send(radio_address_t dst, uint8_t len, uint8_t *data) { p.length = len; p.dst = dst; - display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); - display_chars(LCD_SEG_L2_5_0, (char*) itoa(p.dst, 6, 0), SEG_ON); p.data = data; msg_send(&mesg, transceiver_pid, 1); @@ -64,10 +62,7 @@ void radio(void) { if (m.type == PKT_PENDING) { p = (radio_packet_t*) m.content.ptr; - display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); - display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON); send(p->src, p->length, p->data); - p->processing--; } @@ -92,7 +87,8 @@ int main(void) { int radio_pid; struct tm now; - now.tm_min = 5; + now.tm_hour = 3; + now.tm_min = 59; now.tm_sec = 42; rtc_set_localtime(&now); @@ -101,7 +97,7 @@ int main(void) { rtc_set_alarm(&now, RTC_ALARM_MIN); - gpioint_set(2, BUTTON_STAR_PIN, GPIOINT_RISING_EDGE, change_mode); + gpioint_set(2, BUTTON_STAR_PIN, (GPIOINT_RISING_EDGE | GPIOINT_DEBOUNCE), change_mode); radio_address_t addr = 43; memset(snd_buffer, 43, SEND_SIZE); @@ -110,12 +106,10 @@ int main(void) { 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); + printf("CC430"); tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &addr; msg_send(&mesg, transceiver_pid, 1); @@ -128,10 +122,10 @@ int main(void) { switch (mode) { case 0: - display_chars(LCD_SEG_L1_3_0, (char*) itoa(now.tm_sec, 4, 0), SEG_ON); + printf("\n%02u:%02u", now.tm_hour, now.tm_min); break; case 1: - display_chars(LCD_SEG_L1_3_0, (char*) itoa(now.tm_min, 4, 0), SEG_ON); + printf("\n%02u", now.tm_sec); break; } } From 08295b04ca61cb320df4f927a6267b1c05da385a Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 16 Dec 2010 17:11:23 +0100 Subject: [PATCH 09/38] [cpu/cc430] * fixed some bugs in gpioint --- cpu/cc430/cc430-gpioint.c | 40 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/cpu/cc430/cc430-gpioint.c b/cpu/cc430/cc430-gpioint.c index bceb3587b1..585c78e601 100644 --- a/cpu/cc430/cc430-gpioint.c +++ b/cpu/cc430/cc430-gpioint.c @@ -44,7 +44,7 @@ and the mailinglist (subscription via web site) #define BITMASK_SIZE (8) /** debouncing port interrupts */ -#define DEBOUNCE_TIMEOUT (50) +#define DEBOUNCE_TIMEOUT (150) /** interrupt callbacks */ fp_irqcb cb[INT_PORTS][BITMASK_SIZE]; @@ -55,6 +55,8 @@ uint8_t debounce_flags[INT_PORTS]; /** debounce interrupt times */ uint16_t debounce_time[INT_PORTS][BITMASK_SIZE]; +uint16_t c1 = 0, c2 = 0; + void gpioint_init(void) { uint8_t i, j; for (i = 0; i < INT_PORTS; i++) { @@ -144,7 +146,7 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { } interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { - uint8_t int_enable, istate, ifg_num; + uint8_t int_enable, ifg_num; uint16_t p1iv; __enter_isr(); @@ -152,14 +154,12 @@ interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { * Disable PORT1 IRQ */ p1iv = P1IV; - istate = disableIRQ(); int_enable = P1IE; - restoreIRQ(istate); P1IE = 0x00; + ifg_num = (p1iv >> 1) - 1; /* check interrupt source */ if (debounce_flags[0] & P1IFG) { - ifg_num = (p1iv >> 1) - 1; /* check if bouncing */ if ((hwtimer_now() - debounce_time[0][ifg_num]) > DEBOUNCE_TIMEOUT) { debounce_time[0][ifg_num] = hwtimer_now(); @@ -169,45 +169,53 @@ interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { /* TODO: check for long duration irq */ } } + else { + cb[0][ifg_num](); + } P1IFG = 0x00; - istate = disableIRQ(); P1IE = int_enable; - restoreIRQ(istate); __exit_isr(); } interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { - uint8_t int_enable, istate, ifg_num; + uint8_t int_enable, ifg_num, p2ifg; uint16_t p2iv; + uint16_t diff; __enter_isr(); /* Debounce * Disable PORT2 IRQ */ + p2ifg = P2IFG; p2iv = P2IV; - istate = disableIRQ(); int_enable = P2IE; - restoreIRQ(istate); P2IE = 0x00; + ifg_num = (p2iv >> 1) - 1; /* check interrupt source */ - if (debounce_flags[1] & P1IFG) { - ifg_num = (p2iv >> 1) - 1; + if (debounce_flags[1] & p2ifg) { /* check if bouncing */ - if ((hwtimer_now() - debounce_time[1][ifg_num]) > DEBOUNCE_TIMEOUT) { + diff = hwtimer_now() - debounce_time[1][ifg_num]; + if (diff > DEBOUNCE_TIMEOUT) { debounce_time[1][ifg_num] = hwtimer_now(); - cb[1][ifg_num](); + c1++; + if (cb[1][ifg_num] != NULL) { + cb[1][ifg_num](); + } } else { + c2++; /* TODO: check for long duration irq */ + asm volatile (" nop "); } } + else { + cb[1][ifg_num](); + } P2IFG = 0x00; - istate = disableIRQ(); P2IE = int_enable; - restoreIRQ(istate); __exit_isr(); } From b416fef56b7acff959110f78e74ce5ccf8a8fb5b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 16 Dec 2010 18:09:40 +0100 Subject: [PATCH 10/38] [cpu/cc430] * fixed debouncing for gpioint --- cpu/cc430/cc430-gpioint.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/cpu/cc430/cc430-gpioint.c b/cpu/cc430/cc430-gpioint.c index 585c78e601..460d2a4879 100644 --- a/cpu/cc430/cc430-gpioint.c +++ b/cpu/cc430/cc430-gpioint.c @@ -44,7 +44,7 @@ and the mailinglist (subscription via web site) #define BITMASK_SIZE (8) /** debouncing port interrupts */ -#define DEBOUNCE_TIMEOUT (150) +#define DEBOUNCE_TIMEOUT (250) /** interrupt callbacks */ fp_irqcb cb[INT_PORTS][BITMASK_SIZE]; @@ -146,33 +146,41 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { } interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { - uint8_t int_enable, ifg_num; + uint8_t int_enable, ifg_num, p1ifg; uint16_t p1iv; + uint16_t diff; __enter_isr(); /* Debounce * Disable PORT1 IRQ */ + p1ifg = P1IFG; p1iv = P1IV; int_enable = P1IE; P1IE = 0x00; ifg_num = (p1iv >> 1) - 1; /* check interrupt source */ - if (debounce_flags[0] & P1IFG) { + if (debounce_flags[0] & p1ifg) { /* check if bouncing */ - if ((hwtimer_now() - debounce_time[0][ifg_num]) > DEBOUNCE_TIMEOUT) { + diff = hwtimer_now() - debounce_time[0][ifg_num]; + if (diff > DEBOUNCE_TIMEOUT) { debounce_time[0][ifg_num] = hwtimer_now(); - cb[0][ifg_num](); + if (cb[0][ifg_num] != NULL) { + cb[0][ifg_num](); + } } else { /* TODO: check for long duration irq */ + asm volatile (" nop "); } } else { - cb[0][ifg_num](); + if (cb[0][ifg_num] != NULL) { + cb[0][ifg_num](); + } } - + P1IFG = 0x00; P1IE = int_enable; __exit_isr(); @@ -211,7 +219,9 @@ interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { } } else { - cb[1][ifg_num](); + if (cb[1][ifg_num] != NULL) { + cb[1][ifg_num](); + } } P2IFG = 0x00; From 9e58c8bcb7aa4c7c8a84368c0f7be5448c122fbb Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 16 Dec 2010 18:21:24 +0100 Subject: [PATCH 11/38] *watch: chronos watch application initial checkin --- cpu/cc430/cc430-rtc.c | 35 ++++++++++---- drivers/include/rtc.h | 4 ++ projects/watch/Jamfile | 5 ++ projects/watch/alarm_app.c | 62 ++++++++++++++++++++++++ projects/watch/alarm_app.h | 6 +++ projects/watch/clock_app.c | 58 ++++++++++++++++++++++ projects/watch/clock_app.h | 7 +++ projects/watch/main.c | 83 ++++++++++++++++++++++++++++++++ projects/watch/tests/hello-world | 13 +++++ projects/watch/watch.h | 9 ++++ 10 files changed, 272 insertions(+), 10 deletions(-) create mode 100644 projects/watch/Jamfile create mode 100644 projects/watch/alarm_app.c create mode 100644 projects/watch/alarm_app.h create mode 100644 projects/watch/clock_app.c create mode 100644 projects/watch/clock_app.h create mode 100644 projects/watch/main.c create mode 100755 projects/watch/tests/hello-world create mode 100644 projects/watch/watch.h diff --git a/cpu/cc430/cc430-rtc.c b/cpu/cc430/cc430-rtc.c index 3ef3d7c279..8895e05996 100644 --- a/cpu/cc430/cc430-rtc.c +++ b/cpu/cc430/cc430-rtc.c @@ -33,11 +33,16 @@ and the mailinglist (subscription via web site) //static volatile time_t epoch; static struct tm time_to_set; +static int set_time = 0; +int rtc_second_pid = 0; /*---------------------------------------------------------------------------*/ void rtc_init(void) { /* Set to calendar mode */ RTCCTL1 |= RTCMODE_H; + + /* enable ready interrupt (every second) */ + RTCCTL0 |= RTCRDYIE; } /*---------------------------------------------------------------------------*/ @@ -59,7 +64,8 @@ void rtc_set_localtime(struct tm* localt) { /* copy time to be set */ memcpy(&time_to_set, localt, sizeof(struct tm)); /* set interrupt to set this time after the next transition */ - RTCCTL0 |= RTCRDYIE; +// RTCCTL0 |= RTCRDYIE; + set_time = 1; } /*--------------------------------------------------------------------------- @@ -166,16 +172,25 @@ interrupt(RTC_VECTOR) __attribute__ ((naked)) rtc_isr(void) { /* RTC is save to write for up to one second now */ if (RTCIV == RTC_RTCRDYIFG) { /* disable interrupt */ - RTCCTL0 &= ~RTCRDYIE; + //RTCCTL0 &= ~RTCRDYIE; + + if (set_time) { + set_time = 0; /* set previous set time and reset it */ - RTCSEC = time_to_set.tm_sec; - RTCMIN = time_to_set.tm_min; - RTCHOUR = time_to_set.tm_hour; - RTCDAY = time_to_set.tm_mday; - RTCDOW = time_to_set.tm_wday; - RTCMON = time_to_set.tm_mon + 1; - RTCYEARL = (time_to_set.tm_year + 1900) & 0xFF; - RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08; + RTCSEC = time_to_set.tm_sec; + RTCMIN = time_to_set.tm_min; + RTCHOUR = time_to_set.tm_hour; + RTCDAY = time_to_set.tm_mday; + RTCDOW = time_to_set.tm_wday; + RTCMON = time_to_set.tm_mon + 1; + RTCYEARL = (time_to_set.tm_year + 1900) & 0xFF; + RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08; + } + if (rtc_second_pid) { + msg m; + m.type = RTC_SECOND; + msg_send_int(&m, rtc_second_pid); + } } /* RTC alarm */ else if (RTCIV == RTC_RTCAIFG) { diff --git a/drivers/include/rtc.h b/drivers/include/rtc.h index d36382cfd2..b40b72b503 100644 --- a/drivers/include/rtc.h +++ b/drivers/include/rtc.h @@ -27,6 +27,8 @@ and the mailinglist (subscription via web site) #ifndef RTC_H #define RTC_H +#define RTC_SECOND 10001U + #include /** @@ -56,4 +58,6 @@ void rtc_set_localtime(struct tm* localt); */ void rtc_get_localtime(struct tm* localt); +extern int rtc_second_pid; + #endif diff --git a/projects/watch/Jamfile b/projects/watch/Jamfile new file mode 100644 index 0000000000..d3484567e3 --- /dev/null +++ b/projects/watch/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects watch ; + +Module watch : main.c clock_app.c alarm_app.c : uart0 posix_io rtc display_putchar gpioint hwtimer board_buzzer auto_init ; + +UseModule watch ; diff --git a/projects/watch/alarm_app.c b/projects/watch/alarm_app.c new file mode 100644 index 0000000000..7a9f206bb7 --- /dev/null +++ b/projects/watch/alarm_app.c @@ -0,0 +1,62 @@ +#include +#include + +#include +#include +#include +#include + +#include "alarm_app.h" +#include "clock_app.h" +#include "watch.h" + +static char alarm_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; + +static void alarm_thread(void) { + msg m; + + struct tm time; + + time.tm_sec = 1; + time.tm_min = 2; + time.tm_hour = 3; + + int active = 0; + + while(1) { + msg_receive(&m); + switch (m.type) { + case MSG_ACTIVATE: + { + time_print(&time); + if (active) { + } else { + } + break; + } + case MSG_DEACTIVATE: + { + break; + } + case MSG_BUTTON_HASH: + { + if (active) { + active = 0; + display_symbol(LCD_ICON_ALARM, SEG_OFF); + } else { + active = 1; + display_symbol(LCD_ICON_ALARM, SEG_ON); + } + break; + } + default: + { + printf("def alarm\n"); + } + } + } +} + +int alarm_app_init() { + return thread_create(alarm_stack, sizeof(alarm_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, alarm_thread, "alarm"); +} diff --git a/projects/watch/alarm_app.h b/projects/watch/alarm_app.h new file mode 100644 index 0000000000..569be69b02 --- /dev/null +++ b/projects/watch/alarm_app.h @@ -0,0 +1,6 @@ +#ifndef __ALARM_APP_H +#define __ALARM_APP_H + +int alarm_app_init(); + +#endif /* __ALARM_APP_H */ diff --git a/projects/watch/clock_app.c b/projects/watch/clock_app.c new file mode 100644 index 0000000000..761ebe17fc --- /dev/null +++ b/projects/watch/clock_app.c @@ -0,0 +1,58 @@ +#include +#include + +#include +#include +#include + +#include "clock_app.h" +#include "watch.h" + +void time_print(struct tm *time) { + printf("%02i %02i%02i\n", time->tm_sec, time->tm_hour, time->tm_min); +} + +static char clock_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; + +static void clock_thread(void) { + msg m; + + int active = 0; + rtc_second_pid = thread_getpid(); + + while(1) { + msg_receive(&m); + switch (m.type) { + case RTC_SECOND: + { + if (! active) break; + } + case MSG_ACTIVATE: + { + active = 1; + struct tm now; + rtc_get_localtime(&now); + time_print(&now); + break; + } + case MSG_DEACTIVATE: + { + active = 0; + break; + } + case MSG_BUTTON_HASH: + { + printf("hashclock\n"); + break; + } + default: + { + printf("def clock\n"); + } + } + } +} + +int clock_app_init() { + return thread_create(clock_stack, sizeof(clock_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, clock_thread, "clock"); +} diff --git a/projects/watch/clock_app.h b/projects/watch/clock_app.h new file mode 100644 index 0000000000..084f588668 --- /dev/null +++ b/projects/watch/clock_app.h @@ -0,0 +1,7 @@ +#ifndef __CLOCK_APP_H +#define __CLOCK_APP_H + +int clock_app_init(); +void time_print(struct tm *time); + +#endif /* __CLOCK_APP_H */ diff --git a/projects/watch/main.c b/projects/watch/main.c new file mode 100644 index 0000000000..e67dbe6018 --- /dev/null +++ b/projects/watch/main.c @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "watch.h" +#include "alarm_app.h" +#include "clock_app.h" + +#define NUM_APPS 2 +int napps = NUM_APPS; +int apps[NUM_APPS]; + +int button_thread = 0; +void button_star(void) { + msg m; + + if (button_thread) { + m.type = MSG_BUTTON_STAR; + msg_send(&m, button_thread, false); + } +} + +int main(void) +{ + memset(apps, '\0', sizeof(apps)); + apps[0] = clock_app_init(); + apps[1] = alarm_app_init(); + + gpioint_set(2, BUTTON_STAR_PIN, (GPIOINT_RISING_EDGE | GPIOINT_DEBOUNCE), button_star); + button_thread = thread_getpid(); + + int active_app = 0; + + msg m; + + //buzzer_beep(15, 5000); + + printf("ukleos\n"); + + m.type = MSG_ACTIVATE; + msg_send(&m, apps[active_app], true); + + while(1) { + msg_receive(&m); + + switch (m.type) { + case MSG_BUTTON_STAR: { + m.type = MSG_DEACTIVATE; + msg_send(&m, apps[active_app], true); + + active_app++; + + if (active_app == (NUM_APPS)) active_app = 0; + + m.type = MSG_ACTIVATE; + msg_send(&m, apps[active_app], true); + + // buzzer_beep(15, 5000); + + break; + } + case MSG_BUTTON_HASH: + { + m.type = MSG_BUTTON_HASH; + msg_send(&m, apps[active_app], true); + break; + } + default: + { + printf("msg\n"); + } + } + } +} diff --git a/projects/watch/tests/hello-world b/projects/watch/tests/hello-world new file mode 100755 index 0000000000..acde8265fe --- /dev/null +++ b/projects/watch/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" + diff --git a/projects/watch/watch.h b/projects/watch/watch.h new file mode 100644 index 0000000000..c2cd7ddbe0 --- /dev/null +++ b/projects/watch/watch.h @@ -0,0 +1,9 @@ +#ifndef __WATCH_H +#define __WATCH_H + +#define MSG_ACTIVATE 0 +#define MSG_DEACTIVATE 1 +#define MSG_BUTTON_STAR 2 +#define MSG_BUTTON_HASH 3 + +#endif /* __WATCH_H */ From be71c14f047c5b8d1ed5069c4b97eae13abf4539 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 17 Dec 2010 13:20:29 +0100 Subject: [PATCH 12/38] [cpu/cc430] * added adc driver for cc430 --- cpu/cc430/Jamfile | 1 + cpu/cc430/cc430-adc.c | 149 ++++++++++++++++++++++++++++++++++ cpu/cc430/include/cc430-adc.h | 44 ++++++++++ 3 files changed, 194 insertions(+) create mode 100644 cpu/cc430/cc430-adc.c create mode 100644 cpu/cc430/include/cc430-adc.h diff --git a/cpu/cc430/Jamfile b/cpu/cc430/Jamfile index dafac6212a..886cb44296 100644 --- a/cpu/cc430/Jamfile +++ b/cpu/cc430/Jamfile @@ -30,5 +30,6 @@ SubDir TOP cpu cc430 ; Module hwtimer_cpu : hwtimer_cc430.c : hwtimer_msp430 ; Module rtc : cc430-rtc.c ; Module gpioint : cc430-gpioint.c ; +Module adc : cc430-adc.c : hwtimer ; SubInclude TOP cpu msp430-common ; diff --git a/cpu/cc430/cc430-adc.c b/cpu/cc430/cc430-adc.c new file mode 100644 index 0000000000..470725ad70 --- /dev/null +++ b/cpu/cc430/cc430-adc.c @@ -0,0 +1,149 @@ +/* ************************************************************************************************* + * + * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ************************************************************************************************* + * ADC12 functions. + * ************************************************************************************************/ + + +#include +#include +#include +#include + +uint16_t adc12_result; +uint8_t adc12_data_ready; + +/* ************************************************************************************************* + * @fn adc12_single_conversion + * @brief Init ADC12. Do single conversion. Turn off ADC12. + * @param none + * @return none + * ************************************************************************************************/ +uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel) { + /* Initialize the shared reference module */ + REFCTL0 |= REFMSTR + ref + REFON; /* Enable internal reference (1.5V or 2.5V) */ + + /* Initialize ADC12_A */ + ADC12CTL0 = sht + ADC12ON; /* Set sample time */ + ADC12CTL1 = ADC12SHP; /* Enable sample timer */ + ADC12MCTL0 = ADC12SREF_1 + channel; /* ADC input channel */ + ADC12IE = 0x001; /* ADC_IFG upon conv result-ADCMEMO */ + + eINT(); + + /* Wait 2 ticks (66us) to allow internal reference to settle */ + hwtimer_wait(2); + + /* Start ADC12 */ + ADC12CTL0 |= ADC12ENC; + + /* Clear data ready flag */ + adc12_data_ready = 0; + + /* Sampling and conversion start */ + ADC12CTL0 |= ADC12SC; + + /* Wait until ADC12 has finished */ + hwtimer_wait(5); + while (!adc12_data_ready); + + /* Shut down ADC12 */ + ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht); + ADC12CTL0 &= ~ADC12ON; + + /* Shut down reference voltage */ + REFCTL0 &= ~(REFMSTR + ref + REFON); + + ADC12IE = 0; + + /* Return ADC result */ + dINT(); + return adc12_result; +} + +/* ************************************************************************************************* + * @fn ADC12ISR + * @brief Store ADC12 conversion result. Set flag to indicate data ready. + * @param none + * @return none + * ************************************************************************************************/ +interrupt (ADC12_VECTOR) __attribute__ ((naked)) adc_isr (void) { + __enter_isr(); + switch(ADC12IV) { + case 0: + break; /* Vector 0: No interrupt */ + case 2: + break; /* Vector 2: ADC overflow */ + case 4: + break; /* Vector 4: ADC timing overflow */ + case 6: + /* Vector 6: ADC12IFG0 */ + adc12_result = ADC12MEM0; /* Move results, IFG is cleared */ + adc12_data_ready = 1; + break; + case 8: + break; /* Vector 8: ADC12IFG1 */ + case 10: + break; /* Vector 10: ADC12IFG2 */ + case 12: + break; /* Vector 12: ADC12IFG3 */ + case 14: + break; /* Vector 14: ADC12IFG4 */ + case 16: + break; /* Vector 16: ADC12IFG5 */ + case 18: + break; /* Vector 18: ADC12IFG6 */ + case 20: + break; /* Vector 20: ADC12IFG7 */ + case 22: + break; /* Vector 22: ADC12IFG8 */ + case 24: + break; /* Vector 24: ADC12IFG9 */ + case 26: + break; /* Vector 26: ADC12IFG10 */ + case 28: + break; /* Vector 28: ADC12IFG11 */ + case 30: + break; /* Vector 30: ADC12IFG12 */ + case 32: + break; /* Vector 32: ADC12IFG13 */ + case 34: + break; /* Vector 34: ADC12IFG14 */ + default: + break; + } + __exit_isr(); +} + + diff --git a/cpu/cc430/include/cc430-adc.h b/cpu/cc430/include/cc430-adc.h new file mode 100644 index 0000000000..8ac19a9385 --- /dev/null +++ b/cpu/cc430/include/cc430-adc.h @@ -0,0 +1,44 @@ +/* ************************************************************************************************* + * + * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ************************************************************************************************/ + +#ifndef CC430_ADC_H +#define CC430_ADC_H + +extern uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel); + +extern uint16_t adc12_result; +extern uint8_t adc12_data_ready; + +#endif From 443a5efbeac57baa56b0d56ee7a2bc5727a7ff8d Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 17 Dec 2010 13:38:03 +0100 Subject: [PATCH 13/38] [board/chronos] * introduced battery driver --- board/chronos/drivers/Jamfile | 1 + board/chronos/drivers/battery.c | 13 +++++++++++++ board/chronos/drivers/include/battery.h | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 board/chronos/drivers/battery.c create mode 100644 board/chronos/drivers/include/battery.h diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index 54d2fb4e7b..286616c5d9 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -5,5 +5,6 @@ HDRS += $(TOP)/board/$(CPU)/drivers/include ; Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; +Module battery : battery.c : adc hwtimer ; Module display_putchar : display_putchar.c : board_display ; diff --git a/board/chronos/drivers/battery.c b/board/chronos/drivers/battery.c new file mode 100644 index 0000000000..69553fc451 --- /dev/null +++ b/board/chronos/drivers/battery.c @@ -0,0 +1,13 @@ +#include +#include +#include + +uint16_t battery_get_voltate(void) { + uint16_t voltage; + voltage = adc12_single_conversion(REFVSEL_1, ADC12SHT0_10, ADC12INCH_11); + + /* Ideally we have A11=0->AVCC=0V ... A11=4095(2^12-1)->AVCC=4V + * --> (A11/4095)*4V=AVCC --> AVCC=(A11*4)/4095 */ + voltage = (voltage * 2 * 2 * 1000) / 4095; + return voltage; +} diff --git a/board/chronos/drivers/include/battery.h b/board/chronos/drivers/include/battery.h new file mode 100644 index 0000000000..6b206c6eca --- /dev/null +++ b/board/chronos/drivers/include/battery.h @@ -0,0 +1,6 @@ +#ifndef BATTERY_H +#define BATTERY_H + +uint16_t battery_get_voltate(void); + +#endif /* BATTERY_H */ From cb1d4dd041aa8d066a6ade1e5a628caf20bb8238 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 24 Jan 2011 15:52:36 +0100 Subject: [PATCH 14/38] [projects/default] * added missing transceiver init and start --- projects/default/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/default/main.c b/projects/default/main.c index 959c694616..06c8a16e7e 100644 --- a/projects/default/main.c +++ b/projects/default/main.c @@ -10,6 +10,7 @@ #include #include #include +#include int shell_readc() { char c = 0; @@ -24,6 +25,8 @@ void shell_putchar(int c) { int main(void) { posix_open(uart0_handler_pid, 0); ltc4150_start(); + transceiver_init(TRANSCEIVER_CC1100); + transceiver_start(); puts("Welcome to ukleos!"); From 45337262149a4b300c53972ef71859c202e5966a Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 31 Jan 2011 18:25:20 +0100 Subject: [PATCH 15/38] * introduced energy profiling (yet in a very early state) --- board/msba2-common/drivers/msba2-ltc4150.c | 8 +- cpu/arm_common/Jamfile | 5 + cpu/arm_common/Jamrules.arm_common | 5 + cpu/arm_common/profiling.c | 109 +++++++++++++++++++++ cpu/lpc2387/lpc2387-gpioint.c | 4 +- drivers/Jamfile | 2 +- drivers/include/ltc4150.h | 1 + drivers/ltc4150.c | 10 +- sys/auto_init.c | 4 + 9 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 cpu/arm_common/profiling.c diff --git a/board/msba2-common/drivers/msba2-ltc4150.c b/board/msba2-common/drivers/msba2-ltc4150.c index c590dee8db..4e6534c022 100644 --- a/board/msba2-common/drivers/msba2-ltc4150.c +++ b/board/msba2-common/drivers/msba2-ltc4150.c @@ -45,19 +45,19 @@ and the mailinglist (subscription via web site) #include "ltc4150_arch.h" #include "gpioint.h" -void ltc4150_disable_int(void) { +void __attribute__((__no_instrument_function__)) ltc4150_disable_int(void) { gpioint_set(0, BIT4, GPIOINT_DISABLE, NULL); } -void ltc4150_enable_int(void) { +void __attribute__((__no_instrument_function__)) ltc4150_enable_int(void) { gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, <c4150_interrupt); } -void ltc4150_sync_blocking(void) { +void __attribute__((__no_instrument_function__)) ltc4150_sync_blocking(void) { while(!(FIO0PIN & BIT4)) {}; } -void ltc4150_arch_init() { +void __attribute__((__no_instrument_function__)) ltc4150_arch_init() { FIO0DIR |= BIT5; FIO0SET = BIT5; } diff --git a/cpu/arm_common/Jamfile b/cpu/arm_common/Jamfile index 0252c75781..1889eef63e 100644 --- a/cpu/arm_common/Jamfile +++ b/cpu/arm_common/Jamfile @@ -30,6 +30,11 @@ SubDir TOP cpu arm_common ; Module arm_common : common.s bootloader.c VIC.c atomic.s arm_cpu.c iap.c ; UseModule arm_common ; +Module profiling : profiling.c ; +if $(PROFILING) { + UseModule profiling ; +} + Module hwtimer_cpu : hwtimer_cpu.c ; Objects syscalls.c ; diff --git a/cpu/arm_common/Jamrules.arm_common b/cpu/arm_common/Jamrules.arm_common index dac4bff7d8..afb14fa247 100644 --- a/cpu/arm_common/Jamrules.arm_common +++ b/cpu/arm_common/Jamrules.arm_common @@ -40,9 +40,14 @@ LINK = $(CC) ; OPTIM = -Os ; #OPTIM = -O0 -g ; + CCFLAGS += -std=gnu99 -Wall -mcpu=arm7tdmi-s -mfloat-abi=soft -mfpu=vfp ; LINKFLAGS = -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T [ FPath $(TOP) cpu $(CPU) linkerscript.x ] ; +if $(PROFILING) = 1 { + CCFLAGS += -g -finstrument-functions ; +} + AS = $(TOOLCHAIN)as ; ASFLAGS += -mcpu=arm7tdmi-s --defsym $(CPU)=1 -mfloat-abi=soft -mfpu=vfp ; diff --git a/cpu/arm_common/profiling.c b/cpu/arm_common/profiling.c new file mode 100644 index 0000000000..8bbe2c0edc --- /dev/null +++ b/cpu/arm_common/profiling.c @@ -0,0 +1,109 @@ +#include +#include +#include +#include + +#define MAX_TRACED_FUNCTIONS (32) +#define PROFILING_STACK_SIZE (16) + +typedef struct { + uint32_t address; + uint32_t time; + uint32_t start_time; + double consumption; + double consumption_start; + uint16_t counter; +} profiling_info_t; + +static profiling_info_t functions[MAX_TRACED_FUNCTIONS]; +static uint8_t profiling_stack[PROFILING_STACK_SIZE]; +static uint8_t profiling_sp = 0; + +static uint8_t traced_functions = 0; +static uint8_t profiling = 0; + +void __attribute__((__no_instrument_function__)) profiling_init(void) { + uint8_t i; + for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { + functions[i].address = 0; + functions[i].time = 0; + functions[i].consumption = 0; + functions[i].counter = 0; + } + for (i = 0; i < PROFILING_STACK_SIZE; i++) { + profiling_stack[i] = 0; + } + + ltc4150_start(); + + profiling = 1; +} + +static int16_t __attribute__((__no_instrument_function__)) get_function_index(uint32_t addr) { + uint8_t i; + for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { + if (functions[i].address == addr) { + return i; + } + } + return -1; +} + +void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter (void *func, void *caller) { + if (!profiling) { + return; + } + /* + uint8_t i; + int16_t idx = -1; + for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { + if (functions[i].address == (uint32_t) func) { + idx = i; + break; + } + } + */ + uint8_t idx = get_function_index((uint32_t) func); + if ((idx < 0) && (traced_functions < MAX_TRACED_FUNCTIONS)) { + idx = traced_functions++; + functions[idx].address = (uint32_t) func; + } + else if (idx < 0) { + return; + } + functions[idx].start_time = T0TC; + functions[idx].counter++; + functions[idx].consumption_start = ltc4150_get_total_mAh(); + // functions[idx].consumption_start = ltc4150_get_intcount(); +} + +void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit (void *func, void *caller) { + if (!profiling) { + return; + } + /* + uint8_t i; + int16_t idx = -1; + for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { + if (functions[i].address == (uint32_t) func) { + idx = i; + break; + } + } + */ + uint8_t idx = get_function_index((uint32_t) func); + if (idx >= 0) { + functions[idx].time += T0TC - functions[idx].start_time; + //functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start; + functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start; + } +} + +void profiling_stats(void) { + uint8_t i; + for (i = 0; i < traced_functions; i++) { +// printf("Function @%04lX was running %u times for %lu ticks, consuming %li ltc-ticks\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption); + printf("Function @%04lX was running %u times for %lu ticks, consuming %lf mAh\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption); + } + puts("________________________________________________________"); +} diff --git a/cpu/lpc2387/lpc2387-gpioint.c b/cpu/lpc2387/lpc2387-gpioint.c index e33fc854a4..7ce5941410 100644 --- a/cpu/lpc2387/lpc2387-gpioint.c +++ b/cpu/lpc2387/lpc2387-gpioint.c @@ -123,7 +123,7 @@ gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) return true; // success } /*---------------------------------------------------------------------------*/ -static void test_irq(int port, unsigned long f_mask, unsigned long r_mask, struct irq_callback* pcb) +static void __attribute__ ((__no_instrument_function__)) test_irq(int port, unsigned long f_mask, unsigned long r_mask, struct irq_callback* pcb) { /* Test each bit of rising and falling masks, if set trigger interrupt * on corresponding device */ @@ -148,7 +148,7 @@ void GPIO_IRQHandler(void) __attribute__((interrupt("IRQ"))); * Invoked whenever an activated gpio interrupt is triggered by a rising * or falling edge. */ -void GPIO_IRQHandler(void) { +void __attribute__ ((__no_instrument_function__)) GPIO_IRQHandler(void) { if( IO_INT_STAT & BIT0 ) { // interrupt(s) on PORT0 pending unsigned long int_stat_f = IO0_INT_STAT_F; // save content unsigned long int_stat_r = IO0_INT_STAT_R; // save content diff --git a/drivers/Jamfile b/drivers/Jamfile index 9713df17fd..3dbeed6d7c 100644 --- a/drivers/Jamfile +++ b/drivers/Jamfile @@ -29,7 +29,7 @@ SubDir TOP drivers ; Module sht11 : sht11.c : hwtimer ; -Module ltc4150 : ltc4150.c : board_ltc4150 ; +Module ltc4150 : ltc4150.c : board_ltc4150 hwtimer ; SubInclude TOP drivers cc110x ; SubInclude TOP drivers cc110x_ng ; diff --git a/drivers/include/ltc4150.h b/drivers/include/ltc4150.h index 88160c8913..4a3c055153 100644 --- a/drivers/include/ltc4150.h +++ b/drivers/include/ltc4150.h @@ -11,5 +11,6 @@ double ltc4150_get_current_mA(); double ltc4150_get_total_mAh(); double ltc4150_get_avg_mA(); int ltc4150_get_interval(); +long ltc4150_get_intcount(void); #endif /* __LTC4150_H */ diff --git a/drivers/ltc4150.c b/drivers/ltc4150.c index 7c50553a85..947265f6a5 100644 --- a/drivers/ltc4150.c +++ b/drivers/ltc4150.c @@ -46,11 +46,11 @@ static unsigned int last_int_time; static unsigned int last_int_duration; static unsigned int start_time; -static double int_to_coulomb(int ints) { +static double __attribute__((__no_instrument_function__)) int_to_coulomb(int ints) { return ((double)ints) / (_GFH * _R_SENSE); } -static double coulomb_to_mA(double coulomb){ +static double __attribute__((__no_instrument_function__)) coulomb_to_mA(double coulomb){ return (coulomb * 1000) / 3600; } @@ -62,7 +62,7 @@ double ltc4150_get_current_mA() { return 1000000000/(ltc4150_get_last_int_duration_us()*(_GFH * _R_SENSE)); } -double ltc4150_get_total_mAh() { +double __attribute__((__no_instrument_function__)) ltc4150_get_total_mAh() { return coulomb_to_mA(int_to_coulomb(int_count)); } @@ -74,7 +74,7 @@ int ltc4150_get_interval() { return HWTIMER_TICKS_TO_US(last_int_time - start_time); } -unsigned long ltc4150_get_intcount() { +unsigned long __attribute__((__no_instrument_function__)) ltc4150_get_intcount() { return int_count; } @@ -96,7 +96,7 @@ void ltc4150_stop() { ltc4150_disable_int(); } -void ltc4150_interrupt() +void __attribute__((__no_instrument_function__)) ltc4150_interrupt() { uint32_t now = hwtimer_now(); if (now >= last_int_time) { diff --git a/sys/auto_init.c b/sys/auto_init.c index e9e7a4d486..c142d7ef32 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -52,6 +52,10 @@ void auto_init(void) { #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); +#endif +#ifdef MODULE_PROFILING + extern void profiling_init(void); + profiling_init(); #endif main(); } From d96783a66e53132d916db1ae056e4dfa9e5dfbf9 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 31 Jan 2011 18:36:06 +0100 Subject: [PATCH 16/38] [cpu/arm_common/profiling] * fixed get_index function --- cpu/arm_common/profiling.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/cpu/arm_common/profiling.c b/cpu/arm_common/profiling.c index 8bbe2c0edc..fbdf6282f2 100644 --- a/cpu/arm_common/profiling.c +++ b/cpu/arm_common/profiling.c @@ -53,17 +53,7 @@ void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter (void if (!profiling) { return; } - /* - uint8_t i; - int16_t idx = -1; - for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { - if (functions[i].address == (uint32_t) func) { - idx = i; - break; - } - } - */ - uint8_t idx = get_function_index((uint32_t) func); + int16_t idx = get_function_index((uint32_t) func); if ((idx < 0) && (traced_functions < MAX_TRACED_FUNCTIONS)) { idx = traced_functions++; functions[idx].address = (uint32_t) func; @@ -81,17 +71,7 @@ void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit (void * if (!profiling) { return; } - /* - uint8_t i; - int16_t idx = -1; - for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { - if (functions[i].address == (uint32_t) func) { - idx = i; - break; - } - } - */ - uint8_t idx = get_function_index((uint32_t) func); + int16_t idx = get_function_index((uint32_t) func); if (idx >= 0) { functions[idx].time += T0TC - functions[idx].start_time; //functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start; From 3622d83ea98834a4785708985e27f599ee20af6c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 4 Mar 2011 16:46:20 +0100 Subject: [PATCH 17/38] [board msba2] * fixed header guards [drivers ltc4150] * added joule conversion --- board/msba2-common/include/msba2_common.h | 6 +++--- board/msba2/include/board.h | 1 + drivers/include/ltc4150.h | 1 + drivers/include/ltc4150_arch.h | 1 + drivers/ltc4150.c | 8 ++++++++ projects/default/main.c | 1 - projects/laser/main.c | 5 ++++- projects/test_cc110x_ng/Jamfile | 2 +- 8 files changed, 19 insertions(+), 6 deletions(-) diff --git a/board/msba2-common/include/msba2_common.h b/board/msba2-common/include/msba2_common.h index a9d9d3e72c..fff12f965d 100644 --- a/board/msba2-common/include/msba2_common.h +++ b/board/msba2-common/include/msba2_common.h @@ -24,8 +24,8 @@ and the mailinglist (subscription via web site) scatterweb@lists.spline.inf.fu-berlin.de *******************************************************************************/ -#ifndef __BOARD_H -#define __BOARD_H +#ifndef __MSBA2_COMMON_H +#define __MSBA2_COMMON_H /** * @ingroup msb_a2 @@ -48,4 +48,4 @@ and the mailinglist (subscription via web site) #define VICIntEnClear VICIntEnClr /** @} */ -#endif // __BOARD_H +#endif // __MSBA2_COMMON_H diff --git a/board/msba2/include/board.h b/board/msba2/include/board.h index bf596f0ee1..2b1f28fd2a 100644 --- a/board/msba2/include/board.h +++ b/board/msba2/include/board.h @@ -2,6 +2,7 @@ #define __BOARD_H #include +#include #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) diff --git a/drivers/include/ltc4150.h b/drivers/include/ltc4150.h index 4a3c055153..fdc08573ae 100644 --- a/drivers/include/ltc4150.h +++ b/drivers/include/ltc4150.h @@ -9,6 +9,7 @@ void ltc4150_stop(); double ltc4150_get_current_mA(); double ltc4150_get_total_mAh(); +double ltc4150_get_total_Joule(void); double ltc4150_get_avg_mA(); int ltc4150_get_interval(); long ltc4150_get_intcount(void); diff --git a/drivers/include/ltc4150_arch.h b/drivers/include/ltc4150_arch.h index 1a6c5c630b..51fc9478a3 100644 --- a/drivers/include/ltc4150_arch.h +++ b/drivers/include/ltc4150_arch.h @@ -46,6 +46,7 @@ and the mailinglist (subscription via web site) #define _GFH (double)32.631375 #define _R_SENSE (double)0.330 +#define SUPPLY_VOLTAGE (5) void ltc4150_disable_int(void); void ltc4150_enable_int(void); diff --git a/drivers/ltc4150.c b/drivers/ltc4150.c index 947265f6a5..9f4134b5c9 100644 --- a/drivers/ltc4150.c +++ b/drivers/ltc4150.c @@ -54,6 +54,10 @@ static double __attribute__((__no_instrument_function__)) coulomb_to_mA(double c return (coulomb * 1000) / 3600; } +static double mAh_to_Joule(double mAh) { + return (SUPPLY_VOLTAGE * mAh * 3600); +} + uint32_t ltc4150_get_last_int_duration_us() { return HWTIMER_TICKS_TO_US(last_int_duration); } @@ -66,6 +70,10 @@ double __attribute__((__no_instrument_function__)) ltc4150_get_total_mAh() { return coulomb_to_mA(int_to_coulomb(int_count)); } +double ltc4150_get_total_Joule(void) { + return mAh_to_Joule(ltc4150_get_total_mAh()); +} + double ltc4150_get_avg_mA() { return (int_to_coulomb(int_count)*1000000000)/HWTIMER_TICKS_TO_US(last_int_time - start_time); } diff --git a/projects/default/main.c b/projects/default/main.c index 06c8a16e7e..ccc4cfd9a1 100644 --- a/projects/default/main.c +++ b/projects/default/main.c @@ -34,7 +34,6 @@ int main(void) { shell_init(&shell, NULL, shell_readc, shell_putchar); shell_run(&shell); - return 0; } diff --git a/projects/laser/main.c b/projects/laser/main.c index 902ffc3088..e3c3d4f83e 100644 --- a/projects/laser/main.c +++ b/projects/laser/main.c @@ -7,6 +7,8 @@ int main(void) { sht11_val_t sht11_val; + double mAh = 0; + uint8_t success = 0; puts(""); @@ -18,11 +20,12 @@ int main(void) while (1) { success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + mAh = ltc4150_get_total_mAh(); if (!success) { printf("error;error;error\n"); } else { - printf("%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp); + printf("%.2f;%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp, mAh); } LED_RED_TOGGLE; swtimer_usleep(60 * 1000*1000); diff --git a/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile index 2a13cb0892..5ef69ea238 100644 --- a/projects/test_cc110x_ng/Jamfile +++ b/projects/test_cc110x_ng/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects test_cc110x_ng ; -Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer config ; +Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer config ltc4150 ; UseModule test_cc110x_ng ; From 6a96de0d2f2fb607599f40ccedd01bed7c034ebe Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 8 Mar 2011 10:54:40 +0100 Subject: [PATCH 18/38] changed msg to msg_t --- core/include/msg.h | 14 +++++++------- core/include/tcb.h | 2 +- core/msg.c | 26 +++++++++++++------------- cpu/cc430/cc430-rtc.c | 2 +- drivers/cc110x/cc1100_phy.c | 4 ++-- drivers/cc110x_ng/cc110x-rx.c | 2 +- projects/chronos_cc110x_ng/main.c | 6 +++--- projects/chronos_default/main.c | 6 +++--- projects/msb430_cc110x_ng/main.c | 6 +++--- projects/pingpong/main.c | 4 ++-- projects/pingpong_sync/main.c | 4 ++-- projects/test_cc110x_ng/main.c | 6 +++--- projects/test_swtimer_basic/main.c | 2 +- projects/watch/alarm_app.c | 2 +- projects/watch/clock_app.c | 2 +- projects/watch/main.c | 4 ++-- sys/chardev_thread.c | 2 +- sys/posix_io.c | 4 ++-- sys/shell/cc110x_ng.c | 2 +- sys/swtimer.c | 2 +- sys/transceiver.c | 6 +++--- sys/uart0.c | 2 +- 22 files changed, 55 insertions(+), 55 deletions(-) diff --git a/core/include/msg.h b/core/include/msg.h index 4d9a0b9aba..71d2d58915 100644 --- a/core/include/msg.h +++ b/core/include/msg.h @@ -35,7 +35,7 @@ typedef struct msg { char *ptr; ///< pointer content field uint32_t value; ///< value content field } content; -} msg; +} msg_t; /** @@ -54,7 +54,7 @@ typedef struct msg { * @return 0 if receiver is not waiting and block == false * @return -1 on error (invalid PID) */ -int msg_send(msg* m, unsigned int target_pid, bool block); +int msg_send(msg_t* m, unsigned int target_pid, bool block); /** @@ -68,7 +68,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block); * @return 1 if sending was successfull * @return 0 if receiver is not waiting and block == false */ -int msg_send_int(msg* m, unsigned int target_pid); +int msg_send_int(msg_t* m, unsigned int target_pid); /** @@ -79,7 +79,7 @@ int msg_send_int(msg* m, unsigned int target_pid); * * @return 1 Function always succeeds or blocks forever. */ -int msg_receive(msg* m); +int msg_receive(msg_t* m); /** * @brief Send a message, block until reply received. @@ -90,7 +90,7 @@ int msg_receive(msg* m); * @param target pid the pid of the target process * @return 1 if successful */ -int msg_send_receive(msg *m, msg *reply, unsigned int target_pid); +int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid); /** * @brief Replies to a message. @@ -103,7 +103,7 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid); * @return 1 if succcessful * qreturn 0 on error */ -int msg_reply(msg *m, msg *reply); +int msg_reply(msg_t *m, msg_t *reply); /** * @brief Initialize the current thread's message queue. @@ -111,7 +111,7 @@ int msg_reply(msg *m, msg *reply); * @param array Pointer to preallocated array of msg objects * @param num Number of msg objects in array. MUST BE POWER OF TWO! */ -int msg_init_queue(msg* array, int num); +int msg_init_queue(msg_t* array, int num); /** @} */ #endif /* __MSG_H */ diff --git a/core/include/tcb.h b/core/include/tcb.h index d5d2a63645..8ca79c1905 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -48,7 +48,7 @@ typedef struct tcb { queue_node_t msg_waiters; cib_t msg_queue; - msg* msg_array; + msg_t* msg_array; const char* name; char* stack_start; diff --git a/core/msg.c b/core/msg.c index b33eda5691..05ff734b82 100644 --- a/core/msg.c +++ b/core/msg.c @@ -27,7 +27,7 @@ //#define ENABLE_DEBUG #include "debug.h" -static int queue_msg(tcb *target, msg *m) { +static int queue_msg(tcb *target, msg_t *m) { int n = cib_put(&(target->msg_queue)); if (n != -1) { @@ -38,7 +38,7 @@ static int queue_msg(tcb *target, msg *m) { return 0; } -int msg_send(msg* m, unsigned int target_pid, bool block) { +int msg_send(msg_t* m, unsigned int target_pid, bool block) { if (inISR()) { return msg_send_int(m, target_pid); } @@ -90,7 +90,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { } else { DEBUG("%s: direct msg copy.\n", active_thread->name); /* copy msg to target */ - msg* target_message = (msg*)target->wait_data; + msg_t* target_message = (msg_t*)target->wait_data; *target_message = *m; sched_set_status(target, STATUS_PENDING); } @@ -101,7 +101,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { return 1; } -int msg_send_int(msg* m, unsigned int target_pid) { +int msg_send_int(msg_t* m, unsigned int target_pid) { tcb *target = (tcb*)sched_threads[target_pid]; if (target->status == STATUS_RECEIVE_BLOCKED) { @@ -110,7 +110,7 @@ int msg_send_int(msg* m, unsigned int target_pid) { m->sender_pid = target_pid; /* copy msg to target */ - msg* target_message = (msg*)target->wait_data; + msg_t* target_message = (msg_t*)target->wait_data; *target_message = *m; sched_set_status(target, STATUS_PENDING); @@ -122,7 +122,7 @@ int msg_send_int(msg* m, unsigned int target_pid) { } } -int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { +int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid) { dINT(); tcb *me = (tcb*) sched_threads[thread_pid]; sched_set_status(me, STATUS_REPLY_BLOCKED); @@ -134,7 +134,7 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { return 1; } -int msg_reply(msg *m, msg *reply) { +int msg_reply(msg_t *m, msg_t *reply) { int state = disableIRQ(); tcb *target = (tcb*)sched_threads[m->sender_pid]; @@ -146,7 +146,7 @@ int msg_reply(msg *m, msg *reply) { DEBUG("%s: msg_reply(): direct msg copy.\n", active_thread->name); /* copy msg to target */ - msg* target_message = (msg*)target->wait_data; + msg_t* target_message = (msg_t*)target->wait_data; *target_message = *reply; sched_set_status(target, STATUS_PENDING); restoreIRQ(state); @@ -155,20 +155,20 @@ int msg_reply(msg *m, msg *reply) { return 1; } -int msg_reply_int(msg *m, msg *reply) { +int msg_reply_int(msg_t *m, msg_t *reply) { tcb *target = (tcb*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name); return -1; } - msg* target_message = (msg*)target->wait_data; + msg_t* target_message = (msg_t*)target->wait_data; *target_message = *reply; sched_set_status(target, STATUS_PENDING); sched_context_switch_request = 1; return 1; } -int msg_receive(msg* m) { +int msg_receive(msg_t* m) { dINT(); DEBUG("%s: msg_receive.\n", active_thread->name); @@ -212,7 +212,7 @@ int msg_receive(msg* m) { } /* copy msg */ - msg* sender_msg = (msg*)sender->wait_data; + msg_t* sender_msg = (msg_t*)sender->wait_data; *m = *sender_msg; /* remove sender from queue */ @@ -224,7 +224,7 @@ int msg_receive(msg* m) { } } -int msg_init_queue(msg* array, int num) { +int msg_init_queue(msg_t* array, int num) { /* make sure brainfuck condition is met */ if (num && (num & (num - 1)) == 0) { tcb *me = (tcb*)active_thread; diff --git a/cpu/cc430/cc430-rtc.c b/cpu/cc430/cc430-rtc.c index 8895e05996..59afacfa95 100644 --- a/cpu/cc430/cc430-rtc.c +++ b/cpu/cc430/cc430-rtc.c @@ -187,7 +187,7 @@ interrupt(RTC_VECTOR) __attribute__ ((naked)) rtc_isr(void) { RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08; } if (rtc_second_pid) { - msg m; + msg_t m; m.type = RTC_SECOND; msg_send_int(&m, rtc_second_pid); } diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 441b7d6a28..76acfb33ac 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -624,7 +624,7 @@ int cc1100_set_packet_handler(protocol_t protocol, packet_handler_t handler) static void cc1100_event_handler_function(void) { - msg m; + msg_t m; while (1) { if (cc1100_watch_dog_period != 0) { @@ -685,7 +685,7 @@ static void cc1100_event_handler_function(void) void cc1100_phy_rx_handler(void) { - msg m; + msg_t m; m.type = MSG_POLL; bool dup = false; bool res = false; diff --git a/drivers/cc110x_ng/cc110x-rx.c b/drivers/cc110x_ng/cc110x-rx.c index 7b2229169c..3a5e5ba9ad 100644 --- a/drivers/cc110x_ng/cc110x-rx.c +++ b/drivers/cc110x_ng/cc110x-rx.c @@ -51,7 +51,7 @@ void cc110x_rx_handler(void) { /* notify transceiver thread if any */ if (transceiver_pid) { - msg m; + msg_t m; m.type = (uint16_t) RCV_PKT_CC1100; m.content.value = rx_buffer_next; msg_send_int(&m, transceiver_pid); diff --git a/projects/chronos_cc110x_ng/main.c b/projects/chronos_cc110x_ng/main.c index 4e14c50d1a..4d19a34222 100644 --- a/projects/chronos_cc110x_ng/main.c +++ b/projects/chronos_cc110x_ng/main.c @@ -22,9 +22,9 @@ char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SEND_SIZE]; -msg msg_q[RCV_BUFFER_SIZE]; +msg_t msg_q[RCV_BUFFER_SIZE]; -static msg mesg; +static msg_t mesg; static transceiver_command_t tcmd; static radio_packet_t p; @@ -48,7 +48,7 @@ void send(radio_address_t dst, uint8_t len, uint8_t *data) { void radio(void) { - msg m; + msg_t m; radio_packet_t *p; msg_init_queue(msg_q, RCV_BUFFER_SIZE); diff --git a/projects/chronos_default/main.c b/projects/chronos_default/main.c index f521910d7f..6e647ad3a0 100644 --- a/projects/chronos_default/main.c +++ b/projects/chronos_default/main.c @@ -27,9 +27,9 @@ char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SEND_SIZE]; -msg msg_q[RCV_BUFFER_SIZE]; +msg_t msg_q[RCV_BUFFER_SIZE]; -static msg mesg; +static msg_t mesg; static transceiver_command_t tcmd; static radio_packet_t p; @@ -52,7 +52,7 @@ void send(radio_address_t dst, uint8_t len, uint8_t *data) { } void radio(void) { - msg m; + msg_t m; radio_packet_t *p; msg_init_queue(msg_q, RCV_BUFFER_SIZE); diff --git a/projects/msb430_cc110x_ng/main.c b/projects/msb430_cc110x_ng/main.c index 019e8cb57d..60719ec145 100644 --- a/projects/msb430_cc110x_ng/main.c +++ b/projects/msb430_cc110x_ng/main.c @@ -25,9 +25,9 @@ char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SND_BUFFER_SIZE][CC1100_MAX_DATA_LENGTH]; -msg msg_q[RCV_BUFFER_SIZE]; +msg_t msg_q[RCV_BUFFER_SIZE]; -static msg mesg; +static msg_t mesg; static transceiver_command_t tcmd; static radio_packet_t p; @@ -98,7 +98,7 @@ void print_buffer(char *unused) { } void radio(void) { - msg m; + msg_t m; radio_packet_t *p; uint8_t i; diff --git a/projects/pingpong/main.c b/projects/pingpong/main.c index 2c9f214571..0a4a910a9b 100644 --- a/projects/pingpong/main.c +++ b/projects/pingpong/main.c @@ -5,7 +5,7 @@ void second_thread(void) { printf("second_thread starting.\n"); - msg m; + msg_t m; while(1) { msg_receive(&m); @@ -21,7 +21,7 @@ int main(void) { printf("Hello world!\n"); - msg m; + msg_t m; int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); diff --git a/projects/pingpong_sync/main.c b/projects/pingpong_sync/main.c index 8e1fd4d7d4..47989a2678 100644 --- a/projects/pingpong_sync/main.c +++ b/projects/pingpong_sync/main.c @@ -5,7 +5,7 @@ void second_thread(void) { printf("second_thread starting.\n"); - msg m; + msg_t m; int i = 1; while(1) { msg_receive(&m); @@ -21,7 +21,7 @@ int main(void) { printf("Hello world!\n"); - msg m; + msg_t m; int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index 22b9485b5d..1470e4fde0 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -25,9 +25,9 @@ char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SND_BUFFER_SIZE][CC1100_MAX_DATA_LENGTH]; -msg msg_q[RCV_BUFFER_SIZE]; +msg_t msg_q[RCV_BUFFER_SIZE]; -static msg mesg; +static msg_t mesg; static transceiver_command_t tcmd; static radio_packet_t p; @@ -121,7 +121,7 @@ void set_delay(char *delay) { } void radio(void) { - msg m; + msg_t m; radio_packet_t *p; uint8_t i; diff --git a/projects/test_swtimer_basic/main.c b/projects/test_swtimer_basic/main.c index 25837a3ace..0130aa4d65 100644 --- a/projects/test_swtimer_basic/main.c +++ b/projects/test_swtimer_basic/main.c @@ -14,7 +14,7 @@ void wakeup_thread(void){ } void msg_thread(void){ - msg m; + msg_t m; msg_receive(&m); printf("%s\n",(char*)m.content.ptr); } diff --git a/projects/watch/alarm_app.c b/projects/watch/alarm_app.c index 7a9f206bb7..92158382d2 100644 --- a/projects/watch/alarm_app.c +++ b/projects/watch/alarm_app.c @@ -13,7 +13,7 @@ static char alarm_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; static void alarm_thread(void) { - msg m; + msg_t m; struct tm time; diff --git a/projects/watch/clock_app.c b/projects/watch/clock_app.c index 761ebe17fc..f46fc35bd0 100644 --- a/projects/watch/clock_app.c +++ b/projects/watch/clock_app.c @@ -15,7 +15,7 @@ void time_print(struct tm *time) { static char clock_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; static void clock_thread(void) { - msg m; + msg_t m; int active = 0; rtc_second_pid = thread_getpid(); diff --git a/projects/watch/main.c b/projects/watch/main.c index e67dbe6018..94bbcc8646 100644 --- a/projects/watch/main.c +++ b/projects/watch/main.c @@ -21,7 +21,7 @@ int apps[NUM_APPS]; int button_thread = 0; void button_star(void) { - msg m; + msg_t m; if (button_thread) { m.type = MSG_BUTTON_STAR; @@ -40,7 +40,7 @@ int main(void) int active_app = 0; - msg m; + msg_t m; //buzzer_beep(15, 5000); diff --git a/sys/chardev_thread.c b/sys/chardev_thread.c index 6c90928c44..11d75eac62 100644 --- a/sys/chardev_thread.c +++ b/sys/chardev_thread.c @@ -17,7 +17,7 @@ static int min(int a, int b) { } void chardev_loop(ringbuffer *rb) { - msg m; + msg_t m; int pid = thread_getpid(); diff --git a/sys/posix_io.c b/sys/posix_io.c index fd423e1655..9d277af2fd 100644 --- a/sys/posix_io.c +++ b/sys/posix_io.c @@ -4,7 +4,7 @@ static int _posix_fileop(int pid, int op, int flags) { - msg m; + msg_t m; m.type = op; m.content.value = flags; msg_send_receive(&m, &m, pid); @@ -16,7 +16,7 @@ static int _posix_fileop_data(int pid, int op, char* buffer, int nbytes) { r.nbytes = nbytes; r.buffer = buffer; - msg m; + msg_t m; m.type = op; m.content.ptr = (char*) &r; diff --git a/sys/shell/cc110x_ng.c b/sys/shell/cc110x_ng.c index ca192d2289..ed9aa45110 100644 --- a/sys/shell/cc110x_ng.c +++ b/sys/shell/cc110x_ng.c @@ -8,7 +8,7 @@ #define TEXT_SIZE CC1100_MAX_DATA_LENGTH char text_msg[TEXT_SIZE]; -msg mesg; +msg_t mesg; transceiver_command_t tcmd; void _cc110x_ng_get_set_address_handler(char *addr) { diff --git a/sys/swtimer.c b/sys/swtimer.c index 0b998de8b7..4dc2485156 100644 --- a/sys/swtimer.c +++ b/sys/swtimer.c @@ -235,7 +235,7 @@ static void swtimer_action(swtimer_t *swtimer) { } case SWTIMER_MSG: { - msg m; + msg_t m; m.content.value = swtimer->action.msg.value; int result = msg_send_int(&m, swtimer->action.msg.target_pid); if (result < 0) { diff --git a/sys/transceiver.c b/sys/transceiver.c index 7fb49b6ed0..d9b60b0af3 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -34,7 +34,7 @@ radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; uint8_t data_buffer[TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE]; /* message buffer */ -msg msg_buffer[TRANSCEIVER_MSG_BUFFER_SIZE]; +msg_t msg_buffer[TRANSCEIVER_MSG_BUFFER_SIZE]; uint32_t response; ///< response bytes for messages to upper layer threads @@ -116,7 +116,7 @@ uint8_t transceiver_register(transceiver_type_t t, int pid) { * loop */ void run(void) { - msg m; + msg_t m; transceiver_command_t *cmd; msg_init_queue(msg_buffer, TRANSCEIVER_MSG_BUFFER_SIZE); @@ -180,7 +180,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { uint8_t i = 0; transceiver_type_t t; rx_buffer_pos = pos; - msg m; + msg_t m; DEBUG("Packet received\n"); switch (type) { diff --git a/sys/uart0.c b/sys/uart0.c index 04182b082c..6907fa89be 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -33,7 +33,7 @@ void uart0_handle_incoming(int c) { } void uart0_notify_thread(void) { - msg m; + msg_t m; m.type = 0; msg_send_int(&m, uart0_handler_pid); } From e9d351da8df1936a7b19614484ab591f576c97e7 Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 8 Mar 2011 11:17:57 +0100 Subject: [PATCH 19/38] changed ringbuffer to ringbuffer_t --- sys/chardev_thread.c | 2 +- sys/include/chardev_thread.h | 2 +- sys/lib/ringbuffer.c | 10 +++++----- sys/lib/ringbuffer.h | 12 ++++++------ sys/uart0.c | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sys/chardev_thread.c b/sys/chardev_thread.c index 11d75eac62..6f70af7dfe 100644 --- a/sys/chardev_thread.c +++ b/sys/chardev_thread.c @@ -16,7 +16,7 @@ static int min(int a, int b) { else return b; } -void chardev_loop(ringbuffer *rb) { +void chardev_loop(ringbuffer_t *rb) { msg_t m; int pid = thread_getpid(); diff --git a/sys/include/chardev_thread.h b/sys/include/chardev_thread.h index 4596cda832..bb811bddde 100644 --- a/sys/include/chardev_thread.h +++ b/sys/include/chardev_thread.h @@ -3,6 +3,6 @@ #include -void chardev_loop(ringbuffer *rb); +void chardev_loop(ringbuffer_t *rb); #endif /* __CHARDEV_THREAD_H */ diff --git a/sys/lib/ringbuffer.c b/sys/lib/ringbuffer.c index ef2116d5a7..4e021942d5 100755 --- a/sys/lib/ringbuffer.c +++ b/sys/lib/ringbuffer.c @@ -8,7 +8,7 @@ //#define DEBUG(...) printf (__VA_ARGS__) #define DEBUG(...) -void ringbuffer_init(ringbuffer *rb, char* buffer, unsigned int bufsize) { +void ringbuffer_init(ringbuffer_t *rb, char* buffer, unsigned int bufsize) { rb->buf = buffer; rb->start = 0; rb->end = 0; @@ -16,13 +16,13 @@ void ringbuffer_init(ringbuffer *rb, char* buffer, unsigned int bufsize) { rb->avail = 0; } -void rb_add_elements(ringbuffer* rb, char *buf, int n) { +void rb_add_elements(ringbuffer_t* rb, char *buf, int n) { for (int i = 0; i < n; i++) { rb_add_element(rb, buf[i]); } } -void rb_add_element(ringbuffer* rb, char c) { +void rb_add_element(ringbuffer_t* rb, char c) { if (rb->avail == rb->size) rb_get_element(rb); rb->buf[rb->end++] = c; @@ -31,7 +31,7 @@ void rb_add_element(ringbuffer* rb, char c) { rb->avail++; } -int rb_get_element(ringbuffer *rb) { +int rb_get_element(ringbuffer_t *rb) { if (rb->avail == 0) return -1; rb->avail--; @@ -42,7 +42,7 @@ int rb_get_element(ringbuffer *rb) { return c; } -int rb_get_elements(ringbuffer *rb, char* buf, int n) { +int rb_get_elements(ringbuffer_t *rb, char* buf, int n) { int count = 0; while (rb->avail && (count < n)) { buf[count++] = rb_get_element(rb); diff --git a/sys/lib/ringbuffer.h b/sys/lib/ringbuffer.h index 11f7222af1..3e646ae795 100755 --- a/sys/lib/ringbuffer.h +++ b/sys/lib/ringbuffer.h @@ -7,12 +7,12 @@ typedef struct ringbuffer { unsigned int end; unsigned int size; unsigned int avail; -} ringbuffer; +} ringbuffer_t; -void ringbuffer_init(ringbuffer *rb, char* buffer, unsigned int bufsize); -void rb_add_element(ringbuffer *rb, char c); -void rb_add_elements(ringbuffer *rb, char *buf, int n); -int rb_get_element(ringbuffer *rb); -int rb_get_elements(ringbuffer *rb, char *buf, int n); +void ringbuffer_init(ringbuffer_t *rb, char* buffer, unsigned int bufsize); +void rb_add_element(ringbuffer_t *rb, char c); +void rb_add_elements(ringbuffer_t *rb, char *buf, int n); +int rb_get_element(ringbuffer_t *rb); +int rb_get_elements(ringbuffer_t *rb, char *buf, int n); #endif /* __RINGBUFFER_H */ diff --git a/sys/uart0.c b/sys/uart0.c index 6907fa89be..5ba90d98ab 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -10,7 +10,7 @@ #define UART0_BUFSIZE (32) #define UART0_STACKSIZE (MINIMUM_STACK_SIZE + 256) -ringbuffer uart0_ringbuffer; +ringbuffer_t uart0_ringbuffer; int uart0_handler_pid; static char buffer[UART0_BUFSIZE]; From 5abef6daf2bcd9f625d1791fd64a76c1ef098e74 Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 8 Mar 2011 11:43:21 +0100 Subject: [PATCH 20/38] changed types irq_callback, hashtable, posix_io, s_display_flags, seq_buffer_entry, tcb, toprint to type_t" --- board/chronos/drivers/display.c | 2 +- board/chronos/drivers/include/display.h | 4 ++-- board/msba2-common/drivers/msba2-uart0.c | 8 ++++---- core/include/sched.h | 6 +++--- core/include/tcb.h | 4 ++-- core/kernel_init.c | 4 ++-- core/msg.c | 20 ++++++++++---------- core/mutex.c | 4 ++-- core/sched.c | 14 +++++++------- core/thread.c | 8 ++++---- cpu/lpc2387/lpc2387-gpioint.c | 10 +++++----- drivers/cc110x/cc1100_phy.c | 6 +++--- sys/chardev_thread.c | 4 ++-- sys/include/posix_io.h | 2 +- sys/posix_io.c | 2 +- sys/shell/ps.c | 2 +- 16 files changed, 50 insertions(+), 50 deletions(-) diff --git a/board/chronos/drivers/display.c b/board/chronos/drivers/display.c index 39774279b3..063ade5855 100644 --- a/board/chronos/drivers/display.c +++ b/board/chronos/drivers/display.c @@ -57,7 +57,7 @@ void display_symbol(uint8_t symbol, uint8_t mode); * Global Variable section */ /* Display flags */ -volatile s_display_flags display; +volatile s_display_flags_t display; /* Global return string for itoa function */ char itoa_str[8]; diff --git a/board/chronos/drivers/include/display.h b/board/chronos/drivers/include/display.h index 805d801d2e..3b7c2e131f 100644 --- a/board/chronos/drivers/include/display.h +++ b/board/chronos/drivers/include/display.h @@ -67,9 +67,9 @@ typedef union { uint16_t update_acceleration : 1; // 1 = Acceleration data was updated } flag; uint16_t all_flags; // Shortcut to all display flags (for reset) -} s_display_flags; +} s_display_flags_t; -extern volatile s_display_flags display; +extern volatile s_display_flags_t display; // Constants defined in library extern const uint8_t lcd_font[]; diff --git a/board/msba2-common/drivers/msba2-uart0.c b/board/msba2-common/drivers/msba2-uart0.c index 3107e8d40c..31a9870aaf 100644 --- a/board/msba2-common/drivers/msba2-uart0.c +++ b/board/msba2-common/drivers/msba2-uart0.c @@ -49,13 +49,13 @@ and the mailinglist (subscription via web site) * @note $Id$ */ -typedef struct toprint { +typedef struct toprint_t { unsigned int len; char content[]; -}toprint; +}toprint_t; #define QUEUESIZE 255 -static volatile toprint* queue[QUEUESIZE]; +static volatile toprint_t* queue[QUEUESIZE]; static volatile unsigned char queue_head = 0; static volatile unsigned char queue_tail = 0; static volatile unsigned char queue_items = 0; @@ -64,7 +64,7 @@ static volatile unsigned int actual_pos = 0; static volatile unsigned int running = 0; static volatile unsigned int fifo = 0; -static volatile toprint* actual = NULL; +static volatile toprint_t* actual = NULL; static inline void enqueue(void) { queue_items++; diff --git a/core/include/sched.h b/core/include/sched.h index ad30cfb601..bce3864310 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -24,13 +24,13 @@ void sched_init(); void sched_run(); -void sched_set_status(tcb *process, unsigned int status); +void sched_set_status(tcb_t *process, unsigned int status); void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr); volatile unsigned int sched_context_switch_request; -volatile tcb *sched_threads[MAXTHREADS]; -volatile tcb *active_thread; +volatile tcb_t *sched_threads[MAXTHREADS]; +volatile tcb_t *active_thread; extern volatile int num_tasks; volatile int thread_pid; diff --git a/core/include/tcb.h b/core/include/tcb.h index 8ca79c1905..9d6f5f26cf 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -35,7 +35,7 @@ #define STATUS_REPLY_BLOCKED (0x0100) #define STATUS_TIMER_WAITING (0x0200) -typedef struct tcb { +typedef struct tcb_t { char* sp; uint16_t status; @@ -53,7 +53,7 @@ typedef struct tcb { const char* name; char* stack_start; int stack_size; -} tcb; +} tcb_t; /** @} */ #endif /* TCB_H_ */ diff --git a/core/kernel_init.c b/core/kernel_init.c index fc9abc751e..6af76399cf 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -33,8 +33,8 @@ #define ENABLE_DEBUG #include -volatile tcb *sched_threads[MAXTHREADS]; -volatile tcb *active_thread; +volatile tcb_t *sched_threads[MAXTHREADS]; +volatile tcb_t *active_thread; volatile int lpm_prevent_sleep = 0; extern void main(void); diff --git a/core/msg.c b/core/msg.c index 05ff734b82..349caf7c54 100644 --- a/core/msg.c +++ b/core/msg.c @@ -27,7 +27,7 @@ //#define ENABLE_DEBUG #include "debug.h" -static int queue_msg(tcb *target, msg_t *m) { +static int queue_msg(tcb_t *target, msg_t *m) { int n = cib_put(&(target->msg_queue)); if (n != -1) { @@ -43,7 +43,7 @@ int msg_send(msg_t* m, unsigned int target_pid, bool block) { return msg_send_int(m, target_pid); } - tcb *target = (tcb*)sched_threads[target_pid]; + tcb_t *target = (tcb_t*)sched_threads[target_pid]; m->sender_pid = thread_pid; if (m->sender_pid == target_pid) { @@ -84,7 +84,7 @@ int msg_send(msg_t* m, unsigned int target_pid, bool block) { newstatus = STATUS_SEND_BLOCKED; } - sched_set_status((tcb*)active_thread, newstatus); + sched_set_status((tcb_t*)active_thread, newstatus); DEBUG("%s: back from send block.\n", active_thread->name); } else { @@ -102,7 +102,7 @@ int msg_send(msg_t* m, unsigned int target_pid, bool block) { } int msg_send_int(msg_t* m, unsigned int target_pid) { - tcb *target = (tcb*)sched_threads[target_pid]; + tcb_t *target = (tcb_t*)sched_threads[target_pid]; if (target->status == STATUS_RECEIVE_BLOCKED) { DEBUG("msg_send_int: direct msg copy.\n"); @@ -124,7 +124,7 @@ int msg_send_int(msg_t* m, unsigned int target_pid) { int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid) { dINT(); - tcb *me = (tcb*) sched_threads[thread_pid]; + tcb_t *me = (tcb_t*) sched_threads[thread_pid]; sched_set_status(me, STATUS_REPLY_BLOCKED); me->wait_data = (void*) reply; msg_send(m, target_pid, true); @@ -137,7 +137,7 @@ int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid) { int msg_reply(msg_t *m, msg_t *reply) { int state = disableIRQ(); - tcb *target = (tcb*)sched_threads[m->sender_pid]; + tcb_t *target = (tcb_t*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", active_thread->name, target->name); restoreIRQ(state); @@ -156,7 +156,7 @@ int msg_reply(msg_t *m, msg_t *reply) { } int msg_reply_int(msg_t *m, msg_t *reply) { - tcb *target = (tcb*)sched_threads[m->sender_pid]; + tcb_t *target = (tcb_t*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name); return -1; @@ -172,7 +172,7 @@ int msg_receive(msg_t* m) { dINT(); DEBUG("%s: msg_receive.\n", active_thread->name); - tcb *me = (tcb*) sched_threads[thread_pid]; + tcb_t *me = (tcb_t*) sched_threads[thread_pid]; int n = -1; if (me->msg_array) { @@ -202,7 +202,7 @@ int msg_receive(msg_t* m) { return 1; } else { DEBUG("%s: msg_receive(): Wakeing up waiting thread.\n", active_thread->name); - tcb *sender = (tcb*)node->data; + tcb_t *sender = (tcb_t*)node->data; if (n >= 0) { /* we've already got a messgage from the queue. as there is a @@ -227,7 +227,7 @@ int msg_receive(msg_t* m) { int msg_init_queue(msg_t* array, int num) { /* make sure brainfuck condition is met */ if (num && (num & (num - 1)) == 0) { - tcb *me = (tcb*)active_thread; + tcb_t *me = (tcb_t*)active_thread; me->msg_array = array; cib_init(&(me->msg_queue), num); return 0; diff --git a/core/mutex.c b/core/mutex.c index fd4b708a3e..b31f5a44a2 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -61,7 +61,7 @@ void mutex_wait(struct mutex_t *mutex) { return; } - sched_set_status((tcb*)active_thread, STATUS_MUTEX_BLOCKED); + sched_set_status((tcb_t*)active_thread, STATUS_MUTEX_BLOCKED); queue_node_t n; n.priority = (unsigned int) active_thread->priority; @@ -86,7 +86,7 @@ void mutex_unlock(struct mutex_t* mutex, int yield) { if (mutex->val != 0) { if (mutex->queue.next) { queue_node_t *next = queue_remove_head(&(mutex->queue)); - tcb* process = (tcb*)next->data; + tcb_t* process = (tcb_t*)next->data; DEBUG("%s: waking up waiter %s.\n", process->name); sched_set_status(process, STATUS_PENDING); diff --git a/core/sched.c b/core/sched.c index 0563e46f4f..9b33d386d8 100644 --- a/core/sched.c +++ b/core/sched.c @@ -56,7 +56,7 @@ void sched_init() { void sched_run() { sched_context_switch_request = 0; - tcb *my_active_thread = (tcb*)active_thread; + tcb_t *my_active_thread = (tcb_t*)active_thread; if (my_active_thread) { if( my_active_thread->status == STATUS_RUNNING) { @@ -94,9 +94,9 @@ void sched_run() { // if (runqueues[i]) { int nextrq = number_of_lowest_bit(runqueue_bitcache); clist_node_t next = *(runqueues[nextrq]); - DEBUG("scheduler: first in queue: %s\n", ((tcb*)next.data)->name); + DEBUG("scheduler: first in queue: %s\n", ((tcb_t*)next.data)->name); clist_advance(&(runqueues[nextrq])); - my_active_thread = (tcb*)next.data; + my_active_thread = (tcb_t*)next.data; thread_pid = (volatile int) my_active_thread->pid; #if SCHEDSTATISTICS pidlist[my_active_thread->pid].laststart = time; @@ -115,16 +115,16 @@ void sched_run() { active_thread->status = STATUS_PENDING ; } } - sched_set_status((tcb*)my_active_thread, STATUS_RUNNING); + sched_set_status((tcb_t*)my_active_thread, STATUS_RUNNING); } - active_thread = (volatile tcb*) my_active_thread; + active_thread = (volatile tcb_t*) my_active_thread; DEBUG("scheduler: done.\n"); } -void sched_set_status(tcb *process, unsigned int status) { +void sched_set_status(tcb_t *process, unsigned int status) { if (status & STATUS_ON_RUNQUEUE) { if (! (process->status & STATUS_ON_RUNQUEUE)) { DEBUG("adding process %s to runqueue %u.\n", process->name, process->priority); @@ -163,7 +163,7 @@ void sched_task_exit(void) { sched_threads[active_thread->pid] = NULL; num_tasks--; - sched_set_status((tcb*)active_thread, STATUS_STOPPED); + sched_set_status((tcb_t*)active_thread, STATUS_STOPPED); active_thread = NULL; cpu_switch_context_exit(); diff --git a/core/thread.c b/core/thread.c index e087f2a9d6..1a5bf82f7f 100644 --- a/core/thread.c +++ b/core/thread.c @@ -39,7 +39,7 @@ unsigned int thread_getstatus(int pid) { void thread_sleep() { if ( inISR()) return; dINT(); - sched_set_status((tcb*)active_thread, STATUS_SLEEPING); + sched_set_status((tcb_t*)active_thread, STATUS_SLEEPING); thread_yield(); } @@ -54,7 +54,7 @@ int thread_wakeup(int pid) { int result = sched_threads[pid]->status; if (result == STATUS_SLEEPING) { DEBUG("thread_wakeup: Thread is sleeping.\n"); - sched_set_status((tcb*)sched_threads[pid], STATUS_RUNNING); + sched_set_status((tcb_t*)sched_threads[pid], STATUS_RUNNING); if (!isr) { eINT(); thread_yield(); @@ -83,7 +83,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f { /* allocate our thread control block at the top of our stackspace */ int total_stacksize = stacksize; - stacksize -= sizeof(tcb); + stacksize -= sizeof(tcb_t); /* align tcb address on 32bit boundary */ unsigned int tcb_address = (unsigned int) stack + stacksize; @@ -95,7 +95,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f tcb_address-=2; stacksize-=2; } - tcb *cb = (tcb*) tcb_address; + tcb_t *cb = (tcb_t*) tcb_address; if (priority >= SCHED_PRIO_LEVELS) { return -EINVAL; diff --git a/cpu/lpc2387/lpc2387-gpioint.c b/cpu/lpc2387/lpc2387-gpioint.c index 7ce5941410..4941727454 100644 --- a/cpu/lpc2387/lpc2387-gpioint.c +++ b/cpu/lpc2387/lpc2387-gpioint.c @@ -48,12 +48,12 @@ and the mailinglist (subscription via web site) #include "cpu.h" #include -struct irq_callback { +struct irq_callback_t { fp_irqcb callback; }; -static struct irq_callback gpioint0[32]; -static struct irq_callback gpioint2[32]; +static struct irq_callback_t gpioint0[32]; +static struct irq_callback_t gpioint2[32]; void gpioint_init(void) { @@ -68,7 +68,7 @@ void gpioint_init(void) { bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { - struct irq_callback* cbdata; + struct irq_callback_t* cbdata; unsigned long bit; volatile unsigned long* en_f; volatile unsigned long* en_r; @@ -123,7 +123,7 @@ gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) return true; // success } /*---------------------------------------------------------------------------*/ -static void __attribute__ ((__no_instrument_function__)) test_irq(int port, unsigned long f_mask, unsigned long r_mask, struct irq_callback* pcb) +static void __attribute__ ((__no_instrument_function__)) test_irq(int port, unsigned long f_mask, unsigned long r_mask, struct irq_callback_t* pcb) { /* Test each bit of rising and falling masks, if set trigger interrupt * on corresponding device */ diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 76acfb33ac..d97a3857a6 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -119,10 +119,10 @@ typedef struct uint64_t m_ticks; ///< 64-bit timestamp uint8_t source; ///< Source address uint8_t identification; ///< Identification (1-bit) -} seq_buffer_entry; +} seq_buffer_entry_t; /// Sequence number buffer for this layer -static seq_buffer_entry seq_buffer[MAX_SEQ_BUFFER_SIZE]; +static seq_buffer_entry_t seq_buffer[MAX_SEQ_BUFFER_SIZE]; /// Next position to enter a new value into ::seqBuffer static uint8_t seq_buffer_pos = 0; @@ -186,7 +186,7 @@ void cc1100_phy_init() pm_init_table((pm_table_t*)&handler_table, MAX_PACKET_HANDLERS, handlers); // Clear sequence number buffer - memset(seq_buffer, 0, sizeof(seq_buffer_entry) * MAX_SEQ_BUFFER_SIZE); + memset(seq_buffer, 0, sizeof(seq_buffer_entry_t) * MAX_SEQ_BUFFER_SIZE); // Initialize mutex cc1100_mutex_pid = -1; diff --git a/sys/chardev_thread.c b/sys/chardev_thread.c index 6f70af7dfe..d307829267 100644 --- a/sys/chardev_thread.c +++ b/sys/chardev_thread.c @@ -22,7 +22,7 @@ void chardev_loop(ringbuffer_t *rb) { int pid = thread_getpid(); int reader_pid = -1; - struct posix_iop *r = NULL; + struct posix_iop_t *r = NULL; puts("UART0 thread started."); @@ -46,7 +46,7 @@ void chardev_loop(ringbuffer_t *rb) { m.content.value = -EINVAL; msg_reply(&m, &m); } else { - r = (struct posix_iop *)m.content.ptr; + r = (struct posix_iop_t *)m.content.ptr; } break; case CLOSE: diff --git a/sys/include/posix_io.h b/sys/include/posix_io.h index 656e1ea3e4..b39bdb3a38 100644 --- a/sys/include/posix_io.h +++ b/sys/include/posix_io.h @@ -6,7 +6,7 @@ #define READ 2 #define WRITE 3 -struct posix_iop { +struct posix_iop_t { int nbytes; char *buffer; }; diff --git a/sys/posix_io.c b/sys/posix_io.c index 9d277af2fd..63ec13621b 100644 --- a/sys/posix_io.c +++ b/sys/posix_io.c @@ -12,7 +12,7 @@ static int _posix_fileop(int pid, int op, int flags) { } static int _posix_fileop_data(int pid, int op, char* buffer, int nbytes) { - struct posix_iop r; + struct posix_iop_t r; r.nbytes = nbytes; r.buffer = buffer; diff --git a/sys/shell/ps.c b/sys/shell/ps.c index 0848bd5090..6c3226fead 100644 --- a/sys/shell/ps.c +++ b/sys/shell/ps.c @@ -27,7 +27,7 @@ void thread_print_all(void) printf("\tpid | %-21s| %-9sQ | pri | stack ( used) location | runtime | switches \n", "name", "state"); for( i = 0; i < MAXTHREADS; i++ ) { - tcb* p = (tcb*)sched_threads[i]; + tcb_t* p = (tcb_t*)sched_threads[i]; if( p != NULL ) { int state = p->status; // copy state From bc23a41a30719eb1d95105056871d9e544b0b1a6 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 18 Mar 2011 15:59:50 +0100 Subject: [PATCH 21/38] * some changes to chronos (not yet finished) --- board/chronos/drivers/Jamfile | 1 + board/chronos/drivers/battery.c | 4 +- board/chronos/drivers/include/battery.h | 2 +- cpu/cc430/cc430-adc.c | 2 - cpu/cc430/cc430-rtc.c | 2 + drivers/Jamfile | 2 + projects/chronos_default/Jamfile | 2 +- projects/chronos_default/main.c | 57 ++++++++++++++++++++----- 8 files changed, 55 insertions(+), 17 deletions(-) diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index 286616c5d9..71ee1c982c 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -6,5 +6,6 @@ Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; Module battery : battery.c : adc hwtimer ; +Module vti_ps_twi : vti_ps_twi.c : hwtimer ; Module display_putchar : display_putchar.c : board_display ; diff --git a/board/chronos/drivers/battery.c b/board/chronos/drivers/battery.c index 69553fc451..bae37d3295 100644 --- a/board/chronos/drivers/battery.c +++ b/board/chronos/drivers/battery.c @@ -2,8 +2,8 @@ #include #include -uint16_t battery_get_voltate(void) { - uint16_t voltage; +uint32_t battery_get_voltage(void) { + uint32_t voltage; voltage = adc12_single_conversion(REFVSEL_1, ADC12SHT0_10, ADC12INCH_11); /* Ideally we have A11=0->AVCC=0V ... A11=4095(2^12-1)->AVCC=4V diff --git a/board/chronos/drivers/include/battery.h b/board/chronos/drivers/include/battery.h index 6b206c6eca..c6381b721b 100644 --- a/board/chronos/drivers/include/battery.h +++ b/board/chronos/drivers/include/battery.h @@ -1,6 +1,6 @@ #ifndef BATTERY_H #define BATTERY_H -uint16_t battery_get_voltate(void); +uint32_t battery_get_voltage(void); #endif /* BATTERY_H */ diff --git a/cpu/cc430/cc430-adc.c b/cpu/cc430/cc430-adc.c index 470725ad70..3617d155c6 100644 --- a/cpu/cc430/cc430-adc.c +++ b/cpu/cc430/cc430-adc.c @@ -59,7 +59,6 @@ uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel) { ADC12CTL1 = ADC12SHP; /* Enable sample timer */ ADC12MCTL0 = ADC12SREF_1 + channel; /* ADC input channel */ ADC12IE = 0x001; /* ADC_IFG upon conv result-ADCMEMO */ - eINT(); /* Wait 2 ticks (66us) to allow internal reference to settle */ @@ -88,7 +87,6 @@ uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel) { ADC12IE = 0; /* Return ADC result */ - dINT(); return adc12_result; } diff --git a/cpu/cc430/cc430-rtc.c b/cpu/cc430/cc430-rtc.c index 8895e05996..44aa93f18c 100644 --- a/cpu/cc430/cc430-rtc.c +++ b/cpu/cc430/cc430-rtc.c @@ -42,7 +42,9 @@ void rtc_init(void) { RTCCTL1 |= RTCMODE_H; /* enable ready interrupt (every second) */ +#ifndef ENABLE_DEBUG RTCCTL0 |= RTCRDYIE; +#endif } /*---------------------------------------------------------------------------*/ diff --git a/drivers/Jamfile b/drivers/Jamfile index 3dbeed6d7c..09eba8ba4e 100644 --- a/drivers/Jamfile +++ b/drivers/Jamfile @@ -31,5 +31,7 @@ Module sht11 : sht11.c : hwtimer ; Module ltc4150 : ltc4150.c : board_ltc4150 hwtimer ; +Module vti_ps : vti_ps.c : vti_ps_twi ; + SubInclude TOP drivers cc110x ; SubInclude TOP drivers cc110x_ng ; diff --git a/projects/chronos_default/Jamfile b/projects/chronos_default/Jamfile index 0198f8ae66..0e68768aa2 100644 --- a/projects/chronos_default/Jamfile +++ b/projects/chronos_default/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects chronos_default ; -Module chronos_default : main.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint display_putchar ; +Module chronos_default : main.c altitude.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint display_putchar battery vti_ps ; UseModule chronos_default ; diff --git a/projects/chronos_default/main.c b/projects/chronos_default/main.c index f521910d7f..6a34f6982a 100644 --- a/projects/chronos_default/main.c +++ b/projects/chronos_default/main.c @@ -15,7 +15,18 @@ #include #include #include +#include +#include +#include "altitude.h" + +#define BUTTON_EVENT_STAR (0x01) +#define BUTTON_EVENT_NUM (0x02) +#define BUTTON_EVENT_UP (0x04) +#define BUTTON_EVENT_DOWN (0x08) +#define BUTTON_EVENT_BACKLIGHT (0x10) + +#define BUTTON_HANDLER_STACK_SIZE (256) #define RADIO_STACK_SIZE (512) #define SEND_SIZE CC1100_MAX_DATA_LENGTH @@ -24,6 +35,7 @@ #define SENDING_DELAY (5 * 1000) char radio_stack_buffer[RADIO_STACK_SIZE]; +char button_handler_stack_buffer[BUTTON_HANDLER_STACK_SIZE]; uint8_t snd_buffer[SEND_SIZE]; @@ -33,6 +45,8 @@ static msg mesg; static transceiver_command_t tcmd; static radio_packet_t p; +static int button_handler_pid; +static uint8_t button_event = 0; static uint8_t mode = 0; void send(radio_address_t dst, uint8_t len, uint8_t *data); @@ -73,20 +87,30 @@ void radio(void) { } } +void button_handler(void) { + while (1) { + if (button_event & BUTTON_EVENT_STAR) { + buzzer_beep(15, 5000); + mode++; + button_event &= ~BUTTON_EVENT_STAR; + } + thread_sleep(); + } +} + void change_mode(void) { - buzzer_beep(15, 5000); - if (mode) { - mode = 0; - } - else { - mode = 1; - } + button_event |= BUTTON_EVENT_STAR; + thread_wakeup(button_handler_pid); } int main(void) { int radio_pid; + uint32_t voltage; struct tm now; + ps_init(); + reset_altitude_measurement(); + now.tm_hour = 3; now.tm_min = 59; now.tm_sec = 42; @@ -97,10 +121,12 @@ int main(void) { rtc_set_alarm(&now, RTC_ALARM_MIN); + button_handler_pid = thread_create(button_handler_stack_buffer, BUTTON_HANDLER_STACK_SIZE, PRIORITY_MAIN+1, CREATE_STACKTEST, button_handler, "button_handler"); gpioint_set(2, BUTTON_STAR_PIN, (GPIOINT_RISING_EDGE | GPIOINT_DEBOUNCE), change_mode); radio_address_t addr = 43; memset(snd_buffer, 43, 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(); @@ -115,17 +141,26 @@ int main(void) { msg_send(&mesg, transceiver_pid, 1); send(12, SEND_SIZE, snd_buffer); - +*/ while (1) { hwtimer_wait(SENDING_DELAY); rtc_get_localtime(&now); - + + voltage = battery_get_voltage(); switch (mode) { case 0: - printf("\n%02u:%02u", now.tm_hour, now.tm_min); + printf("\n%lu", voltage); break; case 1: - printf("\n%02u", now.tm_sec); + printf("\n%02u:%02u", now.tm_hour, now.tm_min); + break; + case 2: + start_altitude_measurement(); + printf("\n%u", sAlt.altitude); + stop_altitude_measurement(); + break; + default: + mode = 0; break; } } From 0e6e0a46473b5ef7e73f30bf4e733152404f55f3 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 25 Mar 2011 11:42:58 +0100 Subject: [PATCH 22/38] * deleted falsy comment symbols --- tools/pyterm/pyterm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pyterm/pyterm.py b/tools/pyterm/pyterm.py index 59eadcfbd1..d2b58da3d5 100755 --- a/tools/pyterm/pyterm.py +++ b/tools/pyterm/pyterm.py @@ -22,8 +22,8 @@ class SerCmd(cmd.Cmd): sys.stderr.write("No port specified!\n") sys.exit(-1) self.ser = serial.Serial(port=self.port, baudrate=115200, dsrdtr=0, rtscts=0) - #self.ser.setDTR(0) - #self.ser.setRTS(0) + self.ser.setDTR(0) + self.ser.setRTS(0) # start serial->console thread receiver_thread = threading.Thread(target=reader, args=(self.ser,)) From 23cd123bdbd763ea96e5bb626d49ddd9f1e619ed Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 4 Apr 2011 13:15:21 +0200 Subject: [PATCH 23/38] [core thread] * fixed wrong struct name in macro --- core/include/thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/thread.h b/core/include/thread.h index 359d778d91..77eea8d4ba 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -17,7 +17,7 @@ #include /** Minimum stack size */ -#define MINIMUM_STACK_SIZE (sizeof(tcb)) +#define MINIMUM_STACK_SIZE (sizeof(tcb_t)) /** * @brief Creates a new thread. From c0af1a81893e363c0094dd2c66f3d887bcc1d649 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 4 Apr 2011 13:28:33 +0200 Subject: [PATCH 24/38] [projects WEAtHeR] * added project --- projects/WEAtHeR/Jamfile | 5 +++++ projects/WEAtHeR/main.c | 33 ++++++++++++++++++++++++++++++ projects/WEAtHeR/tests/hello-world | 13 ++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 projects/WEAtHeR/Jamfile create mode 100644 projects/WEAtHeR/main.c create mode 100755 projects/WEAtHeR/tests/hello-world diff --git a/projects/WEAtHeR/Jamfile b/projects/WEAtHeR/Jamfile new file mode 100644 index 0000000000..d2eb26f50e --- /dev/null +++ b/projects/WEAtHeR/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects weather ; + +Module weather : main.c : sht11 ltc4150 swtimer auto_init ; + +UseModule weather ; diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c new file mode 100644 index 0000000000..2c248b1173 --- /dev/null +++ b/projects/WEAtHeR/main.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include + +int main(void) +{ + sht11_val_t sht11_val; + double mAh = 0; + + uint8_t success = 0; + + puts(""); + puts("WEAtHeR: Wireless Energy-Aware mulTi-Hop sEnsor Reading."); + puts("Printing \"temperature in °C;relative humidity;temperature compensated relative humidity\"."); + puts(""); + + ltc4150_start(); + + while (1) { + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + mAh = ltc4150_get_total_mAh(); + if (!success) { + printf("error;error;error\n"); + } + else { + printf("%.2f;%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp, mAh); + } + LED_RED_TOGGLE; + swtimer_usleep(60 * 1000*1000); + } +} diff --git a/projects/WEAtHeR/tests/hello-world b/projects/WEAtHeR/tests/hello-world new file mode 100755 index 0000000000..acde8265fe --- /dev/null +++ b/projects/WEAtHeR/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" + From 364905f0d6ad8332235d390b573d8e67f80a26d4 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 4 Apr 2011 20:33:18 +0200 Subject: [PATCH 25/38] [projects WEAtHeR] * updated project by adding routing functionality --- projects/WEAtHeR/Jamfile | 6 +- projects/WEAtHeR/main.c | 193 ++++++++++++++++++++++-- projects/WEAtHeR/protocol_msg_gateway.c | 54 +++++++ projects/WEAtHeR/protocol_msg_gateway.h | 18 +++ projects/WEAtHeR/weather_protocol.h | 41 +++++ projects/WEAtHeR/weather_routing.c | 60 ++++++++ projects/WEAtHeR/weather_routing.h | 17 +++ 7 files changed, 374 insertions(+), 15 deletions(-) create mode 100644 projects/WEAtHeR/protocol_msg_gateway.c create mode 100644 projects/WEAtHeR/protocol_msg_gateway.h create mode 100644 projects/WEAtHeR/weather_protocol.h create mode 100644 projects/WEAtHeR/weather_routing.c create mode 100644 projects/WEAtHeR/weather_routing.h diff --git a/projects/WEAtHeR/Jamfile b/projects/WEAtHeR/Jamfile index d2eb26f50e..3576888c65 100644 --- a/projects/WEAtHeR/Jamfile +++ b/projects/WEAtHeR/Jamfile @@ -1,5 +1,5 @@ -SubDir TOP projects weather ; +SubDir TOP projects WEAtHeR ; -Module weather : main.c : sht11 ltc4150 swtimer auto_init ; +Module WEAtHeR : main.c weather_routing.c protocol_msg_gateway.c : sht11 ltc4150 cc110x gpioint swtimer shell shell_commands posix_io uart0 auto_init rtc ; -UseModule weather ; +UseModule WEAtHeR ; diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index 2c248b1173..878c5bba34 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -3,31 +3,200 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -int main(void) -{ +#include "weather_routing.h" +#include "weather_protocol.h" +#include "protocol_msg_gateway.h" + +#define SHELL_STACK_SIZE (2048) +#define PH_STACK_SIZE (2048) + +/* per default not acting as data sink */ +static uint8_t data_sink = 0; +static uint8_t data_src = 0; + +char shell_stack_buffer[SHELL_STACK_SIZE]; +char ph_stack_buffer[PH_STACK_SIZE]; + +void weather_send(char* unused); +void weather_sink(char* unused); + +shell_t shell; +const shell_command_t sc[] = { + {"sender", "Enables node as data source.", weather_send}, + {"sink", "Enables node as data sink.", weather_sink}, + {NULL, NULL, NULL}}; + +void shell_runner(void) { + shell_init(&shell, sc, uart0_readc, uart0_putc); + posix_open(uart0_handler_pid, 0); + shell_run(&shell); +} + +void weather_send(char* unused) { + if (data_src) { + data_src = 0; + puts("Disabling data source mode."); + } + else { + data_src = 1; + puts("Enabling data source mode."); + } +} + +void weather_sink(char* unused) { + if (data_sink) { + data_sink = 0; + puts("Disabling data sink mode."); + } + else { + data_sink = 1; + puts("Enabling data sink mode."); + } +} + +static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { + weather_packet_header_t *header = (weather_packet_header_t*) msg; + + printf("\n\t Pkt received from phy: %u\n" + "\t -> SEQ: %u | TYPE: %u | SRC: %hu \n\n", + packet_info->phy_src, + header->seq_nr, + header->type, + header->src + ); + + /* when destination is set, but I'm not the receiver, pass to routing */ + if (!data_sink) { + if (header->type == WEATHER_DATA) { + weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + /* ;;;;;;; */ + printf("%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", + header->src, + 0, + wdp->timestamp, + 0, + wdp->temperature, + wdp->relhum, + wdp->relhum_temp, + wdp->energy); + } + + puts("Not for me, routing, baby!"); + route_packet(msg, msg_size); + return; + } + + /* in all other cases handle the packet */ + switch (header->type) { + case WEATHER_HELLO: { + if (msg_size < sizeof(weather_hello_pkt_t)) { + puts("Bad hello packet received."); + } else { + puts("Hello packet received - no handler implemented"); + } + break; + } + case WEATHER_CHAT: { + puts("\n*================================================================================*"); + printf("\tCHAT MESSAGE from %hu: %s\n\n", packet_info->phy_src, ((weather_chat_pkt_t*) msg)->mesg); + puts("*================================================================================*\n"); + break; + } + case WEATHER_DATA: { + weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + time_t local_time = rtc_time(NULL); + /* ;;;;;;; */ + printf("%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f\n", + header->src, + 1, + wdp->timestamp, + local_time, + wdp->temperature, + wdp->relhum, + wdp->relhum_temp, + wdp->energy); + break; + } + default: { + printf("Unknown packet type \"%i\" received.", header->type); + } + } +} + +/* endless loop for packet handling */ +static void protocol_handler_thread(void) { + msg_t m; + puts("Protocol handler thread started."); + + while(1) { + msg_receive(&m); + + packet_t packet; + int pos = m.content.value; + packet = packet_buffer[pos]; + + handle_packet(packet.payload, packet.msg_size, &(packet.packet_info)); + } +} + +int main(void) { + weather_data_pkt_t wdp; sht11_val_t sht11_val; - double mAh = 0; uint8_t success = 0; + + wdp.header.seq_nr = 0; + wdp.header.type = WEATHER_DATA; puts(""); puts("WEAtHeR: Wireless Energy-Aware mulTi-Hop sEnsor Reading."); - puts("Printing \"temperature in °C;relative humidity;temperature compensated relative humidity\"."); + /* ;;;;;;; */ + puts("Printing \"node id of data source;node id of sink;timestamp of measurement;timestamp at data sink;temperature in °C;relative humidity;temperature compensated relative humidity;energy value\"."); puts(""); + thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); + + /* create thread for radio packet handling */ + int pid = thread_create(ph_stack_buffer, PH_STACK_SIZE, PRIORITY_MAIN-5, CREATE_STACKTEST, protocol_handler_thread, "protocol_handler"); + set_protocol_handler_thread(pid); + ltc4150_start(); + rtc_enable(); while (1) { - success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); - mAh = ltc4150_get_total_mAh(); - if (!success) { - printf("error;error;error\n"); + if (data_src) { + wdp.header.src = cc1100_get_address(); + wdp.timestamp = rtc_time(NULL); + wdp.energy = ltc4150_get_total_mAh(); + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + if (!success) { + printf("error;error;error\n"); + } + else { + wdp.temperature = sht11_val.temperature; + wdp.relhum = sht11_val.relhum; + wdp.relhum_temp = sht11_val.relhum_temp; + if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)&wdp, sizeof(weather_data_pkt_t))) { + printf("Successfully sent packet: \n"); + wdp.header.seq_nr++; + } + else { + puts("Error on sending packet!"); + } + } + LED_RED_TOGGLE; } - else { - printf("%.2f;%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp, mAh); - } - LED_RED_TOGGLE; swtimer_usleep(60 * 1000*1000); } } diff --git a/projects/WEAtHeR/protocol_msg_gateway.c b/projects/WEAtHeR/protocol_msg_gateway.c new file mode 100644 index 0000000000..1e439c5d53 --- /dev/null +++ b/projects/WEAtHeR/protocol_msg_gateway.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include "protocol_msg_gateway.h" + +#define NUM_PROTOCOL_HANDLER_PIDS 8 + +static uint16_t protocol_handler_pid; + +static int packet_buffer_next = 0; +packet_t packet_buffer[PACKET_BUFFER_SIZE]; + +static void protocol_msg_gateway(void* payload, int msg_size, protocol_t protocol, packet_info_t* packet_info) { + msg_t m; + +// if ((((int16_t) packet_info->phy_src) > (((int16_t) cc1100_get_address()) + 10)) || (((int16_t) packet_info->phy_src) < (((int16_t) cc1100_get_address()) - 10))) { + // return; + // } + if (protocol_handler_pid <= 0) { + puts("protocol_handler(): received packet without protocol handler. msg dropped."); + return; + } + + int mypos = packet_buffer_next++; + if (packet_buffer_next == PACKET_BUFFER_SIZE) packet_buffer_next = 0; + + packet_t *p = &(packet_buffer[mypos]); + p->packet_info = *packet_info; + p->msg_size = msg_size; + memcpy(p->payload, payload, msg_size); + + m.type = 0; + m.content.value = mypos; + int success = msg_send_int(&m, protocol_handler_pid); + if (! success) { + /* should set timer to retry. Dropping pkt for now. */ + puts("protocol_handler(): msg dropped."); + } +} + +void init_protocol_msg_gateway() { + cc1100_set_packet_monitor(protocol_msg_gateway); +} + +int set_protocol_handler_thread(int pid) { + protocol_handler_pid = pid; + return 0; +} diff --git a/projects/WEAtHeR/protocol_msg_gateway.h b/projects/WEAtHeR/protocol_msg_gateway.h new file mode 100644 index 0000000000..dd190da99f --- /dev/null +++ b/projects/WEAtHeR/protocol_msg_gateway.h @@ -0,0 +1,18 @@ +#ifndef __PROTOCOL_MSG_GATEWAY_H +#define __PROTOCOL_MSG_GATEWAY_H + +#define PACKET_BUFFER_SIZE 32 +#define MAXIMUM_PAYLOAD_SIZE 64 + +typedef struct { + packet_info_t packet_info; + unsigned int msg_size; + char payload[MAXIMUM_PAYLOAD_SIZE]; +} packet_t; + +void init_protocol_msg_gateway(); +int set_protocol_handler_thread(int pid); + +extern packet_t packet_buffer[PACKET_BUFFER_SIZE]; + +#endif /* __PROTOCOL_MSG_GATEWAY_H */ diff --git a/projects/WEAtHeR/weather_protocol.h b/projects/WEAtHeR/weather_protocol.h new file mode 100644 index 0000000000..f504204c92 --- /dev/null +++ b/projects/WEAtHeR/weather_protocol.h @@ -0,0 +1,41 @@ +#ifndef WEATHER_PROTOCOL_H_ +#define WEATHER_PROTOCOL_H_ + +#include +#include + +#define WEATHER_PROTOCOL_NR 6 + +typedef enum { + WEATHER_HELLO, + WEATHER_CHAT, + WEATHER_DATA +} packet_types; + +typedef struct { + uint16_t seq_nr; + uint8_t src; + uint8_t type; + uint8_t resevered; +} weather_packet_header_t; + +typedef struct __attribute__ ((packed)) { + weather_packet_header_t header; +} weather_hello_pkt_t; + +typedef struct { + weather_packet_header_t header; + uint8_t len; + char mesg[40]; +} weather_chat_pkt_t; + +typedef struct { + weather_packet_header_t header; + time_t timestamp; + double temperature; + double relhum; + double relhum_temp; + double energy; +} weather_data_pkt_t; + +#endif diff --git a/projects/WEAtHeR/weather_routing.c b/projects/WEAtHeR/weather_routing.c new file mode 100644 index 0000000000..8c354b0215 --- /dev/null +++ b/projects/WEAtHeR/weather_routing.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include "weather_protocol.h" +#include "weather_routing.h" + +static source_timestamp_t sources[MAX_SOURCES]; + +static uint8_t update_sources(uint8_t id, time_t timestamp) { + uint8_t i; + for (i = 0; i < MAX_SOURCES; i++) { + /* source id found */ + if (sources[i].id == id) { + /* more current timestamp received, updating */ + if (sources[i].timestamp < timestamp) { + sources[i].timestamp = timestamp; + return 1; + } + /* older, but still valid timestamp, not updating */ + else if (sources[i].timestamp < timestamp + MAX_INTERVAL) { + return 1; + } + /* timestamp too old, discard this packet */ + else { + puts("Timestamp too old, not routing"); + return 0; + } + } + /* source id not yet stored creating new entry */ + else if (!sources[i].id) { + sources[i].id = id; + sources[i].timestamp = timestamp; + return 1; + } + } + puts("No more sources could be stored!"); + return 0; +} + +void route_packet(void* msg, int msg_size) { + weather_packet_header_t *header = (weather_packet_header_t*) msg; + if (header->type == WEATHER_DATA) { + weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + if (!update_sources(wdp->header.src, wdp->timestamp)) { + return; + } + } + + if ((100.0 * rand()/(double) RAND_MAX) <= FLOODING_PROB) { + printf("Broadcasting packet..."); + if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)msg, msg_size)) { + puts("successful!"); + } + else { + puts("failed!"); + } + } +} + diff --git a/projects/WEAtHeR/weather_routing.h b/projects/WEAtHeR/weather_routing.h new file mode 100644 index 0000000000..14d050177e --- /dev/null +++ b/projects/WEAtHeR/weather_routing.h @@ -0,0 +1,17 @@ +#ifndef WEATHER_ROUTING_H +#define WEATHER_ROUTING_H + +#include + +#define FLOODING_PROB (100) +#define MAX_SOURCES (10) +#define MAX_INTERVAL (5 * 60) + +typedef struct { + uint8_t id; + time_t timestamp; +} source_timestamp_t; + +void route_packet(void* msg, int msg_size); + +#endif /* WEATHER_ROUTING_H */ From 430bad0d69c687e91b933d9dd9c457b0fd84d184 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 6 Apr 2011 11:09:29 +0200 Subject: [PATCH 26/38] [drivers cc110x] * fixed cc110x driver (some references where broken due to renaming of spi functions from cc1100_* to cc110x_* --- drivers/cc110x/Jamfile | 2 +- drivers/cc110x/arch_cc1100.h | 16 +++++----- drivers/cc110x/cc1100-csmaca-mac.c | 13 ++++---- drivers/cc110x/cc1100.c | 48 +++++++++++++++--------------- drivers/cc110x/cc1100_phy.c | 7 +++-- drivers/cc110x/cc1100_spi.c | 46 ++++++++++++++-------------- drivers/cc110x/cc1100_spi.h | 14 ++++----- 7 files changed, 74 insertions(+), 72 deletions(-) diff --git a/drivers/cc110x/Jamfile b/drivers/cc110x/Jamfile index b96d897d9e..528cef8d1b 100755 --- a/drivers/cc110x/Jamfile +++ b/drivers/cc110x/Jamfile @@ -31,5 +31,5 @@ HDRS += $(TOP)/drivers/cc110x ; Module cc110x : cc1100.c cc1100-csmaca-mac.c cc1100-defaultSettings.c cc1100_phy.c cc1100_spi.c - : board_cc1100 swtimer protocol_multiplex gpioint ; + : board_cc110x swtimer protocol_multiplex gpioint ; diff --git a/drivers/cc110x/arch_cc1100.h b/drivers/cc110x/arch_cc1100.h index ef61dd61c9..7c8b018a50 100644 --- a/drivers/cc110x/arch_cc1100.h +++ b/drivers/cc110x/arch_cc1100.h @@ -38,13 +38,13 @@ and the mailinglist (subscription via web site) #include -uint8_t cc1100_txrx(uint8_t c); +uint8_t cc110x_txrx(uint8_t c); -void cc1100_gdo0_enable(void); -void cc1100_gdo0_disable(void); -void cc1100_gdo2_enable(void); -void cc1100_gdo2_disable(void); -void cc1100_init_interrupts(void); +void cc110x_gdo0_enable(void); +void cc110x_gdo0_disable(void); +void cc110x_gdo2_enable(void); +void cc110x_gdo2_disable(void); +void cc110x_init_interrupts(void); -void cc1100_before_send(void); -void cc1100_after_send(void); +void cc110x_before_send(void); +void cc110x_after_send(void); diff --git a/drivers/cc110x/cc1100-csmaca-mac.c b/drivers/cc110x/cc1100-csmaca-mac.c index fab9610cc3..3dc9c3b2fa 100644 --- a/drivers/cc110x/cc1100-csmaca-mac.c +++ b/drivers/cc110x/cc1100-csmaca-mac.c @@ -38,7 +38,7 @@ and the mailinglist (subscription via web site) */ #include -//#include +#include #include #include "cc1100.h" @@ -47,6 +47,7 @@ and the mailinglist (subscription via web site) #include "protocol-multiplex.h" #include "hwtimer.h" +#include /*---------------------------------------------------------------------------*/ @@ -106,9 +107,9 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit collisions_per_sec = 0; collision_state = COLLISION_STATE_MEASURE; } else if (collision_state == COLLISION_STATE_MEASURE) { - uint64_t timespan = swtimer_now() - collision_measurement_start; - if (timespan > 1000000) { - collisions_per_sec = (collision_count * 1000000) / (double) timespan; + uint64_t timespan = swtimer_now() - collision_measurement_start; + if (timespan > 1000000) { + collisions_per_sec = (collision_count * 1000000) / (double) timespan; if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) { collision_measurement_start = swtimer_now(); collision_state = COLLISION_STATE_KEEP; @@ -120,8 +121,8 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit } } } else if (collision_state == COLLISION_STATE_KEEP) { - uint64_t timespan = swtimer_now() - collision_measurement_start; - if (timespan > 5000000) { + uint64_t timespan = swtimer_now() - collision_measurement_start; + if (timespan > 5000000) { collision_state = COLLISION_STATE_INITIAL; } } diff --git a/drivers/cc110x/cc1100.c b/drivers/cc110x/cc1100.c index 5b671b3ad8..7199694d23 100644 --- a/drivers/cc110x/cc1100.c +++ b/drivers/cc110x/cc1100.c @@ -160,19 +160,19 @@ volatile int wor_hwtimer_id = -1; void cc1100_disable_interrupts(void) { - cc1100_gdo2_disable(); - cc1100_gdo0_disable(); + cc110x_gdo2_disable(); + cc110x_gdo0_disable(); } -void cc1100_gdo0_irq(void) +void cc110x_gdo0_irq(void) { // Air was not free -> Clear CCA flag rflags.CAA = false; // Disable carrier sense detection (GDO0 interrupt) - cc1100_gdo0_disable(); + cc110x_gdo0_disable(); } -void cc1100_gdo2_irq(void) +void cc110x_gdo2_irq(void) { cc1100_phy_rx_handler(); } @@ -251,9 +251,9 @@ bool cc1100_spi_receive_packet(uint8_t *rxBuffer, uint8_t length) void cc1100_set_idle(void) { if (radio_state == RADIO_WOR) { // Wake up the chip from WOR/sleep - cc1100_spi_select(); + cc110x_spi_select(); hwtimer_wait(RTIMER_TICKS(122)); - cc1100_spi_unselect(); + cc110x_spi_unselect(); radio_state = RADIO_IDLE; // XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) hwtimer_wait(FS_CAL_TIME); @@ -292,9 +292,9 @@ static void wakeup_from_wor(void) return; } // Wake up the chip from WOR/sleep - cc1100_spi_select(); + cc110x_spi_select(); hwtimer_wait(RTIMER_TICKS(122)); - cc1100_spi_unselect(); + cc110x_spi_unselect(); radio_state = RADIO_IDLE; // XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) hwtimer_wait(FS_CAL_TIME); @@ -305,7 +305,7 @@ static void wakeup_from_wor(void) */ void switch_to_wor2(void) { - if (cc1100_get_gdo2()) return; // If incoming packet, then don't go to WOR now + if (cc110x_get_gdo2()) return; // If incoming packet, then don't go to WOR now cc1100_spi_strobe(CC1100_SIDLE); // Put CC1100 to IDLE radio_state = RADIO_IDLE; // Radio state now IDLE cc1100_spi_write_reg(CC1100_MCSM2, @@ -336,7 +336,7 @@ static void hwtimer_switch_to_wor2_wrapper(void* ptr) static void switch_to_wor(void) { // Any incoming packet? - if (cc1100_get_gdo2()) + if (cc110x_get_gdo2()) { // Then don't go to WOR now return; @@ -558,16 +558,16 @@ void cc1100_hwtimer_go_receive_wrapper(void *ptr) static void reset(void) { cc1100_go_idle(); - cc1100_spi_select(); + cc110x_spi_select(); cc1100_spi_strobe(CC1100_SRES); hwtimer_wait(RTIMER_TICKS(10)); } static void power_up_reset(void) { - cc1100_spi_unselect(); - cc1100_spi_cs(); - cc1100_spi_unselect(); + cc110x_spi_unselect(); + cc110x_spi_cs(); + cc110x_spi_unselect(); hwtimer_wait(RESET_WAIT_TIME); reset(); radio_state = RADIO_IDLE; @@ -587,7 +587,7 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size) if (size > PACKET_LENGTH) return; // Disables RX interrupt etc. - cc1100_before_send(); + cc110x_before_send(); // But CC1100 in IDLE mode to flush the FIFO cc1100_spi_strobe(CC1100_SIDLE); @@ -600,7 +600,7 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size) unsigned int cpsr = disableIRQ(); cc1100_spi_strobe(CC1100_STX); // Wait for GDO2 to be set -> sync word transmitted - while (cc1100_get_gdo2() == 0) { + while (cc110x_get_gdo2() == 0) { abort_count++; if (abort_count > CC1100_SYNC_WORD_TX_TIME) { // Abort waiting. CC1100 maybe in wrong mode @@ -611,9 +611,9 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size) } restoreIRQ(cpsr); // Wait for GDO2 to be cleared -> end of packet - while (cc1100_get_gdo2() != 0); + while (cc110x_get_gdo2() != 0); // Experimental - TOF Measurement - cc1100_after_send(); + cc110x_after_send(); } /*---------------------------------------------------------------------------*/ @@ -742,7 +742,7 @@ rssi_2_dbm(uint8_t rssi) void cc1100_init(void) { // Initialize SPI - cc1100_spi_init(); + cc110x_spi_init(); // Set default mode (with default (energy optimized) RX interval) cc1100_set_mode0(CC1100_RADIO_MODE, T_RX_INTERVAL); @@ -834,7 +834,7 @@ rd_set_mode(int mode) switch (mode) { case RADIO_MODE_ON: - cc1100_init_interrupts(); // Enable interrupts + cc110x_init_interrupts(); // Enable interrupts cc1100_setup_mode(); // Set chip to desired mode break; case RADIO_MODE_OFF: @@ -877,19 +877,19 @@ void cc1100_cs_set_enabled(bool enabled) if (enabled) { // Enable carrier sense detection (GDO0 interrupt) - cc1100_gdo0_enable(); + cc110x_gdo0_enable(); } else { // Disable carrier sense detection (GDO0 interrupt) - cc1100_gdo0_disable(); + cc110x_gdo0_disable(); } } int cc1100_cs_read(void) { /* GDO0 reflects CS (high: air not free, low: air free) */ - return cc1100_get_gdo0(); + return cc110x_get_gdo0(); } int cc1100_cs_read_cca(void) diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index d97a3857a6..acc374761d 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -45,7 +45,7 @@ and the mailinglist (subscription via web site) #include #include "hwtimer.h" -#include "swtimer.h" +#include #include "cc1100.h" #include "cc1100_spi.h" @@ -382,7 +382,7 @@ static bool contains_seq_entry(uint8_t src, uint8_t id) { // Check if time stamp is OK cmp = (radio_mode == CC1100_MODE_WOR) ? cc1100_wor_config.rx_interval : 16000; // constant RX ~16ms - if ((now - seq_buffer[i].m_ticks) <= cmp) + if ((now - seq_buffer[i].m_ticks) <= cmp) { return true; } @@ -412,7 +412,7 @@ static void add_seq_entry(uint8_t src, uint8_t id) // Add new entry seq_buffer[seq_buffer_pos].source = src; seq_buffer[seq_buffer_pos].identification = id; - seq_buffer[seq_buffer_pos].m_ticks = swtimer_now(); + seq_buffer[seq_buffer_pos].m_ticks = swtimer_now(); // Store 16 bit sequence number of layer 0 for speedup last_seq_num = src; @@ -625,6 +625,7 @@ int cc1100_set_packet_handler(protocol_t protocol, packet_handler_t handler) static void cc1100_event_handler_function(void) { msg_t m; + while (1) { if (cc1100_watch_dog_period != 0) { diff --git a/drivers/cc110x/cc1100_spi.c b/drivers/cc110x/cc1100_spi.c index ef5206cb64..2614caf20a 100644 --- a/drivers/cc110x/cc1100_spi.c +++ b/drivers/cc110x/cc1100_spi.c @@ -61,13 +61,13 @@ cc1100_spi_writeburst_reg(uint8_t addr, char *src, uint8_t count) { int i = 0; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr | CC1100_WRITE_BURST); + cc110x_spi_select(); + cc110x_txrx(addr | CC1100_WRITE_BURST); while (i < count) { - cc1100_txrx(src[i]); + cc110x_txrx(src[i]); i++; } - cc1100_spi_unselect(); + cc110x_spi_unselect(); restoreIRQ(cpsr); return count; } @@ -77,13 +77,13 @@ cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { int i = 0; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr | CC1100_READ_BURST); + cc110x_spi_select(); + cc110x_txrx(addr | CC1100_READ_BURST); while (i < count) { - buffer[i] = cc1100_txrx(NOBYTE); + buffer[i] = cc110x_txrx(NOBYTE); i++; } - cc1100_spi_unselect(); + cc110x_spi_unselect(); restoreIRQ(cpsr); } @@ -91,10 +91,10 @@ void cc1100_spi_write_reg(uint8_t addr, uint8_t value) { unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr); - cc1100_txrx(value); - cc1100_spi_unselect(); + cc110x_spi_select(); + cc110x_txrx(addr); + cc110x_txrx(value); + cc110x_spi_unselect(); restoreIRQ(cpsr); } @@ -102,10 +102,10 @@ uint8_t cc1100_spi_read_reg(uint8_t addr) { uint8_t result; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr | CC1100_READ_SINGLE); - result = cc1100_txrx(NOBYTE); - cc1100_spi_unselect(); + cc110x_spi_select(); + cc110x_txrx(addr | CC1100_READ_SINGLE); + result = cc110x_txrx(NOBYTE); + cc110x_spi_unselect(); restoreIRQ(cpsr); return result; } @@ -114,10 +114,10 @@ uint8_t cc1100_spi_read_status(uint8_t addr) { uint8_t result; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr | CC1100_READ_BURST); - result = cc1100_txrx(NOBYTE); - cc1100_spi_unselect(); + cc110x_spi_select(); + cc110x_txrx(addr | CC1100_READ_BURST); + result = cc110x_txrx(NOBYTE); + cc110x_spi_unselect(); restoreIRQ(cpsr); return result; } @@ -126,9 +126,9 @@ uint8_t cc1100_spi_strobe(uint8_t c) { uint8_t result; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - result = cc1100_txrx(c); - cc1100_spi_unselect(); + cc110x_spi_select(); + result = cc110x_txrx(c); + cc110x_spi_unselect(); restoreIRQ(cpsr); return result; } diff --git a/drivers/cc110x/cc1100_spi.h b/drivers/cc110x/cc1100_spi.h index 736f982187..e76deb8b27 100644 --- a/drivers/cc110x/cc1100_spi.h +++ b/drivers/cc110x/cc1100_spi.h @@ -44,14 +44,14 @@ and the mailinglist (subscription via web site) #ifndef CC1100_SPI_H_ #define CC1100_SPI_H_ -int cc1100_get_gdo0(void); -int cc1100_get_gdo1(void); -int cc1100_get_gdo2(void); +int cc110x_get_gdo0(void); +int cc110x_get_gdo1(void); +int cc110x_get_gdo2(void); -void cc1100_spi_init(void); -void cc1100_spi_cs(void); -void cc1100_spi_select(void); -void cc1100_spi_unselect(void); +void cc110x_spi_init(void); +void cc110x_spi_cs(void); +void cc110x_spi_select(void); +void cc110x_spi_unselect(void); uint8_t cc1100_spi_writeburst_reg(uint8_t addr, char *buffer, uint8_t count); void cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count); From f7d6ef47098a7724e02591e0034061b2c0a6e613 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 6 Apr 2011 11:10:28 +0200 Subject: [PATCH 27/38] [projects WEAtHeR] * added routing and duplicate detection --- projects/WEAtHeR/main.c | 54 ++++++++++++++++++------- projects/WEAtHeR/protocol_msg_gateway.c | 4 +- projects/WEAtHeR/weather_protocol.h | 6 ++- projects/WEAtHeR/weather_routing.c | 19 ++++++--- 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index 878c5bba34..54459dc9c4 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -18,8 +18,16 @@ #include "weather_protocol.h" #include "protocol_msg_gateway.h" -#define SHELL_STACK_SIZE (2048) -#define PH_STACK_SIZE (2048) +#define SECOND (1000 * 1000) +#define MINUTE (60 * SECOND) + +#define SENDING_INTERVAL (1 * SECOND) + +/* size of weather data packet without hop list */ +#define EMPTY_WDP_SIZE (sizeof(weather_data_pkt_t) - MAX_HOP_LIST) + +#define SHELL_STACK_SIZE (4048) +#define PH_STACK_SIZE (4048) /* per default not acting as data sink */ static uint8_t data_sink = 0; @@ -68,15 +76,19 @@ void weather_sink(char* unused) { static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { weather_packet_header_t *header = (weather_packet_header_t*) msg; - printf("\n\t Pkt received from phy: %u\n" + /* packet origins at current node, just ignore it */ + if (header->src == cc1100_get_address()) { + return; + } + printf("\n\t Pkt received from phy: %u (%u bytes)\n" "\t -> SEQ: %u | TYPE: %u | SRC: %hu \n\n", packet_info->phy_src, + msg_size, header->seq_nr, header->type, header->src ); - - /* when destination is set, but I'm not the receiver, pass to routing */ + /* while not acting as sink route the packet */ if (!data_sink) { if (header->type == WEATHER_DATA) { weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; @@ -97,7 +109,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { return; } - /* in all other cases handle the packet */ + /* if current node acts as sink, handle packet */ switch (header->type) { case WEATHER_HELLO: { if (msg_size < sizeof(weather_hello_pkt_t)) { @@ -116,16 +128,21 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { case WEATHER_DATA: { weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; time_t local_time = rtc_time(NULL); + uint8_t i; /* ;;;;;;; */ - printf("%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f\n", + printf("%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f;", header->src, - 1, + cc1100_get_address(), wdp->timestamp, local_time, wdp->temperature, wdp->relhum, wdp->relhum_temp, wdp->energy); + for (i = 0; i < wdp->hop_counter; i++) { + printf("%03u-", wdp->hops[i]); + } + puts(""); break; } default: { @@ -158,7 +175,9 @@ int main(void) { wdp.header.seq_nr = 0; wdp.header.type = WEATHER_DATA; - + wdp.hop_counter = 1; + + printf("EMPTY: %lu, WDP: %lu\n", EMPTY_WDP_SIZE, sizeof(weather_data_pkt_t)); puts(""); puts("WEAtHeR: Wireless Energy-Aware mulTi-Hop sEnsor Reading."); /* ;;;;;;; */ @@ -167,8 +186,9 @@ int main(void) { thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); + init_protocol_msg_gateway(); /* create thread for radio packet handling */ - int pid = thread_create(ph_stack_buffer, PH_STACK_SIZE, PRIORITY_MAIN-5, CREATE_STACKTEST, protocol_handler_thread, "protocol_handler"); + int pid = thread_create(ph_stack_buffer, PH_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, protocol_handler_thread, "protocol_handler"); set_protocol_handler_thread(pid); ltc4150_start(); @@ -187,16 +207,22 @@ int main(void) { wdp.temperature = sht11_val.temperature; wdp.relhum = sht11_val.relhum; wdp.relhum_temp = sht11_val.relhum_temp; - if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)&wdp, sizeof(weather_data_pkt_t))) { - printf("Successfully sent packet: \n"); + wdp.hops[0] = cc1100_get_address(); + /* send packet with one entry in hop list */ + if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)&wdp, (EMPTY_WDP_SIZE + 1)) > 0) { + printf("Sending %lu bytes.\n", (EMPTY_WDP_SIZE + 1)); wdp.header.seq_nr++; } else { puts("Error on sending packet!"); } } + LED_GREEN_TOGGLE; + } + else { LED_RED_TOGGLE; } - swtimer_usleep(60 * 1000*1000); + hwtimer_wait(SENDING_INTERVAL); } + puts("Something went wrong."); } diff --git a/projects/WEAtHeR/protocol_msg_gateway.c b/projects/WEAtHeR/protocol_msg_gateway.c index 1e439c5d53..5501aff90c 100644 --- a/projects/WEAtHeR/protocol_msg_gateway.c +++ b/projects/WEAtHeR/protocol_msg_gateway.c @@ -19,9 +19,6 @@ packet_t packet_buffer[PACKET_BUFFER_SIZE]; static void protocol_msg_gateway(void* payload, int msg_size, protocol_t protocol, packet_info_t* packet_info) { msg_t m; -// if ((((int16_t) packet_info->phy_src) > (((int16_t) cc1100_get_address()) + 10)) || (((int16_t) packet_info->phy_src) < (((int16_t) cc1100_get_address()) - 10))) { - // return; - // } if (protocol_handler_pid <= 0) { puts("protocol_handler(): received packet without protocol handler. msg dropped."); return; @@ -45,6 +42,7 @@ static void protocol_msg_gateway(void* payload, int msg_size, protocol_t protoco } void init_protocol_msg_gateway() { + puts("Init protocol msg gateway"); cc1100_set_packet_monitor(protocol_msg_gateway); } diff --git a/projects/WEAtHeR/weather_protocol.h b/projects/WEAtHeR/weather_protocol.h index f504204c92..8785fd0264 100644 --- a/projects/WEAtHeR/weather_protocol.h +++ b/projects/WEAtHeR/weather_protocol.h @@ -5,6 +5,7 @@ #include #define WEATHER_PROTOCOL_NR 6 +#define MAX_HOP_LIST (11) typedef enum { WEATHER_HELLO, @@ -16,7 +17,6 @@ typedef struct { uint16_t seq_nr; uint8_t src; uint8_t type; - uint8_t resevered; } weather_packet_header_t; typedef struct __attribute__ ((packed)) { @@ -29,13 +29,15 @@ typedef struct { char mesg[40]; } weather_chat_pkt_t; -typedef struct { +typedef struct __attribute__ ((packed)) { weather_packet_header_t header; time_t timestamp; double temperature; double relhum; double relhum_temp; double energy; + uint8_t hop_counter; + uint8_t hops[MAX_HOP_LIST]; } weather_data_pkt_t; #endif diff --git a/projects/WEAtHeR/weather_routing.c b/projects/WEAtHeR/weather_routing.c index 8c354b0215..139953cbb4 100644 --- a/projects/WEAtHeR/weather_routing.c +++ b/projects/WEAtHeR/weather_routing.c @@ -9,18 +9,17 @@ static source_timestamp_t sources[MAX_SOURCES]; static uint8_t update_sources(uint8_t id, time_t timestamp) { uint8_t i; + + puts("updating sources list"); for (i = 0; i < MAX_SOURCES; i++) { /* source id found */ if (sources[i].id == id) { + printf("source already known, comparing timestamps: %04lX : %04lX\n", sources[i].timestamp, timestamp); /* more current timestamp received, updating */ if (sources[i].timestamp < timestamp) { sources[i].timestamp = timestamp; return 1; } - /* older, but still valid timestamp, not updating */ - else if (sources[i].timestamp < timestamp + MAX_INTERVAL) { - return 1; - } /* timestamp too old, discard this packet */ else { puts("Timestamp too old, not routing"); @@ -29,6 +28,7 @@ static uint8_t update_sources(uint8_t id, time_t timestamp) { } /* source id not yet stored creating new entry */ else if (!sources[i].id) { + puts("got to know a new source"); sources[i].id = id; sources[i].timestamp = timestamp; return 1; @@ -40,8 +40,9 @@ static uint8_t update_sources(uint8_t id, time_t timestamp) { void route_packet(void* msg, int msg_size) { weather_packet_header_t *header = (weather_packet_header_t*) msg; + weather_data_pkt_t* wdp = NULL; if (header->type == WEATHER_DATA) { - weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + wdp = (weather_data_pkt_t*) msg; if (!update_sources(wdp->header.src, wdp->timestamp)) { return; } @@ -49,6 +50,14 @@ void route_packet(void* msg, int msg_size) { if ((100.0 * rand()/(double) RAND_MAX) <= FLOODING_PROB) { printf("Broadcasting packet..."); + /* if broadcasting weather data, append current hop */ + if (wdp != NULL) { + if (wdp->hop_counter < MAX_HOP_LIST) { + wdp->hops[wdp->hop_counter] = cc1100_get_address(); + wdp->hop_counter++; + msg_size++; + } + } if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)msg, msg_size)) { puts("successful!"); } From 0661ce2f7f909c1e15aaa3b076cd95fe1cb4fdfe Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 6 Apr 2011 11:11:03 +0200 Subject: [PATCH 28/38] [sys shell] * fixed some shell commands --- sys/shell/cc1100.c | 42 ++++++++++++++++++++++++++------------ sys/shell/id.c | 2 ++ sys/shell/shell_commands.c | 8 ++++---- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/sys/shell/cc1100.c b/sys/shell/cc1100.c index 47901d7344..b9542e3b72 100644 --- a/sys/shell/cc1100.c +++ b/sys/shell/cc1100.c @@ -1,27 +1,43 @@ #include +#include +#include #include #ifdef MODULE_CC110X -void _cc1100_get_address_handler(char *str) { - radio_address_t addr = cc1100_get_address(); - printf("cc1100 address: %i\n", addr); +void _cc110x_get_set_address_handler(char *addr) { + int16_t a; + + a = atoi(addr+5); + if (strlen(addr) > 5) { + printf("[cc110x] Setting address %i ... ", a); + cc1100_set_address((radio_address_t)a); + if (cc1100_get_address() == (radio_address_t)a) { + puts("[OK]"); + } else { + puts("Error!"); + } + } + else { + printf("[cc1100] Got address: %i\n", cc1100_get_address()); + } } -void _cc1100_set_address_handler(char *str) { - int addr; - int res = sscanf(str, "cc1100_set_address %i", &addr); - if (res == 1) { - cc1100_set_address((radio_address_t)addr); - printf("Setting cc1100 address to %i: ", addr); - if (cc1100_get_address() == (radio_address_t)addr) { +void _cc110x_get_set_channel_handler(char *addr) { + int16_t a; + + a = atoi(addr+5); + if (strlen(addr) > 5) { + printf("[cc110x] Setting channel %i...", a); + cc1100_set_channel(a); + if (cc1100_get_channel() == a) { puts("OK"); } else { puts("Error!"); } - } else { - puts("usage: cc1100_set_address
"); + } + else { + printf("[cc1100] Got address: %i\n", cc1100_get_channel()); } } - #endif diff --git a/sys/shell/id.c b/sys/shell/id.c index 414997bac5..3807484ff3 100644 --- a/sys/shell/id.c +++ b/sys/shell/id.c @@ -8,7 +8,9 @@ void _id_handler(char *id) { newid = atoi(id+3); if (strlen(id) < 3) { +#ifdef MODULE_CONFIG printf("Current id: %u\n", sysconfig.id); +#endif } else { printf("Setting new id %lu\n", newid); diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index dd5372b99a..6023faf2a9 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -24,8 +24,8 @@ extern void _reset_current_handler(char* unused); #endif #ifdef MODULE_CC110X -extern void _cc110x_get_address_handler(char *unused); -extern void _cc110x_set_address_handler(char *ptr); +extern void _cc110x_get_set_address_handler(char *addr); +extern void _cc110x_get_set_channel_handler(char *addr); #endif #ifdef MODULE_TRANSCEIVER @@ -56,8 +56,8 @@ const shell_command_t _shell_command_list[] = { {"rstcur", "Resets coulomb counter.", _reset_current_handler}, #endif #ifdef MODULE_CC110X - {"cc110x_get_address", "", _cc110x_get_address_handler}, - {"cc110x_set_address", "", _cc110x_set_address_handler}, + {"addr", "Gets or sets the address for the CC1100 transceiver", _cc110x_get_set_address_handler}, + {"chan", "Gets or sets the channel for the CC1100 transceiver", _cc110x_get_set_channel_handler}, #endif #ifdef MODULE_TRANSCEIVER #ifdef MODULE_CC110X_NG From 71f10ed8e652e4861afbd71549501fe27e9a73cb Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 6 Apr 2011 15:50:31 +0200 Subject: [PATCH 29/38] [projects WEAtHeR] * some bugfixing --- projects/WEAtHeR/main.c | 74 ++++++++++++++++++++++--- projects/WEAtHeR/protocol_msg_gateway.c | 5 +- projects/WEAtHeR/weather_routing.c | 4 +- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index 54459dc9c4..aeb555fc97 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "weather_routing.h" #include "weather_protocol.h" @@ -21,7 +23,7 @@ #define SECOND (1000 * 1000) #define MINUTE (60 * SECOND) -#define SENDING_INTERVAL (1 * SECOND) +#define DEFAULT_INTERVAL (60 * SECOND) /* size of weather data packet without hop list */ #define EMPTY_WDP_SIZE (sizeof(weather_data_pkt_t) - MAX_HOP_LIST) @@ -33,16 +35,23 @@ static uint8_t data_sink = 0; static uint8_t data_src = 0; +static uint32_t sending_interval = DEFAULT_INTERVAL; +extern uint8_t gossip_probability; + char shell_stack_buffer[SHELL_STACK_SIZE]; char ph_stack_buffer[PH_STACK_SIZE]; void weather_send(char* unused); void weather_sink(char* unused); +static void set_interval(char* interval); +static void set_probability(char* prob); shell_t shell; const shell_command_t sc[] = { {"sender", "Enables node as data source.", weather_send}, {"sink", "Enables node as data sink.", weather_sink}, + {"int", "Set the sending interval in seconds", set_interval}, + {"prob", "Set the gossiping probability", set_probability}, {NULL, NULL, NULL}}; void shell_runner(void) { @@ -73,6 +82,32 @@ void weather_sink(char* unused) { } } +static void set_interval(char* interval) { + uint16_t a; + + a = atoi(interval+4); + if (strlen(interval) > 4) { + printf("[WEAtHeR] Set interval to %u\n ", a); + sending_interval = a * SECOND; + } + else { + printf("[WEAtHeR] Current interval is %lu\n ", (sending_interval / SECOND)); + } +} + +static void set_probability(char* prob) { + uint16_t a; + + a = atoi(prob+4); + if (strlen(prob) > 4) { + printf("[WEAtHeR] Set probability to %hu\n ", a); + gossip_probability = a; + } + else { + printf("[WEAtHeR] Current probability is %hu\n ", gossip_probability); + } +} + static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { weather_packet_header_t *header = (weather_packet_header_t*) msg; @@ -80,6 +115,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { if (header->src == cc1100_get_address()) { return; } + /* printf("\n\t Pkt received from phy: %u (%u bytes)\n" "\t -> SEQ: %u | TYPE: %u | SRC: %hu \n\n", packet_info->phy_src, @@ -88,12 +124,13 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { header->type, header->src ); + */ /* while not acting as sink route the packet */ if (!data_sink) { if (header->type == WEATHER_DATA) { - weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + //weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; /* ;;;;;;; */ - printf("%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", + /* printf("$0;%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", header->src, 0, wdp->timestamp, @@ -102,10 +139,11 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { wdp->relhum, wdp->relhum_temp, wdp->energy); + */ + puts("Not for me, routing, baby!"); + route_packet(msg, msg_size); } - puts("Not for me, routing, baby!"); - route_packet(msg, msg_size); return; } @@ -130,7 +168,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { time_t local_time = rtc_time(NULL); uint8_t i; /* ;;;;;;; */ - printf("%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f;", + printf("$1;%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f;", header->src, cc1100_get_address(), wdp->timestamp, @@ -146,7 +184,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { break; } default: { - printf("Unknown packet type \"%i\" received.", header->type); + printf("Unknown packet type \"%i\" received.\n", header->type); } } } @@ -172,17 +210,19 @@ int main(void) { sht11_val_t sht11_val; uint8_t success = 0; + gossip_probability = FLOODING_PROB; wdp.header.seq_nr = 0; wdp.header.type = WEATHER_DATA; wdp.hop_counter = 1; - printf("EMPTY: %lu, WDP: %lu\n", EMPTY_WDP_SIZE, sizeof(weather_data_pkt_t)); + cc1100_set_channel(10); puts(""); puts("WEAtHeR: Wireless Energy-Aware mulTi-Hop sEnsor Reading."); /* ;;;;;;; */ puts("Printing \"node id of data source;node id of sink;timestamp of measurement;timestamp at data sink;temperature in °C;relative humidity;temperature compensated relative humidity;energy value\"."); puts(""); + printf("Sending interval: %lu\n", sending_interval); thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); @@ -195,6 +235,7 @@ int main(void) { rtc_enable(); while (1) { + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); if (data_src) { wdp.header.src = cc1100_get_address(); wdp.timestamp = rtc_time(NULL); @@ -222,7 +263,22 @@ int main(void) { else { LED_RED_TOGGLE; } - hwtimer_wait(SENDING_INTERVAL); + + if (!success) { + printf("error;error;error\n"); + } + else { + printf("$0;%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", + cc1100_get_address(), + 0, + rtc_time(NULL), + 0, + sht11_val.temperature, + sht11_val.relhum, + sht11_val.relhum_temp, + ltc4150_get_total_mAh()); + } + hwtimer_wait(sending_interval); } puts("Something went wrong."); } diff --git a/projects/WEAtHeR/protocol_msg_gateway.c b/projects/WEAtHeR/protocol_msg_gateway.c index 5501aff90c..6c32d3469a 100644 --- a/projects/WEAtHeR/protocol_msg_gateway.c +++ b/projects/WEAtHeR/protocol_msg_gateway.c @@ -8,6 +8,7 @@ #include #include "protocol_msg_gateway.h" +#include "weather_protocol.h" #define NUM_PROTOCOL_HANDLER_PIDS 8 @@ -16,7 +17,7 @@ static uint16_t protocol_handler_pid; static int packet_buffer_next = 0; packet_t packet_buffer[PACKET_BUFFER_SIZE]; -static void protocol_msg_gateway(void* payload, int msg_size, protocol_t protocol, packet_info_t* packet_info) { +static void protocol_msg_gateway(void* payload, int msg_size, packet_info_t* packet_info) { msg_t m; if (protocol_handler_pid <= 0) { @@ -43,7 +44,7 @@ static void protocol_msg_gateway(void* payload, int msg_size, protocol_t protoco void init_protocol_msg_gateway() { puts("Init protocol msg gateway"); - cc1100_set_packet_monitor(protocol_msg_gateway); + cc1100_set_packet_handler(WEATHER_PROTOCOL_NR, protocol_msg_gateway); } int set_protocol_handler_thread(int pid) { diff --git a/projects/WEAtHeR/weather_routing.c b/projects/WEAtHeR/weather_routing.c index 139953cbb4..cce201a9e6 100644 --- a/projects/WEAtHeR/weather_routing.c +++ b/projects/WEAtHeR/weather_routing.c @@ -5,6 +5,8 @@ #include "weather_protocol.h" #include "weather_routing.h" +uint8_t gossip_probability; + static source_timestamp_t sources[MAX_SOURCES]; static uint8_t update_sources(uint8_t id, time_t timestamp) { @@ -48,7 +50,7 @@ void route_packet(void* msg, int msg_size) { } } - if ((100.0 * rand()/(double) RAND_MAX) <= FLOODING_PROB) { + if ((100.0 * rand()/(double) RAND_MAX) <= gossip_probability) { printf("Broadcasting packet..."); /* if broadcasting weather data, append current hop */ if (wdp != NULL) { From fe94bf9b7431c93e46c067248ebd54f64057202b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 7 Apr 2011 10:50:13 +0200 Subject: [PATCH 30/38] [projects WEAtHeR] * commit debug version * added more comments --- projects/WEAtHeR/Jamfile | 2 +- projects/WEAtHeR/main.c | 138 +++++++++++++++++++---------- projects/WEAtHeR/weather_routing.c | 18 ++-- 3 files changed, 104 insertions(+), 54 deletions(-) diff --git a/projects/WEAtHeR/Jamfile b/projects/WEAtHeR/Jamfile index 3576888c65..4974b6d046 100644 --- a/projects/WEAtHeR/Jamfile +++ b/projects/WEAtHeR/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects WEAtHeR ; -Module WEAtHeR : main.c weather_routing.c protocol_msg_gateway.c : sht11 ltc4150 cc110x gpioint swtimer shell shell_commands posix_io uart0 auto_init rtc ; +Module WEAtHeR : main.c weather_routing.c protocol_msg_gateway.c : ltc4150 cc110x gpioint vtimer shell shell_commands posix_io uart0 auto_init rtc ; UseModule WEAtHeR ; diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index aeb555fc97..5f47235153 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -1,51 +1,71 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +/* stdlib includes */ #include #include #include +#include +/* core includes */ +#include +#include +#include + +#define ENABLE_DEBUG +#include + +/* sensors and actors */ +#include +#include +#include + +/* shell */ +#include +#include +#include + +/* transceiver */ +#include + +/* real time clock */ +#include +#include + +/* application header */ #include "weather_routing.h" #include "weather_protocol.h" #include "protocol_msg_gateway.h" +/* some local defines */ #define SECOND (1000 * 1000) -#define MINUTE (60 * SECOND) - -#define DEFAULT_INTERVAL (60 * SECOND) +#define MINUTE (1 * SECOND) /* size of weather data packet without hop list */ #define EMPTY_WDP_SIZE (sizeof(weather_data_pkt_t) - MAX_HOP_LIST) +/* default values */ +#define DEFAULT_INTERVAL (5 * SECOND) + +/* stack space for threads */ #define SHELL_STACK_SIZE (4048) #define PH_STACK_SIZE (4048) -/* per default not acting as data sink */ -static uint8_t data_sink = 0; -static uint8_t data_src = 0; - -static uint32_t sending_interval = DEFAULT_INTERVAL; -extern uint8_t gossip_probability; - char shell_stack_buffer[SHELL_STACK_SIZE]; char ph_stack_buffer[PH_STACK_SIZE]; -void weather_send(char* unused); -void weather_sink(char* unused); +/* per default acting only as relay */ +static uint8_t data_sink = 0; +static uint8_t data_src = 0; + +static uint32_t sending_interval = DEFAULT_INTERVAL; + +extern uint8_t gossip_probability; + +/* function prototypes */ +static void weather_send(char* unused); +static void weather_sink(char* unused); static void set_interval(char* interval); static void set_probability(char* prob); +/* shell commands */ shell_t shell; const shell_command_t sc[] = { {"sender", "Enables node as data source.", weather_send}, @@ -54,13 +74,13 @@ const shell_command_t sc[] = { {"prob", "Set the gossiping probability", set_probability}, {NULL, NULL, NULL}}; -void shell_runner(void) { +static void shell_runner(void) { shell_init(&shell, sc, uart0_readc, uart0_putc); posix_open(uart0_handler_pid, 0); shell_run(&shell); } -void weather_send(char* unused) { +static void weather_send(char* unused) { if (data_src) { data_src = 0; puts("Disabling data source mode."); @@ -71,7 +91,7 @@ void weather_send(char* unused) { } } -void weather_sink(char* unused) { +static void weather_sink(char* unused) { if (data_sink) { data_sink = 0; puts("Disabling data sink mode."); @@ -108,6 +128,7 @@ static void set_probability(char* prob) { } } +/* packet handling */ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { weather_packet_header_t *header = (weather_packet_header_t*) msg; @@ -115,8 +136,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { if (header->src == cc1100_get_address()) { return; } - /* - printf("\n\t Pkt received from phy: %u (%u bytes)\n" + DEBUG("\n\t Pkt received from phy: %u (%u bytes)\n" "\t -> SEQ: %u | TYPE: %u | SRC: %hu \n\n", packet_info->phy_src, msg_size, @@ -124,13 +144,11 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { header->type, header->src ); - */ - /* while not acting as sink route the packet */ + /* while not acting as sink and packet contains data, route the packet */ if (!data_sink) { if (header->type == WEATHER_DATA) { - //weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; - /* ;;;;;;; */ - /* printf("$0;%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", + weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + DEBUG("$0;%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", header->src, 0, wdp->timestamp, @@ -139,8 +157,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { wdp->relhum, wdp->relhum_temp, wdp->energy); - */ - puts("Not for me, routing, baby!"); + DEBUG("Not for me, routing, baby!\n"); route_packet(msg, msg_size); } @@ -165,8 +182,8 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { } case WEATHER_DATA: { weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; - time_t local_time = rtc_time(NULL); uint8_t i; + time_t local_time = rtc_time(NULL); /* ;;;;;;; */ printf("$1;%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f;", header->src, @@ -209,38 +226,56 @@ int main(void) { weather_data_pkt_t wdp; sht11_val_t sht11_val; + /* initialize variables */ uint8_t success = 0; + int sending_state = 0; gossip_probability = FLOODING_PROB; + /* fill some fields of the packet */ wdp.header.seq_nr = 0; wdp.header.type = WEATHER_DATA; wdp.hop_counter = 1; + /* set initial channel */ cc1100_set_channel(10); + + /* boot screen */ puts(""); puts("WEAtHeR: Wireless Energy-Aware mulTi-Hop sEnsor Reading."); - /* ;;;;;;; */ - puts("Printing \"node id of data source;node id of sink;timestamp of measurement;timestamp at data sink;temperature in °C;relative humidity;temperature compensated relative humidity;energy value\"."); puts(""); - printf("Sending interval: %lu\n", sending_interval); - + printf("Sending interval: %lu\n", sending_interval / SECOND); + + /* start shell */ thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); + /* initialize message gateway */ init_protocol_msg_gateway(); /* create thread for radio packet handling */ int pid = thread_create(ph_stack_buffer, PH_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, protocol_handler_thread, "protocol_handler"); set_protocol_handler_thread(pid); + /* start coulomb counter and RTC */ ltc4150_start(); rtc_enable(); + /* loop forever */ while (1) { + DEBUG("Measurement in progress...\n"); +#ifndef ENABLE_DEBUG success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); +#else + success = 1; + sht11_val.temperature = 1; + sht11_val.relhum = 2; + sht11_val.relhum_temp = 3; +#endif + DEBUG("...done.\n"); + if (data_src) { wdp.header.src = cc1100_get_address(); wdp.timestamp = rtc_time(NULL); wdp.energy = ltc4150_get_total_mAh(); - success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + if (!success) { printf("error;error;error\n"); } @@ -250,12 +285,13 @@ int main(void) { wdp.relhum_temp = sht11_val.relhum_temp; wdp.hops[0] = cc1100_get_address(); /* send packet with one entry in hop list */ - if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)&wdp, (EMPTY_WDP_SIZE + 1)) > 0) { - printf("Sending %lu bytes.\n", (EMPTY_WDP_SIZE + 1)); + sending_state = cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)&wdp, (EMPTY_WDP_SIZE + 1)); + if (sending_state > 0) { + DEBUG("Sending %lu bytes.\n", (EMPTY_WDP_SIZE + 1)); wdp.header.seq_nr++; } else { - puts("Error on sending packet!"); + printf("Error on sending packet with code %i!\n", sending_state); } } LED_GREEN_TOGGLE; @@ -268,6 +304,14 @@ int main(void) { printf("error;error;error\n"); } else { +#ifdef ENABLE_DEBUG + puts("=================================================="); + cc1100_print_statistic(); + puts("--------------------------------------------------"); + cc1100_print_config(); + puts("=================================================="); +#endif + printf("$0;%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", cc1100_get_address(), 0, diff --git a/projects/WEAtHeR/weather_routing.c b/projects/WEAtHeR/weather_routing.c index cce201a9e6..3e572a96cd 100644 --- a/projects/WEAtHeR/weather_routing.c +++ b/projects/WEAtHeR/weather_routing.c @@ -1,10 +1,14 @@ #include #include -#include #include +#include + #include "weather_protocol.h" #include "weather_routing.h" +#define ENABLE_DEBUG +#include + uint8_t gossip_probability; static source_timestamp_t sources[MAX_SOURCES]; @@ -12,11 +16,11 @@ static source_timestamp_t sources[MAX_SOURCES]; static uint8_t update_sources(uint8_t id, time_t timestamp) { uint8_t i; - puts("updating sources list"); + DEBUG("updating sources list\n"); for (i = 0; i < MAX_SOURCES; i++) { /* source id found */ if (sources[i].id == id) { - printf("source already known, comparing timestamps: %04lX : %04lX\n", sources[i].timestamp, timestamp); + DEBUG("source already known, comparing timestamps: %04lX : %04lX\n", sources[i].timestamp, timestamp); /* more current timestamp received, updating */ if (sources[i].timestamp < timestamp) { sources[i].timestamp = timestamp; @@ -43,6 +47,8 @@ static uint8_t update_sources(uint8_t id, time_t timestamp) { void route_packet(void* msg, int msg_size) { weather_packet_header_t *header = (weather_packet_header_t*) msg; weather_data_pkt_t* wdp = NULL; + int state = 0; + if (header->type == WEATHER_DATA) { wdp = (weather_data_pkt_t*) msg; if (!update_sources(wdp->header.src, wdp->timestamp)) { @@ -57,14 +63,14 @@ void route_packet(void* msg, int msg_size) { if (wdp->hop_counter < MAX_HOP_LIST) { wdp->hops[wdp->hop_counter] = cc1100_get_address(); wdp->hop_counter++; - msg_size++; } } - if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)msg, msg_size)) { + state = cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)msg, msg_size); + if (state > 0) { puts("successful!"); } else { - puts("failed!"); + printf("failed with code %i!\n", state); } } } From 5c365dc21ce73da3db79f590d9029ca2da68055f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 7 Apr 2011 11:29:18 +0200 Subject: [PATCH 31/38] [projects WEAtHeR] * added cc1100 debugging command * discard packets when address is not set --- projects/WEAtHeR/main.c | 15 +++++++++++++++ projects/WEAtHeR/protocol_msg_gateway.c | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index 5f47235153..c89c8fa16a 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -64,6 +64,7 @@ static void weather_send(char* unused); static void weather_sink(char* unused); static void set_interval(char* interval); static void set_probability(char* prob); +static void print_cc1100_info(char* unused); /* shell commands */ shell_t shell; @@ -72,6 +73,7 @@ const shell_command_t sc[] = { {"sink", "Enables node as data sink.", weather_sink}, {"int", "Set the sending interval in seconds", set_interval}, {"prob", "Set the gossiping probability", set_probability}, + {"cc1100", "Show state, statistics and config of cc1100", print_cc1100_info}, {NULL, NULL, NULL}}; static void shell_runner(void) { @@ -128,6 +130,14 @@ static void set_probability(char* prob) { } } +static void print_cc1100_info(char* unused) { + puts("=================================================="); + cc1100_print_statistic(); + puts("--------------------------------------------------"); + cc1100_print_config(); + puts("=================================================="); +} + /* packet handling */ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { weather_packet_header_t *header = (weather_packet_header_t*) msg; @@ -219,6 +229,7 @@ static void protocol_handler_thread(void) { packet = packet_buffer[pos]; handle_packet(packet.payload, packet.msg_size, &(packet.packet_info)); + DEBUG("Packet handler done\n"); } } @@ -273,8 +284,11 @@ int main(void) { if (data_src) { wdp.header.src = cc1100_get_address(); + DEBUG("Src filled\n"); wdp.timestamp = rtc_time(NULL); + DEBUG("Timestamp filled\n"); wdp.energy = ltc4150_get_total_mAh(); + DEBUG("Energy filled\n"); if (!success) { printf("error;error;error\n"); @@ -284,6 +298,7 @@ int main(void) { wdp.relhum = sht11_val.relhum; wdp.relhum_temp = sht11_val.relhum_temp; wdp.hops[0] = cc1100_get_address(); + DEBUG("Ready for sending\n"); /* send packet with one entry in hop list */ sending_state = cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)&wdp, (EMPTY_WDP_SIZE + 1)); if (sending_state > 0) { diff --git a/projects/WEAtHeR/protocol_msg_gateway.c b/projects/WEAtHeR/protocol_msg_gateway.c index 6c32d3469a..baccab5e9a 100644 --- a/projects/WEAtHeR/protocol_msg_gateway.c +++ b/projects/WEAtHeR/protocol_msg_gateway.c @@ -20,6 +20,11 @@ packet_t packet_buffer[PACKET_BUFFER_SIZE]; static void protocol_msg_gateway(void* payload, int msg_size, packet_info_t* packet_info) { msg_t m; + if (!cc1100_get_address()) { + puts("No address configured, not processing incoming packet"); + return; + } + if (protocol_handler_pid <= 0) { puts("protocol_handler(): received packet without protocol handler. msg dropped."); return; From 67a62dae399d29ea4c7e30459d485c02a5265509 Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 19 Apr 2011 13:14:44 +0200 Subject: [PATCH 32/38] buildbot testing --- projects/WEAtHeR/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index c89c8fa16a..9f3a854928 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -256,7 +256,7 @@ int main(void) { puts(""); printf("Sending interval: %lu\n", sending_interval / SECOND); - /* start shell */ + /* start shell thread */ thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); /* initialize message gateway */ From ff6be18b84196c49ea9af44da2183da31a215e4c Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 19 Apr 2011 13:35:25 +0200 Subject: [PATCH 33/38] buildbot testing --- projects/WEAtHeR/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index 9f3a854928..c89c8fa16a 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -256,7 +256,7 @@ int main(void) { puts(""); printf("Sending interval: %lu\n", sending_interval / SECOND); - /* start shell thread */ + /* start shell */ thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); /* initialize message gateway */ From 5a0e412249a8ddb2fcc3e33f398a1fbc9722962a Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 24 Jun 2011 17:53:09 +0200 Subject: [PATCH 34/38] [core sched] * removed declaration from header file --- core/include/queue.h | 1 + core/include/sched.h | 8 ++++---- core/sched.c | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/include/queue.h b/core/include/queue.h index d7a122e506..ae377409de 100644 --- a/core/include/queue.h +++ b/core/include/queue.h @@ -23,6 +23,7 @@ void queue_add_head(queue_node_t* root, queue_node_t* new_obj); queue_node_t *queue_remove_head(queue_node_t* root); void queue_priority_add(queue_node_t* root, queue_node_t* new_obj); void queue_priority_add_generic(queue_node_t* root, queue_node_t* new_obj, int(*cmp)(queue_node_t*,queue_node_t*)) ; +void queue_remove(queue_node_t* root, queue_node_t *node); /** @} */ #endif // __QUEUE_H diff --git a/core/include/sched.h b/core/include/sched.h index bce3864310..9f97122491 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -27,13 +27,13 @@ void sched_run(); void sched_set_status(tcb_t *process, unsigned int status); void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr); -volatile unsigned int sched_context_switch_request; +extern volatile unsigned int sched_context_switch_request; -volatile tcb_t *sched_threads[MAXTHREADS]; -volatile tcb_t *active_thread; +extern volatile tcb_t *sched_threads[MAXTHREADS]; +extern volatile tcb_t *active_thread; extern volatile int num_tasks; -volatile int thread_pid; +extern volatile int thread_pid; //#define SCHEDSTATISTICS #if SCHEDSTATISTICS diff --git a/core/sched.c b/core/sched.c index 9b33d386d8..51fdaef62e 100644 --- a/core/sched.c +++ b/core/sched.c @@ -25,6 +25,13 @@ volatile int num_tasks = 0; +volatile unsigned int sched_context_switch_request; + +volatile tcb_t *sched_threads[MAXTHREADS]; +volatile tcb_t *active_thread; + +volatile int thread_pid; + clist_node_t *runqueues[SCHED_PRIO_LEVELS]; static uint32_t runqueue_bitcache = 0; From 15d27d8244f288731739e78710cac7cbf9bb9afb Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 24 Jun 2011 18:54:20 +0200 Subject: [PATCH 35/38] * Wiselib update for the linekrscript * some minor changes in vtimer --- cpu/lpc2387/linkerscript.x | 49 ++++++++++++++++++++++++++++++++++++-- projects/WEAtHeR/main.c | 8 +++++-- sys/include/vtimer.h | 3 +++ sys/vtimer.c | 37 ++++++++++++++++++++++++---- 4 files changed, 88 insertions(+), 9 deletions(-) diff --git a/cpu/lpc2387/linkerscript.x b/cpu/lpc2387/linkerscript.x index a0fc127b5e..121167139c 100644 --- a/cpu/lpc2387/linkerscript.x +++ b/cpu/lpc2387/linkerscript.x @@ -75,7 +75,17 @@ SECTIONS *(.cfgspec) /* configuration spec table */ __cfgspec_end = .; . = ALIGN(4); - + + __ctors_start = .; + PROVIDE (_os_ctor_start = .); + *(.ctors); + KEEP (*(.init_array)) + PROVIDE (_os_ctor_end = .); + __ctors_end = .; + *(.dtors); + LONG (0); + + *(.rodata .rodata.*) /* all .rodata sections (constants, strings, etc.) */ *(.gnu.linkonce.r.*) *(.glue_7) /* all .glue_7 sections (no idea what these are) */ @@ -109,6 +119,40 @@ SECTIONS /************************************************************************** * RAM **************************************************************************/ + + + .ctors (NOLOAD) : + + { + + . = ALIGN(4096); + + start_ctors = .; + + *(.init_array); + + *(.ctors); + + end_ctors = .; + + } + + + + .dtors (NOLOAD) : + + { + + . = ALIGN(4096); + + start_dtors = .; + + *(.fini_array); + + *(.dtors); + + end_dtors = .; + } /* * collect all uninitialized sections that go into RAM @@ -130,7 +174,8 @@ SECTIONS { . = ALIGN(4); /* ensure data is aligned so relocation can use 4-byte operations */ __bss_start = .; /* define a global symbol marking the start of the .bss section */ - *(.bss) /* all .bss sections */ + *(.bss) /* all .bss sections */ + *(.bss*) /* all .bss sections */ *(COMMON) } > ram /* put all the above in RAM (it will be cleared in the startup code */ . = ALIGN(4); /* ensure data is aligned so relocation can use 4-byte operations */ diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index c89c8fa16a..b562d334cb 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -34,9 +34,13 @@ #include "weather_protocol.h" #include "protocol_msg_gateway.h" -/* some local defines */ #define SECOND (1000 * 1000) -#define MINUTE (1 * SECOND) +#define MINUTE (60 * SECOND) + +#define SENDING_INTERVAL (1 * SECOND) + +#define SHELL_STACK_SIZE (2048) +#define PH_STACK_SIZE (2048) /* size of weather data packet without hop list */ #define EMPTY_WDP_SIZE (sizeof(weather_data_pkt_t) - MAX_HOP_LIST) diff --git a/sys/include/vtimer.h b/sys/include/vtimer.h index 8a97729736..9431524ace 100644 --- a/sys/include/vtimer.h +++ b/sys/include/vtimer.h @@ -22,6 +22,8 @@ #include #include +#define MSG_TIMER 12345 + /** * A vtimer object. * @@ -34,6 +36,7 @@ typedef struct vtimer_t { timex_t absolute; void(*action)(void*); void* arg; + int pid; } vtimer_t; /** diff --git a/sys/vtimer.c b/sys/vtimer.c index fa92de7a9f..5db4ad4ff3 100644 --- a/sys/vtimer.c +++ b/sys/vtimer.c @@ -4,7 +4,7 @@ #include #include #include - +#include #include #include @@ -51,7 +51,6 @@ static int update_shortterm() { } } - hwtimer_next_absolute = shortterm_queue_root.next->priority; unsigned int next = hwtimer_next_absolute + longterm_tick_start; @@ -60,9 +59,10 @@ static int update_shortterm() { if((next - VTIMER_THRESHOLD - now) > NANOSECONDS_PER_TICK ) { next = now + VTIMER_BACKOFF; } - + + hwtimer_id = hwtimer_set_absolute(next, vtimer_callback, NULL); - + printf("hw_id: %i\n", hwtimer_id); DEBUG("update_shortterm: Set hwtimer to %lu (now=%lu)\n", hwtimer_next_absolute + longterm_tick_start, hwtimer_now()); return 0; } @@ -104,8 +104,17 @@ void vtimer_callback(void *ptr) { DEBUG("vtimer_callback(): Shooting %lu.\n", timer->absolute.nanoseconds); + printf("timer pid: %i\n", timer->pid); + /* shoot timer */ - timer->action(timer->arg); + if(timer->pid != 0){ + /* ugly*/ + msg_t msg; + msg.content.value = (unsigned int) timer->arg; + msg_send_int(&msg, timer->pid); + } else { + timer->action(timer->arg); + } in_callback = false; update_shortterm(); @@ -220,3 +229,21 @@ int vtimer_set_cb(vtimer_t *t, timex_t interval, void (*f_ptr)(void *), void *pt return vtimer_set(t); } +int vtimer_remove(vtimer_t *t){ + queue_remove(&shortterm_queue_root, (queue_node_t*)t); + queue_remove(&longterm_queue_root, (queue_node_t*)t); + + update_shortterm(); + + if (! inISR() ) eINT(); + return 0; +} + +int vtimer_set_msg(vtimer_t *t, timex_t interval, int pid, void *ptr){ + t->action = (void* ) msg_send_int; + t->arg = (void*) ptr; + t->absolute = interval; + t->pid = pid; + vtimer_set(t); + return 0; +} From ecec50e90522970f45f5a02b694bee90abc4c495 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 27 Jun 2011 09:41:56 +0200 Subject: [PATCH 36/38] [cpu lpc3487] * removed unnecessary from linkerscript --- cpu/lpc2387/linkerscript.x | 1 - 1 file changed, 1 deletion(-) diff --git a/cpu/lpc2387/linkerscript.x b/cpu/lpc2387/linkerscript.x index 121167139c..ad2fe40e0d 100644 --- a/cpu/lpc2387/linkerscript.x +++ b/cpu/lpc2387/linkerscript.x @@ -174,7 +174,6 @@ SECTIONS { . = ALIGN(4); /* ensure data is aligned so relocation can use 4-byte operations */ __bss_start = .; /* define a global symbol marking the start of the .bss section */ - *(.bss) /* all .bss sections */ *(.bss*) /* all .bss sections */ *(COMMON) } > ram /* put all the above in RAM (it will be cleared in the startup code */ From 706d9827053560477cc2996d7a6fa60815ebd559 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 27 Jun 2011 11:34:21 +0200 Subject: [PATCH 37/38] [core kernel] * fixed include search directive for internal header file --- core/include/kernel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/kernel.h b/core/include/kernel.h index 54c7d51e6c..49dda3664b 100644 --- a/core/include/kernel.h +++ b/core/include/kernel.h @@ -22,7 +22,7 @@ */ #include -#include +#include "config.h" #include "tcb.h" #include "cpu.h" #include "flags.h" From 686bb4d8c384368fa815e3d7ef773cdcc0a9af96 Mon Sep 17 00:00:00 2001 From: Rami Akkad Date: Mon, 4 Jul 2011 11:17:03 +0200 Subject: [PATCH 38/38] Added a new project to prepare ukleos to work out of the box with wiselib. --- projects/wiselib/Jamfile | 5 +++++ projects/wiselib/main.c | 42 ++++++++++++++++++++++++++++++++++++++++ projects/wiselib/script | 3 +++ 3 files changed, 50 insertions(+) create mode 100644 projects/wiselib/Jamfile create mode 100644 projects/wiselib/main.c create mode 100755 projects/wiselib/script diff --git a/projects/wiselib/Jamfile b/projects/wiselib/Jamfile new file mode 100644 index 0000000000..3301526cb0 --- /dev/null +++ b/projects/wiselib/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects wiselib ; + +Module wiseleb : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer config ltc4150 ; + +UseModule wiseleb ; diff --git a/projects/wiselib/main.c b/projects/wiselib/main.c new file mode 100644 index 0000000000..ecf6cba1d8 --- /dev/null +++ b/projects/wiselib/main.c @@ -0,0 +1,42 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SHELL_STACK_SIZE (2048) +#define RADIO_STACK_SIZE (2048) + +#define SND_BUFFER_SIZE (100) +#define RCV_BUFFER_SIZE (64) + +#define SENDING_DELAY (5 * 1000) + +char shell_stack_buffer[SHELL_STACK_SIZE]; +char radio_stack_buffer[RADIO_STACK_SIZE]; + +uint8_t snd_buffer[SND_BUFFER_SIZE][CC1100_MAX_DATA_LENGTH]; + +msg_t msg_q[RCV_BUFFER_SIZE]; + +static msg_t mesg; +static transceiver_command_t tcmd; +static radio_packet_t p; + +static uint32_t sending_delay = SENDING_DELAY; + +void sender(char *count); +void print_buffer(char *unused); +void switch2rx(char *unused); +void powerdown(char *unused); +void set_delay(char *delay); + +int main(void){} diff --git a/projects/wiselib/script b/projects/wiselib/script new file mode 100755 index 0000000000..c5978378c0 --- /dev/null +++ b/projects/wiselib/script @@ -0,0 +1,3 @@ +echo "Doing stuff..." +cd $FEUERWHERE_PATH +jam -sPROJECT=wiselib