From 820cdad59b5c3bf20e76eff3bb5204f3c5d52904 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 11 Oct 2010 13:26:24 +0200 Subject: [PATCH 001/115] * removed incomplete sixlowpan from master branch --- sys/net/sixlowmac.c | 20 -------------------- sys/net/sixlowmac.h | 11 ----------- sys/net/sixlowpan.c | 41 ----------------------------------------- sys/net/sixlowpan.h | 21 --------------------- 4 files changed, 93 deletions(-) delete mode 100644 sys/net/sixlowmac.c delete mode 100644 sys/net/sixlowmac.h delete mode 100644 sys/net/sixlowpan.c delete mode 100644 sys/net/sixlowpan.h diff --git a/sys/net/sixlowmac.c b/sys/net/sixlowmac.c deleted file mode 100644 index eff1ad2f9c..0000000000 --- a/sys/net/sixlowmac.c +++ /dev/null @@ -1,20 +0,0 @@ -/* 6LoWPAN MAC - layer 2 implementations */ - -#include "sixlowmac.h" -#include "drivers/cc110x/cc1100.h" -#include -#include - -static void init_msba2_mac(mac_addr addr){ - addr.oui1 = MSBA2_OUI >> 8; - addr.oui2 = 0x0 | MSBA2_OUI; - addr.ext_ident = MSBA2_R8BIT; - addr.ext_ident = cc1100_get_address(); -} - -static void init_mac_address(mac_addr addr){ - -#ifdef SIXLOWPAN_MSBA2 - init_msba2_mac(addr); -#endif -} diff --git a/sys/net/sixlowmac.h b/sys/net/sixlowmac.h deleted file mode 100644 index bb1c3e53a4..0000000000 --- a/sys/net/sixlowmac.h +++ /dev/null @@ -1,11 +0,0 @@ -/* 6LoWPAN MAC header file */ - -#define MSBA2_OUI 0x005BA2 // 24bit OUI -#define MSBA2_R8BIT 0xA2 // random 8bit - -typedef struct mac_addr{ - uint16_t oui_1; - uint8_t oui_2; - uint8_t ext_ident_1; // MSBA2_R8BIT - uint16_t ext_ident_2; // radio address -} mac_addr; diff --git a/sys/net/sixlowpan.c b/sys/net/sixlowpan.c deleted file mode 100644 index 7a099c0f69..0000000000 --- a/sys/net/sixlowpan.c +++ /dev/null @@ -1,41 +0,0 @@ -/* 6LoWPAN layer 3 implementation */ - -#include -#include "drivers/cc110x/cc1100.h" -#include "sixlowmac.h" - - -static void output(void){ - - // TODO - // 1. get dest addr from function param - // 2. get pointer to packet buffer - // 3. if dest is null send broadcast - // 4. hc1 or hc1x header compression - // 5. check if ip-packet is to large to fit into a single mac-packet - // if no, fragment the packet - // frag1 dispatch + header - // fragn dispatch - // set fragments into queue and send it -} - -/* convert 48-bit MAC address to IPv6 modified EUI-64 Identifier*/ -static eui64 get_eui64_from_mac(void){ - mac_addr maddr; - eui64 ident; - - init_mac_address(maddr); - - /* change bit 7 from oui1 to 1 */ - ident.oui1 = (maddr.oui_1 >> 8) | 0x2; - ident.oui2 = (maddr.oui_1 << 8) | maddr.oui_2; - ident.pattern = MAC_TO_EUI64_PTRN; - ident.ext_ident_1 = maddr.ext_ident_1; - ident.ext_ident_2 = maddr.ext_ident_1; - - return ident; -} - -static void set_6lowpan_address(uint64_t prefix){ - -} diff --git a/sys/net/sixlowpan.h b/sys/net/sixlowpan.h deleted file mode 100644 index 14cbca8f8c..0000000000 --- a/sys/net/sixlowpan.h +++ /dev/null @@ -1,21 +0,0 @@ -/* fragmentation defines */ -#define FRAG1_HDR_LEN 32 // in bit -#define FRAGN_HDR_LEN 40 // in bit -#define FRAG1_DISPATCH 0xC0 // 11000000 -#define FRAGN_DISPATCH 0xE0 // 11100000 - -/* 48-bit MAC to EUI64 pattern */ -#define MAC_TO_EUI64_PTRN 0xFFFE - -typedef struct eui64{ - uint8_t oui_1; - uint16_t oui_2; - uint16_t pattern; - uint8_t ext_ident_1; - uint16_t ext_ident_2; -} eui64; - -typedef struct ipv6_addr{ - uint16_t prefix[4]; - eui64 interface_id; -} ipv6_addr; From cfccf0f2caeb1742e3c3a1c51107c7b73b8ffd5f Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 11 Oct 2010 17:05:33 +0200 Subject: [PATCH 002/115] * remove mu character from kernel greeting line. --- core/kernel_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/kernel_init.c b/core/kernel_init.c index 8c3f0a2eab..cc6e273c2f 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -66,7 +66,7 @@ const char *idle_name = "idle"; void kernel_init(void) { dINT(); - printf("kernel_init(): This is µkleos!\n"); + printf("kernel_init(): This is ukleos!\n"); scheduler_init(); From 2bc373984aa40b19de217a996c81efe8f91758b2 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 11 Oct 2010 17:05:40 +0200 Subject: [PATCH 003/115] * added msb-430 support, split msb-430 and 430h common stuff out --- board/msb-430-common/Jamfile | 33 +++++++++ board/msb-430-common/Jamrules.msb-430-common | 36 ++++++++++ .../{msb-430h => msb-430-common}/board_init.c | 0 .../{msb-430h => msb-430-common}/debug_uart.c | 0 board/msb-430/Jamfile | 32 +++++++++ board/msb-430/Jamrules.msb-430 | 3 + board/msb-430/include/board.h | 69 +++++++++++++++++++ board/msb-430h/Jamfile | 5 +- board/msb-430h/Jamrules.msb-430h | 36 +--------- 9 files changed, 176 insertions(+), 38 deletions(-) create mode 100644 board/msb-430-common/Jamfile create mode 100644 board/msb-430-common/Jamrules.msb-430-common rename board/{msb-430h => msb-430-common}/board_init.c (100%) rename board/{msb-430h => msb-430-common}/debug_uart.c (100%) create mode 100644 board/msb-430/Jamfile create mode 100644 board/msb-430/Jamrules.msb-430 create mode 100644 board/msb-430/include/board.h diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile new file mode 100644 index 0000000000..97c2be0f30 --- /dev/null +++ b/board/msb-430-common/Jamfile @@ -0,0 +1,33 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet 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 FeuerWare. +# +# 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 +# ****************************************************************************** +# $Id$ + +SubDir TOP board msb-430-common ; + +Module board : board_init.c debug_uart.c ; +UseModule board ; + +SubInclude TOP cpu $(CPU) ; diff --git a/board/msb-430-common/Jamrules.msb-430-common b/board/msb-430-common/Jamrules.msb-430-common new file mode 100644 index 0000000000..db12fc6763 --- /dev/null +++ b/board/msb-430-common/Jamrules.msb-430-common @@ -0,0 +1,36 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet 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 FeuerWare. +# +# 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 +# ****************************************************************************** +# $Id$ + +CPU = msp430 ; +MCU = msp430x1612 ; + +FLASH_PORT ?= /dev/ttyUSB0 ; +FLASHER ?= mspdebug ; +FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; + +RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; + diff --git a/board/msb-430h/board_init.c b/board/msb-430-common/board_init.c similarity index 100% rename from board/msb-430h/board_init.c rename to board/msb-430-common/board_init.c diff --git a/board/msb-430h/debug_uart.c b/board/msb-430-common/debug_uart.c similarity index 100% rename from board/msb-430h/debug_uart.c rename to board/msb-430-common/debug_uart.c diff --git a/board/msb-430/Jamfile b/board/msb-430/Jamfile new file mode 100644 index 0000000000..f2592c24cf --- /dev/null +++ b/board/msb-430/Jamfile @@ -0,0 +1,32 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet 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 FeuerWare. +# +# 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 +# ****************************************************************************** +# $Id$ + +SubDir TOP board msb-430 ; + +SubInclude TOP board msb-430-common ; +SubInclude TOP cpu $(CPU) ; + diff --git a/board/msb-430/Jamrules.msb-430 b/board/msb-430/Jamrules.msb-430 new file mode 100644 index 0000000000..ae1d28b444 --- /dev/null +++ b/board/msb-430/Jamrules.msb-430 @@ -0,0 +1,3 @@ +BOARD = msb-430 ; + +include $(TOP)/board/msb-430-common/Jamrules.msb-430-common ; diff --git a/board/msb-430/include/board.h b/board/msb-430/include/board.h new file mode 100644 index 0000000000..6ca75c9c45 --- /dev/null +++ b/board/msb-430/include/board.h @@ -0,0 +1,69 @@ +/****************************************************************************** +Copyright 2009, Freie Universitaet 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 FeuerWare. + +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 +*******************************************************************************/ + +#ifndef _MSB_BOARD_H +#define _MSB_BOARD_H + +/** + * @defgroup msb_430h ScatterWeb MSB-430H + * @ingroup msp430 + * +

Compontents

+\li MSP430 +\li CC1100 + +* @{ +*/ + +/** + * @file + * @brief MSB-430H Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @version $Revision$ + * + * @note $Id$ + */ + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 7372800uL +#define MSP430_HAS_DCOR 1 +#define MSP430_HAS_EXTERNAL_CRYSTAL 0 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x80 +#define LEDS_CONF_GREEN 0x00 +#define LEDS_CONF_YELLOW 0x00 + +#define RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define RED_OFF LEDS_PxOUT |= LEDS_CONF_RED + +#include + +/** @} */ +#endif // _MSB_BOARD_H diff --git a/board/msb-430h/Jamfile b/board/msb-430h/Jamfile index b1181a57db..79e6f920c0 100644 --- a/board/msb-430h/Jamfile +++ b/board/msb-430h/Jamfile @@ -27,9 +27,8 @@ SubDir TOP board msb-430h ; -Module board : board_init.c debug_uart.c ; -UseModule board ; - Module board_cc1100 : driver_cc1100.c ; +SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; + diff --git a/board/msb-430h/Jamrules.msb-430h b/board/msb-430h/Jamrules.msb-430h index 41bf0779d9..d1913ed542 100644 --- a/board/msb-430h/Jamrules.msb-430h +++ b/board/msb-430h/Jamrules.msb-430h @@ -1,37 +1,3 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet 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 FeuerWare. -# -# 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 -# ****************************************************************************** -# $Id$ - BOARD = msb-430h ; -CPU = msp430 ; -MCU = msp430x1612 ; - -FLASH_PORT ?= /dev/ttyUSB0 ; -FLASHER ?= mspdebug ; -FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; - -RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; +include $(TOP)/board/msb-430-common/Jamrules.msb-430-common ; From 57c9d3423f730ceb31751d204d2f8e5ec0d26f03 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 11 Oct 2010 17:32:58 +0200 Subject: [PATCH 004/115] * fix kernel name --- cpu/msp430/startup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu/msp430/startup.c b/cpu/msp430/startup.c index d4a3219135..8e04b9b97d 100644 --- a/cpu/msp430/startup.c +++ b/cpu/msp430/startup.c @@ -1,6 +1,6 @@ #include -#include "board.h" -#include "kernel_intern.h" +#include +#include extern void board_init(); @@ -10,7 +10,7 @@ __attribute__ ((constructor)) static void startup() { board_init(); - puts("FireKernel MSP430 hardware initialization complete.\n"); + puts("ukleos MSP430 hardware initialization complete.\n"); kernel_init(); } From 1c4f8b52c834e54bc1408aea652196f5719709cb Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 25 Oct 2010 15:30:27 +0200 Subject: [PATCH 005/115] * fix pingpong-Jamfile to use new Module framework --- projects/pingpong/Jamfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/projects/pingpong/Jamfile b/projects/pingpong/Jamfile index e2ed342b57..2de8f82530 100644 --- a/projects/pingpong/Jamfile +++ b/projects/pingpong/Jamfile @@ -1,6 +1,4 @@ SubDir TOP projects pingpong ; -# LOCATE_TARGET = $(SEARCH_SOURCE)/bin ; -Library pingpong : main.c ; - -LinkLibraries $(BOARD).elf : pingpong ; +Module pingpong : main.c ; +UseModule pingpong ; From 57dc520af98ea1d3024e46ff9f154618ddcdad3f Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 25 Oct 2010 15:31:02 +0200 Subject: [PATCH 006/115] * change default lpc2387 stacksize to 4500 bytes --- cpu/lpc2387/include/cpu-conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/lpc2387/include/cpu-conf.h b/cpu/lpc2387/include/cpu-conf.h index dd0a216d01..fd9ecb10b2 100644 --- a/cpu/lpc2387/include/cpu-conf.h +++ b/cpu/lpc2387/include/cpu-conf.h @@ -68,7 +68,7 @@ and the mailinglist (subscription via web site) * @{ */ #ifndef KERNEL_CONF_STACKSIZE_DEFAULT -#define KERNEL_CONF_STACKSIZE_DEFAULT 2500 +#define KERNEL_CONF_STACKSIZE_DEFAULT 4500 #endif #define KERNEL_CONF_STACKSIZE_IDLE 500 From 58bf287751301cc92baa912a73ae884e3ae62317 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 25 Oct 2010 15:38:22 +0200 Subject: [PATCH 007/115] * misc fixes --- sys/shell/shell.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 6a960b47f0..3c017c1a05 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -55,7 +55,7 @@ static void(*find_handler(const shell_command_t *command_list, char *command))(c if ( strcmp(entry->name, command) == 0) { return entry->handler; } else { - command_list++; + entry++; } } return NULL; @@ -69,14 +69,13 @@ static void handle_input_line(shell_t *shell, char* line) { if (command) { handler = find_handler(shell->command_list, command); - if (handler) { + if (handler != NULL) { handler(line); } else { - printf("shell: command \"%s\" not found.\n", command); + puts("shell: command not found."); } } - free(line); } int readline(shell_t *shell, char* buf, int size) { @@ -109,7 +108,9 @@ void shell_run(shell_t *shell) { shell->put_char('>'); int res = readline(shell, line_buf, sizeof(line_buf)); if (! res ) { - handle_input_line(shell, strdup(line_buf)); + char* line_copy = strdup(line_buf); + handle_input_line(shell, line_copy); + free(line_copy); } } } From 2acc0368315a025fbfdbd98ef39cbc87bb8a31fb Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 25 Oct 2010 15:39:26 +0200 Subject: [PATCH 008/115] * fix msba2 flash command to use lpc2k_pgm from path, without flashutil --- board/msba2/Jamrules.msba2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/board/msba2/Jamrules.msba2 b/board/msba2/Jamrules.msba2 index 5111de74d3..b0ad55f759 100644 --- a/board/msba2/Jamrules.msba2 +++ b/board/msba2/Jamrules.msba2 @@ -29,5 +29,5 @@ CPU = lpc2387 ; HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; -FLASHER ?= $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; -FLASHFLAGS ?= --basedir $(TOP)/board/msba2/tools --id "MSB-A2" --ports "$(PORT)" ; +FLASHER ?= $(POSIXSHELL) lpc2k_pgm ; +FLASHFLAGS ?= "$(PORT)" ; From f945b72067f06533da61df76282e4b5de47c3d97 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 25 Oct 2010 15:40:01 +0200 Subject: [PATCH 009/115] * API CHANGE: thread_create no longer uses malloc --- core/include/flags.h | 4 +-- core/include/thread.h | 6 ++-- core/kernel_init.c | 11 +++++-- core/scheduler.c | 9 ++++-- core/thread.c | 55 +++++++++++--------------------- drivers/cc110x/cc1100_phy.c | 10 ++++-- projects/pingpong/main.c | 5 ++- projects/pingpong_sync/main.c | 5 ++- projects/test_sleep/main.c | 4 ++- projects/test_thread_exit/main.c | 5 ++- sys/uart0.c | 6 +++- 11 files changed, 68 insertions(+), 52 deletions(-) diff --git a/core/include/flags.h b/core/include/flags.h index 97da2efa8a..462133ef70 100644 --- a/core/include/flags.h +++ b/core/include/flags.h @@ -15,9 +15,9 @@ #ifndef _FLAGS_H #define _FLAGS_H -#define CREATE_WOUT_YIELD 4 #define CREATE_SLEEPING 1 -#define EXPECTS_REPLY 2 +#define AUTO_FREE 2 +#define CREATE_WOUT_YIELD 4 #define CREATE_STACKTEST 8 /** diff --git a/core/include/thread.h b/core/include/thread.h index 9f75470acb..d2a4c8e7e8 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -19,7 +19,9 @@ /** * @brief Creates a new thread. * This version will allocate it's stack itself using malloc. - * + * + * @param cb Address of preallocated tcb structure + * @param stack Lowest address of preallocated stack space * @param stacksize * @param flags Options: * YIELD: force context switch. @@ -32,7 +34,7 @@ * * @return returns <0 on error, pid of newly created task else. */ -int thread_create(int stacksize, char priority, int flags, void (*function) (void), const char* name); +int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, void (*function) (void), const char* name); /** * @brief returns the status of a process. diff --git a/core/kernel_init.c b/core/kernel_init.c index cc6e273c2f..7de3b50e3d 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -41,6 +41,7 @@ volatile int lpm_prevent_sleep = 0; extern void main(void); extern void fk_switch_context_exit(void); + void fk_idle(void) { while(1) { if (lpm_prevent_sleep) { @@ -57,6 +58,12 @@ void fk_idle(void) { const char *main_name = "main"; const char *idle_name = "idle"; +static tcb main_tcb; +static char main_stack[KERNEL_CONF_STACKSIZE_MAIN]; + +static tcb idle_tcb; +static char idle_stack[KERNEL_CONF_STACKSIZE_IDLE]; + #ifdef MODULE_AUTO_INIT #define MAIN_FUNC auto_init #else @@ -70,11 +77,11 @@ void kernel_init(void) scheduler_init(); - if (thread_create(KERNEL_CONF_STACKSIZE_IDLE, PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, fk_idle, idle_name) < 0) { + if (thread_create(&main_tcb, main_stack, sizeof(main_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, fk_idle, idle_name) < 0) { printf("kernel_init(): error creating idle task.\n"); } - if (thread_create(KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) { + if (thread_create(&idle_tcb, idle_stack, sizeof(idle_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) { printf("kernel_init(): error creating main task.\n"); } diff --git a/core/scheduler.c b/core/scheduler.c index 279bb456a2..f391bb386a 100644 --- a/core/scheduler.c +++ b/core/scheduler.c @@ -149,12 +149,17 @@ extern void fk_switch_context_exit(void); void fk_task_exit(void) { DEBUG("fk_task_exit(): ending task %s...\n", fk_thread->name); + tcb* thread = (tcb*)fk_thread; dINT(); fk_threads[fk_thread->pid] = NULL; num_tasks--; - sched_set_status((tcb*)fk_thread, STATUS_STOPPED); + sched_set_status(thread, STATUS_STOPPED); + +// if ( thread->flags & AUTO_FREE ) { +// free(thread)->stack_start); +// free(thread); +// } - free(((tcb*)fk_thread)->stack_start); fk_thread = NULL; fk_switch_context_exit(); } diff --git a/core/thread.c b/core/thread.c index a9f4663267..b6895a6764 100644 --- a/core/thread.c +++ b/core/thread.c @@ -74,7 +74,7 @@ int fk_measure_stack_free(char* stack) { return space; } -int thread_create(int stacksize, char priority, int flags, void (*function) (void), const char* name) +int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, void (*function) (void), const char* name) { /* stacksize must be a multitude of 4 for alignment and stacktest */ // assert( ((stacksize & 0x03) == 0) && (stacksize > 0) ); @@ -86,20 +86,6 @@ int thread_create(int stacksize, char priority, int flags, void (*function) (voi return -EINVAL; } - tcb *pd = (tcb*)malloc(sizeof(tcb)); - if ( pd == NULL) { - DEBUG("thread_create(): out of memory\n"); - return -ENOMEM; - } - - char *stack = (char*)malloc(stacksize); - if (stack==NULL) - { - DEBUG("thread_create(): out of memory\n"); - free (pd); - return -ENOMEM; - } - if (flags & CREATE_STACKTEST) { /* assign each int of the stack the value of it's address */ unsigned int *stackmax = (unsigned int*) ((char*)stack + stacksize); @@ -120,8 +106,8 @@ int thread_create(int stacksize, char priority, int flags, void (*function) (voi int pid = 0; while (pid < MAXTHREADS) { if (fk_threads[pid] == NULL) { - fk_threads[pid] = pd; - pd->pid = pid; + fk_threads[pid] = cb; + cb->pid = pid; break; } pid++; @@ -130,42 +116,39 @@ int thread_create(int stacksize, char priority, int flags, void (*function) (voi if (pid == MAXTHREADS) { DEBUG("thread_create(): too many threads!\n"); - free (pd); - free (stack); - if (! inISR()) { eINT(); } return -EOVERFLOW; } - pd->sp = fk_stack_init(function,stack+stacksize); - pd->stack_start = stack; - pd->stack_size = stacksize; + cb->sp = fk_stack_init(function,stack+stacksize); + cb->stack_start = stack; + cb->stack_size = stacksize; - pd->priority = priority; - pd->status = 0; + cb->priority = priority; + cb->status = 0; - pd->name = name; + cb->name = name; - pd->wait_data = NULL; + cb->wait_data = NULL; - pd->msg_queue.data = 0; - pd->msg_queue.priority = 0; - pd->msg_queue.next = NULL; + cb->msg_queue.data = 0; + cb->msg_queue.priority = 0; + cb->msg_queue.next = NULL; - pd->rq_entry.data = (unsigned int) pd; - pd->rq_entry.next = NULL; - pd->rq_entry.prev = NULL; + cb->rq_entry.data = (unsigned int) cb; + cb->rq_entry.next = NULL; + cb->rq_entry.prev = NULL; num_tasks++; - DEBUG("Created thread %s. PID: %u. Priority: %u.\n", name, pd->pid, priority); + DEBUG("Created thread %s. PID: %u. Priority: %u.\n", name, cb->pid, priority); if (flags & CREATE_SLEEPING) { - sched_set_status(pd, STATUS_SLEEPING); + sched_set_status(cb, STATUS_SLEEPING); } else { - sched_set_status(pd, STATUS_PENDING); + sched_set_status(cb, STATUS_PENDING); if (!(flags & CREATE_WOUT_YIELD)) { if (! inISR()) { eINT(); diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 036792ee2e..08594d1e3c 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -94,11 +94,15 @@ static const pm_table_t handler_table; static const char *cc1100_event_handler_name = "cc1100_event_handler"; static mutex_t cc1100_mutex; volatile int cc1100_mutex_pid; -static uint16_t cc1100_event_handler_pid; -static void cc1100_event_handler_function(void); static swtimer_t cc1100_watch_dog; static uint64_t cc1100_watch_dog_period = 0; +static uint16_t cc1100_event_handler_pid; +static void cc1100_event_handler_function(void); + +static tcb event_handler_tcb; +static char event_handler_stack[KERNEL_CONF_STACKSIZE_MAIN]; + /*---------------------------------------------------------------------------*/ // Sequence number buffer management data structures /*---------------------------------------------------------------------------*/ @@ -188,7 +192,7 @@ void cc1100_phy_init() mutex_init(&cc1100_mutex); // Allocate event numbers and start cc1100 event process - cc1100_event_handler_pid = thread_create(2500, PRIORITY_CC1100, CREATE_STACKTEST, + cc1100_event_handler_pid = thread_create(&event_handler_tcb, event_handler_stack, sizeof(event_handler_stack), PRIORITY_CC1100, CREATE_STACKTEST, cc1100_event_handler_function, cc1100_event_handler_name); // Active watchdog for the first time diff --git a/projects/pingpong/main.c b/projects/pingpong/main.c index daf898b88d..62b720a55a 100644 --- a/projects/pingpong/main.c +++ b/projects/pingpong/main.c @@ -15,13 +15,16 @@ void second_thread(void) { } } +tcb second_thread_tcb; +char second_thread_stack[KERNEL_CONF_STACKSIZE_MAIN]; + int main(void) { printf("Hello world!\n"); msg m; - int pid = thread_create(KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); + int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); m.content.value = 1; diff --git a/projects/pingpong_sync/main.c b/projects/pingpong_sync/main.c index 739ec3acf7..d0468ffeac 100644 --- a/projects/pingpong_sync/main.c +++ b/projects/pingpong_sync/main.c @@ -15,13 +15,16 @@ void second_thread(void) { } } +tcb second_thread_tcb; +char second_thread_stack[8192]; + int main(void) { printf("Hello world!\n"); msg m; - int pid = thread_create(8192, PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); + int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); m.content.value = 1; diff --git a/projects/test_sleep/main.c b/projects/test_sleep/main.c index 32e05f90b7..75a67e8938 100644 --- a/projects/test_sleep/main.c +++ b/projects/test_sleep/main.c @@ -18,6 +18,8 @@ void second_thread(void) { } } +tcb second_thread_tcb; +char second_thread_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; int main(void) { @@ -25,7 +27,7 @@ int main(void) printf("Hello world!\n"); - int pid = thread_create(KERNEL_CONF_STACKSIZE_DEFAULT, PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper"); + int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper"); if (pid < 0) { puts("Error creating second_thread! Stopping test."); diff --git a/projects/test_thread_exit/main.c b/projects/test_thread_exit/main.c index 3f09c7284e..4646c2679a 100644 --- a/projects/test_thread_exit/main.c +++ b/projects/test_thread_exit/main.c @@ -9,8 +9,11 @@ void second_thread(void) { puts("2nd: running..."); } +tcb second_thread_tcb; +char second_thread_stack[8192]; + int main(void) { - int pid = thread_create(8192, PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "nr2"); + int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "nr2"); puts("Main thread exiting..."); } diff --git a/sys/uart0.c b/sys/uart0.c index e6ad35bc38..c4656d6cf2 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -13,15 +13,19 @@ int uart0_handler_pid; static char buffer[UART0_BUFSIZE]; +static tcb uart0_thread_tcb; +static char uart0_thread_stack[KERNEL_CONF_STACKSIZE_MAIN]; + static void uart0_loop() { chardev_loop(&uart0_ringbuffer); } void board_uart0_init() { ringbuffer_init(&uart0_ringbuffer, buffer, UART0_BUFSIZE); - int pid = thread_create(KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); + int pid = thread_create(&uart0_thread_tcb, uart0_thread_stack, sizeof(uart0_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); uart0_handler_pid = pid; puts("uart0_init() [OK]"); + printf("%i\n", sizeof(uart0_thread_stack)); } void uart0_handle_incoming(int c) { From 38994445dd2c07df9cf6696cca3e38dd8ecb391a Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 26 Oct 2010 16:51:28 +0200 Subject: [PATCH 010/115] python expect swtimer test included --- projects/test_swtimer_basic/Jamfile | 5 +++ projects/test_swtimer_basic/main.c | 45 +++++++++++++++++++ projects/test_swtimer_basic/tests/hello-world | 13 ++++++ projects/test_swtimer_basic/tests/swtimer.py | 15 +++++++ 4 files changed, 78 insertions(+) create mode 100644 projects/test_swtimer_basic/Jamfile create mode 100644 projects/test_swtimer_basic/main.c create mode 100755 projects/test_swtimer_basic/tests/hello-world create mode 100755 projects/test_swtimer_basic/tests/swtimer.py diff --git a/projects/test_swtimer_basic/Jamfile b/projects/test_swtimer_basic/Jamfile new file mode 100644 index 0000000000..7a5e6acb08 --- /dev/null +++ b/projects/test_swtimer_basic/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects expect_swtimer ; + +Module expect_swtimer : main.c : swtimer ; + +UseModule expect_swtimer ; diff --git a/projects/test_swtimer_basic/main.c b/projects/test_swtimer_basic/main.c new file mode 100644 index 0000000000..25837a3ace --- /dev/null +++ b/projects/test_swtimer_basic/main.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include + +void callback(void* ptr){ + puts((char*)ptr); +} + +void wakeup_thread(void){ + puts("wakeup"); +} + +void msg_thread(void){ + msg m; + msg_receive(&m); + printf("%s\n",(char*)m.content.ptr); +} + +int main(void) +{ + hwtimer_init(); + swtimer_init(); + + int pid1 = thread_create(8192, PRIORITY_MAIN-1, + CREATE_WOUT_YIELD | CREATE_SLEEPING | CREATE_STACKTEST, wakeup_thread, "nr1"); + + int pid2 = thread_create(8192, PRIORITY_MAIN-1, + /*CREATE_WOUT_YIELD | CREATE_SLEEPING |*/ CREATE_STACKTEST, msg_thread, "nr2"); + + + swtimer_t cbt; + swtimer_t wut; + swtimer_t mst; + /* test callback */ + swtimer_set_cb(&cbt,1000L,callback,"callback"); + /* test wake-up */ + swtimer_set_wakeup(&wut, 1000L, pid1); + /* test message */ + swtimer_set_msg(&mst,1000L, pid2, "message"); + + while(1); +} diff --git a/projects/test_swtimer_basic/tests/hello-world b/projects/test_swtimer_basic/tests/hello-world new file mode 100755 index 0000000000..6f4a6ca811 --- /dev/null +++ b/projects/test_swtimer_basic/tests/hello-world @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn board/msba2/tools/bin/pseudoterm $env(PORT) + +expect { + "Hello World!" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" + diff --git a/projects/test_swtimer_basic/tests/swtimer.py b/projects/test_swtimer_basic/tests/swtimer.py new file mode 100755 index 0000000000..013073dd0b --- /dev/null +++ b/projects/test_swtimer_basic/tests/swtimer.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +import pexpect +import os +import subprocess + +child = pexpect.spawn ("board/msba2/tools/bin/pseudoterm %s" % os.environ["PORT"]) + +null = open('/dev/null', 'wb') +subprocess.call(['jam', 'reset'], stdout=null) + +child.expect ('callback\r\n'); +child.expect ('wakeup\r\n'); +child.expect ('message\r\n'); +print("Test successful!") From c80ab019c4c6578ca34a370a92a3ebddce45cb7a Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 26 Oct 2010 16:59:05 +0200 Subject: [PATCH 011/115] removed accidentally added file from repo --- projects/test_swtimer_basic/tests/hello-world | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100755 projects/test_swtimer_basic/tests/hello-world diff --git a/projects/test_swtimer_basic/tests/hello-world b/projects/test_swtimer_basic/tests/hello-world deleted file mode 100755 index 6f4a6ca811..0000000000 --- a/projects/test_swtimer_basic/tests/hello-world +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/expect - -set timeout 5 - -spawn board/msba2/tools/bin/pseudoterm $env(PORT) - -expect { - "Hello World!" {} - timeout { exit 1 } -} - -puts "\nTest successful!\n" - From f6e76b8f246215598fd82b35d8ced3d28983043d Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 26 Oct 2010 17:06:07 +0200 Subject: [PATCH 012/115] python expect hwtimer test included --- projects/test_hwtimer_basic/Jamfile | 5 ++++ projects/test_hwtimer_basic/main.c | 29 +++++++++++++++++++ .../test_hwtimer_basic/tests/test_hwtimer.py | 17 +++++++++++ 3 files changed, 51 insertions(+) create mode 100644 projects/test_hwtimer_basic/Jamfile create mode 100644 projects/test_hwtimer_basic/main.c create mode 100755 projects/test_hwtimer_basic/tests/test_hwtimer.py diff --git a/projects/test_hwtimer_basic/Jamfile b/projects/test_hwtimer_basic/Jamfile new file mode 100644 index 0000000000..e9f9af9ec8 --- /dev/null +++ b/projects/test_hwtimer_basic/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects test_hwtimer ; + +Module test_hwtimer : main.c : hwtimer ; + +UseModule test_hwtimer ; diff --git a/projects/test_hwtimer_basic/main.c b/projects/test_hwtimer_basic/main.c new file mode 100644 index 0000000000..8e215d1056 --- /dev/null +++ b/projects/test_hwtimer_basic/main.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +void callback(void* ptr) { + puts((char*)ptr); +} + +extern uint32_t hwtimer_now(); + +int main(void) +{ + puts("hwtimer test project."); + + puts("Initializing hwtimer..."); + hwtimer_init(); + + puts("Initializing hwtimer [OK]."); + + +// while (TA0R < 20000); + + hwtimer_set(20000LU, callback, (void*)"callback1"); + hwtimer_set(50000LU, callback, (void*)"callback2"); + hwtimer_set(30000LU, callback, (void*)"callback3"); + + puts("hwtimer set."); +} diff --git a/projects/test_hwtimer_basic/tests/test_hwtimer.py b/projects/test_hwtimer_basic/tests/test_hwtimer.py new file mode 100755 index 0000000000..261c511bb1 --- /dev/null +++ b/projects/test_hwtimer_basic/tests/test_hwtimer.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import pexpect +import os +import subprocess + +child = pexpect.spawn ("board/msba2/tools/bin/pseudoterm %s" % os.environ["PORT"]) + +null = open('/dev/null', 'wb') +subprocess.call(['jam', 'reset'], stdout=null) + +child.expect ('OK\r\n'); +child.expect ('callback1\r\n'); +child.expect ('callback3\r\n'); +child.expect ('callback2\r\n'); +print("Test successful!") + From 7f252e0f2bec5e57502a7d7d6552527cacc016ae Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 26 Oct 2010 17:12:45 +0200 Subject: [PATCH 013/115] python expect thread test included --- .../tests/{swtimer.py => test_swtimer.py} | 0 projects/test_thread_basic/Jamfile | 5 +++++ projects/test_thread_basic/main.c | 14 ++++++++++++++ projects/test_thread_basic/tests/test_thread.py | 15 +++++++++++++++ 4 files changed, 34 insertions(+) rename projects/test_swtimer_basic/tests/{swtimer.py => test_swtimer.py} (100%) create mode 100644 projects/test_thread_basic/Jamfile create mode 100644 projects/test_thread_basic/main.c create mode 100755 projects/test_thread_basic/tests/test_thread.py diff --git a/projects/test_swtimer_basic/tests/swtimer.py b/projects/test_swtimer_basic/tests/test_swtimer.py similarity index 100% rename from projects/test_swtimer_basic/tests/swtimer.py rename to projects/test_swtimer_basic/tests/test_swtimer.py diff --git a/projects/test_thread_basic/Jamfile b/projects/test_thread_basic/Jamfile new file mode 100644 index 0000000000..3f9c7e01da --- /dev/null +++ b/projects/test_thread_basic/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects test_thread_exit ; + +Module test_thread_exit : main.c ; + +UseModule test_thread_exit ; diff --git a/projects/test_thread_basic/main.c b/projects/test_thread_basic/main.c new file mode 100644 index 0000000000..ff95845563 --- /dev/null +++ b/projects/test_thread_basic/main.c @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +void second_thread(void) { + puts("second thread\n"); +} + +int main(void) +{ + int pid = thread_create(8192, PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "nr2"); + puts("first thread\n"); +} diff --git a/projects/test_thread_basic/tests/test_thread.py b/projects/test_thread_basic/tests/test_thread.py new file mode 100755 index 0000000000..40df9e651e --- /dev/null +++ b/projects/test_thread_basic/tests/test_thread.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +import pexpect +import os +import subprocess + +child = pexpect.spawn("board/msba2/tools/bin/pseudoterm %s" % os.environ["PORT"]) + +null = open('/dev/null', 'wb') +subprocess.call(['jam', 'reset'], stdout=null) + +child.expect ('first thread\r\n') +child.expect ('second thread\r\n') +print("Test successful!") + From 6f5b9c599aca1b5603729c86537de0dbdf486ebc Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 26 Oct 2010 17:14:55 +0200 Subject: [PATCH 014/115] ... --- projects/test_swtimer_basic/tests/test_swtimer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/test_swtimer_basic/tests/test_swtimer.py b/projects/test_swtimer_basic/tests/test_swtimer.py index 013073dd0b..465e5562ad 100755 --- a/projects/test_swtimer_basic/tests/test_swtimer.py +++ b/projects/test_swtimer_basic/tests/test_swtimer.py @@ -4,7 +4,7 @@ import pexpect import os import subprocess -child = pexpect.spawn ("board/msba2/tools/bin/pseudoterm %s" % os.environ["PORT"]) +child = pexpect.spawn ("pseudoterm %s" % os.environ["PORT"]) null = open('/dev/null', 'wb') subprocess.call(['jam', 'reset'], stdout=null) From 06036def7ca0f84f858979cef60480bb0b98d4d4 Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Wed, 27 Oct 2010 21:54:08 +0200 Subject: [PATCH 015/115] fixed bug in msg_reply function --- core/msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/msg.c b/core/msg.c index 373309603d..707f2effd2 100644 --- a/core/msg.c +++ b/core/msg.c @@ -133,7 +133,7 @@ int msg_reply(msg *m, msg *reply) { DEBUG("%s: msg_reply(): direct msg copy.\n", fk_thread->name); /* copy msg to target */ msg* target_message = (msg*)target->wait_data; - *target_message = *m; + *target_message = *reply; sched_set_status(target, STATUS_PENDING); restoreIRQ(state); fk_yield(); From 7a8a07fe089602a890c2704e172454a34b0dbb41 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 28 Oct 2010 10:12:45 +0200 Subject: [PATCH 016/115] * msg: fix msg_reply --- core/msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/msg.c b/core/msg.c index 373309603d..707f2effd2 100644 --- a/core/msg.c +++ b/core/msg.c @@ -133,7 +133,7 @@ int msg_reply(msg *m, msg *reply) { DEBUG("%s: msg_reply(): direct msg copy.\n", fk_thread->name); /* copy msg to target */ msg* target_message = (msg*)target->wait_data; - *target_message = *m; + *target_message = *reply; sched_set_status(target, STATUS_PENDING); restoreIRQ(state); fk_yield(); From 1e238e413125f2b63ae555fbafbc18063a1ec63b Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 28 Oct 2010 11:22:57 +0200 Subject: [PATCH 017/115] * massive name changes --- board/olimex_lpc2148/tick.c | 4 +- core/Jamfile | 2 +- core/include/kernel.h | 2 +- core/include/kernel_intern.h | 8 +-- core/include/{scheduler.h => sched.h} | 12 ++-- core/include/thread.h | 4 +- core/kernel_init.c | 17 +++--- core/msg.c | 58 +++++++++---------- core/mutex.c | 38 ++++++------- core/{scheduler.c => sched.c} | 81 +++++++++++++-------------- core/thread.c | 36 ++++++------ cpu/arm_common/arm_cpu.c | 12 ++-- cpu/arm_common/atomic.s | 2 +- cpu/arm_common/common.s | 41 +++++++------- cpu/arm_common/include/arm_cpu.h | 2 +- cpu/arm_common/syscalls.c | 2 +- cpu/lpc214x/startup.s | 2 +- cpu/lpc2387/startup.s | 2 +- cpu/msp430/cpu.c | 22 ++++---- cpu/msp430/include/cpu.h | 10 ++-- drivers/cc110x/cc1100_phy.c | 4 +- projects/test_sleep/main.c | 2 +- projects/test_swtimer_remove/main.c | 12 ++-- sys/shell/ps.c | 6 +- sys/swtimer.c | 2 +- 25 files changed, 189 insertions(+), 194 deletions(-) rename core/include/{scheduler.h => sched.h} (80%) rename core/{scheduler.c => sched.c} (59%) diff --git a/board/olimex_lpc2148/tick.c b/board/olimex_lpc2148/tick.c index 08b3dcb0bb..4b8912607b 100644 --- a/board/olimex_lpc2148/tick.c +++ b/board/olimex_lpc2148/tick.c @@ -51,12 +51,12 @@ int counter = 0; void Timer0_IRQHandler (void) { - extern unsigned int fk_context_switch_request; + extern unsigned int sched_context_switch_request; counter++; T0IR |= 0xff; // reset timer1 interrupt flag sl_printf("#"); - fk_context_switch_request = 1; + sched_context_switch_request = 1; VICVectAddr = 0; // acknowledge interrupt (if using VIC IRQ) } diff --git a/core/Jamfile b/core/Jamfile index 64862e7ed7..2787dcbc76 100644 --- a/core/Jamfile +++ b/core/Jamfile @@ -27,7 +27,7 @@ SubDir TOP core ; -Module core : kernel_init.c scheduler.c mutex.c msg.c queue.c +Module core : kernel_init.c sched.c mutex.c msg.c queue.c clist.c thread.c bitarithm.c ; Module hwtimer : hwtimer.c : hwtimer_cpu ; diff --git a/core/include/kernel.h b/core/include/kernel.h index 69e12e6dd8..97313916e9 100644 --- a/core/include/kernel.h +++ b/core/include/kernel.h @@ -25,7 +25,7 @@ #include "tcb.h" #include "cpu.h" #include "flags.h" -#include "scheduler.h" +#include "sched.h" #include "cpu-conf.h" /* ------------------------------------------------------------------------- */ diff --git a/core/include/kernel_intern.h b/core/include/kernel_intern.h index a58205319e..7b5bd12c17 100644 --- a/core/include/kernel_intern.h +++ b/core/include/kernel_intern.h @@ -18,10 +18,10 @@ void kernel_init(void); void board_init_drivers(); -char *fk_stack_init(void *task_func, void *stack_start); -void fk_task_exit(void); -void fk_print_stack (); -int fk_measure_stack_free(char* stack); +char *thread_stack_init(void *task_func, void *stack_start); +void sched_task_exit(void); +void thread_print_stack (); +int thread_measure_stack_usage(char* stack); /** @} */ #endif /* KERNEL_INTERN_H_ */ diff --git a/core/include/scheduler.h b/core/include/sched.h similarity index 80% rename from core/include/scheduler.h rename to core/include/sched.h index afff055c97..ca5f74ddb1 100644 --- a/core/include/scheduler.h +++ b/core/include/sched.h @@ -21,18 +21,18 @@ #define SCHED_PRIO_LEVELS 16 #endif -void scheduler_init(); -void fk_schedule(); +void sched_init(); +void sched_run(); void sched_set_status(tcb *process, unsigned int status); -volatile unsigned int fk_context_switch_request; +volatile unsigned int sched_context_switch_request; -volatile tcb *fk_threads[MAXTHREADS]; -volatile tcb *fk_thread; +volatile tcb *sched_threads[MAXTHREADS]; +volatile tcb *active_thread; extern volatile int num_tasks; -volatile int fk_pid; +volatile int thread_pid; //#define SCHEDSTATISTICS #if SCHEDSTATISTICS diff --git a/core/include/thread.h b/core/include/thread.h index d2a4c8e7e8..df4c73060d 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -65,9 +65,9 @@ int thread_getpid(); * @brief Measures the stack usage of a stack. * Only works if the thread was created with the flag CREATE_STACKTEST. * - * @param stack The stack you want to measure. try fk_thread->stack_start. + * @param stack The stack you want to measure. try active_thread->stack_start. */ -int fk_measure_stack_free(char* stack); +int thread_measure_stack_usage(char* stack); /* @} */ #endif /* __THREAD_H */ diff --git a/core/kernel_init.c b/core/kernel_init.c index 7de3b50e3d..dca0b45c94 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -20,7 +20,7 @@ #include "tcb.h" #include "kernel.h" #include "kernel_intern.h" -#include "scheduler.h" +#include "sched.h" #include "flags.h" #include "cpu.h" #include "lpm.h" @@ -34,15 +34,14 @@ #define ENABLE_DEBUG #include "debug.h" -volatile tcb *fk_threads[MAXTHREADS]; -volatile tcb *fk_thread; +volatile tcb *sched_threads[MAXTHREADS]; +volatile tcb *active_thread; volatile int lpm_prevent_sleep = 0; extern void main(void); -extern void fk_switch_context_exit(void); +extern void cpu_switch_context_exit(void); - -void fk_idle(void) { +static void idle_thread(void) { while(1) { if (lpm_prevent_sleep) { lpm_set(LPM_IDLE); @@ -75,9 +74,9 @@ void kernel_init(void) dINT(); printf("kernel_init(): This is ukleos!\n"); - scheduler_init(); + sched_init(); - if (thread_create(&main_tcb, main_stack, sizeof(main_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, fk_idle, idle_name) < 0) { + if (thread_create(&main_tcb, main_stack, sizeof(main_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_stack, idle_name) < 0) { printf("kernel_init(): error creating idle task.\n"); } @@ -87,6 +86,6 @@ void kernel_init(void) printf("kernel_init(): jumping into first task...\n"); - fk_switch_context_exit(); + cpu_switch_context_exit(); } diff --git a/core/msg.c b/core/msg.c index 707f2effd2..32eda613fc 100644 --- a/core/msg.c +++ b/core/msg.c @@ -14,7 +14,7 @@ */ #include "kernel.h" -#include "scheduler.h" +#include "sched.h" #include "msg.h" #include "queue.h" #include "tcb.h" @@ -33,9 +33,9 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { int result = 1; - tcb *target = (tcb*)fk_threads[target_pid]; + tcb *target = (tcb*)sched_threads[target_pid]; - m->sender_pid = fk_pid; + m->sender_pid = thread_pid; if (m->sender_pid == target_pid) return -1; dINT(); @@ -47,33 +47,33 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { if (target->status != STATUS_RECEIVE_BLOCKED) { if (! block ) { - DEBUG("%s: receiver not waiting. block=%u\n", fk_thread->name, block); + DEBUG("%s: receiver not waiting. block=%u\n", active_thread->name, block); eINT(); return 0; } - DEBUG("%s: send_blocked.\n", fk_thread->name); + DEBUG("%s: send_blocked.\n", active_thread->name); queue_node_t n; - n.priority = fk_thread->priority; - n.data = (unsigned int) fk_thread; - DEBUG("%s: Adding node to msg_queue:\n", fk_thread->name); + n.priority = active_thread->priority; + n.data = (unsigned int) active_thread; + DEBUG("%s: Adding node to msg_queue:\n", active_thread->name); queue_priority_add(&(target->msg_queue), &n); - fk_thread->wait_data = (void*) m; + active_thread->wait_data = (void*) m; int newstatus; - if (fk_thread->status == STATUS_REPLY_BLOCKED) { + if (active_thread->status == STATUS_REPLY_BLOCKED) { newstatus = STATUS_REPLY_BLOCKED; } else { newstatus = STATUS_SEND_BLOCKED; } - sched_set_status((tcb*)fk_thread, newstatus); + sched_set_status((tcb*)active_thread, newstatus); - DEBUG("%s: back from send block.\n", fk_thread->name); + DEBUG("%s: back from send block.\n", active_thread->name); } else { - DEBUG("%s: direct msg copy.\n", fk_thread->name); + DEBUG("%s: direct msg copy.\n", active_thread->name); /* copy msg to target */ msg* target_message = (msg*)target->wait_data; *target_message = *m; @@ -81,13 +81,13 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { } eINT(); - fk_yield(); + thread_yield(); return result; } int msg_send_int(msg* m, unsigned int target_pid) { - tcb *target = (tcb*)fk_threads[target_pid]; + tcb *target = (tcb*)sched_threads[target_pid]; if (target->status == STATUS_RECEIVE_BLOCKED) { DEBUG("msg_send_int: direct msg copy.\n"); @@ -99,7 +99,7 @@ int msg_send_int(msg* m, unsigned int target_pid) { *target_message = *m; sched_set_status(target, STATUS_PENDING); - fk_context_switch_request = 1; + sched_context_switch_request = 1; return 1; } else { DEBUG("msg_send_int: receiver not waiting.\n"); @@ -110,7 +110,7 @@ int msg_send_int(msg* m, unsigned int target_pid) { int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { dINT(); - tcb *me = (tcb*) fk_threads[fk_pid]; + tcb *me = (tcb*) sched_threads[thread_pid]; sched_set_status(me, STATUS_REPLY_BLOCKED); me->wait_data = (void*) reply; msg_send(m, target_pid, true); @@ -123,59 +123,59 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { int msg_reply(msg *m, msg *reply) { int state = disableIRQ(); - tcb *target = (tcb*)fk_threads[m->sender_pid]; + tcb *target = (tcb*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { - DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", fk_thread->name, target->name); + DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", active_thread->name, target->name); restoreIRQ(state); return -1; } - DEBUG("%s: msg_reply(): direct msg copy.\n", fk_thread->name); + DEBUG("%s: msg_reply(): direct msg copy.\n", active_thread->name); /* copy msg to target */ msg* target_message = (msg*)target->wait_data; *target_message = *reply; sched_set_status(target, STATUS_PENDING); restoreIRQ(state); - fk_yield(); + thread_yield(); return 1; } int msg_reply_int(msg *m, msg *reply) { - tcb *target = (tcb*)fk_threads[m->sender_pid]; + 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.", fk_thread->name, target->name); + 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; *target_message = *m; sched_set_status(target, STATUS_PENDING); - fk_context_switch_request = 1; + sched_context_switch_request = 1; return 1; } int msg_receive(msg* m) { dINT(); - DEBUG("%s: msg_receive.\n", fk_thread->name); + DEBUG("%s: msg_receive.\n", active_thread->name); - tcb *me = (tcb*) fk_threads[fk_pid]; + tcb *me = (tcb*) sched_threads[thread_pid]; me->wait_data = (void*) m; queue_node_t *n = queue_remove_head(&(me->msg_queue)); if (n == NULL) { - DEBUG("%s: msg_receive blocked\n", fk_thread->name); + DEBUG("%s: msg_receive blocked\n", active_thread->name); sched_set_status(me, STATUS_RECEIVE_BLOCKED); eINT(); - fk_yield(); + thread_yield(); /* sender copied message */ return 1; } else { - DEBUG("%s: msg_receive direct copy.\n", fk_thread->name); + DEBUG("%s: msg_receive direct copy.\n", active_thread->name); tcb *sender = (tcb*)n->data; /* copy msg */ diff --git a/core/mutex.c b/core/mutex.c index a9d4722ea3..be33fba931 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -19,7 +19,7 @@ #include "queue.h" #include "tcb.h" #include "kernel.h" -#include "scheduler.h" +#include "sched.h" //#define ENABLE_DEBUG #include @@ -35,17 +35,17 @@ int mutex_init(struct mutex_t* mutex) { } int mutex_trylock(struct mutex_t* mutex) { - return (atomic_set_return(&mutex->val, fk_pid ) == 0); + return (atomic_set_return(&mutex->val, thread_pid ) == 0); } int prio() { - return fk_thread->priority; + return active_thread->priority; } int mutex_lock(struct mutex_t* mutex) { - DEBUG("%s: trying to get mutex. val: %u\n", fk_thread->name, mutex->val); + DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val); - if (atomic_set_return(&mutex->val,fk_pid) != 0) { + if (atomic_set_return(&mutex->val,thread_pid) != 0) { // mutex was locked. mutex_wait(mutex); } @@ -53,14 +53,14 @@ int mutex_lock(struct mutex_t* mutex) { } void mutex_unlock(struct mutex_t* mutex, int yield) { - DEBUG("%s: unlocking mutex. val: %u pid: %u\n", fk_thread->name, mutex->val, fk_pid); + DEBUG("%s: unlocking mutex. val: %u pid: %u\n", active_thread->name, mutex->val, thread_pid); int me_value; if (inISR()) { me_value = 0; yield = MUTEX_INISR; } else { - me_value = fk_pid; + me_value = thread_pid; } if (atomic_set_return(&mutex->val,0) != me_value ) { @@ -71,36 +71,36 @@ void mutex_unlock(struct mutex_t* mutex, int yield) { void mutex_wait(struct mutex_t *mutex) { dINT(); - DEBUG("%s: Mutex in use. %u\n", fk_thread->name, mutex->val); + DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val); if (mutex->val == 0) { // somebody released the mutex. return. - mutex->val = fk_pid; - DEBUG("%s: mutex_wait early out. %u\n", fk_thread->name, mutex->val); + mutex->val = thread_pid; + DEBUG("%s: mutex_wait early out. %u\n", active_thread->name, mutex->val); eINT(); return; } - sched_set_status((tcb*)fk_thread, STATUS_MUTEX_BLOCKED); + sched_set_status((tcb*)active_thread, STATUS_MUTEX_BLOCKED); queue_node_t n; - n.priority = (unsigned int) fk_thread->priority; - n.data = (unsigned int) fk_thread; + n.priority = (unsigned int) active_thread->priority; + n.data = (unsigned int) active_thread; n.next = NULL; - DEBUG("%s: Adding node to mutex queue: prio: %u data: %u\n", fk_thread->name, n.priority, n.data); + DEBUG("%s: Adding node to mutex queue: prio: %u data: %u\n", active_thread->name, n.priority, n.data); queue_priority_add(&(mutex->queue), &n); eINT(); - fk_yield(); + thread_yield(); /* we were woken up by scheduler. waker removed us from queue. we have the mutex now. */ } void mutex_wake_waiters(struct mutex_t *mutex, int flags) { if ( ! (flags & MUTEX_INISR)) dINT(); - DEBUG("%s: waking up waiters.\n", fk_thread->name); + DEBUG("%s: waking up waiters.\n", active_thread->name); queue_node_t *next = queue_remove_head(&(mutex->queue)); tcb* process = (tcb*)next->data; @@ -113,14 +113,14 @@ void mutex_wake_waiters(struct mutex_t *mutex, int flags) { mutex->val = process->pid; } - DEBUG("%s: waiters woken up.\n", fk_thread->name); + DEBUG("%s: waiters woken up.\n", active_thread->name); /* If called from process, reenable interrupts, yield if requested */ if (! (flags & MUTEX_INISR)) { eINT(); - if (flags & MUTEX_YIELD) fk_yield(); + if (flags & MUTEX_YIELD) thread_yield(); } else { - fk_context_switch_request = 1; + sched_context_switch_request = 1; } } diff --git a/core/scheduler.c b/core/sched.c similarity index 59% rename from core/scheduler.c rename to core/sched.c index f391bb386a..907a635fd9 100644 --- a/core/scheduler.c +++ b/core/sched.c @@ -15,7 +15,7 @@ #include #include -#include "scheduler.h" +#include "sched.h" #include "kernel.h" #include "kernel_intern.h" #include "clist.h" @@ -33,11 +33,11 @@ static uint32_t runqueue_bitcache = 0; schedstat pidlist[MAXTHREADS]; #endif -void scheduler_init() { +void sched_init() { printf("Scheduler..."); int i; for (i=0; istatus == STATUS_RUNNING) { - my_fk_thread->status = STATUS_PENDING; + if (my_active_thread) { + if( my_active_thread->status == STATUS_RUNNING) { + my_active_thread->status = STATUS_PENDING; } #ifdef SCHED_TEST_STACK - if (*((unsigned int*)my_fk_thread->stack_start) != (unsigned int) my_fk_thread->stack_start) { - printf("scheduler(): stack overflow detected, task=%s pid=%u\n", my_fk_thread->name, my_fk_thread->pid); + if (*((unsigned int*)my_active_thread->stack_start) != (unsigned int) my_active_thread->stack_start) { + printf("scheduler(): stack overflow detected, task=%s pid=%u\n", my_active_thread->name, my_active_thread->pid); } #endif @@ -75,12 +75,12 @@ void fk_schedule() { #if SCHEDSTATISTICS extern unsigned long hwtimer_now(void); unsigned int time = hwtimer_now(); - if (my_fk_thread && (pidlist[my_fk_thread->pid].laststart)) { - pidlist[my_fk_thread->pid].runtime += time - pidlist[my_fk_thread->pid].laststart; + if (my_active_thread && (pidlist[my_active_thread->pid].laststart)) { + pidlist[my_active_thread->pid].runtime += time - pidlist[my_active_thread->pid].laststart; } #endif - DEBUG("\nscheduler: previous task: %s\n", ( my_fk_thread == NULL) ? "none" : my_fk_thread->name ); + DEBUG("\nscheduler: previous task: %s\n", ( my_active_thread == NULL) ? "none" : my_active_thread->name ); if (num_tasks == 0) { DEBUG("scheduler: no tasks left.\n"); @@ -88,8 +88,8 @@ void fk_schedule() { DEBUG("scheduler: new task created.\n"); } - my_fk_thread = NULL; - while(! my_fk_thread) { + my_active_thread = NULL; + while(! my_active_thread) { // for (int i = 0; i < SCHED_PRIO_LEVELS; i++) { /* TODO: introduce bitfield cache */ // if (runqueues[i]) { @@ -97,29 +97,29 @@ void fk_schedule() { clist_node_t next = *(runqueues[nextrq]); DEBUG("scheduler: first in queue: %s\n", ((tcb*)next.data)->name); clist_advance(&(runqueues[nextrq])); - my_fk_thread = (tcb*)next.data; - fk_pid = (volatile int) my_fk_thread->pid; + my_active_thread = (tcb*)next.data; + thread_pid = (volatile int) my_active_thread->pid; #if SCHEDSTATISTICS - pidlist[my_fk_thread->pid].laststart = time; - pidlist[my_fk_thread->pid].schedules ++; + pidlist[my_active_thread->pid].laststart = time; + pidlist[my_active_thread->pid].schedules ++; #endif // break; // } // } } - DEBUG("scheduler: next task: %s\n", my_fk_thread->name); + DEBUG("scheduler: next task: %s\n", my_active_thread->name); - if (my_fk_thread != fk_thread) { - if (fk_thread != NULL) { //TODO: necessary? - if (fk_thread->status == STATUS_RUNNING) { - fk_thread->status = STATUS_PENDING ; + if (my_active_thread != active_thread) { + if (active_thread != NULL) { //TODO: necessary? + if (active_thread->status == STATUS_RUNNING) { + active_thread->status = STATUS_PENDING ; } } - sched_set_status((tcb*)my_fk_thread, STATUS_RUNNING); + sched_set_status((tcb*)my_active_thread, STATUS_RUNNING); } - fk_thread = (volatile tcb*) my_fk_thread; + active_thread = (volatile tcb*) my_active_thread; DEBUG("scheduler: done.\n"); } @@ -144,23 +144,20 @@ void sched_set_status(tcb *process, unsigned int status) { process->status = status; } -extern void fk_switch_context_exit(void); +extern void cpu_switch_context_exit(void); -void fk_task_exit(void) { - DEBUG("fk_task_exit(): ending task %s...\n", fk_thread->name); +void sched_task_exit(void) { + DEBUG("sched_task_exit(): ending task %s...\n", active_thread->name); - tcb* thread = (tcb*)fk_thread; + tcb* thread = (tcb*)active_thread; dINT(); - fk_threads[fk_thread->pid] = NULL; + sched_threads[active_thread->pid] = NULL; num_tasks--; - sched_set_status(thread, STATUS_STOPPED); + + sched_set_status((tcb*)active_thread, STATUS_STOPPED); -// if ( thread->flags & AUTO_FREE ) { -// free(thread)->stack_start); -// free(thread); -// } - - fk_thread = NULL; - fk_switch_context_exit(); + free(((tcb*)active_thread)->stack_start); + active_thread = NULL; + cpu_switch_context_exit(); } diff --git a/core/thread.c b/core/thread.c index b6895a6764..49fbc53a5c 100644 --- a/core/thread.c +++ b/core/thread.c @@ -25,37 +25,37 @@ #include "kernel_intern.h" #include "bitarithm.h" #include "hwtimer.h" -#include "scheduler.h" +#include "sched.h" inline int thread_getpid() { - return fk_thread->pid; + return active_thread->pid; } unsigned int thread_getstatus(int pid) { - if (fk_threads[pid]==NULL) + if (sched_threads[pid]==NULL) return STATUS_NOT_FOUND; - return fk_threads[pid]->status; + return sched_threads[pid]->status; } void thread_sleep() { if ( inISR()) return; dINT(); - sched_set_status((tcb*)fk_thread, STATUS_SLEEPING); - fk_yield(); + sched_set_status((tcb*)active_thread, STATUS_SLEEPING); + thread_yield(); } int thread_wakeup(int pid) { int isr = inISR(); if (! isr) dINT(); - int result = fk_threads[pid]->status; + int result = sched_threads[pid]->status; if (result == STATUS_SLEEPING) { - sched_set_status((tcb*)fk_threads[pid], STATUS_RUNNING); + sched_set_status((tcb*)sched_threads[pid], STATUS_RUNNING); if (!isr) { eINT(); - fk_yield(); + thread_yield(); } else { - fk_context_switch_request = 1; + sched_context_switch_request = 1; } return 0; } else { @@ -64,7 +64,7 @@ int thread_wakeup(int pid) { } } -int fk_measure_stack_free(char* stack) { +int thread_measure_stack_usage(char* stack) { unsigned int* stackp = (unsigned int*)stack; /* assumption that the comparison fails before or after end of stack */ while( *stackp == (unsigned int)stackp ) @@ -105,9 +105,9 @@ int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, int pid = 0; while (pid < MAXTHREADS) { - if (fk_threads[pid] == NULL) { - fk_threads[pid] = cb; - cb->pid = pid; + if (sched_threads[pid] == NULL) { + sched_threads[pid] = cb; + pd->pid = pid; break; } pid++; @@ -122,7 +122,7 @@ int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, return -EOVERFLOW; } - cb->sp = fk_stack_init(function,stack+stacksize); + cb->sp = thread_stack_init(function,stack+stacksize); cb->stack_start = stack; cb->stack_size = stacksize; @@ -152,14 +152,14 @@ int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, if (!(flags & CREATE_WOUT_YIELD)) { if (! inISR()) { eINT(); - fk_yield(); + thread_yield(); } else { - fk_context_switch_request = 1; + sched_context_switch_request = 1; } } } - if (!inISR() && fk_thread!=NULL) { + if (!inISR() && active_thread!=NULL) { eINT(); } diff --git a/cpu/arm_common/arm_cpu.c b/cpu/arm_common/arm_cpu.c index 35a20a47de..a5ffb50f45 100644 --- a/cpu/arm_common/arm_cpu.c +++ b/cpu/arm_common/arm_cpu.c @@ -22,10 +22,10 @@ #include #include "arm_cpu.h" -#include "scheduler.h" +#include "sched.h" #include "kernel_intern.h" -void fk_yield() { +void thread_yield() { asm("svc 0\n"); } @@ -33,7 +33,7 @@ void fk_yield() { // Processor specific routine - here for ARM7 // sizeof(void*) = sizeof(int) //---------------------------------------------------------------------------- -char * fk_stack_init(void * task_func, void * stack_start) +char * thread_stack_init(void * task_func, void * stack_start) { unsigned int * stk; stk = (unsigned int *) stack_start; @@ -42,7 +42,7 @@ char * fk_stack_init(void * task_func, void * stack_start) *stk = 0x77777777; stk--; - *stk = (unsigned int)fk_task_exit; // LR + *stk = (unsigned int)sched_task_exit; // LR stk--; *stk = (unsigned int) stack_start - 4; // SP @@ -60,12 +60,12 @@ char * fk_stack_init(void * task_func, void * stack_start) return (char*)stk; } -void fk_print_stack () { +void thread_print_stack () { register void * stack = 0; asm( "mov %0, sp" : "=r" (stack)); register unsigned int * s = (unsigned int*) stack; - printf("task: %X SP: %X\n", (unsigned int)fk_thread, (unsigned int)stack); + printf("task: %X SP: %X\n", (unsigned int)active_thread, (unsigned int)stack); register int i = 0; s += 5; while (*s != 0x77777777) { diff --git a/cpu/arm_common/atomic.s b/cpu/arm_common/atomic.s index 3bdeb94dba..eb2612f0f6 100644 --- a/cpu/arm_common/atomic.s +++ b/cpu/arm_common/atomic.s @@ -4,7 +4,7 @@ .code 32 .align 4 /* 0 */ -/* .extern fk_schedule*/ +/* .extern sched_run*/ /* Public functions declared in this file */ .global atomic_set_return diff --git a/cpu/arm_common/common.s b/cpu/arm_common/common.s index cd6290530a..f296f51dd1 100644 --- a/cpu/arm_common/common.s +++ b/cpu/arm_common/common.s @@ -22,15 +22,14 @@ /* External references */ - .extern fk_thread - .extern fk_context_switch_request - .extern fk_schedule + .extern active_thread + .extern sched_context_switch_request + .extern sched_run .extern DEBUG_Routine /* Public functions declared in this file */ - .global fk_cpu_irq_isr - .global fk_switch_context_exit - .global fk_switch_context + .global arm_irq_handler + .global cpu_switch_context_exit .global task_return .global ctx_switch .global dINT @@ -80,32 +79,32 @@ ctx_switch2: /* store return address and spsr on user mode stack */ stmfd lr!, {r0, r1} - /* save user mode stack pointer in *fk_thread */ - ldr r1, =fk_thread /* r1 = &fk_thread */ - ldr r1, [r1] /* r1 = *r1 = fk_thread */ + /* save user mode stack pointer in *active_thread */ + ldr r1, =active_thread /* r1 = &active_thread */ + ldr r1, [r1] /* r1 = *r1 = active_thread */ str lr, [r1] /* store stack pointer in tasks tcb*/ /* now the calling task has all its registers saved on its stack and it's SP is saved in its tcb */ - /* call scheduler so fk_thread points to the next task */ - bl fk_schedule - b fk_task_return + /* call scheduler so active_thread points to the next task */ + bl sched_run + b task_return /* never coming back */ -fk_switch_context_exit: +cpu_switch_context_exit: mov r0, #NOINT|SVCMODE msr cpsr, r0 - /* call scheduler so fk_thread points to the next task */ - bl fk_schedule + /* call scheduler so active_thread points to the next task */ + bl sched_run - /* continue in fk_task_return: */ + /* continue in task_return: */ -fk_task_return: +task_return: /* load tcb->stackpointer in r0 */ - ldr r0, =fk_thread /* r0 = &fk_thread */ - ldr r0, [r0] /* r0 = *r0 = fk_thread */ + ldr r0, =active_thread /* r0 = &active_thread */ + ldr r0, [r0] /* r0 = *r0 = active_thread */ ldr r0, [r0] /* restore saved spsr and return address from tasks stack */ @@ -121,7 +120,7 @@ fk_task_return: /*---------------------------------------------------------------------------- * *----------------------------------------------------------------------------*/ -fk_cpu_irq_isr: +arm_irq_handler: sub lr, lr, #4 /* save interrupted tasks PC onto stack */ @@ -153,7 +152,7 @@ fk_cpu_irq_isr: MSR SPSR, R0 /* check if context switch was requested by irq */ - ldr r0, =fk_context_switch_request + ldr r0, =sched_context_switch_request ldr r0, [r0] cmp r0, #0x00 diff --git a/cpu/arm_common/include/arm_cpu.h b/cpu/arm_common/include/arm_cpu.h index 3159c005e7..6272119a64 100644 --- a/cpu/arm_common/include/arm_cpu.h +++ b/cpu/arm_common/include/arm_cpu.h @@ -11,7 +11,7 @@ extern void dINT(); extern void eINT(); -void fk_yield(); +void thread_yield(); uint32_t get_system_speed(void); void cpu_clock_scale(uint32_t source, uint32_t target, uint32_t* prescale); diff --git a/cpu/arm_common/syscalls.c b/cpu/arm_common/syscalls.c index a1e583f4a1..27dd5a957a 100644 --- a/cpu/arm_common/syscalls.c +++ b/cpu/arm_common/syscalls.c @@ -228,7 +228,7 @@ void _exit(int n) /*---------------------------------------------------------------------------*/ int _getpid(void) { - return fk_thread->pid; + return active_thread->pid; } /*---------------------------------------------------------------------------*/ int _kill_r(struct _reent *r, int pid, int sig) diff --git a/cpu/lpc214x/startup.s b/cpu/lpc214x/startup.s index f9b1f6900a..8a0c95b883 100644 --- a/cpu/lpc214x/startup.s +++ b/cpu/lpc214x/startup.s @@ -55,7 +55,7 @@ Undef_Addr: .word UNDEF_Routine /* defined in main.c */ SWI_Addr: .word ctx_switch /* defined in main.c */ PAbt_Addr: .word UNDEF_Routine /* defined in main.c */ DAbt_Addr: .word UNDEF_Routine /* defined in main.c */ -IRQ_Addr: .word fk_cpu_irq_isr /* defined in main.c */ +IRQ_Addr: .word arm_irq_handler /* defined in main.c */ FIQ_Addr: .word FIQ_Routine /* defined in main.c */ .word 0 /* rounds the vectors and ISR addresses to 64 bytes total */ diff --git a/cpu/lpc2387/startup.s b/cpu/lpc2387/startup.s index f9ef062b4b..057270f591 100644 --- a/cpu/lpc2387/startup.s +++ b/cpu/lpc2387/startup.s @@ -57,7 +57,7 @@ Undef_Addr: .word UNDEF_Routine /* defined in main.c */ SWI_Addr: .word ctx_switch /* defined in main.c */ PAbt_Addr: .word PABT_Routine /* defined in main.c */ DAbt_Addr: .word DABT_Routine /* defined in main.c */ -IRQ_Addr: .word fk_cpu_irq_isr /* defined in main.c */ +IRQ_Addr: .word arm_irq_handler /* defined in main.c */ /* Begin of boot code */ .text diff --git a/cpu/msp430/cpu.c b/cpu/msp430/cpu.c index 1ea79aa337..1ffd72b78a 100644 --- a/cpu/msp430/cpu.c +++ b/cpu/msp430/cpu.c @@ -28,25 +28,25 @@ and the mailinglist (subscription via web site) #include #include "kernel.h" #include "kernel_intern.h" -#include "scheduler.h" +#include "sched.h" volatile int __inISR = 0; char __isr_stack[MSP430_ISR_STACK_SIZE]; -void fk_yield() { +void thread_yield() { __save_context(); dINT(); - /* have fk_thread point to the next thread */ - fk_schedule(); + /* have active_thread point to the next thread */ + sched_run(); eINT(); __restore_context(); } // static void __resume_context () { -// __asm__("mov.w %0,r1" : : "m" (fk_thread->sp)); +// __asm__("mov.w %0,r1" : : "m" (active_thread->sp)); // // __asm__("pop r15"); // __asm__("pop r14"); @@ -81,15 +81,15 @@ void fk_yield() { // __asm__("push r14"); // __asm__("push r15"); // -// __asm__("mov.w r1,%0" : "=r" (fk_thread->sp)); +// __asm__("mov.w r1,%0" : "=r" (active_thread->sp)); // } // // // __return_from_isr -void fk_switch_context_exit(){ - fk_thread = fk_threads[0]; - fk_schedule(); +void cpu_switch_context_exit(){ + active_thread = sched_threads[0]; + sched_run(); __restore_context(); } @@ -97,12 +97,12 @@ void fk_switch_context_exit(){ //---------------------------------------------------------------------------- // Processor specific routine - here for MSP //---------------------------------------------------------------------------- -char *fk_stack_init(void *task_func, void *stack_start) +char *thread_stack_init(void *task_func, void *stack_start) { unsigned short * stk; stk = (unsigned short *) stack_start; - *stk = (unsigned short) fk_task_exit; + *stk = (unsigned short) sched_task_exit; --stk; *stk = (unsigned short) task_func; diff --git a/cpu/msp430/include/cpu.h b/cpu/msp430/include/cpu.h index 7a920aa053..830e5c9e7f 100644 --- a/cpu/msp430/include/cpu.h +++ b/cpu/msp430/include/cpu.h @@ -37,7 +37,7 @@ and the mailinglist (subscription via web site) * @{ */ -#include +#include #include #include #include @@ -66,11 +66,11 @@ inline void __save_context_isr() { __asm__("push r5"); __asm__("push r4"); - __asm__("mov.w r1,%0" : "=r" (fk_thread->sp)); + __asm__("mov.w r1,%0" : "=r" (active_thread->sp)); } inline void __restore_context_isr() { - __asm__("mov.w %0,r1" : : "m" (fk_thread->sp)); + __asm__("mov.w %0,r1" : : "m" (active_thread->sp)); __asm__("pop r4"); __asm__("pop r5"); @@ -94,7 +94,7 @@ inline void __enter_isr() { inline void __exit_isr() { __inISR = 0; - if (fk_context_switch_request) fk_schedule(); + if (sched_context_switch_request) sched_run(); __restore_context_isr(); __asm__("reti"); } @@ -121,7 +121,7 @@ inline void dINT() { #define lpm_set(...) -void fk_yield(); +void thread_yield(); int inISR(); diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 08594d1e3c..bb20e242c8 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -210,9 +210,9 @@ void cc1100_phy_init() void cc1100_phy_mutex_lock(void) { - if (fk_thread->pid != cc1100_mutex_pid) { + if (active_thread->pid != cc1100_mutex_pid) { mutex_lock(&cc1100_mutex); - cc1100_mutex_pid = fk_thread->pid; + cc1100_mutex_pid = active_thread->pid; } } diff --git a/projects/test_sleep/main.c b/projects/test_sleep/main.c index 75a67e8938..d5e02846fe 100644 --- a/projects/test_sleep/main.c +++ b/projects/test_sleep/main.c @@ -40,7 +40,7 @@ int main(void) if (i % 100 == 0) { printf("Waking up sleeper.\n"); thread_wakeup(pid); - fk_yield(); + thread_yield(); } } } diff --git a/projects/test_swtimer_remove/main.c b/projects/test_swtimer_remove/main.c index 773265c758..414e57d61d 100644 --- a/projects/test_swtimer_remove/main.c +++ b/projects/test_swtimer_remove/main.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include int main(void) { @@ -13,7 +13,7 @@ int main(void) swtimer_t t; puts("Setting timer...\n"); - swtimer_set_wakeup(&t, 10000000L, fk_thread->pid); + swtimer_set_wakeup(&t, 10000000L, active_thread->pid); puts("Small delay...\n"); hwtimer_wait(200000); puts("Removing timer...\n"); @@ -22,9 +22,9 @@ int main(void) swtimer_t t2; puts("Setting timer...\n"); - swtimer_set_wakeup(&t, 10000000L, fk_thread->pid); + swtimer_set_wakeup(&t, 10000000L, active_thread->pid); puts("Setting timer 2...\n"); - swtimer_set_wakeup(&t2, 50000000L, fk_thread->pid); + swtimer_set_wakeup(&t2, 50000000L, active_thread->pid); puts("Small delay...\n"); hwtimer_wait(200000); puts("Removing timer 1...\n"); @@ -34,9 +34,9 @@ int main(void) puts("Done.\n"); puts("Setting timer...\n"); - swtimer_set_wakeup(&t, 10000000L, fk_thread->pid); + swtimer_set_wakeup(&t, 10000000L, active_thread->pid); puts("Setting timer 2...\n"); - swtimer_set_wakeup(&t2, 50000000L, fk_thread->pid); + swtimer_set_wakeup(&t2, 50000000L, active_thread->pid); puts("Small delay...\n"); hwtimer_wait(200000); puts("Removing timer 2...\n"); diff --git a/sys/shell/ps.c b/sys/shell/ps.c index a54c8bc35b..0848bd5090 100644 --- a/sys/shell/ps.c +++ b/sys/shell/ps.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include /* list of states copied from tcb.h */ @@ -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*)fk_threads[i]; + tcb* p = (tcb*)sched_threads[i]; if( p != NULL ) { int state = p->status; // copy state @@ -42,7 +42,7 @@ void thread_print_all(void) switches = pidlist[i].schedules; #endif overall_stacksz += stacksz; - stacksz -= fk_measure_stack_free(p->stack_start); + stacksz -= thread_measure_stack_usage(p->stack_start); printf("\t%3u | %-21s| %-8s %.1s | %3i | %5i (%5i) %p | %6.3f%% | %8i\n", p->pid, p->name, sname, queued, p->priority, p->stack_size, stacksz, p->stack_start, runtime, switches); } diff --git a/sys/swtimer.c b/sys/swtimer.c index 0d87b97581..0b998de8b7 100644 --- a/sys/swtimer.c +++ b/sys/swtimer.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include From 11bc939d67fe554f94352ba8390a2a7877f4eb5b Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 28 Oct 2010 11:31:19 +0200 Subject: [PATCH 018/115] * merge fixes --- core/kernel_init.c | 2 +- core/sched.c | 2 -- core/thread.c | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/kernel_init.c b/core/kernel_init.c index dca0b45c94..39d3e66094 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -76,7 +76,7 @@ void kernel_init(void) sched_init(); - if (thread_create(&main_tcb, main_stack, sizeof(main_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_stack, idle_name) < 0) { + if (thread_create(&main_tcb, main_stack, sizeof(main_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) { printf("kernel_init(): error creating idle task.\n"); } diff --git a/core/sched.c b/core/sched.c index 907a635fd9..03e2f4f32a 100644 --- a/core/sched.c +++ b/core/sched.c @@ -149,14 +149,12 @@ extern void cpu_switch_context_exit(void); void sched_task_exit(void) { DEBUG("sched_task_exit(): ending task %s...\n", active_thread->name); - tcb* thread = (tcb*)active_thread; dINT(); sched_threads[active_thread->pid] = NULL; num_tasks--; sched_set_status((tcb*)active_thread, STATUS_STOPPED); - free(((tcb*)active_thread)->stack_start); active_thread = NULL; cpu_switch_context_exit(); } diff --git a/core/thread.c b/core/thread.c index 49fbc53a5c..779fc2b6b5 100644 --- a/core/thread.c +++ b/core/thread.c @@ -107,7 +107,7 @@ int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, while (pid < MAXTHREADS) { if (sched_threads[pid] == NULL) { sched_threads[pid] = cb; - pd->pid = pid; + cb->pid = pid; break; } pid++; From 4ba5cfbeca44137d57ee725c5fb42895ee36ca00 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 28 Oct 2010 16:54:49 +0200 Subject: [PATCH 019/115] * msba2_tools: create bin dir if needed --- board/msba2/tools/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/board/msba2/tools/Makefile b/board/msba2/tools/Makefile index 91d44fdf78..e98492a309 100644 --- a/board/msba2/tools/Makefile +++ b/board/msba2/tools/Makefile @@ -12,9 +12,11 @@ PSEUDOTERM_OBJS = ${addprefix obj/,${patsubst %.c,%.o,$(PSEUDOTERM_SRC)}} TARGETDIR = bin lpc2k_pgm: $(OBJS) + mkdir -p $(TARGETDIR) $(CC) -o $(TARGETDIR)/lpc2k_pgm $(OBJS) pseudoterm: $(PSEUDOTERM_OBJS) + mkdir -p $(TARGETDIR) $(CC) -lpthread -o $(TARGETDIR)/pseudoterm $(PSEUDOTERM_OBJS) chipinfo.o: boot_2xxx.h boot_23xx.h From f38f32f6cceb8c0293699d29b49fc162815d0275 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 29 Oct 2010 17:32:03 +0200 Subject: [PATCH 020/115] * added support for sht11 for msb-430-common * fixed some jamfile isssues for msb-430 * fixed arch32 detection for scheduler * changed sht11 driver to be platform independent --- Jamrules | 1 - board/msb-430-common/Jamrules.msb-430-common | 1 + board/msb-430-common/board_init.c | 2 +- .../drivers/include/sht11-board.h | 61 +++++++++++++++++++ core/bitarithm.c | 2 - core/include/bitarithm.h | 2 + core/include/sched.h | 2 +- drivers/include/sht11.h | 5 ++ drivers/sht11.c | 17 ++++-- 9 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 board/msb-430-common/drivers/include/sht11-board.h diff --git a/Jamrules b/Jamrules index 8eca19afc7..85c1a1d70c 100644 --- a/Jamrules +++ b/Jamrules @@ -53,7 +53,6 @@ CCFLAGS += -DBOARD=BOARD_$(BOARD:U) ; # core source directories HDRS += $(TOP) ; HDRS += [ FPath $(TOP) core include ] ; -HDRS += [ FPath $(TOP) hal include ] ; HDRS += [ FPath $(TOP) sys include ] [ FPath $(TOP) sys config ] [ FPath $(TOP) sys drivers include ] [ FPath $(TOP) sys drivers cc110x ] [ FPath $(TOP) sys drivers nanopan5375 ] ; HDRS += [ FPath $(TOP) sys net ] ; HDRS += [ FPath $(TOP) sys lib ] [ FPath $(TOP) sys lib fat include ] ; diff --git a/board/msb-430-common/Jamrules.msb-430-common b/board/msb-430-common/Jamrules.msb-430-common index db12fc6763..bfe5a1a6f8 100644 --- a/board/msb-430-common/Jamrules.msb-430-common +++ b/board/msb-430-common/Jamrules.msb-430-common @@ -34,3 +34,4 @@ FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; +HDRS += [ FPath $(TOP) board msb-430-common drivers include ] ; diff --git a/board/msb-430-common/board_init.c b/board/msb-430-common/board_init.c index 7dee70e3b1..4673600445 100644 --- a/board/msb-430-common/board_init.c +++ b/board/msb-430-common/board_init.c @@ -201,7 +201,7 @@ void board_init() { msp430_cpu_init(); msb_ports_init(); - RED_ON; + LED_RED_ON; msp430_set_cpu_speed(7372800uL); } diff --git a/board/msb-430-common/drivers/include/sht11-board.h b/board/msb-430-common/drivers/include/sht11-board.h new file mode 100644 index 0000000000..a4debd4473 --- /dev/null +++ b/board/msb-430-common/drivers/include/sht11-board.h @@ -0,0 +1,61 @@ +/****************************************************************************** +Copyright 2009, Freie Universitaet 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 FeuerWare. + +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 +*******************************************************************************/ + +#ifndef SHT11BOARD_H_ +#define SHT11BOARD_H_ + +/** + * @ingroup msb_430h + * @{ + */ + +/** + * @file + * @brief SHT11 Device Driver Configuration For MSB-430 Platform + * + * @author Freie Universität Berlin, Computer Systems & Telematics, µkleos + * @version $Revision$ + * + * @note $Id$ + */ +#include +#include + +/* SCK = P3B5 + * DATA = P3B4 + */ + +#define SHT11_SCK_LOW P3OUT &= ~(BIT5); /**< serial clock line low */ +#define SHT11_SCK_HIGH P3OUT |= BIT5; /**< serial clock line high */ +#define SHT11_DATA (P3IN & BIT5) /**< read serial I/O */ +#define SHT11_DATA_LOW P3OUT &= ~(BIT5); /**< serial I/O line low */ +#define SHT11_DATA_HIGH P3OUT |= BIT5; /**< serial I/O line high */ +#define SHT11_DATA_IN P3DIR &= ~(BIT5); /**< serial I/O as input */ +#define SHT11_DATA_OUT P3DIR |= BIT5; /**< serial I/O as output */ +#define SHT11_INIT P3DIR |= BIT5; /* FIO1DIR |= BIT25; PINSEL3 &= ~(BIT14|BIT15 | BIT16|BIT17); */ + +/** @} */ +#endif /* SHT11BOARD_H_ */ diff --git a/core/bitarithm.c b/core/bitarithm.c index bf9ee86991..7ffd031400 100644 --- a/core/bitarithm.c +++ b/core/bitarithm.c @@ -15,8 +15,6 @@ #include -#define ARCH_32_BIT (__INT_MAX__ == 2147483647) - unsigned number_of_highest_bit(unsigned v) { diff --git a/core/include/bitarithm.h b/core/include/bitarithm.h index de06c50241..d159f33348 100644 --- a/core/include/bitarithm.h +++ b/core/include/bitarithm.h @@ -64,6 +64,8 @@ #endif /** @} */ +#define ARCH_32_BIT (__INT_MAX__ == 2147483647) + /** * @brief Returns the number of the highest '1' bit in a value * @param[in] v Input value diff --git a/core/include/sched.h b/core/include/sched.h index ca5f74ddb1..a506d3cc36 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -15,7 +15,7 @@ #define MAXTHREADS 32 -#ifdef ARCH_32_BIT +#if ARCH_32_BIT #define SCHED_PRIO_LEVELS 32 #else #define SCHED_PRIO_LEVELS 16 diff --git a/drivers/include/sht11.h b/drivers/include/sht11.h index c649f402d8..9119d911db 100644 --- a/drivers/include/sht11.h +++ b/drivers/include/sht11.h @@ -50,6 +50,11 @@ and the mailinglist (subscription via web site) #define SHT11_MEASURE_HUMI (0x05) //000 0010 1 #define SHT11_RESET (0x1E) //000 1111 0 +/* time to wait after toggling the data line */ +#define SHT11_DATA_WAIT (HWTIMER_TICKS(5)) +/* time to wait after toggling the clock line */ +#define SHT11_CLK_WAIT (HWTIMER_TICKS(1)) + /* set measurement timeout to 1 second */ #define SHT11_MEASURE_TIMEOUT (1000) diff --git a/drivers/sht11.c b/drivers/sht11.c index b0d77e03ab..70e4039e85 100644 --- a/drivers/sht11.c +++ b/drivers/sht11.c @@ -37,7 +37,6 @@ and the mailinglist (subscription via web site) * @note $Id: sht11.c 2396 2010-07-06 15:12:35Z ziegert $ */ -#include #include #include @@ -46,6 +45,9 @@ and the mailinglist (subscription via web site) #include #include +//#define ENABLE_DEBUG (1) +#include + /** * @brief Perform measurement * @@ -147,6 +149,7 @@ static uint8_t read_byte (uint8_t ack) value = value << 1; SHT11_SCK_HIGH; hwtimer_wait(SHT11_CLK_WAIT); + if (SHT11_DATA) { /* increase data by one when DATA is high */ value++; @@ -230,10 +233,10 @@ static uint8_t measure(uint8_t *p_value, uint8_t *p_checksum, uint8_t mode) uint8_t ack = 1; uint16_t i; - transmission_start(); + transmission_start(); error = write_byte(mode); - hwtimer_wait(HWTIMER_MSEC); + hwtimer_wait(HWTIMER_TICKS(1000)); /* wait untile sensor has finished measurement or timeout */ for (i = 0; (i < SHT11_MEASURE_TIMEOUT) && (!error); i++) { @@ -242,7 +245,7 @@ static uint8_t measure(uint8_t *p_value, uint8_t *p_checksum, uint8_t mode) if (!ack) { break; } - hwtimer_wait(HWTIMER_MSEC); + hwtimer_wait(HWTIMER_TICKS(1000)); } error += ack; @@ -259,7 +262,7 @@ static uint8_t measure(uint8_t *p_value, uint8_t *p_checksum, uint8_t mode) void sht11_init(void) { mutex_init(&sht11_mutex); SHT11_INIT; - hwtimer_wait(11 * HWTIMER_MSEC); + hwtimer_wait(11 * HWTIMER_TICKS(1000)); } /*---------------------------------------------------------------------------*/ uint8_t sht11_read_status(uint8_t *p_value, uint8_t *p_checksum) { @@ -303,7 +306,9 @@ uint8_t sht11_read_sensor(sht11_val_t *value, sht11_mode_t mode) { const float T2 = +0.00008; /* check for valid buffer */ - assert(value != NULL); + if (value == NULL) { + return 0; + } value->temperature = 0; value->relhum = 0; From 13b651ee868f2bebe6cce82d3d81ba36ba7ad9b1 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 29 Oct 2010 17:34:13 +0200 Subject: [PATCH 021/115] * missing parts of last commit --- board/msb-430/include/board.h | 5 +++-- board/msb-430h/include/board.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/board/msb-430/include/board.h b/board/msb-430/include/board.h index 6ca75c9c45..18d4a04721 100644 --- a/board/msb-430/include/board.h +++ b/board/msb-430/include/board.h @@ -60,8 +60,9 @@ and the mailinglist (subscription via web site) #define LEDS_CONF_GREEN 0x00 #define LEDS_CONF_YELLOW 0x00 -#define RED_ON LEDS_PxOUT &=~LEDS_CONF_RED -#define RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED #include diff --git a/board/msb-430h/include/board.h b/board/msb-430h/include/board.h index ef2bbb6585..d9634d6b4d 100644 --- a/board/msb-430h/include/board.h +++ b/board/msb-430h/include/board.h @@ -60,8 +60,9 @@ and the mailinglist (subscription via web site) #define LEDS_CONF_GREEN 0x00 #define LEDS_CONF_YELLOW 0x00 -#define RED_ON LEDS_PxOUT &=~LEDS_CONF_RED -#define RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED #include From a55f8fe45021a767a464154965664656a97b0c0c Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 29 Oct 2010 19:16:02 +0200 Subject: [PATCH 022/115] * removed SHT11 timings from msba2 header --- board/msba2/drivers/include/sht11-board.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/board/msba2/drivers/include/sht11-board.h b/board/msba2/drivers/include/sht11-board.h index fc0313906a..c35fb00788 100644 --- a/board/msba2/drivers/include/sht11-board.h +++ b/board/msba2/drivers/include/sht11-board.h @@ -54,10 +54,5 @@ and the mailinglist (subscription via web site) #define SHT11_DATA_OUT (FIO1DIR |= BIT26) // serial I/O as output #define SHT11_INIT FIO1DIR |= BIT25; PINSEL3 &= ~(BIT14|BIT15 | BIT16|BIT17); -/* time to wait after toggling the data line */ -#define SHT11_DATA_WAIT (50) -/* time to wait after toggling the clock line */ -#define SHT11_CLK_WAIT (10) - /** @} */ #endif /* SHT11BOARD_H_ */ From 53a86e4d45311753ffece5a49db5096d6fc4a507 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 13:28:14 +0100 Subject: [PATCH 023/115] * fix skel project test path --- projects/skel/tests/hello-world | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/skel/tests/hello-world b/projects/skel/tests/hello-world index 6f4a6ca811..acde8265fe 100755 --- a/projects/skel/tests/hello-world +++ b/projects/skel/tests/hello-world @@ -2,7 +2,7 @@ set timeout 5 -spawn board/msba2/tools/bin/pseudoterm $env(PORT) +spawn pseudoterm $env(PORT) expect { "Hello World!" {} From 5b3209ea19a04e87faa81add6f708819cba661fb Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 1 Nov 2010 13:29:40 +0100 Subject: [PATCH 024/115] * check for null pointer in mutex wake waiters function --- core/mutex.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/mutex.c b/core/mutex.c index be33fba931..b337a85fbe 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -103,6 +103,13 @@ void mutex_wake_waiters(struct mutex_t *mutex, int flags) { DEBUG("%s: waking up waiters.\n", active_thread->name); queue_node_t *next = queue_remove_head(&(mutex->queue)); + + /* queue is empty */ + if (!next) { + mutex->val = 0; + return; + } + tcb* process = (tcb*)next->data; sched_set_status(process, STATUS_PENDING); From c269e2286da2e47771a4dd2ccdbb1f259c0c8dfa Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 13:38:11 +0100 Subject: [PATCH 025/115] * name change --- Jamrules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jamrules b/Jamrules index 85c1a1d70c..a2801d2a9a 100644 --- a/Jamrules +++ b/Jamrules @@ -31,7 +31,7 @@ include $(TOP)$(SLASH)Jamrules.common ; # -# Setup FeuerWare build system configuration (default values for common options) +# Setup ukleos build system configuration (default values for common options) # PROJECT = $(PROJECT:E=hello-world) ; BOARD = $(BOARD:E=msba2) ; From 2c42a8a1233b66c25c0ed319516ff7a862b9db8d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 13:40:14 +0100 Subject: [PATCH 026/115] whitespace fix --- Jamrules.common | 1 - 1 file changed, 1 deletion(-) diff --git a/Jamrules.common b/Jamrules.common index d92882466a..acc3ad643a 100644 --- a/Jamrules.common +++ b/Jamrules.common @@ -357,4 +357,3 @@ actions ShowFlags { echo "" | $(CC) -E -dD - } - From cc800bcb1374ca31bfa4e00280dfbe57ed966f5b Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 13:45:30 +0100 Subject: [PATCH 027/115] * honour previous IRQ state in error path --- core/mutex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/core/mutex.c b/core/mutex.c index b337a85fbe..42e356196a 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -107,6 +107,7 @@ void mutex_wake_waiters(struct mutex_t *mutex, int flags) { /* queue is empty */ if (!next) { mutex->val = 0; + if ( ! (flags & MUTEX_INISR)) eINT(); return; } From c58f15c0a8b592859f5f455c8ab6555010f8efb1 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 14:28:06 +0100 Subject: [PATCH 028/115] * whitespace fix --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index aed49aaf32..44f24ab49a 100644 --- a/README +++ b/README @@ -7,3 +7,4 @@ License a separate license. All code files contain licensing information. + From 0f4a72974a8cf796614c5213a4760172cf87f0ee Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 15:50:31 +0100 Subject: [PATCH 029/115] * hwtimer.c cosmetics --- core/hwtimer.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/hwtimer.c b/core/hwtimer.c index 01600a4f77..e056a3dd60 100644 --- a/core/hwtimer.c +++ b/core/hwtimer.c @@ -16,18 +16,14 @@ */ #include -#include "hwtimer.h" -#include "hwtimer_cpu.h" -#include "hwtimer_arch.h" +#include +#include +#include #include -#define USE_NONBLOCKING_WAIT 1 -#if USE_NONBLOCKING_WAIT -//#include -#include "kernel.h" -#include "mutex.h" -#endif +#include +#include /*---------------------------------------------------------------------------*/ From f47541c33f1f6f2d2fcc1f8c3261803467386876 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 15:50:56 +0100 Subject: [PATCH 030/115] * have project compiled last --- Jamfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index 3c442afa90..3e199228c3 100644 --- a/Jamfile +++ b/Jamfile @@ -67,8 +67,8 @@ Debug debug : $(TARGET) ; ListModules listmodules ; ShowFlags showflags : $(TARGET) ; -SubInclude TOP projects $(PROJECT) ; SubInclude TOP sys ; SubInclude TOP core ; SubInclude TOP drivers ; SubInclude TOP board ; +SubInclude TOP projects $(PROJECT) ; From 62035f36c8d2375f1c0c13a90918ae710c485956 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 15:53:33 +0100 Subject: [PATCH 031/115] * add some more debug statements --- core/mutex.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/mutex.c b/core/mutex.c index 42e356196a..affc7cb622 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -35,6 +35,7 @@ int mutex_init(struct mutex_t* mutex) { } int mutex_trylock(struct mutex_t* mutex) { + DEBUG("%s: trylocking to get mutex. val: %u\n", active_thread->name, mutex->val); return (atomic_set_return(&mutex->val, thread_pid ) == 0); } @@ -43,7 +44,7 @@ int prio() { } int mutex_lock(struct mutex_t* mutex) { - DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val); + DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val); if (atomic_set_return(&mutex->val,thread_pid) != 0) { // mutex was locked. @@ -106,6 +107,7 @@ void mutex_wake_waiters(struct mutex_t *mutex, int flags) { /* queue is empty */ if (!next) { + DEBUG("%s: no waiters?\n", active_thread->name); mutex->val = 0; if ( ! (flags & MUTEX_INISR)) eINT(); return; From fa12fbf167cf8e6513b462319cad435be02748fa Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 16:12:22 +0100 Subject: [PATCH 032/115] * added mutex trylock regression test --- projects/test_mutex_trylock_fail/Jamfile | 5 +++ projects/test_mutex_trylock_fail/main.c | 31 +++++++++++++++++++ .../tests/test_mutex_trylock_fail | 13 ++++++++ 3 files changed, 49 insertions(+) create mode 100644 projects/test_mutex_trylock_fail/Jamfile create mode 100644 projects/test_mutex_trylock_fail/main.c create mode 100755 projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail diff --git a/projects/test_mutex_trylock_fail/Jamfile b/projects/test_mutex_trylock_fail/Jamfile new file mode 100644 index 0000000000..3f0bfe1dfd --- /dev/null +++ b/projects/test_mutex_trylock_fail/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects test_mutex_trylock_fail ; + +Module test_mutex_trylock_fail : main.c ; + +UseModule test_mutex_trylock_fail ; diff --git a/projects/test_mutex_trylock_fail/main.c b/projects/test_mutex_trylock_fail/main.c new file mode 100644 index 0000000000..de7619adab --- /dev/null +++ b/projects/test_mutex_trylock_fail/main.c @@ -0,0 +1,31 @@ +#include +#include + +#include +#include +#include + +mutex_t mutex; + +void second_thread(void) { + puts(" 2nd: trying to lock mutex..."); + mutex_trylock(&mutex); + puts(" 2nd: done."); +} + +tcb second_tcb; +char second_stack[8192]; + +int main(void) +{ + puts("main: locking mutex..."); + mutex_lock(&mutex); + + puts("main: creating thread..."); + int pid = thread_create(&second_tcb, second_stack, 8192, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2"); + + puts("main: thread created. Unlocking mutex..."); + mutex_unlock(&mutex, true); + + puts("main: mutex unlocked."); +} diff --git a/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail b/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail new file mode 100755 index 0000000000..1795de002a --- /dev/null +++ b/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "main: mutex unlocked." {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" + From 1a6ea56b8bba60d67169ff434a112818760a5c17 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 17:05:00 +0100 Subject: [PATCH 033/115] * added project "test_suite" as container for automatic tests. Added test_mutex_trylock_fail as first example --- projects/test_mutex_trylock_fail/Jamfile | 5 -- .../tests/test_mutex_trylock_fail | 13 --- projects/test_suite/Jamfile | 12 +++ .../mutex_trylock_fail.c} | 6 +- projects/test_suite/test_suite.c | 58 +++++++++++++ projects/test_suite/tests/01-basic | 30 +++++++ .../tests/02-inputlength-regression | 81 +++++++++++++++++++ projects/test_suite/tests/02-unknown-command | 20 +++++ .../test_suite/tests/03-mutex_trylock_fail | 56 +++++++++++++ 9 files changed, 260 insertions(+), 21 deletions(-) delete mode 100644 projects/test_mutex_trylock_fail/Jamfile delete mode 100755 projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail create mode 100644 projects/test_suite/Jamfile rename projects/{test_mutex_trylock_fail/main.c => test_suite/mutex_trylock_fail.c} (68%) create mode 100644 projects/test_suite/test_suite.c create mode 100755 projects/test_suite/tests/01-basic create mode 100755 projects/test_suite/tests/02-inputlength-regression create mode 100755 projects/test_suite/tests/02-unknown-command create mode 100755 projects/test_suite/tests/03-mutex_trylock_fail diff --git a/projects/test_mutex_trylock_fail/Jamfile b/projects/test_mutex_trylock_fail/Jamfile deleted file mode 100644 index 3f0bfe1dfd..0000000000 --- a/projects/test_mutex_trylock_fail/Jamfile +++ /dev/null @@ -1,5 +0,0 @@ -SubDir TOP projects test_mutex_trylock_fail ; - -Module test_mutex_trylock_fail : main.c ; - -UseModule test_mutex_trylock_fail ; diff --git a/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail b/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail deleted file mode 100755 index 1795de002a..0000000000 --- a/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/expect - -set timeout 5 - -spawn pseudoterm $env(PORT) - -expect { - "main: mutex unlocked." {} - timeout { exit 1 } -} - -puts "\nTest successful!\n" - diff --git a/projects/test_suite/Jamfile b/projects/test_suite/Jamfile new file mode 100644 index 0000000000..eb5ff2d43b --- /dev/null +++ b/projects/test_suite/Jamfile @@ -0,0 +1,12 @@ +# +# Copyright (C) 2008, 2009, 2010 FU Berlin +# +# Author: Kaspar Schleiser +# + +SubDir TOP projects test_suite ; + +Module test_suite : test_suite.c mutex_trylock_fail.c + : shell posix_io ps uart0 ; + +UseModule test_suite ; diff --git a/projects/test_mutex_trylock_fail/main.c b/projects/test_suite/mutex_trylock_fail.c similarity index 68% rename from projects/test_mutex_trylock_fail/main.c rename to projects/test_suite/mutex_trylock_fail.c index de7619adab..d2b29dba6e 100644 --- a/projects/test_mutex_trylock_fail/main.c +++ b/projects/test_suite/mutex_trylock_fail.c @@ -14,15 +14,15 @@ void second_thread(void) { } tcb second_tcb; -char second_stack[8192]; +char second_stack[KERNEL_CONF_STACKSIZE_MAIN]; -int main(void) +void mutex_trylock_fail(char* cmdline) { puts("main: locking mutex..."); mutex_lock(&mutex); puts("main: creating thread..."); - int pid = thread_create(&second_tcb, second_stack, 8192, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2"); + int pid = thread_create(&second_tcb, second_stack, KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2"); puts("main: thread created. Unlocking mutex..."); mutex_unlock(&mutex, true); diff --git a/projects/test_suite/test_suite.c b/projects/test_suite/test_suite.c new file mode 100644 index 0000000000..bf1afd7a3c --- /dev/null +++ b/projects/test_suite/test_suite.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008, 2009, 2010 Kaspar Schleiser + */ + +#include +#include +#include + +#include +#include +#include + +void print_teststart(char* str) { + printf("[TEST_START]\n"); +} + +void print_testend(char* str) { + printf("[TEST_END]\n"); +} + +int shell_readc() { + char c = 0; + posix_read(uart0_handler_pid, &c, 1); + return c; +} + +void shell_putchar(int c) { + putchar(c); +} + +void mutex_trylock_fail(char* cmdline); + +const shell_command_t shell_commands[] = { + {"start_test", print_teststart}, + {"end_test", print_testend}, + {"mutex_trylock_fail", mutex_trylock_fail}, + {NULL, NULL} +}; + +int main(void) { + //printf("Moin. build on %s %s SVN-Revision: %s\n", kernel_builddate, kernel_buildtime, kernel_svnrevision); + printf("test_shell.\n"); + + board_uart0_init(); + + posix_open(uart0_handler_pid, 0); + + shell_t shell; + shell_init(&shell, shell_readc, shell_putchar); + + shell.command_list = shell_commands; + + shell_run(&shell); + + return 0; +} + + diff --git a/projects/test_suite/tests/01-basic b/projects/test_suite/tests/01-basic new file mode 100755 index 0000000000..bdeb117734 --- /dev/null +++ b/projects/test_suite/tests/01-basic @@ -0,0 +1,30 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + ">$" {} + timeout { exit 1 } +} + +send "start_test\n" +expect { + "\[TEST_START\]" {} + timeout { exit 1 } +} + +expect { + ">$" {} + timeout { exit 1 } +} + +send "end_test\n" + +expect { + "\[TEST_END\]" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" diff --git a/projects/test_suite/tests/02-inputlength-regression b/projects/test_suite/tests/02-inputlength-regression new file mode 100755 index 0000000000..ae130f5517 --- /dev/null +++ b/projects/test_suite/tests/02-inputlength-regression @@ -0,0 +1,81 @@ +#!/usr/bin/expect + +set timeout 1 + +spawn pseudoterm $env(PORT) + +sleep 1 + +expect { + ">$" {} + timeout { exit 1 } +} + +send "123456789012345678901234567890123456789012345678901234567890\n" +expect { + "shell: command not found." {} + timeout { exit 1 } +} + +send "123456789012345678901234567890123456789012345678901234567890\n" +expect { + "shell: command not found." {} + timeout { exit 1 } +} + +send "123456789012345678901234567890123456789012345678901234567890\n" +expect { + "shell: command not found." {} + timeout { exit 1 } +} + +send "123456789012345678901234567890123456789012345678901234567890\n" +expect { + "shell: command not found." {} + timeout { exit 1 } +} + +send "123456789012345678901234567890123456789012345678901234567890\n" +expect { + "shell: command not found." {} + timeout { exit 1 } +} + +send "123456789012345678901234567890123456789012345678901234567890\n" +expect { + "shell: command not found." {} + timeout { exit 1 } +} + +send "123456789012345678901234567890123456789012345678901234567890\n" +expect { + "shell: command not found." {} + timeout { exit 1 } +} + +send "123456789012345678901234567890123456789012345678901234567890\n" +expect { + "shell: command not found." {} + timeout { exit 1 } +} + + +send "start_test\n" +expect { + "\[TEST_START\]" {} + timeout { exit 1 } +} + +expect { + ">$" {} + timeout { exit 1 } +} + +send "end_test\n" + +expect { + "\[TEST_END\]" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" diff --git a/projects/test_suite/tests/02-unknown-command b/projects/test_suite/tests/02-unknown-command new file mode 100755 index 0000000000..4dc6250422 --- /dev/null +++ b/projects/test_suite/tests/02-unknown-command @@ -0,0 +1,20 @@ +#!/usr/bin/expect + +set timeout 2 + +spawn pseudoterm $env(PORT) + +sleep 1 + +expect { + ">$" {} + timeout { exit 1 } +} + +send "some_definately_unknown_command\n" +expect { + "shell: command "some_definately_unknown_command" not found." {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" diff --git a/projects/test_suite/tests/03-mutex_trylock_fail b/projects/test_suite/tests/03-mutex_trylock_fail new file mode 100755 index 0000000000..e9fa068275 --- /dev/null +++ b/projects/test_suite/tests/03-mutex_trylock_fail @@ -0,0 +1,56 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + ">$" {} + timeout { exit 1 } +} + +send "start_test\n" +expect { + "\[TEST_START\]" {} + timeout { exit 1 } +} + +expect { + ">$" {} + timeout { exit 1 } +} + +send "mutex_trylock_fail\n" +expect { + "main: locking mutex..." {} + timeout { exit 1 } +} +expect { + "main: creating thread..." {} + timeout { exit 1 } +} +expect { + "2nd: trying to lock mutex..." {} + timeout { exit 1 } +} +expect { + "2nd: done." {} + timeout { exit 1 } +} +expect { + "main: thread created. Unlocking mutex..." {} + timeout { exit 1 } +} +expect { + "main: mutex unlocked." {} + timeout { exit 1 } +} + +send "end_test\n" + +expect { + "\[TEST_END\]" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" From a5f7c5191f216cdd13ea200687fb4d3d48c46716 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 17:31:23 +0100 Subject: [PATCH 034/115] * switch to direct serial output (w/o interrupts --- board/msba2/drivers/msba2-uart0.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/board/msba2/drivers/msba2-uart0.c b/board/msba2/drivers/msba2-uart0.c index 9198f50bb2..dceba9aed7 100644 --- a/board/msba2/drivers/msba2-uart0.c +++ b/board/msba2/drivers/msba2-uart0.c @@ -149,7 +149,7 @@ void UART0_IRQHandler(void) static inline int uart0_puts(char *astring,int length) { - while (queue_items == (QUEUESIZE-1)) {} ; +/* while (queue_items == (QUEUESIZE-1)) {} ; U0IER = 0; queue[queue_tail] = malloc(length+sizeof(unsigned int)); queue[queue_tail]->len = length; @@ -158,14 +158,14 @@ static inline int uart0_puts(char *astring,int length) if (!running) push_queue(); U0IER |= BIT0 | BIT1; // enable RX irq - - /* alternative without queue: +*/ + /* alternative without queue:*/ int i; for (i=0;i Date: Mon, 1 Nov 2010 17:38:03 +0100 Subject: [PATCH 035/115] * removed old reference to clock module from rtc * added documentation for sht11 and swtimer Conflicts: drivers/include/sht11.h --- drivers/include/sht11.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/include/sht11.h b/drivers/include/sht11.h index 9119d911db..573a21590b 100644 --- a/drivers/include/sht11.h +++ b/drivers/include/sht11.h @@ -50,22 +50,26 @@ and the mailinglist (subscription via web site) #define SHT11_MEASURE_HUMI (0x05) //000 0010 1 #define SHT11_RESET (0x1E) //000 1111 0 +<<<<<<< HEAD /* time to wait after toggling the data line */ #define SHT11_DATA_WAIT (HWTIMER_TICKS(5)) /* time to wait after toggling the clock line */ #define SHT11_CLK_WAIT (HWTIMER_TICKS(1)) /* set measurement timeout to 1 second */ +======= +/** + * set measurement timeout to 1 second */ +>>>>>>> fb40690... * removed old reference to clock module from rtc #define SHT11_MEASURE_TIMEOUT (1000) -/** sht11 measureable data */ +/** + * @brief sht11 measureable data + */ typedef struct { - /* temperature value */ - float temperature; - /* linear relative humidity */ - float relhum; - /* temperature compensated relative humidity */ - float relhum_temp; + float temperature; /**< temperature value */ + float relhum; /**< linear relative humidity */ + float relhum_temp; /**< temperature compensated relative humidity */ } sht11_val_t; /** @@ -84,9 +88,14 @@ void sht11_init(void); /** * @brief Read sensor * + * @param value The struct to be filled with measured values + * @param mode Specifies type of data to be read + * + * @return 1 on success, 0 otherwise + * * Example: - * \code struct sht11_val sht11; - * sht11_Read_Sensor(&sht11, HUMIDITY|TEMPERATURE); + * \code sht11_val sht11; + * sht11_read_sensor(&sht11, HUMIDITY|TEMPERATURE); * printf("%-6.2f °C %5.2f %% %5.2f %%\n", sht11.temperature, sht11.relhum, sht11.relhum_temp); \endcode */ uint8_t sht11_read_sensor(sht11_val_t *value, sht11_mode_t mode); From 88d3421ee75de9b1d6535c4497b804929c41d6bf Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 1 Nov 2010 17:38:23 +0100 Subject: [PATCH 036/115] * missing part of last commit --- cpu/lpc2387/include/lpc2387-rtc.h | 1 - cpu/lpc2387/lpc2387-rtc.c | 3 --- sys/include/swtimer.h | 9 +++++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cpu/lpc2387/include/lpc2387-rtc.h b/cpu/lpc2387/include/lpc2387-rtc.h index 4fb8f52e51..9420fc7c21 100644 --- a/cpu/lpc2387/include/lpc2387-rtc.h +++ b/cpu/lpc2387/include/lpc2387-rtc.h @@ -51,7 +51,6 @@ and the mailinglist (subscription via web site) #include #include #include "lpc2387.h" -#include "clock.h" /* ------------------------------------------------------------------------- */ /** diff --git a/cpu/lpc2387/lpc2387-rtc.c b/cpu/lpc2387/lpc2387-rtc.c index 7ab60e09c4..ca713833a0 100644 --- a/cpu/lpc2387/lpc2387-rtc.c +++ b/cpu/lpc2387/lpc2387-rtc.c @@ -45,7 +45,6 @@ and the mailinglist (subscription via web site) #include "lpc2387.h" #include "lpc2387-rtc.h" #include "lpm.h" -#include "clock.h" #define PREINT_RTC 0x000001C8 /* Prescaler value, integer portion, PCLK = 15Mhz */ #define PREFRAC_RTC 0x000061C0 /* Prescaler value, fraction portion, PCLK = 15Mhz */ @@ -58,7 +57,6 @@ and the mailinglist (subscription via web site) #define PRINTF(fmt, args...) #endif -extern void _clock_alarm(void); /** * @brief epoch time in hour granularity @@ -155,7 +153,6 @@ void RTC_IRQHandler (void) RTC_AMR = 0xff; // disable alarm irq PRINTF("alarm"); lpm_end_awake(); - _clock_alarm(); } VICVectAddr = 0; // Acknowledge Interrupt diff --git a/sys/include/swtimer.h b/sys/include/swtimer.h index 9f7d9a9730..0cc30f82c0 100644 --- a/sys/include/swtimer.h +++ b/sys/include/swtimer.h @@ -64,14 +64,23 @@ typedef struct swtimer_t { } action; } swtimer_t; +/** + * @brief Current system time + * @return Time in ticks since system boot + */ swtime_t swtimer_now(); +/** + * @brief Initializes swtimer + * @return always 0 + */ int swtimer_init(); /** * @brief set swtimer interval and activate * @param[in] t pointer to preinitialised swtimer_t * @param[in] interval swtimer interval + * @return always 0 */ int swtimer_set(swtimer_t *t, swtime_t interval); From cec06f6b834c7f28acb7c1397be9f80976a3f687 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 1 Nov 2010 17:42:35 +0100 Subject: [PATCH 037/115] * resolved conflict --- drivers/include/sht11.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/include/sht11.h b/drivers/include/sht11.h index 573a21590b..71e7e8bac1 100644 --- a/drivers/include/sht11.h +++ b/drivers/include/sht11.h @@ -50,17 +50,12 @@ and the mailinglist (subscription via web site) #define SHT11_MEASURE_HUMI (0x05) //000 0010 1 #define SHT11_RESET (0x1E) //000 1111 0 -<<<<<<< HEAD /* time to wait after toggling the data line */ #define SHT11_DATA_WAIT (HWTIMER_TICKS(5)) /* time to wait after toggling the clock line */ #define SHT11_CLK_WAIT (HWTIMER_TICKS(1)) /* set measurement timeout to 1 second */ -======= -/** - * set measurement timeout to 1 second */ ->>>>>>> fb40690... * removed old reference to clock module from rtc #define SHT11_MEASURE_TIMEOUT (1000) /** From 3b46b2d2af0d1532e2040f2c6b6d1eab6206fd4a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 11:06:58 +0100 Subject: [PATCH 038/115] * fix stack assignment mixup for main / idle threads --- core/kernel_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/kernel_init.c b/core/kernel_init.c index 39d3e66094..d2d4622185 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -76,11 +76,11 @@ void kernel_init(void) sched_init(); - if (thread_create(&main_tcb, main_stack, sizeof(main_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) { + if (thread_create(&idle_tcb, idle_stack, sizeof(idle_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) { printf("kernel_init(): error creating idle task.\n"); } - if (thread_create(&idle_tcb, idle_stack, sizeof(idle_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) { + if (thread_create(&main_tcb, main_stack, sizeof(main_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) { printf("kernel_init(): error creating main task.\n"); } From b1bf8fb834af8bfdd306ba0e3f96090ebb06af8a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 11:39:11 +0100 Subject: [PATCH 039/115] * msba2_uart0: disable TX interrupt --- board/msba2/drivers/msba2-uart0.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/board/msba2/drivers/msba2-uart0.c b/board/msba2/drivers/msba2-uart0.c index dceba9aed7..8ff7e11e37 100644 --- a/board/msba2/drivers/msba2-uart0.c +++ b/board/msba2/drivers/msba2-uart0.c @@ -199,7 +199,8 @@ bl_uart_init(void) /* irq */ install_irq(UART0_INT, UART0_IRQHandler, 6); - U0IER |= BIT0 | BIT1; // enable RX+TX irq +// U0IER |= BIT0 | BIT1; // enable RX+TX irq + U0IER |= BIT0; // enable only RX irq return 1; } From 711ae3b6868982c073cb30ad5711c3864005d45a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 11:40:10 +0100 Subject: [PATCH 040/115] * thread: add some more debug statements --- core/thread.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/thread.c b/core/thread.c index 779fc2b6b5..8afbcb8446 100644 --- a/core/thread.c +++ b/core/thread.c @@ -45,11 +45,16 @@ void thread_sleep() { } int thread_wakeup(int pid) { + DEBUG("thread_wakeup: Trying to wakeup PID %i...\n", pid); int isr = inISR(); - if (! isr) dINT(); + if (! isr) { + DEBUG("thread_wakeup: Not in interrupt.\n"); + dINT(); + } 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); if (!isr) { eINT(); @@ -59,6 +64,7 @@ int thread_wakeup(int pid) { } return 0; } else { + DEBUG("thread_wakeup: Thread is not sleeping!\n"); if (!isr) eINT(); return STATUS_NOT_FOUND; } From 82abee6769ea77cb75c5a3f286ff4a2ec8bb90f5 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 11:52:39 +0100 Subject: [PATCH 041/115] * fix mutex_trylock_fail test --- projects/test_suite/mutex_trylock_fail.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/test_suite/mutex_trylock_fail.c b/projects/test_suite/mutex_trylock_fail.c index d2b29dba6e..5acb9a05b5 100644 --- a/projects/test_suite/mutex_trylock_fail.c +++ b/projects/test_suite/mutex_trylock_fail.c @@ -7,14 +7,14 @@ mutex_t mutex; -void second_thread(void) { +static void second_thread(void) { puts(" 2nd: trying to lock mutex..."); mutex_trylock(&mutex); puts(" 2nd: done."); } -tcb second_tcb; -char second_stack[KERNEL_CONF_STACKSIZE_MAIN]; +static tcb second_tcb; +static char second_stack[KERNEL_CONF_STACKSIZE_MAIN]; void mutex_trylock_fail(char* cmdline) { @@ -22,7 +22,7 @@ void mutex_trylock_fail(char* cmdline) mutex_lock(&mutex); puts("main: creating thread..."); - int pid = thread_create(&second_tcb, second_stack, KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2"); + thread_create(&second_tcb, second_stack, KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2"); puts("main: thread created. Unlocking mutex..."); mutex_unlock(&mutex, true); From efeaebd096e51ed588bef3c1482f473ced6fde5e Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 11:53:20 +0100 Subject: [PATCH 042/115] * test_suite: added test_thread_sleep --- projects/test_suite/test_suite.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/test_suite/test_suite.c b/projects/test_suite/test_suite.c index bf1afd7a3c..5cfba74eb9 100644 --- a/projects/test_suite/test_suite.c +++ b/projects/test_suite/test_suite.c @@ -29,11 +29,13 @@ void shell_putchar(int c) { } void mutex_trylock_fail(char* cmdline); +void test_thread_sleep(char* line); const shell_command_t shell_commands[] = { {"start_test", print_teststart}, {"end_test", print_testend}, {"mutex_trylock_fail", mutex_trylock_fail}, + {"thread_sleep", test_thread_sleep}, {NULL, NULL} }; From 97e7a80260e5409f59ea2a874b7edebe2af395ca Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 11:54:03 +0100 Subject: [PATCH 043/115] * test_suite: add test_thread_sleep 2/2 --- projects/test_suite/Jamfile | 4 +-- projects/test_suite/thread_sleep.c | 40 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 projects/test_suite/thread_sleep.c diff --git a/projects/test_suite/Jamfile b/projects/test_suite/Jamfile index eb5ff2d43b..dfb96deb7d 100644 --- a/projects/test_suite/Jamfile +++ b/projects/test_suite/Jamfile @@ -6,7 +6,7 @@ SubDir TOP projects test_suite ; -Module test_suite : test_suite.c mutex_trylock_fail.c - : shell posix_io ps uart0 ; +Module test_suite : test_suite.c mutex_trylock_fail.c thread_sleep.c + : shell posix_io ps uart0 hwtimer ; UseModule test_suite ; diff --git a/projects/test_suite/thread_sleep.c b/projects/test_suite/thread_sleep.c new file mode 100644 index 0000000000..c4bc3294a3 --- /dev/null +++ b/projects/test_suite/thread_sleep.c @@ -0,0 +1,40 @@ +#include +#include +#include + +static int integer = 0; +static int i = 0; + +static void second_thread(void) { + while(1) { + integer++; + printf("sleeper: running. integer=%i, i=%i.\n", integer, i); + if (integer % 10 == 0) { + printf("Going to sleep.\n"); + thread_sleep(); + printf("Woke up!\n"); + } + } +} + +static char second_thread_stack[KERNEL_CONF_STACKSIZE_DEFAULT*2]; +static tcb second_thread_tcb; + +void test_thread_sleep(char* line) +{ + int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper"); + + if (pid < 0) { + puts("Error creating second_thread! Stopping test."); + while(1); + } + + while(1) { + i++; + printf(" main: running. integer=%i, i=%i.\n", integer, i); + if (i % 10 == 0) { + printf("Waking up sleeper.\n"); + thread_wakeup(pid); + } + } +} From 09a8bdd2695a078b40486bd347ee14d8473552c8 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 13:01:50 +0100 Subject: [PATCH 044/115] * remove unneccessary debug message --- sys/uart0.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sys/uart0.c b/sys/uart0.c index c4656d6cf2..7360485517 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -25,7 +25,6 @@ void board_uart0_init() { int pid = thread_create(&uart0_thread_tcb, uart0_thread_stack, sizeof(uart0_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); uart0_handler_pid = pid; puts("uart0_init() [OK]"); - printf("%i\n", sizeof(uart0_thread_stack)); } void uart0_handle_incoming(int c) { From 8b91cd790b73ac0d9da358ec47a78393630c8aa4 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 13:46:25 +0100 Subject: [PATCH 045/115] * test_suite: added thread_sleep test & expect script' --- projects/test_suite/tests/04-thread_sleep | 70 +++++++++++++++++++++++ projects/test_suite/thread_sleep.c | 6 +- 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100755 projects/test_suite/tests/04-thread_sleep diff --git a/projects/test_suite/tests/04-thread_sleep b/projects/test_suite/tests/04-thread_sleep new file mode 100755 index 0000000000..1734706b7a --- /dev/null +++ b/projects/test_suite/tests/04-thread_sleep @@ -0,0 +1,70 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + ">$" {} + timeout { exit 1 } +} + +send "start_test\n" +expect { + "\[TEST_START\]" {} + timeout { exit 1 } +} + +expect { + ">$" {} + timeout { exit 1 } +} + +send "thread_sleep\n" +expect { +" main: running. integer=0, i=1." {} +" main: running. integer=0, i=2." {} +"Waking up sleeper." {} +"sleeper: running. integer=1, i=2." {} +"sleeper: running. integer=2, i=2." {} +"Going to sleep." {} +" main: running. integer=2, i=3." {} +" main: running. integer=2, i=4." {} +"Waking up sleeper." {} +"Woke up!" {} +"sleeper: running. integer=3, i=4." {} +"sleeper: running. integer=4, i=4." {} +"Going to sleep." {} +" main: running. integer=4, i=5." {} +" main: running. integer=4, i=6." {} +"Waking up sleeper." {} +"Woke up!" {} +"sleeper: running. integer=5, i=6." {} +"sleeper: running. integer=6, i=6." {} +"Going to sleep." {} +" main: running. integer=6, i=7." {} +" main: running. integer=6, i=8." {} +"Waking up sleeper." {} +"Woke up!" {} +"sleeper: running. integer=7, i=8." {} +"sleeper: running. integer=8, i=8." {} +"Going to sleep." {} +" main: running. integer=8, i=9." {} +" main: running. integer=8, i=10." {} +"Waking up sleeper." {} +"Woke up!" {} +"sleeper: running. integer=9, i=10." {} +"sleeper: running. integer=10, i=10." {} +"Going to sleep." {} + ">$" {} + timeout { exit 1 } +} + +send "end_test\n" + +expect { + "\[TEST_END\]" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" diff --git a/projects/test_suite/thread_sleep.c b/projects/test_suite/thread_sleep.c index c4bc3294a3..7790a32e0d 100644 --- a/projects/test_suite/thread_sleep.c +++ b/projects/test_suite/thread_sleep.c @@ -9,7 +9,7 @@ static void second_thread(void) { while(1) { integer++; printf("sleeper: running. integer=%i, i=%i.\n", integer, i); - if (integer % 10 == 0) { + if (integer % 2 == 0) { printf("Going to sleep.\n"); thread_sleep(); printf("Woke up!\n"); @@ -29,10 +29,10 @@ void test_thread_sleep(char* line) while(1); } - while(1) { + while(i < 10) { i++; printf(" main: running. integer=%i, i=%i.\n", integer, i); - if (i % 10 == 0) { + if (i % 2 == 0) { printf("Waking up sleeper.\n"); thread_wakeup(pid); } From 5a4524539dfbfedbaaf2b980fec1e2efd0c5e037 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 17:23:10 +0100 Subject: [PATCH 046/115] * misc shell improvements --- projects/test_shell/test_shell.c | 4 +--- projects/test_sleep/Jamfile | 2 +- projects/test_sleep/main.c | 11 ++++++----- projects/test_suite/test_suite.c | 4 +--- sys/include/shell.h | 16 ++++++---------- sys/shell/shell.c | 3 ++- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/projects/test_shell/test_shell.c b/projects/test_shell/test_shell.c index 7499c9b85b..3605a6a68f 100644 --- a/projects/test_shell/test_shell.c +++ b/projects/test_shell/test_shell.c @@ -43,10 +43,8 @@ int main(void) { posix_open(uart0_handler_pid, 0); shell_t shell; - shell_init(&shell, shell_readc, shell_putchar); + shell_init(&shell, shell_commands, shell_readc, shell_putchar); - shell.command_list = shell_commands; - shell_run(&shell); return 0; diff --git a/projects/test_sleep/Jamfile b/projects/test_sleep/Jamfile index eee5c1fa22..83289e1e2e 100644 --- a/projects/test_sleep/Jamfile +++ b/projects/test_sleep/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects test_sleep ; -Module test_sleep : main.c : hwtimer ; +Module test_sleep : main.c : hwtimer ps ; UseModule test_sleep ; diff --git a/projects/test_sleep/main.c b/projects/test_sleep/main.c index d5e02846fe..4568b274d0 100644 --- a/projects/test_sleep/main.c +++ b/projects/test_sleep/main.c @@ -2,6 +2,7 @@ #include #include #include +#include int integer = 0; int i = 0; @@ -11,7 +12,7 @@ void second_thread(void) { while(1) { integer++; printf("sleeper: running. integer=%i, i=%i.\n", integer, i); - if (integer % 100 == 0) { + if (integer % 1 == 0) { printf("Going to sleep.\n"); thread_sleep(); } @@ -19,14 +20,12 @@ void second_thread(void) { } tcb second_thread_tcb; -char second_thread_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; +char second_thread_stack[KERNEL_CONF_STACKSIZE_DEFAULT*2]; int main(void) { hwtimer_init(); - printf("Hello world!\n"); - int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper"); if (pid < 0) { @@ -37,9 +36,11 @@ int main(void) while(1) { i++; printf(" main: running. integer=%i, i=%i.\n", integer, i); - if (i % 100 == 0) { + if (i % 1 == 0) { + thread_print_all(); printf("Waking up sleeper.\n"); thread_wakeup(pid); + thread_print_all(); thread_yield(); } } diff --git a/projects/test_suite/test_suite.c b/projects/test_suite/test_suite.c index 5cfba74eb9..6133537be8 100644 --- a/projects/test_suite/test_suite.c +++ b/projects/test_suite/test_suite.c @@ -48,10 +48,8 @@ int main(void) { posix_open(uart0_handler_pid, 0); shell_t shell; - shell_init(&shell, shell_readc, shell_putchar); + shell_init(&shell, shell_commands, shell_readc, shell_putchar); - shell.command_list = shell_commands; - shell_run(&shell); return 0; diff --git a/sys/include/shell.h b/sys/include/shell.h index daa739b531..487256d444 100644 --- a/sys/include/shell.h +++ b/sys/include/shell.h @@ -34,7 +34,7 @@ and the mailinglist (subscription via web site) //#include "hashtable.h" -typedef struct shell_commant_t { +typedef struct shell_command_t { char* name; void (*handler)(char*); } shell_command_t; @@ -47,16 +47,12 @@ typedef struct shell_t { /** * @brief Initialize a shell object + * @param shell Pointer to preallocated shell object + * @param shell_commands Pointer to shell command structure. See test_shell project for example. + * @param read_char Pointer to input device read function. Should return exactly one byte or block. + * @param put_char Pointer to output funtion. currently unused, shell code will use printf. */ -void shell_init(shell_t *shell, int(*read_char)(void), void (*put_char)(int)); - -/** - * @brief Register a new command handler for a shell. - * @param shell Shell object. - * @param name Name of the command to register. - * @param handler Function pointer to handler that takes the complete command line as parameter. - */ -//void shell_register_cmd(shell_t *shell, char* name, void (*handler)(char* args)); +void shell_init(shell_t *shell, const shell_command_t *shell_commands, int(*read_char)(void), void (*put_char)(int)); /** * @brief Endless loop that waits for command and executes handler. diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 3c017c1a05..f4dce41ee3 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -115,7 +115,8 @@ void shell_run(shell_t *shell) { } } -void shell_init(shell_t *shell, int(*readchar)(void), void(*put_char)(int)) { +void shell_init(shell_t *shell, const shell_command_t *shell_commands, int(*readchar)(void), void(*put_char)(int)) { + shell->command_list = shell_commands; shell->readchar = readchar; shell->put_char = put_char; } From dc094d442bdec59902d76eb0f045fb04805f96af Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 3 Nov 2010 11:37:20 +0100 Subject: [PATCH 047/115] * fix msg_reply_int --- core/msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/msg.c b/core/msg.c index 32eda613fc..f33c7bc6e5 100644 --- a/core/msg.c +++ b/core/msg.c @@ -148,7 +148,7 @@ int msg_reply_int(msg *m, msg *reply) { return -1; } msg* target_message = (msg*)target->wait_data; - *target_message = *m; + *target_message = *reply; sched_set_status(target, STATUS_PENDING); sched_context_switch_request = 1; return 1; From 126304cd48ac8100057d71c22a41d3d2b3d5b9a8 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 3 Nov 2010 13:53:11 +0100 Subject: [PATCH 048/115] * shell: strtok workaround --- sys/shell/shell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/shell/shell.c b/sys/shell/shell.c index f4dce41ee3..fc670243a9 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -63,7 +63,8 @@ static void(*find_handler(const shell_command_t *command_list, char *command))(c static void handle_input_line(shell_t *shell, char* line) { char* saveptr; - char* command = strtok_r(line, " ", &saveptr); + char* linedup = strdup(line); + char* command = strtok_r(linedup, " ", &saveptr); void (*handler)(char*) = NULL; @@ -75,7 +76,8 @@ static void handle_input_line(shell_t *shell, char* line) { puts("shell: command not found."); } } - + + free(linedup); } int readline(shell_t *shell, char* buf, int size) { From 8f606669c25728079fc1df06255dd5200f6feb01 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 11:33:42 +0100 Subject: [PATCH 049/115] * added .gitignore to ignore binaries --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..270f8cf773 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o +doc/doxygen/html +doc/doxygen/latex +doc/doxygen/man +*bin From 6198c924e4c30a678effb2fe706cb0ae2d1f5cc5 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 13:59:57 +0100 Subject: [PATCH 050/115] * decreased timing for sht11 (as fix for hwtimer_wait issue) --- drivers/include/sht11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/include/sht11.h b/drivers/include/sht11.h index 71e7e8bac1..d929a2ecb5 100644 --- a/drivers/include/sht11.h +++ b/drivers/include/sht11.h @@ -51,7 +51,7 @@ and the mailinglist (subscription via web site) #define SHT11_RESET (0x1E) //000 1111 0 /* time to wait after toggling the data line */ -#define SHT11_DATA_WAIT (HWTIMER_TICKS(5)) +#define SHT11_DATA_WAIT (HWTIMER_TICKS(1)) /* time to wait after toggling the clock line */ #define SHT11_CLK_WAIT (HWTIMER_TICKS(1)) From 3b1cbf9cb898c578c06898d81a062deceb8fb556 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 14:12:05 +0100 Subject: [PATCH 051/115] * added board_uart0 to auto_init --- sys/auto_init.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/auto_init.c b/sys/auto_init.c index d872c0354f..17fdeb34de 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -1,5 +1,6 @@ #include #include +#include #include #define ENABLE_DEBUG @@ -16,6 +17,10 @@ void auto_init(void) { DEBUG("Auto init swtimer module.\n"); swtimer_init(); #endif +#ifdef MODULE_UART0 + DEBUG("Auto init uart0 module.\n"); + board_uart0_init(); +#endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); From 7f8baa881853489fdf5ae2c47a0f7f9f45bac73e Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 14:21:12 +0100 Subject: [PATCH 052/115] * removed unneccessary priority names --- core/include/kernel.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/core/include/kernel.h b/core/include/kernel.h index 97313916e9..d44f55a03e 100644 --- a/core/include/kernel.h +++ b/core/include/kernel.h @@ -71,14 +71,6 @@ #define PRIORITY_IDLE PRIORITY_MIN #define PRIORITY_MAIN PRIORITY_MIN-1 -#define PRIORITY_CMD_THREADS PRIORITY_MIN-2 ///< all cmd handler threads -#define PRIORITY_CBD PRIORITY_MIN-3 -#define PRIORITY_CMDD PRIORITY_MIN-4 ///< cmdengine demon -#define PRIORITY_PRINTTHREAD PRIORITY_MIN-5 ///< mprint worker thread -#define PRIORITY_HAL PRIORITY_MIN-6 -#define PRIORITY_UTIMER PRIORITY_MIN-7 -#define PRIORITY_MMREQ PRIORITY_MIN-8 -#define PRIORITY_CC1100 PRIORITY_MIN-9 /** * @brief Check whether called from interrupt service routine From dd45a471f66ae41b5c8b8afa13f55e253b861af3 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 14:24:06 +0100 Subject: [PATCH 053/115] * added prio definition --- drivers/cc110x/cc1100_phy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index bb20e242c8..925260fbb1 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -60,6 +60,8 @@ and the mailinglist (subscription via web site) #include "msg.h" #include "debug.h" +#define PRIORITY_CC1100 PRIORITY_MIN-9 + #define MSG_POLL 12346 #define FLAGS_IDENTIFICATION (0x01) ///< Bit mask for reading the identification out of the flags field From 9a0725369deb1c7f13549a9dca7b01b225732c2c Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 14:24:31 +0100 Subject: [PATCH 054/115] * added include to pull in NULL --- sys/shell/shell_commands.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index 5223597d6c..932516a4b8 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -1,4 +1,5 @@ #include +#include const shell_command_t _shell_command_list[] = { #ifdef MODULE_PS From 2e94065cd9d8f535c73b55d2d15986fb0b21f67f Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 15:05:22 +0100 Subject: [PATCH 055/115] * initial import of default project --- projects/default/Jamfile | 11 +++++++++++ projects/default/main.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 projects/default/Jamfile create mode 100644 projects/default/main.c diff --git a/projects/default/Jamfile b/projects/default/Jamfile new file mode 100644 index 0000000000..947f72a353 --- /dev/null +++ b/projects/default/Jamfile @@ -0,0 +1,11 @@ +# +# ukleos default project. Consists of a shell. +# +# Copyright (C) 2008, 2009 Kaspar Schleiser +# + +SubDir TOP projects default ; + +Module default_project : main.c : shell posix_io uart0 shell_commands ps ; + +UseModule default_project ; diff --git a/projects/default/main.c b/projects/default/main.c new file mode 100644 index 0000000000..2a99d72250 --- /dev/null +++ b/projects/default/main.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2008, 2009, 2010 Kaspar Schleiser + */ + +#include +#include + +#include +#include +#include +#include + +int shell_readc() { + char c = 0; + posix_read(uart0_handler_pid, &c, 1); + return c; +} + +void shell_putchar(int c) { + putchar(c); +} + +int main(void) { + puts("Welcome to ukleos!"); + + board_uart0_init(); + + posix_open(uart0_handler_pid, 0); + + shell_t shell; + shell_init(&shell, _shell_command_list, shell_readc, shell_putchar); + + shell_run(&shell); + + return 0; +} + + From 07681a191418c5a22295628bd6fcd5932461a554 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 15:05:51 +0100 Subject: [PATCH 056/115] * shell: added help, * shell: fixed default shell commands --- sys/include/shell.h | 1 + sys/shell/shell.c | 17 ++++++++++++++++- sys/shell/shell_commands.c | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/sys/include/shell.h b/sys/include/shell.h index 487256d444..9020914c88 100644 --- a/sys/include/shell.h +++ b/sys/include/shell.h @@ -36,6 +36,7 @@ and the mailinglist (subscription via web site) typedef struct shell_command_t { char* name; + char* desc; void (*handler)(char*); } shell_command_t; diff --git a/sys/shell/shell.c b/sys/shell/shell.c index fc670243a9..8c5a665fc2 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -61,6 +61,17 @@ static void(*find_handler(const shell_command_t *command_list, char *command))(c return NULL; } +static void print_help(const shell_command_t *command_list) { + const shell_command_t *entry = command_list; + + printf("%-20s %s\n", "Command", "Description"); + + while(entry->name != NULL) { + printf("%-20s %s\n", entry->name, entry->desc); + entry++; + } +} + static void handle_input_line(shell_t *shell, char* line) { char* saveptr; char* linedup = strdup(line); @@ -73,7 +84,11 @@ static void handle_input_line(shell_t *shell, char* line) { if (handler != NULL) { handler(line); } else { - puts("shell: command not found."); + if ( strcmp("help", command) == 0) { + print_help(shell->command_list); + } else { + puts("shell: command not found."); + } } } diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index 932516a4b8..e3656ecf8f 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -1,10 +1,14 @@ #include #include +#ifdef MODULE_PS +extern void _ps_handler(char* unnused); +#endif + const shell_command_t _shell_command_list[] = { #ifdef MODULE_PS - {"ps", ps_handler}, + {"ps", "Prints information about running threads.", _ps_handler}, #endif - {NULL, NULL} + {NULL, NULL, NULL} }; From e335ccfb433ae1de73dc7d3abe86a4f980c4556d Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 16:21:39 +0100 Subject: [PATCH 057/115] * fixed wrong return value for thread_wakeup * changed hwtimer_wait to use thread_sleep instead of mutexes --- core/hwtimer.c | 71 ++++++++++++++++++++++++++---------------- core/include/hwtimer.h | 2 +- core/include/tcb.h | 2 +- core/thread.c | 2 +- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/core/hwtimer.c b/core/hwtimer.c index e056a3dd60..e19c8a2a8f 100644 --- a/core/hwtimer.c +++ b/core/hwtimer.c @@ -23,7 +23,7 @@ #include #include -#include +#include /*---------------------------------------------------------------------------*/ @@ -33,8 +33,14 @@ typedef struct hwtimer_t { uint8_t checksum; } hwtimer_t; +typedef struct hwtimer_wait_t { + unsigned int pid; /**< pid of waiting thread */ + uint8_t state; /**state = 0; + while (!(thread_wakeup((*((hwtimer_wait_t*)hwt)).pid))) { + hwtimer_set(HWTIMER_WAIT_BACKOFF, hwtimer_wakeup, (void*) &hwt); + } } void hwtimer_spin(unsigned long ticks) @@ -109,7 +121,8 @@ void hwtimer_init_comp(uint32_t fcpu) { available_timers = 0; hwtimer_arch_init(multiplexer, fcpu); for (i = 0; i < HWTIMER_QUEUESIZE; i++) { - queue[i] = 0xff; // init queue as empty + /* init queue as empty */ + queue[i] = 0xff; } for (i = 0; i < HWTIMER_QUEUESIZE; i++) { enqueue(i); @@ -119,7 +132,7 @@ void hwtimer_init_comp(uint32_t fcpu) { /*---------------------------------------------------------------------------*/ int hwtimer_active(void) { - return queue_items != HWTIMER_QUEUESIZE; + return (queue_items != HWTIMER_QUEUESIZE); } /*---------------------------------------------------------------------------*/ @@ -133,34 +146,37 @@ unsigned long hwtimer_now(void) void hwtimer_wait(unsigned long ticks) { - mutex_t mutex; - if (ticks <= 4 || inISR()) { + if (ticks <= 6 || inISR()) { hwtimer_spin(ticks); return; } - mutex_init(&mutex); - mutex_lock(&mutex); - // -2 is to adjust the real value - int res = hwtimer_set(ticks-2, hwtimer_releasemutex, &mutex); + hwtimer_wait_t hwt; + hwt.pid = active_thread->pid; + hwt.state = 1; + /* -2 is to adjust the real value */ + int res = hwtimer_set(ticks-2, hwtimer_wakeup, (void*) &hwt); if (res == -1) { - mutex_unlock(&mutex, true); hwtimer_spin(ticks); return; } - mutex_lock(&mutex); + while (hwt.state) { + thread_sleep(); + } } /*---------------------------------------------------------------------------*/ static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr, bool absolute) { - if (! inISR() ) dINT(); -// hwtimer_arch_disable_interrupt(); + if (!inISR()) { + dINT(); + } int x = dequeue(); if (x == Q_FULL) { + if (! inISR()) { + eINT(); + } printf("[KT] no timers left\n"); -// hwtimer_arch_enable_interrupt(); - if (! inISR()) eINT(); return -1; } @@ -168,13 +184,16 @@ static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr timer[x].data = ptr; timer[x].checksum = ++timer_id; - if (absolute) + if (absolute) { hwtimer_arch_set_absolute(offset, x); - else + } + else { hwtimer_arch_set(offset, x); + } - //hwtimer_arch_enable_interrupt(); - if (! inISR()) eINT(); + if (!inISR()) { + eINT(); + } return (timer[x].checksum << 8) + x; } diff --git a/core/include/hwtimer.h b/core/include/hwtimer.h index 39f2c0f189..b2d8d2666e 100644 --- a/core/include/hwtimer.h +++ b/core/include/hwtimer.h @@ -30,7 +30,7 @@ #define __HWTIMER_H #include -#include "hwtimer_cpu.h" +#include /** * @def HWTIMER_SPEED diff --git a/core/include/tcb.h b/core/include/tcb.h index 66ef085e3f..34d7c14477 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -34,7 +34,7 @@ typedef struct tcb { char* sp; - unsigned int status; + uint8_t status; uint16_t pid; uint16_t priority; diff --git a/core/thread.c b/core/thread.c index 8afbcb8446..59aaabccec 100644 --- a/core/thread.c +++ b/core/thread.c @@ -62,7 +62,7 @@ int thread_wakeup(int pid) { } else { sched_context_switch_request = 1; } - return 0; + return 1; } else { DEBUG("thread_wakeup: Thread is not sleeping!\n"); if (!isr) eINT(); From 450b9cc58fd4153c91408947433304d7e98ec6d7 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 16:21:45 +0100 Subject: [PATCH 058/115] * minor stuff --- projects/default/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/projects/default/main.c b/projects/default/main.c index 2a99d72250..bc2100f539 100644 --- a/projects/default/main.c +++ b/projects/default/main.c @@ -21,11 +21,10 @@ void shell_putchar(int c) { } int main(void) { - puts("Welcome to ukleos!"); - board_uart0_init(); - posix_open(uart0_handler_pid, 0); + + puts("Welcome to ukleos!"); shell_t shell; shell_init(&shell, _shell_command_list, shell_readc, shell_putchar); From 02945e22f7bc8f45ac0ea79f9270c0c634fbaf18 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 16:46:25 +0100 Subject: [PATCH 059/115] * fixed for new shell_command_t layout --- projects/test_shell/test_shell.c | 6 +++--- projects/test_suite/test_suite.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/test_shell/test_shell.c b/projects/test_shell/test_shell.c index 3605a6a68f..6839969af9 100644 --- a/projects/test_shell/test_shell.c +++ b/projects/test_shell/test_shell.c @@ -29,9 +29,9 @@ void shell_putchar(int c) { } const shell_command_t shell_commands[] = { - {"start_test", print_teststart}, - {"end_test", print_testend}, - {NULL, NULL} + {"start_test", "", print_teststart}, + {"end_test", "", print_testend}, + {NULL, NULL, NULL} }; int main(void) { diff --git a/projects/test_suite/test_suite.c b/projects/test_suite/test_suite.c index 6133537be8..40a019fc02 100644 --- a/projects/test_suite/test_suite.c +++ b/projects/test_suite/test_suite.c @@ -32,11 +32,11 @@ void mutex_trylock_fail(char* cmdline); void test_thread_sleep(char* line); const shell_command_t shell_commands[] = { - {"start_test", print_teststart}, - {"end_test", print_testend}, - {"mutex_trylock_fail", mutex_trylock_fail}, - {"thread_sleep", test_thread_sleep}, - {NULL, NULL} + {"start_test", "", print_teststart}, + {"end_test", "", print_testend}, + {"mutex_trylock_fail", "", mutex_trylock_fail}, + {"thread_sleep", "", test_thread_sleep}, + {NULL, NULL, NULL} }; int main(void) { From f860abc4088a931c6db6549b139fc3418f1b0dba Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 16:47:13 +0100 Subject: [PATCH 060/115] * checkin of missing header file --- sys/include/shell_commands.h | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 sys/include/shell_commands.h diff --git a/sys/include/shell_commands.h b/sys/include/shell_commands.h new file mode 100644 index 0000000000..1e0ec85759 --- /dev/null +++ b/sys/include/shell_commands.h @@ -0,0 +1,8 @@ +#ifndef __SHELL_COMMANDS_H +#define __SHELL_COMMANDS_H + +#include + +extern const shell_command_t _shell_command_list[]; + +#endif /* __SHELL_COMMANDS_H */ From eff0b1980f41fbf908b19005f91072f96cb84abe Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 16:47:24 +0100 Subject: [PATCH 061/115] * API CHANGE! changed thread_create so it allocates tcb on stack, removing first argument --- core/include/thread.h | 2 +- core/kernel_init.c | 7 ++----- core/thread.c | 13 ++++++------- drivers/cc110x/cc1100_phy.c | 3 +-- projects/pingpong/main.c | 3 +-- projects/pingpong_sync/main.c | 3 +-- projects/test_sleep/main.c | 3 +-- projects/test_suite/mutex_trylock_fail.c | 3 +-- projects/test_suite/thread_sleep.c | 3 +-- projects/test_thread_exit/main.c | 3 +-- sys/uart0.c | 3 +-- 11 files changed, 17 insertions(+), 29 deletions(-) diff --git a/core/include/thread.h b/core/include/thread.h index df4c73060d..268367fbbc 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -34,7 +34,7 @@ * * @return returns <0 on error, pid of newly created task else. */ -int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, void (*function) (void), const char* name); +int thread_create(char *stack, int stacksize, char priority, int flags, void (*function) (void), const char* name); /** * @brief returns the status of a process. diff --git a/core/kernel_init.c b/core/kernel_init.c index d2d4622185..a52597c111 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -57,10 +57,7 @@ static void idle_thread(void) { const char *main_name = "main"; const char *idle_name = "idle"; -static tcb main_tcb; static char main_stack[KERNEL_CONF_STACKSIZE_MAIN]; - -static tcb idle_tcb; static char idle_stack[KERNEL_CONF_STACKSIZE_IDLE]; #ifdef MODULE_AUTO_INIT @@ -76,11 +73,11 @@ void kernel_init(void) sched_init(); - if (thread_create(&idle_tcb, idle_stack, sizeof(idle_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) { + if (thread_create(idle_stack, sizeof(idle_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) { printf("kernel_init(): error creating idle task.\n"); } - if (thread_create(&main_tcb, main_stack, sizeof(main_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) { + if (thread_create(main_stack, sizeof(main_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) { printf("kernel_init(): error creating main task.\n"); } diff --git a/core/thread.c b/core/thread.c index 8afbcb8446..903435159a 100644 --- a/core/thread.c +++ b/core/thread.c @@ -80,13 +80,12 @@ int thread_measure_stack_usage(char* stack) { return space; } -int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, void (*function) (void), const char* name) +int thread_create(char *stack, int stacksize, char priority, int flags, void (*function) (void), const char* name) { - /* stacksize must be a multitude of 4 for alignment and stacktest */ -// assert( ((stacksize & 0x03) == 0) && (stacksize > 0) ); - - // TODO: shall we autoalign the stack? - // stacksize += 4-(~(stacksize & 0x0003)); + /* allocate our thread control block at the top of our stackspace */ + int total_stacksize = stacksize; + stacksize -= sizeof(tcb); + tcb *cb = (tcb*) (stack + stacksize); if (priority >= SCHED_PRIO_LEVELS) { return -EINVAL; @@ -130,7 +129,7 @@ int thread_create(tcb *cb, char *stack, int stacksize, char priority, int flags, cb->sp = thread_stack_init(function,stack+stacksize); cb->stack_start = stack; - cb->stack_size = stacksize; + cb->stack_size = total_stacksize; cb->priority = priority; cb->status = 0; diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 925260fbb1..4723bfa172 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -102,7 +102,6 @@ static uint64_t cc1100_watch_dog_period = 0; static uint16_t cc1100_event_handler_pid; static void cc1100_event_handler_function(void); -static tcb event_handler_tcb; static char event_handler_stack[KERNEL_CONF_STACKSIZE_MAIN]; /*---------------------------------------------------------------------------*/ @@ -194,7 +193,7 @@ void cc1100_phy_init() mutex_init(&cc1100_mutex); // Allocate event numbers and start cc1100 event process - cc1100_event_handler_pid = thread_create(&event_handler_tcb, event_handler_stack, sizeof(event_handler_stack), PRIORITY_CC1100, CREATE_STACKTEST, + cc1100_event_handler_pid = thread_create(event_handler_stack, sizeof(event_handler_stack), PRIORITY_CC1100, CREATE_STACKTEST, cc1100_event_handler_function, cc1100_event_handler_name); // Active watchdog for the first time diff --git a/projects/pingpong/main.c b/projects/pingpong/main.c index 62b720a55a..2c9f214571 100644 --- a/projects/pingpong/main.c +++ b/projects/pingpong/main.c @@ -15,7 +15,6 @@ void second_thread(void) { } } -tcb second_thread_tcb; char second_thread_stack[KERNEL_CONF_STACKSIZE_MAIN]; int main(void) @@ -24,7 +23,7 @@ int main(void) msg m; - int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); + int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); m.content.value = 1; diff --git a/projects/pingpong_sync/main.c b/projects/pingpong_sync/main.c index d0468ffeac..8e1fd4d7d4 100644 --- a/projects/pingpong_sync/main.c +++ b/projects/pingpong_sync/main.c @@ -15,7 +15,6 @@ void second_thread(void) { } } -tcb second_thread_tcb; char second_thread_stack[8192]; int main(void) @@ -24,7 +23,7 @@ int main(void) msg m; - int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); + int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); m.content.value = 1; diff --git a/projects/test_sleep/main.c b/projects/test_sleep/main.c index 4568b274d0..59e9e0013d 100644 --- a/projects/test_sleep/main.c +++ b/projects/test_sleep/main.c @@ -19,14 +19,13 @@ void second_thread(void) { } } -tcb second_thread_tcb; char second_thread_stack[KERNEL_CONF_STACKSIZE_DEFAULT*2]; int main(void) { hwtimer_init(); - int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper"); + int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper"); if (pid < 0) { puts("Error creating second_thread! Stopping test."); diff --git a/projects/test_suite/mutex_trylock_fail.c b/projects/test_suite/mutex_trylock_fail.c index 5acb9a05b5..079d0d960c 100644 --- a/projects/test_suite/mutex_trylock_fail.c +++ b/projects/test_suite/mutex_trylock_fail.c @@ -13,7 +13,6 @@ static void second_thread(void) { puts(" 2nd: done."); } -static tcb second_tcb; static char second_stack[KERNEL_CONF_STACKSIZE_MAIN]; void mutex_trylock_fail(char* cmdline) @@ -22,7 +21,7 @@ void mutex_trylock_fail(char* cmdline) mutex_lock(&mutex); puts("main: creating thread..."); - thread_create(&second_tcb, second_stack, KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2"); + thread_create(second_stack, KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2"); puts("main: thread created. Unlocking mutex..."); mutex_unlock(&mutex, true); diff --git a/projects/test_suite/thread_sleep.c b/projects/test_suite/thread_sleep.c index 7790a32e0d..c88c015503 100644 --- a/projects/test_suite/thread_sleep.c +++ b/projects/test_suite/thread_sleep.c @@ -18,11 +18,10 @@ static void second_thread(void) { } static char second_thread_stack[KERNEL_CONF_STACKSIZE_DEFAULT*2]; -static tcb second_thread_tcb; void test_thread_sleep(char* line) { - int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper"); + int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper"); if (pid < 0) { puts("Error creating second_thread! Stopping test."); diff --git a/projects/test_thread_exit/main.c b/projects/test_thread_exit/main.c index 4646c2679a..363d437a22 100644 --- a/projects/test_thread_exit/main.c +++ b/projects/test_thread_exit/main.c @@ -9,11 +9,10 @@ void second_thread(void) { puts("2nd: running..."); } -tcb second_thread_tcb; char second_thread_stack[8192]; int main(void) { - int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "nr2"); + int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "nr2"); puts("Main thread exiting..."); } diff --git a/sys/uart0.c b/sys/uart0.c index 7360485517..b4c561822d 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -13,7 +13,6 @@ int uart0_handler_pid; static char buffer[UART0_BUFSIZE]; -static tcb uart0_thread_tcb; static char uart0_thread_stack[KERNEL_CONF_STACKSIZE_MAIN]; static void uart0_loop() { @@ -22,7 +21,7 @@ static void uart0_loop() { void board_uart0_init() { ringbuffer_init(&uart0_ringbuffer, buffer, UART0_BUFSIZE); - int pid = thread_create(&uart0_thread_tcb, uart0_thread_stack, sizeof(uart0_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); + int pid = thread_create(uart0_thread_stack, sizeof(uart0_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); uart0_handler_pid = pid; puts("uart0_init() [OK]"); } From 2bf64ea4d0665f2c306aa1782549b0be75104494 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 16:51:04 +0100 Subject: [PATCH 062/115] * make doc reflect latest API change --- core/include/thread.h | 1 - 1 file changed, 1 deletion(-) diff --git a/core/include/thread.h b/core/include/thread.h index 268367fbbc..ec8f5636ce 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -20,7 +20,6 @@ * @brief Creates a new thread. * This version will allocate it's stack itself using malloc. * - * @param cb Address of preallocated tcb structure * @param stack Lowest address of preallocated stack space * @param stacksize * @param flags Options: From ba03f610c49e42c1913384095fcf5ef0f454885a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 4 Nov 2010 17:06:03 +0100 Subject: [PATCH 063/115] * fix status size --- core/include/tcb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/tcb.h b/core/include/tcb.h index 34d7c14477..2de9827728 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -34,7 +34,7 @@ typedef struct tcb { char* sp; - uint8_t status; + uint16_t status; uint16_t pid; uint16_t priority; From 3b218ec24adcd2117a07f759cdf836e9b8a054d2 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 18:16:39 +0100 Subject: [PATCH 064/115] * changed API for rtc * added drivers directory to doxygen file * added missing include to sht11 header * added rtc and sht11 support to default project * added rtc to auto_init * added rtc and sht11 support to shell --- cpu/lpc2387/include/lpc2387-rtc.h | 12 ++++++--- cpu/lpc2387/lpc2387-rtc.c | 14 +++++------ doc/doxygen/ukleos.doxyfile | 4 +-- drivers/include/sht11.h | 1 + projects/default/Jamfile | 2 +- projects/default/main.c | 1 - sys/auto_init.c | 6 +++++ sys/shell/Jamfile | 2 +- sys/shell/rtc.c | 40 ++++++++++++++++++++++++++++++ sys/shell/shell.c | 2 +- sys/shell/shell_commands.c | 22 ++++++++++++++++- sys/shell/sht11.c | 41 +++++++++++++++++++++++++++++++ 12 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 sys/shell/rtc.c create mode 100644 sys/shell/sht11.c diff --git a/cpu/lpc2387/include/lpc2387-rtc.h b/cpu/lpc2387/include/lpc2387-rtc.h index 9420fc7c21..c1580329eb 100644 --- a/cpu/lpc2387/include/lpc2387-rtc.h +++ b/cpu/lpc2387/include/lpc2387-rtc.h @@ -81,9 +81,9 @@ enum rtc_alarm_mask { * @internal * During reboots only alarms are reset. */ -void _rtc_init(void); +void rtc_init(void); -void _rtc_reset(void); +void rtc_reset(void); /** * @brief Returns the time of compilation in seconds @@ -91,6 +91,12 @@ void _rtc_reset(void); */ time_t rtc_get_compile_time(void) __attribute__((noinline)); +/** + * @brief Sets the current time in broken down format directly from to RTC + * @param[in] localt Pointer to structure with time to set + */ +void rtc_set_localtime(struct tm* localt); + /** * @brief Returns the current clock time * @param[out] time optional return value @@ -131,7 +137,7 @@ void rtc_get_localtime(struct tm* localt); * * @see ::rtc_alarm_mask */ -void _rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask); +void rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask); /** * @brief Gets the current alarm setting diff --git a/cpu/lpc2387/lpc2387-rtc.c b/cpu/lpc2387/lpc2387-rtc.c index ca713833a0..4c896c47d2 100644 --- a/cpu/lpc2387/lpc2387-rtc.c +++ b/cpu/lpc2387/lpc2387-rtc.c @@ -68,7 +68,7 @@ static volatile time_t epoch; * @brief Sets the current time in broken down format directly from to RTC * @param[in] localt Pointer to structure with time to set */ -static void +void rtc_set_localtime(struct tm* localt) { if( localt == NULL ) @@ -93,14 +93,14 @@ void rtc_set(time_t time) { } /*---------------------------------------------------------------------------*/ /// set clock to start of unix epoch -void _rtc_reset(void) +void rtc_reset(void) { rtc_set(0); epoch = 0; } /*---------------------------------------------------------------------------*/ void -_rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask) +rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask) { if( localt != NULL ) { RTC_ALSEC = localt->tm_sec; @@ -120,7 +120,7 @@ _rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask) } /*---------------------------------------------------------------------------*/ enum rtc_alarm_mask -_rtc_get_alarm(struct tm* localt) +rtc_get_alarm(struct tm* localt) { if( localt != NULL ) { localt->tm_sec = RTC_ALSEC; @@ -169,7 +169,7 @@ void rtc_enable(void) epoch = now - (now % 3600); } /*---------------------------------------------------------------------------*/ -void _rtc_init(void) +void rtc_init(void) { PCONP |= BIT9; RTC_AMR = 0xff; // disable alarm irq @@ -183,7 +183,7 @@ void _rtc_init(void) /* initialize clock with valid unix compatible values * If RTC_YEAR contains an value larger unix time_t we must reset. */ if( RTC_YEAR > 2037 ) { - _rtc_reset(); + rtc_reset(); } PRINTF("%2lu.%2lu.%4lu %2lu:%2lu:%2lu epoch %lu", @@ -242,7 +242,7 @@ rtc_get_localtime(struct tm* localt) } } /*---------------------------------------------------------------------------*/ -void _gettimeofday_r(struct _reent *r, struct timeval *ptimeval, struct timezone *ptimezone) +void gettimeofday_r(struct _reent *r, struct timeval *ptimeval, struct timezone *ptimezone) { r->_errno = 0; if( ptimeval != NULL ) { diff --git a/doc/doxygen/ukleos.doxyfile b/doc/doxygen/ukleos.doxyfile index bbf20122e9..490fd04f21 100644 --- a/doc/doxygen/ukleos.doxyfile +++ b/doc/doxygen/ukleos.doxyfile @@ -85,7 +85,7 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = ../../core ../../cpu ../../board ../../sys ../manual +INPUT = ../../core ../../cpu ../../board ../../sys ../manual ../../drivers INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.doc *.c *.h RECURSIVE = YES @@ -125,7 +125,7 @@ HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_HEADER = src/ukleos-header.html HTML_FOOTER = src/ukleos-footer.html -HTML_STYLESHEET = src/ukleos.css +HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES HTML_DYNAMIC_SECTIONS = YES GENERATE_DOCSET = NO diff --git a/drivers/include/sht11.h b/drivers/include/sht11.h index d929a2ecb5..227569f5e1 100644 --- a/drivers/include/sht11.h +++ b/drivers/include/sht11.h @@ -40,6 +40,7 @@ and the mailinglist (subscription via web site) * * @note $Id: sht11.h 667 2009-02-19 15:06:38Z baar $ */ +#include #define SHT11_NO_ACK (0) #define SHT11_ACK (1) diff --git a/projects/default/Jamfile b/projects/default/Jamfile index 947f72a353..476db1c00c 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 ; +Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 auto_init ; UseModule default_project ; diff --git a/projects/default/main.c b/projects/default/main.c index bc2100f539..5480211801 100644 --- a/projects/default/main.c +++ b/projects/default/main.c @@ -21,7 +21,6 @@ void shell_putchar(int c) { } int main(void) { - board_uart0_init(); posix_open(uart0_handler_pid, 0); puts("Welcome to ukleos!"); diff --git a/sys/auto_init.c b/sys/auto_init.c index 17fdeb34de..c92b2b0176 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #define ENABLE_DEBUG @@ -21,6 +22,11 @@ void auto_init(void) { DEBUG("Auto init uart0 module.\n"); board_uart0_init(); #endif +#ifdef MODULE_RTC + DEBUG("Auto init rtc module.\n"); + rtc_init(); + rtc_enable(); +#endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); diff --git a/sys/shell/Jamfile b/sys/shell/Jamfile index 195b04fd8c..a17b4173df 100644 --- a/sys/shell/Jamfile +++ b/sys/shell/Jamfile @@ -28,7 +28,7 @@ SubDir TOP sys shell ; Module shell : shell.c ; -Module shell_commands : shell_commands.c : shell ; +Module shell_commands : shell_commands.c rtc.c sht11.c : shell ; Module ps : ps.c ; diff --git a/sys/shell/rtc.c b/sys/shell/rtc.c new file mode 100644 index 0000000000..86d4add0ec --- /dev/null +++ b/sys/shell/rtc.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +void _gettime_handler(char *unused) { + struct tm now; + rtc_get_localtime(&now); + + printf("%s", asctime(&now)); +} + +void _settime_handler(char* c) { + struct tm now; + int res; + uint16_t month, epoch_year; + + res = sscanf(c, "settime %hu-%hu-%i %i:%i:%i", + &epoch_year, + &month, + &(now.tm_mday), + &(now.tm_hour), + &(now.tm_min), + &(now.tm_sec)); + + if (res < 6) { + printf("Usage: settime YYYY-MM-DD hh:mm:ss\n"); + return; + } + else { + printf("OK %s", asctime(&now)); + } + + now.tm_year = epoch_year - 1900; + now.tm_mon = month - 1; + time_t t = mktime(&now); + rtc_set(t); +} + + diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 8c5a665fc2..02f4726cb3 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -122,7 +122,7 @@ void shell_run(shell_t *shell) { char line_buf[255]; while(1) { - shell->put_char('>'); + shell->put_char('> '); int res = readline(shell, line_buf, sizeof(line_buf)); if (! res ) { char* line_copy = strdup(line_buf); diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index e3656ecf8f..f5aa08c650 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -2,12 +2,32 @@ #include #ifdef MODULE_PS -extern void _ps_handler(char* unnused); +extern void _ps_handler(char* unused); +#endif + +#ifdef MODULE_RTC +extern void _gettime_handler(char* unused); +extern void _settime_handler(char* now); +#endif + +#ifdef MODULE_SHT11 +extern void _get_temperature_handler(char* unused); +extern void _get_humidity_handler(char* unused); +extern void _get_weather_handler(char* unused); #endif const shell_command_t _shell_command_list[] = { #ifdef MODULE_PS {"ps", "Prints information about running threads.", _ps_handler}, +#endif +#ifdef MODULE_RTC + {"gettime", "Prints current date and time.", _gettime_handler}, + {"settime", "Sets current time.", _settime_handler}, +#endif +#ifdef MODULE_SHT11 + {"gettemp", "Prints measured temperature.", _get_temperature_handler}, + {"gethum", "Prints measured humidity.", _get_humidity_handler}, + {"getweather", "Prints measured humidity and temperature.", _get_weather_handler}, #endif {NULL, NULL, NULL} }; diff --git a/sys/shell/sht11.c b/sys/shell/sht11.c new file mode 100644 index 0000000000..b24c8db936 --- /dev/null +++ b/sys/shell/sht11.c @@ -0,0 +1,41 @@ +#include +#include +#include + +void _get_humidity_handler(char* unused) { + uint8_t success; + sht11_val_t sht11_val; + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + if (!success) { + printf("Error reading SHT11\n"); + } + else { + printf("Relative humidity: %5.2f%% / Temperature compensated humidity; %5.2f%%\n", + sht11_val.relhum, sht11_val.relhum_temp); + } +} +void _get_temperature_handler(char* unused) { + uint8_t success; + sht11_val_t sht11_val; + success = sht11_read_sensor(&sht11_val, TEMPERATURE); + if (!success) { + printf("Error reading SHT11\n"); + } + else { + printf("Temperature: %-6.2f°C\n", sht11_val.temperature); + } +} +void _get_weather_handler(char* unused) { + uint8_t success; + sht11_val_t sht11_val; + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + if (!success) { + printf("Error reading SHT11\n"); + } + else { + printf("Relative humidity: %5.2f%% / Temperature compensated humidity; %5.2f%% ", + sht11_val.relhum, sht11_val.relhum_temp); + printf("Temperature: %-6.2f°C\n", sht11_val.temperature); + } +} + From c389518a0998e38b2bf7b297940f586e788d4ff5 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 19:06:46 +0100 Subject: [PATCH 065/115] * shell_commands can be added as a module to user defined shell commands --- sys/shell/shell.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 02f4726cb3..37d8097750 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -47,17 +47,30 @@ and the mailinglist (subscription via web site) #include #include #include +#include +#include static void(*find_handler(const shell_command_t *command_list, char *command))(char*) { - const shell_command_t *entry = command_list; + const shell_command_t* entry = command_list; - while(entry->name != NULL) { + while (entry->name != NULL) { if ( strcmp(entry->name, command) == 0) { return entry->handler; } else { entry++; } } + +#ifdef MODULE_SHELL_COMMANDS + entry = _shell_command_list; + while (entry->name != NULL) { + if ( strcmp(entry->name, command) == 0) { + return entry->handler; + } else { + entry++; + } + } +#endif return NULL; } @@ -65,11 +78,20 @@ static void print_help(const shell_command_t *command_list) { const shell_command_t *entry = command_list; printf("%-20s %s\n", "Command", "Description"); + puts("---------------------------------------"); - while(entry->name != NULL) { + while (entry->name != NULL) { printf("%-20s %s\n", entry->name, entry->desc); entry++; } + +#ifdef MODULE_SHELL_COMMANDS + entry = _shell_command_list; + while (entry->name != NULL) { + printf("%-20s %s\n", entry->name, entry->desc); + entry++; + } +#endif } static void handle_input_line(shell_t *shell, char* line) { @@ -122,7 +144,7 @@ void shell_run(shell_t *shell) { char line_buf[255]; while(1) { - shell->put_char('> '); + shell->put_char('>'); int res = readline(shell, line_buf, sizeof(line_buf)); if (! res ) { char* line_copy = strdup(line_buf); From 416029d2c0056aada5b4e5c098f311dfa8517184 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 5 Nov 2010 19:33:45 +0100 Subject: [PATCH 066/115] * changed default project from "hello-world" to "default" * increased main priority to the half of maximum priority * introduced define for minimum stack size * decreased stack size for uart0 thread * merged commands for rtc shell module to one command (date) * cleanup of header includes --- Jamrules | 2 +- core/include/kernel.h | 2 +- core/include/tcb.h | 25 +++++++++++++------------ core/include/thread.h | 4 +++- core/sched.c | 11 +++++------ core/thread.c | 1 - sys/shell/rtc.c | 18 +++++++++++++----- sys/shell/shell.c | 1 - sys/shell/shell_commands.c | 6 ++---- sys/uart0.c | 5 +++-- 10 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Jamrules b/Jamrules index a2801d2a9a..8dbb5f62c7 100644 --- a/Jamrules +++ b/Jamrules @@ -33,7 +33,7 @@ include $(TOP)$(SLASH)Jamrules.common ; # # Setup ukleos build system configuration (default values for common options) # -PROJECT = $(PROJECT:E=hello-world) ; +PROJECT = $(PROJECT:E=default) ; BOARD = $(BOARD:E=msba2) ; SUFFIX ?= "" ; # must be at least "" !!! TARGET = "$(BOARD)-$(PROJECT)$(SUFFIX)$(SUFEXE)" ; # main target binary diff --git a/core/include/kernel.h b/core/include/kernel.h index d44f55a03e..081ced085e 100644 --- a/core/include/kernel.h +++ b/core/include/kernel.h @@ -70,7 +70,7 @@ #define PRIORITY_MIN SCHED_PRIO_LEVELS-1 #define PRIORITY_IDLE PRIORITY_MIN -#define PRIORITY_MAIN PRIORITY_MIN-1 +#define PRIORITY_MAIN (PRIORITY_MIN - (SCHED_PRIO_LEVELS/2)) /** * @brief Check whether called from interrupt service routine diff --git a/core/include/tcb.h b/core/include/tcb.h index 2de9827728..95f9412539 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -17,20 +17,21 @@ #define TCB_H_ #include -#include "queue.h" -#include "clist.h" +#include +#include /* uneven means has to be on runqueue */ -#define STATUS_NOT_FOUND 0 -#define STATUS_ON_RUNQUEUE 1 -#define STATUS_RUNNING 2 + STATUS_ON_RUNQUEUE -#define STATUS_PENDING 4 + STATUS_ON_RUNQUEUE -#define STATUS_STOPPED 8 -#define STATUS_SLEEPING 16 -#define STATUS_MUTEX_BLOCKED 32 -#define STATUS_RECEIVE_BLOCKED 64 -#define STATUS_SEND_BLOCKED 128 -#define STATUS_REPLY_BLOCKED 256 +#define STATUS_NOT_FOUND (0x0000) +#define STATUS_ON_RUNQUEUE (0x0001) +#define STATUS_RUNNING (0x0002) + STATUS_ON_RUNQUEUE +#define STATUS_PENDING (0x0004) + STATUS_ON_RUNQUEUE +#define STATUS_STOPPED (0x0008) +#define STATUS_SLEEPING (0x0010) +#define STATUS_MUTEX_BLOCKED (0x0020) +#define STATUS_RECEIVE_BLOCKED (0x0040) +#define STATUS_SEND_BLOCKED (0x0080) +#define STATUS_REPLY_BLOCKED (0x0100) +#define STATUS_TIMER_WAITING (0x0200) typedef struct tcb { char* sp; diff --git a/core/include/thread.h b/core/include/thread.h index ec8f5636ce..359d778d91 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -14,11 +14,13 @@ */ #include +#include +/** Minimum stack size */ +#define MINIMUM_STACK_SIZE (sizeof(tcb)) /** * @brief Creates a new thread. - * This version will allocate it's stack itself using malloc. * * @param stack Lowest address of preallocated stack space * @param stacksize diff --git a/core/sched.c b/core/sched.c index 03e2f4f32a..bd8728fbe3 100644 --- a/core/sched.c +++ b/core/sched.c @@ -14,15 +14,14 @@ */ #include -#include -#include "sched.h" -#include "kernel.h" -#include "kernel_intern.h" -#include "clist.h" +#include +#include +#include +#include #include //#define ENABLE_DEBUG -#include "debug.h" +#include volatile int num_tasks = 0; diff --git a/core/thread.c b/core/thread.c index 58df5068e4..31fcde282e 100644 --- a/core/thread.c +++ b/core/thread.c @@ -14,7 +14,6 @@ */ #include -#include #include #include "thread.h" diff --git a/sys/shell/rtc.c b/sys/shell/rtc.c index 86d4add0ec..44c58a65a7 100644 --- a/sys/shell/rtc.c +++ b/sys/shell/rtc.c @@ -2,8 +2,9 @@ #include #include #include +#include -void _gettime_handler(char *unused) { +void _gettime_handler(void) { struct tm now; rtc_get_localtime(&now); @@ -15,7 +16,7 @@ void _settime_handler(char* c) { int res; uint16_t month, epoch_year; - res = sscanf(c, "settime %hu-%hu-%i %i:%i:%i", + res = sscanf(c, "date %hu-%hu-%i %i:%i:%i", &epoch_year, &month, &(now.tm_mday), @@ -24,11 +25,11 @@ void _settime_handler(char* c) { &(now.tm_sec)); if (res < 6) { - printf("Usage: settime YYYY-MM-DD hh:mm:ss\n"); + printf("Usage: date YYYY-MM-DD hh:mm:ss\n"); return; } else { - printf("OK %s", asctime(&now)); + puts("OK"); } now.tm_year = epoch_year - 1900; @@ -37,4 +38,11 @@ void _settime_handler(char* c) { rtc_set(t); } - +void _date_handler(char* c) { + if (strlen(c) == 4) { + _gettime_handler(); + } + else { + _settime_handler(c); + } +} diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 37d8097750..2e17a900b9 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -44,7 +44,6 @@ and the mailinglist (subscription via web site) #include #include #include -#include #include #include #include diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index f5aa08c650..e337db6f80 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -6,8 +6,7 @@ extern void _ps_handler(char* unused); #endif #ifdef MODULE_RTC -extern void _gettime_handler(char* unused); -extern void _settime_handler(char* now); +extern void _date_handler(char* now); #endif #ifdef MODULE_SHT11 @@ -21,8 +20,7 @@ const shell_command_t _shell_command_list[] = { {"ps", "Prints information about running threads.", _ps_handler}, #endif #ifdef MODULE_RTC - {"gettime", "Prints current date and time.", _gettime_handler}, - {"settime", "Sets current time.", _settime_handler}, + {"date", "Geets or gets current date and time.", _date_handler}, #endif #ifdef MODULE_SHT11 {"gettemp", "Prints measured temperature.", _get_temperature_handler}, diff --git a/sys/uart0.c b/sys/uart0.c index b4c561822d..29ea4efa05 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -6,14 +6,15 @@ #include -#define UART0_BUFSIZE 32 +#define UART0_BUFSIZE (32) +#define UART0_STACKSIZE (MINIMUM_STACK_SIZE + 256) ringbuffer uart0_ringbuffer; int uart0_handler_pid; static char buffer[UART0_BUFSIZE]; -static char uart0_thread_stack[KERNEL_CONF_STACKSIZE_MAIN]; +static char uart0_thread_stack[UART0_STACKSIZE]; static void uart0_loop() { chardev_loop(&uart0_ringbuffer); From ec467aea806dd8280d7b99a4fdc2172b11e2db2f Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 5 Nov 2010 22:04:11 +0100 Subject: [PATCH 067/115] * added global offset to temperature --- drivers/sht11.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/sht11.c b/drivers/sht11.c index 70e4039e85..d4bb6ec964 100644 --- a/drivers/sht11.c +++ b/drivers/sht11.c @@ -48,6 +48,8 @@ and the mailinglist (subscription via web site) //#define ENABLE_DEBUG (1) #include +float sht11_temperature_offset; + /** * @brief Perform measurement * @@ -260,6 +262,7 @@ static uint8_t measure(uint8_t *p_value, uint8_t *p_checksum, uint8_t mode) } /*---------------------------------------------------------------------------*/ void sht11_init(void) { + sht11_temperature_offset = 0; mutex_init(&sht11_mutex); SHT11_INIT; hwtimer_wait(11 * HWTIMER_TICKS(1000)); @@ -334,7 +337,7 @@ uint8_t sht11_read_sensor(sht11_val_t *value, sht11_mode_t mode) { } if (mode & TEMPERATURE) { - value->temperature = D1 + (D2 * ((float) temp_int)); + value->temperature = D1 + (D2 * ((float) temp_int)) + sht11_temperature_offset; } if (mode & HUMIDITY) { value->relhum = C1 + (C2 * ((float) humi_int)) + (C3 * ((float) humi_int) * ((float) humi_int)); From 8f512fd6d41f86116f393f689549ba288c75a6e8 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 5 Nov 2010 22:36:14 +0100 Subject: [PATCH 068/115] * introduced small python terminal script --- tools/pyterm/pyterm.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 tools/pyterm/pyterm.py diff --git a/tools/pyterm/pyterm.py b/tools/pyterm/pyterm.py new file mode 100755 index 0000000000..1bda7ddd2a --- /dev/null +++ b/tools/pyterm/pyterm.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import cmd, serial, sys, threading, readline, time +from datetime import datetime + +class MyCmd(cmd.Cmd): + + def default(self, line): + self.stdout.write(line + "\n") + + def do_help(self, line): + self.stdout.write(line + "\n") + + def complete_date(self, text, line, begidx, endidx): + date = datetime.now().strftime("%Y-%M-%d %H:%m:%S") + return ["date %s\n" % date] + + def do_exit(self, line): + sys.exit(0) + +def sender(ser): + time.sleep(5) + ser.write("ps\n") + +def reader(ser): + while (1): + c = ser.read(1) + sys.stdout.write(c) + sys.stdout.flush() + +if __name__ == "__main__": + + if (len(sys.argv) != 2): + print("Usage: %s " % sys.argv[0]) + sys.exit(-1) + + p = sys.argv[1] + ser = serial.Serial(port=p, baudrate=115200, dsrdtr=0, rtscts=0) + + ser.setDTR(0) + ser.setRTS(0) + + # start serial->console thread + receiver_thread = threading.Thread(target=reader, args=(ser,)) + receiver_thread.setDaemon(1) + receiver_thread.start() + + sender_thread = threading.Thread(target=sender, args=(ser,)) + sender_thread.start() + + myshell = MyCmd(stdout=ser) + myshell.prompt = "" + + myshell.cmdloop("Opening port: %s" % sys.argv[1]) From ac6d4788ebf489a8f6b054efd982dd70863a50af Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 5 Nov 2010 23:43:14 +0100 Subject: [PATCH 069/115] * added ltc4150 shell command * cosmetics in ltc4150 driver --- drivers/include/ltc4150.h | 2 +- drivers/ltc4150.c | 2 +- projects/default/Jamfile | 2 +- projects/default/main.c | 4 +++- sys/shell/Jamfile | 2 +- sys/shell/shell.c | 29 ++++++++++++++++------------- sys/shell/shell_commands.c | 15 ++++++++++++--- tools/pyterm/pyterm.py | 11 ++--------- 8 files changed, 37 insertions(+), 30 deletions(-) diff --git a/drivers/include/ltc4150.h b/drivers/include/ltc4150.h index e7fbad663f..b024f4b5cd 100644 --- a/drivers/include/ltc4150.h +++ b/drivers/include/ltc4150.h @@ -8,7 +8,7 @@ void ltc4150_start(); void ltc4150_stop(); double ltc4150_get_current_mA(); -double ltc4150_get_total_mA(); +double ltc4150_get_total_mAh(); double ltc4150_get_avg_mA(); #endif /* __LTC4150_H */ diff --git a/drivers/ltc4150.c b/drivers/ltc4150.c index bcc166b70b..6c58b3d7d3 100644 --- a/drivers/ltc4150.c +++ b/drivers/ltc4150.c @@ -62,7 +62,7 @@ double ltc4150_get_current_mA() { return 1000000000/(ltc4150_get_last_int_duration_us()*(_GFH * _R_SENSE)); } -double ltc4150_get_total_mA() { +double ltc4150_get_total_mAh() { return coulomb_to_mA(int_to_coulomb(int_count)); } diff --git a/projects/default/Jamfile b/projects/default/Jamfile index 476db1c00c..2820d752cf 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 auto_init ; +Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 auto_init ; UseModule default_project ; diff --git a/projects/default/main.c b/projects/default/main.c index 5480211801..959c694616 100644 --- a/projects/default/main.c +++ b/projects/default/main.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -22,11 +23,12 @@ void shell_putchar(int c) { int main(void) { posix_open(uart0_handler_pid, 0); + ltc4150_start(); puts("Welcome to ukleos!"); shell_t shell; - shell_init(&shell, _shell_command_list, shell_readc, shell_putchar); + shell_init(&shell, NULL, shell_readc, shell_putchar); shell_run(&shell); diff --git a/sys/shell/Jamfile b/sys/shell/Jamfile index a17b4173df..e6ae372ebb 100644 --- a/sys/shell/Jamfile +++ b/sys/shell/Jamfile @@ -28,7 +28,7 @@ SubDir TOP sys shell ; Module shell : shell.c ; -Module shell_commands : shell_commands.c rtc.c sht11.c : shell ; +Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c : shell ; Module ps : ps.c ; diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 2e17a900b9..37ad42892c 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -51,15 +51,16 @@ and the mailinglist (subscription via web site) static void(*find_handler(const shell_command_t *command_list, char *command))(char*) { const shell_command_t* entry = command_list; - - while (entry->name != NULL) { - if ( strcmp(entry->name, command) == 0) { - return entry->handler; - } else { - entry++; - } - } - + if (entry) { + while (entry->name != NULL) { + if ( strcmp(entry->name, command) == 0) { + return entry->handler; + } else { + entry++; + } + } + } + #ifdef MODULE_SHELL_COMMANDS entry = _shell_command_list; while (entry->name != NULL) { @@ -79,10 +80,12 @@ static void print_help(const shell_command_t *command_list) { printf("%-20s %s\n", "Command", "Description"); puts("---------------------------------------"); - while (entry->name != NULL) { - printf("%-20s %s\n", entry->name, entry->desc); - entry++; - } + if (entry) { + while (entry->name != NULL) { + printf("%-20s %s\n", entry->name, entry->desc); + entry++; + } + } #ifdef MODULE_SHELL_COMMANDS entry = _shell_command_list; diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index e337db6f80..bc68b612fc 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -15,6 +15,11 @@ extern void _get_humidity_handler(char* unused); extern void _get_weather_handler(char* unused); #endif +#ifdef MODULE_LTC4150 +extern void _get_current_handler(char* unused); +extern void _reset_current_handler(char* unused); +#endif + const shell_command_t _shell_command_list[] = { #ifdef MODULE_PS {"ps", "Prints information about running threads.", _ps_handler}, @@ -23,9 +28,13 @@ const shell_command_t _shell_command_list[] = { {"date", "Geets or gets current date and time.", _date_handler}, #endif #ifdef MODULE_SHT11 - {"gettemp", "Prints measured temperature.", _get_temperature_handler}, - {"gethum", "Prints measured humidity.", _get_humidity_handler}, - {"getweather", "Prints measured humidity and temperature.", _get_weather_handler}, + {"temp", "Prints measured temperature.", _get_temperature_handler}, + {"hum", "Prints measured humidity.", _get_humidity_handler}, + {"weather", "Prints measured humidity and temperature.", _get_weather_handler}, +#endif +#ifdef MODULE_LTC4150 + {"cur", "Prints current and average power consumption.", _get_current_handler}, + {"rstcur", "Resets coulomb counter.", _reset_current_handler}, #endif {NULL, NULL, NULL} }; diff --git a/tools/pyterm/pyterm.py b/tools/pyterm/pyterm.py index 1bda7ddd2a..0bfa5106c9 100755 --- a/tools/pyterm/pyterm.py +++ b/tools/pyterm/pyterm.py @@ -10,19 +10,15 @@ class MyCmd(cmd.Cmd): self.stdout.write(line + "\n") def do_help(self, line): - self.stdout.write(line + "\n") + self.stdout.write("help\n") def complete_date(self, text, line, begidx, endidx): date = datetime.now().strftime("%Y-%M-%d %H:%m:%S") - return ["date %s\n" % date] + return ["%s\n" % date] def do_exit(self, line): sys.exit(0) -def sender(ser): - time.sleep(5) - ser.write("ps\n") - def reader(ser): while (1): c = ser.read(1) @@ -46,9 +42,6 @@ if __name__ == "__main__": receiver_thread.setDaemon(1) receiver_thread.start() - sender_thread = threading.Thread(target=sender, args=(ser,)) - sender_thread.start() - myshell = MyCmd(stdout=ser) myshell.prompt = "" From 9916bd33aa6d770f1376c2970f93d00445ab496f Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 5 Nov 2010 23:44:12 +0100 Subject: [PATCH 070/115] * missing ltc4150 shell command handler file --- sys/shell/ltc4150.c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 sys/shell/ltc4150.c diff --git a/sys/shell/ltc4150.c b/sys/shell/ltc4150.c new file mode 100644 index 0000000000..707878ee43 --- /dev/null +++ b/sys/shell/ltc4150.c @@ -0,0 +1,10 @@ +#include +#include + +void _get_current_handler(char* unused) { + printf("Power usage: %.4f mA (%.4f mA avg/ %.4f mAh total)\n", ltc4150_get_current_mA(), ltc4150_get_avg_mA(), ltc4150_get_total_mAh()); +} + +void _reset_current_handler(char* unused) { + ltc4150_start(); +} From 88c0ec84ee2d34283995863c00f00ab92ba5079b Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 7 Nov 2010 23:18:41 +0100 Subject: [PATCH 071/115] * added set offset shell command for sht11 * introduced command separator for pyterm * some cosmetics --- core/kernel_init.c | 20 ++++++++++---------- cpu/lpc2387/include/lpc2387.h | 4 ++-- cpu/lpc2387/lpc2387-lpm.c | 20 ++++++-------------- sys/shell/shell_commands.c | 2 ++ sys/shell/sht11.c | 12 ++++++++++++ tools/pyterm/pyterm.py | 3 ++- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/core/kernel_init.c b/core/kernel_init.c index a52597c111..b38d5a9662 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -17,22 +17,22 @@ #include #include #include -#include "tcb.h" -#include "kernel.h" -#include "kernel_intern.h" -#include "sched.h" -#include "flags.h" -#include "cpu.h" -#include "lpm.h" -#include "thread.h" -#include "hwtimer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef MODULE_AUTO_INIT #include #endif #define ENABLE_DEBUG -#include "debug.h" +#include volatile tcb *sched_threads[MAXTHREADS]; volatile tcb *active_thread; diff --git a/cpu/lpc2387/include/lpc2387.h b/cpu/lpc2387/include/lpc2387.h index d70853a775..98e7d2d695 100644 --- a/cpu/lpc2387/include/lpc2387.h +++ b/cpu/lpc2387/include/lpc2387.h @@ -9,8 +9,8 @@ #ifndef __LPC2387_H #define __LPC2387_H -#include "lpc23xx.h" -#include "bitarithm.h" +#include +#include #define F_CCO 288000000 #define CL_CPU_DIV 4 ///< CPU clock divider diff --git a/cpu/lpc2387/lpc2387-lpm.c b/cpu/lpc2387/lpc2387-lpm.c index d36829b1cf..7cdb23d07e 100644 --- a/cpu/lpc2387/lpc2387-lpm.c +++ b/cpu/lpc2387/lpc2387-lpm.c @@ -55,22 +55,14 @@ static enum lpm_mode lpm; extern void init_clks1(void); extern void init_clks2(void); -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif +#define ENABLE_DEBUG 1 +#include - -void -lpm_init(void) -{ +void lpm_init(void) { lpm = LPM_ON; } -#define LPM_DEBUG 0 +#define LPM_DEBUG 1 void lpm_begin_awake(void) { if (lpm >= LPM_SLEEP ) { // wake up from deep sleep @@ -118,8 +110,8 @@ enum lpm_mode lpm_set(enum lpm_mode target) { lpm = target; - #if DEBUG - PRINTF("# LPM power down %u -> %u", lpm, target); + #if iENABLE_DEBUG + DEBUG("# LPM power down %u -> %u", lpm, target); #endif PCON |= target_flags; // set target power mode diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index bc68b612fc..123f0f4f09 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -13,6 +13,7 @@ extern void _date_handler(char* now); extern void _get_temperature_handler(char* unused); extern void _get_humidity_handler(char* unused); extern void _get_weather_handler(char* unused); +extern void _set_offset_handler(char* offset); #endif #ifdef MODULE_LTC4150 @@ -31,6 +32,7 @@ const shell_command_t _shell_command_list[] = { {"temp", "Prints measured temperature.", _get_temperature_handler}, {"hum", "Prints measured humidity.", _get_humidity_handler}, {"weather", "Prints measured humidity and temperature.", _get_weather_handler}, + {"offset", "Set temperature offset.", _set_offset_handler}, #endif #ifdef MODULE_LTC4150 {"cur", "Prints current and average power consumption.", _get_current_handler}, diff --git a/sys/shell/sht11.c b/sys/shell/sht11.c index b24c8db936..e008444538 100644 --- a/sys/shell/sht11.c +++ b/sys/shell/sht11.c @@ -1,6 +1,9 @@ #include #include #include +#include + +extern float sht11_temperature_offset; void _get_humidity_handler(char* unused) { uint8_t success; @@ -39,3 +42,12 @@ void _get_weather_handler(char* unused) { } } +void _set_offset_handler(char* offset) { + if (strlen(offset) == 6) { + puts("Usage: offset "); + } + else { + sscanf(offset, "offset %f", &sht11_temperature_offset); + printf("Temperature offset set to %f\n", sht11_temperature_offset); + } +} diff --git a/tools/pyterm/pyterm.py b/tools/pyterm/pyterm.py index 0bfa5106c9..9c6858377a 100755 --- a/tools/pyterm/pyterm.py +++ b/tools/pyterm/pyterm.py @@ -7,7 +7,8 @@ from datetime import datetime class MyCmd(cmd.Cmd): def default(self, line): - self.stdout.write(line + "\n") + for tok in line.split(';'): + self.stdout.write(tok.strip() + "\n") def do_help(self, line): self.stdout.write("help\n") From 33a7e40c18aef7cee6037d4effdb2450a57fc934 Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 7 Nov 2010 23:36:18 +0100 Subject: [PATCH 072/115] * fixed bug in date command completion --- 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 9c6858377a..c1ab1dc6a8 100755 --- a/tools/pyterm/pyterm.py +++ b/tools/pyterm/pyterm.py @@ -13,8 +13,8 @@ class MyCmd(cmd.Cmd): def do_help(self, line): self.stdout.write("help\n") - def complete_date(self, text, line, begidx, endidx): - date = datetime.now().strftime("%Y-%M-%d %H:%m:%S") + def complete_date(self, text, line, begidx, endidm): + date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") return ["%s\n" % date] def do_exit(self, line): From be102b6a7d48c50e2587e6463eb0ab2ae9064f38 Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 8 Nov 2010 01:23:04 +0100 Subject: [PATCH 073/115] * added reset command to pyterm --- tools/pyterm/pyterm.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/pyterm/pyterm.py b/tools/pyterm/pyterm.py index c1ab1dc6a8..0f9cb09a79 100755 --- a/tools/pyterm/pyterm.py +++ b/tools/pyterm/pyterm.py @@ -15,7 +15,13 @@ class MyCmd(cmd.Cmd): def complete_date(self, text, line, begidx, endidm): date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - return ["%s\n" % date] + return ["%s" % date] + + def do_reset(self, line): + ser.setDTR(1) + ser.setRTS(1) + ser.setDTR(0) + ser.setRTS(0) def do_exit(self, line): sys.exit(0) From cfad56430d45dad01f9b637931bac06c3b0fd7ba Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 8 Nov 2010 18:21:02 +0100 Subject: [PATCH 074/115] * changed swtime from 64 to 32 bit --- sys/include/swtimer.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sys/include/swtimer.h b/sys/include/swtimer.h index 0cc30f82c0..14835348df 100644 --- a/sys/include/swtimer.h +++ b/sys/include/swtimer.h @@ -28,11 +28,7 @@ #undef wakeup -#if WORDSIZE == 32 -typedef uint64_t swtime_t; -#else typedef uint32_t swtime_t; -#endif /** * A swtimer. From 3b9e9befa980e3dfa45382fc039acf23315c6a55 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 8 Nov 2010 21:39:30 +0100 Subject: [PATCH 075/115] * some cosmetics and lpm flags for UART --- board/msba2/drivers/msba2-uart0.c | 3 +++ core/include/kernel.h | 1 + cpu/lpc2387/lpc2387-lpm.c | 4 ++-- cpu/lpc2387/lpc2387-rtc.c | 16 +++++----------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/board/msba2/drivers/msba2-uart0.c b/board/msba2/drivers/msba2-uart0.c index 8ff7e11e37..3107e8d40c 100644 --- a/board/msba2/drivers/msba2-uart0.c +++ b/board/msba2/drivers/msba2-uart0.c @@ -35,6 +35,7 @@ and the mailinglist (subscription via web site) #include #include "lpc23xx.h" #include "VIC.h" +#include #include @@ -78,12 +79,14 @@ static inline void dequeue(void) { static void push_queue(void) { running = 1; + lpm_prevent_sleep |= LPM_PREVENT_SLEEP_UART; start: if (!actual) { if (queue_items) { dequeue(); } else { running = 0; + lpm_prevent_sleep &= ~LPM_PREVENT_SLEEP_UART; if (!fifo) while(!(U0LSR & BIT6)){}; return; diff --git a/core/include/kernel.h b/core/include/kernel.h index 081ced085e..7aeac5ada1 100644 --- a/core/include/kernel.h +++ b/core/include/kernel.h @@ -80,6 +80,7 @@ */ int inISR(void); +#define LPM_PREVENT_SLEEP_UART BIT2 #define LPM_PREVENT_SLEEP_HWTIMER BIT1 extern volatile int lpm_prevent_sleep; diff --git a/cpu/lpc2387/lpc2387-lpm.c b/cpu/lpc2387/lpc2387-lpm.c index 7cdb23d07e..ff83433e3c 100644 --- a/cpu/lpc2387/lpc2387-lpm.c +++ b/cpu/lpc2387/lpc2387-lpm.c @@ -55,7 +55,7 @@ static enum lpm_mode lpm; extern void init_clks1(void); extern void init_clks2(void); -#define ENABLE_DEBUG 1 +#define ENABLE_DEBUG 0 #include void lpm_init(void) { @@ -88,7 +88,7 @@ void lpm_awake(void) { // Debug tests #if LPM_DEBUG usec = RTC_CTC-usec; - printf("Wakeup in %lu usecs\n",usec * 31); + DEBUG("Wakeup in %lu usecs\n",usec * 31); #endif } lpm = LPM_ON; diff --git a/cpu/lpc2387/lpc2387-rtc.c b/cpu/lpc2387/lpc2387-rtc.c index 4c896c47d2..4642042a6b 100644 --- a/cpu/lpc2387/lpc2387-rtc.c +++ b/cpu/lpc2387/lpc2387-rtc.c @@ -49,14 +49,8 @@ and the mailinglist (subscription via web site) #define PREINT_RTC 0x000001C8 /* Prescaler value, integer portion, PCLK = 15Mhz */ #define PREFRAC_RTC 0x000061C0 /* Prescaler value, fraction portion, PCLK = 15Mhz */ -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(fmt, args...) printf("rtc: " fmt "\n", ##args) -#else -#define PRINTF(fmt, args...) -#endif - +#define ENABLE_DEBUG 0 +#include /** * @brief epoch time in hour granularity @@ -112,7 +106,7 @@ rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask) RTC_ALMON = localt->tm_mon + 1; RTC_ALYEAR = localt->tm_year; RTC_AMR = ~mask; // set wich alarm fields to check - PRINTF("alarm set %2lu.%2lu.%4lu %2lu:%2lu:%2lu", + DEBUG("alarm set %2lu.%2lu.%4lu %2lu:%2lu:%2lu\n", RTC_ALDOM, RTC_ALMON, RTC_ALYEAR, RTC_ALHOUR, RTC_ALMIN, RTC_ALSEC); } else { RTC_AMR = 0xff; @@ -151,7 +145,7 @@ void RTC_IRQHandler (void) } else if( RTC_ILR & ILR_RTCALF ) { RTC_ILR |= ILR_RTCALF; RTC_AMR = 0xff; // disable alarm irq - PRINTF("alarm"); + DEBUG("Ring\n"); lpm_end_awake(); } @@ -186,7 +180,7 @@ void rtc_init(void) rtc_reset(); } - PRINTF("%2lu.%2lu.%4lu %2lu:%2lu:%2lu epoch %lu", + DEBUG("%2lu.%2lu.%4lu %2lu:%2lu:%2lu epoch %lu\n", RTC_DOM, RTC_MONTH, RTC_YEAR, RTC_HOUR, RTC_MIN, RTC_SEC, epoch); } From b1c61e446f0ddf056392afe47d9870c76b365b84 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 9 Nov 2010 16:59:55 +0100 Subject: [PATCH 076/115] * misc fixes --- drivers/cc110x/cc1100_phy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 4723bfa172..441b7d6a28 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -60,7 +60,7 @@ and the mailinglist (subscription via web site) #include "msg.h" #include "debug.h" -#define PRIORITY_CC1100 PRIORITY_MIN-9 +#define PRIORITY_CC1100 PRIORITY_MAIN-1 #define MSG_POLL 12346 @@ -97,7 +97,7 @@ static const char *cc1100_event_handler_name = "cc1100_event_handler"; static mutex_t cc1100_mutex; volatile int cc1100_mutex_pid; static swtimer_t cc1100_watch_dog; -static uint64_t cc1100_watch_dog_period = 0; +static swtime_t cc1100_watch_dog_period = 0; static uint16_t cc1100_event_handler_pid; static void cc1100_event_handler_function(void); From 9122445c27e909c488bb1c7f03f2d3c5074ce9ab Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 9 Nov 2010 17:01:52 +0100 Subject: [PATCH 077/115] * align tcb on 32bit boundary --- core/thread.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/thread.c b/core/thread.c index 31fcde282e..d9a922aec9 100644 --- a/core/thread.c +++ b/core/thread.c @@ -84,7 +84,18 @@ 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); - tcb *cb = (tcb*) (stack + stacksize); + + /* align tcb address on 32bit boundary */ + unsigned int tcb_address = (unsigned int) stack + stacksize; + if ( tcb_address & 1 ) { + tcb_address--; + stacksize--; + } + if ( tcb_address & 2 ) { + tcb_address-=2; + stacksize-=2; + } + tcb *cb = (tcb*) tcb_address; if (priority >= SCHED_PRIO_LEVELS) { return -EINVAL; From 5df2aa6fb78a834396ce37da791e2e68b0db6d0d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 9 Nov 2010 17:08:35 +0100 Subject: [PATCH 078/115] * added initial cc1100 shell commands --- projects/default/Jamfile | 2 +- sys/shell/Jamfile | 2 +- sys/shell/shell_commands.c | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/projects/default/Jamfile b/projects/default/Jamfile index 2820d752cf..2c8d376edc 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 auto_init ; +Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 cc110x auto_init ; UseModule default_project ; diff --git a/sys/shell/Jamfile b/sys/shell/Jamfile index e6ae372ebb..cc0eec2e45 100644 --- a/sys/shell/Jamfile +++ b/sys/shell/Jamfile @@ -28,7 +28,7 @@ SubDir TOP sys shell ; Module shell : shell.c ; -Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c : shell ; +Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c cc1100.c : shell ; Module ps : ps.c ; diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index 123f0f4f09..41f152ce99 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -21,6 +21,11 @@ extern void _get_current_handler(char* unused); extern void _reset_current_handler(char* unused); #endif +#ifdef MODULE_CC110X +extern void _cc1100_get_address_handler(char *unused); +extern void _cc1100_set_address_handler(char *ptr); +#endif + const shell_command_t _shell_command_list[] = { #ifdef MODULE_PS {"ps", "Prints information about running threads.", _ps_handler}, @@ -37,6 +42,10 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_LTC4150 {"cur", "Prints current and average power consumption.", _get_current_handler}, {"rstcur", "Resets coulomb counter.", _reset_current_handler}, +#endif +#ifdef MODULE_CC110X + {"cc1100_get_address", "", _cc1100_get_address_handler}, + {"cc1100_set_address", "", _cc1100_set_address_handler}, #endif {NULL, NULL, NULL} }; From 79d2902d2b7af129d551913600924893198fd3c0 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 9 Nov 2010 17:08:54 +0100 Subject: [PATCH 079/115] * added initial cc1100 shell commands --- sys/shell/cc1100.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 sys/shell/cc1100.c diff --git a/sys/shell/cc1100.c b/sys/shell/cc1100.c new file mode 100644 index 0000000000..4236f517da --- /dev/null +++ b/sys/shell/cc1100.c @@ -0,0 +1,24 @@ +#include +#include + +void _cc1100_get_address_handler(char *str) { + radio_address_t addr = cc1100_get_address(); + printf("cc1100 address: %i\n", addr); +} + +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) { + puts("OK"); + } else { + puts("Error!"); + } + } else { + puts("usage: cc1100_set_address
"); + } +} + From 21fef20ccc09a2a736129f037b02a944afc26d16 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 9 Nov 2010 18:47:19 +0100 Subject: [PATCH 080/115] * added configuration file * added history * added aliases --- tools/pyterm/pyterm.py | 118 ++++++++++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 26 deletions(-) diff --git a/tools/pyterm/pyterm.py b/tools/pyterm/pyterm.py index 0f9cb09a79..342e2bacb4 100755 --- a/tools/pyterm/pyterm.py +++ b/tools/pyterm/pyterm.py @@ -1,31 +1,108 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -import cmd, serial, sys, threading, readline, time +import cmd, serial, sys, threading, readline, time, ConfigParser from datetime import datetime +from os import path -class MyCmd(cmd.Cmd): +class SerCmd(cmd.Cmd): + + def __init__(self, port=None): + cmd.Cmd.__init__(self) + self.port = port + self.aliases = dict() + self.load_config() + try: + readline.read_history_file() + except IOError: + pass + + def preloop(self): + if not self.port: + 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) + + # start serial->console thread + receiver_thread = threading.Thread(target=reader, args=(self.ser,)) + receiver_thread.setDaemon(1) + receiver_thread.start() def default(self, line): for tok in line.split(';'): - self.stdout.write(tok.strip() + "\n") + tok = self.get_alias(tok) + self.ser.write(tok.strip() + "\n") def do_help(self, line): - self.stdout.write("help\n") + self.ser.write("help\n") def complete_date(self, text, line, begidx, endidm): date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") return ["%s" % date] def do_reset(self, line): - ser.setDTR(1) - ser.setRTS(1) - ser.setDTR(0) - ser.setRTS(0) + self.ser.setDTR(1) + self.ser.setRTS(1) + self.ser.setDTR(0) + self.ser.setRTS(0) def do_exit(self, line): + readline.write_history_file() sys.exit(0) + def do_save(self, line): + if not self.config.has_section("general"): + self.config.add_section("general") + self.config.set("general", "port", self.port) + if len(self.aliases): + if not self.config.has_section("aliases"): + self.config.add_section("aliases") + for alias in self.aliases: + self.config.set("aliases", alias, self.aliases[alias]) + + with open(path.expanduser('~/.pyterm'), 'wb') as config_fd: + self.config.write(config_fd) + print("Config saved") + + def do_show_config(self, line): + for key in self.__dict__: + print(str(key) + ": " + str(self.__dict__[key])) + + def do_alias(self, line): + if line.endswith("list"): + for alias in self.aliases: + print("%s = %s" % (alias, self.aliases[alias])) + return + if not line.count("="): + sys.stderr.write("Usage: alias = \n") + return + self.aliases[line.split('=')[0].strip()] = line.split('=')[1].strip() + + def do_rmalias(self, line): + if not self.aliases.pop(line, None): + sys.stderr.write("Alias not found") + + def get_alias(self, tok): + for alias in self.aliases: + if tok.split()[0] == alias: + return self.aliases[alias] + tok[len(alias):] + return tok + + def load_config(self): + self.config = ConfigParser.SafeConfigParser() + self.config.read([path.expanduser('~/.pyterm')]) + + for sec in self.config.sections(): + if sec == "aliases": + for opt in self.config.options(sec): + self.aliases[opt] = self.config.get(sec, opt) + else: + for opt in self.config.options(sec): + self.__dict__[opt] = self.config.get(sec, opt) + + def reader(ser): while (1): c = ser.read(1) @@ -33,23 +110,12 @@ def reader(ser): sys.stdout.flush() if __name__ == "__main__": - - if (len(sys.argv) != 2): - print("Usage: %s " % sys.argv[0]) - sys.exit(-1) + if (len(sys.argv) > 1): + port = sys.argv[1] + else: + port = None - p = sys.argv[1] - ser = serial.Serial(port=p, baudrate=115200, dsrdtr=0, rtscts=0) + myshell = SerCmd(port) + myshell.prompt = '' - ser.setDTR(0) - ser.setRTS(0) - - # start serial->console thread - receiver_thread = threading.Thread(target=reader, args=(ser,)) - receiver_thread.setDaemon(1) - receiver_thread.start() - - myshell = MyCmd(stdout=ser) - myshell.prompt = "" - - myshell.cmdloop("Opening port: %s" % sys.argv[1]) + myshell.cmdloop("Welcome to pyterm") From 75c0962363c8bdfb4444c5f8392c2a85bbd978d9 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 9 Nov 2010 18:48:45 +0100 Subject: [PATCH 081/115] * added get_interval function to ltc4150 * fixed date command (problem with leading zeros) --- drivers/include/ltc4150.h | 1 + drivers/ltc4150.c | 4 ++++ sys/shell/ltc4150.c | 2 +- sys/shell/rtc.c | 10 +++++----- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/include/ltc4150.h b/drivers/include/ltc4150.h index b024f4b5cd..88160c8913 100644 --- a/drivers/include/ltc4150.h +++ b/drivers/include/ltc4150.h @@ -10,5 +10,6 @@ void ltc4150_stop(); double ltc4150_get_current_mA(); double ltc4150_get_total_mAh(); double ltc4150_get_avg_mA(); +int ltc4150_get_interval(); #endif /* __LTC4150_H */ diff --git a/drivers/ltc4150.c b/drivers/ltc4150.c index 6c58b3d7d3..7c50553a85 100644 --- a/drivers/ltc4150.c +++ b/drivers/ltc4150.c @@ -70,6 +70,10 @@ double ltc4150_get_avg_mA() { return (int_to_coulomb(int_count)*1000000000)/HWTIMER_TICKS_TO_US(last_int_time - start_time); } +int ltc4150_get_interval() { + return HWTIMER_TICKS_TO_US(last_int_time - start_time); +} + unsigned long ltc4150_get_intcount() { return int_count; } diff --git a/sys/shell/ltc4150.c b/sys/shell/ltc4150.c index 707878ee43..91d557592a 100644 --- a/sys/shell/ltc4150.c +++ b/sys/shell/ltc4150.c @@ -2,7 +2,7 @@ #include void _get_current_handler(char* unused) { - printf("Power usage: %.4f mA (%.4f mA avg/ %.4f mAh total)\n", ltc4150_get_current_mA(), ltc4150_get_avg_mA(), ltc4150_get_total_mAh()); + printf("Power usage: %.4f mA (%.4f mA avg/ %.4f mAh total / %i sec)\n", ltc4150_get_current_mA(), ltc4150_get_avg_mA(), ltc4150_get_total_mAh(), ltc4150_get_interval()); } void _reset_current_handler(char* unused) { diff --git a/sys/shell/rtc.c b/sys/shell/rtc.c index 44c58a65a7..25f99c089e 100644 --- a/sys/shell/rtc.c +++ b/sys/shell/rtc.c @@ -16,13 +16,13 @@ void _settime_handler(char* c) { int res; uint16_t month, epoch_year; - res = sscanf(c, "date %hu-%hu-%i %i:%i:%i", + res = sscanf(c, "date %hu-%hu-%u %u:%u:%u", &epoch_year, &month, - &(now.tm_mday), - &(now.tm_hour), - &(now.tm_min), - &(now.tm_sec)); + (unsigned int*) &(now.tm_mday), + (unsigned int*) &(now.tm_hour), + (unsigned int*) &(now.tm_min), + (unsigned int*) &(now.tm_sec)); if (res < 6) { printf("Usage: date YYYY-MM-DD hh:mm:ss\n"); From fb784c6628cf03d5ba37785ba68835773576e2d9 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 9 Nov 2010 18:51:04 +0100 Subject: [PATCH 082/115] * fixed units in ltc command --- sys/shell/ltc4150.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/shell/ltc4150.c b/sys/shell/ltc4150.c index 91d557592a..c29519c14c 100644 --- a/sys/shell/ltc4150.c +++ b/sys/shell/ltc4150.c @@ -2,7 +2,7 @@ #include void _get_current_handler(char* unused) { - printf("Power usage: %.4f mA (%.4f mA avg/ %.4f mAh total / %i sec)\n", ltc4150_get_current_mA(), ltc4150_get_avg_mA(), ltc4150_get_total_mAh(), ltc4150_get_interval()); + printf("Power usage: %.4f mA (%.4f mA avg/ %.4f mAh total / %i usec)\n", ltc4150_get_current_mA(), ltc4150_get_avg_mA(), ltc4150_get_total_mAh(), ltc4150_get_interval()); } void _reset_current_handler(char* unused) { From 8b242c74a800a1281466179ec8e682b13fff1178 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 11 Nov 2010 09:55:08 +0100 Subject: [PATCH 083/115] * mutex changes --- core/include/sched.h | 1 + core/mutex.c | 75 +++++++++++++------------------------------- core/sched.c | 10 ++++++ 3 files changed, 33 insertions(+), 53 deletions(-) diff --git a/core/include/sched.h b/core/include/sched.h index a506d3cc36..d31a83bc4d 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -25,6 +25,7 @@ void sched_init(); void sched_run(); void sched_set_status(tcb *process, unsigned int status); +void sched_switch_if_higher(uint16_t current_prio, uint16_t other_prio, int in_isr); volatile unsigned int sched_context_switch_request; diff --git a/core/mutex.c b/core/mutex.c index affc7cb622..c65946755c 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -20,6 +20,7 @@ #include "tcb.h" #include "kernel.h" #include "sched.h" +#include //#define ENABLE_DEBUG #include @@ -36,48 +37,31 @@ int mutex_init(struct mutex_t* mutex) { int mutex_trylock(struct mutex_t* mutex) { DEBUG("%s: trylocking to get mutex. val: %u\n", active_thread->name, mutex->val); - return (atomic_set_return(&mutex->val, thread_pid ) == 0); + return atomic_set_return(&mutex->val, 1 ) == 0; } -int prio() { +static int prio() { return active_thread->priority; } int mutex_lock(struct mutex_t* mutex) { DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val); - if (atomic_set_return(&mutex->val,thread_pid) != 0) { + if (atomic_set_return(&mutex->val,1) != 0) { // mutex was locked. mutex_wait(mutex); } return 1; } -void mutex_unlock(struct mutex_t* mutex, int yield) { - DEBUG("%s: unlocking mutex. val: %u pid: %u\n", active_thread->name, mutex->val, thread_pid); - int me_value; - - if (inISR()) { - me_value = 0; - yield = MUTEX_INISR; - } else { - me_value = thread_pid; - } - - if (atomic_set_return(&mutex->val,0) != me_value ) { - // there were waiters. - mutex_wake_waiters(mutex, yield); - } -} - void mutex_wait(struct mutex_t *mutex) { - dINT(); + int irqstate = disableIRQ(); DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val); if (mutex->val == 0) { // somebody released the mutex. return. mutex->val = thread_pid; DEBUG("%s: mutex_wait early out. %u\n", active_thread->name, mutex->val); - eINT(); + restoreIRQ(irqstate); return; } @@ -92,45 +76,30 @@ void mutex_wait(struct mutex_t *mutex) { queue_priority_add(&(mutex->queue), &n); - eINT(); + restoreIRQ(irqstate); thread_yield(); /* we were woken up by scheduler. waker removed us from queue. we have the mutex now. */ } -void mutex_wake_waiters(struct mutex_t *mutex, int flags) { - if ( ! (flags & MUTEX_INISR)) dINT(); - DEBUG("%s: waking up waiters.\n", active_thread->name); +void mutex_unlock(struct mutex_t* mutex, int yield) { + DEBUG("%s: unlocking mutex. val: %u pid: %u\n", active_thread->name, mutex->val, thread_pid); + int irqstate = disableIRQ(); + + if (mutex->val != 0) { + if (mutex->queue.next) { + queue_node_t *next = queue_remove_head(&(mutex->queue)); + tcb* process = (tcb*)next->data; + DEBUG("%s: waking up waiter %s.\n", process->name); + sched_set_status(process, STATUS_PENDING); - queue_node_t *next = queue_remove_head(&(mutex->queue)); - - /* queue is empty */ - if (!next) { - DEBUG("%s: no waiters?\n", active_thread->name); - mutex->val = 0; - if ( ! (flags & MUTEX_INISR)) eINT(); - return; + sched_switch_if_higher(active_thread->priority, process->priority, inISR()); + } else { + mutex->val = 0; + } } - tcb* process = (tcb*)next->data; - - sched_set_status(process, STATUS_PENDING); - - if ( mutex->queue.next != NULL) { - mutex->val = -1; - } else { - mutex->val = process->pid; - } - - DEBUG("%s: waiters woken up.\n", active_thread->name); - - /* If called from process, reenable interrupts, yield if requested */ - if (! (flags & MUTEX_INISR)) { - eINT(); - if (flags & MUTEX_YIELD) thread_yield(); - } else { - sched_context_switch_request = 1; - } + restoreIRQ(irqstate); } diff --git a/core/sched.c b/core/sched.c index bd8728fbe3..f2fa2ff416 100644 --- a/core/sched.c +++ b/core/sched.c @@ -143,6 +143,16 @@ void sched_set_status(tcb *process, unsigned int status) { process->status = status; } +void sched_switch_if_higher(uint16_t current_prio, uint16_t other_prio, int in_isr) { + if (current_prio < other_prio) { + if (in_isr) { + sched_context_switch_request = 1; + } else { + thread_yield(); + } + } +} + extern void cpu_switch_context_exit(void); void sched_task_exit(void) { From dad5bf866c6018bd45e637f923f5eebf656446ce Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 11 Nov 2010 09:57:54 +0100 Subject: [PATCH 084/115] * removed unused prio function --- core/mutex.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/mutex.c b/core/mutex.c index c65946755c..9c1c17c83d 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -40,10 +40,6 @@ int mutex_trylock(struct mutex_t* mutex) { return atomic_set_return(&mutex->val, 1 ) == 0; } -static int prio() { - return active_thread->priority; -} - int mutex_lock(struct mutex_t* mutex) { DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val); From 21e6aaff24aaa89b34d87f79db36867badcb7ebb Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 11 Nov 2010 11:21:58 +0100 Subject: [PATCH 085/115] * fix priority queue insert --- core/queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/queue.c b/core/queue.c index edb9927f7f..bfc50b4ce0 100644 --- a/core/queue.c +++ b/core/queue.c @@ -56,7 +56,7 @@ void queue_priority_add(queue_node_t* root, queue_node_t* new_obj) { queue_node_t* node = root; while (node->next != NULL) { - if (node->next->priority < new_obj->priority) { + if (node->next->priority > new_obj->priority) { new_obj->next = node->next; node->next = new_obj; return; From 0441c5a4a4397d96373e103c6cd7c839f67eb164 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 11 Nov 2010 11:22:45 +0100 Subject: [PATCH 086/115] * some more mutex related changes --- core/include/sched.h | 2 +- core/mutex.c | 4 ++-- core/sched.c | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/include/sched.h b/core/include/sched.h index d31a83bc4d..ad30cfb601 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -25,7 +25,7 @@ void sched_init(); void sched_run(); void sched_set_status(tcb *process, unsigned int status); -void sched_switch_if_higher(uint16_t current_prio, uint16_t other_prio, int in_isr); +void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr); volatile unsigned int sched_context_switch_request; diff --git a/core/mutex.c b/core/mutex.c index 9c1c17c83d..fd4b708a3e 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -68,7 +68,7 @@ void mutex_wait(struct mutex_t *mutex) { n.data = (unsigned int) active_thread; n.next = NULL; - DEBUG("%s: Adding node to mutex queue: prio: %u data: %u\n", active_thread->name, n.priority, n.data); + DEBUG("%s: Adding node to mutex queue: prio: %u\n", active_thread->name, n.priority); queue_priority_add(&(mutex->queue), &n); @@ -90,7 +90,7 @@ void mutex_unlock(struct mutex_t* mutex, int yield) { DEBUG("%s: waking up waiter %s.\n", process->name); sched_set_status(process, STATUS_PENDING); - sched_switch_if_higher(active_thread->priority, process->priority, inISR()); + sched_switch(active_thread->priority, process->priority, inISR()); } else { mutex->val = 0; } diff --git a/core/sched.c b/core/sched.c index f2fa2ff416..0563e46f4f 100644 --- a/core/sched.c +++ b/core/sched.c @@ -143,8 +143,9 @@ void sched_set_status(tcb *process, unsigned int status) { process->status = status; } -void sched_switch_if_higher(uint16_t current_prio, uint16_t other_prio, int in_isr) { - if (current_prio < other_prio) { +void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr) { + DEBUG("%s: %i %i %i\n", active_thread->name, (int)current_prio, (int)other_prio, in_isr); + if (current_prio <= other_prio) { if (in_isr) { sched_context_switch_request = 1; } else { From 440c6fac8d9769aae5ea2a56d4888e1af944bbc6 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 18 Nov 2010 16:16:57 +0100 Subject: [PATCH 087/115] * removed unnecessary sleep --- board/msba2/tools/src/lpc2k_pgm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/board/msba2/tools/src/lpc2k_pgm.c b/board/msba2/tools/src/lpc2k_pgm.c index 153fa9b425..4891c55946 100644 --- a/board/msba2/tools/src/lpc2k_pgm.c +++ b/board/msba2/tools/src/lpc2k_pgm.c @@ -78,8 +78,6 @@ int main(int argc, char **argv) char* port_name = argv[1]; char* file_name = argv[2]; - sleep(1); - if (open_serial_port(port_name) < 0) { return(1); } From 17e41bae1372b390ece30c86301b33c9cdaab8f3 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 18 Nov 2010 16:47:04 +0100 Subject: [PATCH 088/115] * added LaSeR project --- projects/laser/Jamfile | 5 +++++ projects/laser/main.c | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 projects/laser/Jamfile create mode 100644 projects/laser/main.c diff --git a/projects/laser/Jamfile b/projects/laser/Jamfile new file mode 100644 index 0000000000..562d4305a7 --- /dev/null +++ b/projects/laser/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects laser ; + +Module laser : main.c : sht11 swtimer auto_init ; + +UseModule laser ; diff --git a/projects/laser/main.c b/projects/laser/main.c new file mode 100644 index 0000000000..7a5c0a1872 --- /dev/null +++ b/projects/laser/main.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +int main(void) +{ + sht11_val_t sht11_val; + uint8_t success = 0; + + puts(""); + puts("LaSeR: Longterm Sensor Reader initialized."); + puts("Printing \"temperature in °C;relative humidity;temperature compensated relative humidity\"."); + puts(""); + + while (1) { + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + if (!success) { + printf("error;error;error\n"); + } + else { + printf("%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp); + } + LED_RED_TOGGLE; + swtimer_usleep(1000 * 1000); + } +} From ee4b68371c5be403c484a9124d7ff1583401e5fb Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 18 Nov 2010 17:33:25 +0100 Subject: [PATCH 089/115] * added readc and putc to uart0 library * allow overwrote of port by argument for pyterm --- sys/include/board_uart0.h | 7 +++++-- sys/uart0.c | 17 ++++++++++++++--- tools/pyterm/pyterm.py | 7 ++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sys/include/board_uart0.h b/sys/include/board_uart0.h index 2819ef61b0..d38c22c75b 100644 --- a/sys/include/board_uart0.h +++ b/sys/include/board_uart0.h @@ -3,8 +3,11 @@ extern int uart0_handler_pid; -void board_uart0_init(); +void board_uart0_init(void); void uart0_handle_incoming(int c); -void uart0_notify_thread(); +void uart0_notify_thread(void); + +int uart0_readc(void); +void uart0_putc(int c); #endif /* __BOARD_UART0_H */ diff --git a/sys/uart0.c b/sys/uart0.c index 29ea4efa05..04182b082c 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -16,11 +17,11 @@ static char buffer[UART0_BUFSIZE]; static char uart0_thread_stack[UART0_STACKSIZE]; -static void uart0_loop() { +static void uart0_loop(void) { chardev_loop(&uart0_ringbuffer); } -void board_uart0_init() { +void board_uart0_init(void) { ringbuffer_init(&uart0_ringbuffer, buffer, UART0_BUFSIZE); int pid = thread_create(uart0_thread_stack, sizeof(uart0_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); uart0_handler_pid = pid; @@ -31,8 +32,18 @@ void uart0_handle_incoming(int c) { rb_add_element(&uart0_ringbuffer, c); } -void uart0_notify_thread() { +void uart0_notify_thread(void) { msg m; m.type = 0; msg_send_int(&m, uart0_handler_pid); } + +int uart0_readc(void) { + char c = 0; + posix_read(uart0_handler_pid, &c, 1); + return c; +} + +void uart0_putc(int c) { + putchar(c); +} diff --git a/tools/pyterm/pyterm.py b/tools/pyterm/pyterm.py index 342e2bacb4..59eadcfbd1 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,)) @@ -100,7 +100,8 @@ class SerCmd(cmd.Cmd): self.aliases[opt] = self.config.get(sec, opt) else: for opt in self.config.options(sec): - self.__dict__[opt] = self.config.get(sec, opt) + if not self.__dict__.has_key(opt): + self.__dict__[opt] = self.config.get(sec, opt) def reader(ser): From 2b498020b19cd7cc52ef10f362f1013938dcdf4b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 18 Nov 2010 20:04:38 +0100 Subject: [PATCH 090/115] * introduced a prelimary version for the new cc1100 driver --- drivers/Jamfile | 1 + drivers/cc110x_ng/Jamfile | 33 +++ drivers/cc110x_ng/cc1100-arch.h | 50 ++++ drivers/cc110x_ng/cc1100-config.h | 94 ++++++++ drivers/cc110x_ng/cc1100-defaultSettings.c | 155 ++++++++++++ drivers/cc110x_ng/cc1100-defaultSettings.h | 110 +++++++++ drivers/cc110x_ng/cc1100-internal.h | 218 +++++++++++++++++ drivers/cc110x_ng/cc1100.c | 260 +++++++++++++++++++++ drivers/cc110x_ng/cc1100.h | 82 +++++++ drivers/cc110x_ng/cc1100_spi.c | 128 ++++++++++ drivers/cc110x_ng/cc1100_spi.h | 64 +++++ 11 files changed, 1195 insertions(+) create mode 100755 drivers/cc110x_ng/Jamfile create mode 100644 drivers/cc110x_ng/cc1100-arch.h create mode 100644 drivers/cc110x_ng/cc1100-config.h create mode 100644 drivers/cc110x_ng/cc1100-defaultSettings.c create mode 100644 drivers/cc110x_ng/cc1100-defaultSettings.h create mode 100644 drivers/cc110x_ng/cc1100-internal.h create mode 100644 drivers/cc110x_ng/cc1100.c create mode 100644 drivers/cc110x_ng/cc1100.h create mode 100644 drivers/cc110x_ng/cc1100_spi.c create mode 100644 drivers/cc110x_ng/cc1100_spi.h diff --git a/drivers/Jamfile b/drivers/Jamfile index e0223c05a1..9713df17fd 100644 --- a/drivers/Jamfile +++ b/drivers/Jamfile @@ -32,3 +32,4 @@ Module sht11 : sht11.c : hwtimer ; Module ltc4150 : ltc4150.c : board_ltc4150 ; SubInclude TOP drivers cc110x ; +SubInclude TOP drivers cc110x_ng ; diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile new file mode 100755 index 0000000000..93d557720e --- /dev/null +++ b/drivers/cc110x_ng/Jamfile @@ -0,0 +1,33 @@ +# ****************************************************************************** +# Copyright 2010, Freie Universitaet 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 +# ****************************************************************************** +# $Id: Jamfile 832 2009-03-13 16:45:41Z kaspar $ + +SubDir TOP drivers cc110x_ng ; + +HDRS += $(TOP)/drivers/cc110x_ng ; + +Module cc110x_ng : cc1100.c cc1100-defaultSettings.c cc1100_spi.c : board_cc1100 swtimer gpioint ; + diff --git a/drivers/cc110x_ng/cc1100-arch.h b/drivers/cc110x_ng/cc1100-arch.h new file mode 100644 index 0000000000..ef61dd61c9 --- /dev/null +++ b/drivers/cc110x_ng/cc1100-arch.h @@ -0,0 +1,50 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet 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 FeuerWare. + +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 +*******************************************************************************/ + +/** + * @file + * @ingroup LPC2387 + * @brief CC1100 LPC2387 dependend functions + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @version $Revision: 1775 $ + * + * @note $Id: arch_cc1100.h 1775 2010-01-26 09:37:03Z hillebra $ + */ + +#include + +uint8_t cc1100_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 cc1100_before_send(void); +void cc1100_after_send(void); diff --git a/drivers/cc110x_ng/cc1100-config.h b/drivers/cc110x_ng/cc1100-config.h new file mode 100644 index 0000000000..e7e039d882 --- /dev/null +++ b/drivers/cc110x_ng/cc1100-config.h @@ -0,0 +1,94 @@ +#ifndef CC1100_CONFIG_H +#define CC1100_CONFIG_H + +/** CC1100 register configuration */ +typedef struct { + uint8_t IOCFG2; + uint8_t IOCFG1; + uint8_t IOCFG0; + uint8_t FIFOTHR; + uint8_t SYNC1; + uint8_t SYNC0; + uint8_t PKTLEN; + uint8_t PKTCTRL1; + uint8_t PKTCTRL0; + uint8_t ADDR; + uint8_t CHANNR; + uint8_t FSCTRL1; + uint8_t FSCTRL0; + uint8_t FREQ2; + uint8_t FREQ1; + uint8_t FREQ0; + uint8_t MDMCFG4; + uint8_t MDMCFG3; + uint8_t MDMCFG2; + uint8_t MDMCFG1; + uint8_t MDMCFG0; + uint8_t DEVIATN; + uint8_t MCSM2; + uint8_t MCSM1; + uint8_t MCSM0; + uint8_t FOCCFG; + uint8_t BSCFG; + uint8_t AGCCTRL2; + uint8_t AGCCTRL1; + uint8_t AGCCTRL0; + uint8_t WOREVT1; + uint8_t WOREVT0; + uint8_t WORCTRL; + uint8_t FREND1; + uint8_t FREND0; + uint8_t FSCAL3; + uint8_t FSCAL2; + uint8_t FSCAL1; + uint8_t FSCAL0; +} cc1100_reg_t; + +/** CC1100 radio configuration */ +typedef struct { + cc1100_reg_t reg_cfg; ///< CC1100 register configuration + uint8_t pa_power; ///< Output power setting +} cc1100_cfg_t; + +/** + * @brief Radio Control Flags + */ +typedef struct +{ + uint32_t TOF; ///< Time of flight of the last packet and last ACK + uint32_t TCP; ///< Time to compute packet + unsigned RPS : 16; ///< Raw packets sent to transmit last packet + unsigned RTC : 8; ///< Retransmission count of last send packet + unsigned RSSI : 8; ///< The RSSI value of last received packet + unsigned RSSI_SEND : 8; ///< The RSSI value of the last send unicast packet of this node + unsigned LQI : 8; ///< The LQI value of the last received packet + unsigned LL_ACK : 1; ///< Is set if Link-Level ACK is received, otherwise 0 (reset on new burst) + unsigned CAA : 1; ///< The status of the air (1 = air free, 0 = air not free) + unsigned CRC : 1; ///< The CRC status of last received packet (1 = OK, 0 = not OK) + unsigned SEQ : 1; ///< Sequence number (toggles between 0 and 1) + unsigned MAN_WOR : 1; ///< Manual WOR set (for randomized WOR times => no synch) + unsigned KT_RES_ERR : 1; ///< A hwtimer resource error has occurred (no free timers available) + unsigned TX : 1; ///< State machine TX lock, only ACKs will be received + unsigned WOR_RST : 1; ///< Reset CC1100 real time clock (WOR) on next WOR strobe +} cc1100_flags; + +/** + * @brief Statistic interface for debugging + */ +typedef struct cc1100_statistic { + uint32_t packets_in; + uint32_t packets_in_crc_fail; + uint32_t packets_in_while_tx; + uint32_t packets_in_dups; + uint32_t packets_in_up; + uint32_t packets_out; + uint32_t packets_out_acked; + uint32_t packets_out_broadcast; + uint32_t raw_packets_out; + uint32_t raw_packets_out_acked; + uint32_t acks_send; + uint32_t rx_buffer_max; + uint32_t watch_dog_resets; +} cc1100_statistic_t; + +#endif diff --git a/drivers/cc110x_ng/cc1100-defaultSettings.c b/drivers/cc110x_ng/cc1100-defaultSettings.c new file mode 100644 index 0000000000..f19214914a --- /dev/null +++ b/drivers/cc110x_ng/cc1100-defaultSettings.c @@ -0,0 +1,155 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet 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 FeuerWare. + +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 +*******************************************************************************/ + +/** + * @ingroup dev_cc110x + * @{ + */ + +/** + * @file + * @brief TI Chipcon CC110x default settings + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Thomas Hillebrandt + * @author Heiko Will + * @version $Revision: 2058 $ + * + * @note $Id: cc1100-defaultSettings.c 2058 2010-03-31 08:59:31Z hillebra $ + */ + +#include + +/** + * Usable, non overlapping channels and corresponding frequencies + * for use with CC1100. CHANNR is the register for selecting a channel. + * + * channel number | CHANNR | frequency [MHz] + * ----------------------------------------- + * 0 | 0 | 869.525 + * 1 | 10 | 871.61 + * 2 | 20 | 873.58 ~ seems to be bad (hang-ups with this channel) + * 3 | 30 | 875.61 + * 4 | 40 | 877.58 + * 5 | 50 | 879.61 + * 6 | 60 | 881.58 + * 7 | 70 | 883.61 + * 8 | 80 | 885.58 + * 9 | 90 | 887.61 + * 10 | 100 | 889.58 + * 11 | 110 | 891.57 + * 12 | 120 | 893.58 + * 13 | 130 | 895.61 + * 14 | 140 | 897.58 + * 15 | 150 | 899.57 + * 16 | 160 | 901.57 + * 17 | 170 | 903.61 + * 18 | 180 | 905.57 + * 19 | 190 | 907.57 + * 20 | 200 | 909.57 + * 21 | 210 | 911.57 + * 22 | 220 | 913.57 + * 23 | 230 | 915.61 + * 24 | 240 | 917.61 + */ + +// 400 kbps, MSK, X-tal: 26 MHz (Chip Revision F) +char cc1100_conf[] = { + 0x06, // IOCFG2 + 0x2E, // IOCFG1 + 0x0E, // IOCFG0 + 0x0F, // FIFOTHR + 0x9B, // SYNC1 + 0xAD, // SYNC0 + 0x3D, // PKTLEN (maximum value of packet length byte = 61) + 0x06, // PKTCTRL1 + 0x45, // PKTCTRL0 (variable packet length) + 0xFF, // ADDR + CC1100_DEFAULT_CHANNR*10, // CHANNR + 0x0B, // FSCTRL1 + 0x00, // FSCTRL0 + 0x21, // FREQ2 + 0x71, // FREQ1 + 0x7A, // FREQ0 + 0x2D, // MDMCFG4 + 0xF8, // MDMCFG3 + 0x73, // MDMCFG2 + 0x42, // MDMCFG1 + 0xF8, // MDMCFG0 + 0x00, // DEVIATN + 0x07, // MCSM2 + 0x03, // MCSM1 + 0x18, // MCSM0 + 0x1D, // FOCCFG + 0x1C, // BSCFG + 0xC0, // AGCCTRL2 + 0x49, // AGCCTRL1, (old value was 0x49 -> made carrier sense less sensitive!) + // 0x47 - 7 dB above MAGN_TARGET setting + 0xB2, // AGCCTRL0 + 0x87, // WOREVT1 + 0x6B, // WOREVT0 + 0xF8, // WORCTRL + 0xB6, // FREND1 + 0x10, // FREND0 + 0xEA, // FSCAL3 + 0x2A, // FSCAL2 + 0x00, // FSCAL1 + 0x1F, // FSCAL0 + 0x00 // padding to 4 bytes +}; + +static uint8_t pa_table_index = PATABLE; ///< Current PATABLE Index +static uint8_t pa_table[] = { ///< PATABLE with available output powers + 0x00, ///< -52 dBm + 0x03, ///< -30 dBm + 0x0D, ///< -20 dBm + 0x1C, ///< -15 dBm + 0x34, ///< -10 dBm + 0x57, ///< - 5 dBm + 0x3F, ///< - 1 dBm + 0x8E, ///< 0 dBm + 0x85, ///< + 5 dBm + 0xCC, ///< + 7 dBm + 0xC6, ///< + 9 dBm + 0xC3 ///< +10 dBm +}; // If PATABLE is changed in size, adjust MAX_OUTPUT_POWER definition in CC1100 interface! + +static int8_t pa_table_dBm[] = { ///< Values of the PATABLE in dBm + -52, + -30, + -20, + -15, + -10, + -5, + -1, + 0, + 5, + 7, + 9, + 10 +}; + +/** @} */ diff --git a/drivers/cc110x_ng/cc1100-defaultSettings.h b/drivers/cc110x_ng/cc1100-defaultSettings.h new file mode 100644 index 0000000000..d3c92d4a09 --- /dev/null +++ b/drivers/cc110x_ng/cc1100-defaultSettings.h @@ -0,0 +1,110 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet 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 FeuerWare. + +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 +*******************************************************************************/ + +#ifndef CC1100_DEFAULTSETTINGS_H +#define CC1100_DEFAULTSETTINGS_H + +/** + * @ingroup dev_cc110x + * @{ + */ + +/** + * @file + * @brief TI Chipcon CC110x default settings + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Thomas Hillebrandt + * @author Heiko Will + * @version $Revision: 2139 $ + * + * @note $Id: cc1100-defaultSettings.h 2139 2010-05-26 08:04:04Z hillebra $ + */ + +#include + +// returns hwtimer ticks per us +#define RTIMER_TICKS(us) HWTIMER_TICKS(us) + +#define TIMER_TICK_USEC_RES (122) + +// Default PA table index (output power) +#define PATABLE (11) + +// Watchdog cycle time in seconds, set 0 to disable watchdog +#define CC1100_WATCHDOG_PERIOD (5) + +// Number of transmission retries for unicast packets (constant RX mode) +#define TRANSMISSION_RETRIES_CRX_UC (5) + +// Number of transmission retries for unicast packets (WOR mode) +#define TRANSMISSION_RETRIES_WOR_UC (1) + +// Number of transmission retries for broadcast packets (constant RX mode) +#define TRANSMISSION_RETRIES_CRX_BC (0) + +// Number of transmission retries for broadcast packets (WOR mode) +#define TRANSMISSION_RETRIES_WOR_BC (0) + +// Time before chip goes back to RX (= stays in PWD after incoming packet) +#define WOR_TIMEOUT_1 (3200) // ~ 32 milliseconds + +// Time before chip goes back to WOR (= stays in RX after elapsed WOR_TIMEOUT_1) +#define WOR_TIMEOUT_2 (800) // ~ 8 milliseconds + +// XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) +#define FS_CAL_TIME RTIMER_TICKS(12 * TIMER_TICK_USEC_RES) + +// Manual FS calibration (721 us) +#define MANUAL_FS_CAL_TIME RTIMER_TICKS(7 * TIMER_TICK_USEC_RES) + +// Reset wait time (in reset procedure) +#define RESET_WAIT_TIME RTIMER_TICKS(4 * TIMER_TICK_USEC_RES) + +// Time chip needs to go to RX +#define IDLE_TO_RX_TIME RTIMER_TICKS(1 * TIMER_TICK_USEC_RES) + +// Time chip needs to go to RX and CS signal is ready +#define CS_READY_TIME RTIMER_TICKS(3 * TIMER_TICK_USEC_RES) + +// Default RX interval for WOR in milliseconds +#define T_RX_INTERVAL (542) + +// Time of packet interval in microseconds (at 400 kbps) +#define T_PACKET_INTERVAL (3800) + +// The size of the configuration array for CC1100 in bytes +#define CC1100_CONF_SIZE (39) + +// The default channel number (0-24) for CC1100 +#define CC1100_DEFAULT_CHANNR (0) + +// Burst retry to TX switch time (measured ~ 230 us) +#define BURST_RETRY_TX_SWITCH_TIME (23) + + +/** @} */ +#endif diff --git a/drivers/cc110x_ng/cc1100-internal.h b/drivers/cc110x_ng/cc1100-internal.h new file mode 100644 index 0000000000..54ddabde70 --- /dev/null +++ b/drivers/cc110x_ng/cc1100-internal.h @@ -0,0 +1,218 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet 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 FeuerWare. + +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 +*******************************************************************************/ + +#ifndef CC1100_INTERNAL_H +#define CC1100_INTERNAL_H + +/** + * @ingroup dev_cc110x + * @{ + */ + +/** + * @file + * @internal + * @brief TI Chipcon CC110x internal hardware constants + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Thomas Hillebrandt + * @author Heiko Will + * @version $Revision: 1231 $ + * + * @note $Id: cc1100-internal.h 1231 2009-08-20 08:31:32Z baar $ + */ + +#define FIXED_PKTLEN (0x00) ///< Fixed length packets, length configured in PKTLEN register. +#define VARIABLE_PKTLEN (0x01) ///< Variable length packets, packet length configured by the first + ///< byte after synch word. + +/** + * @name Bitmasks for reading out status register values + * @{ + */ + +/** + * @brief Bitmask (=10000000) for reading CRC_OK. + * + * If CRC_OK == 1: CRC for received data OK (or CRC disabled). + * If CRC_OK == 0: CRC error in received data. + */ +#define CRC_OK (0x80) +/** + * @brief Bitmask (=01111111) for reading LQI_EST. + * + * The Link Quality Indicator estimates how easily a received signal can be demodulated. + */ +#define LQI_EST (0x7F) +#define I_RSSI (0x00) ///< Index 0 contains RSSI information (from optionally appended packet status bytes). +#define I_LQI (0x01) ///< Index 1 contains LQI & CRC_OK information (from optionally appended packet status bytes). +#define MARC_STATE (0x1F) ///< Bitmask (=00011111) for reading MARC_STATE in MARCSTATE status register. +#define CS (0x40) ///< Bitmask (=01000000) for reading CS (Carrier Sense) in PKTSTATUS status register. +#define PQT_REACHED (0x20) ///< Bitmask (=00100000) for reading PQT_REACHED (Preamble Quality reached) in PKTSTATUS status register. +#define CCA (0x10) ///< Bitmask (=00010000) for reading CCA (clear channel assessment) in PKTSTATUS status register. +#define SFD (0x08) ///< Bitmask (=00001000) for reading SFD (Sync word found) in PKTSTATUS status register. +#define GDO2 (0x04) ///< Bitmask (=00000100) for reading GDO2 (current value on GDO2 pin) in PKTSTATUS status register. +#define GDO1 (0x02) ///< Bitmask (=00000010) for reading GDO1 (current value on GDO1 pin) in PKTSTATUS status register. +#define GDO0 (0x01) ///< Bitmask (=00000001) for reading GDO0 (current value on GDO0 pin) in PKTSTATUS status register. +#define TXFIFO_UNDERFLOW (0x80) ///< Bitmask (=10000000) for reading TXFIFO_UNDERFLOW in TXBYTES status register. +#define BYTES_IN_TXFIFO (0x7F) ///< Bitmask (=01111111) for reading NUM_TXBYTES in TXBYTES status register. +#define RXFIFO_OVERFLOW (0x80) ///< Bitmask (=10000000) for reading RXFIFO_OVERFLOW in RXBYTES status register. +#define BYTES_IN_RXFIFO (0x7F) ///< Bitmask (=01111111) for reading NUM_RXBYTES in RXBYTES status register. +/** @} */ + +/** + * @name Bitmasks for reading out configuration register values + * @{ + */ +#define PKT_LENGTH_CONFIG (0x03) ///< Bitmask (=00000011) for reading LENGTH_CONFIG in PKTCTRL0 configuration register. +/** @} */ + +/** + * @name Definitions to support burst/single access + * @{ + */ +#define CC1100_WRITE_BURST (0x40) ///< Offset for burst write. +#define CC1100_READ_SINGLE (0x80) ///< Offset for read single byte. +#define CC1100_READ_BURST (0xC0) ///< Offset for read burst. +#define CC1100_NOBYTE (0x00) ///< No command (for reading). +/** @} */ + +/** + * @name Configuration Registers (47x) + * @{ + */ +#define CC1100_IOCFG2 (0x00) ///< GDO2 output pin configuration +#define CC1100_IOCFG1 (0x01) ///< GDO1 output pin configuration +#define CC1100_IOCFG0 (0x02) ///< GDO0 output pin configuration +#define CC1100_FIFOTHR (0x03) ///< RX FIFO and TX FIFO thresholds +#define CC1100_SYNC1 (0x04) ///< Sync word, high byte +#define CC1100_SYNC0 (0x05) ///< Sync word, low byte +#define CC1100_PKTLEN (0x06) ///< Packet length +#define CC1100_PKTCTRL1 (0x07) ///< Packet automation control +#define CC1100_PKTCTRL0 (0x08) ///< Packet automation control +#define CC1100_ADDR (0x09) ///< Device address +#define CC1100_CHANNR (0x0A) ///< Channel number +#define CC1100_FSCTRL1 (0x0B) ///< Frequency synthesizer control +#define CC1100_FSCTRL0 (0x0C) ///< Frequency synthesizer control +#define CC1100_FREQ2 (0x0D) ///< Frequency control word, high byte +#define CC1100_FREQ1 (0x0E) ///< Frequency control word, middle byte +#define CC1100_FREQ0 (0x0F) ///< Frequency control word, low byte +#define CC1100_MDMCFG4 (0x10) ///< Modem configuration +#define CC1100_MDMCFG3 (0x11) ///< Modem configuration +#define CC1100_MDMCFG2 (0x12) ///< Modem configuration +#define CC1100_MDMCFG1 (0x13) ///< Modem configuration +#define CC1100_MDMCFG0 (0x14) ///< Modem configuration +#define CC1100_DEVIATN (0x15) ///< Modem deviation setting +#define CC1100_MCSM2 (0x16) ///< Main Radio Control State Machine configuration +#define CC1100_MCSM1 (0x17) ///< Main Radio Control State Machine configuration +#define CC1100_MCSM0 (0x18) ///< Main Radio Control State Machine configuration +#define CC1100_FOCCFG (0x19) ///< Frequency Offset Compensation configuration +#define CC1100_BSCFG (0x1A) ///< Bit Synchronization configuration +#define CC1100_AGCCTRL2 (0x1B) ///< AGC control +#define CC1100_AGCCTRL1 (0x1C) ///< AGC control +#define CC1100_AGCCTRL0 (0x1D) ///< AGC control +#define CC1100_WOREVT1 (0x1E) ///< High byte Event 0 timeout +#define CC1100_WOREVT0 (0x1F) ///< Low byte Event 0 timeout +#define CC1100_WORCTRL (0x20) ///< Wake On Radio control +#define CC1100_FREND1 (0x21) ///< Front end RX configuration +#define CC1100_FREND0 (0x22) ///< Front end TX configuration +#define CC1100_FSCAL3 (0x23) ///< Frequency synthesizer calibration +#define CC1100_FSCAL2 (0x24) ///< Frequency synthesizer calibration +#define CC1100_FSCAL1 (0x25) ///< Frequency synthesizer calibration +#define CC1100_FSCAL0 (0x26) ///< Frequency synthesizer calibration +#define CC1100_RCCTRL1 (0x27) ///< RC oscillator configuration +#define CC1100_RCCTRL0 (0x28) ///< RC oscillator configuration +#define CC1100_FSTEST (0x29) ///< Frequency synthesizer calibration control +#define CC1100_PTEST (0x2A) ///< Production test +#define CC1100_AGCTEST (0x2B) ///< AGC test +#define CC1100_TEST2 (0x2C) ///< Various test settings +#define CC1100_TEST1 (0x2D) ///< Various test settings +#define CC1100_TEST0 (0x2E) ///< Various test settings +/** @} */ + +/** + * @name Strobe commands (14x) + * @{ + */ +#define CC1100_SRES (0x30) ///< Reset chip. +/** + * @brief Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1). + * + * If in RX/TX: Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround). + */ +#define CC1100_SFSTXON (0x31) +#define CC1100_SXOFF (0x32) ///< Turn off crystal oscillator. +#define CC1100_SCAL (0x33) ///< Calibrate frequency synthesizer and turn it off (enables quick start). +#define CC1100_SRX (0x34) ///< Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1. +/** + * In IDLE state: Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL=1. + * If in RX state and CCA is enabled: Only go to TX if channel is clear. + */ +#define CC1100_STX (0x35) +#define CC1100_SIDLE (0x36) ///< Exit RX / TX, turn off frequency synthesizer and exit WOR mode if applicable. +#define CC1100_SAFC (0x37) ///< Perform AFC adjustment of the frequency synthesizer +#define CC1100_SWOR (0x38) ///< Start automatic RX polling sequence (Wake-on-Radio) +#define CC1100_SPWD (0x39) ///< Enter power down mode when CSn goes high. +#define CC1100_SFRX (0x3A) ///< Flush the RX FIFO buffer (CC1100 should be in IDLE state). +#define CC1100_SFTX (0x3B) ///< Flush the TX FIFO buffer (CC1100 should be in IDLE state). +#define CC1100_SWORRST (0x3C) ///< Reset real time clock. +#define CC1100_SNOP (0x3D) ///< No operation. May be used to pad strobe commands to two bytes for simpler software. +/** @} */ + +/** + * @name Status registers (12x) + * @{ + */ +#define CC1100_PARTNUM (0x30) ///< Part number of CC1100. +#define CC1100_VERSION (0x31) ///< Current version number. +#define CC1100_FREQEST (0x32) ///< Frequency Offset Estimate. +#define CC1100_LQI (0x33) ///< Demodulator estimate for Link Quality. +#define CC1100_RSSI (0x34) ///< Received signal strength indication. +#define CC1100_MARCSTATE (0x35) ///< Control state machine state. +#define CC1100_WORTIME1 (0x36) ///< High byte of WOR timer. +#define CC1100_WORTIME0 (0x37) ///< Low byte of WOR timer. +#define CC1100_PKTSTATUS (0x38) ///< Current GDOx status and packet status. +#define CC1100_VCO_VC_DAC (0x39) ///< Current setting from PLL calibration module. +#define CC1100_TXBYTES (0x3A) ///< Underflow and number of bytes in the TX FIFO. +#define CC1100_RXBYTES (0x3B) ///< Overflow and number of bytes in the RX FIFO. +/** @} */ + +/** + * @name Multi byte registers + * @{ + */ +/** + * @brief Register for eight user selected output power settings. + * + * 3-bit FREND0.PA_POWER value selects the PATABLE entry to use. + */ +#define CC1100_PATABLE (0x3E) +#define CC1100_TXFIFO (0x3F) ///< TX FIFO: Write operations write to the TX FIFO (SB: +0x00; BURST: +0x40) +#define CC1100_RXFIFO (0x3F) ///< RX FIFO: Read operations read from the RX FIFO (SB: +0x80; BURST: +0xC0) + +/** @} */ + +#endif diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c new file mode 100644 index 0000000000..6668934221 --- /dev/null +++ b/drivers/cc110x_ng/cc1100.c @@ -0,0 +1,260 @@ +#include +#include +#include +#include +#include +#include + +#include + +#define RX_BUF_SIZE (10) + +/* some externals */ +extern uint8_t pa_table[]; ///< PATABLE with available output powers +extern uint8_t pa_table_index; ///< Current PATABLE Index + +/* global variables */ + +static rx_buffer_t rx_buffer[RX_BUF_SIZE]; ///< RX buffer + +volatile cc1100_flags rflags; ///< Radio control flags +volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state + +static volatile uint8_t rx_buffer_tail; ///< RX queue tail + +static uint8_t radio_address; ///< Radio address +static uint8_t radio_channel; ///< Radio channel + +cc1100_statistic_t cc1100_statistic; + +/* internal function prototypes */ +static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); +static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length); +static void reset(void); +static void power_up_reset(void); +static void write_register(uint8_t r, uint8_t value); + +static void setup_rx_mode(void); +static void switch_to_rx(void); +static void wakeup_from_rx(void); +static void switch_to_pwd(void); + +/*---------------------------------------------------------------------------*/ +// Radio Driver API +/*---------------------------------------------------------------------------*/ +void cc1100_init(void) { + rx_buffer_tail = 0; + + /* Initialize SPI */ + cc1100_spi_init(); + + /* Load driver & reset */ + power_up_reset(); + + /* Write configuration to configuration registers */ + cc1100_spi_writeburst_reg(0x00, cc1100_conf, CC1100_CONF_SIZE); + + /* Write PATABLE (power settings) */ + cc1100_spi_write_reg(CC1100_PATABLE, pa_table[pa_table_index]); + + /* Initialize Radio Flags */ + rflags.RSSI = 0x00; + rflags.LL_ACK = 0; + rflags.CAA = 0; + rflags.CRC = 0; + rflags.SEQ = 0; + rflags.MAN_WOR = 0; + rflags.KT_RES_ERR = 0; + rflags.TX = 0; + rflags.WOR_RST = 0; + + /* Set default channel number */ + radio_channel = CC1100_DEFAULT_CHANNR; +} + +void cc1100_disable_interrupts(void) { + cc1100_gdo2_disable(); + cc1100_gdo0_disable(); +} + +void cc1100_gdo0_irq(void) { + // Air was not free -> Clear CCA flag + rflags.CAA = false; + // Disable carrier sense detection (GDO0 interrupt) + cc1100_gdo0_disable(); +} + +void cc1100_gdo2_irq(void) { + cc1100_rx_handler(); +} + +void cc1100_rx_handler(void) { + uint8_t res = 0; + + res = receive_packet((uint8_t*)&(rx_buffer[rx_buffer_tail].packet), sizeof(cc1100_packet_t)); +} + +uint8_t cc1100_set_address(radio_address_t address) { + if ((address < MIN_UID) || (address > MAX_UID)) { + return 0; + } + + uint8_t id = (uint8_t) address; + if (radio_state != RADIO_UNKNOWN) { + write_register(CC1100_ADDR, id); + } + + radio_address = id; + return 0; +} +/*---------------------------------------------------------------------------*/ +/* Internal functions */ +/*---------------------------------------------------------------------------*/ + +static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { + uint8_t status[2]; + uint8_t packetLength = 0; + + /* Any bytes available in RX FIFO? */ + if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) + { + // Read length byte (first byte in RX FIFO) + packetLength = cc1100_spi_read_reg(CC1100_RXFIFO); + // Read data from RX FIFO and store in rxBuffer + if (packetLength <= length) + { + // Put length byte at first position in RX Buffer + rxBuffer[0] = packetLength; + + // Read the rest of the packet + cc1100_spi_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); + + // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) + cc1100_spi_readburst_reg(CC1100_RXFIFO, (char*)status, 2); + + // Store RSSI value of packet + rflags.RSSI = status[I_RSSI]; + + // MSB of LQI is the CRC_OK bit + rflags.CRC = (status[I_LQI] & CRC_OK) >> 7; + if (!rflags.CRC) { + cc1100_statistic.packets_in_crc_fail++; + } + + // Bit 0-6 of LQI indicates the link quality (LQI) + rflags.LQI = status[I_LQI] & LQI_EST; + + return rflags.CRC; + } + /* too many bytes in FIFO */ + else { + // RX FIFO get automatically flushed if return value is false + return 0; + } + } + /* no bytes in RX FIFO */ + else { + // RX FIFO get automatically flushed if return value is false + return 0; + } +} + +static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length) { + uint8_t pkt_len_cfg = cc1100_spi_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; + if (pkt_len_cfg == VARIABLE_PKTLEN) + { + return receive_packet_variable(rxBuffer, length); + } + // Fixed packet length not supported. + // RX FIFO get automatically flushed if return value is false + return 0; +} + +/*---------------------------------------------------------------------------*/ +// CC1100 reset functionality +/*---------------------------------------------------------------------------*/ + +static void reset(void) { + wakeup_from_rx(); + cc1100_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(); + hwtimer_wait(RESET_WAIT_TIME); + reset(); + radio_state = RADIO_IDLE; +} + +static void write_register(uint8_t r, uint8_t value) { + // Save old radio state + uint8_t old_state = radio_state; + + /* Wake up from WOR/RX (if in WOR/RX, else no effect) */ + wakeup_from_rx(); + cc1100_spi_write_reg(r, value); + + // Have to put radio back to WOR/RX if old radio state + // was WOR/RX, otherwise no action is necessary + if ((old_state == RADIO_WOR) || (old_state == RADIO_RX)) { + switch_to_rx(); + } +} + +static int rd_set_mode(int mode) { + int result; + + // Get current radio mode + if ((radio_state == RADIO_UNKNOWN) || (radio_state == RADIO_PWD)) { + result = RADIO_MODE_OFF; + } + else { + result = RADIO_MODE_ON; + } + + switch (mode) { + case RADIO_MODE_ON: + cc1100_init_interrupts(); // Enable interrupts + setup_rx_mode(); // Set chip to desired mode + break; + case RADIO_MODE_OFF: + cc1100_disable_interrupts(); // Disable interrupts + switch_to_pwd(); // Set chip to power down mode + break; + case RADIO_MODE_GET: + // do nothing, just return current mode + default: + // do nothing + break; + } + + // Return previous mode + return result; +} + +static void setup_rx_mode(void) { + // Stay in RX mode until end of packet + cc1100_spi_write_reg(CC1100_MCSM2, 0x07); + switch_to_rx(); +} + +static void switch_to_rx(void) { + radio_state = RADIO_RX; + cc1100_spi_strobe(CC1100_SRX); +} + +static void wakeup_from_rx(void) { + if (radio_state != RADIO_RX) return; + cc1100_spi_strobe(CC1100_SIDLE); + radio_state = RADIO_IDLE; +} + +static void switch_to_pwd(void) { + wakeup_from_rx(); + cc1100_spi_strobe(CC1100_SPWD); + radio_state = RADIO_PWD; +} diff --git a/drivers/cc110x_ng/cc1100.h b/drivers/cc110x_ng/cc1100.h new file mode 100644 index 0000000000..01c98fe588 --- /dev/null +++ b/drivers/cc110x_ng/cc1100.h @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +#define MAX_DATA_LENGTH (58) + +#define CC1100_BROADCAST_ADDRESS (0x00) ///< CC1100 broadcast address + +#define MAX_UID (0xFF) ///< Maximum UID of a node is 255 +#define MIN_UID (0x01) ///< Minimum UID of a node is 1 + +#define MIN_CHANNR (0) ///< Minimum channel number +#define MAX_CHANNR (24) ///< Maximum channel number + +#define MIN_OUTPUT_POWER (0) ///< Minimum output power value +#define MAX_OUTPUT_POWER (11) ///< Maximum output power value + +/** + * @name Defines used as state values for state machine + * @{ + */ +#define RADIO_UNKNOWN (0) +#define RADIO_AIR_FREE_WAITING (1) +#define RADIO_WOR (2) +#define RADIO_IDLE (3) +#define RADIO_SEND_BURST (4) +#define RADIO_RX (5) +#define RADIO_SEND_ACK (6) +#define RADIO_PWD (7) + +/** @} */ +extern volatile cc1100_flags rflags; ///< Radio flags +extern char cc1100_conf[]; + +/** + * @brief CC1100 layer 0 protocol + * + *
+---------------------------------------------------
+|        |         |         |       |            |
+| Length | Address | PhySrc  | Flags |    Data    |
+|        |         |         |       |            |
+---------------------------------------------------
+  1 byte   1 byte    1 byte   1 byte   <= 58 bytes
+
+Flags:
+		Bit | Meaning
+		--------------------
+		7:4	| -
+		3:1 | Protocol
+		  0 | Identification
+
+Notes: +\li length & address are given by CC1100 +\li Identification is increased is used to scan duplicates. It must be increased + for each new packet and kept for packet retransmissions. + */ +typedef struct __attribute__ ((packed)) { + uint8_t length; ///< Length of the packet (without length byte) + uint8_t address; ///< Destination address + uint8_t phy_src; ///< Source address (physical source) + uint8_t flags; ///< Flags + uint8_t data[MAX_DATA_LENGTH]; ///< Data (high layer protocol) +} cc1100_packet_t; + +typedef struct { + cc1100_packet_t packet; + packet_info_t info; +} rx_buffer_t; + +enum radio_mode { + RADIO_MODE_GET = -1, ///< leave mode unchanged + RADIO_MODE_OFF = 0, ///< turn radio off + RADIO_MODE_ON = 1 ///< turn radio on +}; + +void cc1100_init(void); + +void cc1100_rx_handler(void); + +void cc1100_disable_interrupts(void); diff --git a/drivers/cc110x_ng/cc1100_spi.c b/drivers/cc110x_ng/cc1100_spi.c new file mode 100644 index 0000000000..010f31a5ed --- /dev/null +++ b/drivers/cc110x_ng/cc1100_spi.c @@ -0,0 +1,128 @@ +/****************************************************************************** +Copyright 2010, Freie Universitaet 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 +*******************************************************************************/ + +/** + * @ingroup dev_cc110x + * @{ + */ + +/** + * @file + * @internal + * @brief TI Chipcon CC1100 SPI driver + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Thomas Hillebrandt + * @author Heiko Will + * @version $Revision: 1775 $ + * + * @note $Id: cc1100_spi.c 1775 2010-01-26 09:37:03Z hillebra $ + */ + +#include + +#include +#include +#include +#include + +#include + +/*---------------------------------------------------------------------------*/ +// CC1100 SPI access +/*---------------------------------------------------------------------------*/ + +#define NOBYTE 0xFF + +uint8_t 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); + while (i < count) { + cc1100_txrx(src[i]); + i++; + } + cc1100_spi_unselect(); + restoreIRQ(cpsr); + return count; +} + +void 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); + while (i < count) { + buffer[i] = cc1100_txrx(NOBYTE); + i++; + } + cc1100_spi_unselect(); + restoreIRQ(cpsr); +} + +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(); + restoreIRQ(cpsr); +} + +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(); + restoreIRQ(cpsr); + return result; +} + +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(); + restoreIRQ(cpsr); + return result; +} + +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(); + restoreIRQ(cpsr); + return result; +} + +/** @} */ diff --git a/drivers/cc110x_ng/cc1100_spi.h b/drivers/cc110x_ng/cc1100_spi.h new file mode 100644 index 0000000000..736f982187 --- /dev/null +++ b/drivers/cc110x_ng/cc1100_spi.h @@ -0,0 +1,64 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet 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 FeuerWare. + +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 +*******************************************************************************/ +/** + * @ingroup dev_cc110x + * @{ + */ + +/** + * @file + * @internal + * @brief TI Chipcon CC1100 SPI driver + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Thomas Hillebrandt + * @author Heiko Will + * @version $Revision: 1775 $ + * + * @note $Id: cc1100_spi.h 1775 2010-01-26 09:37:03Z hillebra $ + */ + +#ifndef CC1100_SPI_H_ +#define CC1100_SPI_H_ + +int cc1100_get_gdo0(void); +int cc1100_get_gdo1(void); +int cc1100_get_gdo2(void); + +void cc1100_spi_init(void); +void cc1100_spi_cs(void); +void cc1100_spi_select(void); +void cc1100_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); +void cc1100_spi_write_reg(uint8_t addr, uint8_t value); +uint8_t cc1100_spi_read_reg(uint8_t addr); +uint8_t cc1100_spi_read_status(uint8_t addr); +uint8_t cc1100_spi_strobe(uint8_t c); + +/** @} */ +#endif /* CC1100_SPI_H_ */ From 044616bf198b87ee10903ea9d8caf28438bb1c9c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 19 Nov 2010 20:10:09 +0100 Subject: [PATCH 091/115] * some work on rx handling in cc110x_ng * added first version of cc110x_ng test application * introduced a generic transceiver interface and module --- projects/test_cc110x_ng/Jamfile | 5 ++ projects/test_cc110x_ng/main.c | 28 ++++++++ projects/test_cc110x_ng/tests/hello-world | 13 ++++ sys/Jamfile | 2 + sys/include/radio/types.h | 19 ++++++ sys/include/transceiver.h | 28 ++++++++ sys/transceiver.c | 78 +++++++++++++++++++++++ 7 files changed, 173 insertions(+) create mode 100644 projects/test_cc110x_ng/Jamfile create mode 100644 projects/test_cc110x_ng/main.c create mode 100755 projects/test_cc110x_ng/tests/hello-world create mode 100644 sys/include/transceiver.h create mode 100644 sys/transceiver.c diff --git a/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile new file mode 100644 index 0000000000..29f79da92f --- /dev/null +++ b/projects/test_cc110x_ng/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects test_cc110x_ng ; + +Module test_cc110x_ng : main.c : cc110x_ng shell ps rtc posix_io uart0 ; + +UseModule test_cc110x_ng ; diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c new file mode 100644 index 0000000000..25fbfdaa8b --- /dev/null +++ b/projects/test_cc110x_ng/main.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include + +#define SHELL_STACK_SIZE (4096) + +char shell_stack_buffer[SHELL_STACK_SIZE]; + +shell_t shell; +const shell_command_t sc[] = {{NULL, NULL, NULL}}; + +void shell_runner(void) { + shell_init(&shell, sc, uart0_readc, uart0_putc); + posix_open(uart0_handler_pid, 0); + shell_run(&shell); +} + +int main(void) { + thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); + + while (1) { + LED_GREEN_TOGGLE; + hwtimer_wait(1000 * 1000); + } +} diff --git a/projects/test_cc110x_ng/tests/hello-world b/projects/test_cc110x_ng/tests/hello-world new file mode 100755 index 0000000000..acde8265fe --- /dev/null +++ b/projects/test_cc110x_ng/tests/hello-world @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "Hello World!" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" + diff --git a/sys/Jamfile b/sys/Jamfile index 0ae65f81c8..a8ff40a5c0 100644 --- a/sys/Jamfile +++ b/sys/Jamfile @@ -35,6 +35,8 @@ Module auto_init : auto_init.c ; Module chardev_thread : chardev_thread.c : ringbuffer ; Module uart0 : uart0.c : ringbuffer chardev_thread ; +Module transceiver : transceiver.c ; + SubInclude TOP sys net ; SubInclude TOP sys lib ; SubInclude TOP sys shell ; diff --git a/sys/include/radio/types.h b/sys/include/radio/types.h index 7018480f65..5c191e3805 100644 --- a/sys/include/radio/types.h +++ b/sys/include/radio/types.h @@ -73,6 +73,25 @@ typedef struct __attribute__ ((packed)) packet_info_t bool promiscuous; ///< Radio layer: whether network interface is in promiscuous mode } packet_info_t; + +typedef struct __attribute__ ((packed)) { + uint8_t rssi; ///< Radio layer: RSSI + uint8_t lqi; ///< Radio layer: LQI +} radio_info_t; + +/** + * @brief General link layer packet format + */ +typedef struct __attribute__ ((packed)) { + uint16_t src; ///< Radio source address + uint16_t dst; ///< Radio destination address + uint8_t rssi; ///< Radio Signal Strength Indication + uint8_t lqi; ///< Link Quality Indicator + uint8_t length; ///< Length of payload + uint8_t *data; ///< Payload +} radio_packet_t; + + /** * Packet handler (receive function) of all layers. * @param [in/out] payload Pointer to packet payload data diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h new file mode 100644 index 0000000000..563f4669ad --- /dev/null +++ b/sys/include/transceiver.h @@ -0,0 +1,28 @@ +#ifndef TRANSCEIVER_H +#define TRANSCEIVER_H + +#define TRANSCEIVER_BUFFER_SIZE (10) +#define TRANSCEIVER_STACK_SIZE (4096) + +enum transceiver_msg_type_t { + RCV_PKT, + SND_PKT, + SND_ACK, + SWITCH_RX, + POWERDOWN, +}; + +enum transceiver_type_t { + NONE, + CC1100, + CC1020 +}; + +void transceiver_init(transceiver_type_t transceiver); + +void transceiver_start(void); + +extern int transceiver_pid; +extern void *transceiver_rx_buffer; + +#endif /* TRANSCEIVER_H */ diff --git a/sys/transceiver.c b/sys/transceiver.c new file mode 100644 index 0000000000..9c3c05b1d9 --- /dev/null +++ b/sys/transceiver.c @@ -0,0 +1,78 @@ +#include +#include + +#include + +/* supported transceivers */ +#include + +transceiver_type_t transceiver = NONE; +int transceiver_pid = EINVAL; +radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; + +static volatile uint8_t rx_buffer_pos = 0; +static volatile uint8_t transceiver_buffer_pos = 0; + +const char transceiver_stack[TRANSCEIVER_STACK_SIZE]; + +void run(void); +void receive_packet(void); + +void transceiver_init(transceiver_type_t t) { + switch (t) { + case CC110: + transceiver = t; + cc1100_init(); + break; + default: + puts("Invalid transceiver type"); + break; + } +} + +void transceiver_start(void) { + transceiver_pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING, run, "Transceiver"); + if (transceiver < 0) { + puts("Error creating transceiver thread"); + } +} + +void run(void) { + msg m; + while (1) { + msg_receive(&m); + switch (m) { + case RCV_PKT: + receive_packet(); + break; + default: + DEBUG("Unknown message received\n"); + break; + } + } +} + + +void receive_packet(void) { + switch (transveiver) { + case CC1100: + dINT(); + rx_buffer_pos = cc1100_rx_buffer_next - 1; + cc1100_packet_t p = cc1100_rx_buffer[rx_buffer_pos].packet; + radio_info_t info = cc1100_rx_buffer[rx_buffer_pos].info; + radio_packet_t trans_p = transceiver_buffer[transceiver_buffer_pos]; + + trans_p.src = p.phy_src; + trans_p.dst = p.address; + trans_p.rssi = info.rssi; + trans_p.lqi = info.lqi; + trans_p.length = p.length; + + /* TODO: copy payload */ + eINT(); + break; + default: + puts("Invalid transceiver type"); + break; + } +} From 6a08a479029e13663f16af11cc0b66d3bbbe3b04 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 19 Nov 2010 20:12:35 +0100 Subject: [PATCH 092/115] * missing driver files from last commit --- drivers/cc110x_ng/cc1100.c | 147 +++++++++++++++++++++++++++---------- drivers/cc110x_ng/cc1100.h | 18 ++++- 2 files changed, 124 insertions(+), 41 deletions(-) diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 6668934221..4379b0f697 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -5,6 +5,7 @@ #include #include +#include #include #define RX_BUF_SIZE (10) @@ -15,17 +16,24 @@ extern uint8_t pa_table_index; ///< Current PATABLE Index /* global variables */ -static rx_buffer_t rx_buffer[RX_BUF_SIZE]; ///< RX buffer +rx_buffer_t cc1100_rx_buffer[RX_BUF_SIZE]; ///< RX buffer +cc1100_statistic_t cc1100_statistic; -volatile cc1100_flags rflags; ///< Radio control flags +volatile cc1100_flags rflags; ///< Radio control flags volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state -static volatile uint8_t rx_buffer_tail; ///< RX queue tail +volatile uint8_t cc1100_rx_buffer_next; ///< Next packet in RX queue -static uint8_t radio_address; ///< Radio address -static uint8_t radio_channel; ///< Radio channel +static uint8_t radio_address; ///< Radio address +static uint8_t radio_channel; ///< Radio channel + +/** + * @brief Last sequence number this node has seen + * + * @note (phySrc + flags.identification) - for speedup in ISR. + */ +static volatile uint16_t last_seq_num = 0; -cc1100_statistic_t cc1100_statistic; /* internal function prototypes */ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); @@ -34,16 +42,11 @@ static void reset(void); static void power_up_reset(void); static void write_register(uint8_t r, uint8_t value); -static void setup_rx_mode(void); -static void switch_to_rx(void); -static void wakeup_from_rx(void); -static void switch_to_pwd(void); - /*---------------------------------------------------------------------------*/ // Radio Driver API /*---------------------------------------------------------------------------*/ void cc1100_init(void) { - rx_buffer_tail = 0; + cc1100_rx_buffer_next = 0; /* Initialize SPI */ cc1100_spi_init(); @@ -91,7 +94,71 @@ void cc1100_gdo2_irq(void) { void cc1100_rx_handler(void) { uint8_t res = 0; - res = receive_packet((uint8_t*)&(rx_buffer[rx_buffer_tail].packet), sizeof(cc1100_packet_t)); + // Possible packet received, RX -> IDLE (0.1 us) + rflags.CAA = 0; + rflags.MAN_WOR = 0; + cc1100_statistic.packets_in++; + + res = receive_packet((uint8_t*)&(rx_buffer[cc1100_rx_buffer_next].packet), sizeof(cc1100_packet_t)); + if (res) + { + // If we are sending a burst, don't accept packets. + // Only ACKs are processed (for stopping the burst). + // Same if state machine is in TX lock. + if (radio_state == RADIO_SEND_BURST || rflags.TX) + { + cc1100_statistic.packets_in_while_tx++; + return; + } + rx_buffer[cc1100_rx_buffer_next].info.rssi = rflags.RSSI; + rx_buffer[cc1100_rx_buffer_next].info.lqi = rflags.LQI; + + // Valid packet. After a wake-up, the radio should be in IDLE. + // So put CC1100 to RX for WOR_TIMEOUT (have to manually put + // the radio back to sleep/WOR). + cc1100_spi_write_reg(CC1100_MCSM0, 0x08); // Turn off FS-Autocal + cc1100_spi_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME (until end of packet) + cc1100_spi_strobe(CC1100_SRX); + hwtimer_wait(IDLE_TO_RX_TIME); + radio_state = RADIO_RX; + + if (++cc1100_rx_buffer_next == RX_BUF_SIZE) { + cc1100_rx_buffer_next = 0; + } + msg m; + m.type = RCV_PKT; + m.content = NULL; + msg_send_int(m, transceiver_pid); + return; + } + else + { + // No ACK received so TOF is unpredictable + rflags.TOF = 0; + + // CRC false or RX buffer full -> clear RX FIFO in both cases + last_seq_num = 0; // Reset for correct burst detection + cc1100_spi_strobe(CC1100_SIDLE); // Switch to IDLE (should already be)... + cc1100_spi_strobe(CC1100_SFRX); // ...for flushing the RX FIFO + + // If packet interrupted this nodes send call, + // don't change anything after this point. + if (radio_state == RADIO_AIR_FREE_WAITING) + { + cc1100_spi_strobe(CC1100_SRX); + hwtimer_wait(IDLE_TO_RX_TIME); + return; + } + // If currently sending, exit here (don't go to RX/WOR) + if (radio_state == RADIO_SEND_BURST) + { + cc1100_statistic.packets_in_while_tx++; + return; + } + + // No valid packet, so go back to RX/WOR as soon as possible + cc1100_switch_to_rx(); + } } uint8_t cc1100_set_address(radio_address_t address) { @@ -107,6 +174,29 @@ uint8_t cc1100_set_address(radio_address_t address) { radio_address = id; return 0; } + +void cc1100_setup_rx_mode(void) { + // Stay in RX mode until end of packet + cc1100_spi_write_reg(CC1100_MCSM2, 0x07); + cc1100_switch_to_rx(); +} + +void cc1100_switch_to_rx(void) { + radio_state = RADIO_RX; + cc1100_spi_strobe(CC1100_SRX); +} + +void cc1100_wakeup_from_rx(void) { + if (radio_state != RADIO_RX) return; + cc1100_spi_strobe(CC1100_SIDLE); + radio_state = RADIO_IDLE; +} + +void switch_to_pwd(void) { + cc1100_wakeup_from_rx(); + cc1100_spi_strobe(CC1100_SPWD); + radio_state = RADIO_PWD; +} /*---------------------------------------------------------------------------*/ /* Internal functions */ /*---------------------------------------------------------------------------*/ @@ -175,7 +265,7 @@ static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length) { /*---------------------------------------------------------------------------*/ static void reset(void) { - wakeup_from_rx(); + cc1100_wakeup_from_rx(); cc1100_spi_select(); cc1100_spi_strobe(CC1100_SRES); hwtimer_wait(RTIMER_TICKS(10)); @@ -195,13 +285,13 @@ static void write_register(uint8_t r, uint8_t value) { uint8_t old_state = radio_state; /* Wake up from WOR/RX (if in WOR/RX, else no effect) */ - wakeup_from_rx(); + cc1100_wakeup_from_rx(); cc1100_spi_write_reg(r, value); // Have to put radio back to WOR/RX if old radio state // was WOR/RX, otherwise no action is necessary if ((old_state == RADIO_WOR) || (old_state == RADIO_RX)) { - switch_to_rx(); + cc1100_switch_to_rx(); } } @@ -219,11 +309,11 @@ static int rd_set_mode(int mode) { switch (mode) { case RADIO_MODE_ON: cc1100_init_interrupts(); // Enable interrupts - setup_rx_mode(); // Set chip to desired mode + cc1100_setup_rx_mode(); // Set chip to desired mode break; case RADIO_MODE_OFF: cc1100_disable_interrupts(); // Disable interrupts - switch_to_pwd(); // Set chip to power down mode + cc1100_switch_to_pwd(); // Set chip to power down mode break; case RADIO_MODE_GET: // do nothing, just return current mode @@ -236,25 +326,4 @@ static int rd_set_mode(int mode) { return result; } -static void setup_rx_mode(void) { - // Stay in RX mode until end of packet - cc1100_spi_write_reg(CC1100_MCSM2, 0x07); - switch_to_rx(); -} -static void switch_to_rx(void) { - radio_state = RADIO_RX; - cc1100_spi_strobe(CC1100_SRX); -} - -static void wakeup_from_rx(void) { - if (radio_state != RADIO_RX) return; - cc1100_spi_strobe(CC1100_SIDLE); - radio_state = RADIO_IDLE; -} - -static void switch_to_pwd(void) { - wakeup_from_rx(); - cc1100_spi_strobe(CC1100_SPWD); - radio_state = RADIO_PWD; -} diff --git a/drivers/cc110x_ng/cc1100.h b/drivers/cc110x_ng/cc1100.h index 01c98fe588..6889f16171 100644 --- a/drivers/cc110x_ng/cc1100.h +++ b/drivers/cc110x_ng/cc1100.h @@ -1,3 +1,6 @@ +#ifndef CC1100_H +#define CC1100_H + #include #include #include @@ -30,6 +33,9 @@ #define RADIO_PWD (7) /** @} */ + +extern rx_buffer_t cc1100_rx_buffer[]; + extern volatile cc1100_flags rflags; ///< Radio flags extern char cc1100_conf[]; @@ -65,8 +71,8 @@ typedef struct __attribute__ ((packed)) { } cc1100_packet_t; typedef struct { - cc1100_packet_t packet; - packet_info_t info; + radio_info_t info; + cc1100_packet_t; } rx_buffer_t; enum radio_mode { @@ -75,8 +81,16 @@ enum radio_mode { RADIO_MODE_ON = 1 ///< turn radio on }; +extern volatile uint8_t cc1100_rx_buffer_next; + void cc1100_init(void); void cc1100_rx_handler(void); +void cc1100_setup_rx_mode(void); +void cc1100_switch_to_rx(void); +void cc1100_wakeup_from_rx(void); +void cc1100_switch_to_pwd(void); + void cc1100_disable_interrupts(void); +#endif From d98545f3788b3e2f263c046436bee69eab918c35 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sun, 21 Nov 2010 14:00:24 +0100 Subject: [PATCH 093/115] * changed buffer format for cc110x_ng and transceiver * added some documentation * added support for more than one transceiver --- drivers/cc110x_ng/cc1100.c | 23 ++++---- drivers/cc110x_ng/cc1100.h | 12 +++-- sys/Jamfile | 2 +- sys/include/radio/types.h | 6 +-- sys/include/transceiver.h | 66 ++++++++++++++++++----- sys/transceiver.c | 105 ++++++++++++++++++++++++++----------- 6 files changed, 146 insertions(+), 68 deletions(-) diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 4379b0f697..87cf951bc0 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -7,6 +9,7 @@ #include #include +#include #define RX_BUF_SIZE (10) @@ -27,13 +30,6 @@ volatile uint8_t cc1100_rx_buffer_next; ///< Next packet in RX queue static uint8_t radio_address; ///< Radio address static uint8_t radio_channel; ///< Radio channel -/** - * @brief Last sequence number this node has seen - * - * @note (phySrc + flags.identification) - for speedup in ISR. - */ -static volatile uint16_t last_seq_num = 0; - /* internal function prototypes */ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); @@ -99,7 +95,7 @@ void cc1100_rx_handler(void) { rflags.MAN_WOR = 0; cc1100_statistic.packets_in++; - res = receive_packet((uint8_t*)&(rx_buffer[cc1100_rx_buffer_next].packet), sizeof(cc1100_packet_t)); + res = receive_packet((uint8_t*)&(cc1100_rx_buffer[cc1100_rx_buffer_next].packet), sizeof(cc1100_packet_t)); if (res) { // If we are sending a burst, don't accept packets. @@ -110,8 +106,8 @@ void cc1100_rx_handler(void) { cc1100_statistic.packets_in_while_tx++; return; } - rx_buffer[cc1100_rx_buffer_next].info.rssi = rflags.RSSI; - rx_buffer[cc1100_rx_buffer_next].info.lqi = rflags.LQI; + cc1100_rx_buffer[cc1100_rx_buffer_next].rssi = rflags.RSSI; + cc1100_rx_buffer[cc1100_rx_buffer_next].lqi = rflags.LQI; // Valid packet. After a wake-up, the radio should be in IDLE. // So put CC1100 to RX for WOR_TIMEOUT (have to manually put @@ -126,9 +122,9 @@ void cc1100_rx_handler(void) { cc1100_rx_buffer_next = 0; } msg m; - m.type = RCV_PKT; - m.content = NULL; - msg_send_int(m, transceiver_pid); + m.type = (uint16_t) RCV_PKT; + m.content.ptr = NULL; + msg_send_int(&m, transceiver_pid); return; } else @@ -137,7 +133,6 @@ void cc1100_rx_handler(void) { rflags.TOF = 0; // CRC false or RX buffer full -> clear RX FIFO in both cases - last_seq_num = 0; // Reset for correct burst detection cc1100_spi_strobe(CC1100_SIDLE); // Switch to IDLE (should already be)... cc1100_spi_strobe(CC1100_SFRX); // ...for flushing the RX FIFO diff --git a/drivers/cc110x_ng/cc1100.h b/drivers/cc110x_ng/cc1100.h index 6889f16171..90f327592e 100644 --- a/drivers/cc110x_ng/cc1100.h +++ b/drivers/cc110x_ng/cc1100.h @@ -6,7 +6,7 @@ #include #include -#define MAX_DATA_LENGTH (58) +#define CC1100_MAX_DATA_LENGTH (58) #define CC1100_BROADCAST_ADDRESS (0x00) ///< CC1100 broadcast address @@ -34,7 +34,6 @@ /** @} */ -extern rx_buffer_t cc1100_rx_buffer[]; extern volatile cc1100_flags rflags; ///< Radio flags extern char cc1100_conf[]; @@ -67,12 +66,13 @@ typedef struct __attribute__ ((packed)) { uint8_t address; ///< Destination address uint8_t phy_src; ///< Source address (physical source) uint8_t flags; ///< Flags - uint8_t data[MAX_DATA_LENGTH]; ///< Data (high layer protocol) + uint8_t data[CC1100_MAX_DATA_LENGTH]; ///< Data (high layer protocol) } cc1100_packet_t; typedef struct { - radio_info_t info; - cc1100_packet_t; + uint8_t rssi; + uint8_t lqi; + cc1100_packet_t packet; } rx_buffer_t; enum radio_mode { @@ -81,6 +81,8 @@ enum radio_mode { RADIO_MODE_ON = 1 ///< turn radio on }; +extern rx_buffer_t cc1100_rx_buffer[]; + extern volatile uint8_t cc1100_rx_buffer_next; void cc1100_init(void); diff --git a/sys/Jamfile b/sys/Jamfile index a8ff40a5c0..f236e498ea 100644 --- a/sys/Jamfile +++ b/sys/Jamfile @@ -35,7 +35,7 @@ Module auto_init : auto_init.c ; Module chardev_thread : chardev_thread.c : ringbuffer ; Module uart0 : uart0.c : ringbuffer chardev_thread ; -Module transceiver : transceiver.c ; +Module transceiver : transceiver.c : oneway_malloc ; SubInclude TOP sys net ; SubInclude TOP sys lib ; diff --git a/sys/include/radio/types.h b/sys/include/radio/types.h index 5c191e3805..f5b88c9c0e 100644 --- a/sys/include/radio/types.h +++ b/sys/include/radio/types.h @@ -74,15 +74,11 @@ typedef struct __attribute__ ((packed)) packet_info_t } packet_info_t; -typedef struct __attribute__ ((packed)) { - uint8_t rssi; ///< Radio layer: RSSI - uint8_t lqi; ///< Radio layer: LQI -} radio_info_t; - /** * @brief General link layer packet format */ typedef struct __attribute__ ((packed)) { + uint8_t processing; ///< internal processing state uint16_t src; ///< Radio source address uint16_t dst; ///< Radio destination address uint8_t rssi; ///< Radio Signal Strength Indication diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index 563f4669ad..4a60a42fe5 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -1,28 +1,70 @@ #ifndef TRANSCEIVER_H #define TRANSCEIVER_H +/* Packets to buffer */ #define TRANSCEIVER_BUFFER_SIZE (10) +/* Stack size for transceiver thread */ #define TRANSCEIVER_STACK_SIZE (4096) +/* The maximum of threads to register */ +#define TRANSCEIVER_MAX_REGISTERED (10) + +/** + * @brief Message types for transceiver interface + */ enum transceiver_msg_type_t { - RCV_PKT, - SND_PKT, - SND_ACK, - SWITCH_RX, - POWERDOWN, + RCV_PKT, ///< packet was received + SND_PKT, ///< request for sending a packet + SND_ACK, ///< request for sending an acknowledgement + SWITCH_RX, ///< switch receiver to RX sate + POWERDOWN, ///< power down receiver }; -enum transceiver_type_t { - NONE, - CC1100, - CC1020 -}; +/** + * @brief All supported transceivers + */ +typedef enum { + NONE, ///< Invalid + CC1100, ///< CC110X transceivers + CC1020 ///< CC1020 transceivers +} transceiver_type_t; -void transceiver_init(transceiver_type_t transceiver); +/** + * @brief Manage registered threads per transceiver + */ +typedef struct { + transceiver_type_t transceivers; ///< the tranceivers the thread is registered for + int pid; ///< the thread's pid +} registered_t; -void transceiver_start(void); +typedef struct { + transceiver_type_t transceivers; + radio_packet_t *packet; +} send_packet_t; extern int transceiver_pid; extern void *transceiver_rx_buffer; +/** + * @brief Initializes the transceiver module for certain transceiver types + * + * @param transceivers Specifies all transceivers to init + **/ +void transceiver_init(transceiver_type_t transceivers); + +/** + * @brief Runs the transceiver thread + */ +void transceiver_start(void); + +/** + * @brief register a thread for events from certain transceivers + * + * @param transceivers The transceiver types to register for + * @param pid The pid of the thread to register + * + * return 1 on success, 0 otherwise + */ +uint8_t transceiver_register(transceiver_type_t transceivers, int pid); + #endif /* TRANSCEIVER_H */ diff --git a/sys/transceiver.c b/sys/transceiver.c index 9c3c05b1d9..5c11f7fd72 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -1,42 +1,71 @@ #include #include +#include #include /* supported transceivers */ #include -transceiver_type_t transceiver = NONE; +/* used transceiver types */ +uint8_t transceivers = NONE; int transceiver_pid = EINVAL; + +registered_t reg[TRANSCEIVER_MAX_REGISTERED]; + +/* packet buffers */ radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; +uint8_t *cc1100_data_buffer; static volatile uint8_t rx_buffer_pos = 0; static volatile uint8_t transceiver_buffer_pos = 0; +/* transceiver stack */ const char transceiver_stack[TRANSCEIVER_STACK_SIZE]; +/* function prototypes */ void run(void); -void receive_packet(void); +void receive_packet(transceiver_type_t t); void transceiver_init(transceiver_type_t t) { - switch (t) { - case CC110: - transceiver = t; - cc1100_init(); - break; - default: - puts("Invalid transceiver type"); - break; + uint8_t i; + for (i = 0; i < TRANSCEIVER_MAX_REGISTERED; i++) { + reg[i].transceiver = NULL; + reg[i].pid = NULL; + } + if (t & CC1100) { + transceiver |= t; + cc1100_init(); + cc1100_data_buffer = malloc(TRANSCEIVER_BUFFER_SIZE * CC100_MAX_DATA_LENGTH); + } + else { + puts("Invalid transceiver type"); } } void transceiver_start(void) { transceiver_pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING, run, "Transceiver"); - if (transceiver < 0) { + if (transceiver_pid < 0) { puts("Error creating transceiver thread"); } } +uint8_t transceiver_register(transceiver_type_t t, int pid) { + uint8_t i; + for (i = 0; ((i < TRANSCEIVER_MAX_REGISTERED) && (reg[i].transceiver != NULL)); i++); + + if (i >= TRANSCEIVER_MAX_REGISTERED) { + return ENOMEM; + } + else { + reg[i].transceiver = t: + reg[i].pid = pid; + } +} + +/*------------------------------------------------------------------------------------*/ +/* Internal functions */ +/*------------------------------------------------------------------------------------*/ void run(void) { msg m; while (1) { @@ -45,6 +74,10 @@ void run(void) { case RCV_PKT: receive_packet(); break; + case SND_PKT: + send_packet_t spkt = (send_packet_t*) m.cotent.ptr; + send_packet(spkt.transceiver, spkt.packet); + break; default: DEBUG("Unknown message received\n"); break; @@ -53,26 +86,36 @@ void run(void) { } -void receive_packet(void) { - switch (transveiver) { - case CC1100: - dINT(); - rx_buffer_pos = cc1100_rx_buffer_next - 1; - cc1100_packet_t p = cc1100_rx_buffer[rx_buffer_pos].packet; - radio_info_t info = cc1100_rx_buffer[rx_buffer_pos].info; - radio_packet_t trans_p = transceiver_buffer[transceiver_buffer_pos]; +void receive_packet(transceiver_type_t t) { + uint8_t i = 0; + msg m; - trans_p.src = p.phy_src; - trans_p.dst = p.address; - trans_p.rssi = info.rssi; - trans_p.lqi = info.lqi; - trans_p.length = p.length; - - /* TODO: copy payload */ - eINT(); - break; - default: - puts("Invalid transceiver type"); - break; + if (t & CC1100) { + dINT(); + rx_buffer_pos = cc1100_rx_buffer_next - 1; + cc1100_packet_t p = cc1100_rx_buffer[rx_buffer_pos].packet; + radio_info_t info = cc1100_rx_buffer[rx_buffer_pos].info; + radio_packet_t trans_p = transceiver_buffer[transceiver_buffer_pos]; + + trans_p.src = p.phy_src; + trans_p.dst = p.address; + trans_p.rssi = info.rssi; + trans_p.lqi = info.lqi; + trans_p.length = p.length; + memcpy(cc1100_data_buffer[transceiver_buffer_pos], p.data, CC1100_MAX_DATA_LENGTH); + eINT(); + + while (reg[i].transceiver != NULL) { + if (reg[i].transceiver & t) { + msg_send(&m, reg[i].pid, false); + } + i++: + } + } + else { + puts("Invalid transceiver type"); } } + +uint8_t send_packet(transceiver_type_t t, radio_packet_t *pkt) { +} From 8d5a4890e46db4eaac9c420e9735c35a23d01a56 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 23 Nov 2010 11:37:13 +0100 Subject: [PATCH 094/115] * revised buffer and messaging management of transceiver * renamed cc1100_ng header --- Jamrules | 1 + drivers/cc110x_ng/cc1100.c | 35 +++-- drivers/cc110x_ng/{cc1100.h => cc1100_ng.h} | 6 +- drivers/cc110x_ng/cc1100_spi.c | 2 +- sys/Jamfile | 2 +- sys/include/transceiver.h | 22 +++- sys/transceiver.c | 137 +++++++++++++------- 7 files changed, 133 insertions(+), 72 deletions(-) rename drivers/cc110x_ng/{cc1100.h => cc1100_ng.h} (97%) diff --git a/Jamrules b/Jamrules index 8dbb5f62c7..13a6088f0c 100644 --- a/Jamrules +++ b/Jamrules @@ -73,3 +73,4 @@ HDRS += [ FPath $(TOP) projects $(PROJECT) ] ; # drivers HDRS += [ FPath $(TOP) drivers include ] ; HDRS += [ FPath $(TOP) drivers cc110x ] ; +HDRS += [ FPath $(TOP) drivers cc110x_ng ] ; diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 87cf951bc0..85ea601d2b 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -1,6 +1,6 @@ #include -#include +#include #include #include #include @@ -25,11 +25,12 @@ cc1100_statistic_t cc1100_statistic; volatile cc1100_flags rflags; ///< Radio control flags volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state -volatile uint8_t cc1100_rx_buffer_next; ///< Next packet in RX queue +static volatile uint8_t rx_buffer_next; ///< Next packet in RX queue static uint8_t radio_address; ///< Radio address static uint8_t radio_channel; ///< Radio channel +static int transceiver_pid; ///< the transceiver thread pid /* internal function prototypes */ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); @@ -41,8 +42,10 @@ static void write_register(uint8_t r, uint8_t value); /*---------------------------------------------------------------------------*/ // Radio Driver API /*---------------------------------------------------------------------------*/ -void cc1100_init(void) { - cc1100_rx_buffer_next = 0; +void cc1100_init(int tpid) { + transceiver_pid = tpid; + + rx_buffer_next = 0; /* Initialize SPI */ cc1100_spi_init(); @@ -95,7 +98,7 @@ void cc1100_rx_handler(void) { rflags.MAN_WOR = 0; cc1100_statistic.packets_in++; - res = receive_packet((uint8_t*)&(cc1100_rx_buffer[cc1100_rx_buffer_next].packet), sizeof(cc1100_packet_t)); + res = receive_packet((uint8_t*)&(cc1100_rx_buffer[rx_buffer_next].packet), sizeof(cc1100_packet_t)); if (res) { // If we are sending a burst, don't accept packets. @@ -106,8 +109,8 @@ void cc1100_rx_handler(void) { cc1100_statistic.packets_in_while_tx++; return; } - cc1100_rx_buffer[cc1100_rx_buffer_next].rssi = rflags.RSSI; - cc1100_rx_buffer[cc1100_rx_buffer_next].lqi = rflags.LQI; + cc1100_rx_buffer[rx_buffer_next].rssi = rflags.RSSI; + cc1100_rx_buffer[rx_buffer_next].lqi = rflags.LQI; // Valid packet. After a wake-up, the radio should be in IDLE. // So put CC1100 to RX for WOR_TIMEOUT (have to manually put @@ -118,13 +121,15 @@ void cc1100_rx_handler(void) { hwtimer_wait(IDLE_TO_RX_TIME); radio_state = RADIO_RX; - if (++cc1100_rx_buffer_next == RX_BUF_SIZE) { - cc1100_rx_buffer_next = 0; + if (++rx_buffer_next == RX_BUF_SIZE) { + rx_buffer_next = 0; + } + if (transceiver_pid) { + msg m; + m.type = (uint16_t) RCV_PKT; + m.content.value = TRANSCEIVER_CC1100; + msg_send_int(&m, transceiver_pid); } - msg m; - m.type = (uint16_t) RCV_PKT; - m.content.ptr = NULL; - msg_send_int(&m, transceiver_pid); return; } else @@ -156,6 +161,10 @@ void cc1100_rx_handler(void) { } } +uint8_t cc1100_get_buffer_pos(void) { + return (rx_buffer_next-1); +} + uint8_t cc1100_set_address(radio_address_t address) { if ((address < MIN_UID) || (address > MAX_UID)) { return 0; diff --git a/drivers/cc110x_ng/cc1100.h b/drivers/cc110x_ng/cc1100_ng.h similarity index 97% rename from drivers/cc110x_ng/cc1100.h rename to drivers/cc110x_ng/cc1100_ng.h index 90f327592e..cc42454fc9 100644 --- a/drivers/cc110x_ng/cc1100.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -83,12 +83,12 @@ enum radio_mode { extern rx_buffer_t cc1100_rx_buffer[]; -extern volatile uint8_t cc1100_rx_buffer_next; - -void cc1100_init(void); +void cc1100_init(int transceiver_pid); void cc1100_rx_handler(void); +uint8_t cc1100_get_buffer_pos(void); + void cc1100_setup_rx_mode(void); void cc1100_switch_to_rx(void); void cc1100_wakeup_from_rx(void); diff --git a/drivers/cc110x_ng/cc1100_spi.c b/drivers/cc110x_ng/cc1100_spi.c index 010f31a5ed..0eaa70d572 100644 --- a/drivers/cc110x_ng/cc1100_spi.c +++ b/drivers/cc110x_ng/cc1100_spi.c @@ -44,7 +44,7 @@ and the mailinglist (subscription via web site) #include -#include +#include #include #include #include diff --git a/sys/Jamfile b/sys/Jamfile index f236e498ea..a8ff40a5c0 100644 --- a/sys/Jamfile +++ b/sys/Jamfile @@ -35,7 +35,7 @@ Module auto_init : auto_init.c ; Module chardev_thread : chardev_thread.c : ringbuffer ; Module uart0 : uart0.c : ringbuffer chardev_thread ; -Module transceiver : transceiver.c : oneway_malloc ; +Module transceiver : transceiver.c ; SubInclude TOP sys net ; SubInclude TOP sys lib ; diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index 4a60a42fe5..b8a44a91fb 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -1,6 +1,8 @@ #ifndef TRANSCEIVER_H #define TRANSCEIVER_H +#include + /* Packets to buffer */ #define TRANSCEIVER_BUFFER_SIZE (10) /* Stack size for transceiver thread */ @@ -13,20 +15,27 @@ * @brief Message types for transceiver interface */ enum transceiver_msg_type_t { + /* Packet types for driver <-> transceiver communication */ RCV_PKT, ///< packet was received + + /* Packet types for transceiver <-> upper layer communication */ + PKT_PENDING, ///< packet pending in transceiver buffer SND_PKT, ///< request for sending a packet SND_ACK, ///< request for sending an acknowledgement - SWITCH_RX, ///< switch receiver to RX sate - POWERDOWN, ///< power down receiver + SWITCH_RX, ///< switch transceiver to RX sate + POWERDOWN, ///< power down transceiver + + /* Error messages */ + ENOBUFFER, }; /** * @brief All supported transceivers */ typedef enum { - NONE, ///< Invalid - CC1100, ///< CC110X transceivers - CC1020 ///< CC1020 transceivers + TRANSCEIVER_NONE, ///< Invalid + TRANSCEIVER_CC1100, ///< CC110X transceivers + TRANSCEIVER_CC1020 ///< CC1020 transceivers } transceiver_type_t; /** @@ -42,7 +51,6 @@ typedef struct { radio_packet_t *packet; } send_packet_t; -extern int transceiver_pid; extern void *transceiver_rx_buffer; /** @@ -55,7 +63,7 @@ void transceiver_init(transceiver_type_t transceivers); /** * @brief Runs the transceiver thread */ -void transceiver_start(void); +int transceiver_start(void); /** * @brief register a thread for events from certain transceivers diff --git a/sys/transceiver.c b/sys/transceiver.c index 5c11f7fd72..85d4b6b4d6 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -1,21 +1,34 @@ #include #include -#include +#include + +#include +#include #include +#define PAYLOAD_SIZE (0) + /* supported transceivers */ -#include +#ifdef MODULE_CC110X_NG +#include +#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE) + #undef PAYLOAD_SIZE + #define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH;) +#endif +#endif + +//#define ENABLE_DEBUG (1) +#include /* used transceiver types */ -uint8_t transceivers = NONE; -int transceiver_pid = EINVAL; +transceiver_type_t transceivers = TRANSCEIVER_NONE; registered_t reg[TRANSCEIVER_MAX_REGISTERED]; /* packet buffers */ radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; -uint8_t *cc1100_data_buffer; +uint8_t data_buffer[TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE]; static volatile uint8_t rx_buffer_pos = 0; static volatile uint8_t transceiver_buffer_pos = 0; @@ -24,42 +37,47 @@ static volatile uint8_t transceiver_buffer_pos = 0; const char transceiver_stack[TRANSCEIVER_STACK_SIZE]; /* function prototypes */ -void run(void); -void receive_packet(transceiver_type_t t); +static void run(void); +static void receive_packet(transceiver_type_t t); +static void receive_cc1100_packet(radio_packet_t *trans_p); +static uint8_t send_packet(transceiver_type_t t, radio_packet_t *pkt); void transceiver_init(transceiver_type_t t) { uint8_t i; for (i = 0; i < TRANSCEIVER_MAX_REGISTERED; i++) { - reg[i].transceiver = NULL; - reg[i].pid = NULL; + reg[i].transceivers = TRANSCEIVER_NONE; + reg[i].pid = 0; } - if (t & CC1100) { - transceiver |= t; - cc1100_init(); - cc1100_data_buffer = malloc(TRANSCEIVER_BUFFER_SIZE * CC100_MAX_DATA_LENGTH); + if (t & TRANSCEIVER_CC1100) { + transceivers |= t; } else { puts("Invalid transceiver type"); } } -void transceiver_start(void) { - transceiver_pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING, run, "Transceiver"); - if (transceiver_pid < 0) { +int transceiver_start(void) { + int pid = thread_create((char*) transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING, run, "Transceiver"); + if (pid < 0) { puts("Error creating transceiver thread"); } + else if (transceivers & TRANSCEIVER_CC1100) { + cc1100_init(pid); + } + return pid; } uint8_t transceiver_register(transceiver_type_t t, int pid) { uint8_t i; - for (i = 0; ((i < TRANSCEIVER_MAX_REGISTERED) && (reg[i].transceiver != NULL)); i++); + for (i = 0; ((i < TRANSCEIVER_MAX_REGISTERED) && (reg[i].transceivers != TRANSCEIVER_NONE)); i++); if (i >= TRANSCEIVER_MAX_REGISTERED) { return ENOMEM; } else { - reg[i].transceiver = t: + reg[i].transceivers |= t; reg[i].pid = pid; + return 1; } } @@ -68,15 +86,16 @@ uint8_t transceiver_register(transceiver_type_t t, int pid) { /*------------------------------------------------------------------------------------*/ void run(void) { msg m; + send_packet_t *spkt; while (1) { msg_receive(&m); - switch (m) { + switch (m.type) { case RCV_PKT: - receive_packet(); + receive_packet(m.content.value); break; case SND_PKT: - send_packet_t spkt = (send_packet_t*) m.cotent.ptr; - send_packet(spkt.transceiver, spkt.packet); + spkt = (send_packet_t*) m.content.ptr; + send_packet(spkt->transceivers, spkt->packet); break; default: DEBUG("Unknown message received\n"); @@ -86,36 +105,60 @@ void run(void) { } -void receive_packet(transceiver_type_t t) { +static void receive_packet(transceiver_type_t t) { uint8_t i = 0; msg m; - - if (t & CC1100) { - dINT(); - rx_buffer_pos = cc1100_rx_buffer_next - 1; - cc1100_packet_t p = cc1100_rx_buffer[rx_buffer_pos].packet; - radio_info_t info = cc1100_rx_buffer[rx_buffer_pos].info; - radio_packet_t trans_p = transceiver_buffer[transceiver_buffer_pos]; - - trans_p.src = p.phy_src; - trans_p.dst = p.address; - trans_p.rssi = info.rssi; - trans_p.lqi = info.lqi; - trans_p.length = p.length; - memcpy(cc1100_data_buffer[transceiver_buffer_pos], p.data, CC1100_MAX_DATA_LENGTH); - eINT(); - - while (reg[i].transceiver != NULL) { - if (reg[i].transceiver & t) { - msg_send(&m, reg[i].pid, false); - } - i++: - } + + transceiver_buffer_pos = 0; + while ((transceiver_buffer[transceiver_buffer_pos].processing) && (transceiver_buffer_pos < TRANSCEIVER_BUFFER_SIZE)) + { + transceiver_buffer_pos++; + } + if (transceiver_buffer_pos >= TRANSCEIVER_BUFFER_SIZE) { + m.type = ENOBUFFER; + m.content.value = t; } else { - puts("Invalid transceiver type"); + radio_packet_t trans_p = transceiver_buffer[transceiver_buffer_pos]; + m.type = PKT_PENDING; + + if (t & TRANSCEIVER_CC1100) { + receive_cc1100_packet(&trans_p); + } + else { + puts("Invalid transceiver type"); + return; + } + } + + while (reg[i].transceivers != TRANSCEIVER_NONE) { + if (reg[i].transceivers & t) { + m.content.value = transceiver_buffer_pos; + msg_send(&m, reg[i].pid, false); + } + i++; } } -uint8_t send_packet(transceiver_type_t t, radio_packet_t *pkt) { +static void receive_cc1100_packet(radio_packet_t *trans_p) { + /* disable interrupts while copying packet */ + dINT(); + rx_buffer_pos = cc1100_get_buffer_pos(); + cc1100_packet_t p = cc1100_rx_buffer[rx_buffer_pos].packet; + + trans_p->src = p.phy_src; + trans_p->dst = p.address; + trans_p->rssi = cc1100_rx_buffer[rx_buffer_pos].rssi; + trans_p->lqi = cc1100_rx_buffer[rx_buffer_pos].lqi; + trans_p->length = p.length; + memcpy((void*) &(cc1100_data_buffer[transceiver_buffer_pos]), p.data, CC1100_MAX_DATA_LENGTH); + eINT(); + + trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]); +} + + +static uint8_t send_packet(transceiver_type_t t, radio_packet_t *pkt) { + + return res; } From d5b65f9866c00bc3fae78b1223fa01af1b176c35 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 24 Nov 2010 11:08:15 +0100 Subject: [PATCH 095/115] * changed interval for laser --- projects/laser/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/projects/laser/main.c b/projects/laser/main.c index 7a5c0a1872..902ffc3088 100644 --- a/projects/laser/main.c +++ b/projects/laser/main.c @@ -2,6 +2,7 @@ #include #include #include +#include int main(void) { @@ -12,6 +13,8 @@ int main(void) puts("LaSeR: Longterm Sensor Reader initialized."); puts("Printing \"temperature in °C;relative humidity;temperature compensated relative humidity\"."); puts(""); + + ltc4150_start(); while (1) { success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); @@ -22,6 +25,6 @@ int main(void) printf("%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp); } LED_RED_TOGGLE; - swtimer_usleep(1000 * 1000); + swtimer_usleep(60 * 1000*1000); } } From d950fbcf8195ad274eb7e97cb11b108fb7f09c3b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 24 Nov 2010 11:20:27 +0100 Subject: [PATCH 096/115] * CC1100_NG still not working! * added some debugging stuff * changed cc1100_ng <-> transceiver msg api * revised test application --- drivers/cc110x_ng/cc1100-defaultSettings.c | 4 +- drivers/cc110x_ng/cc1100.c | 33 +++++++++---- projects/cc110x/main.c | 3 +- projects/test_cc110x_ng/Jamfile | 2 +- projects/test_cc110x_ng/main.c | 36 +++++++++++++- sys/include/transceiver.h | 3 +- sys/transceiver.c | 57 ++++++++++++++++------ 7 files changed, 107 insertions(+), 31 deletions(-) diff --git a/drivers/cc110x_ng/cc1100-defaultSettings.c b/drivers/cc110x_ng/cc1100-defaultSettings.c index f19214914a..1ea81b18f0 100644 --- a/drivers/cc110x_ng/cc1100-defaultSettings.c +++ b/drivers/cc110x_ng/cc1100-defaultSettings.c @@ -121,8 +121,8 @@ char cc1100_conf[] = { 0x00 // padding to 4 bytes }; -static uint8_t pa_table_index = PATABLE; ///< Current PATABLE Index -static uint8_t pa_table[] = { ///< PATABLE with available output powers +uint8_t pa_table_index = PATABLE; ///< Current PATABLE Index +uint8_t pa_table[] = { ///< PATABLE with available output powers 0x00, ///< -52 dBm 0x03, ///< -30 dBm 0x0D, ///< -20 dBm diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 85ea601d2b..ef2e87659a 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -11,6 +11,10 @@ #include #include +//#define ENABLE_DEBUG (1) +#include +#include + #define RX_BUF_SIZE (10) /* some externals */ @@ -35,6 +39,7 @@ static int transceiver_pid; ///< the transceiver thread /* internal function prototypes */ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length); +static int rd_set_mode(int mode); static void reset(void); static void power_up_reset(void); static void write_register(uint8_t r, uint8_t value); @@ -44,6 +49,7 @@ static void write_register(uint8_t r, uint8_t value); /*---------------------------------------------------------------------------*/ void cc1100_init(int tpid) { transceiver_pid = tpid; + DEBUG("Transceiver PID: %i\n", transceiver_pid); rx_buffer_next = 0; @@ -72,6 +78,10 @@ void cc1100_init(int tpid) { /* Set default channel number */ radio_channel = CC1100_DEFAULT_CHANNR; + DEBUG("CC1100 initialized and set to channel %i\n", radio_channel); + + // Switch to desired mode (WOR or RX) + rd_set_mode(RADIO_MODE_ON); } void cc1100_disable_interrupts(void) { @@ -99,8 +109,7 @@ void cc1100_rx_handler(void) { cc1100_statistic.packets_in++; res = receive_packet((uint8_t*)&(cc1100_rx_buffer[rx_buffer_next].packet), sizeof(cc1100_packet_t)); - if (res) - { + if (res) { // If we are sending a burst, don't accept packets. // Only ACKs are processed (for stopping the burst). // Same if state machine is in TX lock. @@ -121,15 +130,18 @@ void cc1100_rx_handler(void) { hwtimer_wait(IDLE_TO_RX_TIME); radio_state = RADIO_RX; - if (++rx_buffer_next == RX_BUF_SIZE) { - rx_buffer_next = 0; - } + /* notify transceiver thread if any */ if (transceiver_pid) { msg m; - m.type = (uint16_t) RCV_PKT; - m.content.value = TRANSCEIVER_CC1100; + m.type = (uint16_t) RCV_PKT_CC1100; + m.content.value = rx_buffer_next; msg_send_int(&m, transceiver_pid); } + + /* shift to next buffer element */ + if (++rx_buffer_next == RX_BUF_SIZE) { + rx_buffer_next = 0; + } return; } else @@ -192,6 +204,7 @@ void cc1100_switch_to_rx(void) { void cc1100_wakeup_from_rx(void) { if (radio_state != RADIO_RX) return; + DEBUG("CC1100 going to idle\n"); cc1100_spi_strobe(CC1100_SIDLE); radio_state = RADIO_IDLE; } @@ -210,8 +223,8 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { uint8_t packetLength = 0; /* Any bytes available in RX FIFO? */ - if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) - { + if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { + LED_GREEN_TOGGLE; // Read length byte (first byte in RX FIFO) packetLength = cc1100_spi_read_reg(CC1100_RXFIFO); // Read data from RX FIFO and store in rxBuffer @@ -248,6 +261,7 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { } /* no bytes in RX FIFO */ else { + LED_RED_TOGGLE; // RX FIFO get automatically flushed if return value is false return 0; } @@ -312,6 +326,7 @@ static int rd_set_mode(int mode) { switch (mode) { case RADIO_MODE_ON: + DEBUG("Enabling rx mode\n"); cc1100_init_interrupts(); // Enable interrupts cc1100_setup_rx_mode(); // Set chip to desired mode break; diff --git a/projects/cc110x/main.c b/projects/cc110x/main.c index e515189602..4847b47cb3 100644 --- a/projects/cc110x/main.c +++ b/projects/cc110x/main.c @@ -58,7 +58,7 @@ int main(void) // radio stack cc1100_init(); cc1100_set_packet_handler(4, protocol_handler); - cc1100_set_channel(10); + cc1100_set_channel(0); // cc1100_set_output_power(5); printf("cc1100..[OK]\n"); @@ -72,6 +72,7 @@ int main(void) puts("."); int result = cc1100_send_csmaca(1, 4, 2, i, sizeof(i)); printf("%i\n", result); + hwtimer_wait(1000 * 1000); } #else cc1100_set_address(1); diff --git a/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile index 29f79da92f..28bf8b6f1a 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 ps rtc posix_io uart0 ; +Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init ; UseModule test_cc110x_ng ; diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index 25fbfdaa8b..070d695fb8 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -1,16 +1,36 @@ +#include #include #include #include #include #include #include +#include +#include #define SHELL_STACK_SIZE (4096) +#define RADIO_STACK_SIZE (4096) +int radio_pid; char shell_stack_buffer[SHELL_STACK_SIZE]; +char radio_stack_buffer[RADIO_STACK_SIZE]; + +void trans_run(char *unused); +void trans_register(char *unused); shell_t shell; -const shell_command_t sc[] = {{NULL, NULL, NULL}}; +const shell_command_t sc[] = { + {"trun", "Run the transceiver thread", trans_run}, + {"treg", "Register application for CC1100", trans_register}, + {NULL, NULL, NULL}}; + +void trans_run(char *unused) { + puts("NOP"); +} + +void trans_register(char *unused) { + transceiver_register(TRANSCEIVER_CC1100, active_thread->pid); +} void shell_runner(void) { shell_init(&shell, sc, uart0_readc, uart0_putc); @@ -18,11 +38,23 @@ void shell_runner(void) { shell_run(&shell); } +void radio(void) { + msg m; + + while (1) { + msg_receive(&m); + printf("Received message of type %i: %lX\n", m.type, m.content.value); + } +} + int main(void) { thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); + thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); + transceiver_init(TRANSCEIVER_CC1100); + transceiver_start(); while (1) { - LED_GREEN_TOGGLE; +// LED_GREEN_TOGGLE; hwtimer_wait(1000 * 1000); } } diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index b8a44a91fb..fd5d0004b3 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -16,7 +16,8 @@ */ enum transceiver_msg_type_t { /* Packet types for driver <-> transceiver communication */ - RCV_PKT, ///< packet was received + RCV_PKT_CC1020, ///< packet was received by CC1020 transceiver + RCV_PKT_CC1100, ///< packet was received by CC1100 transceiver /* Packet types for transceiver <-> upper layer communication */ PKT_PENDING, ///< packet pending in transceiver buffer diff --git a/sys/transceiver.c b/sys/transceiver.c index 85d4b6b4d6..5110f498a4 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -14,11 +14,11 @@ #include #if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE) #undef PAYLOAD_SIZE - #define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH;) + #define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH) #endif #endif -//#define ENABLE_DEBUG (1) +#define ENABLE_DEBUG (1) #include /* used transceiver types */ @@ -34,11 +34,11 @@ static volatile uint8_t rx_buffer_pos = 0; static volatile uint8_t transceiver_buffer_pos = 0; /* transceiver stack */ -const char transceiver_stack[TRANSCEIVER_STACK_SIZE]; +char transceiver_stack[TRANSCEIVER_STACK_SIZE]; /* function prototypes */ static void run(void); -static void receive_packet(transceiver_type_t t); +static void receive_packet(uint16_t type, uint8_t pos); static void receive_cc1100_packet(radio_packet_t *trans_p); static uint8_t send_packet(transceiver_type_t t, radio_packet_t *pkt); @@ -57,11 +57,12 @@ void transceiver_init(transceiver_type_t t) { } int transceiver_start(void) { - int pid = thread_create((char*) transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING, run, "Transceiver"); + int pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-3, CREATE_STACKTEST, run, "Transceiver"); if (pid < 0) { puts("Error creating transceiver thread"); } else if (transceivers & TRANSCEIVER_CC1100) { + DEBUG("Transceiver started for CC1100\n"); cc1100_init(pid); } return pid; @@ -69,7 +70,9 @@ int transceiver_start(void) { uint8_t transceiver_register(transceiver_type_t t, int pid) { uint8_t i; - for (i = 0; ((i < TRANSCEIVER_MAX_REGISTERED) && (reg[i].transceivers != TRANSCEIVER_NONE)); i++); + for (i = 0; ((reg[i].pid != pid) && + (i < TRANSCEIVER_MAX_REGISTERED) && + (reg[i].transceivers != TRANSCEIVER_NONE)); i++); if (i >= TRANSCEIVER_MAX_REGISTERED) { return ENOMEM; @@ -77,6 +80,7 @@ uint8_t transceiver_register(transceiver_type_t t, int pid) { else { reg[i].transceivers |= t; reg[i].pid = pid; + DEBUG("Thread %i registered for %i\n", reg[i].pid, reg[i].transceivers); return 1; } } @@ -87,11 +91,16 @@ uint8_t transceiver_register(transceiver_type_t t, int pid) { void run(void) { msg m; send_packet_t *spkt; + while (1) { + DEBUG("Waiting for messages\n"); + /* TODO: check here if message was lost, while handling the last */ msg_receive(&m); + DEBUG("Transceiver: Message received\n"); switch (m.type) { - case RCV_PKT: - receive_packet(m.content.value); + case RCV_PKT_CC1020: + case RCV_PKT_CC1100: + receive_packet(m.type, m.content.value); break; case SND_PKT: spkt = (send_packet_t*) m.content.ptr; @@ -105,24 +114,41 @@ void run(void) { } -static void receive_packet(transceiver_type_t t) { +static void receive_packet(uint16_t type, uint8_t pos) { uint8_t i = 0; + transceiver_type_t t; + rx_buffer_pos = pos; msg m; - - transceiver_buffer_pos = 0; + + switch (type) { + case RCV_PKT_CC1020: + t = TRANSCEIVER_CC1020; + break; + case RCV_PKT_CC1100: + t = TRANSCEIVER_CC1100; + break; + default: + t = TRANSCEIVER_NONE; + break; + } + + /* search first free position in transceiver buffer */ while ((transceiver_buffer[transceiver_buffer_pos].processing) && (transceiver_buffer_pos < TRANSCEIVER_BUFFER_SIZE)) { transceiver_buffer_pos++; } + /* no buffer left */ if (transceiver_buffer_pos >= TRANSCEIVER_BUFFER_SIZE) { + /* inform upper layers of lost packet */ m.type = ENOBUFFER; m.content.value = t; } + /* copy packet and handle it */ else { radio_packet_t trans_p = transceiver_buffer[transceiver_buffer_pos]; m.type = PKT_PENDING; - if (t & TRANSCEIVER_CC1100) { + if (type == RCV_PKT_CC1100) { receive_cc1100_packet(&trans_p); } else { @@ -131,6 +157,8 @@ static void receive_packet(transceiver_type_t t) { } } + /* finally notify waiting upper layers + * this is done non-blocking, so packets can get lost */ while (reg[i].transceivers != TRANSCEIVER_NONE) { if (reg[i].transceivers & t) { m.content.value = transceiver_buffer_pos; @@ -143,7 +171,6 @@ static void receive_packet(transceiver_type_t t) { static void receive_cc1100_packet(radio_packet_t *trans_p) { /* disable interrupts while copying packet */ dINT(); - rx_buffer_pos = cc1100_get_buffer_pos(); cc1100_packet_t p = cc1100_rx_buffer[rx_buffer_pos].packet; trans_p->src = p.phy_src; @@ -151,7 +178,7 @@ static void receive_cc1100_packet(radio_packet_t *trans_p) { trans_p->rssi = cc1100_rx_buffer[rx_buffer_pos].rssi; trans_p->lqi = cc1100_rx_buffer[rx_buffer_pos].lqi; trans_p->length = p.length; - memcpy((void*) &(cc1100_data_buffer[transceiver_buffer_pos]), p.data, CC1100_MAX_DATA_LENGTH); + memcpy((void*) &(data_buffer[transceiver_buffer_pos]), p.data, CC1100_MAX_DATA_LENGTH); eINT(); trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]); @@ -159,6 +186,6 @@ static void receive_cc1100_packet(radio_packet_t *trans_p) { static uint8_t send_packet(transceiver_type_t t, radio_packet_t *pkt) { - + uint8_t res = 0; return res; } From 4ebfaefce12011e7424721fae2b804c39909fa1b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 24 Nov 2010 13:47:31 +0100 Subject: [PATCH 097/115] * additionally debug for transceiver receiving functions * added set_channel function to cc110x_ng --- drivers/cc110x_ng/cc1100.c | 11 ++++++++++- drivers/cc110x_ng/cc1100_ng.h | 1 + sys/transceiver.c | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index ef2e87659a..60dce6bf89 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -77,7 +77,7 @@ void cc1100_init(int tpid) { rflags.WOR_RST = 0; /* Set default channel number */ - radio_channel = CC1100_DEFAULT_CHANNR; + cc1100_set_channel(CC1100_DEFAULT_CHANNR); DEBUG("CC1100 initialized and set to channel %i\n", radio_channel); // Switch to desired mode (WOR or RX) @@ -214,6 +214,15 @@ void switch_to_pwd(void) { cc1100_spi_strobe(CC1100_SPWD); radio_state = RADIO_PWD; } + +uint8_t cc1100_set_channel(uint8_t channr) { + if (channr > MAX_CHANNR) { + return 0; + } + write_register(CC1100_CHANNR, channr*10); + radio_channel = channr; + return 1; +} /*---------------------------------------------------------------------------*/ /* Internal functions */ /*---------------------------------------------------------------------------*/ diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index cc42454fc9..f20d1dbbab 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -95,4 +95,5 @@ void cc1100_wakeup_from_rx(void); void cc1100_switch_to_pwd(void); void cc1100_disable_interrupts(void); +uint8_t cc1100_set_channel(uint8_t channr); #endif diff --git a/sys/transceiver.c b/sys/transceiver.c index 5110f498a4..b820b71a30 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -120,6 +120,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { rx_buffer_pos = pos; msg m; + DEBUG("Packet received\n"); switch (type) { case RCV_PKT_CC1020: t = TRANSCEIVER_CC1020; @@ -162,6 +163,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { while (reg[i].transceivers != TRANSCEIVER_NONE) { if (reg[i].transceivers & t) { m.content.value = transceiver_buffer_pos; + DEBUG("Notify thread %i\n", reg[i].pid); msg_send(&m, reg[i].pid, false); } i++; @@ -169,6 +171,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { } static void receive_cc1100_packet(radio_packet_t *trans_p) { + DEBUG("Handling CC1100 packet\n"); /* disable interrupts while copying packet */ dINT(); cc1100_packet_t p = cc1100_rx_buffer[rx_buffer_pos].packet; @@ -181,6 +184,7 @@ static void receive_cc1100_packet(radio_packet_t *trans_p) { memcpy((void*) &(data_buffer[transceiver_buffer_pos]), p.data, CC1100_MAX_DATA_LENGTH); eINT(); + DEBUG("Packet was from %hu to %hu, size: %u\n", trans_p->src, trans_p->dst, trans_p->length); trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]); } From 7b344c37c139a7b293143f3d02ba1116b7d58071 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 24 Nov 2010 14:23:32 +0100 Subject: [PATCH 098/115] * see diff ;) --- drivers/cc110x_ng/cc1100-internal.h | 4 +- drivers/cc110x_ng/cc1100.c | 75 +++++++++++++++++++++++++++++ drivers/cc110x_ng/cc1100_ng.h | 2 + 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/drivers/cc110x_ng/cc1100-internal.h b/drivers/cc110x_ng/cc1100-internal.h index 54ddabde70..bf7309db9f 100644 --- a/drivers/cc110x_ng/cc1100-internal.h +++ b/drivers/cc110x_ng/cc1100-internal.h @@ -79,8 +79,8 @@ and the mailinglist (subscription via web site) #define GDO0 (0x01) ///< Bitmask (=00000001) for reading GDO0 (current value on GDO0 pin) in PKTSTATUS status register. #define TXFIFO_UNDERFLOW (0x80) ///< Bitmask (=10000000) for reading TXFIFO_UNDERFLOW in TXBYTES status register. #define BYTES_IN_TXFIFO (0x7F) ///< Bitmask (=01111111) for reading NUM_TXBYTES in TXBYTES status register. -#define RXFIFO_OVERFLOW (0x80) ///< Bitmask (=10000000) for reading RXFIFO_OVERFLOW in RXBYTES status register. -#define BYTES_IN_RXFIFO (0x7F) ///< Bitmask (=01111111) for reading NUM_RXBYTES in RXBYTES status register. +#define RXFIFO_OVERFLOW (0xBF) ///< Bitmask (=10000000) for reading RXFIFO_OVERFLOW in RXBYTES status register. +#define BYTES_IN_RXFIFO (0xFF) ///< Bitmask (=01111111) for reading NUM_RXBYTES in RXBYTES status register. /** @} */ /** diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 60dce6bf89..39b871a00d 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -209,6 +209,79 @@ void cc1100_wakeup_from_rx(void) { radio_state = RADIO_IDLE; } +char* cc1100_get_marc_state(void) +{ + uint8_t state; + + // Save old radio state + uint8_t old_state = radio_state; + + // Read content of status register + state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE; + + // Make sure in IDLE state. + // Only goes to IDLE if state was RX/WOR + cc1100_wakeup_from_rx(); + + // Have to put radio back to WOR/RX if old radio state + // was WOR/RX, otherwise no action is necessary + if (old_state == RADIO_WOR || old_state == RADIO_RX) { + cc1100_switch_to_rx(); + } + + switch (state) + { + // Note: it is not possible to read back the SLEEP or XOFF state numbers + // because setting CSn low will make the chip enter the IDLE mode from the + // SLEEP (0) or XOFF (2) states. + case 1: return "IDLE"; + case 3: case 4: case 5: return "MANCAL"; + case 6: case 7: return "FS_WAKEUP"; + case 8: case 12: return "CALIBRATE"; + case 9: case 10: case 11: return "SETTLING"; + case 13: case 14: case 15: return "RX"; + case 16: return "TXRX_SETTLING"; + case 17: return "RXFIFO_OVERFLOW"; + case 18: return "FSTXON"; + case 19: case 20: return "TX"; + case 21: return "RXTX_SETTLING"; + case 22: return "TXFIFO_UNDERFLOW"; + default: return "UNKNOWN"; + } +} + +char* cc1100_state_to_text(uint8_t state) { + switch (state) + { + case RADIO_UNKNOWN: + return "Unknown"; + case RADIO_AIR_FREE_WAITING: + return "CS"; + case RADIO_WOR: + return "WOR"; + case RADIO_IDLE: + return "IDLE"; + case RADIO_SEND_BURST: + return "TX BURST"; + case RADIO_RX: + return "RX"; + case RADIO_SEND_ACK: + return "TX ACK"; + case RADIO_PWD: + return "PWD"; + default: + return "unknown"; + } +} + + +void cc1100_print_config(void) { + char buf[8]; + printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); + printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); + printf("Current channel number: %u\r\n", radio_channel); +} + void switch_to_pwd(void) { cc1100_wakeup_from_rx(); cc1100_spi_strobe(CC1100_SPWD); @@ -231,6 +304,8 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { uint8_t status[2]; uint8_t packetLength = 0; + printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); + printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); /* Any bytes available in RX FIFO? */ if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { LED_GREEN_TOGGLE; diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index f20d1dbbab..ffc9053e37 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -96,4 +96,6 @@ void cc1100_switch_to_pwd(void); void cc1100_disable_interrupts(void); uint8_t cc1100_set_channel(uint8_t channr); + +void cc1100_print_config(void); #endif From d378ee19305929ff082a392e4a05ac312dc9a06b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 24 Nov 2010 21:45:38 +0100 Subject: [PATCH 099/115] * added getter and setter for the channel to transceiver * receiving now seems to work... --- drivers/cc110x_ng/cc1100.c | 18 ++++++++------ drivers/cc110x_ng/cc1100_ng.h | 1 + projects/test_cc110x_ng/main.c | 33 +++++++++++++++++++------ sys/include/transceiver.h | 6 +++-- sys/transceiver.c | 44 ++++++++++++++++++++++++++++------ 5 files changed, 79 insertions(+), 23 deletions(-) diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 39b871a00d..146e56d5ff 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -203,14 +203,15 @@ void cc1100_switch_to_rx(void) { } void cc1100_wakeup_from_rx(void) { - if (radio_state != RADIO_RX) return; + if (radio_state != RADIO_RX) { + return; + } DEBUG("CC1100 going to idle\n"); cc1100_spi_strobe(CC1100_SIDLE); radio_state = RADIO_IDLE; } -char* cc1100_get_marc_state(void) -{ +char* cc1100_get_marc_state(void) { uint8_t state; // Save old radio state @@ -289,12 +290,17 @@ void switch_to_pwd(void) { } uint8_t cc1100_set_channel(uint8_t channr) { - if (channr > MAX_CHANNR) { + uint8_t state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE; + if (state != 1) && ((channr > MAX_CHANNR)) { return 0; } write_register(CC1100_CHANNR, channr*10); radio_channel = channr; - return 1; + return radio_channel; +} + +uint8_t cc1100_get_channel(void) { + return radio_channel; } /*---------------------------------------------------------------------------*/ /* Internal functions */ @@ -304,8 +310,6 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { uint8_t status[2]; uint8_t packetLength = 0; - printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); - printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); /* Any bytes available in RX FIFO? */ if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { LED_GREEN_TOGGLE; diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index ffc9053e37..ebd7d9f6e0 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -96,6 +96,7 @@ void cc1100_switch_to_pwd(void); void cc1100_disable_interrupts(void); uint8_t cc1100_set_channel(uint8_t channr); +uint8_t cc1100_get_channel(void); void cc1100_print_config(void); #endif diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index 070d695fb8..ef3b878ce7 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -11,25 +11,42 @@ #define SHELL_STACK_SIZE (4096) #define RADIO_STACK_SIZE (4096) +int transceiver_pid; int radio_pid; char shell_stack_buffer[SHELL_STACK_SIZE]; char radio_stack_buffer[RADIO_STACK_SIZE]; -void trans_run(char *unused); +void trans_chan(char *chan); void trans_register(char *unused); +msg mesg; +transceiver_command_t tcmd; + shell_t shell; const shell_command_t sc[] = { - {"trun", "Run the transceiver thread", trans_run}, + {"tchan", "Set the channel for cc1100", trans_chan}, {"treg", "Register application for CC1100", trans_register}, {NULL, NULL, NULL}}; -void trans_run(char *unused) { - puts("NOP"); +void trans_chan(char *chan) { + unsigned int c; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &c; + mesg.content.ptr = (char*) &tcmd; + if (sscanf(chan, "tchan %u", &c)) { + printf("Trying to set channel %u\n", c); + mesg.type = SET_CHANNEL; + } + else { + mesg.type = GET_CHANNEL; + } + msg_send_receive(&mesg, &mesg, transceiver_pid); + printf("Got channel: %hu\n", c); } void trans_register(char *unused) { - transceiver_register(TRANSCEIVER_CC1100, active_thread->pid); + transceiver_register(TRANSCEIVER_CC1100, radio_pid); } void shell_runner(void) { @@ -49,9 +66,11 @@ void radio(void) { int main(void) { thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); - thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); + radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); transceiver_init(TRANSCEIVER_CC1100); - transceiver_start(); + transceiver_pid = transceiver_start(); + extern void cc1100_set_channel(uint8_t c); + cc1100_set_channel(6); while (1) { // LED_GREEN_TOGGLE; diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index fd5d0004b3..9668cb73ae 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -25,6 +25,8 @@ enum transceiver_msg_type_t { SND_ACK, ///< request for sending an acknowledgement SWITCH_RX, ///< switch transceiver to RX sate POWERDOWN, ///< power down transceiver + GET_CHANNEL, ///< Get current channel + SET_CHANNEL, ///< Set a new channel /* Error messages */ ENOBUFFER, @@ -49,8 +51,8 @@ typedef struct { typedef struct { transceiver_type_t transceivers; - radio_packet_t *packet; -} send_packet_t; + void *data; +} transceiver_command_t;; extern void *transceiver_rx_buffer; diff --git a/sys/transceiver.c b/sys/transceiver.c index b820b71a30..87c6cacaab 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -40,7 +40,9 @@ char transceiver_stack[TRANSCEIVER_STACK_SIZE]; static void run(void); static void receive_packet(uint16_t type, uint8_t pos); static void receive_cc1100_packet(radio_packet_t *trans_p); -static uint8_t send_packet(transceiver_type_t t, radio_packet_t *pkt); +static uint8_t send_packet(transceiver_type_t t, void *pkt); +static uint8_t get_channel(transceiver_type_t t); +static uint8_t set_channel(transceiver_type_t t, void *channel); void transceiver_init(transceiver_type_t t) { uint8_t i; @@ -90,11 +92,9 @@ uint8_t transceiver_register(transceiver_type_t t, int pid) { /*------------------------------------------------------------------------------------*/ void run(void) { msg m; - send_packet_t *spkt; + transceiver_command_t *cmd; while (1) { - DEBUG("Waiting for messages\n"); - /* TODO: check here if message was lost, while handling the last */ msg_receive(&m); DEBUG("Transceiver: Message received\n"); switch (m.type) { @@ -103,8 +103,18 @@ void run(void) { receive_packet(m.type, m.content.value); break; case SND_PKT: - spkt = (send_packet_t*) m.content.ptr; - send_packet(spkt->transceivers, spkt->packet); + cmd = (transceiver_command_t*) m.content.ptr; + send_packet(cmd->transceivers, cmd->data); + break; + case GET_CHANNEL: + cmd = (transceiver_command_t*) m.content.ptr; + *((uint8_t*) cmd->data) = get_channel(cmd->transceivers); + msg_reply(&m, &m); + break; + case SET_CHANNEL: + cmd = (transceiver_command_t*) m.content.ptr; + *((uint8_t*) cmd->data) = set_channel(cmd->transceivers, cmd->data); + msg_reply(&m, &m); break; default: DEBUG("Unknown message received\n"); @@ -151,6 +161,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { if (type == RCV_PKT_CC1100) { receive_cc1100_packet(&trans_p); + m.content.value = transceiver_buffer_pos; } else { puts("Invalid transceiver type"); @@ -189,7 +200,26 @@ static void receive_cc1100_packet(radio_packet_t *trans_p) { } -static uint8_t send_packet(transceiver_type_t t, radio_packet_t *pkt) { +static uint8_t send_packet(transceiver_type_t t, void *pkt) { uint8_t res = 0; return res; } + +static uint8_t set_channel(transceiver_type_t t, void *channel) { + uint8_t c = *((uint8_t*) channel); + switch (t) { + case TRANSCEIVER_CC1100: + return cc1100_set_channel(c); + default: + return -1; + } +} + +static uint8_t get_channel(transceiver_type_t t) { + switch (t) { + case TRANSCEIVER_CC1100: + return cc1100_get_channel(); + default: + return -1; + } +} From d40052e24b4108efe307d3aff24c93a98dc63c5a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 25 Nov 2010 16:22:46 +0100 Subject: [PATCH 100/115] * cosmetics --- core/include/tcb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/tcb.h b/core/include/tcb.h index 95f9412539..75c9e9aeb6 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -24,7 +24,7 @@ #define STATUS_NOT_FOUND (0x0000) #define STATUS_ON_RUNQUEUE (0x0001) #define STATUS_RUNNING (0x0002) + STATUS_ON_RUNQUEUE -#define STATUS_PENDING (0x0004) + STATUS_ON_RUNQUEUE +#define STATUS_PENDING (0x0004) + STATUS_ON_RUNQUEUE #define STATUS_STOPPED (0x0008) #define STATUS_SLEEPING (0x0010) #define STATUS_MUTEX_BLOCKED (0x0020) From 29cb64a37ef737110ab18ed4d4b6e3bdd62796f3 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 26 Nov 2010 10:23:46 +0100 Subject: [PATCH 101/115] * NOTE: simple packet exchange using cc110x_ng seems to work now * added TX functions to cc110x_ng driver and transceiver module * split up cc1100_ng functions to more files * added address asignment and request functions to driver and transceiver module --- drivers/cc110x_ng/Jamfile | 2 +- drivers/cc110x_ng/cc1100-defaultSettings.c | 14 -- drivers/cc110x_ng/cc1100-rx.c | 153 +++++++++++++++++++ drivers/cc110x_ng/cc1100-tx.c | 77 ++++++++++ drivers/cc110x_ng/cc1100.c | 165 ++------------------- drivers/cc110x_ng/cc1100_ng.h | 21 ++- projects/test_cc110x_ng/main.c | 58 ++++++-- sys/include/transceiver.h | 2 + sys/transceiver.c | 137 +++++++++++++++-- 9 files changed, 432 insertions(+), 197 deletions(-) create mode 100644 drivers/cc110x_ng/cc1100-rx.c create mode 100644 drivers/cc110x_ng/cc1100-tx.c diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index 93d557720e..55995d823d 100755 --- a/drivers/cc110x_ng/Jamfile +++ b/drivers/cc110x_ng/Jamfile @@ -29,5 +29,5 @@ SubDir TOP drivers cc110x_ng ; HDRS += $(TOP)/drivers/cc110x_ng ; -Module cc110x_ng : cc1100.c cc1100-defaultSettings.c cc1100_spi.c : board_cc1100 swtimer gpioint ; +Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c cc1100_spi.c : board_cc1100 swtimer gpioint ; diff --git a/drivers/cc110x_ng/cc1100-defaultSettings.c b/drivers/cc110x_ng/cc1100-defaultSettings.c index 1ea81b18f0..d4ae620c8b 100644 --- a/drivers/cc110x_ng/cc1100-defaultSettings.c +++ b/drivers/cc110x_ng/cc1100-defaultSettings.c @@ -137,19 +137,5 @@ uint8_t pa_table[] = { ///< PATABLE with available output powers 0xC3 ///< +10 dBm }; // If PATABLE is changed in size, adjust MAX_OUTPUT_POWER definition in CC1100 interface! -static int8_t pa_table_dBm[] = { ///< Values of the PATABLE in dBm - -52, - -30, - -20, - -15, - -10, - -5, - -1, - 0, - 5, - 7, - 9, - 10 -}; /** @} */ diff --git a/drivers/cc110x_ng/cc1100-rx.c b/drivers/cc110x_ng/cc1100-rx.c new file mode 100644 index 0000000000..91346a6343 --- /dev/null +++ b/drivers/cc110x_ng/cc1100-rx.c @@ -0,0 +1,153 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); +static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length); + +rx_buffer_t cc1100_rx_buffer[RX_BUF_SIZE]; ///< RX buffer +volatile uint8_t rx_buffer_next; ///< Next packet in RX queue + +void cc1100_rx_handler(void) { + uint8_t res = 0; + + // Possible packet received, RX -> IDLE (0.1 us) + rflags.CAA = 0; + rflags.MAN_WOR = 0; + cc1100_statistic.packets_in++; + + res = receive_packet((uint8_t*)&(cc1100_rx_buffer[rx_buffer_next].packet), sizeof(cc1100_packet_t)); + if (res) { + // If we are sending a burst, don't accept packets. + // Only ACKs are processed (for stopping the burst). + // Same if state machine is in TX lock. + if (radio_state == RADIO_SEND_BURST || rflags.TX) + { + cc1100_statistic.packets_in_while_tx++; + return; + } + cc1100_rx_buffer[rx_buffer_next].rssi = rflags.RSSI; + cc1100_rx_buffer[rx_buffer_next].lqi = rflags.LQI; + + // Valid packet. After a wake-up, the radio should be in IDLE. + // So put CC1100 to RX for WOR_TIMEOUT (have to manually put + // the radio back to sleep/WOR). + cc1100_spi_write_reg(CC1100_MCSM0, 0x08); // Turn off FS-Autocal + cc1100_spi_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME (until end of packet) + cc1100_spi_strobe(CC1100_SRX); + hwtimer_wait(IDLE_TO_RX_TIME); + radio_state = RADIO_RX; + + /* notify transceiver thread if any */ + if (transceiver_pid) { + msg m; + m.type = (uint16_t) RCV_PKT_CC1100; + m.content.value = rx_buffer_next; + msg_send_int(&m, transceiver_pid); + } + + /* shift to next buffer element */ + if (++rx_buffer_next == RX_BUF_SIZE) { + rx_buffer_next = 0; + } + return; + } + else + { + // No ACK received so TOF is unpredictable + rflags.TOF = 0; + + // CRC false or RX buffer full -> clear RX FIFO in both cases + cc1100_spi_strobe(CC1100_SIDLE); // Switch to IDLE (should already be)... + cc1100_spi_strobe(CC1100_SFRX); // ...for flushing the RX FIFO + + // If packet interrupted this nodes send call, + // don't change anything after this point. + if (radio_state == RADIO_AIR_FREE_WAITING) + { + cc1100_spi_strobe(CC1100_SRX); + hwtimer_wait(IDLE_TO_RX_TIME); + return; + } + // If currently sending, exit here (don't go to RX/WOR) + if (radio_state == RADIO_SEND_BURST) + { + cc1100_statistic.packets_in_while_tx++; + return; + } + + // No valid packet, so go back to RX/WOR as soon as possible + cc1100_switch_to_rx(); + } +} + + +static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { + uint8_t status[2]; + uint8_t packetLength = 0; + + /* Any bytes available in RX FIFO? */ + if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { + LED_GREEN_TOGGLE; + // Read length byte (first byte in RX FIFO) + packetLength = cc1100_spi_read_reg(CC1100_RXFIFO); + // Read data from RX FIFO and store in rxBuffer + if (packetLength <= length) + { + // Put length byte at first position in RX Buffer + rxBuffer[0] = packetLength; + + // Read the rest of the packet + cc1100_spi_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); + + // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) + cc1100_spi_readburst_reg(CC1100_RXFIFO, (char*)status, 2); + + // Store RSSI value of packet + rflags.RSSI = status[I_RSSI]; + + // MSB of LQI is the CRC_OK bit + rflags.CRC = (status[I_LQI] & CRC_OK) >> 7; + if (!rflags.CRC) { + cc1100_statistic.packets_in_crc_fail++; + } + + // Bit 0-6 of LQI indicates the link quality (LQI) + rflags.LQI = status[I_LQI] & LQI_EST; + + return rflags.CRC; + } + /* too many bytes in FIFO */ + else { + // RX FIFO get automatically flushed if return value is false + return 0; + } + } + /* no bytes in RX FIFO */ + else { + LED_RED_TOGGLE; + // RX FIFO get automatically flushed if return value is false + return 0; + } +} + +static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length) { + uint8_t pkt_len_cfg = cc1100_spi_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; + if (pkt_len_cfg == VARIABLE_PKTLEN) + { + return receive_packet_variable(rxBuffer, length); + } + // Fixed packet length not supported. + // RX FIFO get automatically flushed if return value is false + return 0; +} + + diff --git a/drivers/cc110x_ng/cc1100-tx.c b/drivers/cc110x_ng/cc1100-tx.c new file mode 100644 index 0000000000..72a595d50a --- /dev/null +++ b/drivers/cc110x_ng/cc1100-tx.c @@ -0,0 +1,77 @@ +#include + +#include +#include +#include +#include +#include + +#include + +#include + +uint8_t cc1100_send(cc1100_packet_t *packet) { + puts("Going to send\n"); + volatile uint32_t abort_count; + uint8_t size; + /* TODO: burst sending */ + radio_state = RADIO_SEND_BURST; + rflags.LL_ACK = 0; + + /* + * Number of bytes to send is: + * length of phy payload (packet->length) + * + size of length field (1 byte) + */ + size = packet->length + 1; + + // The number of bytes to be transmitted must be smaller + // or equal to PACKET_LENGTH (62 bytes). So the receiver + // can put the whole packet in its RX-FIFO (with appended + // packet status bytes). + if (size > PACKET_LENGTH) { + return 0; + } + + packet->phy_src = cc1100_get_address(); + + // Disables RX interrupt etc. + cc1100_before_send(); + + // But CC1100 in IDLE mode to flush the FIFO + cc1100_spi_strobe(CC1100_SIDLE); + // Flush TX FIFO to be sure it is empty + cc1100_spi_strobe(CC1100_SFTX); + // Write packet into TX FIFO + cc1100_spi_writeburst_reg(CC1100_TXFIFO, (char*) packet, size); + // Switch to TX mode + abort_count = 0; + unsigned int cpsr = disableIRQ(); + cc1100_spi_strobe(CC1100_STX); + // Wait for GDO2 to be set -> sync word transmitted + while (cc1100_get_gdo2() == 0) { + abort_count++; + if (abort_count > CC1100_SYNC_WORD_TX_TIME) { + // Abort waiting. CC1100 maybe in wrong mode + // e.g. sending preambles for always + puts("[CC1100 TX] fatal error\n"); + break; + } + } + restoreIRQ(cpsr); + // Wait for GDO2 to be cleared -> end of packet + while (cc1100_get_gdo2() != 0); + + // Experimental - TOF Measurement + cc1100_after_send(); + cc1100_statistic.raw_packets_out++; + + // Store number of transmission retries + rflags.TX = 0; + + // Go to mode after TX (CONST_RX -> RX, WOR -> WOR) + cc1100_switch_to_rx(); + + return true; +} + diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 146e56d5ff..3ed3659f76 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -7,15 +5,10 @@ #include #include -#include #include -#include //#define ENABLE_DEBUG (1) #include -#include - -#define RX_BUF_SIZE (10) /* some externals */ extern uint8_t pa_table[]; ///< PATABLE with available output powers @@ -23,22 +16,17 @@ extern uint8_t pa_table_index; ///< Current PATABLE Index /* global variables */ -rx_buffer_t cc1100_rx_buffer[RX_BUF_SIZE]; ///< RX buffer cc1100_statistic_t cc1100_statistic; volatile cc1100_flags rflags; ///< Radio control flags volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state -static volatile uint8_t rx_buffer_next; ///< Next packet in RX queue - static uint8_t radio_address; ///< Radio address static uint8_t radio_channel; ///< Radio channel -static int transceiver_pid; ///< the transceiver thread pid +int transceiver_pid; ///< the transceiver thread pid /* internal function prototypes */ -static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); -static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length); static int rd_set_mode(int mode); static void reset(void); static void power_up_reset(void); @@ -100,84 +88,15 @@ void cc1100_gdo2_irq(void) { cc1100_rx_handler(); } -void cc1100_rx_handler(void) { - uint8_t res = 0; - - // Possible packet received, RX -> IDLE (0.1 us) - rflags.CAA = 0; - rflags.MAN_WOR = 0; - cc1100_statistic.packets_in++; - - res = receive_packet((uint8_t*)&(cc1100_rx_buffer[rx_buffer_next].packet), sizeof(cc1100_packet_t)); - if (res) { - // If we are sending a burst, don't accept packets. - // Only ACKs are processed (for stopping the burst). - // Same if state machine is in TX lock. - if (radio_state == RADIO_SEND_BURST || rflags.TX) - { - cc1100_statistic.packets_in_while_tx++; - return; - } - cc1100_rx_buffer[rx_buffer_next].rssi = rflags.RSSI; - cc1100_rx_buffer[rx_buffer_next].lqi = rflags.LQI; - - // Valid packet. After a wake-up, the radio should be in IDLE. - // So put CC1100 to RX for WOR_TIMEOUT (have to manually put - // the radio back to sleep/WOR). - cc1100_spi_write_reg(CC1100_MCSM0, 0x08); // Turn off FS-Autocal - cc1100_spi_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME (until end of packet) - cc1100_spi_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - radio_state = RADIO_RX; - - /* notify transceiver thread if any */ - if (transceiver_pid) { - msg m; - m.type = (uint16_t) RCV_PKT_CC1100; - m.content.value = rx_buffer_next; - msg_send_int(&m, transceiver_pid); - } - - /* shift to next buffer element */ - if (++rx_buffer_next == RX_BUF_SIZE) { - rx_buffer_next = 0; - } - return; - } - else - { - // No ACK received so TOF is unpredictable - rflags.TOF = 0; - - // CRC false or RX buffer full -> clear RX FIFO in both cases - cc1100_spi_strobe(CC1100_SIDLE); // Switch to IDLE (should already be)... - cc1100_spi_strobe(CC1100_SFRX); // ...for flushing the RX FIFO - - // If packet interrupted this nodes send call, - // don't change anything after this point. - if (radio_state == RADIO_AIR_FREE_WAITING) - { - cc1100_spi_strobe(CC1100_SRX); - hwtimer_wait(IDLE_TO_RX_TIME); - return; - } - // If currently sending, exit here (don't go to RX/WOR) - if (radio_state == RADIO_SEND_BURST) - { - cc1100_statistic.packets_in_while_tx++; - return; - } - - // No valid packet, so go back to RX/WOR as soon as possible - cc1100_switch_to_rx(); - } -} - uint8_t cc1100_get_buffer_pos(void) { return (rx_buffer_next-1); } -uint8_t cc1100_set_address(radio_address_t address) { +radio_address_t cc1100_get_address() { + return radio_address; +} + +radio_address_t cc1100_set_address(radio_address_t address) { if ((address < MIN_UID) || (address > MAX_UID)) { return 0; } @@ -188,7 +107,7 @@ uint8_t cc1100_set_address(radio_address_t address) { } radio_address = id; - return 0; + return radio_address; } void cc1100_setup_rx_mode(void) { @@ -277,7 +196,6 @@ char* cc1100_state_to_text(uint8_t state) { void cc1100_print_config(void) { - char buf[8]; printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); printf("Current channel number: %u\r\n", radio_channel); @@ -289,9 +207,10 @@ void switch_to_pwd(void) { radio_state = RADIO_PWD; } -uint8_t cc1100_set_channel(uint8_t channr) { +/*---------------------------------------------------------------------------*/ +int16_t cc1100_set_channel(uint8_t channr) { uint8_t state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE; - if (state != 1) && ((channr > MAX_CHANNR)) { + if ((state != 1) && (channr > MAX_CHANNR)) { return 0; } write_register(CC1100_CHANNR, channr*10); @@ -299,72 +218,10 @@ uint8_t cc1100_set_channel(uint8_t channr) { return radio_channel; } -uint8_t cc1100_get_channel(void) { +int16_t cc1100_get_channel(void) { return radio_channel; } -/*---------------------------------------------------------------------------*/ -/* Internal functions */ -/*---------------------------------------------------------------------------*/ -static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { - uint8_t status[2]; - uint8_t packetLength = 0; - - /* Any bytes available in RX FIFO? */ - if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { - LED_GREEN_TOGGLE; - // Read length byte (first byte in RX FIFO) - packetLength = cc1100_spi_read_reg(CC1100_RXFIFO); - // Read data from RX FIFO and store in rxBuffer - if (packetLength <= length) - { - // Put length byte at first position in RX Buffer - rxBuffer[0] = packetLength; - - // Read the rest of the packet - cc1100_spi_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); - - // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) - cc1100_spi_readburst_reg(CC1100_RXFIFO, (char*)status, 2); - - // Store RSSI value of packet - rflags.RSSI = status[I_RSSI]; - - // MSB of LQI is the CRC_OK bit - rflags.CRC = (status[I_LQI] & CRC_OK) >> 7; - if (!rflags.CRC) { - cc1100_statistic.packets_in_crc_fail++; - } - - // Bit 0-6 of LQI indicates the link quality (LQI) - rflags.LQI = status[I_LQI] & LQI_EST; - - return rflags.CRC; - } - /* too many bytes in FIFO */ - else { - // RX FIFO get automatically flushed if return value is false - return 0; - } - } - /* no bytes in RX FIFO */ - else { - LED_RED_TOGGLE; - // RX FIFO get automatically flushed if return value is false - return 0; - } -} - -static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length) { - uint8_t pkt_len_cfg = cc1100_spi_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; - if (pkt_len_cfg == VARIABLE_PKTLEN) - { - return receive_packet_variable(rxBuffer, length); - } - // Fixed packet length not supported. - // RX FIFO get automatically flushed if return value is false - return 0; -} /*---------------------------------------------------------------------------*/ // CC1100 reset functionality diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index ebd7d9f6e0..83ad0c1122 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -6,6 +6,8 @@ #include #include +#define RX_BUF_SIZE (10) + #define CC1100_MAX_DATA_LENGTH (58) #define CC1100_BROADCAST_ADDRESS (0x00) ///< CC1100 broadcast address @@ -19,6 +21,9 @@ #define MIN_OUTPUT_POWER (0) ///< Minimum output power value #define MAX_OUTPUT_POWER (11) ///< Maximum output power value +#define PACKET_LENGTH (0x3E) ///< Packet length = 62 Bytes. +#define CC1100_SYNC_WORD_TX_TIME (90000) // loop count (max. timeout ~ 15 ms) to wait for + // sync word to be transmitted (GDO2 from low to high) /** * @name Defines used as state values for state machine * @{ @@ -83,10 +88,19 @@ enum radio_mode { extern rx_buffer_t cc1100_rx_buffer[]; +extern volatile uint8_t rx_buffer_next; ///< Next packet in RX queue + +extern volatile uint8_t radio_state; ///< Radio state +extern cc1100_statistic_t cc1100_statistic; + +int transceiver_pid; ///< the transceiver thread pid + void cc1100_init(int transceiver_pid); void cc1100_rx_handler(void); +uint8_t cc1100_send(cc1100_packet_t *pkt); + uint8_t cc1100_get_buffer_pos(void); void cc1100_setup_rx_mode(void); @@ -95,8 +109,11 @@ void cc1100_wakeup_from_rx(void); void cc1100_switch_to_pwd(void); void cc1100_disable_interrupts(void); -uint8_t cc1100_set_channel(uint8_t channr); -uint8_t cc1100_get_channel(void); +int16_t cc1100_set_channel(uint8_t channr); +int16_t cc1100_get_channel(void); + +radio_address_t cc1100_set_address(radio_address_t addr); +radio_address_t cc1100_get_address(void); void cc1100_print_config(void); #endif diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index ef3b878ce7..f5df8f26e4 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -12,12 +12,12 @@ #define RADIO_STACK_SIZE (4096) int transceiver_pid; -int radio_pid; char shell_stack_buffer[SHELL_STACK_SIZE]; char radio_stack_buffer[RADIO_STACK_SIZE]; void trans_chan(char *chan); -void trans_register(char *unused); +void trans_addr(char *addr); +void trans_send(char *mesg); msg mesg; transceiver_command_t tcmd; @@ -25,28 +25,58 @@ transceiver_command_t tcmd; shell_t shell; const shell_command_t sc[] = { {"tchan", "Set the channel for cc1100", trans_chan}, - {"treg", "Register application for CC1100", trans_register}, + {"taddr", "Set the address for cc1100", trans_addr}, + {"tsnd", "Sends a CC1100 packet", trans_send}, {NULL, NULL, NULL}}; void trans_chan(char *chan) { - unsigned int c; + int c; tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &c; mesg.content.ptr = (char*) &tcmd; - if (sscanf(chan, "tchan %u", &c)) { - printf("Trying to set channel %u\n", c); + if (sscanf(chan, "tchan %i", &c) > 0) { + printf("Trying to set channel %i\n", c); mesg.type = SET_CHANNEL; } else { mesg.type = GET_CHANNEL; } msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("Got channel: %hu\n", c); + printf("Got channel: %i\n", c); } -void trans_register(char *unused) { - transceiver_register(TRANSCEIVER_CC1100, radio_pid); +void trans_addr(char *addr) { + int a; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &a; + mesg.content.ptr = (char*) &tcmd; + if (sscanf(addr, "taddr %i", &a) > 0) { + printf("Trying to set address %i\n", a); + mesg.type = SET_ADDRESS; + } + else { + mesg.type = GET_ADDRESS; + } + msg_send_receive(&mesg, &mesg, transceiver_pid); + printf("Got address: %i\n", a); +} + +void trans_send(char *text) { + radio_packet_t p; + uint32_t response; + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + + p.length = 10; + p.dst = 5; + + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + msg_send_receive(&mesg, &mesg, transceiver_pid); + response = mesg.content.value; + printf("Packet send: %lu\n", response); } void shell_runner(void) { @@ -65,12 +95,12 @@ void radio(void) { } int main(void) { - thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); + int radio_pid; + thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); - transceiver_init(TRANSCEIVER_CC1100); - transceiver_pid = transceiver_start(); - extern void cc1100_set_channel(uint8_t c); - cc1100_set_channel(6); + transceiver_init(TRANSCEIVER_CC1100); + transceiver_pid = transceiver_start(); + transceiver_register(TRANSCEIVER_CC1100, radio_pid); while (1) { // LED_GREEN_TOGGLE; diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index 9668cb73ae..cecd8896a4 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -27,6 +27,8 @@ enum transceiver_msg_type_t { POWERDOWN, ///< power down transceiver GET_CHANNEL, ///< Get current channel SET_CHANNEL, ///< Set a new channel + GET_ADDRESS, ///< Get the radio address + SET_ADDRESS, ///< Set the radio address /* Error messages */ ENOBUFFER, diff --git a/sys/transceiver.c b/sys/transceiver.c index 87c6cacaab..ee1ff38ded 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -6,6 +6,7 @@ #include #include +#include #define PAYLOAD_SIZE (0) @@ -21,29 +22,38 @@ #define ENABLE_DEBUG (1) #include +/*------------------------------------------------------------------------------------*/ /* used transceiver types */ transceiver_type_t transceivers = TRANSCEIVER_NONE; +/* registered upper layer threads */ registered_t reg[TRANSCEIVER_MAX_REGISTERED]; /* packet buffers */ radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; uint8_t data_buffer[TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE]; +uint32_t response; ///< response bytes for messages to upper layer threads + static volatile uint8_t rx_buffer_pos = 0; static volatile uint8_t transceiver_buffer_pos = 0; /* transceiver stack */ char transceiver_stack[TRANSCEIVER_STACK_SIZE]; +/*------------------------------------------------------------------------------------*/ /* function prototypes */ static void run(void); static void receive_packet(uint16_t type, uint8_t pos); static void receive_cc1100_packet(radio_packet_t *trans_p); static uint8_t send_packet(transceiver_type_t t, void *pkt); -static uint8_t get_channel(transceiver_type_t t); -static uint8_t set_channel(transceiver_type_t t, void *channel); +static int16_t get_channel(transceiver_type_t t); +static int16_t set_channel(transceiver_type_t t, void *channel); +static int16_t get_address(transceiver_type_t t); +static int16_t set_address(transceiver_type_t t, void *address); +/*------------------------------------------------------------------------------------*/ +/* Transceiver init */ void transceiver_init(transceiver_type_t t) { uint8_t i; for (i = 0; i < TRANSCEIVER_MAX_REGISTERED; i++) { @@ -58,6 +68,7 @@ void transceiver_init(transceiver_type_t t) { } } +/* Start the transceiver thread */ int transceiver_start(void) { int pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-3, CREATE_STACKTEST, run, "Transceiver"); if (pid < 0) { @@ -70,6 +81,7 @@ int transceiver_start(void) { return pid; } +/* Register an upper layer thread */ uint8_t transceiver_register(transceiver_type_t t, int pid) { uint8_t i; for (i = 0; ((reg[i].pid != pid) && @@ -90,12 +102,19 @@ uint8_t transceiver_register(transceiver_type_t t, int pid) { /*------------------------------------------------------------------------------------*/ /* Internal functions */ /*------------------------------------------------------------------------------------*/ + +/* + * @brief The main thread run, receiving and processing messages in an infinite + * loop + */ void run(void) { msg m; transceiver_command_t *cmd; while (1) { msg_receive(&m); + /* only makes sense for messages for upper layers */ + cmd = (transceiver_command_t*) m.content.ptr; DEBUG("Transceiver: Message received\n"); switch (m.type) { case RCV_PKT_CC1020: @@ -103,17 +122,24 @@ void run(void) { receive_packet(m.type, m.content.value); break; case SND_PKT: - cmd = (transceiver_command_t*) m.content.ptr; - send_packet(cmd->transceivers, cmd->data); + response = send_packet(cmd->transceivers, cmd->data); + m.content.value = response; + msg_reply(&m, &m); break; case GET_CHANNEL: - cmd = (transceiver_command_t*) m.content.ptr; - *((uint8_t*) cmd->data) = get_channel(cmd->transceivers); + *((int16_t*) cmd->data) = get_channel(cmd->transceivers); msg_reply(&m, &m); break; case SET_CHANNEL: - cmd = (transceiver_command_t*) m.content.ptr; - *((uint8_t*) cmd->data) = set_channel(cmd->transceivers, cmd->data); + *((int16_t*) cmd->data) = set_channel(cmd->transceivers, cmd->data); + msg_reply(&m, &m); + break; + case GET_ADDRESS: + *((int16_t*) cmd->data) = get_address(cmd->transceivers); + msg_reply(&m, &m); + break; + case SET_ADDRESS: + *((int16_t*) cmd->data) = set_address(cmd->transceivers, cmd->data); msg_reply(&m, &m); break; default: @@ -123,7 +149,14 @@ void run(void) { } } - +/*------------------------------------------------------------------------------------*/ +/* + * @brief Processes a packet received by any transceiver device + * + * @param type The message type to determine which device has received the + * packet + * @param pos The current device driver's buffer position + */ static void receive_packet(uint16_t type, uint8_t pos) { uint8_t i = 0; transceiver_type_t t; @@ -181,6 +214,11 @@ static void receive_packet(uint16_t type, uint8_t pos) { } } +/* + * @brief process packets from CC1100 + * + * @param trans_p The current entry in the transceiver buffer + */ static void receive_cc1100_packet(radio_packet_t *trans_p) { DEBUG("Handling CC1100 packet\n"); /* disable interrupts while copying packet */ @@ -199,13 +237,47 @@ static void receive_cc1100_packet(radio_packet_t *trans_p) { trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]); } - +/*------------------------------------------------------------------------------------*/ +/* + * @brief Sends a radio packet to the receiver + * + * @param t The transceiver device + * @param pkt Generic pointer to the packet + * + * @return 1 on success, 0 otherwise + */ static uint8_t send_packet(transceiver_type_t t, void *pkt) { uint8_t res = 0; + radio_packet_t p = *((radio_packet_t*) pkt); + cc1100_packet_t cc1100_pkt; + + switch (t) { + case TRANSCEIVER_CC1100: + /* TODO: prepare and send packet here */ + cc1100_pkt.length = p.length; + cc1100_pkt.address = p.dst; + cc1100_pkt.flags = 0; + memcpy(cc1100_pkt.data, p.data, p.length); + + res = cc1100_send(&cc1100_pkt); + break; + default: + puts("Unknown transceiver"); + break; + } return res; } -static uint8_t set_channel(transceiver_type_t t, void *channel) { +/*------------------------------------------------------------------------------------*/ +/* + * @brief Sets the radio channel for any transceiver device + * + * @param t The transceiver device + * @param channel The channel to be set + * + * @return The radio channel AFTER calling the set command, -1 on error + */ +static int16_t set_channel(transceiver_type_t t, void *channel) { uint8_t c = *((uint8_t*) channel); switch (t) { case TRANSCEIVER_CC1100: @@ -215,7 +287,14 @@ static uint8_t set_channel(transceiver_type_t t, void *channel) { } } -static uint8_t get_channel(transceiver_type_t t) { +/* + * @brief Get the radio channel of any transceiver device + * + * @param t The transceiver device + * + * @return The current radio channel of the transceiver, -1 on error + */ +static int16_t get_channel(transceiver_type_t t) { switch (t) { case TRANSCEIVER_CC1100: return cc1100_get_channel(); @@ -223,3 +302,37 @@ static uint8_t get_channel(transceiver_type_t t) { return -1; } } +/*------------------------------------------------------------------------------------*/ +/* + * @brief Get the current address of transceiver device + * + * @param t The transciever device + * + * @return The configured address of the device, -1 on error + */ +static int16_t get_address(transceiver_type_t t) { + switch (t) { + case TRANSCEIVER_CC1100: + return cc1100_get_address(); + default: + return -1; + } +} + +/* + * @brief Set the address of the transceiver device + * + * @param t The transceiver device + * @param address Generic pointer to the address to set + * + * @return The new radio address of the device + */ +static int16_t set_address(transceiver_type_t t, void *address) { + radio_address_t addr = *((radio_address_t*) address); + switch (t) { + case TRANSCEIVER_CC1100: + return cc1100_set_address(addr); + default: + return -1; + } +} From cb1d5c7ab3642306bafb62d65706b84a2822fbe2 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 26 Nov 2010 13:15:01 +0100 Subject: [PATCH 102/115] * added circular index buffer implementation --- core/Jamfile | 2 +- core/cib.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ core/include/cib.h | 15 +++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 core/cib.c create mode 100644 core/include/cib.h diff --git a/core/Jamfile b/core/Jamfile index 2787dcbc76..6e0fae63bf 100644 --- a/core/Jamfile +++ b/core/Jamfile @@ -28,7 +28,7 @@ SubDir TOP core ; Module core : kernel_init.c sched.c mutex.c msg.c queue.c - clist.c thread.c bitarithm.c ; + clist.c thread.c bitarithm.c cib.c ; Module hwtimer : hwtimer.c : hwtimer_cpu ; diff --git a/core/cib.c b/core/cib.c new file mode 100644 index 0000000000..252abbde47 --- /dev/null +++ b/core/cib.c @@ -0,0 +1,47 @@ +typedef struct cib { + unsigned int read_count; + unsigned int write_count; + unsigned int complement; +} cib_t; + +void cib_init(cib_t *cib, unsigned int size) { + cib->read_count = 0; + cib->write_count = 0; + cib->complement = 0-size; +} + +int cib_avail (cib_t *cib) { + return cib->write_count - cib->read_count; +} + +int cib_get(cib_t *cib) { + int avail = cib_avail (cib); + + if (avail > 0) { + return cib->read_count++ & ~cib->complement; + } + + return -1; +} + +int cib_put(cib_t *cib) { + int avail = cib_avail (cib); + + if ((int)(avail + cib->complement) < 0 ) { + return cib->write_count++ & ~(cib->complement); + } + + return -1; +} + +/* +int main() { + cib_t cib; + + cib_init(&cib, 0); + + int res = cib_get(&cib); + + printf("%i\n", res); +} +*/ diff --git a/core/include/cib.h b/core/include/cib.h new file mode 100644 index 0000000000..7ef179280d --- /dev/null +++ b/core/include/cib.h @@ -0,0 +1,15 @@ +#ifndef __CIB_H +#define __CIB_H + +typedef struct cib_t { + unsigned int read_count; + unsigned int write_count; + unsigned int complement; +} cib_t; + +void cib_init(cib_t *cib, unsigned int size); +int cib_get(cib_t *cib); +int cib_put(cib_t *cib); +int cib_avail(cib_t *cib); + +#endif /* __CIB_H */ From cb79a7a237fddc639f3475b25573d4b9c589959d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 26 Nov 2010 14:21:48 +0100 Subject: [PATCH 103/115] * first implementation of msg queues --- core/include/msg.h | 8 ++++- core/include/tcb.h | 11 ++++-- core/msg.c | 89 +++++++++++++++++++++++++++++++++------------- core/thread.c | 14 ++++---- 4 files changed, 88 insertions(+), 34 deletions(-) diff --git a/core/include/msg.h b/core/include/msg.h index 4a0504c7f7..4d9a0b9aba 100644 --- a/core/include/msg.h +++ b/core/include/msg.h @@ -105,7 +105,13 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid); */ int msg_reply(msg *m, msg *reply); -uint16_t msg_alloc_event(void); +/** + * @brief Initialize the current thread's message queue. + * + * @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); /** @} */ #endif /* __MSG_H */ diff --git a/core/include/tcb.h b/core/include/tcb.h index 75c9e9aeb6..d5d2a63645 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include /* uneven means has to be on runqueue */ #define STATUS_NOT_FOUND (0x0000) @@ -40,11 +42,14 @@ typedef struct tcb { uint16_t pid; uint16_t priority; - void* wait_data; - queue_node_t msg_queue; - clist_node_t rq_entry; + void* wait_data; + queue_node_t msg_waiters; + + cib_t msg_queue; + msg* msg_array; + const char* name; char* stack_start; int stack_size; diff --git a/core/msg.c b/core/msg.c index f33c7bc6e5..186eeb15db 100644 --- a/core/msg.c +++ b/core/msg.c @@ -20,32 +20,47 @@ #include "tcb.h" #include #include +#include #include "flags.h" //#define ENABLE_DEBUG #include "debug.h" +static int queue_msg(tcb *target, msg *m) { + int n = cib_put(&(target->msg_queue)); + + if (n != -1) { + target->msg_array[n] = *m; + return 1; + } + + return 0; +} + int msg_send(msg* m, unsigned int target_pid, bool block) { if (inISR()) { return msg_send_int(m, target_pid); } - int result = 1; - tcb *target = (tcb*)sched_threads[target_pid]; m->sender_pid = thread_pid; - if (m->sender_pid == target_pid) return -1; - - dINT(); - - if (target == NULL) { - eINT(); + if (m->sender_pid == target_pid) { return -1; } + if (target == NULL) { + return -1; + } + + dINT(); if (target->status != STATUS_RECEIVE_BLOCKED) { + if (queue_msg(target, m)) { + eINT(); + return 1; + } + if (! block ) { DEBUG("%s: receiver not waiting. block=%u\n", active_thread->name, block); eINT(); @@ -56,9 +71,9 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { queue_node_t n; n.priority = active_thread->priority; n.data = (unsigned int) active_thread; - DEBUG("%s: Adding node to msg_queue:\n", active_thread->name); + DEBUG("%s: Adding node to msg_waiters:\n", active_thread->name); - queue_priority_add(&(target->msg_queue), &n); + queue_priority_add(&(target->msg_waiters), &n); active_thread->wait_data = (void*) m; @@ -83,7 +98,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { eINT(); thread_yield(); - return result; + return 1; } int msg_send_int(msg* m, unsigned int target_pid) { @@ -103,9 +118,8 @@ int msg_send_int(msg* m, unsigned int target_pid) { return 1; } else { DEBUG("msg_send_int: receiver not waiting.\n"); - return 0; + return (queue_msg(target, m)); } - } int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { @@ -154,29 +168,44 @@ int msg_reply_int(msg *m, msg *reply) { return 1; } - int msg_receive(msg* m) { dINT(); DEBUG("%s: msg_receive.\n", active_thread->name); tcb *me = (tcb*) sched_threads[thread_pid]; - me->wait_data = (void*) m; + int n = cib_get(&(me->msg_queue)); + if (n >= 0) { + DEBUG("%s: msg_receive(): We've got a queued message.\n", active_thread->name); + *m = me->msg_array[n]; + } else { + me->wait_data = (void*) m; + } - queue_node_t *n = queue_remove_head(&(me->msg_queue)); + queue_node_t *node = queue_remove_head(&(me->msg_waiters)); - if (n == NULL) { - DEBUG("%s: msg_receive blocked\n", active_thread->name); - sched_set_status(me, STATUS_RECEIVE_BLOCKED); + if (node == NULL) { + DEBUG("%s: msg_receive(): No thread in waiting list.\n", active_thread->name); + if (n < 0) { + DEBUG("%s: msg_receive(): No msg in queue. Going blocked.\n", active_thread->name); + sched_set_status(me, STATUS_RECEIVE_BLOCKED); - eINT(); - thread_yield(); + eINT(); + thread_yield(); - /* sender copied message */ + /* sender copied message */ + } return 1; } else { - DEBUG("%s: msg_receive direct copy.\n", active_thread->name); - tcb *sender = (tcb*)n->data; + DEBUG("%s: msg_receive(): Wakeing up waiting thread.\n", active_thread->name); + tcb *sender = (tcb*)node->data; + + if (n >= 0) { + /* we've already got a messgage from the queue. as there is a + * waiter, take it's message into the just freed queue space. + */ + m = &(me->msg_array[cib_put(&(me->msg_queue))]); + } /* copy msg */ msg* sender_msg = (msg*)sender->wait_data; @@ -190,3 +219,15 @@ int msg_receive(msg* m) { return 1; } } + +int msg_init_queue(msg* array, int num) { + /* make sure brainfuck condition is met */ + if (num && (num & (num - 1)) == 0) { + tcb *me = (tcb*)active_thread; + me->msg_array = array; + cib_init(&(me->msg_queue), num); + return 0; + } + + return -1; +} diff --git a/core/thread.c b/core/thread.c index d9a922aec9..26ef878700 100644 --- a/core/thread.c +++ b/core/thread.c @@ -144,17 +144,19 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f cb->priority = priority; cb->status = 0; + cb->rq_entry.data = (unsigned int) cb; + cb->rq_entry.next = NULL; + cb->rq_entry.prev = NULL; + cb->name = name; cb->wait_data = NULL; - cb->msg_queue.data = 0; - cb->msg_queue.priority = 0; - cb->msg_queue.next = NULL; + cb->msg_waiters.data = 0; + cb->msg_waiters.priority = 0; + cb->msg_waiters.next = NULL; - cb->rq_entry.data = (unsigned int) cb; - cb->rq_entry.next = NULL; - cb->rq_entry.prev = NULL; + cib_init(&(cb->msg_queue),0); num_tasks++; From 5467d08536d4ab25cbacad7b0ddfec787e63ccfc Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 26 Nov 2010 14:34:10 +0100 Subject: [PATCH 104/115] * hwtimer: export hwtimer_now --- core/include/hwtimer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/core/include/hwtimer.h b/core/include/hwtimer.h index b2d8d2666e..d17137edeb 100644 --- a/core/include/hwtimer.h +++ b/core/include/hwtimer.h @@ -124,6 +124,7 @@ void hwtimer_t0_enable_interrupt(void); void hwtimer_t0_set(unsigned long value, short timer); void hwtimer_t0_unset(short timer); unsigned long hwtimer_t0_now(void); +unsigned long hwtimer_now(void); /** @} */ #endif /* __HWTIMER_H */ From 3a83ef082473f8bc8a5188d491f3b6a875923a6a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 26 Nov 2010 15:02:15 +0100 Subject: [PATCH 105/115] * msg queue optimization --- core/msg.c | 8 ++++++-- core/thread.c | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/msg.c b/core/msg.c index 186eeb15db..b33eda5691 100644 --- a/core/msg.c +++ b/core/msg.c @@ -56,7 +56,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { dINT(); if (target->status != STATUS_RECEIVE_BLOCKED) { - if (queue_msg(target, m)) { + if (target->msg_array && queue_msg(target, m)) { eINT(); return 1; } @@ -174,7 +174,11 @@ int msg_receive(msg* m) { tcb *me = (tcb*) sched_threads[thread_pid]; - int n = cib_get(&(me->msg_queue)); + int n = -1; + if (me->msg_array) { + n = cib_get(&(me->msg_queue)); + } + if (n >= 0) { DEBUG("%s: msg_receive(): We've got a queued message.\n", active_thread->name); *m = me->msg_array[n]; diff --git a/core/thread.c b/core/thread.c index 26ef878700..e087f2a9d6 100644 --- a/core/thread.c +++ b/core/thread.c @@ -157,6 +157,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f cb->msg_waiters.next = NULL; cib_init(&(cb->msg_queue),0); + cb->msg_array = NULL; num_tasks++; From 1956603065ac6b3ae627e48dd0c6b234ca591b93 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 26 Nov 2010 15:02:43 +0100 Subject: [PATCH 106/115] [sys/transceiver.c] * fixed pointer handling in receive function --- sys/transceiver.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sys/transceiver.c b/sys/transceiver.c index ee1ff38ded..2c2e77f3ef 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -189,12 +189,11 @@ static void receive_packet(uint16_t type, uint8_t pos) { } /* copy packet and handle it */ else { - radio_packet_t trans_p = transceiver_buffer[transceiver_buffer_pos]; + radio_packet_t *trans_p = &(transceiver_buffer[transceiver_buffer_pos]); m.type = PKT_PENDING; if (type == RCV_PKT_CC1100) { - receive_cc1100_packet(&trans_p); - m.content.value = transceiver_buffer_pos; + receive_cc1100_packet(trans_p); } else { puts("Invalid transceiver type"); @@ -206,7 +205,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { * this is done non-blocking, so packets can get lost */ while (reg[i].transceivers != TRANSCEIVER_NONE) { if (reg[i].transceivers & t) { - m.content.value = transceiver_buffer_pos; + m.content.ptr = (char*) &(transceiver_buffer[transceiver_buffer_pos]); DEBUG("Notify thread %i\n", reg[i].pid); msg_send(&m, reg[i].pid, false); } From 3e70da172e9227744a0b51baa5643d8a558c8143 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 26 Nov 2010 15:12:47 +0100 Subject: [PATCH 107/115] * removed unneccessary double definition of struct --- core/cib.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/cib.c b/core/cib.c index 252abbde47..b588fe671e 100644 --- a/core/cib.c +++ b/core/cib.c @@ -1,8 +1,4 @@ -typedef struct cib { - unsigned int read_count; - unsigned int write_count; - unsigned int complement; -} cib_t; +#include void cib_init(cib_t *cib, unsigned int size) { cib->read_count = 0; From 44f5c27a03077823875481e6f497bac8d3596bb7 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 26 Nov 2010 15:21:00 +0100 Subject: [PATCH 108/115] * make Test rule set PORT of mcu --- Jamrules.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jamrules.common b/Jamrules.common index acc3ad643a..d2f4c9e863 100644 --- a/Jamrules.common +++ b/Jamrules.common @@ -177,7 +177,7 @@ rule Test } actions Test { - for tst in projects/$(PROJECT)/tests/*; do $tst; done + export PORT=$(PORT); for tst in projects/$(PROJECT)/tests/*; do $tst; done } # Reset connected sensor node From e6752c739bc50512ef7e2ab4478bbab9f7a9b28d Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 26 Nov 2010 17:06:54 +0100 Subject: [PATCH 109/115] [drivers/cc110x_ng projects/test_cc110x_ng sys/transceiver] * fixed length handling * more sophisticated sending function in userapp --- drivers/cc110x_ng/cc1100-tx.c | 1 - drivers/cc110x_ng/cc1100_ng.h | 2 ++ projects/test_cc110x_ng/main.c | 56 +++++++++++++++++++++++++--------- sys/include/transceiver.h | 4 +-- sys/transceiver.c | 4 +-- 5 files changed, 47 insertions(+), 20 deletions(-) diff --git a/drivers/cc110x_ng/cc1100-tx.c b/drivers/cc110x_ng/cc1100-tx.c index 72a595d50a..d8a79b37cb 100644 --- a/drivers/cc110x_ng/cc1100-tx.c +++ b/drivers/cc110x_ng/cc1100-tx.c @@ -11,7 +11,6 @@ #include uint8_t cc1100_send(cc1100_packet_t *packet) { - puts("Going to send\n"); volatile uint32_t abort_count; uint8_t size; /* TODO: burst sending */ diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index 83ad0c1122..1b686fdcca 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -10,6 +10,8 @@ #define CC1100_MAX_DATA_LENGTH (58) +#define CC1100_HEADER_LENGTH (3) ///< Header covers SRC, DST and FLAGS + #define CC1100_BROADCAST_ADDRESS (0x00) ///< CC1100 broadcast address #define MAX_UID (0xFF) ///< Maximum UID of a node is 255 diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index f5df8f26e4..96db662427 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -1,4 +1,6 @@ #include +#include + #include #include #include @@ -7,13 +9,16 @@ #include #include #include +#include -#define SHELL_STACK_SIZE (4096) -#define RADIO_STACK_SIZE (4096) +#define SHELL_STACK_SIZE (2048) +#define RADIO_STACK_SIZE (2048) +#define TEXT_SIZE CC1100_MAX_DATA_LENGTH int transceiver_pid; char shell_stack_buffer[SHELL_STACK_SIZE]; char radio_stack_buffer[RADIO_STACK_SIZE]; +char text_msg[TEXT_SIZE]; void trans_chan(char *chan); void trans_addr(char *addr); @@ -30,12 +35,12 @@ const shell_command_t sc[] = { {NULL, NULL, NULL}}; void trans_chan(char *chan) { - int c; + int16_t c; tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &c; mesg.content.ptr = (char*) &tcmd; - if (sscanf(chan, "tchan %i", &c) > 0) { + if (sscanf(chan, "tchan %hi", &c) > 0) { printf("Trying to set channel %i\n", c); mesg.type = SET_CHANNEL; } @@ -47,12 +52,12 @@ void trans_chan(char *chan) { } void trans_addr(char *addr) { - int a; + int16_t a; tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &a; mesg.content.ptr = (char*) &tcmd; - if (sscanf(addr, "taddr %i", &a) > 0) { + if (sscanf(addr, "taddr %hi", &a) > 0) { printf("Trying to set address %i\n", a); mesg.type = SET_ADDRESS; } @@ -68,15 +73,22 @@ void trans_send(char *text) { uint32_t response; tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &p; + uint16_t addr; - p.length = 10; - p.dst = 5; - - mesg.type = SND_PKT; - mesg.content.ptr = (char*) &tcmd; - msg_send_receive(&mesg, &mesg, transceiver_pid); - response = mesg.content.value; - printf("Packet send: %lu\n", response); + if (sscanf(text, "tsnd %hu %s", &(addr), text_msg) == 2) { + p.data = (uint8_t*) text_msg; + p.length = strlen(text_msg); + p.dst = addr; + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + printf("Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char*) p.data); + msg_send_receive(&mesg, &mesg, transceiver_pid); + response = mesg.content.value; + printf("Packet send: %lu\n", response); + } + else { + puts("Usage:\ttsnd "); + } } void shell_runner(void) { @@ -87,10 +99,24 @@ void shell_runner(void) { void radio(void) { msg m; + radio_packet_t *p; + uint8_t i; while (1) { msg_receive(&m); - printf("Received message of type %i: %lX\n", m.type, m.content.value); + printf("Received message of type %i:\n", m.type); + if (m.type == PKT_PENDING) { + p = (radio_packet_t*) m.content.ptr; + printf("Packet waiting, process...\n"); + printf("\tLength:\t%u\n", p->length); + printf("\tSrc:\t%u\n", p->src); + printf("\tDst:\t%u\n", p->dst); + + for (i = 0; i < p->length; i++) { + printf("%02X ", p->data[i]); + } + printf("\n"); + } } } diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index cecd8896a4..a7cc68fa4b 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -6,7 +6,7 @@ /* Packets to buffer */ #define TRANSCEIVER_BUFFER_SIZE (10) /* Stack size for transceiver thread */ -#define TRANSCEIVER_STACK_SIZE (4096) +#define TRANSCEIVER_STACK_SIZE (2048) /* The maximum of threads to register */ #define TRANSCEIVER_MAX_REGISTERED (10) @@ -31,7 +31,7 @@ enum transceiver_msg_type_t { SET_ADDRESS, ///< Set the radio address /* Error messages */ - ENOBUFFER, + ENOBUFFER, ///< No buffer left }; /** diff --git a/sys/transceiver.c b/sys/transceiver.c index 2c2e77f3ef..faddb43a50 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -228,7 +228,7 @@ static void receive_cc1100_packet(radio_packet_t *trans_p) { trans_p->dst = p.address; trans_p->rssi = cc1100_rx_buffer[rx_buffer_pos].rssi; trans_p->lqi = cc1100_rx_buffer[rx_buffer_pos].lqi; - trans_p->length = p.length; + trans_p->length = p.length - CC1100_HEADER_LENGTH; memcpy((void*) &(data_buffer[transceiver_buffer_pos]), p.data, CC1100_MAX_DATA_LENGTH); eINT(); @@ -253,7 +253,7 @@ static uint8_t send_packet(transceiver_type_t t, void *pkt) { switch (t) { case TRANSCEIVER_CC1100: /* TODO: prepare and send packet here */ - cc1100_pkt.length = p.length; + cc1100_pkt.length = p.length + CC1100_HEADER_LENGTH; cc1100_pkt.address = p.dst; cc1100_pkt.flags = 0; memcpy(cc1100_pkt.data, p.data, p.length); From f5ab5c27bb1fdf7cec17d4d94b20a0253a9d35aa Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 27 Nov 2010 10:50:18 +0100 Subject: [PATCH 110/115] [drivers/cc1100_ng sys/transceiver] ' added a monitor mode [sys/shell projects/test_cc1100_ng] ' moved shell commands to get/set channel and address and sending a packet from userapp to default shell command set --- drivers/cc110x_ng/cc1100-defaultSettings.c | 2 +- drivers/cc110x_ng/cc1100.c | 9 +++ drivers/cc110x_ng/cc1100_ng.h | 1 + projects/test_cc110x_ng/main.c | 72 +++------------------- sys/include/transceiver.h | 1 + sys/shell/Jamfile | 2 +- sys/shell/shell_commands.c | 15 +++++ sys/transceiver.c | 20 ++++++ 8 files changed, 55 insertions(+), 67 deletions(-) diff --git a/drivers/cc110x_ng/cc1100-defaultSettings.c b/drivers/cc110x_ng/cc1100-defaultSettings.c index d4ae620c8b..6eb9ae2327 100644 --- a/drivers/cc110x_ng/cc1100-defaultSettings.c +++ b/drivers/cc110x_ng/cc1100-defaultSettings.c @@ -86,7 +86,7 @@ char cc1100_conf[] = { 0xAD, // SYNC0 0x3D, // PKTLEN (maximum value of packet length byte = 61) 0x06, // PKTCTRL1 - 0x45, // PKTCTRL0 (variable packet length) + 0x45, // PKTCTRL0 (variable packet length) 0xFF, // ADDR CC1100_DEFAULT_CHANNR*10, // CHANNR 0x0B, // FSCTRL1 diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 3ed3659f76..55b7fd526d 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -110,6 +110,15 @@ radio_address_t cc1100_set_address(radio_address_t address) { return radio_address; } +void cc1100_set_monitor(uint8_t mode) { + if (mode) { + write_register(CC1100_PKTCTRL1, (0x04)); + } + else { + write_register(CC1100_PKTCTRL1, (0x06)); + } +} + void cc1100_setup_rx_mode(void) { // Stay in RX mode until end of packet cc1100_spi_write_reg(CC1100_MCSM2, 0x07); diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index 1b686fdcca..3431f2e7b0 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -116,6 +116,7 @@ int16_t cc1100_get_channel(void); radio_address_t cc1100_set_address(radio_address_t addr); radio_address_t cc1100_get_address(void); +void cc1100_set_monitor(uint8_t mode); void cc1100_print_config(void); #endif diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index 96db662427..0a9e6c3027 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -13,82 +13,24 @@ #define SHELL_STACK_SIZE (2048) #define RADIO_STACK_SIZE (2048) -#define TEXT_SIZE CC1100_MAX_DATA_LENGTH int transceiver_pid; char shell_stack_buffer[SHELL_STACK_SIZE]; char radio_stack_buffer[RADIO_STACK_SIZE]; -char text_msg[TEXT_SIZE]; -void trans_chan(char *chan); -void trans_addr(char *addr); -void trans_send(char *mesg); - -msg mesg; -transceiver_command_t tcmd; +void mon_handler(char *mode); shell_t shell; const shell_command_t sc[] = { - {"tchan", "Set the channel for cc1100", trans_chan}, - {"taddr", "Set the address for cc1100", trans_addr}, - {"tsnd", "Sends a CC1100 packet", trans_send}, + {"mon", "", mon_handler}, {NULL, NULL, NULL}}; -void trans_chan(char *chan) { - int16_t c; +void mon_handler(char *mode) { + unsigned int m; - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &c; - mesg.content.ptr = (char*) &tcmd; - if (sscanf(chan, "tchan %hi", &c) > 0) { - printf("Trying to set channel %i\n", c); - mesg.type = SET_CHANNEL; - } - else { - mesg.type = GET_CHANNEL; - } - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("Got channel: %i\n", c); -} - -void trans_addr(char *addr) { - int16_t a; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &a; - mesg.content.ptr = (char*) &tcmd; - if (sscanf(addr, "taddr %hi", &a) > 0) { - printf("Trying to set address %i\n", a); - mesg.type = SET_ADDRESS; - } - else { - mesg.type = GET_ADDRESS; - } - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("Got address: %i\n", a); -} - -void trans_send(char *text) { - radio_packet_t p; - uint32_t response; - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &p; - uint16_t addr; - - if (sscanf(text, "tsnd %hu %s", &(addr), text_msg) == 2) { - p.data = (uint8_t*) text_msg; - p.length = strlen(text_msg); - p.dst = addr; - mesg.type = SND_PKT; - mesg.content.ptr = (char*) &tcmd; - printf("Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char*) p.data); - msg_send_receive(&mesg, &mesg, transceiver_pid); - response = mesg.content.value; - printf("Packet send: %lu\n", response); - } - else { - puts("Usage:\ttsnd "); - } + sscanf(mode, "mon %u", &m); + printf("Setting monitor mode: %u\n", m); + cc1100_set_monitor(m); } void shell_runner(void) { diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index a7cc68fa4b..e844f572db 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -29,6 +29,7 @@ enum transceiver_msg_type_t { SET_CHANNEL, ///< Set a new channel GET_ADDRESS, ///< Get the radio address SET_ADDRESS, ///< Set the radio address + SET_MONITOR, ///< Set transceiver to monitor mode (disable address checking) /* Error messages */ ENOBUFFER, ///< No buffer left diff --git a/sys/shell/Jamfile b/sys/shell/Jamfile index cc0eec2e45..fa8b989d31 100644 --- a/sys/shell/Jamfile +++ b/sys/shell/Jamfile @@ -28,7 +28,7 @@ SubDir TOP sys shell ; Module shell : shell.c ; -Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c cc1100.c : shell ; +Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c cc1100.c cc1100_ng.c : shell ; Module ps : ps.c ; diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index 41f152ce99..18526ac422 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -26,6 +26,14 @@ extern void _cc1100_get_address_handler(char *unused); extern void _cc1100_set_address_handler(char *ptr); #endif +#ifdef MODULE_TRANSCEIVER +#ifdef MODULE_CC110X_NG +extern void _cc1100_ng_get_set_address_handler(char *addr); +extern void _cc1100_ng_get_set_channel_handler(char *chan); +extern void _cc1100_ng_send_handler(char *pkt); +#endif +#endif + const shell_command_t _shell_command_list[] = { #ifdef MODULE_PS {"ps", "Prints information about running threads.", _ps_handler}, @@ -46,6 +54,13 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_CC110X {"cc1100_get_address", "", _cc1100_get_address_handler}, {"cc1100_set_address", "", _cc1100_set_address_handler}, +#endif +#ifdef MODULE_TRANSCEIVER +#ifdef MODULE_CC110X_NG + {"addr", "Gets or sets the address for the CC1100 transceiver", _cc1100_ng_get_set_address_handler}, + {"chan", "Gets or sets the channel for the CC1100 transceiver", _cc1100_ng_get_set_channel_handler}, + {"txtsnd", "Sends a text message to a given node via the CC1100 transceiver", _cc1100_ng_send_handler}, +#endif #endif {NULL, NULL, NULL} }; diff --git a/sys/transceiver.c b/sys/transceiver.c index faddb43a50..ac52d9b1e0 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -51,6 +51,7 @@ static int16_t get_channel(transceiver_type_t t); static int16_t set_channel(transceiver_type_t t, void *channel); static int16_t get_address(transceiver_type_t t); static int16_t set_address(transceiver_type_t t, void *address); +static void set_monitor(transceiver_type_t t, void *mode); /*------------------------------------------------------------------------------------*/ /* Transceiver init */ @@ -142,6 +143,9 @@ void run(void) { *((int16_t*) cmd->data) = set_address(cmd->transceivers, cmd->data); msg_reply(&m, &m); break; + case SET_MONITOR: + set_monitor(cmd->transceivers, cmd->data); + break; default: DEBUG("Unknown message received\n"); break; @@ -335,3 +339,19 @@ static int16_t set_address(transceiver_type_t t, void *address) { return -1; } } + +/* + * @brief Set the transceiver device into monitor mode (disabling address check) + * + * @param t The transceiver device + * @param mode 1 for enabling monitor mode, 0 for enabling address check + */ +static void set_monitor(transceiver_type_t t, void *mode) { + switch (t) { + case TRANSCEIVER_CC1100: + cc1100_set_monitor(*((uint8_t*) mode)); + break; + default: + break; + } +} From 413b2898ecd431b05c0ed6b65da83108ba636653 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 27 Nov 2010 10:52:17 +0100 Subject: [PATCH 111/115] * missing file from last commit --- sys/shell/cc1100_ng.c | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 sys/shell/cc1100_ng.c diff --git a/sys/shell/cc1100_ng.c b/sys/shell/cc1100_ng.c new file mode 100644 index 0000000000..5563fee4e3 --- /dev/null +++ b/sys/shell/cc1100_ng.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include + +#define TEXT_SIZE CC1100_MAX_DATA_LENGTH + +char text_msg[TEXT_SIZE]; +msg mesg; +transceiver_command_t tcmd; + +void _cc1100_ng_get_set_address_handler(char *addr) { + int16_t a; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &a; + mesg.content.ptr = (char*) &tcmd; + if (sscanf(addr, "addr %hi", &a) > 0) { + printf("[cc1100] Trying to set address %i\n", a); + mesg.type = SET_ADDRESS; + } + else { + mesg.type = GET_ADDRESS; + } + msg_send_receive(&mesg, &mesg, transceiver_pid); + printf("[cc1100] Got address: %i\n", a); +} + +void _cc1100_ng_get_set_channel_handler(char *chan) { + int16_t c; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &c; + mesg.content.ptr = (char*) &tcmd; + if (sscanf(chan, "chan %hi", &c) > 0) { + printf("[cc1100] Trying to set channel %i\n", c); + mesg.type = SET_CHANNEL; + } + else { + mesg.type = GET_CHANNEL; + } + msg_send_receive(&mesg, &mesg, transceiver_pid); + printf("[cc1100] Got channel: %i\n", c); +} + +void _cc1100_ng_send_handler(char *pkt) { + radio_packet_t p; + uint32_t response; + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + uint16_t addr; + + if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) { + p.data = (uint8_t*) text_msg; + p.length = strlen(text_msg); + p.dst = addr; + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + printf("[cc1100] Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char*) p.data); + msg_send_receive(&mesg, &mesg, transceiver_pid); + response = mesg.content.value; + printf("[cc1100] Packet sent: %lu\n", response); + } + else { + puts("Usage:\ttsnd "); + } +} From 54172b5c867764bc44b5e7ddd4ca215b5347c208 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 27 Nov 2010 11:09:42 +0100 Subject: [PATCH 112/115] [sys/shell project/test_cc110x_ng] ' moved monitor command from userapp to default shell command set [sys/transceiver] ' make transceiver_pid "public" --- projects/test_cc110x_ng/main.c | 14 +------------- sys/include/transceiver.h | 3 ++- sys/shell/cc1100_ng.c | 20 +++++++++++++++++++- sys/shell/shell_commands.c | 2 ++ sys/transceiver.c | 10 ++++++---- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index 0a9e6c3027..f3ab6c7cef 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -14,25 +14,13 @@ #define SHELL_STACK_SIZE (2048) #define RADIO_STACK_SIZE (2048) -int transceiver_pid; char shell_stack_buffer[SHELL_STACK_SIZE]; char radio_stack_buffer[RADIO_STACK_SIZE]; -void mon_handler(char *mode); - shell_t shell; const shell_command_t sc[] = { - {"mon", "", mon_handler}, {NULL, NULL, NULL}}; -void mon_handler(char *mode) { - unsigned int m; - - sscanf(mode, "mon %u", &m); - printf("Setting monitor mode: %u\n", m); - cc1100_set_monitor(m); -} - void shell_runner(void) { shell_init(&shell, sc, uart0_readc, uart0_putc); posix_open(uart0_handler_pid, 0); @@ -67,7 +55,7 @@ int main(void) { thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); transceiver_init(TRANSCEIVER_CC1100); - transceiver_pid = transceiver_start(); + transceiver_start(); transceiver_register(TRANSCEIVER_CC1100, radio_pid); while (1) { diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index e844f572db..e6b03c696a 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -57,7 +57,8 @@ typedef struct { void *data; } transceiver_command_t;; -extern void *transceiver_rx_buffer; +/* The transceiver thread's pid */ +extern int transceiver_pid; /** * @brief Initializes the transceiver module for certain transceiver types diff --git a/sys/shell/cc1100_ng.c b/sys/shell/cc1100_ng.c index 5563fee4e3..3ae631520c 100644 --- a/sys/shell/cc1100_ng.c +++ b/sys/shell/cc1100_ng.c @@ -63,6 +63,24 @@ void _cc1100_ng_send_handler(char *pkt) { printf("[cc1100] Packet sent: %lu\n", response); } else { - puts("Usage:\ttsnd "); + puts("Usage:\ttxtsnd "); } } + +void _cc1100_ng_monitor_handler(char *mode) { + unsigned int m; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &m; + mesg.content.ptr = (char*) &tcmd; + if (sscanf(mode, "monitor %u", &m) == 1) { + printf("Setting monitor mode: %u\n", m); + mesg.type = SET_MONITOR; + msg_send(&mesg, transceiver_pid, 1); + } + else { + puts("Usage:\nmonitor "); + } +} + + diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index 18526ac422..e894b2456c 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -31,6 +31,7 @@ extern void _cc1100_set_address_handler(char *ptr); extern void _cc1100_ng_get_set_address_handler(char *addr); extern void _cc1100_ng_get_set_channel_handler(char *chan); extern void _cc1100_ng_send_handler(char *pkt); +extern void _cc1100_ng_monitor_handler(char *mode); #endif #endif @@ -60,6 +61,7 @@ const shell_command_t _shell_command_list[] = { {"addr", "Gets or sets the address for the CC1100 transceiver", _cc1100_ng_get_set_address_handler}, {"chan", "Gets or sets the channel for the CC1100 transceiver", _cc1100_ng_get_set_channel_handler}, {"txtsnd", "Sends a text message to a given node via the CC1100 transceiver", _cc1100_ng_send_handler}, + {"monitor", "Enables or disables address checking for the CC1100 transceiver", _cc1100_ng_monitor_handler}, #endif #endif {NULL, NULL, NULL} diff --git a/sys/transceiver.c b/sys/transceiver.c index ac52d9b1e0..3a1f3414dc 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -35,6 +35,8 @@ uint8_t data_buffer[TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE]; uint32_t response; ///< response bytes for messages to upper layer threads +int transceiver_pid; ///< the transceiver thread's pid + static volatile uint8_t rx_buffer_pos = 0; static volatile uint8_t transceiver_buffer_pos = 0; @@ -71,15 +73,15 @@ void transceiver_init(transceiver_type_t t) { /* Start the transceiver thread */ int transceiver_start(void) { - int pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-3, CREATE_STACKTEST, run, "Transceiver"); - if (pid < 0) { + transceiver_pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-3, CREATE_STACKTEST, run, "Transceiver"); + if (transceiver_pid < 0) { puts("Error creating transceiver thread"); } else if (transceivers & TRANSCEIVER_CC1100) { DEBUG("Transceiver started for CC1100\n"); - cc1100_init(pid); + cc1100_init(transceiver_pid); } - return pid; + return transceiver_pid; } /* Register an upper layer thread */ From b522722ec66a46387795b176dad1e0bb619f714b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 27 Nov 2010 19:27:05 +0100 Subject: [PATCH 113/115] [sys/transceiver projects/test_cc110x_ng] ' fixed buffer management ' introduced a message queue --- drivers/cc110x_ng/cc1100-rx.c | 2 +- projects/test_cc110x_ng/main.c | 68 +++++++++++++++++++++++++++++++++- sys/include/transceiver.h | 4 ++ sys/transceiver.c | 23 ++++++++---- 4 files changed, 86 insertions(+), 11 deletions(-) diff --git a/drivers/cc110x_ng/cc1100-rx.c b/drivers/cc110x_ng/cc1100-rx.c index 91346a6343..de8f615575 100644 --- a/drivers/cc110x_ng/cc1100-rx.c +++ b/drivers/cc110x_ng/cc1100-rx.c @@ -40,7 +40,7 @@ void cc1100_rx_handler(void) { // Valid packet. After a wake-up, the radio should be in IDLE. // So put CC1100 to RX for WOR_TIMEOUT (have to manually put // the radio back to sleep/WOR). - cc1100_spi_write_reg(CC1100_MCSM0, 0x08); // Turn off FS-Autocal + //cc1100_spi_write_reg(CC1100_MCSM0, 0x08); // Turn off FS-Autocal cc1100_spi_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME (until end of packet) cc1100_spi_strobe(CC1100_SRX); hwtimer_wait(IDLE_TO_RX_TIME); diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index f3ab6c7cef..86c8b9f717 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -14,11 +15,29 @@ #define SHELL_STACK_SIZE (2048) #define RADIO_STACK_SIZE (2048) +#define SND_BUFFER_SIZE (100) +#define RCV_BUFFER_SIZE (64) + +#define SENDING_DELAY (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 msg_q[RCV_BUFFER_SIZE]; + +static msg mesg; +static transceiver_command_t tcmd; +static radio_packet_t p; + +void sender(char *count); +void print_buffer(char *unused); + shell_t shell; const shell_command_t sc[] = { + {"snd", "", sender}, + {"buffer", "", print_buffer}, {NULL, NULL, NULL}}; void shell_runner(void) { @@ -27,17 +46,51 @@ void shell_runner(void) { shell_run(&shell); } +void sender(char *count) { + unsigned int c, i; + + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + + p.length = CC1100_MAX_DATA_LENGTH; + p.dst = 0; + + sscanf(count, "snd %u", &c); + for (i = 0; i < c; i++) { + puts("."); + p.data = snd_buffer[i % SND_BUFFER_SIZE]; + msg_send(&mesg, transceiver_pid, 1); + swtimer_usleep(SENDING_DELAY); + } +} + +void print_buffer(char *unused) { + uint8_t i; + extern radio_packet_t transceiver_buffer[]; + for (i = 0; i < TRANSCEIVER_BUFFER_SIZE; i++) { + printf("[%u] %u # %u # %u\n", i, transceiver_buffer[i].processing, transceiver_buffer[i].length, transceiver_buffer[i].data[i]); + } + extern rx_buffer_t cc1100_rx_buffer[]; + for (i = 0; i < TRANSCEIVER_BUFFER_SIZE; i++) { + printf("[%u] %u # %u \n", i, cc1100_rx_buffer[i].packet.length, cc1100_rx_buffer[i].packet.data[i]); + } +} + void radio(void) { msg m; radio_packet_t *p; uint8_t i; + msg_init_queue(msg_q, RCV_BUFFER_SIZE); + while (1) { msg_receive(&m); - printf("Received message of type %i:\n", m.type); if (m.type == PKT_PENDING) { p = (radio_packet_t*) m.content.ptr; - printf("Packet waiting, process...\n"); + printf("Packet waiting, process %p...\n", p); printf("\tLength:\t%u\n", p->length); printf("\tSrc:\t%u\n", p->src); printf("\tDst:\t%u\n", p->dst); @@ -45,13 +98,24 @@ void radio(void) { for (i = 0; i < p->length; i++) { printf("%02X ", p->data[i]); } + p->processing--; printf("\n"); } + else if (m.type == ENOBUFFER) { + puts("Transceiver buffer full"); + } + else { + puts("Unknown packet received"); + } } } int main(void) { int radio_pid; + uint8_t i; + for (i = 0; i < SND_BUFFER_SIZE; i++) { + memset(snd_buffer[i], i, CC1100_MAX_DATA_LENGTH); + } thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); transceiver_init(TRANSCEIVER_CC1100); diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index e6b03c696a..a31876bd7f 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -11,6 +11,10 @@ /* The maximum of threads to register */ #define TRANSCEIVER_MAX_REGISTERED (10) +/* The size of the message queue between driver and transceiver (must be power + * of two */ +#define TRANSCEIVER_MSG_BUFFER_SIZE (64) + /** * @brief Message types for transceiver interface */ diff --git a/sys/transceiver.c b/sys/transceiver.c index 3a1f3414dc..d3828d1861 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -33,6 +33,9 @@ registered_t reg[TRANSCEIVER_MAX_REGISTERED]; 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]; + uint32_t response; ///< response bytes for messages to upper layer threads int transceiver_pid; ///< the transceiver thread's pid @@ -114,6 +117,7 @@ void run(void) { msg m; transceiver_command_t *cmd; + msg_init_queue(msg_buffer, TRANSCEIVER_MSG_BUFFER_SIZE); while (1) { msg_receive(&m); /* only makes sense for messages for upper layers */ @@ -183,12 +187,13 @@ static void receive_packet(uint16_t type, uint8_t pos) { } /* search first free position in transceiver buffer */ - while ((transceiver_buffer[transceiver_buffer_pos].processing) && (transceiver_buffer_pos < TRANSCEIVER_BUFFER_SIZE)) - { - transceiver_buffer_pos++; + for (i = 0; (i < TRANSCEIVER_BUFFER_SIZE) && (transceiver_buffer[transceiver_buffer_pos].processing); i++) { + if (++transceiver_buffer_pos == TRANSCEIVER_BUFFER_SIZE) { + transceiver_buffer_pos = 0; + } } /* no buffer left */ - if (transceiver_buffer_pos >= TRANSCEIVER_BUFFER_SIZE) { + if (i >= TRANSCEIVER_BUFFER_SIZE) { /* inform upper layers of lost packet */ m.type = ENOBUFFER; m.content.value = t; @@ -209,11 +214,14 @@ static void receive_packet(uint16_t type, uint8_t pos) { /* finally notify waiting upper layers * this is done non-blocking, so packets can get lost */ + i = 0; while (reg[i].transceivers != TRANSCEIVER_NONE) { if (reg[i].transceivers & t) { m.content.ptr = (char*) &(transceiver_buffer[transceiver_buffer_pos]); DEBUG("Notify thread %i\n", reg[i].pid); - msg_send(&m, reg[i].pid, false); + if (msg_send(&m, reg[i].pid, false)) { + transceiver_buffer[transceiver_buffer_pos].processing++; + } } i++; } @@ -235,10 +243,10 @@ static void receive_cc1100_packet(radio_packet_t *trans_p) { trans_p->rssi = cc1100_rx_buffer[rx_buffer_pos].rssi; trans_p->lqi = cc1100_rx_buffer[rx_buffer_pos].lqi; trans_p->length = p.length - CC1100_HEADER_LENGTH; - memcpy((void*) &(data_buffer[transceiver_buffer_pos]), p.data, CC1100_MAX_DATA_LENGTH); + memcpy((void*) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), p.data, CC1100_MAX_DATA_LENGTH); eINT(); - DEBUG("Packet was from %hu to %hu, size: %u\n", trans_p->src, trans_p->dst, trans_p->length); + DEBUG("Packet %p was from %hu to %hu, size: %u\n", trans_p, trans_p->src, trans_p->dst, trans_p->length); trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]); } @@ -258,7 +266,6 @@ static uint8_t send_packet(transceiver_type_t t, void *pkt) { switch (t) { case TRANSCEIVER_CC1100: - /* TODO: prepare and send packet here */ cc1100_pkt.length = p.length + CC1100_HEADER_LENGTH; cc1100_pkt.address = p.dst; cc1100_pkt.flags = 0; From c6de4d2627c07264e43c749f5c1346ed4e6215c2 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 29 Nov 2010 16:17:44 +0100 Subject: [PATCH 114/115] * make pseudoterm reset terminal on sigint, make it honour ctrl-c --- board/msba2/tools/src/pseudoterm.c | 291 ++++++++++++++++------------- 1 file changed, 156 insertions(+), 135 deletions(-) diff --git a/board/msba2/tools/src/pseudoterm.c b/board/msba2/tools/src/pseudoterm.c index ce8a446b32..cf17d99703 100644 --- a/board/msba2/tools/src/pseudoterm.c +++ b/board/msba2/tools/src/pseudoterm.c @@ -1,135 +1,156 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "serial.h" -#include "pthread.h" -#include "download.h" - -int tty_fd; -int stopped = 0; -char* port_name = "/dev/ttyUSB1"; -pthread_t serial_reader; - -void* serial_reader_func(void* arg) { - unsigned char buf[255]; - while(1) { - int n = read_serial_port(buf, sizeof(buf)); - if (n > 0) { - write(tty_fd, buf, n); - } - } -} - -int init() { - int result = open_serial_port(port_name); - pthread_create(&serial_reader, NULL, serial_reader_func, NULL); - hard_reset_to_user_code(); - return result; -} - -void sig_handler(int signal) { - if (signal == SIGUSR1) { - if (stopped) { - stopped = 0; - printf("\nSignal received, opening port.\r\n"); - if (init() < 0) { - printf("Cannot open port.\r\n"); - exit(1); - } - } - } else if (signal == SIGUSR2) { - if (!stopped) { - stopped = 1; - printf("\nSignal received, closing port. \r\n"); - pthread_cancel(serial_reader); - close_serial_port(); - } - } -} - -int open_tty(void) -{ - int r, fd; - struct termios term_setting; - - fd = open("/dev/tty", O_RDWR); - if (fd < 0) return -1; - r = tcgetattr(fd, &term_setting); - if (r != 0) return -2; - term_setting.c_oflag |= ( ONLRET ); - term_setting.c_iflag |= (IGNBRK | IGNPAR); - term_setting.c_iflag &= ~(ISTRIP | BRKINT); - term_setting.c_lflag &= ~(ICANON | ISIG | ECHO); - term_setting.c_cflag |= CREAD; - term_setting.c_cc[VMIN] = 1; - term_setting.c_cc[VTIME] = 1; - r = tcsetattr(fd, TCSANOW, &term_setting); - if (r != 0) return -3; - return fd; -} - -void install_sighandler() { - struct sigaction action; - sigemptyset (&action.sa_mask); - sigaddset( &action.sa_mask, SIGUSR1 ); - sigaddset( &action.sa_mask, SIGUSR2 ); - action.sa_flags = 0; - action.sa_handler = sig_handler; - sigaction(SIGUSR1, &action, NULL); - sigaction(SIGUSR2, &action, NULL); -} - -int main(int argc, char** argv) { - if (argc == 2) { - port_name = argv[1]; - } - - printf("Using %s as serial device.\n", port_name); - - char ttybuf[255]; - tty_fd = open_tty(); - if (tty_fd < 0) { - printf("Error opening terminal.\n"); - return(1); - } - - install_sighandler(); - - if (init() < 0) { - printf("Cannot open port.\r\n"); - exit(1); - } - - while (1) { - int n = read(tty_fd, ttybuf, sizeof(ttybuf)); - int i; - - /* check for 0x3 (ctrl-c), clean exit */ - for (i = 0; i < n; i++) { - if (ttybuf[i] == 0x3) { - if (i > 0) { - write_serial_port(ttybuf, i); - } - close_serial_port(); - system("tset -c"); - return 0; - } - - } - write_serial_port(ttybuf,n); - } - - close_serial_port(); - return 0; -} - - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "serial.h" +#include "pthread.h" +#include "download.h" + +int tty_fd; +int stopped = 0; +char* port_name = "/dev/ttyUSB1"; +pthread_t serial_reader; + +void* serial_reader_func(void* arg) { + unsigned char buf[255]; + while(1) { + int n = read_serial_port(buf, sizeof(buf)); + if (n > 0) { + write(tty_fd, buf, n); + } + } +} + +int init() { + int result = open_serial_port(port_name); + pthread_create(&serial_reader, NULL, serial_reader_func, NULL); + hard_reset_to_user_code(); + return result; +} + +struct termios old_term_setting; + +void close_tty() { + tcsetattr(tty_fd, TCSANOW, &old_term_setting); +} + +void sig_handler(int signal) { + if (signal == SIGUSR1) { + if (stopped) { + stopped = 0; + printf("\nSignal received, opening port.\r\n"); + if (init() < 0) { + printf("Cannot open port.\r\n"); + close_tty(); + exit(1); + } + } + } else if (signal == SIGUSR2) { + if (!stopped) { + stopped = 1; + printf("\nSignal received, closing port. \r\n"); + pthread_cancel(serial_reader); + close_serial_port(); + } + } else if (signal == SIGINT) { + printf("SIGINT received, exiting...\n"); + pthread_cancel(serial_reader); + close_serial_port(); + close_tty(); + exit(0); + } +} + +int open_tty(void) +{ + int r, fd; + struct termios term_setting; + + fd = open("/dev/tty", O_RDWR); + if (fd < 0) return -1; + r = tcgetattr(fd, &term_setting); + if (r != 0) return -2; + + old_term_setting = term_setting; + + term_setting.c_oflag |= ( ONLRET ); + term_setting.c_iflag |= (/*IGNBRK |*/ BRKINT | IGNPAR); + term_setting.c_iflag &= ~(ISTRIP); + term_setting.c_lflag &= ~(ICANON |/* ISIG |*/ ECHO); + term_setting.c_lflag |= ( ISIG ); + term_setting.c_cflag |= CREAD; + term_setting.c_cc[VMIN] = 1; + term_setting.c_cc[VTIME] = 1; + r = tcsetattr(fd, TCSANOW, &term_setting); + if (r != 0) return -3; + return fd; +} + +void install_sighandler() { + struct sigaction action; + sigemptyset (&action.sa_mask); + sigaddset( &action.sa_mask, SIGINT ); + sigaddset( &action.sa_mask, SIGUSR1 ); + sigaddset( &action.sa_mask, SIGUSR2 ); + action.sa_flags = 0; + action.sa_handler = sig_handler; + sigaction(SIGINT, &action, NULL); + sigaction(SIGUSR1, &action, NULL); + sigaction(SIGUSR2, &action, NULL); +} + +int main(int argc, char** argv) { + if (argc == 2) { + port_name = argv[1]; + } + + printf("Using %s as serial device.\n", port_name); + + char ttybuf[255]; + tty_fd = open_tty(); + if (tty_fd < 0) { + printf("Error opening terminal.\n"); + return(1); + } + + install_sighandler(); + + if (init() < 0) { + printf("Cannot open port.\r\n"); + exit(1); + } + + while (1) { + int n = read(tty_fd, ttybuf, sizeof(ttybuf)); + int i; + + /* check for 0x3 (ctrl-c), clean exit */ + for (i = 0; i < n; i++) { + if (ttybuf[i] == 0x3) { + if (i > 0) { + write_serial_port(ttybuf, i); + } + close_serial_port(); + close_tty(); + system("tset -c"); + return 0; + } + + } + write_serial_port(ttybuf,n); + } + + close_tty(); + close_serial_port(); + return 0; +} + + From 5ebbd2c92e6a9ea0aadf28662de0a030a967fe1a Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 29 Nov 2010 19:19:59 +0100 Subject: [PATCH 115/115] [cpu/arm_common cpu/lpc2387] * added a iap driver --- cpu/arm_common/Jamfile | 2 +- cpu/arm_common/iap.c | 254 ++++++++++++++++++++++++++++++++++ cpu/arm_common/include/iap.h | 67 +++++++++ cpu/lpc2387/Jamfile | 2 +- cpu/lpc2387/include/lpc2387.h | 2 + cpu/lpc2387/linkerscript.x | 8 ++ cpu/lpc2387/lpc23xx-iap.c | 92 ++++++++++++ 7 files changed, 425 insertions(+), 2 deletions(-) create mode 100644 cpu/arm_common/iap.c create mode 100644 cpu/arm_common/include/iap.h create mode 100644 cpu/lpc2387/lpc23xx-iap.c diff --git a/cpu/arm_common/Jamfile b/cpu/arm_common/Jamfile index 5438882366..0252c75781 100644 --- a/cpu/arm_common/Jamfile +++ b/cpu/arm_common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP cpu arm_common ; -Module arm_common : common.s bootloader.c VIC.c atomic.s arm_cpu.c ; +Module arm_common : common.s bootloader.c VIC.c atomic.s arm_cpu.c iap.c ; UseModule arm_common ; Module hwtimer_cpu : hwtimer_cpu.c ; diff --git a/cpu/arm_common/iap.c b/cpu/arm_common/iap.c new file mode 100644 index 0000000000..92f8ff82c4 --- /dev/null +++ b/cpu/arm_common/iap.c @@ -0,0 +1,254 @@ +/* iap driver + * + * based on iap driver for LPC2148 Controller made by Andreas Weschenfelder, 2008 + * see: + * + */ + +#include +#include + +#define ENABLE_DEBUG +#include + +static unsigned int iap_command[5]; // contains parameters for IAP command +static unsigned int iap_result[2]; // contains results +typedef void (*IAP) (unsigned int[],unsigned int[]); // typedefinition for IAP entry function +IAP IAP_Entry; + +/* some function prototypes */ +static uint32_t blank_check_sector(uint32_t tmp_sect1, uint32_t tmp_sect2); +static uint32_t prepare_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2); +static uint32_t erase_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2); +static uint32_t copy_ram_to_flash(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size); +static uint32_t compare(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size); +static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4); + +/****************************************************************************** + * P U B L I C F U N C T I O N S + *****************************************************************************/ +uint8_t iap_write(uint32_t dst, char *src, uint32_t size) { + char err; + uint32_t buffer_vic; + uint8_t sec; + + buffer_vic = VICIntEnable; // save interrupt enable + VICIntEnClr = 0xFFFFFFFF; // clear vic + + sec = iap_get_sector(dst); + + /* check sector */ + if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) { + DEBUG("Warning: Sector %i not blank\n", sec); + } + + /* prepare sector */ + err = prepare_sectors(iap_get_sector(dst), iap_get_sector(dst)); + if (err) { + DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u", err); + /* set interrupts back and return */ + VICIntEnable = buffer_vic; + return 0; + } + /* write flash */ + else { + err = copy_ram_to_flash(dst, (uint32_t) src, size); + if(err) { + DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err); + /* set interrupts back and return */ + VICIntEnable = buffer_vic; + return 0; + } + /* check result */ + else { + err = compare(dst, (uint32_t) src, size); + if (err) { + DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]); + /* set interrupts back and return */ + VICIntEnable = buffer_vic; + return 0; + } + else + { + DEBUG("Data successfully written!\n"); + /* set interrupts back and return */ + return 1; + } + } + } +} + + +uint8_t iap_erase(uint32_t addr) { + /* check sector */ + if (!blank_check_sector(iap_get_sector(addr), iap_get_sector(addr))) { + DEBUG("Sector already blank!\n"); + return 1; + } + /* prepare sector */ + if (prepare_sectors(iap_get_sector(addr), iap_get_sector(addr))) { + DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n"); + return 0; + } + /* erase sector */ + if (erase_sectors(iap_get_sector(addr), iap_get_sector(addr))) { + DEBUG("-- ERROR: ERASE SECTOR --\n"); + return 0; + } + /* check again */ + if (blank_check_sector(iap_get_sector(addr), iap_get_sector(addr))) { + DEBUG("-- ERROR: BLANK_CHECK_SECTOR\n"); + return 0; + } + DEBUG("Sector successfully erased.\n"); + return 1; +} + + +/****************************************************************************** + * PRIVATE FUNCTIONS + *****************************************************************************/ + +static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4) { + iap_command[0] = code; // set command code + iap_command[1] = p1; // set 1st param + iap_command[2] = p2; // set 2nd param + iap_command[3] = p3; // set 3rd param + iap_command[4] = p4; // set 4th param + + ((void (*)())0x7ffffff1)(iap_command, iap_result); // IAP entry point + return *iap_result; +} + +/****************************************************************************** + * Function: blank_check_sector + * + * Description: This command is used to blank check a sector or multiple sectors + * of on-chip Flash memory. To blank check a single sector use the + * same "Start" and "End" sector numbers. + * Command: 53 + * Param0: Start Sector Number + * Param1: End Sector Number (should be greater than equal to the start + * sector number) + * + * Parameters: long tmp_sect1: Param0 + * long tmp_sect2: Param1 + * + * Return: Code CMD_SUCCESS | + * BUSY | + * SECTOR_NOT_BLANK | + * INVALID_SECTOR + * Result0: Offset of the first non blank word location if the status code is SECTOR_NOT_BLANK. + * Result1: Contents of non blank wird location. + *****************************************************************************/ +uint32_t blank_check_sector(uint32_t tmp_sect1, uint32_t tmp_sect2) { + return iap(BLANK_CHECK_SECTOR, tmp_sect1, tmp_sect2, 0 , 0); +} + + +/****************************************************************************** + * Function: copy_ram_to_flash + * + * Description: This command is used to programm the flash memory. the affected should be + * prepared first by calling "Prepare Sector for Write Operation" command. the + * affected sectors are automatically protected again once the copy command is + * successfully executed. the boot sector cannot be written by this command. + * Command: 51 + * Param0: (DST) Destination Flash adress where data bytes are to be written. + * This address should be a 512 byte boundary. + * Param1: (SRC) Source RAM adress from which data byre are to be read. + * Param2: Number of bytes to be written. Should be 512 | 1024 | 4096 | 8192. + * Param3: System Clock Frequency (CCLK) in KHz. + * + * Parameters: long tmp_adr_dst: Param0 + * long tmp_adr_src: Param1 + * long tmp_size: Param2 + * + * Return: Code CMD_SUCCESS | + * SRC_ADDR_ERROR (Address not on word boundary) | + * DST_ADDR_ERROR (Address not on correct boundary) | + * SRC_ADDR_NOT_MAPPED | + * DST_ADDR_NOT_MAPPED | + * COUNT_ERROR (Byte count is not 512 | 1024 | 4096 | 8192) | + * SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | + * BUSY + *****************************************************************************/ +uint32_t copy_ram_to_flash(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size) { + return iap(COPY_RAM_TO_FLASH, tmp_adr_dst, tmp_adr_src, tmp_size, _XTAL); +} + + +/****************************************************************************** + * Function: Prepare_Sector + * + * Description: This command must be executed before executing "Copy RAM to Flash" or "Erase Sector(s)" + * command. Successful execution of the "Copy RAM to Flash" or "Erase Sector(s)" command causes + * relevant sectors to be protected again. The boot sector can not be prepared by this command. To + * prepare a single sector use the same "Start" and "End" sector numbers.. + * Command code: 50 + * Param0: Start Sector Number + * Param1: End Sector Number: Should be greater than or equal to start sector number. + * + * Parameters: long tmp_sect1: Param0 + * long tmp_sect2: Param1 + * + * Return: Code CMD_SUCCESS | + * BUSY | + * INVALID_SECTOR + *****************************************************************************/ +uint32_t prepare_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2) { + return iap(PREPARE_SECTOR_FOR_WRITE_OPERATION, tmp_sect1, tmp_sect2, 0 , 0); +} + + +/****************************************************************************** + * Function: erase_sectors + * + * Description: This command is used to erase a sector or multiple sectors of on-chip Flash memory. The boot + * sector can not be erased by this command. To erase a single sector use the same "Start" and "End" + * sector numbers. + * Command code: 52 + * Param0: Start Sector Number + * Param1: End Sector Number: Should be greater than or equal to start sector number. + * Param2: System Clock Frequency (CCLK) in KHz. + * + * Parameters: long tmp_sect1: Param0 + * long tmp_sect2: Param1 + * + * Return: Code CMD_SUCCESS | + * BUSY | + * SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | + * INVALID_SECTOR + *****************************************************************************/ +uint32_t erase_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2) { + return iap(ERASE_SECTOR, tmp_sect1, tmp_sect2, _XTAL, 0); +} + + +/****************************************************************************** + * Function: compare + * + * Description: This command is used to compare the memory contents at two locations. compare result may not + * be correct when source or destination address contains any of the first 64 bytes starting + * from address zero. First 64 bytes can be re-mapped to RAM. + * Command Code: 56 + * Param0(DST): Starting Flash or RAM address from where data bytes are to be + * address should be a word boundary. + * Param1(SRC): Starting Flash or RAM address from where data bytes are to be + * address should be a word boundary. + * Param2: Number of bytes to be compared. Count should be in multiple of 4. + * + * Parameters: long tmp_adr_dst + * long tmp_adr_src + * long tmp_size + * + * Return: Code CMD_SUCCESS | + * COMPARE_ERROR | + * COUNT_ERROR (Byte count is not multiple of 4) | + * ADDR_ERROR | + * ADDR_NOT_MAPPED + * Result0: Offset of the first mismatch if the Status Code is COMPARE_ERROR. + *****************************************************************************/ +uint32_t compare(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size) { + return iap(COMPARE, tmp_adr_dst, tmp_adr_src, tmp_size, 0); +} diff --git a/cpu/arm_common/include/iap.h b/cpu/arm_common/include/iap.h new file mode 100644 index 0000000000..1ec589eab2 --- /dev/null +++ b/cpu/arm_common/include/iap.h @@ -0,0 +1,67 @@ +#ifndef IAP_H_ +#define IAP_H_ + +#include + +/* IAP-Commands */ +#define PREPARE_SECTOR_FOR_WRITE_OPERATION (50) +#define COPY_RAM_TO_FLASH (51) +#define ERASE_SECTOR (52) +#define BLANK_CHECK_SECTOR (53) +#define READ_PART_ID (54) +#define READ_BOOT_CODE_VERSION (55) +#define COMPARE (56) + +/* IAP status codes */ +#define CMD_SUCCESS (0) +#define INVALID_COMMAND (1) +#define SRC_ADDR_ERROR (2) +#define DST_ADDR_ERROR (3) +#define SRC_ADDR_NOT_MAPPED (4) +#define DST_ADDR_NOT_MAPPED (5) +#define COUNT_ERROR (6) +#define INVALID_SECTOR (7) +#define SECTOR_NOT_BLANK (8) +#define SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION (9) +#define COMPARE_ERROR (10) +#define BUSY (11) + +/* IAP start location on flash */ +#define IAP_LOCATION (0x7FFFFFF1) + +/* PLL */ +#define PLLCON_PLLE (0x01) ///< PLL Enable +#define PLLCON_PLLD (0x00) ///< PLL Disable +#define PLLCON_PLLC (0x03) ///< PLL Connect +#define PLLSTAT_PLOCK (0x0400) //infomem + . = ALIGN(4); + /************************************************************************** * RAM **************************************************************************/ diff --git a/cpu/lpc2387/lpc23xx-iap.c b/cpu/lpc2387/lpc23xx-iap.c new file mode 100644 index 0000000000..febe5c8d27 --- /dev/null +++ b/cpu/lpc2387/lpc23xx-iap.c @@ -0,0 +1,92 @@ +#include + +uint8_t iap_get_sector(uint32_t addr) { + if ((addr >=0x00000000) && (addr <= 0x00000FFF)) { + return 0; + } + if ((addr >=0x00001000) && (addr <= 0x00001FFF)) { + return 1; + } + if ((addr >=0x00002000) && (addr <= 0x00002FFF)) { + return 2; + } + if ((addr >=0x00003000) && (addr <= 0x00003FFF)) { + return 3; + } + if ((addr >=0x00004000) && (addr <= 0x00004FFF)) { + return 4; + } + if ((addr >=0x00005000) && (addr <= 0x00005FFF)) { + return 5; + } + if ((addr >=0x00006000) && (addr <= 0x00006FFF)) { + return 6; + } + if ((addr >=0x00007000) && (addr <= 0x00007FFF)) { + return 7; + } + + if ((addr >=0x00008000) && (addr <= 0x0000FFFF)) { + return 8; + } + if ((addr >=0x00010000) && (addr <= 0x00017FFF)) { + return 9; + } + if ((addr >=0x00018000) && (addr <= 0x0001FFFF)) { + return 10; + } + if ((addr >=0x00020000) && (addr <= 0x00027FFF)) { + return 11; + } + if ((addr >=0x00028000) && (addr <= 0x0002FFFF)) { + return 12; + } + if ((addr >=0x00030000) && (addr <= 0x00037FFF)) { + return 13; + } + if ((addr >=0x00038000) && (addr <= 0x0003FFFF)) { + return 14; + } + if ((addr >=0x00040000) && (addr <= 0x00047FFF)) { + return 15; + } + if ((addr >=0x00048000) && (addr <= 0x0004FFFF)) { + return 16; + } + if ((addr >=0x00050000) && (addr <= 0x00057FFF)) { + return 17; + } + if ((addr >=0x00058000) && (addr <= 0x0005FFFF)) { + return 18; + } + if ((addr >=0x00060000) && (addr <= 0x00067FFF)) { + return 19; + } + if ((addr >=0x00068000) && (addr <= 0x0006FFFF)) { + return 20; + } + if ((addr >=0x00070000) && (addr <= 0x00077FFF)) { + return 21; + } + if ((addr >=0x00078000) && (addr <= 0x00078FFF)) { + return 22; + } + if ((addr >=0x00079000) && (addr <= 0x00079FFF)) { + return 23; + } + if ((addr >=0x0007A000) && (addr <= 0x0007AFFF)) { + return 24; + } + if ((addr >=0x0007B000) && (addr <= 0x0007BFFF)) { + return 25; + } + if ((addr >=0x0007C000) && (addr <= 0x0007CFFF)) { + return 26; + } + if ((addr >=0x0007D000) && (addr <= 0x0007DFFF)) { + return 27; + } + + /* no valid address within flash */ + return 0xFF; +}