From cfccf0f2caeb1742e3c3a1c51107c7b73b8ffd5f Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 11 Oct 2010 17:05:33 +0200 Subject: [PATCH 001/199] * 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 8c3f0a2ea..cc6e273c2 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 002/199] * 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 000000000..97c2be0f3 --- /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 000000000..db12fc676 --- /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 000000000..f2592c24c --- /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 000000000..ae1d28b44 --- /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 000000000..6ca75c9c4 --- /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 b1181a57d..79e6f920c 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 41bf0779d..d1913ed54 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 003/199] * 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 d4a321913..8e04b9b97 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 004/199] * 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 e2ed342b5..2de8f8253 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 005/199] * 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 dd0a216d0..fd9ecb10b 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 006/199] * 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 6a960b47f..3c017c1a0 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 007/199] * 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 5111de74d..b0ad55f75 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 008/199] * 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 97da2efa8..462133ef7 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 9f75470ac..d2a4c8e7e 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 cc6e273c2..7de3b50e3 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 279bb456a..f391bb386 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 a9f466326..b6895a676 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 036792ee2..08594d1e3 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 daf898b88..62b720a55 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 739ec3acf..d0468ffea 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 32e05f90b..75a67e893 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 3f09c7284..4646c2679 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 e6ad35bc3..c4656d6cf 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 009/199] 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 000000000..7a5e6acb0 --- /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 000000000..25837a3ac --- /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 000000000..6f4a6ca81 --- /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 000000000..013073dd0 --- /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 010/199] 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 6f4a6ca81..000000000 --- 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 011/199] 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 000000000..e9f9af9ec --- /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 000000000..8e215d105 --- /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 000000000..261c511bb --- /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 012/199] 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 000000000..3f9c7e01d --- /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 000000000..ff9584556 --- /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 000000000..40df9e651 --- /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 013/199] ... --- 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 013073dd0..465e5562a 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 014/199] 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 373309603..707f2effd 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 015/199] * 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 373309603..707f2effd 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 016/199] * 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 08b3dcb0b..4b8912607 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 64862e7ed..2787dcbc7 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 69e12e6dd..97313916e 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 a58205319..7b5bd12c1 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 afff055c9..ca5f74ddb 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 d2a4c8e7e..df4c73060 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 7de3b50e3..dca0b45c9 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 707f2effd..32eda613f 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 a9d4722ea..be33fba93 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 f391bb386..907a635fd 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 b6895a676..49fbc53a5 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 35a20a47d..a5ffb50f4 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 3bdeb94db..eb2612f0f 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 cd6290530..f296f51dd 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 3159c005e..6272119a6 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 a1e583f4a..27dd5a957 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 f9b1f6900..8a0c95b88 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 f9ef062b4..057270f59 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 1ea79aa33..1ffd72b78 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 7a920aa05..830e5c9e7 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 08594d1e3..bb20e242c 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 75a67e893..d5e02846f 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 773265c75..414e57d61 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 a54c8bc35..0848bd509 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 0d87b9758..0b998de8b 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 017/199] * 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 dca0b45c9..39d3e6609 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 907a635fd..03e2f4f32 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 49fbc53a5..779fc2b6b 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 018/199] * 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 91d44fdf7..e98492a30 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 019/199] * 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 8eca19afc..85c1a1d70 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 db12fc676..bfe5a1a6f 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 7dee70e3b..467360044 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 000000000..a4debd447 --- /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 bf9ee8699..7ffd03140 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 de06c5024..d159f3334 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 ca5f74ddb..a506d3cc3 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 c649f402d..9119d911d 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 b0d77e03a..70e4039e8 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 020/199] * 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 6ca75c9c4..18d4a0472 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 ef2bbb658..d9634d6b4 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 021/199] * 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 fc0313906..c35fb0078 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 022/199] * 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 6f4a6ca81..acde8265f 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 023/199] * 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 be33fba93..b337a85fb 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 024/199] * name change --- Jamrules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jamrules b/Jamrules index 85c1a1d70..a2801d2a9 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 025/199] whitespace fix --- Jamrules.common | 1 - 1 file changed, 1 deletion(-) diff --git a/Jamrules.common b/Jamrules.common index d92882466..acc3ad643 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 026/199] * 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 b337a85fb..42e356196 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 027/199] * whitespace fix --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index aed49aaf3..44f24ab49 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 028/199] * 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 01600a4f7..e056a3dd6 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 029/199] * have project compiled last --- Jamfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index 3c442afa9..3e199228c 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 030/199] * 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 42e356196..affc7cb62 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 031/199] * 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 000000000..3f0bfe1df --- /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 000000000..de7619ada --- /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 000000000..1795de002 --- /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 032/199] * 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 3f0bfe1df..000000000 --- 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 1795de002..000000000 --- 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 000000000..eb5ff2d43 --- /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 de7619ada..d2b29dba6 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 000000000..bf1afd7a3 --- /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 000000000..bdeb11773 --- /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 000000000..ae130f551 --- /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 000000000..4dc625042 --- /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 000000000..e9fa06827 --- /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 033/199] * 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 9198f50bb..dceba9aed 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 034/199] * 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 9119d911d..573a21590 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 035/199] * 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 4fb8f52e5..9420fc7c2 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 7ab60e09c..ca713833a 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 9f7d9a973..0cc30f82c 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 036/199] * 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 573a21590..71e7e8bac 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 037/199] * 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 39d3e6609..d2d462218 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 038/199] * 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 dceba9aed..8ff7e11e3 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 039/199] * 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 779fc2b6b..8afbcb844 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 040/199] * 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 d2b29dba6..5acb9a05b 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 041/199] * 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 bf1afd7a3..5cfba74eb 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 042/199] * 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 eb5ff2d43..dfb96deb7 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 000000000..c4bc3294a --- /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 043/199] * remove unneccessary debug message --- sys/uart0.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sys/uart0.c b/sys/uart0.c index c4656d6cf..736048551 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 044/199] * 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 000000000..1734706b7 --- /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 c4bc3294a..7790a32e0 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 045/199] * 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 7499c9b85..3605a6a68 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 eee5c1fa2..83289e1e2 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 d5e02846f..4568b274d 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 5cfba74eb..6133537be 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 daa739b53..487256d44 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 3c017c1a0..f4dce41ee 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 046/199] * 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 32eda613f..f33c7bc6e 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 047/199] * 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 f4dce41ee..fc670243a 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 048/199] * 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 000000000..270f8cf77 --- /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 049/199] * 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 71e7e8bac..d929a2ecb 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 050/199] * 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 d872c0354..17fdeb34d 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 051/199] * 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 97313916e..d44f55a03 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 052/199] * 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 bb20e242c..925260fbb 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 053/199] * 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 5223597d6..932516a4b 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 054/199] * 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 000000000..947f72a35 --- /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 000000000..2a99d7225 --- /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 055/199] * 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 487256d44..9020914c8 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 fc670243a..8c5a665fc 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 932516a4b..e3656ecf8 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 056/199] * 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 e056a3dd6..e19c8a2a8 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 39f2c0f18..b2d8d2666 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 66ef085e3..34d7c1447 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 8afbcb844..59aaabcce 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 057/199] * 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 2a99d7225..bc2100f53 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 058/199] * 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 3605a6a68..6839969af 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 6133537be..40a019fc0 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 059/199] * 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 000000000..1e0ec8575 --- /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 060/199] * 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 df4c73060..268367fbb 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 d2d462218..a52597c11 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 8afbcb844..903435159 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 925260fbb..4723bfa17 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 62b720a55..2c9f21457 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 d0468ffea..8e1fd4d7d 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 4568b274d..59e9e0013 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 5acb9a05b..079d0d960 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 7790a32e0..c88c01550 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 4646c2679..363d437a2 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 736048551..b4c561822 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 061/199] * 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 268367fbb..ec8f5636c 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 062/199] * 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 34d7c1447..2de982772 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 063/199] * 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 9420fc7c2..c1580329e 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 ca713833a..4c896c47d 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 bbf20122e..490fd04f2 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 d929a2ecb..227569f5e 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 947f72a35..476db1c00 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 bc2100f53..548021180 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 17fdeb34d..c92b2b017 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 195b04fd8..a17b4173d 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 000000000..86d4add0e --- /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 8c5a665fc..02f4726cb 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 e3656ecf8..f5aa08c65 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 000000000..b24c8db93 --- /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 064/199] * 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 02f4726cb..37d809775 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 065/199] * 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 a2801d2a9..8dbb5f62c 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 d44f55a03..081ced085 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 2de982772..95f941253 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 ec8f5636c..359d778d9 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 03e2f4f32..bd8728fbe 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 58df5068e..31fcde282 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 86d4add0e..44c58a65a 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 37d809775..2e17a900b 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 f5aa08c65..e337db6f8 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 b4c561822..29ea4efa0 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 066/199] * 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 70e4039e8..d4bb6ec96 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 067/199] * 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 000000000..1bda7ddd2 --- /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 068/199] * 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 e7fbad663..b024f4b5c 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 bcc166b70..6c58b3d7d 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 476db1c00..2820d752c 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 548021180..959c69461 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 a17b4173d..e6ae372eb 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 2e17a900b..37ad42892 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 e337db6f8..bc68b612f 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 1bda7ddd2..0bfa5106c 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 069/199] * 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 000000000..707878ee4 --- /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 070/199] * 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 a52597c11..b38d5a966 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 d70853a77..98e7d2d69 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 d36829b1c..7cdb23d07 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 bc68b612f..123f0f4f0 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 b24c8db93..e00844453 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 0bfa5106c..9c6858377 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 071/199] * 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 9c6858377..c1ab1dc6a 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 072/199] * 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 c1ab1dc6a..0f9cb09a7 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 073/199] * 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 0cc30f82c..14835348d 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 074/199] * 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 8ff7e11e3..3107e8d40 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 081ced085..7aeac5ada 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 7cdb23d07..ff83433e3 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 4c896c47d..4642042a6 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 075/199] * 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 4723bfa17..441b7d6a2 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 076/199] * 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 31fcde282..d9a922aec 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 077/199] * 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 2820d752c..2c8d376ed 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 e6ae372eb..cc0eec2e4 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 123f0f4f0..41f152ce9 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 078/199] * 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 000000000..4236f517d --- /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 079/199] * 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 0f9cb09a7..342e2bacb 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) - - 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() + if (len(sys.argv) > 1): + port = sys.argv[1] + else: + port = None - myshell = MyCmd(stdout=ser) - myshell.prompt = "" + myshell = SerCmd(port) + 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 080/199] * 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 b024f4b5c..88160c891 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 6c58b3d7d..7c50553a8 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 707878ee4..91d557592 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 44c58a65a..25f99c089 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 081/199] * 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 91d557592..c29519c14 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 082/199] * mutex changes --- core/include/sched.h | 1 + core/mutex.c | 77 +++++++++++++------------------------------- core/sched.c | 10 ++++++ 3 files changed, 34 insertions(+), 54 deletions(-) diff --git a/core/include/sched.h b/core/include/sched.h index a506d3cc3..d31a83bc4 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 affc7cb62..c65946755 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); - - 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; - } - - tcb* process = (tcb*)next->data; - - sched_set_status(process, STATUS_PENDING); - - if ( mutex->queue.next != NULL) { - mutex->val = -1; - } else { - mutex->val = process->pid; +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); + + sched_switch_if_higher(active_thread->priority, process->priority, inISR()); + } else { + mutex->val = 0; + } } - 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 bd8728fbe..f2fa2ff41 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 083/199] * removed unused prio function --- core/mutex.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/mutex.c b/core/mutex.c index c65946755..9c1c17c83 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 084/199] * 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 edb9927f7..bfc50b4ce 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 085/199] * 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 d31a83bc4..ad30cfb60 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 9c1c17c83..fd4b708a3 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 f2fa2ff41..0563e46f4 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 086/199] * 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 153fa9b42..4891c5594 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 087/199] * 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 000000000..562d4305a --- /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 000000000..7a5c0a187 --- /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 088/199] * 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 2819ef61b..d38c22c75 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 29ea4efa0..04182b082 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 342e2bacb..59eadcfbd 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 089/199] * 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 e0223c05a..9713df17f 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 000000000..93d557720 --- /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 000000000..ef61dd61c --- /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 000000000..e7e039d88 --- /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 000000000..f19214914 --- /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 000000000..d3c92d4a0 --- /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 000000000..54ddabde7 --- /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 000000000..666893422 --- /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 000000000..01c98fe58 --- /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 000000000..010f31a5e --- /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 000000000..736f98218 --- /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 090/199] * 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 000000000..29f79da92 --- /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 000000000..25fbfdaa8 --- /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 000000000..acde8265f --- /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 0ae65f81c..a8ff40a5c 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 7018480f6..5c191e380 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 000000000..563f4669a --- /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 000000000..9c3c05b1d --- /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 091/199] * 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 666893422..4379b0f69 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 01c98fe58..6889f1617 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 092/199] * 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 | 107 ++++++++++++++++++++++++++----------- 6 files changed, 147 insertions(+), 69 deletions(-) diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 4379b0f69..87cf951bc 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 6889f1617..90f327592 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 a8ff40a5c..f236e498e 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 5c191e380..f5b88c9c0 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 563f4669a..4a60a42fe 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 9c3c05b1d..5c11f7fd7 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]; - - 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; +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++: + } } + 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 093/199] * 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 | 135 +++++++++++++------- 7 files changed, 132 insertions(+), 71 deletions(-) rename drivers/cc110x_ng/{cc1100.h => cc1100_ng.h} (97%) diff --git a/Jamrules b/Jamrules index 8dbb5f62c..13a6088f0 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 87cf951bc..85ea601d2 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 90f327592..cc42454fc 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 010f31a5e..0eaa70d57 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 f236e498e..a8ff40a5c 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 4a60a42fe..b8a44a91f 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 5c11f7fd7..85d4b6b4d 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; + + 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 { 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++: + m.type = PKT_PENDING; + + if (t & TRANSCEIVER_CC1100) { + receive_cc1100_packet(&trans_p); + } + else { + puts("Invalid transceiver type"); + return; } } - else { - puts("Invalid transceiver type"); + + 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 094/199] * 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 7a5c0a187..902ffc308 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 095/199] * 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 f19214914..1ea81b18f 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 85ea601d2..ef2e87659 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 e51518960..4847b47cb 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 29f79da92..28bf8b6f1 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 25fbfdaa8..070d695fb 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 b8a44a91f..fd5d0004b 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 85d4b6b4d..5110f498a 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 096/199] * 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 ef2e87659..60dce6bf8 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 cc42454fc..f20d1dbba 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 5110f498a..b820b71a3 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 097/199] * 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 54ddabde7..bf7309db9 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 60dce6bf8..39b871a00 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 f20d1dbba..ffc9053e3 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 098/199] * 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 39b871a00..146e56d5f 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 ffc9053e3..ebd7d9f6e 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 070d695fb..ef3b878ce 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 fd5d0004b..9668cb73a 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 b820b71a3..87c6cacaa 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 099/199] * 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 95f941253..75c9e9aeb 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 100/199] * 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 93d557720..55995d823 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 1ea81b18f..d4ae620c8 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 000000000..91346a634 --- /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 000000000..72a595d50 --- /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 146e56d5f..3ed3659f7 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 ebd7d9f6e..83ad0c112 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 ef3b878ce..f5df8f26e 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 9668cb73a..cecd8896a 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 87c6cacaa..ee1ff38de 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 101/199] * 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 2787dcbc7..6e0fae63b 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 000000000..252abbde4 --- /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 000000000..7ef179280 --- /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 102/199] * first implementation of msg queues --- core/include/msg.h | 8 ++++- core/include/tcb.h | 9 +++-- core/msg.c | 85 ++++++++++++++++++++++++++++++++++------------ core/thread.c | 14 ++++---- 4 files changed, 85 insertions(+), 31 deletions(-) diff --git a/core/include/msg.h b/core/include/msg.h index 4a0504c7f..4d9a0b9ab 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 75c9e9aeb..d5d2a6364 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,10 +42,13 @@ typedef struct tcb { uint16_t pid; uint16_t priority; + clist_node_t rq_entry; + void* wait_data; - queue_node_t msg_queue; + queue_node_t msg_waiters; - clist_node_t rq_entry; + cib_t msg_queue; + msg* msg_array; const char* name; char* stack_start; diff --git a/core/msg.c b/core/msg.c index f33c7bc6e..186eeb15d 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 (m->sender_pid == target_pid) { + return -1; + } if (target == NULL) { - eINT(); 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 d9a922aec..26ef87870 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 103/199] * 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 b2d8d2666..d17137ede 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 104/199] * 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 186eeb15d..b33eda569 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 26ef87870..e087f2a9d 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 105/199] [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 ee1ff38de..2c2e77f3e 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 106/199] * 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 252abbde4..b588fe671 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 107/199] * 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 acc3ad643..d2f4c9e86 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 108/199] [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 72a595d50..d8a79b37c 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 83ad0c112..1b686fdcc 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 f5df8f26e..96db66242 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 cecd8896a..a7cc68fa4 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 2c2e77f3e..faddb43a5 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 109/199] [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 d4ae620c8..6eb9ae232 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 3ed3659f7..55b7fd526 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 1b686fdcc..3431f2e7b 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 96db66242..0a9e6c302 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 a7cc68fa4..e844f572d 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 cc0eec2e4..fa8b989d3 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 41f152ce9..18526ac42 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 faddb43a5..ac52d9b1e 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 110/199] * 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 000000000..5563fee4e --- /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 111/199] [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 0a9e6c302..f3ab6c7ce 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 e844f572d..e6b03c696 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 5563fee4e..3ae631520 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 18526ac42..e894b2456 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 ac52d9b1e..3a1f3414d 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 112/199] [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 91346a634..de8f61557 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 f3ab6c7ce..86c8b9f71 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 e6b03c696..a31876bd7 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 3a1f3414d..d3828d186 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 113/199] * 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 ce8a446b3..cf17d9970 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 114/199] [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 543888236..0252c7578 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 000000000..92f8ff82c --- /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 000000000..1ec589eab --- /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 000000000..febe5c8d2 --- /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; +} From a46cdf189a3baef47e5f520caedf360dc4d9227c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 1 Dec 2010 16:26:48 +0100 Subject: [PATCH 115/199] * introduced identifiers (include shell commands to get and set) * introduced a system wide configuration --- board/msba2/Jamfile | 2 +- board/msba2/board_init.c | 23 +++++++- board/msba2/config.c | 8 +++ core/include/config.h | 27 +++++++++ cpu/arm_common/bootloader.c | 4 ++ cpu/arm_common/iap.c | 59 ++++++++++++++------ cpu/arm_common/include/{iap.h => flashrom.h} | 8 ++- cpu/lpc2387/lpc23xx-iap.c | 5 +- sys/shell/Jamfile | 2 +- sys/shell/id.c | 17 ++++++ sys/shell/shell_commands.c | 5 +- 11 files changed, 132 insertions(+), 28 deletions(-) create mode 100644 board/msba2/config.c create mode 100644 core/include/config.h rename cpu/arm_common/include/{iap.h => flashrom.h} (90%) create mode 100644 sys/shell/id.c diff --git a/board/msba2/Jamfile b/board/msba2/Jamfile index 88106e45c..4bef1bd29 100644 --- a/board/msba2/Jamfile +++ b/board/msba2/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msba2 ; -Module board : board_init.c ; +Module board : board_init.c config.c ; UseModule board ; UseModule board_common ; diff --git a/board/msba2/board_init.c b/board/msba2/board_init.c index 44c6cc33a..4996b0778 100644 --- a/board/msba2/board_init.c +++ b/board/msba2/board_init.c @@ -42,12 +42,21 @@ and the mailinglist (subscription via web site) */ #include #include -#include "VIC.h" -#include "cpu.h" +#include +#include +#include +#include +#include #define PCRTC BIT9 #define CL_CPU_DIV 4 +config_t sysconfig = { + 0, ///< default ID + 0, ///< default radio address + 0, ///< default radio channel +}; + /*---------------------------------------------------------------------------*/ /** * @brief Enabling MAM and setting number of clocks used for Flash memory fetch @@ -154,3 +163,13 @@ void bl_blink(void) { LED_GREEN_OFF; } +void bl_config_init(void) { + extern char configmem[]; + if (*((uint16_t*) configmem) == CONFIG_KEY) { + memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); + LED_GREEN_TOGGLE; + } + else { + config_save(); + } +} diff --git a/board/msba2/config.c b/board/msba2/config.c new file mode 100644 index 000000000..9d149eb86 --- /dev/null +++ b/board/msba2/config.c @@ -0,0 +1,8 @@ +#include +#include +#include + +uint8_t config_save(void) { + configmem_t mem = { CONFIG_KEY, sysconfig }; + return (flashrom_erase((uint32_t) configmem) && flashrom_write((uint32_t) configmem, (char*) &mem, sizeof(mem))); +} diff --git a/core/include/config.h b/core/include/config.h new file mode 100644 index 000000000..d320f8a4e --- /dev/null +++ b/core/include/config.h @@ -0,0 +1,27 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#include + +#define CONFIG_KEY (0x1701) + +extern char configmem[]; + +/* @brief: Stores configuration data of the node */ +typedef struct { + uint16_t id; ///< unique node identifier + uint8_t radio_address; ///< address for radio communication + uint8_t radio_channel; ///< current frequency +} config_t; + +/* @brief: Element to store in flashrom */ +typedef struct { + uint16_t magic_key; ///< validity check + config_t config; ///< the node's configuration +} configmem_t; + +extern config_t sysconfig; + +uint8_t config_save(void); + +#endif /* CONFIG_H */ diff --git a/cpu/arm_common/bootloader.c b/cpu/arm_common/bootloader.c index 7634c2017..5560fb413 100644 --- a/cpu/arm_common/bootloader.c +++ b/cpu/arm_common/bootloader.c @@ -165,6 +165,7 @@ void bootloader(void) { extern void bl_init_ports(void); extern void bl_init_clks(void); extern void bl_blink(void); + extern void bl_config_init(void); /* board specific setup of clocks */ bl_init_clks(); @@ -177,6 +178,9 @@ void bootloader(void) { /* board specific setup of UART */ bl_uart_init(); + /* initialize board configuration */ + bl_config_init(); + printf("Board initialized.\n"); } diff --git a/cpu/arm_common/iap.c b/cpu/arm_common/iap.c index 92f8ff82c..8b6428a85 100644 --- a/cpu/arm_common/iap.c +++ b/cpu/arm_common/iap.c @@ -5,12 +5,16 @@ * */ -#include +#include +#include #include #define ENABLE_DEBUG #include +/* pointer to reserved flash rom section for configuration data */ +__attribute ((aligned(256))) char configmem[256] __attribute__ ((section (".configmem"))); + 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 @@ -27,15 +31,19 @@ static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32 /****************************************************************************** * 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) { +uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) { char err; - uint32_t buffer_vic; + unsigned intstate; uint8_t sec; - buffer_vic = VICIntEnable; // save interrupt enable - VICIntEnClr = 0xFFFFFFFF; // clear vic + //buffer_vic = VICIntEnable; // save interrupt enable + //VICIntEnClr = 0xFFFFFFFF; // clear vic - sec = iap_get_sector(dst); + sec = flashrom_get_sector(dst); + if (sec == INVALID_ADDRESS) { + DEBUG("Invalid address\n"); + return 0; + } /* check sector */ if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) { @@ -43,35 +51,39 @@ uint8_t iap_write(uint32_t dst, char *src, uint32_t size) { } /* prepare sector */ - err = prepare_sectors(iap_get_sector(dst), iap_get_sector(dst)); + err = prepare_sectors(sec, sec); if (err) { - DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u", err); + DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err); /* set interrupts back and return */ - VICIntEnable = buffer_vic; +// VICIntEnable = buffer_vic; return 0; } /* write flash */ else { - err = copy_ram_to_flash(dst, (uint32_t) src, size); + intstate = disableIRQ(); + err = copy_ram_to_flash(dst, (uint32_t) src, 256); + restoreIRQ(intstate); if(err) { DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err); /* set interrupts back and return */ - VICIntEnable = buffer_vic; + restoreIRQ(intstate); +// VICIntEnable = buffer_vic; return 0; } /* check result */ else { - err = compare(dst, (uint32_t) src, size); + err = compare(dst, (uint32_t) src, 256); if (err) { DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]); /* set interrupts back and return */ - VICIntEnable = buffer_vic; +// VICIntEnable = buffer_vic; return 0; } else { DEBUG("Data successfully written!\n"); /* set interrupts back and return */ +// VICIntEnable = buffer_vic; return 1; } } @@ -79,24 +91,35 @@ uint8_t iap_write(uint32_t dst, char *src, uint32_t size) { } -uint8_t iap_erase(uint32_t addr) { +uint8_t flashrom_erase(uint32_t addr) { + uint8_t sec = flashrom_get_sector(addr); + unsigned intstate; + + if (sec == INVALID_ADDRESS) { + DEBUG("Invalid address\n"); + return 0; + } + /* check sector */ - if (!blank_check_sector(iap_get_sector(addr), iap_get_sector(addr))) { + if (!blank_check_sector(sec, sec)) { DEBUG("Sector already blank!\n"); return 1; } /* prepare sector */ - if (prepare_sectors(iap_get_sector(addr), iap_get_sector(addr))) { + if (prepare_sectors(sec, sec)) { DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n"); return 0; } + intstate = disableIRQ(); /* erase sector */ - if (erase_sectors(iap_get_sector(addr), iap_get_sector(addr))) { + if (erase_sectors(sec, sec)) { DEBUG("-- ERROR: ERASE SECTOR --\n"); + restoreIRQ(intstate); return 0; } + restoreIRQ(intstate); /* check again */ - if (blank_check_sector(iap_get_sector(addr), iap_get_sector(addr))) { + if (blank_check_sector(sec, sec)) { DEBUG("-- ERROR: BLANK_CHECK_SECTOR\n"); return 0; } diff --git a/cpu/arm_common/include/iap.h b/cpu/arm_common/include/flashrom.h similarity index 90% rename from cpu/arm_common/include/iap.h rename to cpu/arm_common/include/flashrom.h index 1ec589eab..bc9dc92ce 100644 --- a/cpu/arm_common/include/iap.h +++ b/cpu/arm_common/include/flashrom.h @@ -26,6 +26,8 @@ #define COMPARE_ERROR (10) #define BUSY (11) +#define INVALID_ADDRESS (0xFF) + /* IAP start location on flash */ #define IAP_LOCATION (0x7FFFFFF1) @@ -42,7 +44,7 @@ * * @return 1 on success, 0 otherwise */ -uint8_t iap_erase(uint32_t addr); +uint8_t flashrom_erase(uint32_t addr); /* @brief Write buffer from ram to flash * @@ -52,7 +54,7 @@ uint8_t iap_erase(uint32_t addr); * * @return 1 on success, 0 otherwise */ -uint8_t iap_write(uint32_t dst, char *src, uint32_t size); +uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size); /* * @brief: Converts 'addr' to sector number @@ -62,6 +64,6 @@ uint8_t iap_write(uint32_t dst, char *src, uint32_t size); * * @return Sector number. 0xFF on error */ -uint8_t iap_get_sector(uint32_t addr); +uint8_t flashrom_get_sector(uint32_t addr); #endif /*IAP_H_*/ diff --git a/cpu/lpc2387/lpc23xx-iap.c b/cpu/lpc2387/lpc23xx-iap.c index febe5c8d2..574eb5793 100644 --- a/cpu/lpc2387/lpc23xx-iap.c +++ b/cpu/lpc2387/lpc23xx-iap.c @@ -1,6 +1,7 @@ #include +#include -uint8_t iap_get_sector(uint32_t addr) { +uint8_t flashrom_get_sector(uint32_t addr) { if ((addr >=0x00000000) && (addr <= 0x00000FFF)) { return 0; } @@ -88,5 +89,5 @@ uint8_t iap_get_sector(uint32_t addr) { } /* no valid address within flash */ - return 0xFF; + return INVALID_ADDRESS; } diff --git a/sys/shell/Jamfile b/sys/shell/Jamfile index fa8b989d3..d147c243c 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 cc1100_ng.c : shell ; +Module shell_commands : shell_commands.c id.c rtc.c sht11.c ltc4150.c cc1100.c cc1100_ng.c : shell ; Module ps : ps.c ; diff --git a/sys/shell/id.c b/sys/shell/id.c new file mode 100644 index 000000000..6714efbbb --- /dev/null +++ b/sys/shell/id.c @@ -0,0 +1,17 @@ +#include +#include + +void _id_handler(char *id) { + uint16_t newid; + + if (sscanf(id, "id %hu", &newid) == 1) { + printf("Setting new id %u\n", newid); + sysconfig.id = newid; + if (!config_save()) { + puts("ERROR setting new id"); + } + } + else { + printf("Current id: %u\n", sysconfig.id); + } +} diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index e894b2456..68a509c53 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -1,6 +1,8 @@ #include #include +extern void _id_handler(char* id); + #ifdef MODULE_PS extern void _ps_handler(char* unused); #endif @@ -36,11 +38,12 @@ extern void _cc1100_ng_monitor_handler(char *mode); #endif const shell_command_t _shell_command_list[] = { + {"id", "Gets or sets the node's id.", _id_handler}, #ifdef MODULE_PS {"ps", "Prints information about running threads.", _ps_handler}, #endif #ifdef MODULE_RTC - {"date", "Geets or gets current date and time.", _date_handler}, + {"date", "Gets or sets current date and time.", _date_handler}, #endif #ifdef MODULE_SHT11 {"temp", "Prints measured temperature.", _get_temperature_handler}, From 69a7fb1d76ce5ee0c2ecc1b092ce3e2376220905 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 1 Dec 2010 17:07:05 +0100 Subject: [PATCH 116/199] * modified cc110x_ng driver to use sysconfig --- drivers/cc110x_ng/cc1100.c | 24 ++++++++++++------------ projects/test_cc110x_ng/main.c | 2 ++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 55b7fd526..1fd378c9d 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -6,6 +6,7 @@ #include #include +#include //#define ENABLE_DEBUG (1) #include @@ -21,9 +22,6 @@ cc1100_statistic_t cc1100_statistic; volatile cc1100_flags rflags; ///< Radio control flags volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state -static uint8_t radio_address; ///< Radio address -static uint8_t radio_channel; ///< Radio channel - int transceiver_pid; ///< the transceiver thread pid /* internal function prototypes */ @@ -65,8 +63,8 @@ void cc1100_init(int tpid) { rflags.WOR_RST = 0; /* Set default channel number */ - cc1100_set_channel(CC1100_DEFAULT_CHANNR); - DEBUG("CC1100 initialized and set to channel %i\n", radio_channel); + cc1100_set_channel(sysconfig.radio_channel); + DEBUG("CC1100 initialized and set to channel %i\n", sysconfig.radio_channel); // Switch to desired mode (WOR or RX) rd_set_mode(RADIO_MODE_ON); @@ -93,7 +91,7 @@ uint8_t cc1100_get_buffer_pos(void) { } radio_address_t cc1100_get_address() { - return radio_address; + return sysconfig.radio_address; } radio_address_t cc1100_set_address(radio_address_t address) { @@ -106,8 +104,9 @@ radio_address_t cc1100_set_address(radio_address_t address) { write_register(CC1100_ADDR, id); } - radio_address = id; - return radio_address; + sysconfig.radio_address = id; + config_save(); + return sysconfig.radio_address; } void cc1100_set_monitor(uint8_t mode) { @@ -207,7 +206,7 @@ char* cc1100_state_to_text(uint8_t state) { void cc1100_print_config(void) { printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); - printf("Current channel number: %u\r\n", radio_channel); + printf("Current channel number: %u\r\n", sysconfig.radio_channel); } void switch_to_pwd(void) { @@ -223,12 +222,13 @@ int16_t cc1100_set_channel(uint8_t channr) { return 0; } write_register(CC1100_CHANNR, channr*10); - radio_channel = channr; - return radio_channel; + sysconfig.radio_channel = channr; + config_save(); + return sysconfig.radio_channel; } int16_t cc1100_get_channel(void) { - return radio_channel; + return sysconfig.radio_channel; } diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index 86c8b9f71..dda0a7a3d 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -94,6 +94,8 @@ void radio(void) { printf("\tLength:\t%u\n", p->length); printf("\tSrc:\t%u\n", p->src); printf("\tDst:\t%u\n", p->dst); + printf("\tLQI:\t%u\n", p->lqi); + printf("\tRSSI:\t%u\n", p->rssi); for (i = 0; i < p->length; i++) { printf("%02X ", p->data[i]); From 2cc6d44e522a3e27e770f4412cfdd304bf11c3f0 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 1 Dec 2010 17:13:37 +0100 Subject: [PATCH 117/199] * initial checkin of timex lib --- sys/include/timex.h | 13 +++++++++++++ sys/timex.c | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 sys/include/timex.h create mode 100644 sys/timex.c diff --git a/sys/include/timex.h b/sys/include/timex.h new file mode 100644 index 000000000..83707091c --- /dev/null +++ b/sys/include/timex.h @@ -0,0 +1,13 @@ +#ifndef __TIMEX_H +#define __TIMEX_H + +#include + +typedef struct timex_t { + uint32_t seconds; + uint32_t nanoseconds; +} timex_t; + +timex_t timex_add(const timex_t a, const timex_t b); + +#endif /* __TIMEX_H */ diff --git a/sys/timex.c b/sys/timex.c new file mode 100644 index 000000000..e422f1f31 --- /dev/null +++ b/sys/timex.c @@ -0,0 +1,14 @@ +#include + +timex_t timex_add(const timex_t a, const timex_t b) { + timex_t result; + result.seconds = a.seconds + b.seconds; + result.nanoseconds = a.nanoseconds + b.nanoseconds; + + while (result.nanoseconds > 1000*1000) { + result.nanoseconds -= 1000*1000; + result.seconds++; + } + + return result; +} From 0b515b4063dd2250a1b7ebcf636755d0ca609105 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 1 Dec 2010 17:15:58 +0100 Subject: [PATCH 118/199] * added timex to Jamfile --- sys/Jamfile | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/Jamfile b/sys/Jamfile index a8ff40a5c..fcbf64e37 100644 --- a/sys/Jamfile +++ b/sys/Jamfile @@ -27,6 +27,7 @@ SubDir TOP sys ; +Module timex : timex.c ; Module swtimer : swtimer.c : hwtimer ; Module posix_io : posix_io.c ; From 0de6300af09151ce640d29766c29e01c747511c4 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 1 Dec 2010 17:23:28 +0100 Subject: [PATCH 119/199] * added some time functions --- sys/include/timex.h | 6 ++++++ sys/timex.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/sys/include/timex.h b/sys/include/timex.h index 83707091c..6480223cb 100644 --- a/sys/include/timex.h +++ b/sys/include/timex.h @@ -8,6 +8,12 @@ typedef struct timex_t { uint32_t nanoseconds; } timex_t; +/* a+b */ timex_t timex_add(const timex_t a, const timex_t b); +/* a-b*/ +timex_t timex_sub(const timex_t a, const timex_t b); + +timex_t timex_set(uint32_t seconds, uint32_t nanoseconds); + #endif /* __TIMEX_H */ diff --git a/sys/timex.c b/sys/timex.c index e422f1f31..9a1fad129 100644 --- a/sys/timex.c +++ b/sys/timex.c @@ -12,3 +12,25 @@ timex_t timex_add(const timex_t a, const timex_t b) { return result; } + +timex_t timex_set(uint32_t seconds, uint32_t nanoseconds) { + timex_t result; + result.seconds = seconds; + result.nanoseconds = nanoseconds; + + while (result.nanoseconds > 1000*1000) { + result.nanoseconds -= 1000*1000; + result.seconds++; + } + + return result; + +} + +timex_t timex_sub(const timex_t a, const timex_t b) { + timex_t result; + result.seconds = a.seconds - b.seconds; + result.nanoseconds = a.nanoseconds - b.nanoseconds; + + return result; +} From 4a2c58bbba2b6d0e554e623537db039be4e78c6b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 2 Dec 2010 15:38:28 +0100 Subject: [PATCH 120/199] [drivers/cc110x_ng sys/transceiver] * updated interface to switch transceiver off and back to rx mode * removed some debugging stuff --- board/msba2/board_init.c | 1 - cpu/arm_common/iap.c | 554 +++++++++++++++--------------- drivers/cc110x_ng/cc1100-config.h | 5 +- drivers/cc110x_ng/cc1100-tx.c | 1 + drivers/cc110x_ng/cc1100.c | 4 +- projects/laser/Jamfile | 2 +- projects/test_cc110x_ng/main.c | 45 ++- sys/include/radio/types.h | 2 + sys/shell/cc1100_ng.c | 2 - sys/transceiver.c | 34 +- 10 files changed, 361 insertions(+), 289 deletions(-) diff --git a/board/msba2/board_init.c b/board/msba2/board_init.c index 4996b0778..aea2c5093 100644 --- a/board/msba2/board_init.c +++ b/board/msba2/board_init.c @@ -167,7 +167,6 @@ void bl_config_init(void) { extern char configmem[]; if (*((uint16_t*) configmem) == CONFIG_KEY) { memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); - LED_GREEN_TOGGLE; } else { config_save(); diff --git a/cpu/arm_common/iap.c b/cpu/arm_common/iap.c index 8b6428a85..5802b2876 100644 --- a/cpu/arm_common/iap.c +++ b/cpu/arm_common/iap.c @@ -1,277 +1,277 @@ -/* iap driver - * - * based on iap driver for LPC2148 Controller made by Andreas Weschenfelder, 2008 - * see: - * - */ - -#include -#include -#include - -#define ENABLE_DEBUG -#include - -/* pointer to reserved flash rom section for configuration data */ -__attribute ((aligned(256))) char configmem[256] __attribute__ ((section (".configmem"))); - -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 flashrom_write(uint32_t dst, char *src, uint32_t size) { - char err; - unsigned intstate; - uint8_t sec; - - //buffer_vic = VICIntEnable; // save interrupt enable - //VICIntEnClr = 0xFFFFFFFF; // clear vic - - sec = flashrom_get_sector(dst); - if (sec == INVALID_ADDRESS) { - DEBUG("Invalid address\n"); - return 0; - } - - /* check sector */ - if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) { - DEBUG("Warning: Sector %i not blank\n", sec); - } - - /* prepare sector */ - err = prepare_sectors(sec, sec); - if (err) { - DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err); - /* set interrupts back and return */ -// VICIntEnable = buffer_vic; - return 0; - } - /* write flash */ - else { - intstate = disableIRQ(); - err = copy_ram_to_flash(dst, (uint32_t) src, 256); - restoreIRQ(intstate); - if(err) { - DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err); - /* set interrupts back and return */ - restoreIRQ(intstate); -// VICIntEnable = buffer_vic; - return 0; - } - /* check result */ - else { - err = compare(dst, (uint32_t) src, 256); - 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 */ -// VICIntEnable = buffer_vic; - return 1; - } - } - } -} - - -uint8_t flashrom_erase(uint32_t addr) { - uint8_t sec = flashrom_get_sector(addr); - unsigned intstate; - - if (sec == INVALID_ADDRESS) { - DEBUG("Invalid address\n"); - return 0; - } - - /* check sector */ - if (!blank_check_sector(sec, sec)) { - DEBUG("Sector already blank!\n"); - return 1; - } - /* prepare sector */ - if (prepare_sectors(sec, sec)) { - DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n"); - return 0; - } - intstate = disableIRQ(); - /* erase sector */ - if (erase_sectors(sec, sec)) { - DEBUG("-- ERROR: ERASE SECTOR --\n"); - restoreIRQ(intstate); - return 0; - } - restoreIRQ(intstate); - /* check again */ - if (blank_check_sector(sec, sec)) { - 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); -} +/* iap driver + * + * based on iap driver for LPC2148 Controller made by Andreas Weschenfelder, 2008 + * see: + * + */ + +#include +#include +#include + +//#define ENABLE_DEBUG +#include + +/* pointer to reserved flash rom section for configuration data */ +__attribute ((aligned(256))) char configmem[256] __attribute__ ((section (".configmem"))); + +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 flashrom_write(uint32_t dst, char *src, uint32_t size) { + char err; + unsigned intstate; + uint8_t sec; + + //buffer_vic = VICIntEnable; // save interrupt enable + //VICIntEnClr = 0xFFFFFFFF; // clear vic + + sec = flashrom_get_sector(dst); + if (sec == INVALID_ADDRESS) { + DEBUG("Invalid address\n"); + return 0; + } + + /* check sector */ + if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) { + DEBUG("Warning: Sector %i not blank\n", sec); + } + + /* prepare sector */ + err = prepare_sectors(sec, sec); + if (err) { + DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err); + /* set interrupts back and return */ +// VICIntEnable = buffer_vic; + return 0; + } + /* write flash */ + else { + intstate = disableIRQ(); + err = copy_ram_to_flash(dst, (uint32_t) src, 256); + restoreIRQ(intstate); + if(err) { + DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err); + /* set interrupts back and return */ + restoreIRQ(intstate); +// VICIntEnable = buffer_vic; + return 0; + } + /* check result */ + else { + err = compare(dst, (uint32_t) src, 256); + 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 */ +// VICIntEnable = buffer_vic; + return 1; + } + } + } +} + + +uint8_t flashrom_erase(uint32_t addr) { + uint8_t sec = flashrom_get_sector(addr); + unsigned intstate; + + if (sec == INVALID_ADDRESS) { + DEBUG("Invalid address\n"); + return 0; + } + + /* check sector */ + if (!blank_check_sector(sec, sec)) { + DEBUG("Sector already blank!\n"); + return 1; + } + /* prepare sector */ + if (prepare_sectors(sec, sec)) { + DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n"); + return 0; + } + intstate = disableIRQ(); + /* erase sector */ + if (erase_sectors(sec, sec)) { + DEBUG("-- ERROR: ERASE SECTOR --\n"); + restoreIRQ(intstate); + return 0; + } + restoreIRQ(intstate); + /* check again */ + if (blank_check_sector(sec, sec)) { + 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/drivers/cc110x_ng/cc1100-config.h b/drivers/cc110x_ng/cc1100-config.h index e7e039d88..2069375a1 100644 --- a/drivers/cc110x_ng/cc1100-config.h +++ b/drivers/cc110x_ng/cc1100-config.h @@ -1,6 +1,8 @@ #ifndef CC1100_CONFIG_H #define CC1100_CONFIG_H +#include + /** CC1100 register configuration */ typedef struct { uint8_t IOCFG2; @@ -56,6 +58,7 @@ typedef struct { typedef struct { uint32_t TOF; ///< Time of flight of the last packet and last ACK + timex_t TOA; ///< Time of packet arriveal 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 @@ -82,10 +85,8 @@ typedef struct cc1100_statistic { 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; diff --git a/drivers/cc110x_ng/cc1100-tx.c b/drivers/cc110x_ng/cc1100-tx.c index d8a79b37c..47ce43a6a 100644 --- a/drivers/cc110x_ng/cc1100-tx.c +++ b/drivers/cc110x_ng/cc1100-tx.c @@ -60,6 +60,7 @@ uint8_t cc1100_send(cc1100_packet_t *packet) { restoreIRQ(cpsr); // Wait for GDO2 to be cleared -> end of packet while (cc1100_get_gdo2() != 0); + LED_GREEN_TOGGLE; // Experimental - TOF Measurement cc1100_after_send(); diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 1fd378c9d..8fc5d176a 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -202,14 +202,14 @@ char* cc1100_state_to_text(uint8_t state) { } } - void cc1100_print_config(void) { printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); printf("Current channel number: %u\r\n", sysconfig.radio_channel); } -void switch_to_pwd(void) { +void cc1100_switch_to_pwd(void) { + DEBUG("[cc110x_ng] switching to powerdown\n"); cc1100_wakeup_from_rx(); cc1100_spi_strobe(CC1100_SPWD); radio_state = RADIO_PWD; diff --git a/projects/laser/Jamfile b/projects/laser/Jamfile index 562d4305a..9a9c55950 100644 --- a/projects/laser/Jamfile +++ b/projects/laser/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects laser ; -Module laser : main.c : sht11 swtimer auto_init ; +Module laser : main.c : sht11 ltc4150 swtimer auto_init ; UseModule laser ; diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index dda0a7a3d..baf042dfd 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -18,7 +18,7 @@ #define SND_BUFFER_SIZE (100) #define RCV_BUFFER_SIZE (64) -#define SENDING_DELAY (1000) +#define SENDING_DELAY (5 * 1000) char shell_stack_buffer[SHELL_STACK_SIZE]; char radio_stack_buffer[RADIO_STACK_SIZE]; @@ -31,12 +31,20 @@ static msg mesg; static transceiver_command_t tcmd; static radio_packet_t p; +static uint32_t sending_delay = SENDING_DELAY; + void sender(char *count); void print_buffer(char *unused); +void switch2rx(char *unused); +void powerdown(char *unused); +void set_delay(char *delay); shell_t shell; const shell_command_t sc[] = { + {"on", "", switch2rx}, + {"off", "", powerdown}, {"snd", "", sender}, + {"delay", "", set_delay}, {"buffer", "", print_buffer}, {NULL, NULL, NULL}}; @@ -63,7 +71,7 @@ void sender(char *count) { puts("."); p.data = snd_buffer[i % SND_BUFFER_SIZE]; msg_send(&mesg, transceiver_pid, 1); - swtimer_usleep(SENDING_DELAY); + swtimer_usleep(sending_delay); } } @@ -79,6 +87,39 @@ void print_buffer(char *unused) { } } +void switch2rx(char *unused) { + mesg.type = SWITCH_RX; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + puts("Turning transceiver on"); + if (msg_send(&mesg, transceiver_pid, 1)) { + puts("\tsuccess"); + } +} + +void powerdown(char *unused) { + mesg.type = POWERDOWN; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + puts("Turning transceiver off"); + if (msg_send(&mesg, transceiver_pid, 1)) { + puts("\tsuccess"); + } +} + +void set_delay(char *delay) { + uint32_t d; + + if (sscanf(delay, "delay %lu", &d) == 1) { + sending_delay = d; + } + else { + puts("Usage:\tdelay <µs>"); + } +} + void radio(void) { msg m; radio_packet_t *p; diff --git a/sys/include/radio/types.h b/sys/include/radio/types.h index f5b88c9c0..c84a12e09 100644 --- a/sys/include/radio/types.h +++ b/sys/include/radio/types.h @@ -40,6 +40,7 @@ and the mailinglist (subscription via web site) #include #include +#include typedef uint8_t protocol_t; ///< Packet protocol type typedef uint16_t radio_address_t; ///< Radio layer address type @@ -83,6 +84,7 @@ typedef struct __attribute__ ((packed)) { uint16_t dst; ///< Radio destination address uint8_t rssi; ///< Radio Signal Strength Indication uint8_t lqi; ///< Link Quality Indicator + timex_t toa; ///< Time of Arrival uint8_t length; ///< Length of payload uint8_t *data; ///< Payload } radio_packet_t; diff --git a/sys/shell/cc1100_ng.c b/sys/shell/cc1100_ng.c index 3ae631520..3fe0d1f49 100644 --- a/sys/shell/cc1100_ng.c +++ b/sys/shell/cc1100_ng.c @@ -82,5 +82,3 @@ void _cc1100_ng_monitor_handler(char *mode) { puts("Usage:\nmonitor "); } } - - diff --git a/sys/transceiver.c b/sys/transceiver.c index d3828d186..d0d5920e5 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -19,7 +19,7 @@ #endif #endif -#define ENABLE_DEBUG (1) +//#define ENABLE_DEBUG (1) #include /*------------------------------------------------------------------------------------*/ @@ -57,6 +57,8 @@ 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); +static void powerdown(transceiver_type_t t); +static void switch_to_rx(transceiver_type_t t); /*------------------------------------------------------------------------------------*/ /* Transceiver init */ @@ -122,6 +124,7 @@ void run(void) { 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: @@ -152,6 +155,12 @@ void run(void) { case SET_MONITOR: set_monitor(cmd->transceivers, cmd->data); break; + case POWERDOWN: + powerdown(cmd->transceivers); + break; + case SWITCH_RX: + switch_to_rx(cmd->transceivers); + break; default: DEBUG("Unknown message received\n"); break; @@ -219,7 +228,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { if (reg[i].transceivers & t) { m.content.ptr = (char*) &(transceiver_buffer[transceiver_buffer_pos]); DEBUG("Notify thread %i\n", reg[i].pid); - if (msg_send(&m, reg[i].pid, false)) { + if (msg_send(&m, reg[i].pid, false) && (m.type != ENOBUFFER)) { transceiver_buffer[transceiver_buffer_pos].processing++; } } @@ -364,3 +373,24 @@ static void set_monitor(transceiver_type_t t, void *mode) { break; } } +/*------------------------------------------------------------------------------------*/ +static void powerdown(transceiver_type_t t) { + switch (t) { + case TRANSCEIVER_CC1100: + cc1100_switch_to_pwd(); + break; + default: + break; + } +} + +/*------------------------------------------------------------------------------------*/ +static void switch_to_rx(transceiver_type_t t) { + switch (t) { + case TRANSCEIVER_CC1100: + cc1100_switch_to_rx(); + break; + default: + break; + } +} From fb1cb91c75ae37e5400e1fbc6cd3eb2f61826fc7 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 3 Dec 2010 18:42:03 +0100 Subject: [PATCH 121/199] [board/msp-430-common board/msba2 core/] * introduced dummy function for msp-430 config-save * moved sysconfig from board to core [sys/transceiver cpu/] * moved some buffer size defines to cpu dependent parts * some cleanups --- board/msb-430-common/Jamfile | 2 +- board/msb-430-common/Jamrules.msb-430-common | 2 +- board/msb-430-common/config.c | 6 + board/msba2/board_init.c | 6 - core/include/kernel.h | 3 + core/kernel_init.c | 7 ++ core/oneway_malloc.c | 2 + cpu/lpc2387/include/cpu-conf.h | 3 + cpu/msp430/include/cpu-conf.h | 3 + drivers/cc110x_ng/Jamfile | 2 +- drivers/cc110x_ng/cc1100-rx.c | 4 +- drivers/cc110x_ng/cc1100-tx.c | 2 +- drivers/cc110x_ng/cc1100_ng.h | 2 - projects/cc110x/main.c | 4 +- projects/msb430_cc110x_ng/Jamfile | 5 + projects/msb430_cc110x_ng/main.c | 119 +++++++++++++++++++ projects/msb430_cc110x_ng/tests/hello-world | 13 ++ projects/test_cc110x_ng/Jamfile | 2 +- sys/auto_init.c | 2 + sys/include/transceiver.h | 8 +- sys/transceiver.c | 4 + 21 files changed, 180 insertions(+), 21 deletions(-) create mode 100644 board/msb-430-common/config.c create mode 100644 projects/msb430_cc110x_ng/Jamfile create mode 100644 projects/msb430_cc110x_ng/main.c create mode 100755 projects/msb430_cc110x_ng/tests/hello-world diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile index 97c2be0f3..6cc5f8f1e 100644 --- a/board/msb-430-common/Jamfile +++ b/board/msb-430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430-common ; -Module board : board_init.c debug_uart.c ; +Module board : board_init.c debug_uart.c config.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 index bfe5a1a6f..af4e671c1 100644 --- a/board/msb-430-common/Jamrules.msb-430-common +++ b/board/msb-430-common/Jamrules.msb-430-common @@ -28,7 +28,7 @@ CPU = msp430 ; MCU = msp430x1612 ; -FLASH_PORT ?= /dev/ttyUSB0 ; +FLASH_PORT ?= "$(PORT)" ; FLASHER ?= mspdebug ; FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; diff --git a/board/msb-430-common/config.c b/board/msb-430-common/config.c new file mode 100644 index 000000000..f8d169e2a --- /dev/null +++ b/board/msb-430-common/config.c @@ -0,0 +1,6 @@ +#include +#include + +uint8_t config_save(void) { + return 1; +} diff --git a/board/msba2/board_init.c b/board/msba2/board_init.c index aea2c5093..de730c33b 100644 --- a/board/msba2/board_init.c +++ b/board/msba2/board_init.c @@ -51,12 +51,6 @@ and the mailinglist (subscription via web site) #define PCRTC BIT9 #define CL_CPU_DIV 4 -config_t sysconfig = { - 0, ///< default ID - 0, ///< default radio address - 0, ///< default radio channel -}; - /*---------------------------------------------------------------------------*/ /** * @brief Enabling MAM and setting number of clocks used for Flash memory fetch diff --git a/core/include/kernel.h b/core/include/kernel.h index 7aeac5ada..54c7d51e6 100644 --- a/core/include/kernel.h +++ b/core/include/kernel.h @@ -22,6 +22,7 @@ */ #include +#include #include "tcb.h" #include "cpu.h" #include "flags.h" @@ -85,5 +86,7 @@ int inISR(void); extern volatile int lpm_prevent_sleep; +extern config_t sysconfig; + /** @} */ #endif /* KERNEL_H_ */ diff --git a/core/kernel_init.c b/core/kernel_init.c index b38d5a966..30be1e68d 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -26,6 +26,7 @@ #include #include #include +#include #ifdef MODULE_AUTO_INIT #include @@ -41,6 +42,12 @@ volatile int lpm_prevent_sleep = 0; extern void main(void); extern void cpu_switch_context_exit(void); +config_t sysconfig = { + 0, ///< default ID + 0, ///< default radio address + 0, ///< default radio channel +}; + static void idle_thread(void) { while(1) { if (lpm_prevent_sleep) { diff --git a/core/oneway_malloc.c b/core/oneway_malloc.c index 10c76c9c3..d10e23b96 100644 --- a/core/oneway_malloc.c +++ b/core/oneway_malloc.c @@ -17,6 +17,8 @@ #include #include +#include +#include #define ENABLE_DEBUG #include diff --git a/cpu/lpc2387/include/cpu-conf.h b/cpu/lpc2387/include/cpu-conf.h index fd9ecb10b..9e6a2dde9 100644 --- a/cpu/lpc2387/include/cpu-conf.h +++ b/cpu/lpc2387/include/cpu-conf.h @@ -84,5 +84,8 @@ and the mailinglist (subscription via web site) #define CC_CONF_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) /** @} */ +#define TRANSCEIVER_BUFFER_SIZE (10) +#define RX_BUF_SIZE (10) + /** @} */ #endif /* CPUCONF_H_ */ diff --git a/cpu/msp430/include/cpu-conf.h b/cpu/msp430/include/cpu-conf.h index 62958016e..9f9e114f1 100644 --- a/cpu/msp430/include/cpu-conf.h +++ b/cpu/msp430/include/cpu-conf.h @@ -37,6 +37,9 @@ and the mailinglist (subscription via web site) #define KERNEL_CONF_STACKSIZE_IDLE 64 #define MSP430_ISR_STACK_SIZE 256 + +#define RX_BUF_SIZE (4) +#define TRANSCEIVER_BUFFER_SIZE (4) /** @} */ #endif /* CPUCONF_H_ */ diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index 55995d823..039d0f4bd 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-rx.c cc1100-tx.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 ; diff --git a/drivers/cc110x_ng/cc1100-rx.c b/drivers/cc110x_ng/cc1100-rx.c index de8f61557..275f4d00f 100644 --- a/drivers/cc110x_ng/cc1100-rx.c +++ b/drivers/cc110x_ng/cc1100-rx.c @@ -8,6 +8,7 @@ #include #include +#include #include static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); @@ -96,7 +97,8 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { /* Any bytes available in RX FIFO? */ if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { - LED_GREEN_TOGGLE; + //LED_GREEN_TOGGLE; + LED_RED_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 diff --git a/drivers/cc110x_ng/cc1100-tx.c b/drivers/cc110x_ng/cc1100-tx.c index 47ce43a6a..ff9867604 100644 --- a/drivers/cc110x_ng/cc1100-tx.c +++ b/drivers/cc110x_ng/cc1100-tx.c @@ -60,7 +60,7 @@ uint8_t cc1100_send(cc1100_packet_t *packet) { restoreIRQ(cpsr); // Wait for GDO2 to be cleared -> end of packet while (cc1100_get_gdo2() != 0); - LED_GREEN_TOGGLE; + //LED_GREEN_TOGGLE; // Experimental - TOF Measurement cc1100_after_send(); diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index 3431f2e7b..b126a42fa 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -6,8 +6,6 @@ #include #include -#define RX_BUF_SIZE (10) - #define CC1100_MAX_DATA_LENGTH (58) #define CC1100_HEADER_LENGTH (3) ///< Header covers SRC, DST and FLAGS diff --git a/projects/cc110x/main.c b/projects/cc110x/main.c index 4847b47cb..c552a7939 100644 --- a/projects/cc110x/main.c +++ b/projects/cc110x/main.c @@ -68,12 +68,12 @@ int main(void) cc1100_set_address(2); - while(1) { +// while(1) { 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); while(1) { diff --git a/projects/msb430_cc110x_ng/Jamfile b/projects/msb430_cc110x_ng/Jamfile new file mode 100644 index 000000000..031c60429 --- /dev/null +++ b/projects/msb430_cc110x_ng/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects msb430_cc110x_ng ; + +Module msb430_cc110x_ng : main.c : cc110x_ng transceiver ps posix_io uart0 auto_init ; + +UseModule msb430_cc110x_ng ; diff --git a/projects/msb430_cc110x_ng/main.c b/projects/msb430_cc110x_ng/main.c new file mode 100644 index 000000000..a25070219 --- /dev/null +++ b/projects/msb430_cc110x_ng/main.c @@ -0,0 +1,119 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RADIO_STACK_SIZE (1024) + +#define SND_BUFFER_SIZE (3) +#define RCV_BUFFER_SIZE (4) + +#define SENDING_DELAY (5 * 1000) + +char radio_stack_buffer[RADIO_STACK_SIZE]; + +uint8_t snd_buffer[SND_BUFFER_SIZE][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); + +void sender(char *count) { + unsigned int c = 3; + unsigned int i; + + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + + p.length = CC1100_MAX_DATA_LENGTH; + p.dst = 0; + + for (i = 0; i < c; i++) { + 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); + if (m.type == PKT_PENDING) { + p = (radio_packet_t*) m.content.ptr; + 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); + printf("\tLQI:\t%u\n", p->lqi); + printf("\tRSSI:\t%u\n", p->rssi); + + 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); + } + radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); + transceiver_init(TRANSCEIVER_CC1100); + transceiver_start(); + transceiver_register(TRANSCEIVER_CC1100, radio_pid); + sender(NULL); + + while (1) { + extern void thread_print_all(void); + thread_print_all(); + print_buffer(NULL); + swtimer_usleep(10000000); + } +} diff --git a/projects/msb430_cc110x_ng/tests/hello-world b/projects/msb430_cc110x_ng/tests/hello-world new file mode 100755 index 000000000..acde8265f --- /dev/null +++ b/projects/msb430_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/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile index 28bf8b6f1..108b3c141 100644 --- a/projects/test_cc110x_ng/Jamfile +++ b/projects/test_cc110x_ng/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects test_cc110x_ng ; -Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init ; +Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init gpioint ; UseModule test_cc110x_ng ; diff --git a/sys/auto_init.c b/sys/auto_init.c index c92b2b017..cbb7db914 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -1,7 +1,9 @@ #include #include #include +#ifdef MODULE_RTC #include +#endif #include #define ENABLE_DEBUG diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index a31876bd7..eddd4314d 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -3,17 +3,15 @@ #include -/* Packets to buffer */ -#define TRANSCEIVER_BUFFER_SIZE (10) /* Stack size for transceiver thread */ -#define TRANSCEIVER_STACK_SIZE (2048) +#define TRANSCEIVER_STACK_SIZE (512) /* The maximum of threads to register */ -#define TRANSCEIVER_MAX_REGISTERED (10) +#define TRANSCEIVER_MAX_REGISTERED (4) /* The size of the message queue between driver and transceiver (must be power * of two */ -#define TRANSCEIVER_MSG_BUFFER_SIZE (64) +#define TRANSCEIVER_MSG_BUFFER_SIZE (32) /** * @brief Message types for transceiver interface diff --git a/sys/transceiver.c b/sys/transceiver.c index d0d5920e5..13de0a6fa 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -20,6 +20,10 @@ #endif //#define ENABLE_DEBUG (1) +#ifdef ENABLE_DEBUG +#undef TRANSCEIVER_BUFFER_SIZE +#define TRANSCEIVER_BUFFER_SIZE (2048) +#endif #include /*------------------------------------------------------------------------------------*/ From 1eec8e170ecbfad43503e800c1549a325513bc0f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 3 Dec 2010 22:22:58 +0100 Subject: [PATCH 122/199] * introduced flashrom driver for msb430 * restructured some files concerning flashrom access * added some ifdefs to shell commands --- board/msb-430-common/Jamrules.msb-430-common | 1 + board/msb-430-common/config.c | 5 +- board/msb-430-common/include/board-conf.h | 6 ++ board/msba2/config.c | 2 +- cpu/arm_common/iap.c | 13 ++-- cpu/arm_common/include/{flashrom.h => iap.h} | 21 +---- cpu/lpc2387/lpc23xx-iap.c | 3 +- cpu/msp430/Jamfile | 2 +- cpu/msp430/flashrom.c | 80 ++++++++++++++++++++ drivers/include/flashrom.h | 27 +++++++ projects/msb430_cc110x_ng/Jamfile | 2 +- projects/msb430_cc110x_ng/main.c | 24 +++++- sys/shell/cc1100.c | 3 + sys/shell/cc1100_ng.c | 15 +++- sys/shell/id.c | 15 ++-- sys/shell/rtc.c | 6 +- sys/shell/shell.c | 4 +- sys/shell/shell_commands.c | 2 +- sys/shell/sht11.c | 4 + 19 files changed, 189 insertions(+), 46 deletions(-) create mode 100644 board/msb-430-common/include/board-conf.h rename cpu/arm_common/include/{flashrom.h => iap.h} (72%) create mode 100644 cpu/msp430/flashrom.c create mode 100644 drivers/include/flashrom.h diff --git a/board/msb-430-common/Jamrules.msb-430-common b/board/msb-430-common/Jamrules.msb-430-common index af4e671c1..9c51cd21d 100644 --- a/board/msb-430-common/Jamrules.msb-430-common +++ b/board/msb-430-common/Jamrules.msb-430-common @@ -34,4 +34,5 @@ FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; +HDRS += [ FPath $(TOP) board msb-430-common include ] ; HDRS += [ FPath $(TOP) board msb-430-common drivers include ] ; diff --git a/board/msb-430-common/config.c b/board/msb-430-common/config.c index f8d169e2a..3e752592c 100644 --- a/board/msb-430-common/config.c +++ b/board/msb-430-common/config.c @@ -1,6 +1,9 @@ #include +#include #include +#include uint8_t config_save(void) { - return 1; + configmem_t mem = { CONFIG_KEY, sysconfig }; + return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem))); } diff --git a/board/msb-430-common/include/board-conf.h b/board/msb-430-common/include/board-conf.h new file mode 100644 index 000000000..e85c3128f --- /dev/null +++ b/board/msb-430-common/include/board-conf.h @@ -0,0 +1,6 @@ +#ifndef BOARD_CONF_H +#define BOARD_CONF_H + +#define INFOMEM (0x1000) + +#endif /* BOARD-CONF_H */ diff --git a/board/msba2/config.c b/board/msba2/config.c index 9d149eb86..0ca717665 100644 --- a/board/msba2/config.c +++ b/board/msba2/config.c @@ -4,5 +4,5 @@ uint8_t config_save(void) { configmem_t mem = { CONFIG_KEY, sysconfig }; - return (flashrom_erase((uint32_t) configmem) && flashrom_write((uint32_t) configmem, (char*) &mem, sizeof(mem))); + return (flashrom_erase((uint8_t*) &configmem) && flashrom_write((uint8_t*) &configmem, (char*) &mem, sizeof(mem))); } diff --git a/cpu/arm_common/iap.c b/cpu/arm_common/iap.c index 5802b2876..0f0b418ab 100644 --- a/cpu/arm_common/iap.c +++ b/cpu/arm_common/iap.c @@ -7,6 +7,7 @@ #include #include +#include #include //#define ENABLE_DEBUG @@ -31,7 +32,7 @@ static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32 /****************************************************************************** * P U B L I C F U N C T I O N S *****************************************************************************/ -uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) { +uint8_t flashrom_write(uint8_t *dst, char *src, size_t size) { char err; unsigned intstate; uint8_t sec; @@ -39,7 +40,7 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) { //buffer_vic = VICIntEnable; // save interrupt enable //VICIntEnClr = 0xFFFFFFFF; // clear vic - sec = flashrom_get_sector(dst); + sec = iap_get_sector((uint32_t) dst); if (sec == INVALID_ADDRESS) { DEBUG("Invalid address\n"); return 0; @@ -61,7 +62,7 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) { /* write flash */ else { intstate = disableIRQ(); - err = copy_ram_to_flash(dst, (uint32_t) src, 256); + err = copy_ram_to_flash((uint32_t) dst, (uint32_t) src, 256); restoreIRQ(intstate); if(err) { DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err); @@ -72,7 +73,7 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) { } /* check result */ else { - err = compare(dst, (uint32_t) src, 256); + err = compare((uint32_t) dst, (uint32_t) src, 256); if (err) { DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]); /* set interrupts back and return */ @@ -91,8 +92,8 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) { } -uint8_t flashrom_erase(uint32_t addr) { - uint8_t sec = flashrom_get_sector(addr); +uint8_t flashrom_erase(uint8_t *addr) { + uint8_t sec = iap_get_sector((uint32_t) addr); unsigned intstate; if (sec == INVALID_ADDRESS) { diff --git a/cpu/arm_common/include/flashrom.h b/cpu/arm_common/include/iap.h similarity index 72% rename from cpu/arm_common/include/flashrom.h rename to cpu/arm_common/include/iap.h index bc9dc92ce..d2672f594 100644 --- a/cpu/arm_common/include/flashrom.h +++ b/cpu/arm_common/include/iap.h @@ -37,25 +37,6 @@ #define PLLCON_PLLC (0x03) ///< PLL Connect #define PLLSTAT_PLOCK (0x0400) // #include +#include -uint8_t flashrom_get_sector(uint32_t addr) { +uint8_t iap_get_sector(uint32_t addr) { if ((addr >=0x00000000) && (addr <= 0x00000FFF)) { return 0; } diff --git a/cpu/msp430/Jamfile b/cpu/msp430/Jamfile index 9441b494e..bec5471cd 100644 --- a/cpu/msp430/Jamfile +++ b/cpu/msp430/Jamfile @@ -27,7 +27,7 @@ SubDir TOP cpu msp430 ; -Module cpu : msp430-main.c cpu.c atomic.c irq.c ; +Module cpu : msp430-main.c cpu.c atomic.c irq.c flashrom.c ; Module hwtimer_cpu : hwtimer_cpu.c ; UseModule cpu ; diff --git a/cpu/msp430/flashrom.c b/cpu/msp430/flashrom.c new file mode 100644 index 000000000..1c96e14b0 --- /dev/null +++ b/cpu/msp430/flashrom.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include + +uint8_t ie1, ie2; + +static uint8_t prepare(void); +static void finish(uint8_t istate); +static inline void busy_wait(void); + +/*---------------------------------------------------------------------------*/ +uint8_t flashrom_erase(uint8_t *addr) { + uint8_t istate = prepare(); + + FCTL3 = FWKEY; /* Lock = 0 */ + busy_wait(); + FCTL1 = FWKEY | ERASE; + *addr = 0; /* erase Flash segment */ + busy_wait(); + FCTL1 = FWKEY; /* ERASE = 0 */ + FCTL3 = FWKEY | LOCK; + finish(istate); + return 1; +} + +void flashrom_write(uint8_t *dst, uint8_t *src, size_t size) { + unsigned int i; + FCTL3 = FWKEY; /* Lock = 0 */ + busy_wait(); + for (i = size; i > 0; i--) { + FCTL1 = FWKEY | WRT; + *dst = *src; /* program Flash word */ + while (!(FCTL3 & WAIT)) { + nop(); + } + } + busy_wait(); + FCTL1 = FWKEY; /* WRT = 0 */ + FCTL3 = FWKEY | LOCK; /* Lock = 1 */ +} + +/*---------------------------------------------------------------------------*/ +static uint8_t prepare(void) { + uint8_t istate; + + /* Disable all interrupts. */ + + /* Clear interrupt flag1. */ + IFG1 = 0; + + /* DCO(SMCLK) is 2,4576MHz, /6 = 409600 Hz + select SMCLK for flash timing, divider 4+1 */ + FCTL2 = FWKEY | FSSEL_3 | FN2 | FN0; + + /* disable all interrupts to protect CPU + during programming from system crash */ + istate = disableIRQ(); + + /* disable all NMI-Interrupt sources */ + ie1 = IE1; + ie2 = IE2; + IE1 = 0x00; + IE2 = 0x00; + return istate; +} +/*---------------------------------------------------------------------------*/ +void finish(uint8_t istate) { + /* Enable interrupts. */ + IE1 = ie1; + IE2 = ie2; + restoreIRQ(istate); +} + +static inline void busy_wait(void) { + /* Wait for BUSY = 0, not needed unless run from RAM */ + while(FCTL3 & 0x0001) { + nop(); + } +} diff --git a/drivers/include/flashrom.h b/drivers/include/flashrom.h new file mode 100644 index 000000000..c4fafc9e7 --- /dev/null +++ b/drivers/include/flashrom.h @@ -0,0 +1,27 @@ +#ifndef FLASHROM_H +#define FLASHROM_H + +#include +#include + +/* + * @brief Erase sector + * + * @param addr Address within a flash sector to erase + * + * @return 1 on success, 0 otherwise + */ +uint8_t flashrom_erase(uint8_t *addr); + +/* @brief Write buffer from ram to flash + * + * @param dst Address within a flash sector to write, must be a 256 byte boundary + * @param src Address within ram, must be a word boundary + * @param size Bytes to write + * + * @return 1 on success, 0 otherwise + */ +uint8_t flashrom_write(uint8_t *dst, char *src, size_t size); + + +#endif /* FLASHROM_H */ diff --git a/projects/msb430_cc110x_ng/Jamfile b/projects/msb430_cc110x_ng/Jamfile index 031c60429..c28cac9ad 100644 --- a/projects/msb430_cc110x_ng/Jamfile +++ b/projects/msb430_cc110x_ng/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects msb430_cc110x_ng ; -Module msb430_cc110x_ng : main.c : cc110x_ng transceiver ps posix_io uart0 auto_init ; +Module msb430_cc110x_ng : main.c : cc110x_ng transceiver shell shell_commands ps posix_io uart0 auto_init ; UseModule msb430_cc110x_ng ; diff --git a/projects/msb430_cc110x_ng/main.c b/projects/msb430_cc110x_ng/main.c index a25070219..83b02d2a7 100644 --- a/projects/msb430_cc110x_ng/main.c +++ b/projects/msb430_cc110x_ng/main.c @@ -12,13 +12,15 @@ #include #include -#define RADIO_STACK_SIZE (1024) +#define SHELL_STACK_SIZE (512) +#define RADIO_STACK_SIZE (512) #define SND_BUFFER_SIZE (3) #define RCV_BUFFER_SIZE (4) #define SENDING_DELAY (5 * 1000) +char shell_stack_buffer[SHELL_STACK_SIZE]; char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SND_BUFFER_SIZE][CC1100_MAX_DATA_LENGTH]; @@ -32,6 +34,20 @@ 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) { + shell_init(&shell, sc, uart0_readc, uart0_putc); + posix_open(uart0_handler_pid, 0); + shell_run(&shell); +} + + void sender(char *count) { unsigned int c = 3; unsigned int i; @@ -104,11 +120,17 @@ int main(void) { 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-2, 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_start(); transceiver_register(TRANSCEIVER_CC1100, radio_pid); sender(NULL); + + printf("Config:\n"); + printf("\tid: %u\n", sysconfig.id); + printf("\taddr: %u\n", sysconfig.radio_address); + printf("\tchannel: %u\n", sysconfig.radio_channel); while (1) { extern void thread_print_all(void); diff --git a/sys/shell/cc1100.c b/sys/shell/cc1100.c index 4236f517d..47901d734 100644 --- a/sys/shell/cc1100.c +++ b/sys/shell/cc1100.c @@ -1,6 +1,8 @@ #include #include +#ifdef MODULE_CC110X + void _cc1100_get_address_handler(char *str) { radio_address_t addr = cc1100_get_address(); printf("cc1100 address: %i\n", addr); @@ -22,3 +24,4 @@ void _cc1100_set_address_handler(char *str) { } } +#endif diff --git a/sys/shell/cc1100_ng.c b/sys/shell/cc1100_ng.c index 3fe0d1f49..fe962d249 100644 --- a/sys/shell/cc1100_ng.c +++ b/sys/shell/cc1100_ng.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -16,7 +17,8 @@ void _cc1100_ng_get_set_address_handler(char *addr) { tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &a; mesg.content.ptr = (char*) &tcmd; - if (sscanf(addr, "addr %hi", &a) > 0) { + a = atoi(addr+5); + if (strlen(addr) > 5) { printf("[cc1100] Trying to set address %i\n", a); mesg.type = SET_ADDRESS; } @@ -33,7 +35,8 @@ void _cc1100_ng_get_set_channel_handler(char *chan) { tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &c; mesg.content.ptr = (char*) &tcmd; - if (sscanf(chan, "chan %hi", &c) > 0) { + c = atoi(chan+5); + if (strlen(chan) > 5) { printf("[cc1100] Trying to set channel %i\n", c); mesg.type = SET_CHANNEL; } @@ -51,7 +54,10 @@ void _cc1100_ng_send_handler(char *pkt) { tcmd.data = &p; uint16_t addr; - if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) { + addr = atoi(pkt+7); + memcpy(text_msg, "Text", 5); + /* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/ + if (1 == 1) { p.data = (uint8_t*) text_msg; p.length = strlen(text_msg); p.dst = addr; @@ -73,7 +79,8 @@ void _cc1100_ng_monitor_handler(char *mode) { tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &m; mesg.content.ptr = (char*) &tcmd; - if (sscanf(mode, "monitor %u", &m) == 1) { + m = atoi(mode+8); + if (strlen(mode) > 8) { printf("Setting monitor mode: %u\n", m); mesg.type = SET_MONITOR; msg_send(&mesg, transceiver_pid, 1); diff --git a/sys/shell/id.c b/sys/shell/id.c index 6714efbbb..af8516d6b 100644 --- a/sys/shell/id.c +++ b/sys/shell/id.c @@ -1,17 +1,20 @@ #include +#include #include +#include void _id_handler(char *id) { - uint16_t newid; + long newid; - if (sscanf(id, "id %hu", &newid) == 1) { - printf("Setting new id %u\n", newid); + newid = atoi(id+3); + if (strlen(id) < 3) { + printf("Current id: %u\n", sysconfig.id); + } + else { + printf("Setting new id %lu\n", newid); sysconfig.id = newid; if (!config_save()) { puts("ERROR setting new id"); } } - else { - printf("Current id: %u\n", sysconfig.id); - } } diff --git a/sys/shell/rtc.c b/sys/shell/rtc.c index 25f99c089..476175e20 100644 --- a/sys/shell/rtc.c +++ b/sys/shell/rtc.c @@ -1,8 +1,10 @@ #include #include +#include + +#ifdef MODULE_RTC #include #include -#include void _gettime_handler(void) { struct tm now; @@ -46,3 +48,5 @@ void _date_handler(char* c) { _settime_handler(c); } } + +#endif diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 37ad42892..efebc5d02 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -41,13 +41,13 @@ and the mailinglist (subscription via web site) * @author Kaspar Schleiser */ -#include +//#include #include #include -#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; diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index 68a509c53..af2ea5cbe 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -1,4 +1,4 @@ -#include +#include #include extern void _id_handler(char* id); diff --git a/sys/shell/sht11.c b/sys/shell/sht11.c index e00844453..b3f21ddb3 100644 --- a/sys/shell/sht11.c +++ b/sys/shell/sht11.c @@ -3,6 +3,8 @@ #include #include +#ifdef MODULE_SHT11 + extern float sht11_temperature_offset; void _get_humidity_handler(char* unused) { @@ -51,3 +53,5 @@ void _set_offset_handler(char* offset) { printf("Temperature offset set to %f\n", sht11_temperature_offset); } } + +#endif From e1b3dcf40dc824f3bbcbe5ddde850fbcba3d97d1 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 6 Dec 2010 11:22:15 +0100 Subject: [PATCH 123/199] [drivers/cc110x_ng] * added register interface (it is now possible to communicate with cc1100 via SPI (e.g. on MSB boards) or directly via registers like on eZ430-Chronos --- drivers/cc110x_ng/Jamfile | 5 +- drivers/cc110x_ng/cc1100-config.h | 83 ++++++++++++++++--------------- drivers/cc110x_ng/cc1100-rx.c | 33 ++++++------ drivers/cc110x_ng/cc1100-tx.c | 9 ++-- drivers/cc110x_ng/cc1100.c | 29 +++++++---- drivers/cc110x_ng/cc1100_spi.c | 13 ++--- drivers/cc110x_ng/cc1100_spi.h | 7 --- projects/test_cc110x_ng/Jamfile | 2 +- 8 files changed, 93 insertions(+), 88 deletions(-) diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index 039d0f4bd..f237e6e11 100755 --- a/drivers/cc110x_ng/Jamfile +++ b/drivers/cc110x_ng/Jamfile @@ -29,5 +29,6 @@ SubDir TOP drivers cc110x_ng ; HDRS += $(TOP)/drivers/cc110x_ng ; -Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c cc1100_spi.c : board_cc1100 swtimer ; - +Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : swtimer ; +Module cc110x_spi : cc1100_spi.c : board_cc1100 ; +Module cc110x_reg : cc1100-reg.c ; diff --git a/drivers/cc110x_ng/cc1100-config.h b/drivers/cc110x_ng/cc1100-config.h index 2069375a1..11e940cd8 100644 --- a/drivers/cc110x_ng/cc1100-config.h +++ b/drivers/cc110x_ng/cc1100-config.h @@ -2,48 +2,49 @@ #define CC1100_CONFIG_H #include +#include /** 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; + 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 */ @@ -62,9 +63,9 @@ typedef struct 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 : 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 _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) diff --git a/drivers/cc110x_ng/cc1100-rx.c b/drivers/cc110x_ng/cc1100-rx.c index 275f4d00f..9377f736f 100644 --- a/drivers/cc110x_ng/cc1100-rx.c +++ b/drivers/cc110x_ng/cc1100-rx.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -35,15 +36,15 @@ void cc1100_rx_handler(void) { 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; + 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); + cc1100_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME (until end of packet) + cc1100_strobe(CC1100_SRX); hwtimer_wait(IDLE_TO_RX_TIME); radio_state = RADIO_RX; @@ -67,14 +68,14 @@ void cc1100_rx_handler(void) { 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 + cc1100_strobe(CC1100_SIDLE); // Switch to IDLE (should already be)... + cc1100_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); + cc1100_strobe(CC1100_SRX); hwtimer_wait(IDLE_TO_RX_TIME); return; } @@ -96,11 +97,11 @@ 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_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { //LED_GREEN_TOGGLE; - LED_RED_TOGGLE; + //LED_RED_TOGGLE; // Read length byte (first byte in RX FIFO) - packetLength = cc1100_spi_read_reg(CC1100_RXFIFO); + packetLength = cc1100_read_reg(CC1100_RXFIFO); // Read data from RX FIFO and store in rxBuffer if (packetLength <= length) { @@ -108,13 +109,13 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { rxBuffer[0] = packetLength; // Read the rest of the packet - cc1100_spi_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); + cc1100_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); + cc1100_readburst_reg(CC1100_RXFIFO, (char*)status, 2); // Store RSSI value of packet - rflags.RSSI = status[I_RSSI]; + rflags._RSSI = status[I_RSSI]; // MSB of LQI is the CRC_OK bit rflags.CRC = (status[I_LQI] & CRC_OK) >> 7; @@ -123,7 +124,7 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { } // Bit 0-6 of LQI indicates the link quality (LQI) - rflags.LQI = status[I_LQI] & LQI_EST; + rflags._LQI = status[I_LQI] & LQI_EST; return rflags.CRC; } @@ -135,14 +136,14 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { } /* no bytes in RX FIFO */ else { - LED_RED_TOGGLE; + //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; + uint8_t pkt_len_cfg = cc1100_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; if (pkt_len_cfg == VARIABLE_PKTLEN) { return receive_packet_variable(rxBuffer, length); diff --git a/drivers/cc110x_ng/cc1100-tx.c b/drivers/cc110x_ng/cc1100-tx.c index ff9867604..d85233ecc 100644 --- a/drivers/cc110x_ng/cc1100-tx.c +++ b/drivers/cc110x_ng/cc1100-tx.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -38,15 +39,15 @@ uint8_t cc1100_send(cc1100_packet_t *packet) { cc1100_before_send(); // But CC1100 in IDLE mode to flush the FIFO - cc1100_spi_strobe(CC1100_SIDLE); + cc1100_strobe(CC1100_SIDLE); // Flush TX FIFO to be sure it is empty - cc1100_spi_strobe(CC1100_SFTX); + cc1100_strobe(CC1100_SFTX); // Write packet into TX FIFO - cc1100_spi_writeburst_reg(CC1100_TXFIFO, (char*) packet, size); + cc1100_writeburst_reg(CC1100_TXFIFO, (char*) packet, size); // Switch to TX mode abort_count = 0; unsigned int cpsr = disableIRQ(); - cc1100_spi_strobe(CC1100_STX); + cc1100_strobe(CC1100_STX); // Wait for GDO2 to be set -> sync word transmitted while (cc1100_get_gdo2() == 0) { abort_count++; diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index 8fc5d176a..dab1600bf 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -39,20 +40,22 @@ void cc1100_init(int tpid) { rx_buffer_next = 0; +#ifdef MODULE_CC110X_SPI /* Initialize SPI */ cc1100_spi_init(); +#endif /* Load driver & reset */ power_up_reset(); /* Write configuration to configuration registers */ - cc1100_spi_writeburst_reg(0x00, cc1100_conf, CC1100_CONF_SIZE); + cc1100_writeburst_reg(0x00, cc1100_conf, CC1100_CONF_SIZE); /* Write PATABLE (power settings) */ - cc1100_spi_write_reg(CC1100_PATABLE, pa_table[pa_table_index]); + cc1100_write_reg(CC1100_PATABLE, pa_table[pa_table_index]); /* Initialize Radio Flags */ - rflags.RSSI = 0x00; + rflags._RSSI = 0x00; rflags.LL_ACK = 0; rflags.CAA = 0; rflags.CRC = 0; @@ -120,13 +123,13 @@ void cc1100_set_monitor(uint8_t mode) { void cc1100_setup_rx_mode(void) { // Stay in RX mode until end of packet - cc1100_spi_write_reg(CC1100_MCSM2, 0x07); + cc1100_write_reg(CC1100_MCSM2, 0x07); cc1100_switch_to_rx(); } void cc1100_switch_to_rx(void) { radio_state = RADIO_RX; - cc1100_spi_strobe(CC1100_SRX); + cc1100_strobe(CC1100_SRX); } void cc1100_wakeup_from_rx(void) { @@ -134,7 +137,7 @@ void cc1100_wakeup_from_rx(void) { return; } DEBUG("CC1100 going to idle\n"); - cc1100_spi_strobe(CC1100_SIDLE); + cc1100_strobe(CC1100_SIDLE); radio_state = RADIO_IDLE; } @@ -145,7 +148,7 @@ char* cc1100_get_marc_state(void) { uint8_t old_state = radio_state; // Read content of status register - state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE; + state = cc1100_read_status(CC1100_MARCSTATE) & MARC_STATE; // Make sure in IDLE state. // Only goes to IDLE if state was RX/WOR @@ -211,13 +214,13 @@ void cc1100_print_config(void) { void cc1100_switch_to_pwd(void) { DEBUG("[cc110x_ng] switching to powerdown\n"); cc1100_wakeup_from_rx(); - cc1100_spi_strobe(CC1100_SPWD); + cc1100_strobe(CC1100_SPWD); radio_state = RADIO_PWD; } /*---------------------------------------------------------------------------*/ int16_t cc1100_set_channel(uint8_t channr) { - uint8_t state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE; + uint8_t state = cc1100_read_status(CC1100_MARCSTATE) & MARC_STATE; if ((state != 1) && (channr > MAX_CHANNR)) { return 0; } @@ -238,15 +241,19 @@ int16_t cc1100_get_channel(void) { static void reset(void) { cc1100_wakeup_from_rx(); +#ifdef MODULE_CC110x_SPI cc1100_spi_select(); - cc1100_spi_strobe(CC1100_SRES); +#endif + cc1100_strobe(CC1100_SRES); hwtimer_wait(RTIMER_TICKS(10)); } static void power_up_reset(void) { +#ifdef MODULE_CC110x_SPI cc1100_spi_unselect(); cc1100_spi_cs(); cc1100_spi_unselect(); +#endif hwtimer_wait(RESET_WAIT_TIME); reset(); radio_state = RADIO_IDLE; @@ -258,7 +265,7 @@ static void write_register(uint8_t r, uint8_t value) { /* Wake up from WOR/RX (if in WOR/RX, else no effect) */ cc1100_wakeup_from_rx(); - cc1100_spi_write_reg(r, value); + cc1100_write_reg(r, value); // Have to put radio back to WOR/RX if old radio state // was WOR/RX, otherwise no action is necessary diff --git a/drivers/cc110x_ng/cc1100_spi.c b/drivers/cc110x_ng/cc1100_spi.c index 0eaa70d57..8e4f0aeb2 100644 --- a/drivers/cc110x_ng/cc1100_spi.c +++ b/drivers/cc110x_ng/cc1100_spi.c @@ -48,6 +48,7 @@ and the mailinglist (subscription via web site) #include #include #include +#include #include @@ -57,7 +58,7 @@ and the mailinglist (subscription via web site) #define NOBYTE 0xFF -uint8_t cc1100_spi_writeburst_reg(uint8_t addr, char *src, uint8_t count) { +uint8_t cc1100_writeburst_reg(uint8_t addr, char *src, uint8_t count) { int i = 0; unsigned int cpsr = disableIRQ(); cc1100_spi_select(); @@ -71,7 +72,7 @@ uint8_t cc1100_spi_writeburst_reg(uint8_t addr, char *src, uint8_t count) { return count; } -void cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { +void cc1100_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { int i = 0; unsigned int cpsr = disableIRQ(); cc1100_spi_select(); @@ -84,7 +85,7 @@ void cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { restoreIRQ(cpsr); } -void cc1100_spi_write_reg(uint8_t addr, uint8_t value) { +void cc1100_write_reg(uint8_t addr, uint8_t value) { unsigned int cpsr = disableIRQ(); cc1100_spi_select(); cc1100_txrx(addr); @@ -93,7 +94,7 @@ void cc1100_spi_write_reg(uint8_t addr, uint8_t value) { restoreIRQ(cpsr); } -uint8_t cc1100_spi_read_reg(uint8_t addr) { +uint8_t cc1100_read_reg(uint8_t addr) { uint8_t result; unsigned int cpsr = disableIRQ(); cc1100_spi_select(); @@ -104,7 +105,7 @@ uint8_t cc1100_spi_read_reg(uint8_t addr) { return result; } -uint8_t cc1100_spi_read_status(uint8_t addr) { +uint8_t cc1100_read_status(uint8_t addr) { uint8_t result; unsigned int cpsr = disableIRQ(); cc1100_spi_select(); @@ -115,7 +116,7 @@ uint8_t cc1100_spi_read_status(uint8_t addr) { return result; } -uint8_t cc1100_spi_strobe(uint8_t c) { +uint8_t cc1100_strobe(uint8_t c) { uint8_t result; unsigned int cpsr = disableIRQ(); cc1100_spi_select(); diff --git a/drivers/cc110x_ng/cc1100_spi.h b/drivers/cc110x_ng/cc1100_spi.h index 736f98218..fcb5680d8 100644 --- a/drivers/cc110x_ng/cc1100_spi.h +++ b/drivers/cc110x_ng/cc1100_spi.h @@ -53,12 +53,5 @@ 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_ */ diff --git a/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile index 108b3c141..c2a32ee97 100644 --- a/projects/test_cc110x_ng/Jamfile +++ b/projects/test_cc110x_ng/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects test_cc110x_ng ; -Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init gpioint ; +Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init gpioint cc110x_spi ; UseModule test_cc110x_ng ; From 2a1a10bd749e1afe87ba323e1cec9e2747fabea2 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 6 Dec 2010 12:05:03 +0100 Subject: [PATCH 124/199] [board/eZ430-Chronos board/msba2 drivers/cc110x_ng] * restructured interface functions for cc1100 access --- board/eZ430-Chronos/drivers/Jamfile | 5 +- board/eZ430-Chronos/drivers/cc430-cc1100.c | 66 +++++++++ board/msba2/drivers/Jamfile | 2 +- drivers/cc110x_ng/Jamfile | 6 +- drivers/cc110x_ng/cc1100-reg.h | 12 ++ drivers/cc110x_ng/cc1100_cc430.c | 159 +++++++++++++++++++++ drivers/cc110x_ng/cc1100_ng.h | 14 ++ projects/default/Jamfile | 2 +- projects/test_cc110x_ng/Jamfile | 2 +- 9 files changed, 259 insertions(+), 9 deletions(-) create mode 100644 board/eZ430-Chronos/drivers/cc430-cc1100.c create mode 100644 drivers/cc110x_ng/cc1100-reg.h create mode 100644 drivers/cc110x_ng/cc1100_cc430.c diff --git a/board/eZ430-Chronos/drivers/Jamfile b/board/eZ430-Chronos/drivers/Jamfile index b2fb968fa..2ccbb030e 100644 --- a/board/eZ430-Chronos/drivers/Jamfile +++ b/board/eZ430-Chronos/drivers/Jamfile @@ -1,5 +1,4 @@ SubDir TOP board eZ430-Chronos drivers ; -UseModule board_common ; - -Module board_common : display.c display1.c ; +Module board_display : display.c display1.c ; +Module board_cc1100 : cc430-cc1100.c : cc110x_cc430 ; diff --git a/board/eZ430-Chronos/drivers/cc430-cc1100.c b/board/eZ430-Chronos/drivers/cc430-cc1100.c new file mode 100644 index 000000000..9ca689036 --- /dev/null +++ b/board/eZ430-Chronos/drivers/cc430-cc1100.c @@ -0,0 +1,66 @@ +#include + +#include +#include +#include + +#warning CC430_CC1100 NOT WORKING +/* TODO: defines... */ +#define CC1100_GDO0 (0) +#define CC1100_GDO1 (1) +#define CC1100_GDO2 (2) + +int cc1100_get_gdo0(void) { + return CC1100_GDO0; +} + +int cc1100_get_gdo1(void) { + return CC1100_GDO1; +} + +int cc1100_get_gdo2(void) { + return CC1100_GDO2; +} + +void cc1100_before_send(void) +{ + // Disable GDO2 interrupt before sending packet + cc1100_gdo2_disable(); +} + +void cc1100_after_send(void) +{ + // Enable GDO2 interrupt after sending packet + cc1100_gdo2_enable(); +} + +void cc1100_gdo0_enable(void) { +} + +void cc1100_gdo0_disable(void) { +} + +void cc1100_gdo2_disable(void) { +} + +void cc1100_gdo2_enable(void) { +} + +void cc1100_init_interrupts(void) { + uint8_t state = disableIRQ(); /* Disable all interrupts */ + restoreIRQ(state); /* Enable all interrupts */ +} + +interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ + __enter_isr(); + /* Check IFG */ + if (1 == 1) { + cc1100_gdo2_irq(); + } + else if (2 == 2) { + cc1100_gdo0_irq(); + } else { + puts("cc1100_isr(): unexpected IFG!"); + } + __exit_isr(); +} diff --git a/board/msba2/drivers/Jamfile b/board/msba2/drivers/Jamfile index 0b750d947..50f2ddbf0 100644 --- a/board/msba2/drivers/Jamfile +++ b/board/msba2/drivers/Jamfile @@ -1,6 +1,6 @@ SubDir TOP board msba2 drivers ; -Module board_cc1100 : msba2-cc1100.c ; +Module board_cc1100 : msba2-cc1100.c : gpioint cc110x_spi ; Module board_hal : msba2-hal.c ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; Module board_common : msba2-uart0.c : ringbuffer ; diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index f237e6e11..f3c0bc934 100755 --- a/drivers/cc110x_ng/Jamfile +++ b/drivers/cc110x_ng/Jamfile @@ -29,6 +29,6 @@ SubDir TOP drivers cc110x_ng ; HDRS += $(TOP)/drivers/cc110x_ng ; -Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : swtimer ; -Module cc110x_spi : cc1100_spi.c : board_cc1100 ; -Module cc110x_reg : cc1100-reg.c ; +Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : hwtimer board_cc1100 ; +Module cc110x_spi : cc1100_spi.c ; +Module cc110x_cc430 : cc1100_cc430.c ; diff --git a/drivers/cc110x_ng/cc1100-reg.h b/drivers/cc110x_ng/cc1100-reg.h new file mode 100644 index 000000000..f4b97f7f7 --- /dev/null +++ b/drivers/cc110x_ng/cc1100-reg.h @@ -0,0 +1,12 @@ +#ifndef CC110X_REG_H +#define CC110X_REG_H +#include + +uint8_t cc1100_writeburst_reg(uint8_t addr, char *buffer, uint8_t count); +void cc1100_readburst_reg(uint8_t addr, char *buffer, uint8_t count); +void cc1100_write_reg(uint8_t addr, uint8_t value); +uint8_t cc1100_read_reg(uint8_t addr); +uint8_t cc1100_read_status(uint8_t addr); +uint8_t cc1100_strobe(uint8_t c); + +#endif diff --git a/drivers/cc110x_ng/cc1100_cc430.c b/drivers/cc110x_ng/cc1100_cc430.c new file mode 100644 index 000000000..ed991a049 --- /dev/null +++ b/drivers/cc110x_ng/cc1100_cc430.c @@ -0,0 +1,159 @@ +#include +#include +#include +#include +#include +#include + +// ************************************************************************************************* +// @fn Strobe +// @brief Send command to radio. +// @param none +// @return none +// ************************************************************************************************* +uint8_t cc1100_strobe(uint8_t c) { + uint8_t statusByte = 0; + uint16_t int_state, gdo_state; + + // Check for valid strobe command + if((c == 0xBD) || ((c > RF_SRES) && (c < RF_SNOP))) { + int_state = disableIRQ(); + + // Clear the Status read flag + RF1AIFCTL1 &= ~(RFSTATIFG); + + // Wait for radio to be ready for next instruction + while( !(RF1AIFCTL1 & RFINSTRIFG)); + + // Write the strobe instruction + if ((c > RF_SRES) && (c < RF_SNOP)) + { + + gdo_state = cc1100_read_reg(IOCFG2); // buffer IOCFG2 state + cc1100_write_reg(IOCFG2, 0x29); // c-ready to GDO2 + + RF1AINSTRB = c; + if ((RF1AIN & 0x04) == 0x04 ) // chip at sleep mode + { + if ((c == RF_SXOFF) || (c == RF_SPWD) || (c == RF_SWOR) ) { } + else + { + while ((RF1AIN&0x04)== 0x04); // c-ready ? + hwtimer_wait(RTIMER_TICKS(9800)); // Delay for ~810usec at 12MHz CPU clock + } + } + cc1100_write_reg(IOCFG2, gdo_state); // restore IOCFG2 setting + } + else // chip active mode + { + RF1AINSTRB = c; + } + statusByte = RF1ASTATB; + while( !(RF1AIFCTL1 & RFSTATIFG) ); + restoreIRQ(int_state); + } + return statusByte; +} + + +// ************************************************************************************************* +// @fn cc1100_read_reg +// @brief Read byte from register. +// @param none +// @return none +// ************************************************************************************************* +uint8_t cc1100_read_reg(uint8_t addr) { + unsigned char x; + uint16_t int_state; + + int_state = disableIRQ(); + + RF1AINSTR1B = (addr | RF_REGRD); + x = RF1ADOUT1B; + + restoreIRQ(int_state); + return x; +} + + +// ************************************************************************************************* +// @fn cc1100_write_reg +// @brief Write byte to register. +// @param none +// @return none +// ************************************************************************************************* +void cc1100_write_reg(uint8_t addr, uint8_t value) { + volatile unsigned int i; + uint16_t int_state; + + int_state = disableIRQ(); + + while (!(RF1AIFCTL1 & RFINSTRIFG)); // Wait for the Radio to be ready for the next instruction + + RF1AINSTRW = ((addr | RF_REGWR)<<8 ) + value; // Send address + Instruction + while (!(RFDINIFG & RF1AIFCTL1)); + + i = RF1ADOUTB; // Reset RFDOUTIFG flag which contains status byte + + restoreIRQ(int_state); +} + +uint8_t cc1100_read_status(uint8_t addr) { + char status; + cc1100_readburst_reg(addr, &status, 1); + return status; +} + +// ************************************************************************************************* +// @fn cc1100_readburst_reg +// @brief Read sequence of bytes from register. +// @param none +// @return none +// ************************************************************************************************* +void cc1100_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { + unsigned int i; + uint16_t int_state; + + int_state = disableIRQ(); + + while (!(RF1AIFCTL1 & RFINSTRIFG)); // Wait for the Radio to be ready for next instruction + RF1AINSTR1B = (addr | RF_REGRD); // Send address + Instruction + + for (i = 0; i < (count-1); i++) + { + while (!(RFDOUTIFG&RF1AIFCTL1)); // Wait for the Radio Core to update the RF1ADOUTB reg + buffer[i] = RF1ADOUT1B; // Read DOUT from Radio Core + clears RFDOUTIFG + // Also initiates auo-read for next DOUT byte + } + buffer[count-1] = RF1ADOUT0B; // Store the last DOUT from Radio Core + + restoreIRQ(int_state); +} + + +// ************************************************************************************************* +// @fn cc1100_writeburst_reg +// @brief Write sequence of bytes to register. +// @param none +// @return none +// ************************************************************************************************* +uint8_t cc1100_writeburst_reg(uint8_t addr, char *buffer, uint8_t count) { + // Write Burst works wordwise not bytewise - bug known already + unsigned char i; + uint16_t int_state; + + int_state = disableIRQ(); + + while (!(RF1AIFCTL1 & RFINSTRIFG)); // Wait for the Radio to be ready for next instruction + RF1AINSTRW = ((addr | RF_REGWR)<<8 ) + buffer[0]; // Send address + Instruction + + for (i = 1; i < count; i++) + { + RF1ADINB = buffer[i]; // Send data + while (!(RFDINIFG & RF1AIFCTL1)); // Wait for TX to finish + } + i = RF1ADOUTB; // Reset RFDOUTIFG flag which contains status byte + + restoreIRQ(int_state); + return count; +} diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index b126a42fa..7e901d0d6 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -117,4 +117,18 @@ radio_address_t cc1100_get_address(void); void cc1100_set_monitor(uint8_t mode); void cc1100_print_config(void); + +/** + * @brief GDO0 interrupt handler. + */ +void cc1100_gdo0_irq(void); + +/** + * @brief GDO2 interrupt handler. + * + * @note Wakes up MCU on packet reception. + */ +void cc1100_gdo2_irq(void); + + #endif diff --git a/projects/default/Jamfile b/projects/default/Jamfile index 2c8d376ed..1acfc711c 100644 --- a/projects/default/Jamfile +++ b/projects/default/Jamfile @@ -6,6 +6,6 @@ SubDir TOP projects default ; -Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 cc110x auto_init ; +Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 cc110x_ng transceiver gpioint auto_init ; UseModule default_project ; diff --git a/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile index c2a32ee97..685a316d8 100644 --- a/projects/test_cc110x_ng/Jamfile +++ b/projects/test_cc110x_ng/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects test_cc110x_ng ; -Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init gpioint cc110x_spi ; +Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer ; UseModule test_cc110x_ng ; From e7372b21a9c69024627aa1385a8560f51373b604 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 6 Dec 2010 13:19:31 +0100 Subject: [PATCH 125/199] [board config] * made config optional --- board/msb-430-common/Jamfile | 3 ++- board/msba2/Jamfile | 3 ++- board/msba2/board_init.c | 13 ------------- board/msba2/config.c | 10 ++++++++++ cpu/arm_common/bootloader.c | 3 --- drivers/cc110x_ng/cc1100.c | 16 +++++++++++++--- drivers/cc110x_ng/cc1100_ng.h | 2 ++ sys/shell/id.c | 2 ++ 8 files changed, 31 insertions(+), 21 deletions(-) diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile index 6cc5f8f1e..29cd73df0 100644 --- a/board/msb-430-common/Jamfile +++ b/board/msb-430-common/Jamfile @@ -27,7 +27,8 @@ SubDir TOP board msb-430-common ; -Module board : board_init.c debug_uart.c config.c ; +Module board : board_init.c debug_uart.c ; +Module config : config.c ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/board/msba2/Jamfile b/board/msba2/Jamfile index 4bef1bd29..468b45306 100644 --- a/board/msba2/Jamfile +++ b/board/msba2/Jamfile @@ -27,7 +27,8 @@ SubDir TOP board msba2 ; -Module board : board_init.c config.c ; +Module board : board_init.c ; +Module config : config.c ; UseModule board ; UseModule board_common ; diff --git a/board/msba2/board_init.c b/board/msba2/board_init.c index de730c33b..469c8fe7c 100644 --- a/board/msba2/board_init.c +++ b/board/msba2/board_init.c @@ -44,9 +44,6 @@ and the mailinglist (subscription via web site) #include #include #include -#include -#include -#include #define PCRTC BIT9 #define CL_CPU_DIV 4 @@ -156,13 +153,3 @@ void bl_blink(void) { LED_RED_OFF; LED_GREEN_OFF; } - -void bl_config_init(void) { - extern char configmem[]; - if (*((uint16_t*) configmem) == CONFIG_KEY) { - memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); - } - else { - config_save(); - } -} diff --git a/board/msba2/config.c b/board/msba2/config.c index 0ca717665..1910f0b7f 100644 --- a/board/msba2/config.c +++ b/board/msba2/config.c @@ -2,6 +2,16 @@ #include #include +void config_load(void) { + extern char configmem[]; + if (*((uint16_t*) configmem) == CONFIG_KEY) { + memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); + } + else { + config_save(); + } +} + uint8_t config_save(void) { configmem_t mem = { CONFIG_KEY, sysconfig }; return (flashrom_erase((uint8_t*) &configmem) && flashrom_write((uint8_t*) &configmem, (char*) &mem, sizeof(mem))); diff --git a/cpu/arm_common/bootloader.c b/cpu/arm_common/bootloader.c index 5560fb413..568eebf13 100644 --- a/cpu/arm_common/bootloader.c +++ b/cpu/arm_common/bootloader.c @@ -178,9 +178,6 @@ void bootloader(void) { /* board specific setup of UART */ bl_uart_init(); - /* initialize board configuration */ - bl_config_init(); - printf("Board initialized.\n"); } diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index dab1600bf..e16150d29 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -108,10 +108,15 @@ radio_address_t cc1100_set_address(radio_address_t address) { } sysconfig.radio_address = id; - config_save(); return sysconfig.radio_address; } +radio_address_t cc1100_set_config_address(radio_address_t address) { + radio_address_t a = cc1100_set_address(address); + config_save(); + return a; +} + void cc1100_set_monitor(uint8_t mode) { if (mode) { write_register(CC1100_PKTCTRL1, (0x04)); @@ -222,14 +227,19 @@ void cc1100_switch_to_pwd(void) { int16_t cc1100_set_channel(uint8_t channr) { uint8_t state = cc1100_read_status(CC1100_MARCSTATE) & MARC_STATE; if ((state != 1) && (channr > MAX_CHANNR)) { - return 0; + return -1; } write_register(CC1100_CHANNR, channr*10); sysconfig.radio_channel = channr; - config_save(); return sysconfig.radio_channel; } +int16_t cc1100_set_config_channel(uint8_t channr) { + int16_t c = cc1100_set_channel(channr); + config_save(); + return c; +} + int16_t cc1100_get_channel(void) { return sysconfig.radio_channel; } diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc1100_ng.h index 7e901d0d6..0cf11f63a 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc1100_ng.h @@ -109,10 +109,12 @@ void cc1100_wakeup_from_rx(void); void cc1100_switch_to_pwd(void); void cc1100_disable_interrupts(void); +int16_t cc1100_set_config_channel(uint8_t channr); 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_set_config_address(radio_address_t addr); radio_address_t cc1100_get_address(void); void cc1100_set_monitor(uint8_t mode); diff --git a/sys/shell/id.c b/sys/shell/id.c index af8516d6b..f77778553 100644 --- a/sys/shell/id.c +++ b/sys/shell/id.c @@ -13,8 +13,10 @@ void _id_handler(char *id) { else { printf("Setting new id %lu\n", newid); sysconfig.id = newid; +#ifdef MODULE_CONFIG if (!config_save()) { puts("ERROR setting new id"); } +#endif } } From 80f63acec00476890ab22893efd8f9d87ae52a5a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 15:34:22 +0100 Subject: [PATCH 126/199] * Jamrules.common: cleanall: temporarily disable doc cleaning --- Jamrules.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jamrules.common b/Jamrules.common index d2f4c9e86..7ad058b04 100644 --- a/Jamrules.common +++ b/Jamrules.common @@ -125,7 +125,7 @@ actions Cleanall { echo "> Cleaning binaries" $(RM) bin$(SLASH)* - make -C $(TOP)$(SLASH)doc clean +# make -C $(TOP)$(SLASH)doc clean } # From 6a950320ae6ddb04af7713b1a1f09f086a7d500a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 16:02:40 +0100 Subject: [PATCH 127/199] * vtimer: new virtual timer implementation --- sys/Jamfile | 1 + sys/include/timex.h | 12 +++ sys/include/vtimer.h | 20 +++++ sys/timex.c | 29 +++++-- sys/vtimer.c | 195 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 249 insertions(+), 8 deletions(-) create mode 100644 sys/include/vtimer.h create mode 100644 sys/vtimer.c diff --git a/sys/Jamfile b/sys/Jamfile index fcbf64e37..740a02227 100644 --- a/sys/Jamfile +++ b/sys/Jamfile @@ -28,6 +28,7 @@ SubDir TOP sys ; Module timex : timex.c ; +Module vtimer : vtimer.c : hwtimer timex ; Module swtimer : swtimer.c : hwtimer ; Module posix_io : posix_io.c ; diff --git a/sys/include/timex.h b/sys/include/timex.h index 6480223cb..8be3f64d3 100644 --- a/sys/include/timex.h +++ b/sys/include/timex.h @@ -16,4 +16,16 @@ timex_t timex_sub(const timex_t a, const timex_t b); timex_t timex_set(uint32_t seconds, uint32_t nanoseconds); +/** + * @brief Compares two timex values. + * + * @return -1 when a is smaller, 0 if equal, 1 if a is bigger + */ +timex_t timex_sub(const timex_t a, const timex_t b); + +/** + * @brief Corrects timex_t structure so that nanoseconds < 1000000 + */ +void timex_normalize(timex_t *time); + #endif /* __TIMEX_H */ diff --git a/sys/include/vtimer.h b/sys/include/vtimer.h new file mode 100644 index 000000000..9b4e02a09 --- /dev/null +++ b/sys/include/vtimer.h @@ -0,0 +1,20 @@ +#ifndef __VTIMER_H +#define __VTIMER_H + +#include +#include + +typedef struct vtimer_t { + queue_node_t queue_entry; + timex_t absolute; + void(*action)(void*); + void* arg; +} vtimer_t; + +int vtimer_init(); + +int vtimer_set(vtimer_t *timer, timex_t *offset); +timex_t vtimer_now(); +int vtimer_usleep(uint32_t usecs); + +#endif /* __VTIMER_H */ diff --git a/sys/timex.c b/sys/timex.c index 9a1fad129..b87e9723b 100644 --- a/sys/timex.c +++ b/sys/timex.c @@ -5,26 +5,29 @@ timex_t timex_add(const timex_t a, const timex_t b) { result.seconds = a.seconds + b.seconds; result.nanoseconds = a.nanoseconds + b.nanoseconds; - while (result.nanoseconds > 1000*1000) { - result.nanoseconds -= 1000*1000; + if (result.nanoseconds < a.nanoseconds) { result.seconds++; } +/* if (result.nanoseconds > 1000000) { + result.nanoseconds -= 1000000; + result.seconds++; + } +*/ return result; } +void timex_normalize(timex_t *time) { + time->seconds += (time->nanoseconds / 1000000); + time->nanoseconds %= 1000000; +} + timex_t timex_set(uint32_t seconds, uint32_t nanoseconds) { timex_t result; result.seconds = seconds; result.nanoseconds = nanoseconds; - while (result.nanoseconds > 1000*1000) { - result.nanoseconds -= 1000*1000; - result.seconds++; - } - return result; - } timex_t timex_sub(const timex_t a, const timex_t b) { @@ -34,3 +37,13 @@ timex_t timex_sub(const timex_t a, const timex_t b) { return result; } + +int timex_cmp(const timex_t a, const timex_t b) { + if (a.seconds < b.seconds) return -1; + if (a.seconds == b.seconds) { + if (a.nanoseconds < b.nanoseconds) return -1; + if (a.nanoseconds == b.nanoseconds) return 0; + } + return 1; +} + diff --git a/sys/vtimer.c b/sys/vtimer.c new file mode 100644 index 000000000..74e05adf8 --- /dev/null +++ b/sys/vtimer.c @@ -0,0 +1,195 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include + +//#define ENABLE_DEBUG +#include + +#define VTIMER_THRESHOLD 20U + +#define SECONDS_PER_TICK (4096U) +#define NANOSECONDS_PER_TICK (4096U * 1000000) + +void vtimer_callback(void *ptr); +void vtimer_tick(void *ptr); +static int set_longterm(vtimer_t *timer); +static int set_shortterm(vtimer_t *timer); + +static queue_node_t longterm_queue_root; +static queue_node_t shortterm_queue_root; + +static vtimer_t longterm_tick_timer; +static uint32_t longterm_tick_start; +static volatile int in_callback = false; + +static int hwtimer_id = -1; +static uint32_t hwtimer_next_absolute; + +static uint32_t seconds = 0; + +static int set_longterm(vtimer_t *timer) { + timer->queue_entry.priority = timer->absolute.seconds; + queue_priority_add(&longterm_queue_root, (queue_node_t*)timer); + return 0; +} + +static int update_shortterm() { + if (hwtimer_id) { + if (hwtimer_next_absolute != shortterm_queue_root.next->priority) { + hwtimer_remove(hwtimer_id); + } else { + return 0; + } + } + + uint32_t now = hwtimer_now(); + hwtimer_next_absolute = shortterm_queue_root.next->priority; + + while ((hwtimer_next_absolute + longterm_tick_start)-(hwtimer_now()+VTIMER_THRESHOLD) > NANOSECONDS_PER_TICK) { + hwtimer_next_absolute += VTIMER_THRESHOLD; + } + + hwtimer_id = hwtimer_set_absolute(hwtimer_next_absolute + longterm_tick_start, vtimer_callback, NULL); + + DEBUG("update_shortterm: Set hwtimer to %lu (now=%lu)\n", hwtimer_next_absolute + longterm_tick_start, hwtimer_now()); + //printf("%lu (now=%lu)\n", hwtimer_next_absolute + longterm_tick_start, hwtimer_now()); + + return 0; +} + +void vtimer_tick(void *ptr) { + puts("vtimer_tick()."); + seconds += SECONDS_PER_TICK; + + longterm_tick_start = longterm_tick_timer.absolute.nanoseconds; + longterm_tick_timer.absolute.nanoseconds = longterm_tick_timer.absolute.nanoseconds + NANOSECONDS_PER_TICK; + set_shortterm(&longterm_tick_timer); + + while (longterm_queue_root.next) { + vtimer_t *timer = (vtimer_t*) longterm_queue_root.next; + if (timer->absolute.seconds == seconds) { + timer = (vtimer_t*) queue_remove_head(&longterm_queue_root); + set_shortterm(timer); + } else { + break; + } + } + + update_shortterm(); +} + +static int set_shortterm(vtimer_t *timer) { + DEBUG("set_shortterm(): Absolute: %lu %lu\n", timer->absolute.seconds, timer->absolute.nanoseconds); + timer->queue_entry.priority = timer->absolute.nanoseconds; + queue_priority_add(&shortterm_queue_root, (queue_node_t*)timer); + return 1; +} + +void vtimer_callback(void *ptr) { + vtimer_t *timer; + in_callback = true; + timer = (vtimer_t *)queue_remove_head(&shortterm_queue_root); + + DEBUG("vtimer_callback(): Shooting %lu.\n", timer->absolute.nanoseconds); + /* shoot timer */ + timer->action(timer->arg); + + in_callback = false; + update_shortterm(); +} + +void normalize_to_tick(timex_t *time) { + DEBUG("Normalizing: %lu %lu\n", time->seconds, time->nanoseconds); + uint32_t seconds_tmp = time->seconds % SECONDS_PER_TICK; + time->seconds -= seconds_tmp; + uint32_t nsecs_tmp = time->nanoseconds + (seconds_tmp * 1000000); + DEBUG("Normalizin2: %lu %lu\n", time->seconds, nsecs_tmp); + if (nsecs_tmp < time->nanoseconds) { + nsecs_tmp -= NANOSECONDS_PER_TICK; + time->seconds += SECONDS_PER_TICK; + } + if (nsecs_tmp > NANOSECONDS_PER_TICK) { + nsecs_tmp -= NANOSECONDS_PER_TICK; + time->seconds += SECONDS_PER_TICK; + } + time->nanoseconds = nsecs_tmp; + DEBUG(" Result: %lu %lu\n", time->seconds, time->nanoseconds); +} + +int vtimer_set(vtimer_t *timer, timex_t *offset) { + DEBUG("vtimer_set(): New timer. Offset: %lu %lu\n", offset->seconds, offset->nanoseconds); + + +// timex_t vnow = vtimer_now(); +// DEBUG("Now = %lu %lu\n", vnow.seconds, vnow.nanoseconds); + + timer->absolute = timex_add(vtimer_now(), *offset); + normalize_to_tick(&(timer->absolute)); + + DEBUG("vtimer_set(): Absolute: %lu %lu\n", timer->absolute.seconds, timer->absolute.nanoseconds); + + int result = 0; + + int state = disableIRQ(); + if (timer->absolute.seconds != seconds ) { + /* we're long-term */ + DEBUG("vtimer_set(): setting long_term\n"); + result = set_longterm(timer); + } else { + DEBUG("vtimer_set(): setting short_term\n"); + if (set_shortterm(timer)) { + + /* delay update of next shortterm timer if we + * are called from within vtimer_callback. + */ + if (!in_callback) { + result = update_shortterm(); + } + } + } + + restoreIRQ(state); + + return result; +} + +timex_t vtimer_now() { + timex_t t = timex_set(seconds, hwtimer_now()-longterm_tick_start); + return t; +} + +int vtimer_init() { + DEBUG("vtimer_init().\n"); + seconds = 0; + + longterm_tick_timer.action = vtimer_tick; + longterm_tick_timer.arg = NULL; + + longterm_tick_timer.absolute.seconds = 0; + longterm_tick_timer.absolute.nanoseconds = NANOSECONDS_PER_TICK; + + DEBUG("vtimer_init(): Setting longterm tick to %lu\n", longterm_tick_timer.absolute.nanoseconds); + + set_shortterm(&longterm_tick_timer); + update_shortterm(); + + return 0; +} + +int vtimer_usleep(uint32_t usecs) { + vtimer_t t; + timex_t offset = timex_set(0, usecs); + t.action = thread_wakeup; + t.arg = (void*) thread_getpid(); + vtimer_set(&t, &offset); + thread_sleep(); + return 0; +} + From 5a5d083e50fd0e5ad9e1b51b2086aff7fc6eeae4 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 16:06:14 +0100 Subject: [PATCH 128/199] * msba2: updated pttu port, refactored common code into msba2-common --- board/msba2-common/Jamfile | 6 + board/{msba2 => msba2-common}/Jamfile.msba2 | 3 +- board/msba2-common/Jamrules.msba2 | 34 +++ board/msba2-common/board_common_init.c | 160 ++++++++++++++ board/{msba2 => msba2-common}/config.c | 0 board/msba2-common/drivers/Jamfile | 5 + .../drivers/include/sht11-board.h | 0 .../drivers/include/uart0.h | 0 .../drivers/msba2-cc1100.c | 0 .../drivers/msba2-ltc4150.c | 0 .../drivers/msba2-uart0.c | 0 .../include/msba2_common.h} | 33 +-- .../{msba2 => msba2-common}/lpc2387-timer3.c | 0 board/{msba2 => msba2-common}/tools/CHANGES | 0 board/{msba2 => msba2-common}/tools/COPYING | 0 board/{msba2 => msba2-common}/tools/Makefile | 0 .../{msba2 => msba2-common}/tools/README.txt | 0 .../tools/armtools.txt | 0 board/{msba2 => msba2-common}/tools/flash.cmd | 0 .../tools/flashutil.sh | 0 board/{msba2 => msba2-common}/tools/mkbootc | 0 .../tools/mkstaticlist | 0 .../tools/obj/boot_23xx.d | 0 .../tools/obj/boot_2xxx.d | 0 .../tools/obj/chipinfo.d | 0 .../tools/obj/control_2xxx.d | 0 .../tools/obj/download.d | 0 .../{msba2 => msba2-common}/tools/obj/ihex.d | 0 .../tools/obj/lpc2k_pgm.d | 0 .../tools/obj/pseudoterm.d | 0 .../tools/obj/serial.d | 0 .../tools/obj/uuencode.d | 0 .../{msba2 => msba2-common}/tools/src/Jamfile | 0 .../{msba2 => msba2-common}/tools/src/boot.h | 0 .../tools/src/boot_23xx.armasm | 0 .../tools/src/boot_23xx.c | 0 .../tools/src/boot_23xx.h | 0 .../tools/src/boot_2xxx.armasm | 0 .../tools/src/boot_2xxx.c | 0 .../tools/src/boot_2xxx.h | 0 .../tools/src/chipinfo.c | 0 .../tools/src/chipinfo.h | 0 .../tools/src/cksum_test.c | 0 .../tools/src/control_2xxx.c | 0 .../tools/src/control_2xxx.h | 0 .../tools/src/download.c | 0 .../tools/src/download.h | 0 board/{msba2 => msba2-common}/tools/src/gui.c | 0 board/{msba2 => msba2-common}/tools/src/gui.h | 0 .../{msba2 => msba2-common}/tools/src/ihex.c | 0 .../{msba2 => msba2-common}/tools/src/ihex.h | 0 .../tools/src/lpc2k_pgm.c | 0 .../tools/src/lpc2k_pgm.h | 0 .../tools/src/pseudoterm.c | 0 .../tools/src/serial.c | 0 .../tools/src/serial.h | 0 .../tools/src/settings.c | 0 .../tools/src/settings.h | 0 .../tools/src/uuencode.c | 0 .../tools/src/uuencode.h | 0 .../{msba2 => msba2-common}/tools/termctrl.sh | 0 board/msba2/Jamfile | 10 +- board/msba2/Jamrules.msba2 | 34 +-- board/msba2/board_init.c | 149 ++----------- board/msba2/drivers/Jamfile | 7 - board/msba2/include/board-conf.h | 68 ------ board/msba2/include/board.h | 51 +---- board/pttu/Jamfile | 9 +- board/pttu/Jamrules.pttu | 5 +- board/pttu/board_init.c | 86 +------- board/pttu/drivers/Jamfile | 2 - board/pttu/drivers/pttu-uart0.c | 204 ------------------ 72 files changed, 250 insertions(+), 616 deletions(-) create mode 100644 board/msba2-common/Jamfile rename board/{msba2 => msba2-common}/Jamfile.msba2 (90%) create mode 100644 board/msba2-common/Jamrules.msba2 create mode 100644 board/msba2-common/board_common_init.c rename board/{msba2 => msba2-common}/config.c (100%) create mode 100644 board/msba2-common/drivers/Jamfile rename board/{msba2 => msba2-common}/drivers/include/sht11-board.h (100%) rename board/{msba2 => msba2-common}/drivers/include/uart0.h (100%) rename board/{msba2 => msba2-common}/drivers/msba2-cc1100.c (100%) rename board/{msba2 => msba2-common}/drivers/msba2-ltc4150.c (100%) rename board/{msba2 => msba2-common}/drivers/msba2-uart0.c (100%) rename board/{msba2/drivers/include/hal-board.h => msba2-common/include/msba2_common.h} (74%) rename board/{msba2 => msba2-common}/lpc2387-timer3.c (100%) rename board/{msba2 => msba2-common}/tools/CHANGES (100%) rename board/{msba2 => msba2-common}/tools/COPYING (100%) rename board/{msba2 => msba2-common}/tools/Makefile (100%) rename board/{msba2 => msba2-common}/tools/README.txt (100%) rename board/{msba2 => msba2-common}/tools/armtools.txt (100%) rename board/{msba2 => msba2-common}/tools/flash.cmd (100%) rename board/{msba2 => msba2-common}/tools/flashutil.sh (100%) rename board/{msba2 => msba2-common}/tools/mkbootc (100%) rename board/{msba2 => msba2-common}/tools/mkstaticlist (100%) rename board/{msba2 => msba2-common}/tools/obj/boot_23xx.d (100%) rename board/{msba2 => msba2-common}/tools/obj/boot_2xxx.d (100%) rename board/{msba2 => msba2-common}/tools/obj/chipinfo.d (100%) rename board/{msba2 => msba2-common}/tools/obj/control_2xxx.d (100%) rename board/{msba2 => msba2-common}/tools/obj/download.d (100%) rename board/{msba2 => msba2-common}/tools/obj/ihex.d (100%) rename board/{msba2 => msba2-common}/tools/obj/lpc2k_pgm.d (100%) rename board/{msba2 => msba2-common}/tools/obj/pseudoterm.d (100%) rename board/{msba2 => msba2-common}/tools/obj/serial.d (100%) rename board/{msba2 => msba2-common}/tools/obj/uuencode.d (100%) rename board/{msba2 => msba2-common}/tools/src/Jamfile (100%) rename board/{msba2 => msba2-common}/tools/src/boot.h (100%) rename board/{msba2 => msba2-common}/tools/src/boot_23xx.armasm (100%) rename board/{msba2 => msba2-common}/tools/src/boot_23xx.c (100%) rename board/{msba2 => msba2-common}/tools/src/boot_23xx.h (100%) rename board/{msba2 => msba2-common}/tools/src/boot_2xxx.armasm (100%) rename board/{msba2 => msba2-common}/tools/src/boot_2xxx.c (100%) rename board/{msba2 => msba2-common}/tools/src/boot_2xxx.h (100%) rename board/{msba2 => msba2-common}/tools/src/chipinfo.c (100%) rename board/{msba2 => msba2-common}/tools/src/chipinfo.h (100%) rename board/{msba2 => msba2-common}/tools/src/cksum_test.c (100%) rename board/{msba2 => msba2-common}/tools/src/control_2xxx.c (100%) rename board/{msba2 => msba2-common}/tools/src/control_2xxx.h (100%) rename board/{msba2 => msba2-common}/tools/src/download.c (100%) rename board/{msba2 => msba2-common}/tools/src/download.h (100%) rename board/{msba2 => msba2-common}/tools/src/gui.c (100%) rename board/{msba2 => msba2-common}/tools/src/gui.h (100%) rename board/{msba2 => msba2-common}/tools/src/ihex.c (100%) rename board/{msba2 => msba2-common}/tools/src/ihex.h (100%) rename board/{msba2 => msba2-common}/tools/src/lpc2k_pgm.c (100%) rename board/{msba2 => msba2-common}/tools/src/lpc2k_pgm.h (100%) rename board/{msba2 => msba2-common}/tools/src/pseudoterm.c (100%) rename board/{msba2 => msba2-common}/tools/src/serial.c (100%) rename board/{msba2 => msba2-common}/tools/src/serial.h (100%) rename board/{msba2 => msba2-common}/tools/src/settings.c (100%) rename board/{msba2 => msba2-common}/tools/src/settings.h (100%) rename board/{msba2 => msba2-common}/tools/src/uuencode.c (100%) rename board/{msba2 => msba2-common}/tools/src/uuencode.h (100%) rename board/{msba2 => msba2-common}/tools/termctrl.sh (100%) delete mode 100644 board/msba2/drivers/Jamfile delete mode 100644 board/msba2/include/board-conf.h delete mode 100644 board/pttu/drivers/pttu-uart0.c diff --git a/board/msba2-common/Jamfile b/board/msba2-common/Jamfile new file mode 100644 index 000000000..8b3d8febc --- /dev/null +++ b/board/msba2-common/Jamfile @@ -0,0 +1,6 @@ +SubDir TOP board msba2-common ; + +Module board_common : board_common_init.c ; + +SubInclude TOP board msba2-common drivers ; + diff --git a/board/msba2/Jamfile.msba2 b/board/msba2-common/Jamfile.msba2 similarity index 90% rename from board/msba2/Jamfile.msba2 rename to board/msba2-common/Jamfile.msba2 index 44014a6c9..e9e291c90 100644 --- a/board/msba2/Jamfile.msba2 +++ b/board/msba2-common/Jamfile.msba2 @@ -25,7 +25,6 @@ # ****************************************************************************** # $Id$ -#LinkLibraries $(BOARD).elf : sys-drivers.a net_mm.a sys-lib.a fat-lib.a -# cpu_drivers.a board_drivers.a cc110x.a hal.a hal_drivers.a lpc2387_hal.a ; +Module msba2_common : board_init.c ; include [ FPath $(TOP) cpu arm_common Jamfile.arm_common ] ; diff --git a/board/msba2-common/Jamrules.msba2 b/board/msba2-common/Jamrules.msba2 new file mode 100644 index 000000000..1bce8075c --- /dev/null +++ b/board/msba2-common/Jamrules.msba2 @@ -0,0 +1,34 @@ +# ****************************************************************************** +# 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 = lpc2387 ; + +HDRS += [ FPath $(TOP) board msba2-common include ] ; +HDRS += [ FPath $(TOP) board msba2-common drivers include ] ; + +FLASHER ?= $(POSIXSHELL) lpc2k_pgm ; +FLASHFLAGS ?= "$(PORT)" ; diff --git a/board/msba2-common/board_common_init.c b/board/msba2-common/board_common_init.c new file mode 100644 index 000000000..0823a71bc --- /dev/null +++ b/board/msba2-common/board_common_init.c @@ -0,0 +1,160 @@ +/****************************************************************************** +Copyright 2008-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 +*******************************************************************************/ + +/** + * @ingroup msba2 + * @{ + */ + +/** + * @file + * @brief MSB-A2 board initialization + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Kaspar Schleiser + * @author Michael Baar + * + * @note $Id$ + */ +#include +#include +#include +#include +#include +#include +#include + +#define PCRTC BIT9 +#define CL_CPU_DIV 4 + +config_t sysconfig = { + 0, ///< default ID + 0, ///< default radio address + 0, ///< default radio channel +}; + +/*---------------------------------------------------------------------------*/ +/** + * @brief Enabling MAM and setting number of clocks used for Flash memory fetch + * @internal + */ +static void +init_mam(void) +{ + MAMCR = 0x0000; + MAMTIM = 0x0003; + MAMCR = 0x0002; +} +/*---------------------------------------------------------------------------*/ +static inline void +pllfeed(void) +{ + PLLFEED = 0xAA; + PLLFEED = 0x55; +} +/*---------------------------------------------------------------------------*/ +void init_clks1(void) +{ + // Disconnect PLL + PLLCON &= ~0x0002; + pllfeed(); + + // Disable PLL + PLLCON &= ~0x0001; + pllfeed(); + + SCS |= 0x20; // Enable main OSC + while( !(SCS & 0x40) ); // Wait until main OSC is usable + + /* select main OSC, 16MHz, as the PLL clock source */ + CLKSRCSEL = 0x0001; + + // Setting Multiplier and Divider values + PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz + pllfeed(); + + // Enabling the PLL */ + PLLCON = 0x0001; + pllfeed(); + + /* Set clock divider to 4 (value+1) */ + CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz + +#if USE_USB + USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ +#endif +} + +void init_clks2(void){ + // Wait for the PLL to lock to set frequency + while(!(PLLSTAT & BIT26)); + + // Connect the PLL as the clock source + PLLCON = 0x0003; + pllfeed(); + + /* Check connect bit status */ + while (!(PLLSTAT & BIT25)); +} + +void bl_init_clks(void) +{ + PCONP = PCRTC; // switch off everything except RTC + init_clks1(); + init_clks2(); + init_mam(); +} + +void loop_delay(void) { + volatile uint16_t i, j; + for (i = 1; i < 30; i++) { + for (j = 1; j != 0; j++) { + asm volatile (" nop "); + } + } +} + +/*void bl_blink(void) { + LED_RED_ON; + LED_GREEN_ON; + + loop_delay(); + + LED_RED_OFF; + LED_GREEN_OFF; +}*/ + +// void bl_config_init(void) { +// extern char configmem[]; +// if (*((uint16_t*) configmem) == CONFIG_KEY) { +// memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); +// LED_GREEN_TOGGLE; +// } +// else { +// config_save(); +// } +// } diff --git a/board/msba2/config.c b/board/msba2-common/config.c similarity index 100% rename from board/msba2/config.c rename to board/msba2-common/config.c diff --git a/board/msba2-common/drivers/Jamfile b/board/msba2-common/drivers/Jamfile new file mode 100644 index 000000000..963798216 --- /dev/null +++ b/board/msba2-common/drivers/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP board msba2-common drivers ; + +Module board_cc1100 : msba2-cc1100.c ; +Module board_ltc4150 : msba2-ltc4150.c : gpioint ; +Module board_uart : msba2-uart0.c : chardev_thread ringbuffer ; diff --git a/board/msba2/drivers/include/sht11-board.h b/board/msba2-common/drivers/include/sht11-board.h similarity index 100% rename from board/msba2/drivers/include/sht11-board.h rename to board/msba2-common/drivers/include/sht11-board.h diff --git a/board/msba2/drivers/include/uart0.h b/board/msba2-common/drivers/include/uart0.h similarity index 100% rename from board/msba2/drivers/include/uart0.h rename to board/msba2-common/drivers/include/uart0.h diff --git a/board/msba2/drivers/msba2-cc1100.c b/board/msba2-common/drivers/msba2-cc1100.c similarity index 100% rename from board/msba2/drivers/msba2-cc1100.c rename to board/msba2-common/drivers/msba2-cc1100.c diff --git a/board/msba2/drivers/msba2-ltc4150.c b/board/msba2-common/drivers/msba2-ltc4150.c similarity index 100% rename from board/msba2/drivers/msba2-ltc4150.c rename to board/msba2-common/drivers/msba2-ltc4150.c diff --git a/board/msba2/drivers/msba2-uart0.c b/board/msba2-common/drivers/msba2-uart0.c similarity index 100% rename from board/msba2/drivers/msba2-uart0.c rename to board/msba2-common/drivers/msba2-uart0.c diff --git a/board/msba2/drivers/include/hal-board.h b/board/msba2-common/include/msba2_common.h similarity index 74% rename from board/msba2/drivers/include/hal-board.h rename to board/msba2-common/include/msba2_common.h index a4dfc293a..a9d9d3e72 100644 --- a/board/msba2/drivers/include/hal-board.h +++ b/board/msba2-common/include/msba2_common.h @@ -24,45 +24,28 @@ and the mailinglist (subscription via web site) scatterweb@lists.spline.inf.fu-berlin.de *******************************************************************************/ -#ifndef HALPLATFORM_H_ -#define HALPLATFORM_H_ +#ifndef __BOARD_H +#define __BOARD_H /** - * @ingroup msba2 + * @ingroup msb_a2 * @{ */ /** * @file - * @brief + * @brief MSB-A2 Common Board Definitions * * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author baar + * @author Kaspar Schleiser * @version $Revision$ * * @note $Id$ */ -#include "vdevice.h" -#include "device-gpio.h" -#include "device-rs232.h" -#include "device-serial.h" +#include -VDEVICE_NAME(vdevice_gpio, gpio_led_green); -VDEVICE_NAME(vdevice_gpio, gpio_led_red); -VDEVICE_NAME(vdevice_gpio, gpio_led_usb); - -/** - * @var tty0 - * @brief RS232 TTY0 device on UART0 - */ -VDEVICE_NAME(vdevice_rs232, tty0); - -/** - * @var console0 - * @brief console device on tty0 - */ -VDEVICE_NAME(vdevice_serial, console0); +#define VICIntEnClear VICIntEnClr /** @} */ -#endif /* HALPLATFORM_H_ */ +#endif // __BOARD_H diff --git a/board/msba2/lpc2387-timer3.c b/board/msba2-common/lpc2387-timer3.c similarity index 100% rename from board/msba2/lpc2387-timer3.c rename to board/msba2-common/lpc2387-timer3.c diff --git a/board/msba2/tools/CHANGES b/board/msba2-common/tools/CHANGES similarity index 100% rename from board/msba2/tools/CHANGES rename to board/msba2-common/tools/CHANGES diff --git a/board/msba2/tools/COPYING b/board/msba2-common/tools/COPYING similarity index 100% rename from board/msba2/tools/COPYING rename to board/msba2-common/tools/COPYING diff --git a/board/msba2/tools/Makefile b/board/msba2-common/tools/Makefile similarity index 100% rename from board/msba2/tools/Makefile rename to board/msba2-common/tools/Makefile diff --git a/board/msba2/tools/README.txt b/board/msba2-common/tools/README.txt similarity index 100% rename from board/msba2/tools/README.txt rename to board/msba2-common/tools/README.txt diff --git a/board/msba2/tools/armtools.txt b/board/msba2-common/tools/armtools.txt similarity index 100% rename from board/msba2/tools/armtools.txt rename to board/msba2-common/tools/armtools.txt diff --git a/board/msba2/tools/flash.cmd b/board/msba2-common/tools/flash.cmd similarity index 100% rename from board/msba2/tools/flash.cmd rename to board/msba2-common/tools/flash.cmd diff --git a/board/msba2/tools/flashutil.sh b/board/msba2-common/tools/flashutil.sh similarity index 100% rename from board/msba2/tools/flashutil.sh rename to board/msba2-common/tools/flashutil.sh diff --git a/board/msba2/tools/mkbootc b/board/msba2-common/tools/mkbootc similarity index 100% rename from board/msba2/tools/mkbootc rename to board/msba2-common/tools/mkbootc diff --git a/board/msba2/tools/mkstaticlist b/board/msba2-common/tools/mkstaticlist similarity index 100% rename from board/msba2/tools/mkstaticlist rename to board/msba2-common/tools/mkstaticlist diff --git a/board/msba2/tools/obj/boot_23xx.d b/board/msba2-common/tools/obj/boot_23xx.d similarity index 100% rename from board/msba2/tools/obj/boot_23xx.d rename to board/msba2-common/tools/obj/boot_23xx.d diff --git a/board/msba2/tools/obj/boot_2xxx.d b/board/msba2-common/tools/obj/boot_2xxx.d similarity index 100% rename from board/msba2/tools/obj/boot_2xxx.d rename to board/msba2-common/tools/obj/boot_2xxx.d diff --git a/board/msba2/tools/obj/chipinfo.d b/board/msba2-common/tools/obj/chipinfo.d similarity index 100% rename from board/msba2/tools/obj/chipinfo.d rename to board/msba2-common/tools/obj/chipinfo.d diff --git a/board/msba2/tools/obj/control_2xxx.d b/board/msba2-common/tools/obj/control_2xxx.d similarity index 100% rename from board/msba2/tools/obj/control_2xxx.d rename to board/msba2-common/tools/obj/control_2xxx.d diff --git a/board/msba2/tools/obj/download.d b/board/msba2-common/tools/obj/download.d similarity index 100% rename from board/msba2/tools/obj/download.d rename to board/msba2-common/tools/obj/download.d diff --git a/board/msba2/tools/obj/ihex.d b/board/msba2-common/tools/obj/ihex.d similarity index 100% rename from board/msba2/tools/obj/ihex.d rename to board/msba2-common/tools/obj/ihex.d diff --git a/board/msba2/tools/obj/lpc2k_pgm.d b/board/msba2-common/tools/obj/lpc2k_pgm.d similarity index 100% rename from board/msba2/tools/obj/lpc2k_pgm.d rename to board/msba2-common/tools/obj/lpc2k_pgm.d diff --git a/board/msba2/tools/obj/pseudoterm.d b/board/msba2-common/tools/obj/pseudoterm.d similarity index 100% rename from board/msba2/tools/obj/pseudoterm.d rename to board/msba2-common/tools/obj/pseudoterm.d diff --git a/board/msba2/tools/obj/serial.d b/board/msba2-common/tools/obj/serial.d similarity index 100% rename from board/msba2/tools/obj/serial.d rename to board/msba2-common/tools/obj/serial.d diff --git a/board/msba2/tools/obj/uuencode.d b/board/msba2-common/tools/obj/uuencode.d similarity index 100% rename from board/msba2/tools/obj/uuencode.d rename to board/msba2-common/tools/obj/uuencode.d diff --git a/board/msba2/tools/src/Jamfile b/board/msba2-common/tools/src/Jamfile similarity index 100% rename from board/msba2/tools/src/Jamfile rename to board/msba2-common/tools/src/Jamfile diff --git a/board/msba2/tools/src/boot.h b/board/msba2-common/tools/src/boot.h similarity index 100% rename from board/msba2/tools/src/boot.h rename to board/msba2-common/tools/src/boot.h diff --git a/board/msba2/tools/src/boot_23xx.armasm b/board/msba2-common/tools/src/boot_23xx.armasm similarity index 100% rename from board/msba2/tools/src/boot_23xx.armasm rename to board/msba2-common/tools/src/boot_23xx.armasm diff --git a/board/msba2/tools/src/boot_23xx.c b/board/msba2-common/tools/src/boot_23xx.c similarity index 100% rename from board/msba2/tools/src/boot_23xx.c rename to board/msba2-common/tools/src/boot_23xx.c diff --git a/board/msba2/tools/src/boot_23xx.h b/board/msba2-common/tools/src/boot_23xx.h similarity index 100% rename from board/msba2/tools/src/boot_23xx.h rename to board/msba2-common/tools/src/boot_23xx.h diff --git a/board/msba2/tools/src/boot_2xxx.armasm b/board/msba2-common/tools/src/boot_2xxx.armasm similarity index 100% rename from board/msba2/tools/src/boot_2xxx.armasm rename to board/msba2-common/tools/src/boot_2xxx.armasm diff --git a/board/msba2/tools/src/boot_2xxx.c b/board/msba2-common/tools/src/boot_2xxx.c similarity index 100% rename from board/msba2/tools/src/boot_2xxx.c rename to board/msba2-common/tools/src/boot_2xxx.c diff --git a/board/msba2/tools/src/boot_2xxx.h b/board/msba2-common/tools/src/boot_2xxx.h similarity index 100% rename from board/msba2/tools/src/boot_2xxx.h rename to board/msba2-common/tools/src/boot_2xxx.h diff --git a/board/msba2/tools/src/chipinfo.c b/board/msba2-common/tools/src/chipinfo.c similarity index 100% rename from board/msba2/tools/src/chipinfo.c rename to board/msba2-common/tools/src/chipinfo.c diff --git a/board/msba2/tools/src/chipinfo.h b/board/msba2-common/tools/src/chipinfo.h similarity index 100% rename from board/msba2/tools/src/chipinfo.h rename to board/msba2-common/tools/src/chipinfo.h diff --git a/board/msba2/tools/src/cksum_test.c b/board/msba2-common/tools/src/cksum_test.c similarity index 100% rename from board/msba2/tools/src/cksum_test.c rename to board/msba2-common/tools/src/cksum_test.c diff --git a/board/msba2/tools/src/control_2xxx.c b/board/msba2-common/tools/src/control_2xxx.c similarity index 100% rename from board/msba2/tools/src/control_2xxx.c rename to board/msba2-common/tools/src/control_2xxx.c diff --git a/board/msba2/tools/src/control_2xxx.h b/board/msba2-common/tools/src/control_2xxx.h similarity index 100% rename from board/msba2/tools/src/control_2xxx.h rename to board/msba2-common/tools/src/control_2xxx.h diff --git a/board/msba2/tools/src/download.c b/board/msba2-common/tools/src/download.c similarity index 100% rename from board/msba2/tools/src/download.c rename to board/msba2-common/tools/src/download.c diff --git a/board/msba2/tools/src/download.h b/board/msba2-common/tools/src/download.h similarity index 100% rename from board/msba2/tools/src/download.h rename to board/msba2-common/tools/src/download.h diff --git a/board/msba2/tools/src/gui.c b/board/msba2-common/tools/src/gui.c similarity index 100% rename from board/msba2/tools/src/gui.c rename to board/msba2-common/tools/src/gui.c diff --git a/board/msba2/tools/src/gui.h b/board/msba2-common/tools/src/gui.h similarity index 100% rename from board/msba2/tools/src/gui.h rename to board/msba2-common/tools/src/gui.h diff --git a/board/msba2/tools/src/ihex.c b/board/msba2-common/tools/src/ihex.c similarity index 100% rename from board/msba2/tools/src/ihex.c rename to board/msba2-common/tools/src/ihex.c diff --git a/board/msba2/tools/src/ihex.h b/board/msba2-common/tools/src/ihex.h similarity index 100% rename from board/msba2/tools/src/ihex.h rename to board/msba2-common/tools/src/ihex.h diff --git a/board/msba2/tools/src/lpc2k_pgm.c b/board/msba2-common/tools/src/lpc2k_pgm.c similarity index 100% rename from board/msba2/tools/src/lpc2k_pgm.c rename to board/msba2-common/tools/src/lpc2k_pgm.c diff --git a/board/msba2/tools/src/lpc2k_pgm.h b/board/msba2-common/tools/src/lpc2k_pgm.h similarity index 100% rename from board/msba2/tools/src/lpc2k_pgm.h rename to board/msba2-common/tools/src/lpc2k_pgm.h diff --git a/board/msba2/tools/src/pseudoterm.c b/board/msba2-common/tools/src/pseudoterm.c similarity index 100% rename from board/msba2/tools/src/pseudoterm.c rename to board/msba2-common/tools/src/pseudoterm.c diff --git a/board/msba2/tools/src/serial.c b/board/msba2-common/tools/src/serial.c similarity index 100% rename from board/msba2/tools/src/serial.c rename to board/msba2-common/tools/src/serial.c diff --git a/board/msba2/tools/src/serial.h b/board/msba2-common/tools/src/serial.h similarity index 100% rename from board/msba2/tools/src/serial.h rename to board/msba2-common/tools/src/serial.h diff --git a/board/msba2/tools/src/settings.c b/board/msba2-common/tools/src/settings.c similarity index 100% rename from board/msba2/tools/src/settings.c rename to board/msba2-common/tools/src/settings.c diff --git a/board/msba2/tools/src/settings.h b/board/msba2-common/tools/src/settings.h similarity index 100% rename from board/msba2/tools/src/settings.h rename to board/msba2-common/tools/src/settings.h diff --git a/board/msba2/tools/src/uuencode.c b/board/msba2-common/tools/src/uuencode.c similarity index 100% rename from board/msba2/tools/src/uuencode.c rename to board/msba2-common/tools/src/uuencode.c diff --git a/board/msba2/tools/src/uuencode.h b/board/msba2-common/tools/src/uuencode.h similarity index 100% rename from board/msba2/tools/src/uuencode.h rename to board/msba2-common/tools/src/uuencode.h diff --git a/board/msba2/tools/termctrl.sh b/board/msba2-common/tools/termctrl.sh similarity index 100% rename from board/msba2/tools/termctrl.sh rename to board/msba2-common/tools/termctrl.sh diff --git a/board/msba2/Jamfile b/board/msba2/Jamfile index 468b45306..553522ba6 100644 --- a/board/msba2/Jamfile +++ b/board/msba2/Jamfile @@ -25,12 +25,12 @@ # ****************************************************************************** # $Id$ -SubDir TOP board msba2 ; +SubDir TOP board $(BOARD) ; -Module board : board_init.c ; -Module config : config.c ; +Module board : board_init.c : board_common board_uart ; UseModule board ; -UseModule board_common ; -SubInclude TOP board $(BOARD) drivers ; +Module config : config.c ; + +SubInclude TOP board $(BOARD)-common ; SubInclude TOP cpu $(CPU) ; diff --git a/board/msba2/Jamrules.msba2 b/board/msba2/Jamrules.msba2 index b0ad55f75..22c8a8806 100644 --- a/board/msba2/Jamrules.msba2 +++ b/board/msba2/Jamrules.msba2 @@ -1,33 +1 @@ -# ****************************************************************************** -# 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 = lpc2387 ; - -HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; - -FLASHER ?= $(POSIXSHELL) lpc2k_pgm ; -FLASHFLAGS ?= "$(PORT)" ; +include board/msba2-common/Jamrules.msba2 ; diff --git a/board/msba2/board_init.c b/board/msba2/board_init.c index 469c8fe7c..f250109c0 100644 --- a/board/msba2/board_init.c +++ b/board/msba2/board_init.c @@ -1,123 +1,23 @@ -/****************************************************************************** -Copyright 2008-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 -*******************************************************************************/ - -/** - * @ingroup msba2 - * @{ - */ - -/** - * @file - * @brief MSB-A2 board initialization - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author Heiko Will - * @author Kaspar Schleiser - * @author Michael Baar - * - * @note $Id$ - */ #include -#include -#include #include -#define PCRTC BIT9 -#define CL_CPU_DIV 4 - -/*---------------------------------------------------------------------------*/ -/** - * @brief Enabling MAM and setting number of clocks used for Flash memory fetch - * @internal - */ -static void -init_mam(void) -{ - MAMCR = 0x0000; - MAMTIM = 0x0003; - MAMCR = 0x0002; -} -/*---------------------------------------------------------------------------*/ -static inline void -pllfeed(void) -{ - PLLFEED = 0xAA; - PLLFEED = 0x55; -} -/*---------------------------------------------------------------------------*/ -void init_clks1(void) -{ - // Disconnect PLL - PLLCON &= ~0x0002; - pllfeed(); - - // Disable PLL - PLLCON &= ~0x0001; - pllfeed(); - - SCS |= 0x20; // Enable main OSC - while( !(SCS & 0x40) ); // Wait until main OSC is usable - - /* select main OSC, 16MHz, as the PLL clock source */ - CLKSRCSEL = 0x0001; - - // Setting Multiplier and Divider values - PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz - pllfeed(); - - // Enabling the PLL */ - PLLCON = 0x0001; - pllfeed(); - - /* Set clock divider to 4 (value+1) */ - CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz - -#if USE_USB - USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ -#endif +void loop_delay(void) { + volatile uint16_t i, j; + for (i = 1; i < 30; i++) { + for (j = 1; j != 0; j++) { + asm volatile (" nop "); + } + } } -void init_clks2(void){ - // Wait for the PLL to lock to set frequency - while(!(PLLSTAT & BIT26)); - - // Connect the PLL as the clock source - PLLCON = 0x0003; - pllfeed(); - - /* Check connect bit status */ - while (!(PLLSTAT & BIT25)); -} +void bl_blink(void) { + LED_RED_ON; + LED_GREEN_ON; + + loop_delay(); -void bl_init_clks(void) -{ - PCONP = PCRTC; // switch off everything except RTC - init_clks1(); - init_clks2(); - init_mam(); + LED_RED_OFF; + LED_GREEN_OFF; } void bl_init_ports(void) @@ -133,23 +33,8 @@ void bl_init_ports(void) FIO3DIR |= LED_GREEN_PIN; LED_RED_OFF; LED_GREEN_OFF; -} - -void loop_delay(void) { - volatile uint16_t i, j; - for (i = 1; i < 30; i++) { - for (j = 1; j != 0; j++) { - asm volatile (" nop "); - } - } -} - -void bl_blink(void) { - LED_RED_ON; - LED_GREEN_ON; - loop_delay(); - - LED_RED_OFF; - LED_GREEN_OFF; + /* short blinking of both of the LEDs on startup */ + bl_blink(); } + diff --git a/board/msba2/drivers/Jamfile b/board/msba2/drivers/Jamfile deleted file mode 100644 index 50f2ddbf0..000000000 --- a/board/msba2/drivers/Jamfile +++ /dev/null @@ -1,7 +0,0 @@ -SubDir TOP board msba2 drivers ; - -Module board_cc1100 : msba2-cc1100.c : gpioint cc110x_spi ; -Module board_hal : msba2-hal.c ; -Module board_ltc4150 : msba2-ltc4150.c : gpioint ; -Module board_common : msba2-uart0.c : ringbuffer ; -Module board_uart : msba2-uart0_thread.c : chardev_thread ringbuffer ; diff --git a/board/msba2/include/board-conf.h b/board/msba2/include/board-conf.h deleted file mode 100644 index 2c8824f1f..000000000 --- a/board/msba2/include/board-conf.h +++ /dev/null @@ -1,68 +0,0 @@ -/****************************************************************************** -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 BOARDCONF_H_ -#define BOARDCONF_H_ - -/** - * @ingroup conf - * @ingroup msba2 - * - * @{ - */ - -/** - * @file - * @brief MSB-A2 board configuration - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author baar - * @version $Revision$ - * - * @note $Id$ - */ - -#define FEUERWARE_CONF_BOARD_NAME "FU Berlin MSB-A2" - -#ifdef MODULE_CC110X -#define FEUERWARE_CONF_NUM_RADIOS 1 -#else -#define FEUERWARE_CONF_NUM_RADIOS 0 -#endif - -// if FAT is enabled this board supports files -#define FEUERWARE_CONF_CORE_SUPPORTS_FILES defined(MODULE_FAT) - -#ifdef MODULE_FAT -#define CFG_CONF_MEM_SIZE 0x7FFFFFFF -#define SYSLOG_CONF_NUM_INTERFACES 2 -#else -#define SYSLOG_CONF_NUM_INTERFACES 1 -#endif - - -/** @} */ -#endif /* BOARDCONF_H_ */ diff --git a/board/msba2/include/board.h b/board/msba2/include/board.h index 4356e4423..bf596f0ee 100644 --- a/board/msba2/include/board.h +++ b/board/msba2/include/board.h @@ -1,51 +1,7 @@ -/****************************************************************************** -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 __BOARD_H -#define __BOARD_H - -/** - * @ingroup msb_a2 - * @{ - */ - -/** - * @file - * @brief MSB-A2 Board - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author Kaspar Schleiser - * @version $Revision$ - * - * @note $Id$ - */ - -#include +#define __BOARD_H -#define VICIntEnClear VICIntEnClr +#include #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) @@ -58,5 +14,4 @@ and the mailinglist (subscription via web site) #define LED_RED_ON (FIO3CLR = LED_RED_PIN) #define LED_RED_TOGGLE (FIO3PIN ^= LED_RED_PIN) -/** @} */ -#endif // __BOARD_H +#endif /* __BOARD_H */ diff --git a/board/pttu/Jamfile b/board/pttu/Jamfile index a7b4d6df1..11b4a77e7 100644 --- a/board/pttu/Jamfile +++ b/board/pttu/Jamfile @@ -23,13 +23,12 @@ # and the mailinglist (subscription via web site) # scatterweb@lists.spline.inf.fu-berlin.de # ****************************************************************************** -# $Id: Jamfile 922 2009-03-26 12:52:27Z baar $ +# $Id$ -SubDir TOP board pttu ; +SubDir TOP board $(BOARD) ; -Module board : board_init.c ; +Module board : board_init.c : board_common board_uart ; UseModule board ; -UseModule board_common ; -SubInclude TOP board $(BOARD) drivers ; +SubInclude TOP board msba2-common ; SubInclude TOP cpu $(CPU) ; diff --git a/board/pttu/Jamrules.pttu b/board/pttu/Jamrules.pttu index 7eff15f0b..53e71c71f 100644 --- a/board/pttu/Jamrules.pttu +++ b/board/pttu/Jamrules.pttu @@ -25,13 +25,10 @@ # ****************************************************************************** # $Id: Jamrules.msba2 881 2009-03-20 12:24:58Z kaspar $ -CPU = lpc2387 ; +include board/msba2-common/Jamrules.msba2 ; HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; -FLASHER = $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; -FLASHFLAGS = --basedir $(TOP)/board/msba2/tools --id PTTU --ports "$(PORT)" --openocd $(TOP)/board/pttu/tools/openocd-pttu.sh --openocd-if $(OPENOCD_IF) ; - GDB = arm-elf-gdb ; GDBFLAGS = -x board/pttu/tools/pttu_debug.gdb ; diff --git a/board/pttu/board_init.c b/board/pttu/board_init.c index 3070bdfce..b5b78bde2 100644 --- a/board/pttu/board_init.c +++ b/board/pttu/board_init.c @@ -33,94 +33,18 @@ and the mailinglist (subscription via web site) * @file * @brief PTTU board initialization * - * @author Freie Universit�t Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project * @author Heiko Will - * @author Kaspar Schleise - * @author Michael Baar + * @author Kaspar Schleiser * - * @note $Id: cmdengine-out.c 971 2009-04-07 13:41:36Z baar $ */ -#include "lpc23xx.h" -#include "VIC.h" -#include "cpu.h" +#include +#include +#include #define PCRTC BIT9 #define CL_CPU_DIV 4 -/*---------------------------------------------------------------------------*/ -/** - * @brief Enabling MAM and setting number of clocks used for Flash memory fetch - * @internal - */ -void -init_mam(void) -{ - MAMCR = 0x0000; - MAMTIM = 0x0003; - MAMCR = 0x0002; -} -/*---------------------------------------------------------------------------*/ -static inline void -pllfeed(void) -{ - PLLFEED = 0xAA; - PLLFEED = 0x55; -} -/*---------------------------------------------------------------------------*/ -void init_clks1(void) -{ - // Disconnect PLL - PLLCON &= ~0x0002; - pllfeed(); - - // Disable PLL - PLLCON &= ~0x0001; - pllfeed(); - - SCS |= 0x20; // Enable main OSC - while( !(SCS & 0x40) ); // Wait until main OSC is usable - - /* select main OSC, 16MHz, as the PLL clock source */ - CLKSRCSEL = 0x0001; - - // Setting Multiplier and Divider values - PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz - pllfeed(); - - // Enabling the PLL */ - PLLCON = 0x0001; - pllfeed(); - - /* Set clock divider to 4 (value+1) */ - CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz - -#if USE_USB - USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ -#endif -} - -void init_clks2(void){ - // Wait for the PLL to lock to set frequency - while(!(PLLSTAT & BIT26)); - - // Connect the PLL as the clock source - PLLCON = 0x0003; - pllfeed(); - - /* Check connect bit status */ - while (!(PLLSTAT & BIT25)); -} - -void bl_init_clks(void) -{ - PCONP = PCRTC; // switch off everything except RTC - init_clks1(); - init_clks2(); - init_mam(); -} - - -// Michael, Do not change anything here! even not the redundant parts! void bl_init_ports(void) { SCS |= BIT0; // Set IO Ports to fast switching mode diff --git a/board/pttu/drivers/Jamfile b/board/pttu/drivers/Jamfile index 26a8b7c2a..31d6db1d6 100644 --- a/board/pttu/drivers/Jamfile +++ b/board/pttu/drivers/Jamfile @@ -1,4 +1,2 @@ SubDir TOP board pttu drivers ; -Module board_common : pttu-uart0.c ; - diff --git a/board/pttu/drivers/pttu-uart0.c b/board/pttu/drivers/pttu-uart0.c deleted file mode 100644 index d542f2260..000000000 --- a/board/pttu/drivers/pttu-uart0.c +++ /dev/null @@ -1,204 +0,0 @@ -/****************************************************************************** -Copyright 2008-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 -*******************************************************************************/ - -/* - * debug_uart.c: provides initial serial debug output - * - * Copyright (C) 2008, 2009 Kaspar Schleiser - * Heiko Will - */ -#include -#include -#include -#include "lpc23xx.h" -#include "VIC.h" - -/** - * @file - * @ingroup lpc2387 - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @version $Revision$ - * - * @note $Id$ - */ - -typedef struct toprint { - unsigned int len; - char content[]; -}toprint; - -#define QUEUESIZE 255 -static volatile toprint* queue[QUEUESIZE]; -static volatile unsigned char queue_head = 0; -static volatile unsigned char queue_tail = 0; -static volatile unsigned char queue_items = 0; - -static volatile unsigned int actual_pos = 0; -static volatile unsigned int running = 0; -static volatile unsigned int fifo = 0; - -static volatile toprint* actual = NULL; -void (*uart0_callback)(int); - -static inline void enqueue(void) { - queue_items++; - queue_tail++; -} - -static inline void dequeue(void) { - actual = (queue[queue_head]); - queue_items--; - queue_head++; -} - -static void push_queue(void) { - running = 1; -start: - if (!actual) { - if (queue_items) { - dequeue(); - } else { - running = 0; - if (!fifo) - while(!(U0LSR & BIT6)){}; - return; - } - } - while ((actual_pos < actual->len) && (fifo++ < 16)){ - U0THR = actual->content[actual_pos++]; - } - if (actual_pos == actual->len) { - free((void*)actual); - actual = NULL; - actual_pos = 0; - goto start; - } -} - -int uart_active(void){ - return (running || fifo); -} - -static inline void receive(int c) -{ - if (uart0_callback != NULL) uart0_callback(c); -} - -void stdio_flush(void) -{ - U0IER &= ~BIT1; // disable THRE interrupt - while(running) { - while(!(U0LSR & (BIT5|BIT6))){}; // transmit fifo - fifo=0; - push_queue(); // dequeue to fifo - } - U0IER |= BIT1; // enable THRE interrupt -} - -void UART0_IRQHandler(void) __attribute__((interrupt("IRQ"))); -void UART0_IRQHandler(void) -{ - int iir; - iir = U0IIR; - - switch(iir & UIIR_ID_MASK) { - case UIIR_THRE_INT: // Transmit Holding Register Empty - fifo=0; - push_queue(); - break; - - case UIIR_CTI_INT: // Character Timeout Indicator - case UIIR_RDA_INT: // Receive Data Available - do { - int c = U0RBR; - receive(c); - } while (U0LSR & ULSR_RDR); - break; - - default: - U0LSR; - U0RBR; - break; - } // switch - VICVectAddr = 0; // Acknowledge Interrupt -} - -static inline int uart0_puts(char *astring,int length) -{ - while (queue_items == (QUEUESIZE-1)) {} ; - U0IER = 0; - queue[queue_tail] = malloc(length+sizeof(unsigned int)); - queue[queue_tail]->len = length; - memcpy(&queue[queue_tail]->content,astring,length); - enqueue(); - if (!running) - push_queue(); - U0IER |= BIT0 | BIT1; // enable RX irq - - // alternative without queue: -// int i; -// for (i=0;iconfig->speed - /* - * Baudrate calculation - * BR = PCLK (9 MHz) / (16 x 256 x DLM + DLL) x (1/(DIVADDVAL/MULVAL)) - */ - U0FDR = 0x92; // DIVADDVAL = 0010 = 2, MULVAL = 1001 = 9 - U0DLM = 0x00; - U0DLL = 0x04; - - U0LCR = 0x03; // DLAB = 0 - U0FCR = 0x07; // Enable and reset TX and RX FIFO - - /* irq */ - install_irq(UART0_INT, UART0_IRQHandler, 6); - U0IER |= BIT0 | BIT1; // enable RX+TX irq - return 1; -} - From b9a52bd231f21dce00e175b9adde7331226c2a63 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 16:12:58 +0100 Subject: [PATCH 129/199] * msba2 bootloader code fix --- cpu/arm_common/bootloader.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cpu/arm_common/bootloader.c b/cpu/arm_common/bootloader.c index 568eebf13..f68a75e07 100644 --- a/cpu/arm_common/bootloader.c +++ b/cpu/arm_common/bootloader.c @@ -169,16 +169,17 @@ void bootloader(void) { /* board specific setup of clocks */ bl_init_clks(); + /* initialize bss and data */ bl_init_data(); + /* board specific setup of i/o pins */ bl_init_ports(); - /* short blinking of both of the LEDs on startup */ - bl_blink(); - /* board specific setup of UART */ + + /* UART setup */ bl_uart_init(); - printf("Board initialized.\n"); + puts("Board initialized."); } /** @} */ From 5ce95c155b15329fb744bdca3f889997ffd7425f Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 16:13:55 +0100 Subject: [PATCH 130/199] * build_gnuarm_naked.sh: builds arm toolchain without newlib --- tools/toolchains/build_gnuarm_naked.sh | 163 +++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100755 tools/toolchains/build_gnuarm_naked.sh diff --git a/tools/toolchains/build_gnuarm_naked.sh b/tools/toolchains/build_gnuarm_naked.sh new file mode 100755 index 000000000..86a6c252a --- /dev/null +++ b/tools/toolchains/build_gnuarm_naked.sh @@ -0,0 +1,163 @@ +#!/bin/bash + +# directory to install compiled binaries into +PREFIX=${HOME}/gnuarm-naked + +# directory to download source files and store intermediates +GNUARM_BUILDDIR=${GNUARM_BUILDDIR:-"/tmp/gnuarm-naked-${USER}"} + +#GCC_VER=4.5.1 +#GCC_MD5=dc8959e31b01a65ce10d269614815054 +GCC_VER=4.3.4 +GCC_MD5=575b3220bb8e7060939c429fc8608d22 + +BINUTILS_VER=2.20.1 +BINUTILS_MD5=9cdfb9d6ec0578c166d3beae5e15c4e5 + +NEWLIB_VER=1.18.0 +NEWLIB_MD5=3dae127d4aa659d72f8ea8c0ff2a7a20 + +GDB_VER=7.2 +GDB_MD5=64260e6c56979ee750a01055f16091a5 + +#uncomment to support multi-threaded compile +MAKE_THREADS=-j4 + +DOWNLOADER=wget +DOWNLOADER_OPTS="-nv -c" + +# +# Build targets +# +FILES=. + +build_binutils() { + echo "Building binutils..." + if [ ! -e .binutils_extracted ] ; then + tar -xjf ${FILES}/binutils-${BINUTILS_VER}.tar.bz2 + touch .binutils_extracted + fi + rm -rf binutils-build && mkdir -p binutils-build && cd binutils-build && + ../binutils-${BINUTILS_VER}/configure --target=arm-elf --prefix=${PREFIX} --enable-interwork --enable-multilibi --with-float=soft --with-fpu=vfp && + make ${MAKE_THREADS} all CFLAGS=-Wformat=0 && + make install && + cd ${GNUARM_BUILDDIR} +} + +build_gcc() { + echo "Building gcc..." + if [ ! -e .gcc_extracted ] ; then + tar -xjf ${FILES}/gcc-core-${GCC_VER}.tar.bz2 && + touch .gcc_extracted + fi + rm -rf gcc-build && mkdir -p gcc-build && cd gcc-build && + ../gcc-${GCC_VER}/configure --target=arm-elf --prefix=${PREFIX} --enable-interwork --enable-multilib --enable-languages="c" --enable-lto --disable-libssp --disable-hardfloat --with-float=soft --with-fpu=vfp --without-headers && + + make ${MAKE_THREADS} all && + make install && + + cd ${GNUARM_BUILDDIR} +} + +extract_newlib() { + if [ ! -e .newlib_extracted ] ; then + echo -n "Extracting newlib..." + tar -xzf ${FILES}/newlib-${NEWLIB_VER}.tar.gz && + touch .newlib_extracted && + echo " Done." + fi +} + +build_newlib() { + cd ${GNUARM_BUILDDIR} && + + if [ ! -e .newlib_extracted ] ; then + extract_newlib + fi + + rm -rf newlib-build && mkdir -p newlib-build && cd newlib-build && + ../newlib-${NEWLIB_VER}/configure --target=arm-elf --prefix=${PREFIX} --enable-interwork --enable-multilib --disable-newlib-supplied-syscalls --enable-newlib-reent-small --enable-newlib-io-long-long --enable-newlib-io-float --with-float=soft --with-fpu=vfp && + #--enable-newlib-supplied-syscalls && + # options to try: --enable-newlib-reent-small + make ${MAKE_THREADS} TARGET_CFLAGS=-DREENTRANT_SYSCALLS_PROVIDED all && + make install && + + # generate zip-file to provide binary download + cd ${PREFIX}/arm-elf && + + # + # package compiled newlib for windows users. any new version must be uploaded to the + # webserver. see manual arm/toolchain/windows for paths and documentation. + # + zip -ru newlib-${NEWLIB_VER}.zip include sys-include lib/*.a lib/thumb/*.a + + cd ${GNUARM_BUILDDIR} +} + +build_gdb() { + echo "Building gdb..." + if [ ! -e .gdb_extracted ] ; then + tar -xjf ${FILES}/gdb-${GDB_VER}.tar.bz2 && + touch .gdb_extracted + fi + rm -rf gdb-build && mkdir -p gdb-build && cd gdb-build && + ../gdb-${GDB_VER}/configure --target=arm-elf --prefix=${PREFIX} --enable-interwork --enable-multilib && + + make ${MAKE_THREADS} all CFLAGS=-D_FORTIFY_SOURCE=0 && + make install && + + cd ${GNUARM_BUILDDIR} +} + +clean() { + echo "Cleaning up..." + rm -rf .gdb_extracted .newlib_extracted .gcc_extracted .binutils_extracted + rm -rf binutils-build gcc-build newlib-build gdb-build +} + +export PATH=$PATH:${PREFIX}/bin + +download() { + download_file http://ftp.gnu.org/gnu/binutils binutils-${BINUTILS_VER}.tar.bz2 ${BINUTILS_MD5} && + download_file ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-${GCC_VER} gcc-core-${GCC_VER}.tar.bz2 ${GCC_MD5} && + download_file http://ftp.gnu.org/gnu/gdb gdb-${GDB_VER}.tar.bz2 ${GDB_MD5} +} + +download_file() { + echo "Downloading ${1}/${2}..." + ${DOWNLOADER} ${DOWNLOADER_OPTS} $1/$2 + + echo -n "Checking MD5 of " + echo "${3} ${2}" | md5sum -c - +} + +build_all() { + echo "Starting in ${GNUARM_BUILDDIR}. Installing to ${PREFIX}." + download && + build_binutils && + build_gcc && + build_gdb && + + echo "Build complete." +} + +usage() { + echo "usage: ${0} build_[binutils|gcc|newlib|gdb|all]" + echo "example: ./build_gnuarm build_all" + echo "" + echo "Builds a GNU ARM toolchain. installs to HOME/gnuarm, uses /tmp/gnuarm-USER as temp." + echo "Edit to change these directories." + echo "Run like \"MAKE_THREADS=-j4 ${0} build_all\" to speed up on multicore systems." +} + +if [ -z "${1}" ]; then + usage + exit 1 +fi + +mkdir -p ${GNUARM_BUILDDIR} + +cd ${GNUARM_BUILDDIR} + +$* + From 86a70393b424da8f45877fedf2878997c722fd2a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 17:15:00 +0100 Subject: [PATCH 131/199] * misc merge fixes --- board/msba2-common/Jamfile | 1 + board/msba2-common/board_common_init.c | 35 -------------------------- board/msba2-common/drivers/Jamfile | 3 ++- board/msba2/Jamfile | 2 -- drivers/cc110x_ng/Jamfile | 2 +- 5 files changed, 4 insertions(+), 39 deletions(-) diff --git a/board/msba2-common/Jamfile b/board/msba2-common/Jamfile index 8b3d8febc..ed2adc564 100644 --- a/board/msba2-common/Jamfile +++ b/board/msba2-common/Jamfile @@ -1,6 +1,7 @@ SubDir TOP board msba2-common ; Module board_common : board_common_init.c ; +Module config : config.c ; SubInclude TOP board msba2-common drivers ; diff --git a/board/msba2-common/board_common_init.c b/board/msba2-common/board_common_init.c index 0823a71bc..8d7c35962 100644 --- a/board/msba2-common/board_common_init.c +++ b/board/msba2-common/board_common_init.c @@ -51,12 +51,6 @@ and the mailinglist (subscription via web site) #define PCRTC BIT9 #define CL_CPU_DIV 4 -config_t sysconfig = { - 0, ///< default ID - 0, ///< default radio address - 0, ///< default radio channel -}; - /*---------------------------------------------------------------------------*/ /** * @brief Enabling MAM and setting number of clocks used for Flash memory fetch @@ -129,32 +123,3 @@ void bl_init_clks(void) init_mam(); } -void loop_delay(void) { - volatile uint16_t i, j; - for (i = 1; i < 30; i++) { - for (j = 1; j != 0; j++) { - asm volatile (" nop "); - } - } -} - -/*void bl_blink(void) { - LED_RED_ON; - LED_GREEN_ON; - - loop_delay(); - - LED_RED_OFF; - LED_GREEN_OFF; -}*/ - -// void bl_config_init(void) { -// extern char configmem[]; -// if (*((uint16_t*) configmem) == CONFIG_KEY) { -// memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); -// LED_GREEN_TOGGLE; -// } -// else { -// config_save(); -// } -// } diff --git a/board/msba2-common/drivers/Jamfile b/board/msba2-common/drivers/Jamfile index 963798216..c0f4138ab 100644 --- a/board/msba2-common/drivers/Jamfile +++ b/board/msba2-common/drivers/Jamfile @@ -1,5 +1,6 @@ SubDir TOP board msba2-common drivers ; -Module board_cc1100 : msba2-cc1100.c ; +Module board_cc1100 : msba2-cc1100.c : cc110x_spi gpioint ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; Module board_uart : msba2-uart0.c : chardev_thread ringbuffer ; + diff --git a/board/msba2/Jamfile b/board/msba2/Jamfile index 553522ba6..6e74471b6 100644 --- a/board/msba2/Jamfile +++ b/board/msba2/Jamfile @@ -30,7 +30,5 @@ SubDir TOP board $(BOARD) ; Module board : board_init.c : board_common board_uart ; UseModule board ; -Module config : config.c ; - SubInclude TOP board $(BOARD)-common ; SubInclude TOP cpu $(CPU) ; diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index f3c0bc934..c6497672f 100755 --- a/drivers/cc110x_ng/Jamfile +++ b/drivers/cc110x_ng/Jamfile @@ -29,6 +29,6 @@ SubDir TOP drivers cc110x_ng ; HDRS += $(TOP)/drivers/cc110x_ng ; -Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : hwtimer board_cc1100 ; +Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : hwtimer board_cc1100 config ; Module cc110x_spi : cc1100_spi.c ; Module cc110x_cc430 : cc1100_cc430.c ; From 57eb9ba8d224fddd4125436638136a994e787394 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 6 Dec 2010 17:17:19 +0100 Subject: [PATCH 132/199] [board/msba2-common] * added string.h include --- board/msba2-common/config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/board/msba2-common/config.c b/board/msba2-common/config.c index 1910f0b7f..8eff7e9db 100644 --- a/board/msba2-common/config.c +++ b/board/msba2-common/config.c @@ -1,4 +1,5 @@ #include +#include #include #include From 88ccc555dcc09f23fd2601500e9c202b1f918f06 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 17:32:27 +0100 Subject: [PATCH 133/199] * moved config to sys, split away board specifics --- board/msba2-common/Jamfile | 2 +- board/msba2-common/{config.c => board_config.c} | 0 core/kernel_init.c | 8 -------- sys/Jamfile | 1 + sys/config.c | 7 +++++++ 5 files changed, 9 insertions(+), 9 deletions(-) rename board/msba2-common/{config.c => board_config.c} (100%) create mode 100644 sys/config.c diff --git a/board/msba2-common/Jamfile b/board/msba2-common/Jamfile index ed2adc564..ff9a8ccd4 100644 --- a/board/msba2-common/Jamfile +++ b/board/msba2-common/Jamfile @@ -1,7 +1,7 @@ SubDir TOP board msba2-common ; Module board_common : board_common_init.c ; -Module config : config.c ; +Module board_config : board_config.c ; SubInclude TOP board msba2-common drivers ; diff --git a/board/msba2-common/config.c b/board/msba2-common/board_config.c similarity index 100% rename from board/msba2-common/config.c rename to board/msba2-common/board_config.c diff --git a/core/kernel_init.c b/core/kernel_init.c index 30be1e68d..fc9abc751 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -25,8 +25,6 @@ #include #include #include -#include -#include #ifdef MODULE_AUTO_INIT #include @@ -42,12 +40,6 @@ volatile int lpm_prevent_sleep = 0; extern void main(void); extern void cpu_switch_context_exit(void); -config_t sysconfig = { - 0, ///< default ID - 0, ///< default radio address - 0, ///< default radio channel -}; - static void idle_thread(void) { while(1) { if (lpm_prevent_sleep) { diff --git a/sys/Jamfile b/sys/Jamfile index 740a02227..6de621983 100644 --- a/sys/Jamfile +++ b/sys/Jamfile @@ -31,6 +31,7 @@ Module timex : timex.c ; Module vtimer : vtimer.c : hwtimer timex ; Module swtimer : swtimer.c : hwtimer ; Module posix_io : posix_io.c ; +Module config : config.c : board_config ; Module auto_init : auto_init.c ; diff --git a/sys/config.c b/sys/config.c new file mode 100644 index 000000000..d63e14e5e --- /dev/null +++ b/sys/config.c @@ -0,0 +1,7 @@ +#include + +config_t sysconfig = { + 0, ///< default ID + 0, ///< default radio address + 0, ///< default radio channel +}; From 8304a8ae7baee307a0715422bc22b7ef90f200bf Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 8 Dec 2010 12:16:49 +0100 Subject: [PATCH 134/199] [board/msb-430-common board/eZ430-Chronos cpu/msp430*] * reorganized msp430 based cpu folders --- board/eZ430-Chronos/Jamrules.eZ430-Chronos | 2 +- board/eZ430-Chronos/board_init.c | 72 ++++++++++++++++++ board/msb-430-common/Jamrules.msb-430-common | 2 +- board/msb-430h/Jamfile | 1 - cpu/cc430/Jamfile | 32 ++++++++ cpu/cc430/Jamrules.cc430 | 1 + cpu/cc430/hwtimer_cc430.c | 73 +++++++++++++++++++ cpu/{msp430 => msp430-common}/Jamfile | 4 +- .../Jamrules.msp430-common} | 2 +- cpu/{msp430 => msp430-common}/atomic.c | 0 cpu/{msp430 => msp430-common}/cpu.c | 0 cpu/{msp430 => msp430-common}/flashrom.c | 0 cpu/{msp430 => msp430-common}/hwtimer_cpu.c | 56 +------------- .../include/cpu-conf.h | 0 cpu/{msp430 => msp430-common}/include/cpu.h | 1 + .../include/errno-base.h | 0 cpu/{msp430 => msp430-common}/include/errno.h | 0 .../include/hwtimer_cpu.h | 4 +- .../include/malloc.h | 0 .../include/msp430.h | 0 cpu/{msp430 => msp430-common}/irq.c | 0 cpu/{msp430 => msp430-common}/msp430-main.c | 0 cpu/{msp430 => msp430-common}/startup.c | 0 cpu/msp430x16x/Jamfile | 32 ++++++++ cpu/msp430x16x/Jamrules.msp430x16x | 1 + cpu/msp430x16x/hwtimer_msp430.c | 55 ++++++++++++++ 26 files changed, 277 insertions(+), 61 deletions(-) create mode 100644 cpu/cc430/Jamfile create mode 100644 cpu/cc430/Jamrules.cc430 create mode 100644 cpu/cc430/hwtimer_cc430.c rename cpu/{msp430 => msp430-common}/Jamfile (95%) rename cpu/{msp430/Jamrules.msp430 => msp430-common/Jamrules.msp430-common} (82%) rename cpu/{msp430 => msp430-common}/atomic.c (100%) rename cpu/{msp430 => msp430-common}/cpu.c (100%) rename cpu/{msp430 => msp430-common}/flashrom.c (100%) rename cpu/{msp430 => msp430-common}/hwtimer_cpu.c (72%) rename cpu/{msp430 => msp430-common}/include/cpu-conf.h (100%) rename cpu/{msp430 => msp430-common}/include/cpu.h (99%) rename cpu/{msp430 => msp430-common}/include/errno-base.h (100%) rename cpu/{msp430 => msp430-common}/include/errno.h (100%) rename cpu/{msp430 => msp430-common}/include/hwtimer_cpu.h (98%) rename cpu/{msp430 => msp430-common}/include/malloc.h (100%) rename cpu/{msp430 => msp430-common}/include/msp430.h (100%) rename cpu/{msp430 => msp430-common}/irq.c (100%) rename cpu/{msp430 => msp430-common}/msp430-main.c (100%) rename cpu/{msp430 => msp430-common}/startup.c (100%) create mode 100644 cpu/msp430x16x/Jamfile create mode 100644 cpu/msp430x16x/Jamrules.msp430x16x create mode 100644 cpu/msp430x16x/hwtimer_msp430.c diff --git a/board/eZ430-Chronos/Jamrules.eZ430-Chronos b/board/eZ430-Chronos/Jamrules.eZ430-Chronos index eef3a0301..74e57f092 100644 --- a/board/eZ430-Chronos/Jamrules.eZ430-Chronos +++ b/board/eZ430-Chronos/Jamrules.eZ430-Chronos @@ -4,7 +4,7 @@ # $Id$ BOARD = eZ430-Chronos ; -CPU = msp430 ; +CPU = cc430 ; MCU = cc430x6137 ; FLASHER ?= mspdebug ; diff --git a/board/eZ430-Chronos/board_init.c b/board/eZ430-Chronos/board_init.c index aa52e65af..74799abac 100644 --- a/board/eZ430-Chronos/board_init.c +++ b/board/eZ430-Chronos/board_init.c @@ -1,2 +1,74 @@ +#include +#include +#include +#include + +void cc430_cpu_init(void) { + volatile uint16_t i; + volatile unsigned char *ptr; + + /* disable watchdog */ + WDTCTL = WDTPW + WDTHOLD; + + // --------------------------------------------------------------------- + // Enable 32kHz ACLK + P5SEL |= 0x03; // Select XIN, XOUT on P5.0 and P5.1 + UCSCTL6 &= ~XT1OFF; // XT1 On, Highest drive strength + UCSCTL6 |= XCAP_3; // Internal load cap + + UCSCTL3 = SELA__XT1CLK; // Select XT1 as FLL reference + UCSCTL4 = SELA__XT1CLK | SELS__DCOCLKDIV | SELM__DCOCLKDIV; + + // --------------------------------------------------------------------- + // Configure CPU clock for 12MHz + _BIS_SR(SCG0); // Disable the FLL control loop + UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx + UCSCTL1 = DCORSEL_5; // Select suitable range + UCSCTL2 = FLLD_1 + 0x16E; // Set DCO Multiplier + _BIC_SR(SCG0); // Enable the FLL control loop + + // Worst-case settling time for the DCO when the DCO range bits have been + // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx + // UG for optimization. + // 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle + for (i = 0xFF; i > 0; i--); // Time for flag to set + + // Loop until XT1 & DCO stabilizes, use do-while to insure that + // body is executed at least once + do + { + UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG); + SFRIFG1 &= ~OFIFG; // Clear fault flags + } while ((SFRIFG1 & OFIFG)); + + // Disable all interrupts + __disable_interrupt(); + // Get write-access to port mapping registers: + PMAPPWD = 0x02D52; + // Allow reconfiguration during runtime: + PMAPCTL = PMAPRECFG; + + // P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output) + ptr = &P2MAP0; + *(ptr+7) = PM_TA1CCR0A; + P2OUT &= ~BIT7; + P2DIR |= BIT7; + + // P1.5 = SPI MISO input + ptr = &P1MAP0; + *(ptr+5) = PM_UCA0SOMI; + // P1.6 = SPI MOSI output + *(ptr+6) = PM_UCA0SIMO; + // P1.7 = SPI CLK output + *(ptr+7) = PM_UCA0CLK; + + // Disable write-access to port mapping registers: + PMAPPWD = 0; + // Re-enable all interrupts + enableIRQ(); + +} + void board_init() { + cc430_cpu_init(); } diff --git a/board/msb-430-common/Jamrules.msb-430-common b/board/msb-430-common/Jamrules.msb-430-common index 9c51cd21d..7eee8b088 100644 --- a/board/msb-430-common/Jamrules.msb-430-common +++ b/board/msb-430-common/Jamrules.msb-430-common @@ -25,7 +25,7 @@ # ****************************************************************************** # $Id$ -CPU = msp430 ; +CPU = msp430x16x ; MCU = msp430x1612 ; FLASH_PORT ?= "$(PORT)" ; diff --git a/board/msb-430h/Jamfile b/board/msb-430h/Jamfile index 79e6f920c..15f7ba97f 100644 --- a/board/msb-430h/Jamfile +++ b/board/msb-430h/Jamfile @@ -31,4 +31,3 @@ Module board_cc1100 : driver_cc1100.c ; SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; - diff --git a/cpu/cc430/Jamfile b/cpu/cc430/Jamfile new file mode 100644 index 000000000..416073e25 --- /dev/null +++ b/cpu/cc430/Jamfile @@ -0,0 +1,32 @@ +# ****************************************************************************** +# 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 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 cpu cc430 ; + +Module hwtimer_cpu : hwtimer_cc430.c : hwtimer_msp430 ; + +SubInclude TOP cpu msp430-common ; diff --git a/cpu/cc430/Jamrules.cc430 b/cpu/cc430/Jamrules.cc430 new file mode 100644 index 000000000..c66536fc9 --- /dev/null +++ b/cpu/cc430/Jamrules.cc430 @@ -0,0 +1 @@ +include [ FPath $(TOP) cpu msp430-common Jamrules.msp430-common ] ; diff --git a/cpu/cc430/hwtimer_cc430.c b/cpu/cc430/hwtimer_cc430.c new file mode 100644 index 000000000..b83de4da9 --- /dev/null +++ b/cpu/cc430/hwtimer_cc430.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include + +static uint32_t ticks = 0; + +extern void (*int_handler)(int); +extern void TA0_unset(short timer); + +void timerA_init() +{ + ticks = 0; // Set tick counter value to 0 + TA0CTL = TASSEL_1 + TACLR; // Clear the timer counter, set ACLK + TA0CTL &= ~TAIE; // Clear the IFG + +/* volatile unsigned int *ccr = &TA0CCR0; + volatile unsigned int *ctl = &TA0CCTL0; + + for (int i = 0; i < ARCH_MAXTIMERS; i++) { + *ccr = 0; + *ctl &= ~(CCIFG); + *ctl &= ~(CCIE); + } + */ + + TA0CCR0 = 0; + TA0CTL |= MC_2; +} + +interrupt(TIMER0_A0_VECTOR) __attribute__ ((naked)) timer0_a0_isr(void) { + __enter_isr(); + + TA0_unset(0); + int_handler(0); + __exit_isr(); +} + +interrupt(TIMER0_A1_VECTOR) __attribute__ ((naked)) timer0_a1_5_isr(void) { + __enter_isr(); + + short taiv = TA0IV; + short timer; + + switch(taiv) { + case TAIFG: + timer = (taiv/2); + TA0_unset(timer); + int_handler(timer); + break; + + // Timer0_A3 Configurable periodic IRQ (used by button_repeat and buzzer) + case 0x06: // Disable IE + TA0CCTL3 &= ~CCIE; + // Reset IRQ flag + TA0CCTL3 &= ~CCIFG; + // Enable timer interrupt + TA0CCTL3 |= CCIE; + // Call function handler + // TODO + break; + + // Timer0_A4 One-time delay + case 0x08: // Disable IE + TA0CCTL4 &= ~CCIE; + // Reset IRQ flag + TA0CCTL4 &= ~CCIFG; + break; + } + + __exit_isr(); +} diff --git a/cpu/msp430/Jamfile b/cpu/msp430-common/Jamfile similarity index 95% rename from cpu/msp430/Jamfile rename to cpu/msp430-common/Jamfile index bec5471cd..540398c72 100644 --- a/cpu/msp430/Jamfile +++ b/cpu/msp430-common/Jamfile @@ -25,10 +25,10 @@ # ****************************************************************************** # $Id$ -SubDir TOP cpu msp430 ; +SubDir TOP cpu msp430-common ; Module cpu : msp430-main.c cpu.c atomic.c irq.c flashrom.c ; -Module hwtimer_cpu : hwtimer_cpu.c ; +Module hwtimer_msp430 : hwtimer_cpu.c ; UseModule cpu ; UseModule oneway_malloc ; diff --git a/cpu/msp430/Jamrules.msp430 b/cpu/msp430-common/Jamrules.msp430-common similarity index 82% rename from cpu/msp430/Jamrules.msp430 rename to cpu/msp430-common/Jamrules.msp430-common index 74d65de84..aaba8a424 100644 --- a/cpu/msp430/Jamrules.msp430 +++ b/cpu/msp430-common/Jamrules.msp430-common @@ -5,7 +5,7 @@ echo "Building for board $(BOARD)." ; echo "Building for MCU $(MCU)." ; -HDRS += $(TOP)/cpu/$(CPU)/include $(TOP)/board/$(BOARD)/drivers $(TOP)/board/$(BOARD)/include $(TOP)/include $(TOP)/core/include ; +HDRS += $(TOP)/cpu/msp430-common/include $(TOP)/cpu/$(CPU)/include $(TOP)/board/$(BOARD)/drivers $(TOP)/board/$(BOARD)/include $(TOP)/include $(TOP)/core/include ; TOOLCHAIN = msp430- ; CC = msp430-gcc ; diff --git a/cpu/msp430/atomic.c b/cpu/msp430-common/atomic.c similarity index 100% rename from cpu/msp430/atomic.c rename to cpu/msp430-common/atomic.c diff --git a/cpu/msp430/cpu.c b/cpu/msp430-common/cpu.c similarity index 100% rename from cpu/msp430/cpu.c rename to cpu/msp430-common/cpu.c diff --git a/cpu/msp430/flashrom.c b/cpu/msp430-common/flashrom.c similarity index 100% rename from cpu/msp430/flashrom.c rename to cpu/msp430-common/flashrom.c diff --git a/cpu/msp430/hwtimer_cpu.c b/cpu/msp430-common/hwtimer_cpu.c similarity index 72% rename from cpu/msp430/hwtimer_cpu.c rename to cpu/msp430-common/hwtimer_cpu.c index e25fd799e..3d193c28e 100644 --- a/cpu/msp430/hwtimer_cpu.c +++ b/cpu/msp430-common/hwtimer_cpu.c @@ -33,29 +33,9 @@ and the mailinglist (subscription via web site) #include "debug.h" -static uint32_t ticks = 0; - -static void (*int_handler)(int); - -static void timerA_init() -{ - ticks = 0; // Set tick counter value to 0 - TA0CTL = TASSEL_1 + TACLR; // Clear the timer counter, set SMCLK - TA0CTL &= ~TAIFG; // Clear the IFG - TA0CTL &= ~TAIE; // Clear the IFG - - volatile unsigned int *ccr = &TA0CCR0; - volatile unsigned int *ctl = &TA0CCTL0; - - for (int i = 0; i < ARCH_MAXTIMERS; i++) { - *ccr = 0; - *ctl &= ~(CCIFG); - *ctl &= ~(CCIE); - } - - TA0CTL |= MC_2; -} +void (*int_handler)(int); +extern void timerA_init(void); static void TA0_disable_interrupt(short timer) { volatile unsigned int *ptr = &TA0CCTL0 + (timer); @@ -80,7 +60,7 @@ static void TA0_set(unsigned long value, short timer) { TA0_enable_interrupt(timer); } -static void TA0_unset(short timer) { +void TA0_unset(short timer) { volatile unsigned int *ptr = &TA0CCR0 + (timer); TA0_disable_interrupt(timer); *ptr = 0; @@ -119,33 +99,3 @@ void hwtimer_arch_set_absolute(unsigned long value, short timer) { void hwtimer_arch_unset(short timer) { TA0_unset(timer); } - -interrupt(TIMERA0_VECTOR) __attribute__ ((naked)) timer_isr_ccr0(void) -{ - __enter_isr(); - - TA0_unset(0); - int_handler(0); - - __exit_isr(); -} - -interrupt(TIMERA1_VECTOR) __attribute__ ((naked)) timer_isr(void) -{ - __enter_isr(); - - short taiv = TA0IV; - - if (taiv & TAIFG) { - puts("msp430/hwtimer_cpu TAIFG set!"); - // TA0CTL &= ~TAIFG; - // ticks += 0xFFFF; - } else { - - short timer = (taiv/2); - TA0_unset(timer); - int_handler(timer); - } - - __exit_isr(); -} diff --git a/cpu/msp430/include/cpu-conf.h b/cpu/msp430-common/include/cpu-conf.h similarity index 100% rename from cpu/msp430/include/cpu-conf.h rename to cpu/msp430-common/include/cpu-conf.h diff --git a/cpu/msp430/include/cpu.h b/cpu/msp430-common/include/cpu.h similarity index 99% rename from cpu/msp430/include/cpu.h rename to cpu/msp430-common/include/cpu.h index 830e5c9e7..e924cdff2 100644 --- a/cpu/msp430/include/cpu.h +++ b/cpu/msp430-common/include/cpu.h @@ -44,6 +44,7 @@ and the mailinglist (subscription via web site) #define WORDSIZE 16 +/* not used(?) */ #define F_CPU 10000000 extern volatile int __inISR; diff --git a/cpu/msp430/include/errno-base.h b/cpu/msp430-common/include/errno-base.h similarity index 100% rename from cpu/msp430/include/errno-base.h rename to cpu/msp430-common/include/errno-base.h diff --git a/cpu/msp430/include/errno.h b/cpu/msp430-common/include/errno.h similarity index 100% rename from cpu/msp430/include/errno.h rename to cpu/msp430-common/include/errno.h diff --git a/cpu/msp430/include/hwtimer_cpu.h b/cpu/msp430-common/include/hwtimer_cpu.h similarity index 98% rename from cpu/msp430/include/hwtimer_cpu.h rename to cpu/msp430-common/include/hwtimer_cpu.h index 1d014640c..e10ca6019 100644 --- a/cpu/msp430/include/hwtimer_cpu.h +++ b/cpu/msp430-common/include/hwtimer_cpu.h @@ -36,10 +36,10 @@ and the mailinglist (subscription via web site) #ifdef __MSP430_HAS_TA3__ #define ARCH_MAXTIMERS 3 #endif -/*#ifdef __MSP430_HAS_TA5__ +#ifdef __MSP430_HAS_T0A5__ #define ARCH_MAXTIMERS 5 #endif -*/ + #ifndef ARCH_MAXTIMERS #warning "ARCH_MAXTIMERS UNSET!" diff --git a/cpu/msp430/include/malloc.h b/cpu/msp430-common/include/malloc.h similarity index 100% rename from cpu/msp430/include/malloc.h rename to cpu/msp430-common/include/malloc.h diff --git a/cpu/msp430/include/msp430.h b/cpu/msp430-common/include/msp430.h similarity index 100% rename from cpu/msp430/include/msp430.h rename to cpu/msp430-common/include/msp430.h diff --git a/cpu/msp430/irq.c b/cpu/msp430-common/irq.c similarity index 100% rename from cpu/msp430/irq.c rename to cpu/msp430-common/irq.c diff --git a/cpu/msp430/msp430-main.c b/cpu/msp430-common/msp430-main.c similarity index 100% rename from cpu/msp430/msp430-main.c rename to cpu/msp430-common/msp430-main.c diff --git a/cpu/msp430/startup.c b/cpu/msp430-common/startup.c similarity index 100% rename from cpu/msp430/startup.c rename to cpu/msp430-common/startup.c diff --git a/cpu/msp430x16x/Jamfile b/cpu/msp430x16x/Jamfile new file mode 100644 index 000000000..a11017067 --- /dev/null +++ b/cpu/msp430x16x/Jamfile @@ -0,0 +1,32 @@ +# ****************************************************************************** +# 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 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 cpu msp430x16x ; + +Module hwtimer_cpu : hwtimer_msp430.c : hwtimer_msp430 ; + +SubInclude TOP cpu msp430-common ; diff --git a/cpu/msp430x16x/Jamrules.msp430x16x b/cpu/msp430x16x/Jamrules.msp430x16x new file mode 100644 index 000000000..c66536fc9 --- /dev/null +++ b/cpu/msp430x16x/Jamrules.msp430x16x @@ -0,0 +1 @@ +include [ FPath $(TOP) cpu msp430-common Jamrules.msp430-common ] ; diff --git a/cpu/msp430x16x/hwtimer_msp430.c b/cpu/msp430x16x/hwtimer_msp430.c new file mode 100644 index 000000000..2a39a7ec8 --- /dev/null +++ b/cpu/msp430x16x/hwtimer_msp430.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include + +static uint32_t ticks = 0; + +extern void (*int_handler)(int); +extern void TA0_unset(short timer); + +void timerA_init() +{ + ticks = 0; // Set tick counter value to 0 + TA0CTL = TASSEL_1 + TACLR; // Clear the timer counter, set ACLK + TA0CTL &= ~TAIFG; // Clear the IFG + TA0CTL &= ~TAIE; // Clear the IFG + volatile unsigned int *ccr = &TA0CCR0; + volatile unsigned int *ctl = &TA0CCTL0; + + for (int i = 0; i < ARCH_MAXTIMERS; i++) { + *ccr = 0; + *ctl &= ~(CCIFG); + *ctl &= ~(CCIE); + } + TA0CTL |= MC_2; +} + +interrupt(TIMERA0_VECTOR) __attribute__ ((naked)) timer_isr_ccr0(void) { + __enter_isr(); + + TA0_unset(0); + int_handler(0); + + __exit_isr(); +} + +interrupt(TIMERA1_VECTOR) __attribute__ ((naked)) timer_isr(void) { + __enter_isr(); + + short taiv = TA0IV; + + if (taiv & TAIFG) { + // puts("msp430/hwtimer_cpu TAIFG set!"); + // TA0CTL &= ~TAIFG; + // ticks += 0xFFFF; + } else { + + short timer = (taiv/2); + TA0_unset(timer); + int_handler(timer); + } + + __exit_isr(); +} From 8de4898694d2f3a4c60c0cf40715e5c3ed96994a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 8 Dec 2010 12:58:02 +0100 Subject: [PATCH 135/199] * renamed eZ430-Chronos board to 'chronos' --- board/{eZ430-Chronos => chronos}/Jamfile | 2 +- .../Jamrules.eZ430-Chronos => chronos/Jamrules.chronos} | 2 +- board/{eZ430-Chronos => chronos}/board_init.c | 0 board/{eZ430-Chronos => chronos}/debug_uart.c | 0 board/{eZ430-Chronos => chronos}/drivers/Jamfile | 2 +- board/{eZ430-Chronos => chronos}/drivers/cc430-cc1100.c | 0 board/{eZ430-Chronos => chronos}/drivers/display.c | 0 board/{eZ430-Chronos => chronos}/drivers/display.h | 0 board/{eZ430-Chronos => chronos}/drivers/display1.c | 0 board/{eZ430-Chronos => chronos}/include/board.h | 0 10 files changed, 3 insertions(+), 3 deletions(-) rename board/{eZ430-Chronos => chronos}/Jamfile (83%) rename board/{eZ430-Chronos/Jamrules.eZ430-Chronos => chronos/Jamrules.chronos} (93%) rename board/{eZ430-Chronos => chronos}/board_init.c (100%) rename board/{eZ430-Chronos => chronos}/debug_uart.c (100%) rename board/{eZ430-Chronos => chronos}/drivers/Jamfile (71%) rename board/{eZ430-Chronos => chronos}/drivers/cc430-cc1100.c (100%) rename board/{eZ430-Chronos => chronos}/drivers/display.c (100%) rename board/{eZ430-Chronos => chronos}/drivers/display.h (100%) rename board/{eZ430-Chronos => chronos}/drivers/display1.c (100%) rename board/{eZ430-Chronos => chronos}/include/board.h (100%) diff --git a/board/eZ430-Chronos/Jamfile b/board/chronos/Jamfile similarity index 83% rename from board/eZ430-Chronos/Jamfile rename to board/chronos/Jamfile index ea723c95a..bf3341d78 100644 --- a/board/eZ430-Chronos/Jamfile +++ b/board/chronos/Jamfile @@ -1,4 +1,4 @@ -SubDir TOP board eZ430-Chronos ; +SubDir TOP board chronos ; HDRS += $(TOP)/board/$(CPU)/include ; diff --git a/board/eZ430-Chronos/Jamrules.eZ430-Chronos b/board/chronos/Jamrules.chronos similarity index 93% rename from board/eZ430-Chronos/Jamrules.eZ430-Chronos rename to board/chronos/Jamrules.chronos index 74e57f092..4c975ae1f 100644 --- a/board/eZ430-Chronos/Jamrules.eZ430-Chronos +++ b/board/chronos/Jamrules.chronos @@ -3,7 +3,7 @@ # ****************************************************************************** # $Id$ -BOARD = eZ430-Chronos ; +BOARD = chronos ; CPU = cc430 ; MCU = cc430x6137 ; diff --git a/board/eZ430-Chronos/board_init.c b/board/chronos/board_init.c similarity index 100% rename from board/eZ430-Chronos/board_init.c rename to board/chronos/board_init.c diff --git a/board/eZ430-Chronos/debug_uart.c b/board/chronos/debug_uart.c similarity index 100% rename from board/eZ430-Chronos/debug_uart.c rename to board/chronos/debug_uart.c diff --git a/board/eZ430-Chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile similarity index 71% rename from board/eZ430-Chronos/drivers/Jamfile rename to board/chronos/drivers/Jamfile index 2ccbb030e..221ba2ffb 100644 --- a/board/eZ430-Chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -1,4 +1,4 @@ -SubDir TOP board eZ430-Chronos drivers ; +SubDir TOP board chronos drivers ; Module board_display : display.c display1.c ; Module board_cc1100 : cc430-cc1100.c : cc110x_cc430 ; diff --git a/board/eZ430-Chronos/drivers/cc430-cc1100.c b/board/chronos/drivers/cc430-cc1100.c similarity index 100% rename from board/eZ430-Chronos/drivers/cc430-cc1100.c rename to board/chronos/drivers/cc430-cc1100.c diff --git a/board/eZ430-Chronos/drivers/display.c b/board/chronos/drivers/display.c similarity index 100% rename from board/eZ430-Chronos/drivers/display.c rename to board/chronos/drivers/display.c diff --git a/board/eZ430-Chronos/drivers/display.h b/board/chronos/drivers/display.h similarity index 100% rename from board/eZ430-Chronos/drivers/display.h rename to board/chronos/drivers/display.h diff --git a/board/eZ430-Chronos/drivers/display1.c b/board/chronos/drivers/display1.c similarity index 100% rename from board/eZ430-Chronos/drivers/display1.c rename to board/chronos/drivers/display1.c diff --git a/board/eZ430-Chronos/include/board.h b/board/chronos/include/board.h similarity index 100% rename from board/eZ430-Chronos/include/board.h rename to board/chronos/include/board.h From c750108ca5fd314ea838936a9340c21d98bf3490 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 8 Dec 2010 18:18:06 +0100 Subject: [PATCH 136/199] [cpu/cc430 cpu/msp430-common] * fixed timera1 irq --- cpu/cc430/hwtimer_cc430.c | 18 ++++++++---------- cpu/msp430-common/Jamfile | 2 +- cpu/msp430-common/flashrom.c | 1 - 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cpu/cc430/hwtimer_cc430.c b/cpu/cc430/hwtimer_cc430.c index b83de4da9..b5843ca23 100644 --- a/cpu/cc430/hwtimer_cc430.c +++ b/cpu/cc430/hwtimer_cc430.c @@ -15,17 +15,15 @@ void timerA_init() TA0CTL = TASSEL_1 + TACLR; // Clear the timer counter, set ACLK TA0CTL &= ~TAIE; // Clear the IFG -/* volatile unsigned int *ccr = &TA0CCR0; + volatile unsigned int *ccr = &TA0CCR0; volatile unsigned int *ctl = &TA0CCTL0; for (int i = 0; i < ARCH_MAXTIMERS; i++) { - *ccr = 0; - *ctl &= ~(CCIFG); - *ctl &= ~(CCIE); + *(ccr+i) = 0; + *(ctl+i) &= ~(CCIFG); + *(ctl+i) &= ~(CCIE); } - */ - TA0CCR0 = 0; TA0CTL |= MC_2; } @@ -43,12 +41,12 @@ interrupt(TIMER0_A1_VECTOR) __attribute__ ((naked)) timer0_a1_5_isr(void) { short taiv = TA0IV; short timer; - switch(taiv) { - case TAIFG: + if (!(taiv & TAIFG)) { +// case TAIFG: timer = (taiv/2); TA0_unset(timer); int_handler(timer); - break; + /* break; // Timer0_A3 Configurable periodic IRQ (used by button_repeat and buzzer) case 0x06: // Disable IE @@ -66,7 +64,7 @@ interrupt(TIMER0_A1_VECTOR) __attribute__ ((naked)) timer0_a1_5_isr(void) { TA0CCTL4 &= ~CCIE; // Reset IRQ flag TA0CCTL4 &= ~CCIFG; - break; + break;*/ } __exit_isr(); diff --git a/cpu/msp430-common/Jamfile b/cpu/msp430-common/Jamfile index 540398c72..19e40bb30 100644 --- a/cpu/msp430-common/Jamfile +++ b/cpu/msp430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP cpu msp430-common ; -Module cpu : msp430-main.c cpu.c atomic.c irq.c flashrom.c ; +Module cpu : msp430-main.c cpu.c atomic.c irq.c ; Module hwtimer_msp430 : hwtimer_cpu.c ; UseModule cpu ; diff --git a/cpu/msp430-common/flashrom.c b/cpu/msp430-common/flashrom.c index 1c96e14b0..dff02c053 100644 --- a/cpu/msp430-common/flashrom.c +++ b/cpu/msp430-common/flashrom.c @@ -1,5 +1,4 @@ #include -#include #include #include From 830f17246cf81df91407379921ea634d6f31bffd Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 9 Dec 2010 13:24:24 +0100 Subject: [PATCH 137/199] [Chronos] * changed display driver interface from uint8_t* to char* * fixed hardware timer interrupt * ported cc1100 driver * added simple test application for radio [msb430] * fixex config and flashrom [cc110x_ng] * removed dependency from sysconfig --- board/chronos/drivers/cc430-cc1100.c | 31 ++++-- board/chronos/drivers/display.c | 18 ++- board/chronos/drivers/display.h | 4 +- board/msb-430-common/Jamfile | 2 +- .../{config.c => board_config.c} | 10 ++ board/msb-430h/Jamfile | 2 +- board/msb-430h/driver_cc1100.c | 3 +- cpu/cc430/hwtimer_cc430.c | 34 ++---- cpu/msp430-common/Jamfile | 2 +- cpu/msp430-common/flashrom.c | 2 + cpu/msp430-common/hwtimer_cpu.c | 5 +- cpu/msp430-common/include/cpu-conf.h | 4 +- drivers/cc110x_ng/Jamfile | 2 +- drivers/cc110x_ng/cc1100.c | 35 ++++-- projects/chronos_cc110x_ng/Jamfile | 5 + projects/chronos_cc110x_ng/main.c | 103 ++++++++++++++++++ projects/chronos_cc110x_ng/tests/hello-world | 13 +++ 17 files changed, 209 insertions(+), 66 deletions(-) rename board/msb-430-common/{config.c => board_config.c} (55%) create mode 100644 projects/chronos_cc110x_ng/Jamfile create mode 100644 projects/chronos_cc110x_ng/main.c create mode 100755 projects/chronos_cc110x_ng/tests/hello-world diff --git a/board/chronos/drivers/cc430-cc1100.c b/board/chronos/drivers/cc430-cc1100.c index 9ca689036..6c36e7e6d 100644 --- a/board/chronos/drivers/cc430-cc1100.c +++ b/board/chronos/drivers/cc430-cc1100.c @@ -2,13 +2,15 @@ #include #include +#include #include -#warning CC430_CC1100 NOT WORKING -/* TODO: defines... */ -#define CC1100_GDO0 (0) -#define CC1100_GDO1 (1) -#define CC1100_GDO2 (2) +#include +#include + +#define CC1100_GDO0 IOCFG0 +#define CC1100_GDO1 IOCFG1 +#define CC1100_GDO2 IOCFG2 int cc1100_get_gdo0(void) { return CC1100_GDO0; @@ -35,15 +37,23 @@ void cc1100_after_send(void) } void cc1100_gdo0_enable(void) { + RF1AIFG &= ~RF1AIV_RFIFG0; + RF1AIE |= RF1AIV_RFIFG0; } void cc1100_gdo0_disable(void) { + RF1AIE &= ~RF1AIV_RFIFG0; + RF1AIFG &= ~RF1AIV_RFIFG0; } void cc1100_gdo2_disable(void) { + RF1AIFG &= ~RF1AIV_RFIFG2; + RF1AIE &= ~RF1AIV_RFIFG2; } void cc1100_gdo2_enable(void) { + RF1AIE &= ~RF1AIV_RFIFG2; + RF1AIFG |= RF1AIV_RFIFG2; } void cc1100_init_interrupts(void) { @@ -51,16 +61,17 @@ void cc1100_init_interrupts(void) { restoreIRQ(state); /* Enable all interrupts */ } -interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ +interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ __enter_isr(); /* Check IFG */ - if (1 == 1) { + if (RF1AIFG & RF1AIV_RFIFG2) { + RF1AIFG &= ~RF1AIV_RFIFG2; cc1100_gdo2_irq(); } - else if (2 == 2) { + if (RF1AIFG & RF1AIV_RFIFG0) { + RF1AIFG &= ~RF1AIV_RFIFG0; + RF1AIE &= ~RF1AIV_RFIFG0; cc1100_gdo0_irq(); - } else { - puts("cc1100_isr(): unexpected IFG!"); } __exit_isr(); } diff --git a/board/chronos/drivers/display.c b/board/chronos/drivers/display.c index c0418f544..1473703e4 100644 --- a/board/chronos/drivers/display.c +++ b/board/chronos/drivers/display.c @@ -43,18 +43,15 @@ #include // driver -#include "cc430x613x.h" -#include "display.h" +#include +#include // ************************************************************************************************* // Prototypes section -void write_lcd_mem(uint8_t * lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); +void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); void clear_line(uint8_t line); void display_symbol(uint8_t symbol, uint8_t mode); -void display_char(uint8_t segment, uint8_t chr, uint8_t mode); -void display_chars(uint8_t segments, uint8_t * str, uint8_t mode); - // ************************************************************************************************* // Defines section @@ -285,12 +282,12 @@ uint8_t * itoa(uint32_t n, uint8_t digits, uint8_t blanks) // ************************************************************************************************* void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) { - uint8_t * str; + uint8_t* str; str = itoa(value, digits, blanks); // Display string in blink mode - display_chars(segments, str, disp_mode); + display_chars(segments, (char*) str, disp_mode); } @@ -332,7 +329,7 @@ void display_symbol(uint8_t symbol, uint8_t mode) // uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK // @return none // ************************************************************************************************* -void display_char(uint8_t segment, uint8_t chr, uint8_t mode) +void display_char(uint8_t segment, char chr, uint8_t mode) { uint8_t * lcdmem; // Pointer to LCD memory uint8_t bitmask; // Bitmask for character @@ -393,8 +390,7 @@ void display_char(uint8_t segment, uint8_t chr, uint8_t mode) // uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK // @return none // ************************************************************************************************* -void display_chars(uint8_t segments, uint8_t * str, uint8_t mode) -{ +void display_chars(uint8_t segments, char *str, uint8_t mode) { uint8_t i; uint8_t length = 0; // Write length uint8_t char_start = 0; // Starting point for consecutive write diff --git a/board/chronos/drivers/display.h b/board/chronos/drivers/display.h index 993814ce7..a4fbde92b 100644 --- a/board/chronos/drivers/display.h +++ b/board/chronos/drivers/display.h @@ -337,8 +337,8 @@ void clear_blink_mem(void); void set_blink_rate(uint8_t bits); // Character / symbol draw functions -void display_char(uint8_t segment, uint8_t chr, uint8_t mode); -void display_chars(uint8_t segments, uint8_t * str, uint8_t mode); +void display_char(uint8_t segment, char chr, uint8_t mode); +void display_chars(uint8_t segments, char* str, uint8_t mode); void display_symbol(uint8_t symbol, uint8_t mode); // Time display function diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile index 29cd73df0..17bf86c9b 100644 --- a/board/msb-430-common/Jamfile +++ b/board/msb-430-common/Jamfile @@ -28,7 +28,7 @@ SubDir TOP board msb-430-common ; Module board : board_init.c debug_uart.c ; -Module config : config.c ; +Module board_config : board_config.c ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/board/msb-430-common/config.c b/board/msb-430-common/board_config.c similarity index 55% rename from board/msb-430-common/config.c rename to board/msb-430-common/board_config.c index 3e752592c..f22e513b2 100644 --- a/board/msb-430-common/config.c +++ b/board/msb-430-common/board_config.c @@ -1,8 +1,18 @@ #include +#include #include #include #include +void config_load(void) { + if (*((uint16_t*) INFOMEM) == CONFIG_KEY) { + memcpy(&sysconfig, (char*) (INFOMEM + sizeof(CONFIG_KEY)), sizeof(sysconfig)); + } + else { + config_save(); + } +} + uint8_t config_save(void) { configmem_t mem = { CONFIG_KEY, sysconfig }; return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem))); diff --git a/board/msb-430h/Jamfile b/board/msb-430h/Jamfile index 15f7ba97f..588fede19 100644 --- a/board/msb-430h/Jamfile +++ b/board/msb-430h/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430h ; -Module board_cc1100 : driver_cc1100.c ; +Module board_cc1100 : driver_cc1100.c : cc110x_spi ; SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; diff --git a/board/msb-430h/driver_cc1100.c b/board/msb-430h/driver_cc1100.c index 9575bee6a..1e5af6e9f 100644 --- a/board/msb-430h/driver_cc1100.c +++ b/board/msb-430h/driver_cc1100.c @@ -23,7 +23,7 @@ Boston, MA 02111-1307, USA. */ #include #include -#include +#include #include #define CC1100_GDO0 (P2IN & 0x02) // read serial I/O (GDO0) @@ -340,4 +340,3 @@ puts("cc1100_isr()"); // if (system_state.POWERDOWN != 0) END_LPM3; __exit_isr(); } - diff --git a/cpu/cc430/hwtimer_cc430.c b/cpu/cc430/hwtimer_cc430.c index b5843ca23..64a7a9bb0 100644 --- a/cpu/cc430/hwtimer_cc430.c +++ b/cpu/cc430/hwtimer_cc430.c @@ -4,6 +4,9 @@ #include #include +// #define ENABLE_DEBUG (1) +#include + static uint32_t ticks = 0; extern void (*int_handler)(int); @@ -41,30 +44,13 @@ interrupt(TIMER0_A1_VECTOR) __attribute__ ((naked)) timer0_a1_5_isr(void) { short taiv = TA0IV; short timer; - if (!(taiv & TAIFG)) { -// case TAIFG: - timer = (taiv/2); - TA0_unset(timer); - int_handler(timer); - /* break; - - // Timer0_A3 Configurable periodic IRQ (used by button_repeat and buzzer) - case 0x06: // Disable IE - TA0CCTL3 &= ~CCIE; - // Reset IRQ flag - TA0CCTL3 &= ~CCIFG; - // Enable timer interrupt - TA0CCTL3 |= CCIE; - // Call function handler - // TODO - break; - - // Timer0_A4 One-time delay - case 0x08: // Disable IE - TA0CCTL4 &= ~CCIE; - // Reset IRQ flag - TA0CCTL4 &= ~CCIFG; - break;*/ + if (taiv & TAIFG) { + DEBUG("Overflow\n"); + } + else { + timer = (taiv/2); + TA0_unset(timer); + int_handler(timer); } __exit_isr(); diff --git a/cpu/msp430-common/Jamfile b/cpu/msp430-common/Jamfile index 19e40bb30..540398c72 100644 --- a/cpu/msp430-common/Jamfile +++ b/cpu/msp430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP cpu msp430-common ; -Module cpu : msp430-main.c cpu.c atomic.c irq.c ; +Module cpu : msp430-main.c cpu.c atomic.c irq.c flashrom.c ; Module hwtimer_msp430 : hwtimer_cpu.c ; UseModule cpu ; diff --git a/cpu/msp430-common/flashrom.c b/cpu/msp430-common/flashrom.c index dff02c053..94d2e023f 100644 --- a/cpu/msp430-common/flashrom.c +++ b/cpu/msp430-common/flashrom.c @@ -1,4 +1,6 @@ #include +#include +#include #include #include diff --git a/cpu/msp430-common/hwtimer_cpu.c b/cpu/msp430-common/hwtimer_cpu.c index 3d193c28e..ffb07fc32 100644 --- a/cpu/msp430-common/hwtimer_cpu.c +++ b/cpu/msp430-common/hwtimer_cpu.c @@ -31,7 +31,8 @@ and the mailinglist (subscription via web site) #include #include -#include "debug.h" +// #define ENABLE_DEBUG (1) +#include void (*int_handler)(int); @@ -55,7 +56,7 @@ static void TA0_set_nostart(unsigned long value, short timer) { } static void TA0_set(unsigned long value, short timer) { -// printf("Setting timer %u to %lu\n", timer, value); + DEBUG("Setting timer %u to %lu\n", timer, value); TA0_set_nostart(value, timer); TA0_enable_interrupt(timer); } diff --git a/cpu/msp430-common/include/cpu-conf.h b/cpu/msp430-common/include/cpu-conf.h index 9f9e114f1..cc7cc1efe 100644 --- a/cpu/msp430-common/include/cpu-conf.h +++ b/cpu/msp430-common/include/cpu-conf.h @@ -38,8 +38,8 @@ and the mailinglist (subscription via web site) #define KERNEL_CONF_STACKSIZE_IDLE 64 #define MSP430_ISR_STACK_SIZE 256 -#define RX_BUF_SIZE (4) -#define TRANSCEIVER_BUFFER_SIZE (4) +#define RX_BUF_SIZE (2) +#define TRANSCEIVER_BUFFER_SIZE (2) /** @} */ #endif /* CPUCONF_H_ */ diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index c6497672f..f3c0bc934 100755 --- a/drivers/cc110x_ng/Jamfile +++ b/drivers/cc110x_ng/Jamfile @@ -29,6 +29,6 @@ SubDir TOP drivers cc110x_ng ; HDRS += $(TOP)/drivers/cc110x_ng ; -Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : hwtimer board_cc1100 config ; +Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : hwtimer board_cc1100 ; Module cc110x_spi : cc1100_spi.c ; Module cc110x_cc430 : cc1100_cc430.c ; diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index e16150d29..fd3048d8a 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -23,6 +23,9 @@ cc1100_statistic_t cc1100_statistic; volatile cc1100_flags rflags; ///< Radio control flags volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state +static radio_address_t radio_address; ///< Radio address +static uint8_t radio_channel; ///< Radio channel + int transceiver_pid; ///< the transceiver thread pid /* internal function prototypes */ @@ -66,8 +69,12 @@ void cc1100_init(int tpid) { rflags.WOR_RST = 0; /* Set default channel number */ - cc1100_set_channel(sysconfig.radio_channel); - DEBUG("CC1100 initialized and set to channel %i\n", sysconfig.radio_channel); +#ifdef MODULE_CONFIG + cc1100_set_config_channel(sysconfig.radio_channel); +#else + cc1100_set_channel(CC1100_DEFAULT_CHANNR); +#endif + DEBUG("CC1100 initialized and set to channel %i\n", radio_channel); // Switch to desired mode (WOR or RX) rd_set_mode(RADIO_MODE_ON); @@ -94,7 +101,7 @@ uint8_t cc1100_get_buffer_pos(void) { } radio_address_t cc1100_get_address() { - return sysconfig.radio_address; + return radio_address; } radio_address_t cc1100_set_address(radio_address_t address) { @@ -107,15 +114,20 @@ radio_address_t cc1100_set_address(radio_address_t address) { write_register(CC1100_ADDR, id); } - sysconfig.radio_address = id; - return sysconfig.radio_address; + radio_address = id; + return radio_address; } +#ifdef MODULE_CONFIG radio_address_t cc1100_set_config_address(radio_address_t address) { radio_address_t a = cc1100_set_address(address); + if (a) { + sysconfig.radio_address = a; + } config_save(); return a; } +#endif void cc1100_set_monitor(uint8_t mode) { if (mode) { @@ -213,7 +225,7 @@ char* cc1100_state_to_text(uint8_t state) { void cc1100_print_config(void) { printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); - printf("Current channel number: %u\r\n", sysconfig.radio_channel); + printf("Current channel number: %u\r\n", radio_channel); } void cc1100_switch_to_pwd(void) { @@ -230,18 +242,23 @@ int16_t cc1100_set_channel(uint8_t channr) { return -1; } write_register(CC1100_CHANNR, channr*10); - sysconfig.radio_channel = channr; - return sysconfig.radio_channel; + radio_channel = channr; + return radio_channel; } +#ifdef MODULE_CONFIG int16_t cc1100_set_config_channel(uint8_t channr) { int16_t c = cc1100_set_channel(channr); + if (c) { + sysconfig.radio_channel = c; + } config_save(); return c; } +#endif int16_t cc1100_get_channel(void) { - return sysconfig.radio_channel; + return radio_channel; } diff --git a/projects/chronos_cc110x_ng/Jamfile b/projects/chronos_cc110x_ng/Jamfile new file mode 100644 index 000000000..8085574cb --- /dev/null +++ b/projects/chronos_cc110x_ng/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects chronos_cc110x_ng ; + +Module chronos_cc110x_ng : main.c : cc110x_ng transceiver auto_init board_display ; + +UseModule chronos_cc110x_ng ; diff --git a/projects/chronos_cc110x_ng/main.c b/projects/chronos_cc110x_ng/main.c new file mode 100644 index 000000000..87a9024ce --- /dev/null +++ b/projects/chronos_cc110x_ng/main.c @@ -0,0 +1,103 @@ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define RADIO_STACK_SIZE (1024) +#define SEND_SIZE CC1100_MAX_DATA_LENGTH + +#define SND_BUFFER_SIZE (3) +#define RCV_BUFFER_SIZE (4) + +#define SENDING_DELAY (5 * 1000) + +char radio_stack_buffer[RADIO_STACK_SIZE]; + +uint8_t snd_buffer[SND_BUFFER_SIZE][SEND_SIZE]; + +msg msg_q[RCV_BUFFER_SIZE]; + +static msg mesg; +static transceiver_command_t tcmd; +static radio_packet_t p; + +void sender(char *count); + +void sender(char *count) { + unsigned int c = 3; + unsigned int i; + + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + + p.length = CC1100_MAX_DATA_LENGTH; + p.dst = 0; + + for (i = 0; i < c; i++) { + display_chars(LCD_SEG_L1_3_0, ".....", SEG_OFF); + display_chars(LCD_SEG_L1_3_0, (char*) itoa(i, 1, 0), SEG_ON); + p.data = snd_buffer[i % SND_BUFFER_SIZE]; + msg_send(&mesg, transceiver_pid, 1); + hwtimer_wait(SENDING_DELAY); + } +} + + +void radio(void) { + msg m; + radio_packet_t *p; + + msg_init_queue(msg_q, RCV_BUFFER_SIZE); + + while (1) { + msg_receive(&m); + if (m.type == PKT_PENDING) { + p = (radio_packet_t*) m.content.ptr; + display_chars(LCD_SEG_L2_5_0, (char*) itoa(p->length, 2, 0), SEG_ON); + p->processing--; + } + else if (m.type == ENOBUFFER) { + } + else { + } + } +} + +int main(void) { + int radio_pid; + uint8_t addr = 43; + uint8_t i; + for (i = 0; i < SND_BUFFER_SIZE; i++) { + memset(snd_buffer[i], i, SEND_SIZE); + } + radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); + transceiver_init(TRANSCEIVER_CC1100); + transceiver_start(); + transceiver_register(TRANSCEIVER_CC1100, radio_pid); + + lcd_init(); + clear_display_all(); + mesg.type = SET_ADDRESS; + mesg.content.ptr = (char*) &tcmd; + + display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_ON); + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &addr; + msg_send(&mesg, transceiver_pid, 1); + + sender(NULL); + + while (1) { + } +} diff --git a/projects/chronos_cc110x_ng/tests/hello-world b/projects/chronos_cc110x_ng/tests/hello-world new file mode 100755 index 000000000..acde8265f --- /dev/null +++ b/projects/chronos_cc110x_ng/tests/hello-world @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "Hello World!" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" + From d5ff633d07dc9c1bbb39e02403fb2a05af5818ab Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 10 Dec 2010 16:49:29 +0100 Subject: [PATCH 138/199] * initial checkin of last in first out array queue (lifo) --- core/Jamfile | 4 ++-- core/include/lifo.h | 9 +++++++++ core/lifo.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 core/include/lifo.h create mode 100644 core/lifo.c diff --git a/core/Jamfile b/core/Jamfile index 6e0fae63b..becba93e2 100644 --- a/core/Jamfile +++ b/core/Jamfile @@ -27,8 +27,8 @@ SubDir TOP core ; -Module core : kernel_init.c sched.c mutex.c msg.c queue.c - clist.c thread.c bitarithm.c cib.c ; +Module core : kernel_init.c sched.c mutex.c msg.c thread.c : core_lib ; +Module core_lib : queue.c clist.c bitarithm.c cib.c lifo.c ; Module hwtimer : hwtimer.c : hwtimer_cpu ; diff --git a/core/include/lifo.h b/core/include/lifo.h new file mode 100644 index 000000000..524698a90 --- /dev/null +++ b/core/include/lifo.h @@ -0,0 +1,9 @@ +#ifndef __LIFO_H +#define __LIFO_H + +int lifo_empty(int *array); +void lifo_init(int *array, int n); +void lifo_insert(int *array, int i); +int lifo_get(int *array); + +#endif /* __LIFO_H */ diff --git a/core/lifo.c b/core/lifo.c new file mode 100644 index 000000000..00237caec --- /dev/null +++ b/core/lifo.c @@ -0,0 +1,44 @@ +#include + +int lifo_empty(int *array) { + return array[0] == -1; +} + +void lifo_init(int *array, int n) { + for (int i = 0; i <= n; i++) { + array[i] = -1; + } +} + +void lifo_insert(int *array, int i) { + int index = i+1; + array[index] = array[0]; + array[0] = i; +} + +int lifo_get(int *array) { + int head = array[0]; + if (head != -1) { + array[0] = array[head+1]; + } + return head; +} + + +#ifdef WITH_MAIN +#include +int main() { + int array[5]; + + lifo_init(array, 4); + + lifo_insert(array, 0); + lifo_insert(array, 1); + lifo_insert(array, 2); + lifo_insert(array, 3); + printf("get: %i\n", lifo_get(array)); + + + return 0; +} +#endif From 5838ce604b158e4d496d8525c05f870537050d4d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 10 Dec 2010 16:50:16 +0100 Subject: [PATCH 139/199] * hwtimer: switched to lifo --- core/hwtimer.c | 151 ++++++++++++++----------------------------------- 1 file changed, 42 insertions(+), 109 deletions(-) diff --git a/core/hwtimer.c b/core/hwtimer.c index e19c8a2a8..b4cdf0727 100644 --- a/core/hwtimer.c +++ b/core/hwtimer.c @@ -20,81 +20,33 @@ #include #include -#include - #include #include +#include /*---------------------------------------------------------------------------*/ typedef struct hwtimer_t { void (*callback)(void*); void* data; - 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); - } +static void hwtimer_wakeup(void* ptr) { + int pid = (int)ptr; + thread_wakeup(pid); } void hwtimer_spin(unsigned long ticks) @@ -113,26 +65,18 @@ void hwtimer_init(void) { /*---------------------------------------------------------------------------*/ void hwtimer_init_comp(uint32_t fcpu) { - int i; - queue_head = 0; - queue_tail = 0; - queue_items = 0; - timer_id = 0; - available_timers = 0; hwtimer_arch_init(multiplexer, fcpu); - for (i = 0; i < HWTIMER_QUEUESIZE; i++) { - /* init queue as empty */ - queue[i] = 0xff; - } - for (i = 0; i < HWTIMER_QUEUESIZE; i++) { - enqueue(i); + + lifo_init(lifo, ARCH_MAXTIMERS); + for (int i = 0; i < ARCH_MAXTIMERS; i++) { + lifo_insert(lifo, i); } } /*---------------------------------------------------------------------------*/ int hwtimer_active(void) { - return (queue_items != HWTIMER_QUEUESIZE); + return (! lifo_empty(lifo)); } /*---------------------------------------------------------------------------*/ @@ -150,51 +94,53 @@ void hwtimer_wait(unsigned long ticks) hwtimer_spin(ticks); return; } - 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); + int res = hwtimer_set(ticks-2, hwtimer_wakeup, (void*) (unsigned int)(active_thread->pid)); if (res == -1) { hwtimer_spin(ticks); return; } - while (hwt.state) { - thread_sleep(); - } + + thread_sleep(); } /*---------------------------------------------------------------------------*/ +#include static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr, bool absolute) { if (!inISR()) { dINT(); } - int x = dequeue(); - if (x == Q_FULL) { + + int n = lifo_get(lifo); + if (n == -1) { if (! inISR()) { eINT(); } - printf("[KT] no timers left\n"); + puts("No hwtimer left."); return -1; } - timer[x].callback = callback; - timer[x].data = ptr; - timer[x].checksum = ++timer_id; + timer[n].callback = callback; + timer[n].data = ptr; if (absolute) { - hwtimer_arch_set_absolute(offset, x); +// printf("hwt: setting %i to %u\n", n, offset); + hwtimer_arch_set_absolute(offset, n); } else { - hwtimer_arch_set(offset, x); +// printf("hwt: setting %i to offset %u\n", n, offset); + hwtimer_arch_set(offset, n); } + lpm_prevent_sleep++; + if (!inISR()) { eINT(); } - return (timer[x].checksum << 8) + x; + return n; } int hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr) { @@ -208,31 +154,18 @@ int hwtimer_set_absolute(unsigned long offset, void (*callback)(void*), void *pt /*---------------------------------------------------------------------------*/ -int hwtimer_remove(int x) +int hwtimer_remove(int n) { - int t = x & 0xff; - uint8_t checksum = (uint8_t) (x >> 8); - if (t < 0 || t >= HWTIMER_QUEUESIZE || timer[t].callback == NULL || timer[t].checksum != checksum) { - return -1; - } +// printf("hwt: remove %i.\n", n); hwtimer_arch_disable_interrupt(); - hwtimer_arch_unset(t); - enqueue(t); - timer[t].callback = NULL; + hwtimer_arch_unset(n); + + lifo_insert(lifo, n); + timer[n].callback = NULL; + + lpm_prevent_sleep--; + hwtimer_arch_enable_interrupt(); return 1; } -/*---------------------------------------------------------------------------*/ - -void hwtimer_debug(int timer) -{ - printf("queue size: %i\n", queue_items); - printf("available timers: %lu\n", available_timers); - int t = timer & 0xff; - if (available_timers & (1 << t)) { - printf("timer %i is: not set\n", timer); - } else { - printf("timer %i is: set\n", timer); - } -} From 9757bb7dda5dfc3094f6f5e89d70653402ed629d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 10 Dec 2010 16:52:06 +0100 Subject: [PATCH 140/199] * many fixes. vtimer_hammer OK now. --- sys/vtimer.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/sys/vtimer.c b/sys/vtimer.c index 74e05adf8..2ea9420eb 100644 --- a/sys/vtimer.c +++ b/sys/vtimer.c @@ -13,6 +13,7 @@ #include #define VTIMER_THRESHOLD 20U +#define VTIMER_BACKOFF 10U #define SECONDS_PER_TICK (4096U) #define NANOSECONDS_PER_TICK (4096U * 1000000) @@ -41,7 +42,7 @@ static int set_longterm(vtimer_t *timer) { } static int update_shortterm() { - if (hwtimer_id) { + if (hwtimer_id != -1) { if (hwtimer_next_absolute != shortterm_queue_root.next->priority) { hwtimer_remove(hwtimer_id); } else { @@ -49,23 +50,24 @@ static int update_shortterm() { } } - uint32_t now = hwtimer_now(); + hwtimer_next_absolute = shortterm_queue_root.next->priority; - - while ((hwtimer_next_absolute + longterm_tick_start)-(hwtimer_now()+VTIMER_THRESHOLD) > NANOSECONDS_PER_TICK) { - hwtimer_next_absolute += VTIMER_THRESHOLD; + + unsigned int next = hwtimer_next_absolute + longterm_tick_start; + unsigned int now = hwtimer_now(); + + if((next - VTIMER_THRESHOLD - now) > NANOSECONDS_PER_TICK ) { + next = now + VTIMER_BACKOFF; } - hwtimer_id = hwtimer_set_absolute(hwtimer_next_absolute + longterm_tick_start, vtimer_callback, NULL); + hwtimer_id = hwtimer_set_absolute(next, vtimer_callback, NULL); DEBUG("update_shortterm: Set hwtimer to %lu (now=%lu)\n", hwtimer_next_absolute + longterm_tick_start, hwtimer_now()); - //printf("%lu (now=%lu)\n", hwtimer_next_absolute + longterm_tick_start, hwtimer_now()); - return 0; } void vtimer_tick(void *ptr) { - puts("vtimer_tick()."); + DEBUG("vtimer_tick()."); seconds += SECONDS_PER_TICK; longterm_tick_start = longterm_tick_timer.absolute.nanoseconds; @@ -95,9 +97,12 @@ static int set_shortterm(vtimer_t *timer) { void vtimer_callback(void *ptr) { vtimer_t *timer; in_callback = true; + hwtimer_id = -1; + timer = (vtimer_t *)queue_remove_head(&shortterm_queue_root); DEBUG("vtimer_callback(): Shooting %lu.\n", timer->absolute.nanoseconds); + /* shoot timer */ timer->action(timer->arg); @@ -126,10 +131,6 @@ void normalize_to_tick(timex_t *time) { int vtimer_set(vtimer_t *timer, timex_t *offset) { DEBUG("vtimer_set(): New timer. Offset: %lu %lu\n", offset->seconds, offset->nanoseconds); - -// timex_t vnow = vtimer_now(); -// DEBUG("Now = %lu %lu\n", vnow.seconds, vnow.nanoseconds); - timer->absolute = timex_add(vtimer_now(), *offset); normalize_to_tick(&(timer->absolute)); @@ -137,6 +138,12 @@ int vtimer_set(vtimer_t *timer, timex_t *offset) { int result = 0; + if (timer->absolute.seconds == 0) { + if (timer->absolute.nanoseconds > 10) { + timer->absolute.nanoseconds -= 10; + } + } + int state = disableIRQ(); if (timer->absolute.seconds != seconds ) { /* we're long-term */ @@ -167,6 +174,7 @@ timex_t vtimer_now() { int vtimer_init() { DEBUG("vtimer_init().\n"); + int state = disableIRQ(); seconds = 0; longterm_tick_timer.action = vtimer_tick; @@ -180,13 +188,14 @@ int vtimer_init() { set_shortterm(&longterm_tick_timer); update_shortterm(); + restoreIRQ(state); return 0; } int vtimer_usleep(uint32_t usecs) { vtimer_t t; timex_t offset = timex_set(0, usecs); - t.action = thread_wakeup; + t.action = (void*) thread_wakeup; t.arg = (void*) thread_getpid(); vtimer_set(&t, &offset); thread_sleep(); From 1ee8fb13dd93591c6a6c71f4ffd6e860e8563cb0 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 10 Dec 2010 17:16:18 +0100 Subject: [PATCH 141/199] * vtimer: api compatible to swtimer. --- sys/include/vtimer.h | 49 ++++++++++++++++++++++++++++++++++++++++++-- sys/vtimer.c | 32 ++++++++++++++++++++++------- 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/sys/include/vtimer.h b/sys/include/vtimer.h index 9b4e02a09..a7bc58d5f 100644 --- a/sys/include/vtimer.h +++ b/sys/include/vtimer.h @@ -13,8 +13,53 @@ typedef struct vtimer_t { int vtimer_init(); -int vtimer_set(vtimer_t *timer, timex_t *offset); timex_t vtimer_now(); -int vtimer_usleep(uint32_t usecs); + +/** + * @brief will cause the calling thread to be suspended from excecution until the number of microseconds has elapsed + * @param[in] us number of microseconds + * @return 0 on success, < 0 on error + */ +int vtimer_usleep(uint32_t us); + +/** + * @brief will cause the calling thread to be suspended from excecution until the time specified by time has elapsed + * @param[in] time timex_t with time to suspend execution + * @return 0 on success, < 0 on error + */ +int vtimer_sleep(timex_t time); +/** + * @brief set a vtimer with msg event handler + * @param[in] t pointer to preinitialised vtimer_t + * @param[in] interval vtimer timex_t interval + * @param[in] pid process id + * @param[in] ptr message value + * @return 0 on success, < 0 on error + */ +int vtimer_set_msg(vtimer_t *t, timex_t interval, int pid, void *ptr); + +/** + * @brief set a vtimer with wakeup event + * @param[in] t pointer to preinitialised vtimer_t + * @param[in] pid process id + * @return 0 on success, < 0 on error + */ +int vtimer_set_wakeup(vtimer_t *t, timex_t interval, int pid); + +/** + * @brief set a vtimer with callback function event handler + * @param[in] t pointer to preinitialised vtimer_t + * @param[in] interval vtimer interval + * @param[in] f_ptr pointer to callback function + * @return 0 on success, < 0 on error + */ +int vtimer_set_cb(vtimer_t *t, timex_t interval, void (*f_ptr)(void *), void *ptr); + +/** + * @brief remove a vtimer + * @param[in] t pointer to preinitialised vtimer_t + * @return 0 on success, < 0 on error + */ +int vtimer_remove(vtimer_t *t); #endif /* __VTIMER_H */ diff --git a/sys/vtimer.c b/sys/vtimer.c index 2ea9420eb..fa92de7a9 100644 --- a/sys/vtimer.c +++ b/sys/vtimer.c @@ -20,6 +20,7 @@ void vtimer_callback(void *ptr); void vtimer_tick(void *ptr); +static int vtimer_set(vtimer_t *timer); static int set_longterm(vtimer_t *timer); static int set_shortterm(vtimer_t *timer); @@ -128,10 +129,10 @@ void normalize_to_tick(timex_t *time) { DEBUG(" Result: %lu %lu\n", time->seconds, time->nanoseconds); } -int vtimer_set(vtimer_t *timer, timex_t *offset) { - DEBUG("vtimer_set(): New timer. Offset: %lu %lu\n", offset->seconds, offset->nanoseconds); +static int vtimer_set(vtimer_t *timer) { + DEBUG("vtimer_set(): New timer. Offset: %lu %lu\n", timer->absolute.seconds, timer->absolute.nanoseconds); - timer->absolute = timex_add(vtimer_now(), *offset); + timer->absolute = timex_add(vtimer_now(), timer->absolute); normalize_to_tick(&(timer->absolute)); DEBUG("vtimer_set(): Absolute: %lu %lu\n", timer->absolute.seconds, timer->absolute.nanoseconds); @@ -192,13 +193,30 @@ int vtimer_init() { return 0; } +int vtimer_set_wakeup(vtimer_t *t, timex_t interval, int pid) { + t->action = (void*) thread_wakeup; + t->arg = (void*) pid; + t->absolute = interval; + vtimer_set(t); + return 0; +} + int vtimer_usleep(uint32_t usecs) { - vtimer_t t; timex_t offset = timex_set(0, usecs); - t.action = (void*) thread_wakeup; - t.arg = (void*) thread_getpid(); - vtimer_set(&t, &offset); + return vtimer_sleep(offset); +} + +int vtimer_sleep(timex_t time) { + vtimer_t t; + vtimer_set_wakeup(&t, time, thread_getpid()); thread_sleep(); return 0; } +int vtimer_set_cb(vtimer_t *t, timex_t interval, void (*f_ptr)(void *), void *ptr) { + t->action = f_ptr; + t->arg = ptr; + t->absolute = interval; + return vtimer_set(t); +} + From 0ac2965b43d176bcd13412bbf31ee45c9e2cca93 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 10 Dec 2010 17:30:21 +0100 Subject: [PATCH 142/199] *swtimers: marked deprecated --- sys/include/swtimer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/include/swtimer.h b/sys/include/swtimer.h index 14835348d..b1962d524 100644 --- a/sys/include/swtimer.h +++ b/sys/include/swtimer.h @@ -17,6 +17,7 @@ #ifndef __SWTIMER_H__ #define __SWTIMER_H__ +#warning Swtimers are deprecated. use virtual timers (vtimer) instead. #include From 54b8f9b48a8d32f55b621ae818bf30fa9038656e Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 10 Dec 2010 17:31:26 +0100 Subject: [PATCH 143/199] * vtimer: api doc updates --- sys/include/vtimer.h | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/sys/include/vtimer.h b/sys/include/vtimer.h index a7bc58d5f..8a9772973 100644 --- a/sys/include/vtimer.h +++ b/sys/include/vtimer.h @@ -1,9 +1,34 @@ +/** \addtogroup system + * @{ */ + +/** + * \defgroup vtimer Virtual (Software) Timer library + * + * The vtimer library provides functions for setting, resetting and restarting + * software timers, and for checking if a vtimer has expired. + * + * (As of now, not resetting, restarting, removing and checking are not implemented) + * + * @{ + */ + +/** + * \file + * Timer library header file. + */ #ifndef __VTIMER_H #define __VTIMER_H #include #include +/** + * A vtimer object. + * + * This structure is used for declaring a vtimer. This should not be used by programmers, use the vtimer_set_*-functions instead. + * + * \hideinitializer + */ typedef struct vtimer_t { queue_node_t queue_entry; timex_t absolute; @@ -11,10 +36,19 @@ typedef struct vtimer_t { void* arg; } vtimer_t; -int vtimer_init(); - +/** + * @brief Current system time + * @return Time as timex_t since system boot + */ timex_t vtimer_now(); +/** + * @brief Initializes the vtimer subsystem. To be called once at system initialization. Will be initialized by auto_init. + * + * @return always 0 + */ +int vtimer_init(); + /** * @brief will cause the calling thread to be suspended from excecution until the number of microseconds has elapsed * @param[in] us number of microseconds @@ -28,6 +62,7 @@ int vtimer_usleep(uint32_t us); * @return 0 on success, < 0 on error */ int vtimer_sleep(timex_t time); + /** * @brief set a vtimer with msg event handler * @param[in] t pointer to preinitialised vtimer_t From ec6a794143de5d6a9ea6fbc78c46a51b52889d69 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 10 Dec 2010 18:00:31 +0100 Subject: [PATCH 144/199] [cc110x_ng] * fuxed transceiver driver for chronos * some more stuff --- board/chronos/drivers/cc430-cc1100.c | 35 ++++++++++--------- board/msba2-common/drivers/msba2-cc1100.c | 3 +- cpu/msp430-common/include/cpu-conf.h | 4 +-- drivers/cc110x_ng/cc1100-rx.c | 2 ++ drivers/cc110x_ng/cc1100.c | 2 +- drivers/cc110x_ng/cc1100_cc430.c | 13 +++++-- projects/chronos_cc110x_ng/main.c | 41 ++++++++++------------- projects/hi_earth/Jamfile | 2 +- projects/hi_earth/main.c | 18 +++++++--- projects/msb430_cc110x_ng/Jamfile | 2 +- projects/msb430_cc110x_ng/main.c | 17 ++++++++++ projects/test_cc110x_ng/Jamfile | 2 +- sys/include/transceiver.h | 4 +++ sys/shell/cc1100_ng.c | 38 ++++++++++++--------- sys/transceiver.c | 4 --- 15 files changed, 111 insertions(+), 76 deletions(-) diff --git a/board/chronos/drivers/cc430-cc1100.c b/board/chronos/drivers/cc430-cc1100.c index 6c36e7e6d..513cef3e5 100644 --- a/board/chronos/drivers/cc430-cc1100.c +++ b/board/chronos/drivers/cc430-cc1100.c @@ -8,9 +8,9 @@ #include #include -#define CC1100_GDO0 IOCFG0 -#define CC1100_GDO1 IOCFG1 -#define CC1100_GDO2 IOCFG2 +#define CC1100_GDO0 (RF1AIN & BIT0) +#define CC1100_GDO1 (RF1AIN & BIT1) +#define CC1100_GDO2 (RF1AIN & BIT2) int cc1100_get_gdo0(void) { return CC1100_GDO0; @@ -37,41 +37,44 @@ void cc1100_after_send(void) } void cc1100_gdo0_enable(void) { - RF1AIFG &= ~RF1AIV_RFIFG0; - RF1AIE |= RF1AIV_RFIFG0; + RF1AIFG &= ~BIT0; + RF1AIE |= BIT0; } void cc1100_gdo0_disable(void) { - RF1AIE &= ~RF1AIV_RFIFG0; - RF1AIFG &= ~RF1AIV_RFIFG0; + RF1AIE &= ~BIT0; + RF1AIFG &= ~BIT0; } void cc1100_gdo2_disable(void) { - RF1AIFG &= ~RF1AIV_RFIFG2; - RF1AIE &= ~RF1AIV_RFIFG2; + RF1AIFG &= ~BIT2; // Clear a pending interrupt + RF1AIE &= ~BIT2; // Disable the interrupt } void cc1100_gdo2_enable(void) { - RF1AIE &= ~RF1AIV_RFIFG2; - RF1AIFG |= RF1AIV_RFIFG2; + RF1AIFG &= ~BIT2; // Clear a pending interrupt + RF1AIE |= BIT2; // Enable the interrupt } void cc1100_init_interrupts(void) { uint8_t state = disableIRQ(); /* Disable all interrupts */ + cc1100_gdo2_enable(); + cc1100_gdo0_disable(); restoreIRQ(state); /* Enable all interrupts */ } interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ __enter_isr(); /* Check IFG */ - if (RF1AIFG & RF1AIV_RFIFG2) { - RF1AIFG &= ~RF1AIV_RFIFG2; + if (RF1AIV == RF1AIV_RFIFG2) { + while (RF1AIN & BIT2); + /* discard all further interrupts */ + RF1AIV = 0; cc1100_gdo2_irq(); } - if (RF1AIFG & RF1AIV_RFIFG0) { - RF1AIFG &= ~RF1AIV_RFIFG0; - RF1AIE &= ~RF1AIV_RFIFG0; + if (RF1AIV == RF1AIV_RFIFG0) { cc1100_gdo0_irq(); + RF1AIE &= ~BIT0; } __exit_isr(); } diff --git a/board/msba2-common/drivers/msba2-cc1100.c b/board/msba2-common/drivers/msba2-cc1100.c index 726d58550..327720c1f 100644 --- a/board/msba2-common/drivers/msba2-cc1100.c +++ b/board/msba2-common/drivers/msba2-cc1100.c @@ -128,8 +128,7 @@ void cc1100_spi_init(void) } } -uint8_t -cc1100_txrx(uint8_t c) { +uint8_t cc1100_txrx(uint8_t c) { uint8_t result; SSP0DR = c; #ifdef DEBUG diff --git a/cpu/msp430-common/include/cpu-conf.h b/cpu/msp430-common/include/cpu-conf.h index cc7cc1efe..a79e422f5 100644 --- a/cpu/msp430-common/include/cpu-conf.h +++ b/cpu/msp430-common/include/cpu-conf.h @@ -38,8 +38,8 @@ and the mailinglist (subscription via web site) #define KERNEL_CONF_STACKSIZE_IDLE 64 #define MSP430_ISR_STACK_SIZE 256 -#define RX_BUF_SIZE (2) -#define TRANSCEIVER_BUFFER_SIZE (2) +#define RX_BUF_SIZE (3) +#define TRANSCEIVER_BUFFER_SIZE (3) /** @} */ #endif /* CPUCONF_H_ */ diff --git a/drivers/cc110x_ng/cc1100-rx.c b/drivers/cc110x_ng/cc1100-rx.c index 9377f736f..052f576ca 100644 --- a/drivers/cc110x_ng/cc1100-rx.c +++ b/drivers/cc110x_ng/cc1100-rx.c @@ -38,6 +38,7 @@ void cc1100_rx_handler(void) { } cc1100_rx_buffer[rx_buffer_next].rssi = rflags._RSSI; cc1100_rx_buffer[rx_buffer_next].lqi = rflags._LQI; + cc1100_strobe(CC1100_SFRX); // ...for flushing the RX FIFO // Valid packet. After a wake-up, the radio should be in IDLE. // So put CC1100 to RX for WOR_TIMEOUT (have to manually put @@ -109,6 +110,7 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { rxBuffer[0] = packetLength; // Read the rest of the packet + // TODO: Offset + 2 here for cc430 cc1100_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc1100.c index fd3048d8a..20667db9f 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc1100.c @@ -272,7 +272,7 @@ static void reset(void) { cc1100_spi_select(); #endif cc1100_strobe(CC1100_SRES); - hwtimer_wait(RTIMER_TICKS(10)); + hwtimer_wait(RTIMER_TICKS(100)); } static void power_up_reset(void) { diff --git a/drivers/cc110x_ng/cc1100_cc430.c b/drivers/cc110x_ng/cc1100_cc430.c index ed991a049..3eb9751d4 100644 --- a/drivers/cc110x_ng/cc1100_cc430.c +++ b/drivers/cc110x_ng/cc1100_cc430.c @@ -99,9 +99,16 @@ void cc1100_write_reg(uint8_t addr, uint8_t value) { } uint8_t cc1100_read_status(uint8_t addr) { - char status; - cc1100_readburst_reg(addr, &status, 1); - return status; + unsigned char x; + uint16_t int_state; + + int_state = disableIRQ(); + + RF1AINSTR1B = (addr | RF_STATREGRD); + x = RF1ADOUT1B; + + restoreIRQ(int_state); + return x; } // ************************************************************************************************* diff --git a/projects/chronos_cc110x_ng/main.c b/projects/chronos_cc110x_ng/main.c index 87a9024ce..e6605182b 100644 --- a/projects/chronos_cc110x_ng/main.c +++ b/projects/chronos_cc110x_ng/main.c @@ -11,17 +11,16 @@ #include #include -#define RADIO_STACK_SIZE (1024) +#define RADIO_STACK_SIZE (512) #define SEND_SIZE CC1100_MAX_DATA_LENGTH -#define SND_BUFFER_SIZE (3) #define RCV_BUFFER_SIZE (4) #define SENDING_DELAY (5 * 1000) char radio_stack_buffer[RADIO_STACK_SIZE]; -uint8_t snd_buffer[SND_BUFFER_SIZE][SEND_SIZE]; +uint8_t snd_buffer[SEND_SIZE]; msg msg_q[RCV_BUFFER_SIZE]; @@ -29,28 +28,20 @@ static msg mesg; static transceiver_command_t tcmd; static radio_packet_t p; -void sender(char *count); - -void sender(char *count) { - unsigned int c = 3; - unsigned int i; +void send(radio_address_t dst, uint8_t len, uint8_t *data); +void send(radio_address_t dst, uint8_t len, uint8_t *data) { mesg.type = SND_PKT; mesg.content.ptr = (char*) &tcmd; tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &p; - p.length = CC1100_MAX_DATA_LENGTH; - p.dst = 0; + p.length = len; + p.dst = dst; - for (i = 0; i < c; i++) { - display_chars(LCD_SEG_L1_3_0, ".....", SEG_OFF); - display_chars(LCD_SEG_L1_3_0, (char*) itoa(i, 1, 0), SEG_ON); - p.data = snd_buffer[i % SND_BUFFER_SIZE]; - msg_send(&mesg, transceiver_pid, 1); - hwtimer_wait(SENDING_DELAY); - } + p.data = data; + msg_send(&mesg, transceiver_pid, 1); } @@ -64,7 +55,9 @@ void radio(void) { msg_receive(&m); if (m.type == PKT_PENDING) { p = (radio_packet_t*) m.content.ptr; - display_chars(LCD_SEG_L2_5_0, (char*) itoa(p->length, 2, 0), SEG_ON); + display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); + display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON); + send(p->src, p->length, p->data); p->processing--; } else if (m.type == ENOBUFFER) { @@ -76,11 +69,8 @@ void radio(void) { int main(void) { int radio_pid; - uint8_t addr = 43; - uint8_t i; - for (i = 0; i < SND_BUFFER_SIZE; i++) { - memset(snd_buffer[i], i, SEND_SIZE); - } + radio_address_t addr = 43; + memset(snd_buffer, 43, SEND_SIZE); radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); transceiver_init(TRANSCEIVER_CC1100); transceiver_start(); @@ -96,8 +86,11 @@ int main(void) { tcmd.data = &addr; msg_send(&mesg, transceiver_pid, 1); - sender(NULL); + send(0, SEND_SIZE, snd_buffer); while (1) { + hwtimer_wait(SENDING_DELAY); + display_chars(LCD_SEG_L1_3_0, ".....", SEG_OFF); + display_chars(LCD_SEG_L1_3_0, (char*) itoa(TA0R, 6, 0), SEG_ON); } } diff --git a/projects/hi_earth/Jamfile b/projects/hi_earth/Jamfile index dd8a116f8..b59a2a7d3 100644 --- a/projects/hi_earth/Jamfile +++ b/projects/hi_earth/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects hi_earth ; -Module hi_earth : main.c ; +Module hi_earth : main.c : board_display hwtimer auto_init ; UseModule hi_earth ; diff --git a/projects/hi_earth/main.c b/projects/hi_earth/main.c index 46911bbea..a335d450e 100644 --- a/projects/hi_earth/main.c +++ b/projects/hi_earth/main.c @@ -5,9 +5,10 @@ // Author: Felix Genicio //****************************************************************************** -#include "cc430x613x.h" +#include #include #include +#include void display1(void); void display2(void); @@ -30,6 +31,11 @@ int main(void) i = 1; display2(); } + for (j = 1; j < 10; j++) { + hwtimer_wait(3333); + } + display_symbol(5, SEG_ON); +/* for (j = 1; j != 0; j++) { if (i) { display_symbol(LCD_ICON_BEEPER1, SEG_ON); @@ -38,16 +44,18 @@ int main(void) display_symbol(5, SEG_OFF); } } +*/ } } void display1(void) { - display_chars(LCD_SEG_L1_3_0, (uint8_t*) "HI", SEG_ON); - display_chars(LCD_SEG_L2_5_0, (uint8_t*) " EARTH", SEG_OFF); + display_chars(LCD_SEG_L1_3_0, "HI", SEG_ON); + display_chars(LCD_SEG_L2_5_0, " EARTH", SEG_OFF); } void display2(void) { - display_chars(LCD_SEG_L1_3_0, (uint8_t*) "HI", SEG_OFF); - display_chars(LCD_SEG_L2_5_0, (uint8_t*) " EARTH", SEG_ON); + display_chars(LCD_SEG_L1_3_0, "HI", SEG_OFF); + display_chars(LCD_SEG_L2_5_0, (char*) itoa(TA0R, 6, 0), SEG_ON); +// display_chars(LCD_SEG_L2_5_0, (uint8_t*) " EARTH", SEG_ON); } diff --git a/projects/msb430_cc110x_ng/Jamfile b/projects/msb430_cc110x_ng/Jamfile index c28cac9ad..61234651e 100644 --- a/projects/msb430_cc110x_ng/Jamfile +++ b/projects/msb430_cc110x_ng/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects msb430_cc110x_ng ; -Module msb430_cc110x_ng : main.c : cc110x_ng transceiver shell shell_commands ps posix_io uart0 auto_init ; +Module msb430_cc110x_ng : main.c : cc110x_ng transceiver swtimer shell shell_commands ps posix_io uart0 auto_init config ; UseModule msb430_cc110x_ng ; diff --git a/projects/msb430_cc110x_ng/main.c b/projects/msb430_cc110x_ng/main.c index 83b02d2a7..019e8cb57 100644 --- a/projects/msb430_cc110x_ng/main.c +++ b/projects/msb430_cc110x_ng/main.c @@ -41,6 +41,22 @@ const shell_command_t sc[] = { {NULL, NULL, NULL} }; +void send(radio_address_t dst, uint8_t len, uint8_t *data); + +void send(radio_address_t dst, uint8_t len, uint8_t *data) { + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + + p.length = len; + p.dst = dst; + + p.data = data; + msg_send(&mesg, transceiver_pid, 1); +} + void shell_runner(void) { shell_init(&shell, sc, uart0_readc, uart0_putc); posix_open(uart0_handler_pid, 0); @@ -102,6 +118,7 @@ void radio(void) { for (i = 0; i < p->length; i++) { printf("%02X ", p->data[i]); } + send(p->src, p->length, p->data); p->processing--; printf("\n"); } diff --git a/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile index 685a316d8..2a13cb089 100644 --- a/projects/test_cc110x_ng/Jamfile +++ b/projects/test_cc110x_ng/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects test_cc110x_ng ; -Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer ; +Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer config ; UseModule test_cc110x_ng ; diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h index eddd4314d..3e528aeba 100644 --- a/sys/include/transceiver.h +++ b/sys/include/transceiver.h @@ -4,7 +4,11 @@ #include /* Stack size for transceiver thread */ +#ifdef ENABLE_DEBUG +#define TRANSCEIVER_STACK_SIZE (2048) +#else #define TRANSCEIVER_STACK_SIZE (512) +#endif /* The maximum of threads to register */ #define TRANSCEIVER_MAX_REGISTERED (4) diff --git a/sys/shell/cc1100_ng.c b/sys/shell/cc1100_ng.c index fe962d249..e837af03d 100644 --- a/sys/shell/cc1100_ng.c +++ b/sys/shell/cc1100_ng.c @@ -50,27 +50,33 @@ void _cc1100_ng_get_set_channel_handler(char *chan) { void _cc1100_ng_send_handler(char *pkt) { radio_packet_t p; uint32_t response; + uint16_t addr; + char *tok; + tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &p; - uint16_t addr; - addr = atoi(pkt+7); - memcpy(text_msg, "Text", 5); + tok = strtok(pkt+7, " "); + if (tok) { + addr = atoi(tok); + tok = strtok(NULL, " "); + if (tok) { + memset(text_msg, 0, TEXT_SIZE); + memcpy(text_msg, tok, strlen(tok)); /* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/ - if (1 == 1) { - 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:\ttxtsnd "); + p.data = (uint8_t*) text_msg; + p.length = strlen(text_msg) + 1; + 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); + return; + } } + puts("Usage:\ttxtsnd "); } void _cc1100_ng_monitor_handler(char *mode) { diff --git a/sys/transceiver.c b/sys/transceiver.c index 13de0a6fa..d0d5920e5 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -20,10 +20,6 @@ #endif //#define ENABLE_DEBUG (1) -#ifdef ENABLE_DEBUG -#undef TRANSCEIVER_BUFFER_SIZE -#define TRANSCEIVER_BUFFER_SIZE (2048) -#endif #include /*------------------------------------------------------------------------------------*/ From 6be1cf2a76237e7c9f61972c8713d842601e2b43 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 11 Dec 2010 12:09:20 +0100 Subject: [PATCH 145/199] [board/chronos board/msb-430h board/msba2-common drivers/cc110x_ng sys/shell sys/transceiver] * renamed all occurrences of cc1100 to cc110x as in fact all driver parts should work for cc1100 and cc110x as well [driver/cc110x_ng] * added some documentation * introduced a new register function to access rxfifo (fixing the of-by-one problem on chronos platform --- board/chronos/drivers/Jamfile | 2 +- .../{cc430-cc1100.c => cc430-cc110x.c} | 43 +++--- board/msb-430h/Jamfile | 2 +- .../{driver_cc1100.c => driver_cc110x.c} | 78 +++++------ board/msba2-common/drivers/Jamfile | 2 +- .../{msba2-cc1100.c => msba2-cc110x.c} | 50 +++---- drivers/cc110x_ng/Jamfile | 6 +- drivers/cc110x_ng/cc1100-reg.h | 12 -- .../{cc1100-arch.h => cc110x-arch.h} | 18 +-- .../{cc1100-config.h => cc110x-config.h} | 12 +- ...ultSettings.c => cc110x-defaultSettings.c} | 6 +- ...ultSettings.h => cc110x-defaultSettings.h} | 2 +- .../{cc1100-internal.h => cc110x-internal.h} | 2 +- drivers/cc110x_ng/cc110x-reg.h | 83 ++++++++++++ .../cc110x_ng/{cc1100-rx.c => cc110x-rx.c} | 58 ++++---- .../cc110x_ng/{cc1100-tx.c => cc110x-tx.c} | 36 ++--- drivers/cc110x_ng/{cc1100.c => cc110x.c} | 128 +++++++++--------- .../{cc1100_cc430.c => cc110x_cc430.c} | 48 +++++-- .../cc110x_ng/{cc1100_ng.h => cc110x_ng.h} | 53 ++++---- .../cc110x_ng/{cc1100_spi.c => cc110x_spi.c} | 74 +++++----- .../cc110x_ng/{cc1100_spi.h => cc110x_spi.h} | 16 +-- projects/chronos_cc110x_ng/main.c | 11 +- projects/test_cc110x_ng/main.c | 6 +- sys/shell/Jamfile | 2 +- sys/shell/{cc1100_ng.c => cc110x_ng.c} | 22 +-- sys/shell/shell_commands.c | 24 ++-- sys/transceiver.c | 42 +++--- 27 files changed, 468 insertions(+), 370 deletions(-) rename board/chronos/drivers/{cc430-cc1100.c => cc430-cc110x.c} (63%) rename board/msb-430h/{driver_cc1100.c => driver_cc110x.c} (84%) rename board/msba2-common/drivers/{msba2-cc1100.c => msba2-cc110x.c} (86%) delete mode 100644 drivers/cc110x_ng/cc1100-reg.h rename drivers/cc110x_ng/{cc1100-arch.h => cc110x-arch.h} (83%) rename drivers/cc110x_ng/{cc1100-config.h => cc110x-config.h} (94%) rename drivers/cc110x_ng/{cc1100-defaultSettings.c => cc110x-defaultSettings.c} (97%) rename drivers/cc110x_ng/{cc1100-defaultSettings.h => cc110x-defaultSettings.h} (98%) rename drivers/cc110x_ng/{cc1100-internal.h => cc110x-internal.h} (99%) create mode 100644 drivers/cc110x_ng/cc110x-reg.h rename drivers/cc110x_ng/{cc1100-rx.c => cc110x-rx.c} (69%) rename drivers/cc110x_ng/{cc1100-tx.c => cc110x-tx.c} (70%) rename drivers/cc110x_ng/{cc1100.c => cc110x.c} (70%) rename drivers/cc110x_ng/{cc1100_cc430.c => cc110x_cc430.c} (76%) rename drivers/cc110x_ng/{cc1100_ng.h => cc110x_ng.h} (73%) rename drivers/cc110x_ng/{cc1100_spi.c => cc110x_spi.c} (67%) rename drivers/cc110x_ng/{cc1100_spi.h => cc110x_spi.h} (87%) rename sys/shell/{cc1100_ng.c => cc110x_ng.c} (78%) diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index 221ba2ffb..4b2a0d0a8 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -1,4 +1,4 @@ SubDir TOP board chronos drivers ; Module board_display : display.c display1.c ; -Module board_cc1100 : cc430-cc1100.c : cc110x_cc430 ; +Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; diff --git a/board/chronos/drivers/cc430-cc1100.c b/board/chronos/drivers/cc430-cc110x.c similarity index 63% rename from board/chronos/drivers/cc430-cc1100.c rename to board/chronos/drivers/cc430-cc110x.c index 513cef3e5..78380c4ca 100644 --- a/board/chronos/drivers/cc430-cc1100.c +++ b/board/chronos/drivers/cc430-cc110x.c @@ -2,78 +2,79 @@ #include #include -#include -#include +#include +#include -#include -#include +//#include +#include +//#include #define CC1100_GDO0 (RF1AIN & BIT0) #define CC1100_GDO1 (RF1AIN & BIT1) #define CC1100_GDO2 (RF1AIN & BIT2) -int cc1100_get_gdo0(void) { +int cc110x_get_gdo0(void) { return CC1100_GDO0; } -int cc1100_get_gdo1(void) { +int cc110x_get_gdo1(void) { return CC1100_GDO1; } -int cc1100_get_gdo2(void) { +int cc110x_get_gdo2(void) { return CC1100_GDO2; } -void cc1100_before_send(void) +void cc110x_before_send(void) { // Disable GDO2 interrupt before sending packet - cc1100_gdo2_disable(); + cc110x_gdo2_disable(); } -void cc1100_after_send(void) +void cc110x_after_send(void) { // Enable GDO2 interrupt after sending packet - cc1100_gdo2_enable(); + cc110x_gdo2_enable(); } -void cc1100_gdo0_enable(void) { +void cc110x_gdo0_enable(void) { RF1AIFG &= ~BIT0; RF1AIE |= BIT0; } -void cc1100_gdo0_disable(void) { +void cc110x_gdo0_disable(void) { RF1AIE &= ~BIT0; RF1AIFG &= ~BIT0; } -void cc1100_gdo2_disable(void) { +void cc110x_gdo2_disable(void) { RF1AIFG &= ~BIT2; // Clear a pending interrupt RF1AIE &= ~BIT2; // Disable the interrupt } -void cc1100_gdo2_enable(void) { +void cc110x_gdo2_enable(void) { RF1AIFG &= ~BIT2; // Clear a pending interrupt RF1AIE |= BIT2; // Enable the interrupt } -void cc1100_init_interrupts(void) { +void cc110x_init_interrupts(void) { uint8_t state = disableIRQ(); /* Disable all interrupts */ - cc1100_gdo2_enable(); - cc1100_gdo0_disable(); + cc110x_gdo2_enable(); + cc110x_gdo0_disable(); restoreIRQ(state); /* Enable all interrupts */ } -interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ +interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc110x_isr(void){ __enter_isr(); /* Check IFG */ if (RF1AIV == RF1AIV_RFIFG2) { while (RF1AIN & BIT2); /* discard all further interrupts */ RF1AIV = 0; - cc1100_gdo2_irq(); + cc110x_gdo2_irq(); } if (RF1AIV == RF1AIV_RFIFG0) { - cc1100_gdo0_irq(); + cc110x_gdo0_irq(); RF1AIE &= ~BIT0; } __exit_isr(); diff --git a/board/msb-430h/Jamfile b/board/msb-430h/Jamfile index 588fede19..9f9ee47bf 100644 --- a/board/msb-430h/Jamfile +++ b/board/msb-430h/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430h ; -Module board_cc1100 : driver_cc1100.c : cc110x_spi ; +Module board_cc110x : driver_cc110x.c : cc110x_spi ; SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; diff --git a/board/msb-430h/driver_cc1100.c b/board/msb-430h/driver_cc110x.c similarity index 84% rename from board/msb-430h/driver_cc1100.c rename to board/msb-430h/driver_cc110x.c index 1e5af6e9f..a0967b272 100644 --- a/board/msb-430h/driver_cc1100.c +++ b/board/msb-430h/driver_cc110x.c @@ -23,8 +23,8 @@ Boston, MA 02111-1307, USA. */ #include #include -#include -#include +#include +#include #define CC1100_GDO0 (P2IN & 0x02) // read serial I/O (GDO0) #define CC1100_GDO1 (P3IN & 0x04) // read serial I/O (GDO1) @@ -39,61 +39,61 @@ Boston, MA 02111-1307, USA. */ volatile int abort_count; volatile int retry_count = 0; -void cc1100_gdo0_enable(void) +void cc110x_gdo0_enable(void) { P2IFG &= ~0x02; /* Clear IFG for GDO0 */ P2IE |= 0x02; /* Enable interrupt for GDO0 */ } -void cc1100_gdo0_disable(void) +void cc110x_gdo0_disable(void) { P2IE &= ~0x02; /* Disable interrupt for GDO0 */ P2IFG &= ~0x02; /* Clear IFG for GDO0 */ } -void cc1100_gdo2_enable(void) +void cc110x_gdo2_enable(void) { P2IFG &= ~0x01; /* Clear IFG for GDO2 */ P2IE |= 0x01; /* Enable interrupt for GDO2 */ } -void cc1100_gdo2_disable(void) +void cc110x_gdo2_disable(void) { P2IE &= ~0x01; /* Disable interrupt for GDO2 */ P2IFG &= ~0x01; /* Clear IFG for GDO2 */ } -void cc1100_before_send(void) +void cc110x_before_send(void) { // Disable GDO2 interrupt before sending packet - cc1100_gdo2_disable(); + cc110x_gdo2_disable(); } -void cc1100_after_send(void) +void cc110x_after_send(void) { // Enable GDO2 interrupt after sending packet - cc1100_gdo2_enable(); + cc110x_gdo2_enable(); } -int cc1100_get_gdo0(void) { +int cc110x_get_gdo0(void) { return CC1100_GDO0; } -int cc1100_get_gdo1(void) { +int cc110x_get_gdo1(void) { return CC1100_GDO1; } -int cc1100_get_gdo2(void) { +int cc110x_get_gdo2(void) { return CC1100_GDO2; } -void cc1100_spi_cs(void) +void cc110x_spi_cs(void) { CC1100_CS_LOW; } -uint8_t cc1100_txrx(uint8_t data) +uint8_t cc110x_txrx(uint8_t data) { /* Ensure TX Buf is empty */ long c = 0; @@ -103,20 +103,20 @@ uint8_t cc1100_txrx(uint8_t data) while(!(IFG1 & UTXIFG0)) { if (c++ == 1000000) - puts("cc1100_txrx alarm()"); + puts("cc110x_txrx alarm()"); } /* Wait for Byte received */ c = 0; while(!(IFG1 & URXIFG0)) { if (c++ == 1000000) - puts("cc1100_txrx alarm()"); + puts("cc110x_txrx alarm()"); } return RXBUF0; } -void cc1100_spi_select(void) +void cc110x_spi_select(void) { // Switch to GDO mode P3SEL &= ~0x04; @@ -147,11 +147,11 @@ void cc1100_spi_select(void) P3SEL |= 0x04; } -void cc1100_spi_unselect(void) { +void cc110x_spi_unselect(void) { CC1100_CS_HIGH; } -void cc1100_init_interrupts(void) +void cc110x_init_interrupts(void) { unsigned int state = disableIRQ(); /* Disable all interrupts */ P2SEL = 0x00; /* must be <> 1 to use interrupts */ @@ -163,7 +163,7 @@ void cc1100_init_interrupts(void) restoreIRQ(state); /* Enable all interrupts */ } -void cc1100_spi_init(uint8_t clockrate) +void cc110x_spi_init(uint8_t clockrate) { // Switch off async UART while(!(UTCTL0 & TXEPT)); // Wait for empty UxTXBUF register @@ -197,8 +197,8 @@ void cc1100_spi_init(uint8_t clockrate) // #include // #include // #include "type.h" -// #include "cc1100_defines.h" -// #include "driver_cc1100.h" +// #include "cc110x_defines.h" +// #include "driver_cc110x.h" // #include "driver_system.h" // #include "spi0.h" // @@ -213,17 +213,17 @@ void cc1100_spi_init(uint8_t clockrate) // // void spiInitTrx(void) // // // // DESCRIPTION: -// // This function puts the cc1100 into spi mode. You have to call this bevore every spi transaction. +// // This function puts the cc110x into spi mode. You have to call this bevore every spi transaction. // // // //------------------------------------------------------------------------------------------------------- // // -// void drivercc1100_spiwriteburstreg(uint8_t addr, unsigned char *buffer, uint8_t count) +// void drivercc110x_spiwriteburstreg(uint8_t addr, unsigned char *buffer, uint8_t count) // { // uint8_t i; // long c; -// drivercc1100_spiinittrx(); -// drivercc1100_trxspi(addr | CC1100_WRITE_BURST); +// drivercc110x_spiinittrx(); +// drivercc110x_trxspi(addr | CC1100_WRITE_BURST); // for (i = 0; i < count; i++) // { // c = 0; @@ -247,11 +247,11 @@ void cc1100_spi_init(uint8_t clockrate) // CC1100_CS_HIGH; // } // -// void drivercc1100_spireadburstreg(uint8_t addr, char *buffer, uint8_t count) +// void drivercc110x_spireadburstreg(uint8_t addr, char *buffer, uint8_t count) // { // uint8_t i; -// drivercc1100_spiinittrx(); -// drivercc1100_trxspi(addr | CC1100_READ_BURST); +// drivercc110x_spiinittrx(); +// drivercc110x_trxspi(addr | CC1100_READ_BURST); // for (i = 0; i < count; i++) // { // long c = 0; @@ -275,21 +275,21 @@ void cc1100_spi_init(uint8_t clockrate) // CC1100_CS_HIGH; // } // -// void drivercc1100_load(callback_t cs_cb,callback_t paket_cb) +// void drivercc110x_load(callback_t cs_cb,callback_t paket_cb) // { // _paket_cb = paket_cb; // _cs_cb = cs_cb; // spi0_init(0); // } // -// void drivercc1100_aftersend(void) +// void drivercc110x_aftersend(void) // { // CLEAR(P2IFG, 0x01); // SET(P2IE, 0x01); /* Enable interrupts on port 2 pin 0 */ // CLEAR(P4OUT, 0x08); /* Turn off Sending Led*/ // } // -// void drivercc1100_initinterrupts(void) +// void drivercc110x_initinterrupts(void) // { // _DINT(); /* Disable all interrupts */ // P2SEL = 0x00; /* must be <> 1 to use interrupts */ @@ -301,7 +301,7 @@ void cc1100_spi_init(uint8_t clockrate) // _EINT(); /* Enable all interrupts */ // } // -// void drivercc1100_beforesend(void) +// void drivercc110x_beforesend(void) // { // /* Turn on Led while sending paket for debug reasons */ // SET(P4OUT, 0x08); @@ -319,21 +319,21 @@ void cc1100_spi_init(uint8_t clockrate) /* * CC1100 receive interrupt */ -interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ +interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc110x_isr(void){ __enter_isr(); -puts("cc1100_isr()"); +puts("cc110x_isr()"); // if (system_state.POWERDOWN) SPI_INIT; /* Initialize SPI after wakeup */ /* Check IFG */ if ((P2IFG & 0x01) != 0) { P2IFG &= ~0x01; - cc1100_gdo2_irq(); + cc110x_gdo2_irq(); } else if ((P2IFG & 0x02) != 0) { - cc1100_gdo0_irq(); + cc110x_gdo0_irq(); P2IE &= ~0x02; // Disable interrupt for GDO0 P2IFG &= ~0x02; // Clear IFG for GDO0 } else { - puts("cc1100_isr(): unexpected IFG!"); + puts("cc110x_isr(): unexpected IFG!"); /* Should not occur - only Port 2 Pin 0 interrupts are enabled */ // CLEAR(P2IFG, 0xFF); /* Clear all flags */ } diff --git a/board/msba2-common/drivers/Jamfile b/board/msba2-common/drivers/Jamfile index c0f4138ab..ed8e73498 100644 --- a/board/msba2-common/drivers/Jamfile +++ b/board/msba2-common/drivers/Jamfile @@ -1,6 +1,6 @@ SubDir TOP board msba2-common drivers ; -Module board_cc1100 : msba2-cc1100.c : cc110x_spi gpioint ; +Module board_cc110x : msba2-cc110x.c : cc110x_spi gpioint ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; Module board_uart : msba2-uart0.c : chardev_thread ringbuffer ; diff --git a/board/msba2-common/drivers/msba2-cc1100.c b/board/msba2-common/drivers/msba2-cc110x.c similarity index 86% rename from board/msba2-common/drivers/msba2-cc1100.c rename to board/msba2-common/drivers/msba2-cc110x.c index 327720c1f..7d5a6b219 100644 --- a/board/msba2-common/drivers/msba2-cc1100.c +++ b/board/msba2-common/drivers/msba2-cc110x.c @@ -34,7 +34,7 @@ and the mailinglist (subscription via web site) * @author Thomas Hillebrandt * @version $Revision: 1781 $ * - * @note $Id: msba2-cc1100.c 1781 2010-01-26 13:39:36Z hillebra $ + * @note $Id: msba2-cc110x.c 1781 2010-01-26 13:39:36Z hillebra $ */ #include @@ -43,10 +43,10 @@ and the mailinglist (subscription via web site) #include #include // sys -#include "cc1100.h" -#include "arch_cc1100.h" -#include "cc1100_spi.h" -#include "gpioint.h" +#include +#include +#include +#include #define CC1100_GDO0 (FIO0PIN & BIT27) // read serial I/O (GDO0) #define CC1100_GDO1 (FIO1PIN & BIT23) // read serial I/O (GDO1) @@ -82,19 +82,19 @@ static int test_time(int code) { } #endif -int cc1100_get_gdo0(void) { +int cc110x_get_gdo0(void) { return CC1100_GDO0; } -int cc1100_get_gdo1(void) { +int cc110x_get_gdo1(void) { return CC1100_GDO1; } -int cc1100_get_gdo2(void) { +int cc110x_get_gdo2(void) { return CC1100_GDO2; } -void cc1100_spi_init(void) +void cc110x_spi_init(void) { // configure chip-select FIO1DIR |= BIT21; @@ -128,7 +128,7 @@ void cc1100_spi_init(void) } } -uint8_t cc1100_txrx(uint8_t c) { +uint8_t cc110x_txrx(uint8_t c) { uint8_t result; SSP0DR = c; #ifdef DEBUG @@ -159,13 +159,13 @@ uint8_t cc1100_txrx(uint8_t c) { return result; } -void cc1100_spi_cs(void) +void cc110x_spi_cs(void) { FIO1CLR = BIT21; } void -cc1100_spi_select(void) +cc110x_spi_select(void) { volatile int retry_count = 0; volatile int abort_count; @@ -199,44 +199,44 @@ cc1100_spi_select(void) } void -cc1100_spi_unselect(void) +cc110x_spi_unselect(void) { FIO1SET = BIT21; } -void cc1100_before_send(void) +void cc110x_before_send(void) { // Disable GDO2 interrupt before sending packet - cc1100_gdo2_disable(); + cc110x_gdo2_disable(); } -void cc1100_after_send(void) +void cc110x_after_send(void) { // Enable GDO2 interrupt after sending packet - cc1100_gdo2_enable(); + cc110x_gdo2_enable(); } -void cc1100_gdo0_enable(void) { - gpioint_set(0, BIT27, GPIOINT_RISING_EDGE, &cc1100_gdo0_irq); +void cc110x_gdo0_enable(void) { + gpioint_set(0, BIT27, GPIOINT_RISING_EDGE, &cc110x_gdo0_irq); } -void cc1100_gdo0_disable(void) { +void cc110x_gdo0_disable(void) { gpioint_set(0, BIT27, GPIOINT_DISABLE, NULL); } -void cc1100_gdo2_disable(void) { +void cc110x_gdo2_disable(void) { gpioint_set(0, BIT28, GPIOINT_DISABLE, NULL); } -void cc1100_gdo2_enable(void) { - gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc1100_gdo2_irq); +void cc110x_gdo2_enable(void) { + gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc110x_gdo2_irq); } -void cc1100_init_interrupts(void) +void cc110x_init_interrupts(void) { // Enable external interrupt on low edge (for GDO2) FIO0DIR &= ~BIT28; - cc1100_gdo2_enable(); + cc110x_gdo2_enable(); // Enable external interrupt on low edge (for GDO0) FIO0DIR &= ~BIT27; } diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index f3c0bc934..cf44c787a 100755 --- a/drivers/cc110x_ng/Jamfile +++ b/drivers/cc110x_ng/Jamfile @@ -29,6 +29,6 @@ SubDir TOP drivers cc110x_ng ; HDRS += $(TOP)/drivers/cc110x_ng ; -Module cc110x_ng : cc1100.c cc1100-rx.c cc1100-tx.c cc1100-defaultSettings.c : hwtimer board_cc1100 ; -Module cc110x_spi : cc1100_spi.c ; -Module cc110x_cc430 : cc1100_cc430.c ; +Module cc110x_ng : cc110x.c cc110x-rx.c cc110x-tx.c cc110x-defaultSettings.c : hwtimer board_cc110x ; +Module cc110x_spi : cc110x_spi.c ; +Module cc110x_cc430 : cc110x_cc430.c ; diff --git a/drivers/cc110x_ng/cc1100-reg.h b/drivers/cc110x_ng/cc1100-reg.h deleted file mode 100644 index f4b97f7f7..000000000 --- a/drivers/cc110x_ng/cc1100-reg.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef CC110X_REG_H -#define CC110X_REG_H -#include - -uint8_t cc1100_writeburst_reg(uint8_t addr, char *buffer, uint8_t count); -void cc1100_readburst_reg(uint8_t addr, char *buffer, uint8_t count); -void cc1100_write_reg(uint8_t addr, uint8_t value); -uint8_t cc1100_read_reg(uint8_t addr); -uint8_t cc1100_read_status(uint8_t addr); -uint8_t cc1100_strobe(uint8_t c); - -#endif diff --git a/drivers/cc110x_ng/cc1100-arch.h b/drivers/cc110x_ng/cc110x-arch.h similarity index 83% rename from drivers/cc110x_ng/cc1100-arch.h rename to drivers/cc110x_ng/cc110x-arch.h index ef61dd61c..3a990b1ba 100644 --- a/drivers/cc110x_ng/cc1100-arch.h +++ b/drivers/cc110x_ng/cc110x-arch.h @@ -33,18 +33,18 @@ and the mailinglist (subscription via web site) * @author Heiko Will * @version $Revision: 1775 $ * - * @note $Id: arch_cc1100.h 1775 2010-01-26 09:37:03Z hillebra $ + * @note $Id: arch_cc110x.h 1775 2010-01-26 09:37:03Z hillebra $ */ #include -uint8_t cc1100_txrx(uint8_t c); +uint8_t cc110x_txrx(uint8_t c); -void cc1100_gdo0_enable(void); -void cc1100_gdo0_disable(void); -void cc1100_gdo2_enable(void); -void cc1100_gdo2_disable(void); -void cc1100_init_interrupts(void); +void cc110x_gdo0_enable(void); +void cc110x_gdo0_disable(void); +void cc110x_gdo2_enable(void); +void cc110x_gdo2_disable(void); +void cc110x_init_interrupts(void); -void cc1100_before_send(void); -void cc1100_after_send(void); +void cc110x_before_send(void); +void cc110x_after_send(void); diff --git a/drivers/cc110x_ng/cc1100-config.h b/drivers/cc110x_ng/cc110x-config.h similarity index 94% rename from drivers/cc110x_ng/cc1100-config.h rename to drivers/cc110x_ng/cc110x-config.h index 11e940cd8..3531d71df 100644 --- a/drivers/cc110x_ng/cc1100-config.h +++ b/drivers/cc110x_ng/cc110x-config.h @@ -45,13 +45,13 @@ typedef struct { uint8_t _FSCAL2; uint8_t _FSCAL1; uint8_t _FSCAL0; -} cc1100_reg_t; +} cc110x_reg_t; /** CC1100 radio configuration */ typedef struct { - cc1100_reg_t reg_cfg; ///< CC1100 register configuration + cc110x_reg_t reg_cfg; ///< CC1100 register configuration uint8_t pa_power; ///< Output power setting -} cc1100_cfg_t; +} cc110x_cfg_t; /** * @brief Radio Control Flags @@ -74,12 +74,12 @@ typedef struct 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; +} cc110x_flags; /** * @brief Statistic interface for debugging */ -typedef struct cc1100_statistic { +typedef struct cc110x_statistic { uint32_t packets_in; uint32_t packets_in_crc_fail; uint32_t packets_in_while_tx; @@ -91,6 +91,6 @@ typedef struct cc1100_statistic { uint32_t acks_send; uint32_t rx_buffer_max; uint32_t watch_dog_resets; -} cc1100_statistic_t; +} cc110x_statistic_t; #endif diff --git a/drivers/cc110x_ng/cc1100-defaultSettings.c b/drivers/cc110x_ng/cc110x-defaultSettings.c similarity index 97% rename from drivers/cc110x_ng/cc1100-defaultSettings.c rename to drivers/cc110x_ng/cc110x-defaultSettings.c index 6eb9ae232..dc15fbd23 100644 --- a/drivers/cc110x_ng/cc1100-defaultSettings.c +++ b/drivers/cc110x_ng/cc110x-defaultSettings.c @@ -38,10 +38,10 @@ and the mailinglist (subscription via web site) * @author Heiko Will * @version $Revision: 2058 $ * - * @note $Id: cc1100-defaultSettings.c 2058 2010-03-31 08:59:31Z hillebra $ + * @note $Id: cc110x-defaultSettings.c 2058 2010-03-31 08:59:31Z hillebra $ */ -#include +#include /** * Usable, non overlapping channels and corresponding frequencies @@ -77,7 +77,7 @@ and the mailinglist (subscription via web site) */ // 400 kbps, MSK, X-tal: 26 MHz (Chip Revision F) -char cc1100_conf[] = { +char cc110x_conf[] = { 0x06, // IOCFG2 0x2E, // IOCFG1 0x0E, // IOCFG0 diff --git a/drivers/cc110x_ng/cc1100-defaultSettings.h b/drivers/cc110x_ng/cc110x-defaultSettings.h similarity index 98% rename from drivers/cc110x_ng/cc1100-defaultSettings.h rename to drivers/cc110x_ng/cc110x-defaultSettings.h index d3c92d4a0..d15a45cd5 100644 --- a/drivers/cc110x_ng/cc1100-defaultSettings.h +++ b/drivers/cc110x_ng/cc110x-defaultSettings.h @@ -41,7 +41,7 @@ and the mailinglist (subscription via web site) * @author Heiko Will * @version $Revision: 2139 $ * - * @note $Id: cc1100-defaultSettings.h 2139 2010-05-26 08:04:04Z hillebra $ + * @note $Id: cc110x-defaultSettings.h 2139 2010-05-26 08:04:04Z hillebra $ */ #include diff --git a/drivers/cc110x_ng/cc1100-internal.h b/drivers/cc110x_ng/cc110x-internal.h similarity index 99% rename from drivers/cc110x_ng/cc1100-internal.h rename to drivers/cc110x_ng/cc110x-internal.h index bf7309db9..409c3b988 100644 --- a/drivers/cc110x_ng/cc1100-internal.h +++ b/drivers/cc110x_ng/cc110x-internal.h @@ -42,7 +42,7 @@ and the mailinglist (subscription via web site) * @author Heiko Will * @version $Revision: 1231 $ * - * @note $Id: cc1100-internal.h 1231 2009-08-20 08:31:32Z baar $ + * @note $Id: cc110x-internal.h 1231 2009-08-20 08:31:32Z baar $ */ #define FIXED_PKTLEN (0x00) ///< Fixed length packets, length configured in PKTLEN register. diff --git a/drivers/cc110x_ng/cc110x-reg.h b/drivers/cc110x_ng/cc110x-reg.h new file mode 100644 index 000000000..02756ca5f --- /dev/null +++ b/drivers/cc110x_ng/cc110x-reg.h @@ -0,0 +1,83 @@ +/** + * @file cc110x-reg.h + * @ingroup dev_cc110x_ng + * @brief Access to CC110X registers + * + * @author Freie Uniersität Berlin, Computer Systems & Telematics, µkleos + * @author Oliver Hahm + +/** + * @brief Write a set of bytes using burst mode (if available) + * + * @param addr Destination register + * @param buffer Data to be written + * @param count Size of data + * + * @return Written bytes + */ +uint8_t cc110x_writeburst_reg(uint8_t addr, char *buffer, uint8_t count); + +/** + * @brief Read a set of bytes using burst mode (if available) + * + * @param addr Source register + * @param buffer Buffer to store read data + * @param count Size of data to be read + */ +void cc110x_readburst_reg(uint8_t addr, char *buffer, uint8_t count); + +/** + * @brief Read bytes from RXFIFO + * + * @param buffer Buffer to store read data + * @param count Size of data to be read + * + * @note: Calls cc110x_readburst_reg if not dedicated fifo read command + * available + */ +void cc110x_read_fifo(char *buffer, uint8_t count); + +/** + * @brief Write one byte to a register + * + * @param addr Destinatoin register + * @param value New value + */ +void cc110x_write_reg(uint8_t addr, uint8_t value); + +/** + * @brief Read a byte from register + * + * @param addr Source register + * + * @return Read state and value of register + */ +uint8_t cc110x_read_reg(uint8_t addr); + +/** + * @brief Read state of a register + * + * @param addr Source register + * + * @return State of register + */ +uint8_t cc110x_read_status(uint8_t addr); + +/** + * @brief Sends a command strobe + * + * @param c Command code + * + * @return Command response + */ +uint8_t cc110x_strobe(uint8_t c); + +#endif diff --git a/drivers/cc110x_ng/cc1100-rx.c b/drivers/cc110x_ng/cc110x-rx.c similarity index 69% rename from drivers/cc110x_ng/cc1100-rx.c rename to drivers/cc110x_ng/cc110x-rx.c index 052f576ca..7b2229169 100644 --- a/drivers/cc110x_ng/cc1100-rx.c +++ b/drivers/cc110x_ng/cc110x-rx.c @@ -1,9 +1,9 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -15,37 +15,37 @@ 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 +rx_buffer_t cc110x_rx_buffer[RX_BUF_SIZE]; ///< RX buffer volatile uint8_t rx_buffer_next; ///< Next packet in RX queue -void cc1100_rx_handler(void) { +void cc110x_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++; + cc110x_statistic.packets_in++; - res = receive_packet((uint8_t*)&(cc1100_rx_buffer[rx_buffer_next].packet), sizeof(cc1100_packet_t)); + res = receive_packet((uint8_t*)&(cc110x_rx_buffer[rx_buffer_next].packet), sizeof(cc110x_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++; + cc110x_statistic.packets_in_while_tx++; return; } - cc1100_rx_buffer[rx_buffer_next].rssi = rflags._RSSI; - cc1100_rx_buffer[rx_buffer_next].lqi = rflags._LQI; - cc1100_strobe(CC1100_SFRX); // ...for flushing the RX FIFO + cc110x_rx_buffer[rx_buffer_next].rssi = rflags._RSSI; + cc110x_rx_buffer[rx_buffer_next].lqi = rflags._LQI; + cc110x_strobe(CC1100_SFRX); // ...for flushing the RX FIFO // 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_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME (until end of packet) - cc1100_strobe(CC1100_SRX); + //cc110x_spi_write_reg(CC1100_MCSM0, 0x08); // Turn off FS-Autocal + cc110x_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME (until end of packet) + cc110x_strobe(CC1100_SRX); hwtimer_wait(IDLE_TO_RX_TIME); radio_state = RADIO_RX; @@ -69,26 +69,26 @@ void cc1100_rx_handler(void) { rflags.TOF = 0; // CRC false or RX buffer full -> clear RX FIFO in both cases - cc1100_strobe(CC1100_SIDLE); // Switch to IDLE (should already be)... - cc1100_strobe(CC1100_SFRX); // ...for flushing the RX FIFO + cc110x_strobe(CC1100_SIDLE); // Switch to IDLE (should already be)... + cc110x_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_strobe(CC1100_SRX); + cc110x_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++; + cc110x_statistic.packets_in_while_tx++; return; } // No valid packet, so go back to RX/WOR as soon as possible - cc1100_switch_to_rx(); + cc110x_switch_to_rx(); } } @@ -98,11 +98,11 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { uint8_t packetLength = 0; /* Any bytes available in RX FIFO? */ - if ((cc1100_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { + if ((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { //LED_GREEN_TOGGLE; //LED_RED_TOGGLE; // Read length byte (first byte in RX FIFO) - packetLength = cc1100_read_reg(CC1100_RXFIFO); + cc110x_read_fifo((char*) &packetLength, 1); // Read data from RX FIFO and store in rxBuffer if (packetLength <= length) { @@ -110,11 +110,11 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { rxBuffer[0] = packetLength; // Read the rest of the packet - // TODO: Offset + 2 here for cc430 - cc1100_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); + //cc110x_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); + cc110x_read_fifo((char*) rxBuffer + 1, packetLength); // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) - cc1100_readburst_reg(CC1100_RXFIFO, (char*)status, 2); + cc110x_readburst_reg(CC1100_RXFIFO, (char*)status, 2); // Store RSSI value of packet rflags._RSSI = status[I_RSSI]; @@ -122,7 +122,7 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { // 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++; + cc110x_statistic.packets_in_crc_fail++; } // Bit 0-6 of LQI indicates the link quality (LQI) @@ -145,7 +145,7 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { } static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length) { - uint8_t pkt_len_cfg = cc1100_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; + uint8_t pkt_len_cfg = cc110x_read_reg(CC1100_PKTCTRL0) & PKT_LENGTH_CONFIG; if (pkt_len_cfg == VARIABLE_PKTLEN) { return receive_packet_variable(rxBuffer, length); diff --git a/drivers/cc110x_ng/cc1100-tx.c b/drivers/cc110x_ng/cc110x-tx.c similarity index 70% rename from drivers/cc110x_ng/cc1100-tx.c rename to drivers/cc110x_ng/cc110x-tx.c index d85233ecc..bffb8339d 100644 --- a/drivers/cc110x_ng/cc1100-tx.c +++ b/drivers/cc110x_ng/cc110x-tx.c @@ -1,17 +1,17 @@ #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include -uint8_t cc1100_send(cc1100_packet_t *packet) { +uint8_t cc110x_send(cc110x_packet_t *packet) { volatile uint32_t abort_count; uint8_t size; /* TODO: burst sending */ @@ -33,23 +33,23 @@ uint8_t cc1100_send(cc1100_packet_t *packet) { return 0; } - packet->phy_src = cc1100_get_address(); + packet->phy_src = cc110x_get_address(); // Disables RX interrupt etc. - cc1100_before_send(); + cc110x_before_send(); // But CC1100 in IDLE mode to flush the FIFO - cc1100_strobe(CC1100_SIDLE); + cc110x_strobe(CC1100_SIDLE); // Flush TX FIFO to be sure it is empty - cc1100_strobe(CC1100_SFTX); + cc110x_strobe(CC1100_SFTX); // Write packet into TX FIFO - cc1100_writeburst_reg(CC1100_TXFIFO, (char*) packet, size); + cc110x_writeburst_reg(CC1100_TXFIFO, (char*) packet, size); // Switch to TX mode abort_count = 0; unsigned int cpsr = disableIRQ(); - cc1100_strobe(CC1100_STX); + cc110x_strobe(CC1100_STX); // Wait for GDO2 to be set -> sync word transmitted - while (cc1100_get_gdo2() == 0) { + while (cc110x_get_gdo2() == 0) { abort_count++; if (abort_count > CC1100_SYNC_WORD_TX_TIME) { // Abort waiting. CC1100 maybe in wrong mode @@ -60,18 +60,18 @@ uint8_t cc1100_send(cc1100_packet_t *packet) { } restoreIRQ(cpsr); // Wait for GDO2 to be cleared -> end of packet - while (cc1100_get_gdo2() != 0); + while (cc110x_get_gdo2() != 0); //LED_GREEN_TOGGLE; // Experimental - TOF Measurement - cc1100_after_send(); - cc1100_statistic.raw_packets_out++; + cc110x_after_send(); + cc110x_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(); + cc110x_switch_to_rx(); return true; } diff --git a/drivers/cc110x_ng/cc1100.c b/drivers/cc110x_ng/cc110x.c similarity index 70% rename from drivers/cc110x_ng/cc1100.c rename to drivers/cc110x_ng/cc110x.c index 20667db9f..243c3c411 100644 --- a/drivers/cc110x_ng/cc1100.c +++ b/drivers/cc110x_ng/cc110x.c @@ -1,10 +1,10 @@ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -18,9 +18,9 @@ extern uint8_t pa_table_index; ///< Current PATABLE Index /* global variables */ -cc1100_statistic_t cc1100_statistic; +cc110x_statistic_t cc110x_statistic; -volatile cc1100_flags rflags; ///< Radio control flags +volatile cc110x_flags rflags; ///< Radio control flags volatile uint8_t radio_state = RADIO_UNKNOWN; ///< Radio state static radio_address_t radio_address; ///< Radio address @@ -37,7 +37,7 @@ static void write_register(uint8_t r, uint8_t value); /*---------------------------------------------------------------------------*/ // Radio Driver API /*---------------------------------------------------------------------------*/ -void cc1100_init(int tpid) { +void cc110x_init(int tpid) { transceiver_pid = tpid; DEBUG("Transceiver PID: %i\n", transceiver_pid); @@ -45,17 +45,17 @@ void cc1100_init(int tpid) { #ifdef MODULE_CC110X_SPI /* Initialize SPI */ - cc1100_spi_init(); + cc110x_spi_init(); #endif /* Load driver & reset */ power_up_reset(); /* Write configuration to configuration registers */ - cc1100_writeburst_reg(0x00, cc1100_conf, CC1100_CONF_SIZE); + cc110x_writeburst_reg(0x00, cc110x_conf, CC1100_CONF_SIZE); /* Write PATABLE (power settings) */ - cc1100_write_reg(CC1100_PATABLE, pa_table[pa_table_index]); + cc110x_write_reg(CC1100_PATABLE, pa_table[pa_table_index]); /* Initialize Radio Flags */ rflags._RSSI = 0x00; @@ -70,9 +70,9 @@ void cc1100_init(int tpid) { /* Set default channel number */ #ifdef MODULE_CONFIG - cc1100_set_config_channel(sysconfig.radio_channel); + cc110x_set_config_channel(sysconfig.radio_channel); #else - cc1100_set_channel(CC1100_DEFAULT_CHANNR); + cc110x_set_channel(CC1100_DEFAULT_CHANNR); #endif DEBUG("CC1100 initialized and set to channel %i\n", radio_channel); @@ -80,31 +80,31 @@ void cc1100_init(int tpid) { rd_set_mode(RADIO_MODE_ON); } -void cc1100_disable_interrupts(void) { - cc1100_gdo2_disable(); - cc1100_gdo0_disable(); +void cc110x_disable_interrupts(void) { + cc110x_gdo2_disable(); + cc110x_gdo0_disable(); } -void cc1100_gdo0_irq(void) { +void cc110x_gdo0_irq(void) { // Air was not free -> Clear CCA flag rflags.CAA = false; // Disable carrier sense detection (GDO0 interrupt) - cc1100_gdo0_disable(); + cc110x_gdo0_disable(); } -void cc1100_gdo2_irq(void) { - cc1100_rx_handler(); +void cc110x_gdo2_irq(void) { + cc110x_rx_handler(); } -uint8_t cc1100_get_buffer_pos(void) { +uint8_t cc110x_get_buffer_pos(void) { return (rx_buffer_next-1); } -radio_address_t cc1100_get_address() { +radio_address_t cc110x_get_address() { return radio_address; } -radio_address_t cc1100_set_address(radio_address_t address) { +radio_address_t cc110x_set_address(radio_address_t address) { if ((address < MIN_UID) || (address > MAX_UID)) { return 0; } @@ -119,8 +119,8 @@ radio_address_t cc1100_set_address(radio_address_t address) { } #ifdef MODULE_CONFIG -radio_address_t cc1100_set_config_address(radio_address_t address) { - radio_address_t a = cc1100_set_address(address); +radio_address_t cc110x_set_config_address(radio_address_t address) { + radio_address_t a = cc110x_set_address(address); if (a) { sysconfig.radio_address = a; } @@ -129,7 +129,7 @@ radio_address_t cc1100_set_config_address(radio_address_t address) { } #endif -void cc1100_set_monitor(uint8_t mode) { +void cc110x_set_monitor(uint8_t mode) { if (mode) { write_register(CC1100_PKTCTRL1, (0x04)); } @@ -138,43 +138,43 @@ void cc1100_set_monitor(uint8_t mode) { } } -void cc1100_setup_rx_mode(void) { +void cc110x_setup_rx_mode(void) { // Stay in RX mode until end of packet - cc1100_write_reg(CC1100_MCSM2, 0x07); - cc1100_switch_to_rx(); + cc110x_write_reg(CC1100_MCSM2, 0x07); + cc110x_switch_to_rx(); } -void cc1100_switch_to_rx(void) { +void cc110x_switch_to_rx(void) { radio_state = RADIO_RX; - cc1100_strobe(CC1100_SRX); + cc110x_strobe(CC1100_SRX); } -void cc1100_wakeup_from_rx(void) { +void cc110x_wakeup_from_rx(void) { if (radio_state != RADIO_RX) { return; } DEBUG("CC1100 going to idle\n"); - cc1100_strobe(CC1100_SIDLE); + cc110x_strobe(CC1100_SIDLE); radio_state = RADIO_IDLE; } -char* cc1100_get_marc_state(void) { +char* cc110x_get_marc_state(void) { uint8_t state; // Save old radio state uint8_t old_state = radio_state; // Read content of status register - state = cc1100_read_status(CC1100_MARCSTATE) & MARC_STATE; + state = cc110x_read_status(CC1100_MARCSTATE) & MARC_STATE; // Make sure in IDLE state. // Only goes to IDLE if state was RX/WOR - cc1100_wakeup_from_rx(); + cc110x_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(); + cc110x_switch_to_rx(); } switch (state) @@ -198,7 +198,7 @@ char* cc1100_get_marc_state(void) { } } -char* cc1100_state_to_text(uint8_t state) { +char* cc110x_state_to_text(uint8_t state) { switch (state) { case RADIO_UNKNOWN: @@ -222,22 +222,22 @@ char* cc1100_state_to_text(uint8_t state) { } } -void cc1100_print_config(void) { - printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); - printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); +void cc110x_print_config(void) { + printf("Current radio state: %s\r\n", cc110x_state_to_text(radio_state)); + printf("Current MARC state: %s\r\n", cc110x_get_marc_state()); printf("Current channel number: %u\r\n", radio_channel); } -void cc1100_switch_to_pwd(void) { +void cc110x_switch_to_pwd(void) { DEBUG("[cc110x_ng] switching to powerdown\n"); - cc1100_wakeup_from_rx(); - cc1100_strobe(CC1100_SPWD); + cc110x_wakeup_from_rx(); + cc110x_strobe(CC1100_SPWD); radio_state = RADIO_PWD; } /*---------------------------------------------------------------------------*/ -int16_t cc1100_set_channel(uint8_t channr) { - uint8_t state = cc1100_read_status(CC1100_MARCSTATE) & MARC_STATE; +int16_t cc110x_set_channel(uint8_t channr) { + uint8_t state = cc110x_read_status(CC1100_MARCSTATE) & MARC_STATE; if ((state != 1) && (channr > MAX_CHANNR)) { return -1; } @@ -247,8 +247,8 @@ int16_t cc1100_set_channel(uint8_t channr) { } #ifdef MODULE_CONFIG -int16_t cc1100_set_config_channel(uint8_t channr) { - int16_t c = cc1100_set_channel(channr); +int16_t cc110x_set_config_channel(uint8_t channr) { + int16_t c = cc110x_set_channel(channr); if (c) { sysconfig.radio_channel = c; } @@ -257,7 +257,7 @@ int16_t cc1100_set_config_channel(uint8_t channr) { } #endif -int16_t cc1100_get_channel(void) { +int16_t cc110x_get_channel(void) { return radio_channel; } @@ -267,19 +267,19 @@ int16_t cc1100_get_channel(void) { /*---------------------------------------------------------------------------*/ static void reset(void) { - cc1100_wakeup_from_rx(); + cc110x_wakeup_from_rx(); #ifdef MODULE_CC110x_SPI - cc1100_spi_select(); + cc110x_spi_select(); #endif - cc1100_strobe(CC1100_SRES); + cc110x_strobe(CC1100_SRES); hwtimer_wait(RTIMER_TICKS(100)); } static void power_up_reset(void) { #ifdef MODULE_CC110x_SPI - cc1100_spi_unselect(); - cc1100_spi_cs(); - cc1100_spi_unselect(); + cc110x_spi_unselect(); + cc110x_spi_cs(); + cc110x_spi_unselect(); #endif hwtimer_wait(RESET_WAIT_TIME); reset(); @@ -291,13 +291,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) */ - cc1100_wakeup_from_rx(); - cc1100_write_reg(r, value); + cc110x_wakeup_from_rx(); + cc110x_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)) { - cc1100_switch_to_rx(); + cc110x_switch_to_rx(); } } @@ -315,12 +315,12 @@ 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 + cc110x_init_interrupts(); // Enable interrupts + cc110x_setup_rx_mode(); // Set chip to desired mode break; case RADIO_MODE_OFF: - cc1100_disable_interrupts(); // Disable interrupts - cc1100_switch_to_pwd(); // Set chip to power down mode + cc110x_disable_interrupts(); // Disable interrupts + cc110x_switch_to_pwd(); // Set chip to power down mode break; case RADIO_MODE_GET: // do nothing, just return current mode diff --git a/drivers/cc110x_ng/cc1100_cc430.c b/drivers/cc110x_ng/cc110x_cc430.c similarity index 76% rename from drivers/cc110x_ng/cc1100_cc430.c rename to drivers/cc110x_ng/cc110x_cc430.c index 3eb9751d4..66b0d09dd 100644 --- a/drivers/cc110x_ng/cc1100_cc430.c +++ b/drivers/cc110x_ng/cc110x_cc430.c @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include #include #include #include @@ -11,7 +11,7 @@ // @param none // @return none // ************************************************************************************************* -uint8_t cc1100_strobe(uint8_t c) { +uint8_t cc110x_strobe(uint8_t c) { uint8_t statusByte = 0; uint16_t int_state, gdo_state; @@ -29,8 +29,8 @@ uint8_t cc1100_strobe(uint8_t c) { if ((c > RF_SRES) && (c < RF_SNOP)) { - gdo_state = cc1100_read_reg(IOCFG2); // buffer IOCFG2 state - cc1100_write_reg(IOCFG2, 0x29); // c-ready to GDO2 + gdo_state = cc110x_read_reg(IOCFG2); // buffer IOCFG2 state + cc110x_write_reg(IOCFG2, 0x29); // c-ready to GDO2 RF1AINSTRB = c; if ((RF1AIN & 0x04) == 0x04 ) // chip at sleep mode @@ -42,7 +42,7 @@ uint8_t cc1100_strobe(uint8_t c) { hwtimer_wait(RTIMER_TICKS(9800)); // Delay for ~810usec at 12MHz CPU clock } } - cc1100_write_reg(IOCFG2, gdo_state); // restore IOCFG2 setting + cc110x_write_reg(IOCFG2, gdo_state); // restore IOCFG2 setting } else // chip active mode { @@ -57,12 +57,12 @@ uint8_t cc1100_strobe(uint8_t c) { // ************************************************************************************************* -// @fn cc1100_read_reg +// @fn cc110x_read_reg // @brief Read byte from register. // @param none // @return none // ************************************************************************************************* -uint8_t cc1100_read_reg(uint8_t addr) { +uint8_t cc110x_read_reg(uint8_t addr) { unsigned char x; uint16_t int_state; @@ -77,12 +77,12 @@ uint8_t cc1100_read_reg(uint8_t addr) { // ************************************************************************************************* -// @fn cc1100_write_reg +// @fn cc110x_write_reg // @brief Write byte to register. // @param none // @return none // ************************************************************************************************* -void cc1100_write_reg(uint8_t addr, uint8_t value) { +void cc110x_write_reg(uint8_t addr, uint8_t value) { volatile unsigned int i; uint16_t int_state; @@ -98,7 +98,7 @@ void cc1100_write_reg(uint8_t addr, uint8_t value) { restoreIRQ(int_state); } -uint8_t cc1100_read_status(uint8_t addr) { +uint8_t cc110x_read_status(uint8_t addr) { unsigned char x; uint16_t int_state; @@ -112,12 +112,12 @@ uint8_t cc1100_read_status(uint8_t addr) { } // ************************************************************************************************* -// @fn cc1100_readburst_reg +// @fn cc110x_readburst_reg // @brief Read sequence of bytes from register. // @param none // @return none // ************************************************************************************************* -void cc1100_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { +void cc110x_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { unsigned int i; uint16_t int_state; @@ -137,14 +137,32 @@ void cc1100_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { restoreIRQ(int_state); } +void cc110x_read_fifo(char *buffer, uint8_t count) { + unsigned int i; + uint16_t int_state; + + int_state = disableIRQ(); + + while (!(RF1AIFCTL1 & RFINSTRIFG)); // Wait for the Radio to be ready for next instruction + RF1AINSTR1B = (RF_RXFIFORD); // Send address + Instruction + + for (i = 0; i < (count-1); i++) + { + while (!(RFDOUTIFG&RF1AIFCTL1)); // Wait for the Radio Core to update the RF1ADOUTB reg + buffer[i] = RF1ADOUT1B; // Read DOUT from Radio Core + clears RFDOUTIFG + // Also initiates auo-read for next DOUT byte + } + buffer[count-1] = RF1ADOUT0B; // Store the last DOUT from Radio Core + restoreIRQ(int_state); +} // ************************************************************************************************* -// @fn cc1100_writeburst_reg +// @fn cc110x_writeburst_reg // @brief Write sequence of bytes to register. // @param none // @return none // ************************************************************************************************* -uint8_t cc1100_writeburst_reg(uint8_t addr, char *buffer, uint8_t count) { +uint8_t cc110x_writeburst_reg(uint8_t addr, char *buffer, uint8_t count) { // Write Burst works wordwise not bytewise - bug known already unsigned char i; uint16_t int_state; diff --git a/drivers/cc110x_ng/cc1100_ng.h b/drivers/cc110x_ng/cc110x_ng.h similarity index 73% rename from drivers/cc110x_ng/cc1100_ng.h rename to drivers/cc110x_ng/cc110x_ng.h index 0cf11f63a..5d0238951 100644 --- a/drivers/cc110x_ng/cc1100_ng.h +++ b/drivers/cc110x_ng/cc110x_ng.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #define CC1100_MAX_DATA_LENGTH (58) @@ -39,9 +39,8 @@ /** @} */ - -extern volatile cc1100_flags rflags; ///< Radio flags -extern char cc1100_conf[]; +extern volatile cc110x_flags rflags; ///< Radio flags +extern char cc110x_conf[]; /** * @brief CC1100 layer 0 protocol @@ -72,12 +71,12 @@ typedef struct __attribute__ ((packed)) { uint8_t phy_src; ///< Source address (physical source) uint8_t flags; ///< Flags uint8_t data[CC1100_MAX_DATA_LENGTH]; ///< Data (high layer protocol) -} cc1100_packet_t; +} cc110x_packet_t; typedef struct { uint8_t rssi; uint8_t lqi; - cc1100_packet_t packet; + cc110x_packet_t packet; } rx_buffer_t; enum radio_mode { @@ -86,51 +85,51 @@ enum radio_mode { RADIO_MODE_ON = 1 ///< turn radio on }; -extern rx_buffer_t cc1100_rx_buffer[]; +extern rx_buffer_t cc110x_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; +extern cc110x_statistic_t cc110x_statistic; int transceiver_pid; ///< the transceiver thread pid -void cc1100_init(int transceiver_pid); +void cc110x_init(int transceiver_pid); -void cc1100_rx_handler(void); +void cc110x_rx_handler(void); -uint8_t cc1100_send(cc1100_packet_t *pkt); +uint8_t cc110x_send(cc110x_packet_t *pkt); -uint8_t cc1100_get_buffer_pos(void); +uint8_t cc110x_get_buffer_pos(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 cc110x_setup_rx_mode(void); +void cc110x_switch_to_rx(void); +void cc110x_wakeup_from_rx(void); +void cc110x_switch_to_pwd(void); -void cc1100_disable_interrupts(void); -int16_t cc1100_set_config_channel(uint8_t channr); -int16_t cc1100_set_channel(uint8_t channr); -int16_t cc1100_get_channel(void); +void cc110x_disable_interrupts(void); +int16_t cc110x_set_config_channel(uint8_t channr); +int16_t cc110x_set_channel(uint8_t channr); +int16_t cc110x_get_channel(void); -radio_address_t cc1100_set_address(radio_address_t addr); -radio_address_t cc1100_set_config_address(radio_address_t addr); -radio_address_t cc1100_get_address(void); -void cc1100_set_monitor(uint8_t mode); +radio_address_t cc110x_set_address(radio_address_t addr); +radio_address_t cc110x_set_config_address(radio_address_t addr); +radio_address_t cc110x_get_address(void); +void cc110x_set_monitor(uint8_t mode); -void cc1100_print_config(void); +void cc110x_print_config(void); /** * @brief GDO0 interrupt handler. */ -void cc1100_gdo0_irq(void); +void cc110x_gdo0_irq(void); /** * @brief GDO2 interrupt handler. * * @note Wakes up MCU on packet reception. */ -void cc1100_gdo2_irq(void); +void cc110x_gdo2_irq(void); #endif diff --git a/drivers/cc110x_ng/cc1100_spi.c b/drivers/cc110x_ng/cc110x_spi.c similarity index 67% rename from drivers/cc110x_ng/cc1100_spi.c rename to drivers/cc110x_ng/cc110x_spi.c index 8e4f0aeb2..cd5730386 100644 --- a/drivers/cc110x_ng/cc1100_spi.c +++ b/drivers/cc110x_ng/cc110x_spi.c @@ -39,16 +39,16 @@ and the mailinglist (subscription via web site) * @author Heiko Will * @version $Revision: 1775 $ * - * @note $Id: cc1100_spi.c 1775 2010-01-26 09:37:03Z hillebra $ + * @note $Id: cc110x_spi.c 1775 2010-01-26 09:37:03Z hillebra $ */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include @@ -58,70 +58,74 @@ and the mailinglist (subscription via web site) #define NOBYTE 0xFF -uint8_t cc1100_writeburst_reg(uint8_t addr, char *src, uint8_t count) { +uint8_t cc110x_writeburst_reg(uint8_t addr, char *src, uint8_t count) { int i = 0; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr | CC1100_WRITE_BURST); + cc110x_spi_select(); + cc110x_txrx(addr | CC1100_WRITE_BURST); while (i < count) { - cc1100_txrx(src[i]); + cc110x_txrx(src[i]); i++; } - cc1100_spi_unselect(); + cc110x_spi_unselect(); restoreIRQ(cpsr); return count; } -void cc1100_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { +void cc110x_readburst_reg(uint8_t addr, char *buffer, uint8_t count) { int i = 0; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr | CC1100_READ_BURST); + cc110x_spi_select(); + cc110x_txrx(addr | CC1100_READ_BURST); while (i < count) { - buffer[i] = cc1100_txrx(NOBYTE); + buffer[i] = cc110x_txrx(NOBYTE); i++; } - cc1100_spi_unselect(); + cc110x_spi_unselect(); restoreIRQ(cpsr); } -void cc1100_write_reg(uint8_t addr, uint8_t value) { +void cc110x_read_fifo(char *buffer, uint8_t count) { + cc110x_readburst_reg(CC1100_RXFIFO, buffer,count); +} + +void cc110x_write_reg(uint8_t addr, uint8_t value) { unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr); - cc1100_txrx(value); - cc1100_spi_unselect(); + cc110x_spi_select(); + cc110x_txrx(addr); + cc110x_txrx(value); + cc110x_spi_unselect(); restoreIRQ(cpsr); } -uint8_t cc1100_read_reg(uint8_t addr) { +uint8_t cc110x_read_reg(uint8_t addr) { uint8_t result; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr | CC1100_READ_SINGLE); - result = cc1100_txrx(NOBYTE); - cc1100_spi_unselect(); + cc110x_spi_select(); + cc110x_txrx(addr | CC1100_READ_SINGLE); + result = cc110x_txrx(NOBYTE); + cc110x_spi_unselect(); restoreIRQ(cpsr); return result; } -uint8_t cc1100_read_status(uint8_t addr) { +uint8_t cc110x_read_status(uint8_t addr) { uint8_t result; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - cc1100_txrx(addr | CC1100_READ_BURST); - result = cc1100_txrx(NOBYTE); - cc1100_spi_unselect(); + cc110x_spi_select(); + cc110x_txrx(addr | CC1100_READ_BURST); + result = cc110x_txrx(NOBYTE); + cc110x_spi_unselect(); restoreIRQ(cpsr); return result; } -uint8_t cc1100_strobe(uint8_t c) { +uint8_t cc110x_strobe(uint8_t c) { uint8_t result; unsigned int cpsr = disableIRQ(); - cc1100_spi_select(); - result = cc1100_txrx(c); - cc1100_spi_unselect(); + cc110x_spi_select(); + result = cc110x_txrx(c); + cc110x_spi_unselect(); restoreIRQ(cpsr); return result; } diff --git a/drivers/cc110x_ng/cc1100_spi.h b/drivers/cc110x_ng/cc110x_spi.h similarity index 87% rename from drivers/cc110x_ng/cc1100_spi.h rename to drivers/cc110x_ng/cc110x_spi.h index fcb5680d8..274f54412 100644 --- a/drivers/cc110x_ng/cc1100_spi.h +++ b/drivers/cc110x_ng/cc110x_spi.h @@ -38,20 +38,20 @@ and the mailinglist (subscription via web site) * @author Heiko Will * @version $Revision: 1775 $ * - * @note $Id: cc1100_spi.h 1775 2010-01-26 09:37:03Z hillebra $ + * @note $Id: cc110x_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); +int cc110x_get_gdo0(void); +int cc110x_get_gdo1(void); +int cc110x_get_gdo2(void); -void cc1100_spi_init(void); -void cc1100_spi_cs(void); -void cc1100_spi_select(void); -void cc1100_spi_unselect(void); +void cc110x_spi_init(void); +void cc110x_spi_cs(void); +void cc110x_spi_select(void); +void cc110x_spi_unselect(void); /** @} */ #endif /* CC1100_SPI_H_ */ diff --git a/projects/chronos_cc110x_ng/main.c b/projects/chronos_cc110x_ng/main.c index e6605182b..b259b0733 100644 --- a/projects/chronos_cc110x_ng/main.c +++ b/projects/chronos_cc110x_ng/main.c @@ -6,10 +6,10 @@ #include #include #include -#include +#include #include #include -#include +#include #define RADIO_STACK_SIZE (512) #define SEND_SIZE CC1100_MAX_DATA_LENGTH @@ -39,6 +39,8 @@ void send(radio_address_t dst, uint8_t len, uint8_t *data) { p.length = len; p.dst = dst; + display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); + display_chars(LCD_SEG_L2_5_0, (char*) itoa(p.dst, 6, 0), SEG_ON); p.data = data; msg_send(&mesg, transceiver_pid, 1); @@ -58,6 +60,9 @@ void radio(void) { display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON); send(p->src, p->length, p->data); + hwtimer_wait(50000); + send(p->src, sizeof(p->length), &(p->length)); + p->processing--; } else if (m.type == ENOBUFFER) { @@ -86,7 +91,7 @@ int main(void) { tcmd.data = &addr; msg_send(&mesg, transceiver_pid, 1); - send(0, SEND_SIZE, snd_buffer); + send(12, SEND_SIZE, snd_buffer); while (1) { hwtimer_wait(SENDING_DELAY); diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index baf042dfd..22b9485b5 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #define SHELL_STACK_SIZE (2048) #define RADIO_STACK_SIZE (2048) @@ -81,9 +81,9 @@ void print_buffer(char *unused) { 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[]; + extern rx_buffer_t cc110x_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]); + printf("[%u] %u # %u \n", i, cc110x_rx_buffer[i].packet.length, cc110x_rx_buffer[i].packet.data[i]); } } diff --git a/sys/shell/Jamfile b/sys/shell/Jamfile index d147c243c..a93dc23f3 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 id.c rtc.c sht11.c ltc4150.c cc1100.c cc1100_ng.c : shell ; +Module shell_commands : shell_commands.c id.c rtc.c sht11.c ltc4150.c cc1100.c cc110x_ng.c : shell ; Module ps : ps.c ; diff --git a/sys/shell/cc1100_ng.c b/sys/shell/cc110x_ng.c similarity index 78% rename from sys/shell/cc1100_ng.c rename to sys/shell/cc110x_ng.c index e837af03d..ca192d228 100644 --- a/sys/shell/cc1100_ng.c +++ b/sys/shell/cc110x_ng.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #define TEXT_SIZE CC1100_MAX_DATA_LENGTH @@ -11,7 +11,7 @@ char text_msg[TEXT_SIZE]; msg mesg; transceiver_command_t tcmd; -void _cc1100_ng_get_set_address_handler(char *addr) { +void _cc110x_ng_get_set_address_handler(char *addr) { int16_t a; tcmd.transceivers = TRANSCEIVER_CC1100; @@ -19,17 +19,17 @@ void _cc1100_ng_get_set_address_handler(char *addr) { mesg.content.ptr = (char*) &tcmd; a = atoi(addr+5); if (strlen(addr) > 5) { - printf("[cc1100] Trying to set address %i\n", a); + printf("[cc110x] 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); + printf("[cc110x] Got address: %i\n", a); } -void _cc1100_ng_get_set_channel_handler(char *chan) { +void _cc110x_ng_get_set_channel_handler(char *chan) { int16_t c; tcmd.transceivers = TRANSCEIVER_CC1100; @@ -37,17 +37,17 @@ void _cc1100_ng_get_set_channel_handler(char *chan) { mesg.content.ptr = (char*) &tcmd; c = atoi(chan+5); if (strlen(chan) > 5) { - printf("[cc1100] Trying to set channel %i\n", c); + printf("[cc110x] 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); + printf("[cc110x] Got channel: %i\n", c); } -void _cc1100_ng_send_handler(char *pkt) { +void _cc110x_ng_send_handler(char *pkt) { radio_packet_t p; uint32_t response; uint16_t addr; @@ -69,17 +69,17 @@ void _cc1100_ng_send_handler(char *pkt) { 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); + printf("[cc110x] 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); + printf("[cc110x] Packet sent: %lu\n", response); return; } } puts("Usage:\ttxtsnd "); } -void _cc1100_ng_monitor_handler(char *mode) { +void _cc110x_ng_monitor_handler(char *mode) { unsigned int m; tcmd.transceivers = TRANSCEIVER_CC1100; diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index af2ea5cbe..dd5372b99 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -24,16 +24,16 @@ 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); +extern void _cc110x_get_address_handler(char *unused); +extern void _cc110x_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); -extern void _cc1100_ng_monitor_handler(char *mode); +extern void _cc110x_ng_get_set_address_handler(char *addr); +extern void _cc110x_ng_get_set_channel_handler(char *chan); +extern void _cc110x_ng_send_handler(char *pkt); +extern void _cc110x_ng_monitor_handler(char *mode); #endif #endif @@ -56,15 +56,15 @@ const shell_command_t _shell_command_list[] = { {"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}, + {"cc110x_get_address", "", _cc110x_get_address_handler}, + {"cc110x_set_address", "", _cc110x_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}, - {"monitor", "Enables or disables address checking for the CC1100 transceiver", _cc1100_ng_monitor_handler}, + {"addr", "Gets or sets the address for the CC1100 transceiver", _cc110x_ng_get_set_address_handler}, + {"chan", "Gets or sets the channel for the CC1100 transceiver", _cc110x_ng_get_set_channel_handler}, + {"txtsnd", "Sends a text message to a given node via the CC1100 transceiver", _cc110x_ng_send_handler}, + {"monitor", "Enables or disables address checking for the CC1100 transceiver", _cc110x_ng_monitor_handler}, #endif #endif {NULL, NULL, NULL} diff --git a/sys/transceiver.c b/sys/transceiver.c index d0d5920e5..7fb49b6ed 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -12,7 +12,7 @@ /* supported transceivers */ #ifdef MODULE_CC110X_NG -#include +#include #if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE) #undef PAYLOAD_SIZE #define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH) @@ -50,7 +50,7 @@ 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 void receive_cc110x_packet(radio_packet_t *trans_p); static uint8_t send_packet(transceiver_type_t t, void *pkt); static int16_t get_channel(transceiver_type_t t); static int16_t set_channel(transceiver_type_t t, void *channel); @@ -84,7 +84,7 @@ int transceiver_start(void) { } else if (transceivers & TRANSCEIVER_CC1100) { DEBUG("Transceiver started for CC1100\n"); - cc1100_init(transceiver_pid); + cc110x_init(transceiver_pid); } return transceiver_pid; } @@ -213,7 +213,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { m.type = PKT_PENDING; if (type == RCV_PKT_CC1100) { - receive_cc1100_packet(trans_p); + receive_cc110x_packet(trans_p); } else { puts("Invalid transceiver type"); @@ -241,16 +241,16 @@ static void receive_packet(uint16_t type, uint8_t pos) { * * @param trans_p The current entry in the transceiver buffer */ -static void receive_cc1100_packet(radio_packet_t *trans_p) { +static void receive_cc110x_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; + cc110x_packet_t p = cc110x_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->rssi = cc110x_rx_buffer[rx_buffer_pos].rssi; + trans_p->lqi = cc110x_rx_buffer[rx_buffer_pos].lqi; trans_p->length = p.length - CC1100_HEADER_LENGTH; memcpy((void*) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), p.data, CC1100_MAX_DATA_LENGTH); eINT(); @@ -271,16 +271,16 @@ static void receive_cc1100_packet(radio_packet_t *trans_p) { 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; + cc110x_packet_t cc110x_pkt; switch (t) { case TRANSCEIVER_CC1100: - 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); + cc110x_pkt.length = p.length + CC1100_HEADER_LENGTH; + cc110x_pkt.address = p.dst; + cc110x_pkt.flags = 0; + memcpy(cc110x_pkt.data, p.data, p.length); - res = cc1100_send(&cc1100_pkt); + res = cc110x_send(&cc110x_pkt); break; default: puts("Unknown transceiver"); @@ -302,7 +302,7 @@ static int16_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); + return cc110x_set_channel(c); default: return -1; } @@ -318,7 +318,7 @@ static int16_t set_channel(transceiver_type_t t, void *channel) { static int16_t get_channel(transceiver_type_t t) { switch (t) { case TRANSCEIVER_CC1100: - return cc1100_get_channel(); + return cc110x_get_channel(); default: return -1; } @@ -334,7 +334,7 @@ static int16_t get_channel(transceiver_type_t t) { static int16_t get_address(transceiver_type_t t) { switch (t) { case TRANSCEIVER_CC1100: - return cc1100_get_address(); + return cc110x_get_address(); default: return -1; } @@ -352,7 +352,7 @@ 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); + return cc110x_set_address(addr); default: return -1; } @@ -367,7 +367,7 @@ static int16_t set_address(transceiver_type_t t, void *address) { static void set_monitor(transceiver_type_t t, void *mode) { switch (t) { case TRANSCEIVER_CC1100: - cc1100_set_monitor(*((uint8_t*) mode)); + cc110x_set_monitor(*((uint8_t*) mode)); break; default: break; @@ -377,7 +377,7 @@ static void set_monitor(transceiver_type_t t, void *mode) { static void powerdown(transceiver_type_t t) { switch (t) { case TRANSCEIVER_CC1100: - cc1100_switch_to_pwd(); + cc110x_switch_to_pwd(); break; default: break; @@ -388,7 +388,7 @@ static void powerdown(transceiver_type_t t) { static void switch_to_rx(transceiver_type_t t) { switch (t) { case TRANSCEIVER_CC1100: - cc1100_switch_to_rx(); + cc110x_switch_to_rx(); break; default: break; From 8f63b18b9f99d88e6cfc34f7d5fe8e6bec8f6a61 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 11 Dec 2010 12:24:06 +0100 Subject: [PATCH 146/199] [drivers/cc110x_ng] * moved all headers to include subfolder --- drivers/cc110x_ng/{ => include}/cc110x-arch.h | 0 drivers/cc110x_ng/{ => include}/cc110x-config.h | 0 drivers/cc110x_ng/{ => include}/cc110x-defaultSettings.h | 0 drivers/cc110x_ng/{ => include}/cc110x-internal.h | 0 drivers/cc110x_ng/{ => include}/cc110x-reg.h | 0 drivers/cc110x_ng/{ => include}/cc110x_ng.h | 0 drivers/cc110x_ng/{ => include}/cc110x_spi.h | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename drivers/cc110x_ng/{ => include}/cc110x-arch.h (100%) rename drivers/cc110x_ng/{ => include}/cc110x-config.h (100%) rename drivers/cc110x_ng/{ => include}/cc110x-defaultSettings.h (100%) rename drivers/cc110x_ng/{ => include}/cc110x-internal.h (100%) rename drivers/cc110x_ng/{ => include}/cc110x-reg.h (100%) rename drivers/cc110x_ng/{ => include}/cc110x_ng.h (100%) rename drivers/cc110x_ng/{ => include}/cc110x_spi.h (100%) diff --git a/drivers/cc110x_ng/cc110x-arch.h b/drivers/cc110x_ng/include/cc110x-arch.h similarity index 100% rename from drivers/cc110x_ng/cc110x-arch.h rename to drivers/cc110x_ng/include/cc110x-arch.h diff --git a/drivers/cc110x_ng/cc110x-config.h b/drivers/cc110x_ng/include/cc110x-config.h similarity index 100% rename from drivers/cc110x_ng/cc110x-config.h rename to drivers/cc110x_ng/include/cc110x-config.h diff --git a/drivers/cc110x_ng/cc110x-defaultSettings.h b/drivers/cc110x_ng/include/cc110x-defaultSettings.h similarity index 100% rename from drivers/cc110x_ng/cc110x-defaultSettings.h rename to drivers/cc110x_ng/include/cc110x-defaultSettings.h diff --git a/drivers/cc110x_ng/cc110x-internal.h b/drivers/cc110x_ng/include/cc110x-internal.h similarity index 100% rename from drivers/cc110x_ng/cc110x-internal.h rename to drivers/cc110x_ng/include/cc110x-internal.h diff --git a/drivers/cc110x_ng/cc110x-reg.h b/drivers/cc110x_ng/include/cc110x-reg.h similarity index 100% rename from drivers/cc110x_ng/cc110x-reg.h rename to drivers/cc110x_ng/include/cc110x-reg.h diff --git a/drivers/cc110x_ng/cc110x_ng.h b/drivers/cc110x_ng/include/cc110x_ng.h similarity index 100% rename from drivers/cc110x_ng/cc110x_ng.h rename to drivers/cc110x_ng/include/cc110x_ng.h diff --git a/drivers/cc110x_ng/cc110x_spi.h b/drivers/cc110x_ng/include/cc110x_spi.h similarity index 100% rename from drivers/cc110x_ng/cc110x_spi.h rename to drivers/cc110x_ng/include/cc110x_spi.h From c083928983e9bb8c5abceb33f130d07cf1d4e38f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 11 Dec 2010 13:38:04 +0100 Subject: [PATCH 147/199] [board/chronos/drivers/display] * cleaned up code and documentation [drivers/cc110x_ng] * fixed include pathes --- Jamrules | 2 +- board/chronos/drivers/display.c | 556 ++++++++++++------------------- board/chronos/drivers/display.h | 316 ++++++++++++------ board/chronos/drivers/display1.c | 227 ++++++------- drivers/cc110x_ng/Jamfile | 2 +- 5 files changed, 525 insertions(+), 578 deletions(-) diff --git a/Jamrules b/Jamrules index 13a6088f0..415f0995e 100644 --- a/Jamrules +++ b/Jamrules @@ -73,4 +73,4 @@ HDRS += [ FPath $(TOP) projects $(PROJECT) ] ; # drivers HDRS += [ FPath $(TOP) drivers include ] ; HDRS += [ FPath $(TOP) drivers cc110x ] ; -HDRS += [ FPath $(TOP) drivers cc110x_ng ] ; +HDRS += [ FPath $(TOP) drivers cc110x_ng include ] ; diff --git a/board/chronos/drivers/display.c b/board/chronos/drivers/display.c index 1473703e4..39774279b 100644 --- a/board/chronos/drivers/display.c +++ b/board/chronos/drivers/display.c @@ -1,514 +1,382 @@ -// ************************************************************************************************* -// -// Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ -// -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// -// Neither the name of Texas Instruments Incorporated nor the names of -// its contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// ************************************************************************************************* -// Display functions. -// ************************************************************************************************* - - -// ************************************************************************************************* -// Include section - -// system +/* ************************************************************************************************* + * + * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ************************************************************************************************* + * Basic display functions. + * ************************************************************************************************/ + +/* ************************************************************************************************* + * Include section + */ + +/* system */ #include -// driver +/* driver */ #include #include -// ************************************************************************************************* -// Prototypes section +/************************************************************************************************** + * Prototypes section */ void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); void clear_line(uint8_t line); void display_symbol(uint8_t symbol, uint8_t mode); -// ************************************************************************************************* -// Defines section +/* ************************************************************************************************* + * Global Variable section */ - - -// ************************************************************************************************* -// Global Variable section - -// Display flags +/* Display flags */ volatile s_display_flags display; -// Global return string for itoa function -uint8_t itoa_str[8]; +/* Global return string for itoa function */ +char itoa_str[8]; - - -// ************************************************************************************************* -// @fn lcd_init -// @brief Erase LCD memory. Init LCD peripheral. -// @param none -// @return none -// ************************************************************************************************* -void lcd_init(void) -{ - // Clear entire display memory +void lcd_init(void) { + /* Clear entire display memory */ LCDBMEMCTL |= LCDCLRBM + LCDCLRM; - // LCD_FREQ = ACLK/16/8 = 256Hz - // Frame frequency = 256Hz/4 = 64Hz, LCD mux 4, LCD on + /* LCD_FREQ = ACLK/16/8 = 256Hz */ + /* Frame frequency = 256Hz/4 = 64Hz, LCD mux 4, LCD on */ LCDBCTL0 = (LCDDIV0 + LCDDIV1 + LCDDIV2 + LCDDIV3) | (LCDPRE0 + LCDPRE1) | LCD4MUX | LCDON; - // LCB_BLK_FREQ = ACLK/8/4096 = 1Hz + /* LCB_BLK_FREQ = ACLK/8/4096 = 1Hz */ LCDBBLKCTL = LCDBLKPRE0 | LCDBLKPRE1 | LCDBLKDIV0 | LCDBLKDIV1 | LCDBLKDIV2 | LCDBLKMOD0; - // I/O to COM outputs + /* I/O to COM outputs */ P5SEL |= (BIT5 | BIT6 | BIT7); P5DIR |= (BIT5 | BIT6 | BIT7); - // Activate LCD output - LCDBPCTL0 = 0xFFFF; // Select LCD segments S0-S15 - LCDBPCTL1 = 0x00FF; // Select LCD segments S16-S22 + /* Activate LCD output */ + LCDBPCTL0 = 0xFFFF; /* Select LCD segments S0-S15 */ + LCDBPCTL1 = 0x00FF; /* Select LCD segments S16-S22 */ #ifdef USE_LCD_CHARGE_PUMP - // Charge pump voltage generated internally, internal bias (V2-V4) generation + /* Charge pump voltage generated internally, internal bias (V2-V4) generation */ LCDBVCTL = LCDCPEN | VLCD_2_72; #endif } - -// ************************************************************************************************* -// @fn clear_display_all -// @brief Erase LINE1 and LINE2 segments. Clear also function-specific content. -// @param none -// @return none -// ************************************************************************************************* -void clear_display_all(void) -{ +void clear_display_all(void) { // Clear generic content clear_line(LINE1); clear_line(LINE2); - - } - -// ************************************************************************************************* -// @fn clear_display -// @brief Erase LINE1 and LINE2 segments. Keep icons. -// @param none -// @return none -// ************************************************************************************************* -void clear_display(void) -{ +void clear_display(void) { clear_line(LINE1); clear_line(LINE2); } - -// ************************************************************************************************* -// @fn clear_line -// @brief Erase segments of a given line. -// @param uint8_t line LINE1, LINE2 -// @return none -// ************************************************************************************************* -void clear_line(uint8_t line) -{ +void clear_line(uint8_t line) { display_chars(switch_seg(line, LCD_SEG_L1_3_0, LCD_SEG_L2_5_0), NULL, SEG_OFF); - if (line == LINE1) - { + if (line == LINE1) { display_symbol(LCD_SEG_L1_DP1, SEG_OFF); display_symbol(LCD_SEG_L1_DP0, SEG_OFF); display_symbol(LCD_SEG_L1_COL, SEG_OFF); } - else // line == LINE2 - { + /* line == LINE2 */ + else { display_symbol(LCD_SEG_L2_DP, SEG_OFF); display_symbol(LCD_SEG_L2_COL1, SEG_OFF); display_symbol(LCD_SEG_L2_COL0, SEG_OFF); } } - -// ************************************************************************************************* -// @fn write_segment -// @brief Write to one or multiple LCD segments -// @param lcdmem Pointer to LCD byte memory -// bits Segments to address -// bitmask Bitmask for particular display item -// mode On, off or blink segments -// @return -// ************************************************************************************************* -void write_lcd_mem(uint8_t * lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state) -{ - if (state == SEG_ON) - { - // Clear segments before writing +void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state) { + if (state == SEG_ON) { + /* Clear segments before writing */ *lcdmem = (uint8_t)(*lcdmem & ~bitmask); - // Set visible segments + /* Set visible segments */ *lcdmem = (uint8_t)(*lcdmem | bits); } - else if (state == SEG_OFF) - { - // Clear segments + else if (state == SEG_OFF) { + /* Clear segments */ *lcdmem = (uint8_t)(*lcdmem & ~bitmask); } - else if (state == SEG_ON_BLINK_ON) - { - // Clear visible / blink segments before writing + else if (state == SEG_ON_BLINK_ON) { + /* Clear visible / blink segments before writing */ *lcdmem = (uint8_t)(*lcdmem & ~bitmask); *(lcdmem+0x20) = (uint8_t)(*(lcdmem+0x20) & ~bitmask); - // Set visible / blink segments + /* Set visible / blink segments */ *lcdmem = (uint8_t)(*lcdmem | bits); *(lcdmem+0x20) = (uint8_t)(*(lcdmem+0x20) | bits); } - else if (state == SEG_ON_BLINK_OFF) - { - // Clear visible segments before writing + else if (state == SEG_ON_BLINK_OFF) { + /* Clear visible segments before writing */ *lcdmem = (uint8_t)(*lcdmem & ~bitmask); - // Set visible segments + /* Set visible segments */ *lcdmem = (uint8_t)(*lcdmem | bits); - // Clear blink segments + /* Clear blink segments */ *(lcdmem+0x20) = (uint8_t)(*(lcdmem+0x20) & ~bitmask); } - else if (state == SEG_OFF_BLINK_OFF) - { - // Clear segments + else if (state == SEG_OFF_BLINK_OFF) { + /* Clear segments */ *lcdmem = (uint8_t)(*lcdmem & ~bitmask); - // Clear blink segments + /* Clear blink segments */ *(lcdmem+0x20) = (uint8_t)(*(lcdmem+0x20) & ~bitmask); } } - -// ************************************************************************************************* -// @fn itoa -// @brief Generic integer to array routine. Converts integer n to string. -// Default conversion result has leading zeros, e.g. "00123" -// Option to convert leading '0' into whitespace (blanks) -// @param uint32_t n integer to convert -// uint8_t digits number of digits -// uint8_t blanks fill up result string with number of whitespaces instead of leading zeros -// @return uint8_t string -// ************************************************************************************************* -uint8_t * itoa(uint32_t n, uint8_t digits, uint8_t blanks) -{ +char *itoa(uint32_t n, uint8_t digits, uint8_t blanks) { uint8_t i; uint8_t digits1 = digits; - // Preset result string + /* Preset result string */ memcpy(itoa_str, "0000000", 7); - // Return empty string if number of digits is invalid (valid range for digits: 1-7) - if ((digits == 0) || (digits > 7)) return (itoa_str); + /* Return empty string if number of digits is invalid (valid range for digits: 1-7) */ + if ((digits == 0) || (digits > 7)) { + return (itoa_str); + } - // Numbers 0 .. 180 can be copied from itoa_conversion_table without conversion - if (n <= 180) - { - if (digits >= 3) - { + /* Numbers 0 .. 180 can be copied from itoa_conversion_table without conversion */ + if (n <= 180) { + if (digits >= 3) { memcpy(itoa_str+(digits-3), itoa_conversion_table[n], 3); } - else // digits == 1 || 2 - { + /* digits == 1 || 2 */ + else { memcpy(itoa_str, itoa_conversion_table[n]+(3-digits), digits); } } - else // For n > 180 need to calculate string content - { - // Calculate digits from least to most significant number - do - { + /* For n > 180 need to calculate string content */ + else { + /* Calculate digits from least to most significant number */ + do { itoa_str[digits-1] = n % 10 + '0'; n /= 10; } while (--digits > 0); } - // Remove specified number of leading '0', always keep last one + /* Remove specified number of leading '0', always keep last one */ i = 0; - while ((itoa_str[i] == '0') && (i < digits1-1)) - { - if (blanks > 0) - { - // Convert only specified number of leading '0' + while ((itoa_str[i] == '0') && (i < digits1-1)) { + if (blanks > 0) { + /* Convert only specified number of leading '0' */ itoa_str[i]=' '; blanks--; } i++; } - return (itoa_str); } - -// ************************************************************************************************* -// @fn display_value1 -// @brief Generic decimal display routine. Used exclusively by set_value function. -// @param uint8_t segments LCD segments where value is displayed -// uint32_t value Integer value to be displayed -// uint8_t digits Number of digits to convert -// uint8_t blanks Number of leadings blanks in itoa result string -// @return none -// ************************************************************************************************* -void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) -{ - uint8_t* str; +void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) { + char *str; str = itoa(value, digits, blanks); - // Display string in blink mode - display_chars(segments, (char*) str, disp_mode); + /* Display string in blink mode */ + display_chars(segments, str, disp_mode); } - -// ************************************************************************************************* -// @fn display_symbol -// @brief Switch symbol on or off on LCD. -// @param uint8_t symbol A valid LCD symbol (index 0..42) -// uint8_t state SEG_ON, SEG_OFF, SEG_BLINK -// @return none -// ************************************************************************************************* -void display_symbol(uint8_t symbol, uint8_t mode) -{ - uint8_t * lcdmem; +void display_symbol(uint8_t symbol, uint8_t mode) { + uint8_t *lcdmem; uint8_t bits; uint8_t bitmask; - if (symbol <= LCD_SEG_L2_DP) - { - // Get LCD memory address for symbol from table - lcdmem = (uint8_t *)segments_lcdmem[symbol]; + if (symbol <= LCD_SEG_L2_DP) { + /* Get LCD memory address for symbol from table */ + lcdmem = (uint8_t*)segments_lcdmem[symbol]; - // Get bits for symbol from table + /* Get bits for symbol from table */ bits = segments_bitmask[symbol]; - // Bitmask for symbols equals bits + /* Bitmask for symbols equals bits */ bitmask = bits; - // Write LCD memory + /* Write LCD memory */ write_lcd_mem(lcdmem, bits, bitmask, mode); } } - -// ************************************************************************************************* -// @fn display_char -// @brief Write to 7-segment characters. -// @param uint8_t segment A valid LCD segment -// uint8_t chr Character to display -// uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK -// @return none -// ************************************************************************************************* -void display_char(uint8_t segment, char chr, uint8_t mode) -{ - uint8_t * lcdmem; // Pointer to LCD memory - uint8_t bitmask; // Bitmask for character - uint8_t bits, bits1; // Bits to write +void display_char(uint8_t segment, char chr, uint8_t mode) { + uint8_t *lcdmem; /* Pointer to LCD memory */ + uint8_t bitmask; /* Bitmask for character */ + uint8_t bits, bits1; /* Bits to write */ - // Write to single 7-segment character - if ((segment >= LCD_SEG_L1_3) && (segment <= LCD_SEG_L2_DP)) - { - // Get LCD memory address for segment from table - lcdmem = (uint8_t *)segments_lcdmem[segment]; + /* Write to single 7-segment character */ + if ((segment >= LCD_SEG_L1_3) && (segment <= LCD_SEG_L2_DP)) { + /* Get LCD memory address for segment from table */ + lcdmem = (uint8_t*)segments_lcdmem[segment]; - // Get bitmask for character from table + /* Get bitmask for character from table */ bitmask = segments_bitmask[segment]; - // Get bits from font set - if ((chr >= 0x30) && (chr <= 0x5A)) - { - // Use font set + /* Get bits from font set */ + if ((chr >= 0x30) && (chr <= 0x5A)) { + /* Use font set */ bits = lcd_font[chr-0x30]; } - else if (chr == 0x2D) - { - // '-' not in font set + else if (chr == 0x2D) { + /* '-' not in font set */ bits = BIT1; } - else - { - // Other characters map to ' ' (blank) + else { + /* Other characters map to ' ' (blank) */ bits = 0; } - // When addressing LINE2 7-segment characters need to swap high- and low-nibble, - // because LCD COM/SEG assignment is mirrored against LINE1 - if (segment >= LCD_SEG_L2_5) - { + /* When addressing LINE2 7-segment characters need to swap high- and low-nibble, */ + /* because LCD COM/SEG assignment is mirrored against LINE1 */ + if (segment >= LCD_SEG_L2_5) { bits1 = ((bits << 4) & 0xF0) | ((bits >> 4) & 0x0F); bits = bits1; - // When addressing LCD_SEG_L2_5, need to convert ASCII '1' and 'L' to 1 bit, - // because LCD COM/SEG assignment is special for this incomplete character - if (segment == LCD_SEG_L2_5) - { + /* When addressing LCD_SEG_L2_5, need to convert ASCII '1' and 'L' to 1 bit, */ + /* because LCD COM/SEG assignment is special for this incomplete character */ + if (segment == LCD_SEG_L2_5) { if ((chr == '1') || (chr == 'L')) bits = BIT7; } } - // Physically write to LCD memory + /* Physically write to LCD memory */ write_lcd_mem(lcdmem, bits, bitmask, mode); } } - -// ************************************************************************************************* -// @fn display_chars -// @brief Write to consecutive 7-segment characters. -// @param uint8_t segments LCD segment array -// uint8_t * str Pointer to a string -// uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK -// @return none -// ************************************************************************************************* void display_chars(uint8_t segments, char *str, uint8_t mode) { uint8_t i; - uint8_t length = 0; // Write length - uint8_t char_start = 0; // Starting point for consecutive write + uint8_t length = 0; /* Write length */ + uint8_t char_start = 0; /* Starting point for consecutive write */ - switch (segments) - { - // LINE1 - case LCD_SEG_L1_3_0: length=4; char_start=LCD_SEG_L1_3; break; - case LCD_SEG_L1_2_0: length=3; char_start=LCD_SEG_L1_2; break; - case LCD_SEG_L1_1_0: length=2; char_start=LCD_SEG_L1_1; break; - case LCD_SEG_L1_3_1: length=3; char_start=LCD_SEG_L1_3; break; - case LCD_SEG_L1_3_2: length=2; char_start=LCD_SEG_L1_3; break; - - // LINE2 - case LCD_SEG_L2_5_0: length=6; char_start=LCD_SEG_L2_5; break; - case LCD_SEG_L2_4_0: length=5; char_start=LCD_SEG_L2_4; break; - case LCD_SEG_L2_3_0: length=4; char_start=LCD_SEG_L2_3; break; - case LCD_SEG_L2_2_0: length=3; char_start=LCD_SEG_L2_2; break; - case LCD_SEG_L2_1_0: length=2; char_start=LCD_SEG_L2_1; break; - case LCD_SEG_L2_5_4: length=2; char_start=LCD_SEG_L2_5; break; - case LCD_SEG_L2_5_2: length=4; char_start=LCD_SEG_L2_5; break; - case LCD_SEG_L2_3_2: length=2; char_start=LCD_SEG_L2_3; break; - case LCD_SEG_L2_4_2: length=3; char_start=LCD_SEG_L2_4; break; + switch (segments) { + /* LINE1 */ + case LCD_SEG_L1_3_0: + length=4; + char_start=LCD_SEG_L1_3; + break; + case LCD_SEG_L1_2_0: + length=3; + char_start=LCD_SEG_L1_2; + break; + case LCD_SEG_L1_1_0: + length=2; + char_start=LCD_SEG_L1_1; + break; + case LCD_SEG_L1_3_1: + length=3; + char_start=LCD_SEG_L1_3; + break; + case LCD_SEG_L1_3_2: + length=2; + char_start=LCD_SEG_L1_3; + break; + + /* LINE2 */ + case LCD_SEG_L2_5_0: + length=6; + char_start=LCD_SEG_L2_5; + break; + case LCD_SEG_L2_4_0: + length=5; + char_start=LCD_SEG_L2_4; + break; + case LCD_SEG_L2_3_0: + length=4; + char_start=LCD_SEG_L2_3; + break; + case LCD_SEG_L2_2_0: + length=3; + char_start=LCD_SEG_L2_2; + break; + case LCD_SEG_L2_1_0: + length=2; + char_start=LCD_SEG_L2_1; + break; + case LCD_SEG_L2_5_4: + length=2; + char_start=LCD_SEG_L2_5; + break; + case LCD_SEG_L2_5_2: + length=4; + char_start=LCD_SEG_L2_5; + break; + case LCD_SEG_L2_3_2: + length=2; + char_start=LCD_SEG_L2_3; + break; + case LCD_SEG_L2_4_2: + length=3; + char_start=LCD_SEG_L2_4; + break; } - // Write to consecutive digits - for(i=0; i) - SEG_A+SEG_B+ SEG_E+ SEG_G, // Displays "?" - 0 , // Displays " " (@) - SEG_A+SEG_B+SEG_C+ SEG_E+SEG_F+SEG_G, // Displays "A" - SEG_C+SEG_D+SEG_E+SEG_F+SEG_G, // Displays "b" - SEG_D+SEG_E+ SEG_G, // Displays "c" - SEG_B+SEG_C+SEG_D+SEG_E+ SEG_G, // Displays "d" - SEG_A+ +SEG_D+SEG_E+SEG_F+SEG_G, // Displays "E" - SEG_A+ SEG_E+SEG_F+SEG_G, // Displays "f" - SEG_A+SEG_B+SEG_C+SEG_D+ SEG_F+SEG_G, // Displays "g" same as 9 - SEG_C+ SEG_E+SEG_F+SEG_G, // Displays "h" - SEG_E , // Displays "i" - SEG_A+SEG_B+SEG_C+SEG_D , // Displays "J" - SEG_D+ SEG_F+SEG_G, // Displays "k" - SEG_D+SEG_E+SEG_F , // Displays "L" - SEG_A+SEG_B+SEG_C+ SEG_E+SEG_F , // Displays "M" - SEG_C+ SEG_E+ SEG_G, // Displays "n" - SEG_C+SEG_D+SEG_E+ SEG_G, // Displays "o" - SEG_A+SEG_B+ SEG_E+SEG_F+SEG_G, // Displays "P" - SEG_A+SEG_B+SEG_C+ SEG_F+SEG_G, // Displays "q" - SEG_E+ SEG_G, // Displays "r" - SEG_A+ SEG_C+SEG_D+ SEG_F+SEG_G, // Displays "S" same as 5 - SEG_D+SEG_E+SEG_F+SEG_G, // Displays "t" - SEG_C+SEG_D+SEG_E , // Displays "u" - SEG_C+SEG_D+SEG_E , // Displays "v" same as u - SEG_B+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G, // Displays "W" - SEG_B+SEG_C+ +SEG_E+SEG_F+SEG_G, // Displays "X" as H - SEG_B+SEG_C+SEG_D+ SEG_F+SEG_G, // Displays "Y" - SEG_A+SEG_B+ SEG_D+SEG_E+ SEG_G, // Displays "Z" same as 2 +/* ************************************************************************************************* + * + * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ************************************************************************************************/ + +/* Basic display functions. */ +/* ************************************************************************************************* */ + +/* ************************************************************************************************* */ +/* Include section */ +#include +#include + +/* ************************************************************************************************* */ +/* Global Variable section */ + +/* Table with memory bit assignment for digits "0" to "9" and characters "A" to "Z" */ +/* A */ +/* F B */ +/* G */ +/* E C */ +/* D */ +const uint8_t lcd_font[] = { + SEG_A+SEG_B+SEG_C+SEG_D+SEG_E+SEG_F, /* Displays "0" */ + SEG_B+SEG_C, /* Displays "1" */ + SEG_A+SEG_B+ SEG_D+SEG_E+ SEG_G, /* Displays "2" */ + SEG_A+SEG_B+SEG_C+SEG_D+ SEG_G, /* Displays "3" */ + SEG_B+SEG_C+ SEG_F+SEG_G, /* Displays "4" */ + SEG_A+ SEG_C+SEG_D+ SEG_F+SEG_G, /* Displays "5" */ + SEG_A+ SEG_C+SEG_D+SEG_E+SEG_F+SEG_G, /* Displays "6" */ + SEG_A+SEG_B+SEG_C, /* Displays "7" */ + SEG_A+SEG_B+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G, /* Displays "8" */ + SEG_A+SEG_B+SEG_C+SEG_D+ SEG_F+SEG_G, /* Displays "9" */ + 0 , /* Displays " " (:) */ + 0 , /* Displays " " (;) */ + SEG_A+ SEG_F+SEG_G, /* Displays "<" as high c */ + SEG_D+ SEG_G, /* Displays "=" */ + 0 , /* Displays " " (>) */ + SEG_A+SEG_B+ SEG_E+ SEG_G, /* Displays "?" */ + 0 , /* Displays " " (@) */ + SEG_A+SEG_B+SEG_C+ SEG_E+SEG_F+SEG_G, /* Displays "A" */ + SEG_C+SEG_D+SEG_E+SEG_F+SEG_G, /* Displays "b" */ + SEG_D+SEG_E+ SEG_G, /* Displays "c" */ + SEG_B+SEG_C+SEG_D+SEG_E+ SEG_G, /* Displays "d" */ + SEG_A+ +SEG_D+SEG_E+SEG_F+SEG_G, /* Displays "E" */ + SEG_A+ SEG_E+SEG_F+SEG_G, /* Displays "f" */ + SEG_A+SEG_B+SEG_C+SEG_D+ SEG_F+SEG_G, /* Displays "g" same as 9 */ + SEG_C+ SEG_E+SEG_F+SEG_G, /* Displays "h" */ + SEG_E , /* Displays "i" */ + SEG_A+SEG_B+SEG_C+SEG_D , /* Displays "J" */ + SEG_D+ SEG_F+SEG_G, /* Displays "k" */ + SEG_D+SEG_E+SEG_F , /* Displays "L" */ + SEG_A+SEG_B+SEG_C+ SEG_E+SEG_F , /* Displays "M" */ + SEG_C+ SEG_E+ SEG_G, /* Displays "n" */ + SEG_C+SEG_D+SEG_E+ SEG_G, /* Displays "o" */ + SEG_A+SEG_B+ SEG_E+SEG_F+SEG_G, /* Displays "P" */ + SEG_A+SEG_B+SEG_C+ SEG_F+SEG_G, /* Displays "q" */ + SEG_E+ SEG_G, /* Displays "r" */ + SEG_A+ SEG_C+SEG_D+ SEG_F+SEG_G, /* Displays "S" same as 5 */ + SEG_D+SEG_E+SEG_F+SEG_G, /* Displays "t" */ + SEG_C+SEG_D+SEG_E , /* Displays "u" */ + SEG_C+SEG_D+SEG_E , /* Displays "v" same as u */ + SEG_B+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G, /* Displays "W" */ + SEG_B+SEG_C+ +SEG_E+SEG_F+SEG_G, /* Displays "X" as H */ + SEG_B+SEG_C+SEG_D+ SEG_F+SEG_G, /* Displays "Y" */ + SEG_A+SEG_B+ SEG_D+SEG_E+ SEG_G, /* Displays "Z" same as 2 */ }; - -// Table with memory address for each display element -const uint8_t * segments_lcdmem[] = -{ +/* Table with memory address for each display element */ +const uint8_t * segments_lcdmem[] = { LCD_SYMB_AM_MEM, LCD_SYMB_PM_MEM, LCD_SYMB_ARROW_UP_MEM, @@ -158,10 +142,8 @@ const uint8_t * segments_lcdmem[] = LCD_SEG_L2_DP_MEM, }; - -// Table with bit mask for each display element -const uint8_t segments_bitmask[] = -{ +/* Table with bit mask for each display element */ +const uint8_t segments_bitmask[] = { LCD_SYMB_AM_MASK, LCD_SYMB_PM_MASK, LCD_SYMB_ARROW_UP_MASK, @@ -206,10 +188,10 @@ const uint8_t segments_bitmask[] = LCD_SEG_L2_DP_MASK, }; - -// Quick integer to array conversion table for most common integer values -const uint8_t itoa_conversion_table[][3] = -{ +/* Quick integer to array conversion table for most common integer values + * discarding this would save aprox. 600 bytes codespace but increase cpu time + * for displaying values */ +const uint8_t itoa_conversion_table[][3] = { "000", "001", "002", "003", "004", "005", "006", "007", "008", "009", "010", "011", "012", "013", "014", "015", "016", "017", "018", "019", "020", "021", "022", "023", "024", "025", "026", "027", "028", "029", "030", "031", "032", "033", "034", "035", "036", "037", "038", "039", "040", "041", "042", "043", "044", "045", "046", "047", @@ -223,4 +205,3 @@ const uint8_t itoa_conversion_table[][3] = "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", }; - diff --git a/drivers/cc110x_ng/Jamfile b/drivers/cc110x_ng/Jamfile index cf44c787a..b47dfc890 100755 --- a/drivers/cc110x_ng/Jamfile +++ b/drivers/cc110x_ng/Jamfile @@ -27,7 +27,7 @@ SubDir TOP drivers cc110x_ng ; -HDRS += $(TOP)/drivers/cc110x_ng ; +HDRS += $(TOP)/drivers/cc110x_ng/include ; Module cc110x_ng : cc110x.c cc110x-rx.c cc110x-tx.c cc110x-defaultSettings.c : hwtimer board_cc110x ; Module cc110x_spi : cc110x_spi.c ; From ddcbd10a03a0a827b610c36d7a950a5afb36e5a9 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 13 Dec 2010 01:29:46 +0100 Subject: [PATCH 148/199] [RTC] * added a general RTC header * added RTC support to chronos --- cpu/cc430/Jamfile | 1 + cpu/cc430/cc430-rtc.c | 184 ++++++++++++++++++++++++++++++ cpu/cc430/include/cc430-rtc.h | 75 ++++++++++++ cpu/lpc2387/include/lpc2387-rtc.h | 36 +----- cpu/msp430-common/include/time.h | 15 +++ drivers/include/rtc.h | 59 ++++++++++ drivers/sht11.c | 1 + sys/auto_init.c | 4 +- sys/shell/id.c | 2 +- sys/shell/rtc.c | 6 +- 10 files changed, 343 insertions(+), 40 deletions(-) create mode 100644 cpu/cc430/cc430-rtc.c create mode 100644 cpu/cc430/include/cc430-rtc.h create mode 100644 cpu/msp430-common/include/time.h create mode 100644 drivers/include/rtc.h diff --git a/cpu/cc430/Jamfile b/cpu/cc430/Jamfile index 416073e25..1614d4fbc 100644 --- a/cpu/cc430/Jamfile +++ b/cpu/cc430/Jamfile @@ -28,5 +28,6 @@ SubDir TOP cpu cc430 ; Module hwtimer_cpu : hwtimer_cc430.c : hwtimer_msp430 ; +Module rtc : cc430-rtc.c ; SubInclude TOP cpu msp430-common ; diff --git a/cpu/cc430/cc430-rtc.c b/cpu/cc430/cc430-rtc.c new file mode 100644 index 000000000..3ef3d7c27 --- /dev/null +++ b/cpu/cc430/cc430-rtc.c @@ -0,0 +1,184 @@ +/****************************************************************************** +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 +*******************************************************************************/ + +#include +#include +#include +#include +#include +#include + +//static volatile time_t epoch; +static struct tm time_to_set; + +/*---------------------------------------------------------------------------*/ +void rtc_init(void) { + /* Set to calendar mode */ + RTCCTL1 |= RTCMODE_H; +} + +/*---------------------------------------------------------------------------*/ +void rtc_enable(void) { + /* Set RTC operational */ + RTCCTL1 &= ~RTCHOLD_H; +} +/*---------------------------------------------------------------------------*/ +void rtc_disable(void) { + /* Stop RTC */ + RTCCTL1 |= RTCHOLD_H; +} +/*---------------------------------------------------------------------------*/ +void rtc_set_localtime(struct tm* localt) { + if(localt == NULL) { + return; + } + + /* copy time to be set */ + memcpy(&time_to_set, localt, sizeof(struct tm)); + /* set interrupt to set this time after the next transition */ + RTCCTL0 |= RTCRDYIE; +} + +/*--------------------------------------------------------------------------- +void rtc_set(time_t time) { + struct tm* localt; + localt = localtime(&time); // convert seconds to broken-down time + rtc_set_localtime(localt); + epoch = time - localt->tm_sec - localt->tm_min * 60; +} +*/ + +/*--------------------------------------------------------------------------- +time_t rtc_time(void) { + time_t sec; + struct tm t; + rtc_get_localtime(&t); + sec = mktime(&t); + return sec; +} +*/ +/*---------------------------------------------------------------------------*/ +void rtc_get_localtime(struct tm* localt) { + uint8_t success = 0; + uint8_t i; + uint16_t tmpyear; + + if( localt == NULL ) { + return; + } + + while (!success) { + for (i = 0; i < 8; i++) { + /* try again when RTC is in transition */ + if (!(RTCCTL1 & RTCRDY_H)) { + break; + } + switch (i) { + case 0: + localt->tm_sec = RTCSEC; + break; + case 1: + localt->tm_min = RTCMIN; + break; + case 2: + localt->tm_hour = RTCHOUR; + break; + case 3: + localt->tm_mday = RTCDAY; + break; + case 4: + localt->tm_wday = RTCDOW; + break; + case 5: + localt->tm_mon = RTCMON - 1; + break; + case 6: + tmpyear = RTCYEARL; + tmpyear |= (RTCYEARH << 0x08); + localt->tm_year = tmpyear - 1900; + break; + default: + success = 1; + break; + } + } + } +} + +/*---------------------------------------------------------------------------*/ +void rtc_set_alarm(struct tm* localt, rtc_alarm_mask_t mask) { + if (mask & RTC_ALARM_MIN) { + RTCAMIN = localt->tm_min; + RTCAMIN |= BIT7; + } + if (mask & RTC_ALARM_HOUR) { + RTCAHOUR = localt->tm_hour; + RTCAHOUR |= BIT7; + } + if (mask & RTC_ALARM_DOW) { + RTCADOW = localt->tm_wday; + RTCADOW |= BIT7; + } + if (mask & RTC_ALARM_DOM) { + RTCADAY = localt->tm_mday; + RTCADAY |= BIT7; + } + RTCCTL0 |= RTCAIE; +} + +/*---------------------------------------------------------------------------*/ +void rtc_remove_alarm(void) { + /* reset all AE bits */ + RTCAHOUR &= ~BIT7; + RTCAMIN &= ~BIT7; + RTCADAY &= ~BIT7; + RTCADOW &= ~BIT7; + + /* reset alarm interrupt enable */ + RTCCTL0 &= ~RTCAIE; +} +/*---------------------------------------------------------------------------*/ +interrupt(RTC_VECTOR) __attribute__ ((naked)) rtc_isr(void) { + __enter_isr(); + /* RTC is save to write for up to one second now */ + if (RTCIV == RTC_RTCRDYIFG) { + /* disable interrupt */ + RTCCTL0 &= ~RTCRDYIE; + /* set previous set time and reset it */ + RTCSEC = time_to_set.tm_sec; + RTCMIN = time_to_set.tm_min; + RTCHOUR = time_to_set.tm_hour; + RTCDAY = time_to_set.tm_mday; + RTCDOW = time_to_set.tm_wday; + RTCMON = time_to_set.tm_mon + 1; + RTCYEARL = (time_to_set.tm_year + 1900) & 0xFF; + RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08; + } + /* RTC alarm */ + else if (RTCIV == RTC_RTCAIFG) { + } + __exit_isr(); +} diff --git a/cpu/cc430/include/cc430-rtc.h b/cpu/cc430/include/cc430-rtc.h new file mode 100644 index 000000000..15e27bdb4 --- /dev/null +++ b/cpu/cc430/include/cc430-rtc.h @@ -0,0 +1,75 @@ +/****************************************************************************** +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 +*******************************************************************************/ + +#ifndef CC430_RTC_H +#define CC430_RTC_H +#include +#include + +/** + * @defgroup cc430_rtc CC430 Real Time Clock + * @ingroup cc430 + */ + +/** + * @file cc430-rtc.h + * @brief CC430 Real Time Clock + * + * @author Freie Universität Berlin, Computer Systems & Telematics, µkleos + * @version $Revision $ + */ + +/** + * @brief Mask for RTC alarms + * @see ::rtc_set_alarm + */ +typedef enum { + RTC_ALARM_DISABLED = 0x00, ///< Alarm disables + RTC_ALARM_MIN = 0x01, ///< Alarm mask for Minutes + RTC_ALARM_HOUR = 0x02, ///< Alarm mask for Hours + RTC_ALARM_DOW = 0x04, ///< Alarm mask for Day of Week + RTC_ALARM_DOM = 0x08 ///< Alarm mask for Day of Month +} rtc_alarm_mask_t; + +/** + * @brief Sets the alarm + * @internal + * @param[in] localt Alarm time + * @param[in] mask Sets the registers to poll for the alarm + * + * To disable the alarm set mask to RTC_ALARM_DISABLED. + * + * @see ::rtc_alarm_mask + */ +void rtc_set_alarm(struct tm* localti, rtc_alarm_mask_t mask); + +/** + * @brief Resets any set alarm + */ +void rtc_remove_alarm(void); + + +#endif diff --git a/cpu/lpc2387/include/lpc2387-rtc.h b/cpu/lpc2387/include/lpc2387-rtc.h index c1580329e..1f7793fa2 100644 --- a/cpu/lpc2387/include/lpc2387-rtc.h +++ b/cpu/lpc2387/include/lpc2387-rtc.h @@ -24,8 +24,8 @@ and the mailinglist (subscription via web site) scatterweb@lists.spline.inf.fu-berlin.de *******************************************************************************/ -#ifndef __RTC_H -#define __RTC_H +#ifndef LPC2387_RTC_H +#define LPC2387_RTC_H /** * @defgroup lpc2387_rtc LPC2387 Real-Time-Clock @@ -48,9 +48,10 @@ and the mailinglist (subscription via web site) * @note $Id: lpc2387-rtc.h 1998 2010-03-16 13:05:41Z baar $ */ +#include #include #include -#include "lpc2387.h" +#include /* ------------------------------------------------------------------------- */ /** @@ -76,13 +77,6 @@ enum rtc_alarm_mask { RTC_AMR_YEAR= AMRYEAR, ///< Alarm mask for Year }; -/** - * @brief Initializes the RTC - * @internal - * During reboots only alarms are reset. - */ -void rtc_init(void); - void rtc_reset(void); /** @@ -91,12 +85,6 @@ 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 @@ -111,22 +99,6 @@ time_t rtc_time(struct timeval* time); */ void rtc_set(time_t time); -/** - * @brief Enables the RTC - */ -void rtc_enable(void); - -/** - * @brief Disables the RTC - */ -void rtc_disable(void); - -/** - * @brief Returns the current time in broken down format directly from the RTC - * @param[out] localt Pointer to structure to receive time - */ -void rtc_get_localtime(struct tm* localt); - /** * @brief Sets the alarm * @internal diff --git a/cpu/msp430-common/include/time.h b/cpu/msp430-common/include/time.h new file mode 100644 index 000000000..97bf471f4 --- /dev/null +++ b/cpu/msp430-common/include/time.h @@ -0,0 +1,15 @@ +#ifndef MSPGCC_TIME_H +#define MSPGCC_TIME_H + +struct tm +{ + int tm_sec; // Seconds after the minute [0, 59] + int tm_min; // Minutes after the hour [0, 59] + int tm_hour; // Hours since midnight [0, 23] + int tm_mday; // Day of the month [1, 31] + int tm_mon; // Months since January [0, 11] + int tm_year; // Years since 1900 + int tm_wday; // Days since Sunday [0, 6] +}; + +#endif diff --git a/drivers/include/rtc.h b/drivers/include/rtc.h new file mode 100644 index 000000000..d36382cfd --- /dev/null +++ b/drivers/include/rtc.h @@ -0,0 +1,59 @@ +/****************************************************************************** +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 +*******************************************************************************/ + +#ifndef RTC_H +#define RTC_H + +#include + +/** + * @brief Initializes the RTC for calendar mode + */ +void rtc_init(void); + +/** + * @brief Starts the RTC + */ +void rtc_enable(void); + +/** + * @brief Stops the RTC + */ +void rtc_disable(void); + +/** + * @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 time in broken down format directly from the RTC + * @param[out] localt Pointer to structure to receive time + */ +void rtc_get_localtime(struct tm* localt); + +#endif diff --git a/drivers/sht11.c b/drivers/sht11.c index d4bb6ec96..c81cfc56b 100644 --- a/drivers/sht11.c +++ b/drivers/sht11.c @@ -44,6 +44,7 @@ and the mailinglist (subscription via web site) #include #include #include +#include //#define ENABLE_DEBUG (1) #include diff --git a/sys/auto_init.c b/sys/auto_init.c index cbb7db914..2dc5338b9 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -1,9 +1,7 @@ #include #include #include -#ifdef MODULE_RTC -#include -#endif +#include #include #define ENABLE_DEBUG diff --git a/sys/shell/id.c b/sys/shell/id.c index f77778553..414997bac 100644 --- a/sys/shell/id.c +++ b/sys/shell/id.c @@ -12,8 +12,8 @@ void _id_handler(char *id) { } else { printf("Setting new id %lu\n", newid); - sysconfig.id = newid; #ifdef MODULE_CONFIG + sysconfig.id = newid; if (!config_save()) { puts("ERROR setting new id"); } diff --git a/sys/shell/rtc.c b/sys/shell/rtc.c index 476175e20..74550f81e 100644 --- a/sys/shell/rtc.c +++ b/sys/shell/rtc.c @@ -3,8 +3,7 @@ #include #ifdef MODULE_RTC -#include -#include +#include void _gettime_handler(void) { struct tm now; @@ -36,8 +35,7 @@ void _settime_handler(char* c) { now.tm_year = epoch_year - 1900; now.tm_mon = month - 1; - time_t t = mktime(&now); - rtc_set(t); + rtc_set_localtime(&now); } void _date_handler(char* c) { From 33512d9fbc6dca2d452bfae86de1549a728948ea Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 13 Dec 2010 01:30:46 +0100 Subject: [PATCH 149/199] [board/msb-430h] * fixed include --- board/msb-430h/driver_cc110x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board/msb-430h/driver_cc110x.c b/board/msb-430h/driver_cc110x.c index a0967b272..9316e8bf5 100644 --- a/board/msb-430h/driver_cc110x.c +++ b/board/msb-430h/driver_cc110x.c @@ -24,7 +24,7 @@ Boston, MA 02111-1307, USA. */ #include #include -#include +#include #define CC1100_GDO0 (P2IN & 0x02) // read serial I/O (GDO0) #define CC1100_GDO1 (P3IN & 0x04) // read serial I/O (GDO1) From eb88673aa5af90a695e00162522714d1845abbbd Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 13 Dec 2010 21:19:58 +0100 Subject: [PATCH 150/199] [board/chronos/drivers] * simple buzzer driver --- board/chronos/Jamrules.chronos | 2 ++ board/chronos/drivers/Jamfile | 3 +++ board/chronos/drivers/buzzer.c | 27 +++++++++++++++++++ board/chronos/drivers/include/buzzer.h | 6 +++++ board/chronos/drivers/{ => include}/display.h | 0 5 files changed, 38 insertions(+) create mode 100644 board/chronos/drivers/buzzer.c create mode 100644 board/chronos/drivers/include/buzzer.h rename board/chronos/drivers/{ => include}/display.h (100%) diff --git a/board/chronos/Jamrules.chronos b/board/chronos/Jamrules.chronos index 4c975ae1f..4c17a9a9a 100644 --- a/board/chronos/Jamrules.chronos +++ b/board/chronos/Jamrules.chronos @@ -7,6 +7,8 @@ BOARD = chronos ; CPU = cc430 ; MCU = cc430x6137 ; +HDRS += [ FPath $(TOP) board chronos drivers include ] ; + FLASHER ?= mspdebug ; FLASHFLAGS ?= rf2500 ; diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index 4b2a0d0a8..d89390029 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -1,4 +1,7 @@ SubDir TOP board chronos drivers ; +HDRS += $(TOP)/board/$(CPU)/drivers/include ; + Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; +Module board_buzzer : buzzer.c : hwtimer ; diff --git a/board/chronos/drivers/buzzer.c b/board/chronos/drivers/buzzer.c new file mode 100644 index 000000000..79002f992 --- /dev/null +++ b/board/chronos/drivers/buzzer.c @@ -0,0 +1,27 @@ +#include +#include +#include + +void buzzer_beep(uint8_t pitch, uint16_t duration) { + // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK + TA1CTL = TACLR | MC_1 | TASSEL__ACLK; + + // Set PWM frequency + TA1CCR0 = pitch; + + // Enable IRQ, set output mode "toggle" + TA1CCTL0 = OUTMOD_4; + + // Allow buzzer PWM output on P2.7 + P2SEL |= BIT7; + + hwtimer_wait(duration); + + // Stop PWM timer + TA1CTL &= ~(BIT4 | BIT5); + + // Reset and disable buzzer PWM output + P2OUT &= ~BIT7; + P2SEL &= ~BIT7; + TA1CCTL0 &= ~CCIE; +} diff --git a/board/chronos/drivers/include/buzzer.h b/board/chronos/drivers/include/buzzer.h new file mode 100644 index 000000000..1786b0c51 --- /dev/null +++ b/board/chronos/drivers/include/buzzer.h @@ -0,0 +1,6 @@ +#ifndef BUZZER_H +#define BUZZER_H + +void buzzer_beep(uint8_t pitch, uint16_t duration); + +#endif /* BUZZER_H */ diff --git a/board/chronos/drivers/display.h b/board/chronos/drivers/include/display.h similarity index 100% rename from board/chronos/drivers/display.h rename to board/chronos/drivers/include/display.h From 13767043e7c9020ab41f2b8aef06b13e6414bd23 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 14 Dec 2010 00:24:42 +0100 Subject: [PATCH 151/199] [cpu/cc430/gpioint] * introduced gpioint to make buttons usable --- board/chronos/drivers/buzzer.c | 1 + board/chronos/include/buttons.h | 11 + cpu/cc430/Jamfile | 1 + cpu/cc430/cc430-gpioint.c | 270 +++++++++++++++++++++ projects/chronos_default/Jamfile | 5 + projects/chronos_default/main.c | 138 +++++++++++ projects/chronos_default/tests/hello-world | 13 + projects/default/Jamfile | 2 +- 8 files changed, 440 insertions(+), 1 deletion(-) create mode 100644 board/chronos/include/buttons.h create mode 100644 cpu/cc430/cc430-gpioint.c create mode 100644 projects/chronos_default/Jamfile create mode 100644 projects/chronos_default/main.c create mode 100755 projects/chronos_default/tests/hello-world diff --git a/board/chronos/drivers/buzzer.c b/board/chronos/drivers/buzzer.c index 79002f992..5e0bc2ca3 100644 --- a/board/chronos/drivers/buzzer.c +++ b/board/chronos/drivers/buzzer.c @@ -1,5 +1,6 @@ #include #include +#include #include void buzzer_beep(uint8_t pitch, uint16_t duration) { diff --git a/board/chronos/include/buttons.h b/board/chronos/include/buttons.h new file mode 100644 index 000000000..4e7ab28dc --- /dev/null +++ b/board/chronos/include/buttons.h @@ -0,0 +1,11 @@ +#ifndef BUTTONS_H +#define BUTTONS_H + +// Button ports +#define BUTTON_STAR_PIN (BIT2) +#define BUTTON_NUM_PIN (BIT1) +#define BUTTON_UP_PIN (BIT4) +#define BUTTON_DOWN_PIN (BIT0) +#define BUTTON_BACKLIGHT_PIN (BIT3) + +#endif diff --git a/cpu/cc430/Jamfile b/cpu/cc430/Jamfile index 1614d4fbc..dafac6212 100644 --- a/cpu/cc430/Jamfile +++ b/cpu/cc430/Jamfile @@ -29,5 +29,6 @@ SubDir TOP cpu cc430 ; Module hwtimer_cpu : hwtimer_cc430.c : hwtimer_msp430 ; Module rtc : cc430-rtc.c ; +Module gpioint : cc430-gpioint.c ; SubInclude TOP cpu msp430-common ; diff --git a/cpu/cc430/cc430-gpioint.c b/cpu/cc430/cc430-gpioint.c new file mode 100644 index 000000000..ec2187964 --- /dev/null +++ b/cpu/cc430/cc430-gpioint.c @@ -0,0 +1,270 @@ +/****************************************************************************** +Copyright 2010, Freie Universität Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of µkleos. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/** min and max portnumber to generate interrupts */ +#define PORTINT_MIN (1) +#define PORTINT_MAX (2) + +/** amount of interrupt capable ports */ +#define INT_PORTS (2) + +/** number of bits per port */ +#define BITMASK_SIZE (8) + +/** debouncing port interrupts */ +#define DEBOUNCE_TIMEOUT (50) + +/** interrupt callbacks */ +fp_irqcb cb[INT_PORTS][BITMASK_SIZE]; + +static int8_t calc_log2(uint8_t power); + +void gpioint_init(void) { + uint8_t i, j; + for (i = 0; i < INT_PORTS; i++) { + for (j = 0; j < BITMASK_SIZE; j++) { + cb[i][j] = NULL; + } + } +} + +bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { + int8_t base; + + if ((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) { + /* set the callback function */ + base = calc_log2(bitmask); + if (base >= 0) { + cb[port - PORTINT_MIN][calc_log2(bitmask)] = callback; + } + else { + return false; + } + } + + switch (port) { + case 1: + /* set port to input */ + P1DIR &= ~bitmask; + /* enable internal pull-down */ + P1OUT &= ~bitmask; + P1REN |= bitmask; + + /* reset IRQ flag */ + P1IFG &= ~bitmask; + + /* trigger on rising... */ + if (flags == GPIOINT_RISING_EDGE) { + P1IES &= bitmask; + } + /* ...or falling edge */ + else if (flags == GPIOINT_FALLING_EDGE) { + P1IES |= bitmask; + } + /* or disable interrupt */ + else { + P1IE &= ~bitmask; + } + /* enable interrupt */ + P1IE |= bitmask; + break; + case 2: + /* set port to input */ + P2DIR &= ~bitmask; + /* enable internal pull-down */ + P2OUT &= ~bitmask; + P2REN |= bitmask; + + /* reset IRQ flag */ + P2IFG &= ~bitmask; + + /* trigger on rising... */ + if (flags == GPIOINT_RISING_EDGE) { + P2IES &= bitmask; + } + /* ...or falling edge */ + else if (flags == GPIOINT_FALLING_EDGE) { + P2IES |= bitmask; + } + /* or disable interrupt */ + else { + P2IE &= ~bitmask; + } + /* enable interrupt */ + P2IE |= bitmask; + break; + default: + return false; + } + return 1; +} + +static int8_t calc_log2(uint8_t power) { + int8_t i; + for (i = 7; i >= 0; i--) { + if ((power >> i) & 1) { + return i; + } + } + return -1; +} + +interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { + uint8_t int_enable, istate; + uint16_t p1iv; + __enter_isr(); + + /* Debounce + * Disable PORT1 IRQ + */ + p1iv = P1IV; + istate = disableIRQ(); + int_enable = P1IE; + restoreIRQ(istate); + P1IE = 0x00; + hwtimer_wait(DEBOUNCE_TIMEOUT); + + switch (p1iv) { + case P1IV_P1IFG0: + if ((P1IN & P1IV_P1IFG0) & P1IV_P1IFG0) { + cb[0][0](); + } + break; + case P1IV_P1IFG1: + if ((P1IN & P1IV_P1IFG1) & P1IV_P1IFG1) { + cb[0][1](); + } + break; + case P1IV_P1IFG2: + if ((P1IN & P1IV_P1IFG2) & P1IV_P1IFG2) { + cb[0][2](); + } + break; + case P1IV_P1IFG3: + if ((P1IN & P1IV_P1IFG3) & P1IV_P1IFG3) { + cb[0][3](); + } + break; + case P1IV_P1IFG4: + if ((P1IN & P1IV_P1IFG4) & P1IV_P1IFG4) { + cb[0][4](); + } + break; + case P1IV_P1IFG5: + if ((P1IN & P1IV_P1IFG5) & P1IV_P1IFG5) { + cb[0][5](); + } + break; + case P1IV_P1IFG6: + if ((P1IN & P1IV_P1IFG6) & P1IV_P1IFG6) { + cb[0][6](); + } + break; + case P1IV_P1IFG7: + if ((P1IN & P1IV_P1IFG7) & P1IV_P1IFG7) { + cb[0][7](); + } + break; + } + P1IFG = 0x00; + istate = disableIRQ(); + P1IE = int_enable; + restoreIRQ(istate); + __exit_isr(); +} + +interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { + uint8_t int_enable, istate; + uint16_t p2iv; + __enter_isr(); + + /* Debounce + * Disable PORT2 IRQ + */ + p2iv = P2IV; + istate = disableIRQ(); + int_enable = P2IE; + restoreIRQ(istate); + P2IE = 0x00; + hwtimer_wait(DEBOUNCE_TIMEOUT); + + switch (p2iv) { + case P2IV_P2IFG0: + if ((P2IN & P2IV_P2IFG0) & P2IV_P2IFG0) { + cb[1][0](); + } + break; + case P2IV_P2IFG1: + if ((P2IN & P2IV_P2IFG1) & P2IV_P2IFG1) { + cb[1][1](); + } + break; + case P2IV_P2IFG2: + if ((P2IN & P2IV_P2IFG2) & P2IV_P2IFG2) { + cb[1][2](); + } + break; + case P2IV_P2IFG3: + if ((P2IN & P2IV_P2IFG3) & P2IV_P2IFG3) { + cb[1][3](); + } + break; + case P2IV_P2IFG4: + if ((P2IN & P2IV_P2IFG4) & P2IV_P2IFG4) { + cb[1][4](); + } + break; + case P2IV_P2IFG5: + if ((P2IN & P2IV_P2IFG5) & P2IV_P2IFG5) { + cb[1][5](); + } + break; + case P2IV_P2IFG6: + if ((P2IN & P2IV_P2IFG6) & P2IV_P2IFG6) { + cb[1][6](); + } + break; + case P2IV_P2IFG7: + if ((P2IN & P2IV_P2IFG7) & P2IV_P2IFG7) { + cb[1][7](); + } + break; + } + P2IFG = 0x00; + istate = disableIRQ(); + P2IE = int_enable; + restoreIRQ(istate); + __exit_isr(); +} + diff --git a/projects/chronos_default/Jamfile b/projects/chronos_default/Jamfile new file mode 100644 index 000000000..515f82219 --- /dev/null +++ b/projects/chronos_default/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects chronos_default ; + +Module chronos_default : main.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint ; + +UseModule chronos_default ; diff --git a/projects/chronos_default/main.c b/projects/chronos_default/main.c new file mode 100644 index 000000000..3894f4ae6 --- /dev/null +++ b/projects/chronos_default/main.c @@ -0,0 +1,138 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define RADIO_STACK_SIZE (512) +#define SEND_SIZE CC1100_MAX_DATA_LENGTH + +#define RCV_BUFFER_SIZE (4) + +#define SENDING_DELAY (5 * 1000) + +char radio_stack_buffer[RADIO_STACK_SIZE]; + +uint8_t snd_buffer[SEND_SIZE]; + +msg msg_q[RCV_BUFFER_SIZE]; + +static msg mesg; +static transceiver_command_t tcmd; +static radio_packet_t p; + +static uint8_t mode = 0; + +void send(radio_address_t dst, uint8_t len, uint8_t *data); + +void send(radio_address_t dst, uint8_t len, uint8_t *data) { + mesg.type = SND_PKT; + mesg.content.ptr = (char*) &tcmd; + + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &p; + + p.length = len; + p.dst = dst; + display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); + display_chars(LCD_SEG_L2_5_0, (char*) itoa(p.dst, 6, 0), SEG_ON); + + p.data = data; + msg_send(&mesg, transceiver_pid, 1); +} + +void radio(void) { + msg m; + radio_packet_t *p; + + msg_init_queue(msg_q, RCV_BUFFER_SIZE); + + while (1) { + msg_receive(&m); + if (m.type == PKT_PENDING) { + + p = (radio_packet_t*) m.content.ptr; + display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); + display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON); + send(p->src, p->length, p->data); + + + p->processing--; + } + else if (m.type == ENOBUFFER) { + } + else { + } + } +} + +void change_mode(void) { + buzzer_beep(15, 5000); + if (mode) { + mode = 0; + } + else { + mode = 1; + } +} + +int main(void) { + int radio_pid; + struct tm now; + + now.tm_min = 5; + now.tm_sec = 42; + + rtc_set_localtime(&now); + + now.tm_min = 6; + + rtc_set_alarm(&now, RTC_ALARM_MIN); + + gpioint_set(2, BUTTON_STAR_PIN, GPIOINT_RISING_EDGE, change_mode); + + radio_address_t addr = 43; + memset(snd_buffer, 43, SEND_SIZE); + radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); + transceiver_init(TRANSCEIVER_CC1100); + transceiver_start(); + transceiver_register(TRANSCEIVER_CC1100, radio_pid); + + lcd_init(); + clear_display_all(); + mesg.type = SET_ADDRESS; + mesg.content.ptr = (char*) &tcmd; + + display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_ON); + tcmd.transceivers = TRANSCEIVER_CC1100; + tcmd.data = &addr; + msg_send(&mesg, transceiver_pid, 1); + + send(12, SEND_SIZE, snd_buffer); + + while (1) { + hwtimer_wait(SENDING_DELAY); + rtc_get_localtime(&now); + + switch (mode) { + case 0: + display_chars(LCD_SEG_L1_3_0, (char*) itoa(now.tm_sec, 4, 0), SEG_ON); + break; + case 1: + display_chars(LCD_SEG_L1_3_0, (char*) itoa(now.tm_min, 4, 0), SEG_ON); + break; + } + } +} diff --git a/projects/chronos_default/tests/hello-world b/projects/chronos_default/tests/hello-world new file mode 100755 index 000000000..acde8265f --- /dev/null +++ b/projects/chronos_default/tests/hello-world @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "Hello World!" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" + diff --git a/projects/default/Jamfile b/projects/default/Jamfile index 1acfc711c..a428e7211 100644 --- a/projects/default/Jamfile +++ b/projects/default/Jamfile @@ -6,6 +6,6 @@ SubDir TOP projects default ; -Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 cc110x_ng transceiver gpioint auto_init ; +Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 cc110x_ng transceiver gpioint auto_init config ; UseModule default_project ; From ed0e2bc2fa0aa42f181dbb8b02bee02f2aa77bd1 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 11:39:52 +0100 Subject: [PATCH 152/199] * minor file rename --- board/msb-430-common/Jamfile | 2 +- board/msb-430-common/{debug_uart.c => uart1.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename board/msb-430-common/{debug_uart.c => uart1.c} (100%) diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile index 17bf86c9b..b59f8c474 100644 --- a/board/msb-430-common/Jamfile +++ b/board/msb-430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430-common ; -Module board : board_init.c debug_uart.c ; +Module board : board_init.c uart1.c ; Module board_config : board_config.c ; UseModule board ; diff --git a/board/msb-430-common/debug_uart.c b/board/msb-430-common/uart1.c similarity index 100% rename from board/msb-430-common/debug_uart.c rename to board/msb-430-common/uart1.c From 99b4dd7314964ee016a595c1c5e45c4646bcdf45 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 16:40:47 +0100 Subject: [PATCH 153/199] * chronos display putchar included --- board/chronos/Jamfile | 2 +- board/chronos/drivers/Jamfile | 2 + board/chronos/drivers/display_putchar.c | 42 ++++++++++++++ .../chronos/drivers/include/display_putchar.h | 6 ++ board/chronos/putchar.c | 11 ++++ board/msb-430-common/putchar.c | 7 +++ projects/hi_earth/Jamfile | 2 +- projects/hi_earth/main.c | 56 +------------------ sys/auto_init.c | 10 ++++ 9 files changed, 82 insertions(+), 56 deletions(-) create mode 100644 board/chronos/drivers/display_putchar.c create mode 100644 board/chronos/drivers/include/display_putchar.h create mode 100644 board/chronos/putchar.c create mode 100644 board/msb-430-common/putchar.c diff --git a/board/chronos/Jamfile b/board/chronos/Jamfile index bf3341d78..0899e4631 100644 --- a/board/chronos/Jamfile +++ b/board/chronos/Jamfile @@ -2,7 +2,7 @@ SubDir TOP board chronos ; HDRS += $(TOP)/board/$(CPU)/include ; -Module board : debug_uart.c board_init.c ; +Module board : putchar.c board_init.c ; UseModule board ; SubInclude TOP board $(BOARD) drivers ; diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index d89390029..54d2fb4e7 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -5,3 +5,5 @@ HDRS += $(TOP)/board/$(CPU)/drivers/include ; Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; + +Module display_putchar : display_putchar.c : board_display ; diff --git a/board/chronos/drivers/display_putchar.c b/board/chronos/drivers/display_putchar.c new file mode 100644 index 000000000..2f1d9468a --- /dev/null +++ b/board/chronos/drivers/display_putchar.c @@ -0,0 +1,42 @@ +#include +#include +#include + +extern int toupper(int c); +extern void (*_putchar)(int c); + +static char display_buf[11]; + +void putchar_to_display(); + +void init_display_putchar() { + memset(display_buf, '\0', 11); + _putchar = putchar_to_display; +} + +void putchar_to_display(int c) { + if (c == '\n') { + display_buf[4] = 1; + return; + } + + if (display_buf[4]) { + memset(display_buf, '\0', 11); + } else { + display_buf[0] = display_buf[1]; + display_buf[1] = display_buf[2]; + display_buf[2] = display_buf[3]; + display_buf[3] = display_buf[5]; + display_buf[5] = display_buf[6]; + display_buf[6] = display_buf[7]; + display_buf[7] = display_buf[8]; + display_buf[8] = display_buf[9]; + } + + display_buf[9] = toupper(c); + + clear_display_all(); + + display_chars(LCD_SEG_L1_3_0, display_buf, SEG_ON); + display_chars(LCD_SEG_L2_5_0, display_buf+4, SEG_ON); +} diff --git a/board/chronos/drivers/include/display_putchar.h b/board/chronos/drivers/include/display_putchar.h new file mode 100644 index 000000000..6adbb9c9c --- /dev/null +++ b/board/chronos/drivers/include/display_putchar.h @@ -0,0 +1,6 @@ +#ifndef __DISPLAY_PUTCHAR_H +#define __DISPLAY_PUTCHAR_H + +void init_display_putchar(); + +#endif /* __DISPLAY_PUTCHAR_H */ diff --git a/board/chronos/putchar.c b/board/chronos/putchar.c new file mode 100644 index 000000000..436d350f5 --- /dev/null +++ b/board/chronos/putchar.c @@ -0,0 +1,11 @@ +static void _dummy(int c) { +} + +void (*_putchar)(int c) = _dummy; + +int putchar(int c) +{ + _putchar(c); + return c; +} + diff --git a/board/msb-430-common/putchar.c b/board/msb-430-common/putchar.c new file mode 100644 index 000000000..4193c0db4 --- /dev/null +++ b/board/msb-430-common/putchar.c @@ -0,0 +1,7 @@ +#include + +void (_putchar(int)) = uart1_putchar; + +void putchar(int c) { + _putchar(c); +} diff --git a/projects/hi_earth/Jamfile b/projects/hi_earth/Jamfile index b59a2a7d3..812f2c912 100644 --- a/projects/hi_earth/Jamfile +++ b/projects/hi_earth/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects hi_earth ; -Module hi_earth : main.c : board_display hwtimer auto_init ; +Module hi_earth : main.c : auto_init display_putchar ; UseModule hi_earth ; diff --git a/projects/hi_earth/main.c b/projects/hi_earth/main.c index a335d450e..fa70601b9 100644 --- a/projects/hi_earth/main.c +++ b/projects/hi_earth/main.c @@ -1,61 +1,9 @@ -//****************************************************************************** -// eZ430 chronos hello world -// Description: initializes lcd module and shows the string 'hi earth' on the -// lcd display becuase 'hello world' is too long -// Author: Felix Genicio -//****************************************************************************** - -#include -#include -#include -#include - -void display1(void); -void display2(void); +#include int main(void) { - lcd_init(); - - clear_display_all(); - - uint8_t i = 0; - uint16_t j; + printf("Hi Earth\n"); while(1) { - if (i) { - i = 0; - display1(); - } - else { - i = 1; - display2(); - } - for (j = 1; j < 10; j++) { - hwtimer_wait(3333); - } - display_symbol(5, SEG_ON); -/* - for (j = 1; j != 0; j++) { - if (i) { - display_symbol(LCD_ICON_BEEPER1, SEG_ON); - } - else { - display_symbol(5, SEG_OFF); - } - } -*/ } } - -void display1(void) { - display_chars(LCD_SEG_L1_3_0, "HI", SEG_ON); - display_chars(LCD_SEG_L2_5_0, " EARTH", SEG_OFF); -} - -void display2(void) { - display_chars(LCD_SEG_L1_3_0, "HI", SEG_OFF); - display_chars(LCD_SEG_L2_5_0, (char*) itoa(TA0R, 6, 0), SEG_ON); -// display_chars(LCD_SEG_L2_5_0, (uint8_t*) " EARTH", SEG_ON); -} - diff --git a/sys/auto_init.c b/sys/auto_init.c index 2dc5338b9..071ad1836 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #define ENABLE_DEBUG @@ -10,6 +12,14 @@ extern void main(void); void auto_init(void) { +#ifdef MODULE_BOARD_DISPLAY + lcd_init(); + DEBUG("DISP OK"); +#endif +#ifdef MODULE_DISPLAY_PUTCHAR + init_display_putchar(); + DEBUG("DISP OK"); +#endif #ifdef MODULE_HWTIMER DEBUG("Auto init hwtimer module.\n"); hwtimer_init(); From 3b99c3955e0ba2f8ed4f2b490dcb2909f6be7310 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 16:41:06 +0100 Subject: [PATCH 154/199] file obsoleted --- board/chronos/debug_uart.c | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 board/chronos/debug_uart.c diff --git a/board/chronos/debug_uart.c b/board/chronos/debug_uart.c deleted file mode 100644 index d80c9c6e8..000000000 --- a/board/chronos/debug_uart.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include "board.h" - -#define UART1_TX TXBUF1 -#define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); } - - -int putchar(int c) -{ -// UART1_TX = c; -// UART1_WAIT_TXDONE(); -// -// if (c == 10) { -// UART1_TX = 13; -// UART1_WAIT_TXDONE(); -// } - - return c; -} - - From 33b68f374468d93e3235ce45a68e48512a52e44b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 14 Dec 2010 16:44:32 +0100 Subject: [PATCH 155/199] * moved flashrom from msp430-common to msb430x16x --- board/msb-430-common/Jamfile | 2 +- cpu/msp430x16x/flashrom.c | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 cpu/msp430x16x/flashrom.c diff --git a/board/msb-430-common/Jamfile b/board/msb-430-common/Jamfile index 17bf86c9b..147e49ea2 100644 --- a/board/msb-430-common/Jamfile +++ b/board/msb-430-common/Jamfile @@ -28,7 +28,7 @@ SubDir TOP board msb-430-common ; Module board : board_init.c debug_uart.c ; -Module board_config : board_config.c ; +Module board_config : board_config.c : flashrom ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/cpu/msp430x16x/flashrom.c b/cpu/msp430x16x/flashrom.c new file mode 100644 index 000000000..686e0cc3d --- /dev/null +++ b/cpu/msp430x16x/flashrom.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include + +uint8_t ie1, ie2; + +static uint8_t prepare(void); +static void finish(uint8_t istate); +static inline void busy_wait(void); + +/*---------------------------------------------------------------------------*/ +uint8_t flashrom_erase(uint8_t *addr) { + uint8_t istate = prepare(); + + FCTL3 = FWKEY; /* Lock = 0 */ + busy_wait(); + FCTL1 = FWKEY | ERASE; + *addr = 0; /* erase Flash segment */ + busy_wait(); + FCTL1 = FWKEY; /* ERASE = 0 */ + FCTL3 = FWKEY | LOCK; + finish(istate); + return 1; +} + +void flashrom_write(uint8_t *dst, uint8_t *src, size_t size) { + unsigned int i; + FCTL3 = FWKEY; /* Lock = 0 */ + busy_wait(); + for (i = size; i > 0; i--) { + FCTL1 = FWKEY | WRT; + *dst = *src; /* program Flash word */ + while (!(FCTL3 & WAIT)) { + nop(); + } + } + busy_wait(); + FCTL1 = FWKEY; /* WRT = 0 */ + FCTL3 = FWKEY | LOCK; /* Lock = 1 */ +} + +/*---------------------------------------------------------------------------*/ +static uint8_t prepare(void) { + uint8_t istate; + + /* Disable all interrupts. */ + + /* Clear interrupt flag1. */ + IFG1 = 0; + + /* DCO(SMCLK) is 2,4576MHz, /6 = 409600 Hz + select SMCLK for flash timing, divider 4+1 */ + FCTL2 = FWKEY | FSSEL_3 | FN2 | FN0; + + /* disable all interrupts to protect CPU + during programming from system crash */ + istate = disableIRQ(); + + /* disable all NMI-Interrupt sources */ + ie1 = IE1; + ie2 = IE2; + IE1 = 0x00; + IE2 = 0x00; + return istate; +} +/*---------------------------------------------------------------------------*/ +void finish(uint8_t istate) { + /* Enable interrupts. */ + IE1 = ie1; + IE2 = ie2; + restoreIRQ(istate); +} + +static inline void busy_wait(void) { + /* Wait for BUSY = 0, not needed unless run from RAM */ + while(FCTL3 & 0x0001) { + nop(); + } +} From 3c343560e9b9ad1504fd77d9fffa3e30cad0aa22 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 15 Dec 2010 12:43:15 +0100 Subject: [PATCH 156/199] * fix auto init --- sys/auto_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/auto_init.c b/sys/auto_init.c index 071ad1836..e9e7a4d48 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -2,8 +2,6 @@ #include #include #include -#include -#include #include #define ENABLE_DEBUG @@ -13,10 +11,12 @@ extern void main(void); void auto_init(void) { #ifdef MODULE_BOARD_DISPLAY + extern void lcd_init(); lcd_init(); DEBUG("DISP OK"); #endif #ifdef MODULE_DISPLAY_PUTCHAR + extern void init_display_putchar(); init_display_putchar(); DEBUG("DISP OK"); #endif From d499b5d2c8ca972c8c95c415ac83153f366cff6f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 15 Dec 2010 15:48:50 +0100 Subject: [PATCH 157/199] [cpu/cc430/ drivers/gpioint] * refactored port interrupt handling --- cpu/cc430/cc430-gpioint.c | 149 +++++++++--------------------- cpu/msp430-common/Jamfile | 2 +- cpu/msp430x16x/Jamfile | 1 + drivers/include/gpioint.h | 1 + projects/chronos_cc110x_ng/main.c | 14 +-- projects/chronos_default/Jamfile | 2 +- projects/chronos_default/main.c | 18 ++-- 7 files changed, 63 insertions(+), 124 deletions(-) diff --git a/cpu/cc430/cc430-gpioint.c b/cpu/cc430/cc430-gpioint.c index ec2187964..bceb3587b 100644 --- a/cpu/cc430/cc430-gpioint.c +++ b/cpu/cc430/cc430-gpioint.c @@ -27,6 +27,7 @@ and the mailinglist (subscription via web site) #include #include #include +#include #include #include #include @@ -48,13 +49,18 @@ and the mailinglist (subscription via web site) /** interrupt callbacks */ fp_irqcb cb[INT_PORTS][BITMASK_SIZE]; -static int8_t calc_log2(uint8_t power); +/** debounce interrupt flags */ +uint8_t debounce_flags[INT_PORTS]; + +/** debounce interrupt times */ +uint16_t debounce_time[INT_PORTS][BITMASK_SIZE]; void gpioint_init(void) { uint8_t i, j; for (i = 0; i < INT_PORTS; i++) { for (j = 0; j < BITMASK_SIZE; j++) { cb[i][j] = NULL; + debounce_time[i][j] = 0; } } } @@ -64,13 +70,19 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { if ((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) { /* set the callback function */ - base = calc_log2(bitmask); + base = number_of_highest_bit(bitmask); if (base >= 0) { - cb[port - PORTINT_MIN][calc_log2(bitmask)] = callback; + cb[port - PORTINT_MIN][base] = callback; } else { return false; } + if (flags & GPIOINT_DEBOUNCE) { + debounce_flags[port - PORTINT_MIN] |= bitmask; + } + else { + debounce_flags[port - PORTINT_MIN] &= ~bitmask; + } } switch (port) { @@ -85,15 +97,16 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { P1IFG &= ~bitmask; /* trigger on rising... */ - if (flags == GPIOINT_RISING_EDGE) { + if (flags & GPIOINT_RISING_EDGE) { P1IES &= bitmask; } /* ...or falling edge */ - else if (flags == GPIOINT_FALLING_EDGE) { + if (flags & GPIOINT_FALLING_EDGE) { P1IES |= bitmask; } - /* or disable interrupt */ - else { + + /* disable interrupt */ + if (flags == GPIOINT_DISABLE) { P1IE &= ~bitmask; } /* enable interrupt */ @@ -130,18 +143,8 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { return 1; } -static int8_t calc_log2(uint8_t power) { - int8_t i; - for (i = 7; i >= 0; i--) { - if ((power >> i) & 1) { - return i; - } - } - return -1; -} - interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { - uint8_t int_enable, istate; + uint8_t int_enable, istate, ifg_num; uint16_t p1iv; __enter_isr(); @@ -153,50 +156,20 @@ interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { int_enable = P1IE; restoreIRQ(istate); P1IE = 0x00; - hwtimer_wait(DEBOUNCE_TIMEOUT); - switch (p1iv) { - case P1IV_P1IFG0: - if ((P1IN & P1IV_P1IFG0) & P1IV_P1IFG0) { - cb[0][0](); - } - break; - case P1IV_P1IFG1: - if ((P1IN & P1IV_P1IFG1) & P1IV_P1IFG1) { - cb[0][1](); - } - break; - case P1IV_P1IFG2: - if ((P1IN & P1IV_P1IFG2) & P1IV_P1IFG2) { - cb[0][2](); - } - break; - case P1IV_P1IFG3: - if ((P1IN & P1IV_P1IFG3) & P1IV_P1IFG3) { - cb[0][3](); - } - break; - case P1IV_P1IFG4: - if ((P1IN & P1IV_P1IFG4) & P1IV_P1IFG4) { - cb[0][4](); - } - break; - case P1IV_P1IFG5: - if ((P1IN & P1IV_P1IFG5) & P1IV_P1IFG5) { - cb[0][5](); - } - break; - case P1IV_P1IFG6: - if ((P1IN & P1IV_P1IFG6) & P1IV_P1IFG6) { - cb[0][6](); - } - break; - case P1IV_P1IFG7: - if ((P1IN & P1IV_P1IFG7) & P1IV_P1IFG7) { - cb[0][7](); - } - break; + /* check interrupt source */ + if (debounce_flags[0] & P1IFG) { + ifg_num = (p1iv >> 1) - 1; + /* check if bouncing */ + if ((hwtimer_now() - debounce_time[0][ifg_num]) > DEBOUNCE_TIMEOUT) { + debounce_time[0][ifg_num] = hwtimer_now(); + cb[0][ifg_num](); + } + else { + /* TODO: check for long duration irq */ + } } + P1IFG = 0x00; istate = disableIRQ(); P1IE = int_enable; @@ -205,7 +178,7 @@ interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { } interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { - uint8_t int_enable, istate; + uint8_t int_enable, istate, ifg_num; uint16_t p2iv; __enter_isr(); @@ -217,50 +190,20 @@ interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { int_enable = P2IE; restoreIRQ(istate); P2IE = 0x00; - hwtimer_wait(DEBOUNCE_TIMEOUT); - switch (p2iv) { - case P2IV_P2IFG0: - if ((P2IN & P2IV_P2IFG0) & P2IV_P2IFG0) { - cb[1][0](); - } - break; - case P2IV_P2IFG1: - if ((P2IN & P2IV_P2IFG1) & P2IV_P2IFG1) { - cb[1][1](); - } - break; - case P2IV_P2IFG2: - if ((P2IN & P2IV_P2IFG2) & P2IV_P2IFG2) { - cb[1][2](); - } - break; - case P2IV_P2IFG3: - if ((P2IN & P2IV_P2IFG3) & P2IV_P2IFG3) { - cb[1][3](); - } - break; - case P2IV_P2IFG4: - if ((P2IN & P2IV_P2IFG4) & P2IV_P2IFG4) { - cb[1][4](); - } - break; - case P2IV_P2IFG5: - if ((P2IN & P2IV_P2IFG5) & P2IV_P2IFG5) { - cb[1][5](); - } - break; - case P2IV_P2IFG6: - if ((P2IN & P2IV_P2IFG6) & P2IV_P2IFG6) { - cb[1][6](); - } - break; - case P2IV_P2IFG7: - if ((P2IN & P2IV_P2IFG7) & P2IV_P2IFG7) { - cb[1][7](); - } - break; + /* check interrupt source */ + if (debounce_flags[1] & P1IFG) { + ifg_num = (p2iv >> 1) - 1; + /* check if bouncing */ + if ((hwtimer_now() - debounce_time[1][ifg_num]) > DEBOUNCE_TIMEOUT) { + debounce_time[1][ifg_num] = hwtimer_now(); + cb[1][ifg_num](); + } + else { + /* TODO: check for long duration irq */ + } } + P2IFG = 0x00; istate = disableIRQ(); P2IE = int_enable; diff --git a/cpu/msp430-common/Jamfile b/cpu/msp430-common/Jamfile index 540398c72..19e40bb30 100644 --- a/cpu/msp430-common/Jamfile +++ b/cpu/msp430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP cpu msp430-common ; -Module cpu : msp430-main.c cpu.c atomic.c irq.c flashrom.c ; +Module cpu : msp430-main.c cpu.c atomic.c irq.c ; Module hwtimer_msp430 : hwtimer_cpu.c ; UseModule cpu ; diff --git a/cpu/msp430x16x/Jamfile b/cpu/msp430x16x/Jamfile index a11017067..14aa4df13 100644 --- a/cpu/msp430x16x/Jamfile +++ b/cpu/msp430x16x/Jamfile @@ -27,6 +27,7 @@ SubDir TOP cpu msp430x16x ; +Module flashrom : flashrom.c ; Module hwtimer_cpu : hwtimer_msp430.c : hwtimer_msp430 ; SubInclude TOP cpu msp430-common ; diff --git a/drivers/include/gpioint.h b/drivers/include/gpioint.h index 66cf138a6..8d5d30f1e 100644 --- a/drivers/include/gpioint.h +++ b/drivers/include/gpioint.h @@ -68,6 +68,7 @@ and the mailinglist (subscription via web site) #define GPIOINT_DISABLE 0x00 #define GPIOINT_RISING_EDGE 0x01 ///< interrupt is generated on rising edge #define GPIOINT_FALLING_EDGE 0x02 ///< interrupt is generated on falling edge +#define GPIOINT_DEBOUNCE 0x04 ///< debounce this interrupt /** * @brief GPIO IRQ callback function type diff --git a/projects/chronos_cc110x_ng/main.c b/projects/chronos_cc110x_ng/main.c index b259b0733..4e14c50d1 100644 --- a/projects/chronos_cc110x_ng/main.c +++ b/projects/chronos_cc110x_ng/main.c @@ -1,12 +1,12 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -56,12 +56,12 @@ void radio(void) { while (1) { msg_receive(&m); if (m.type == PKT_PENDING) { + p = (radio_packet_t*) m.content.ptr; display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON); send(p->src, p->length, p->data); - hwtimer_wait(50000); - send(p->src, sizeof(p->length), &(p->length)); + p->processing--; } @@ -74,6 +74,7 @@ void radio(void) { int main(void) { int radio_pid; + radio_address_t addr = 43; memset(snd_buffer, 43, SEND_SIZE); radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); @@ -91,11 +92,10 @@ int main(void) { tcmd.data = &addr; msg_send(&mesg, transceiver_pid, 1); - send(12, SEND_SIZE, snd_buffer); + send(0, SEND_SIZE, snd_buffer); while (1) { - hwtimer_wait(SENDING_DELAY); - display_chars(LCD_SEG_L1_3_0, ".....", SEG_OFF); - display_chars(LCD_SEG_L1_3_0, (char*) itoa(TA0R, 6, 0), SEG_ON); + hwtimer_wait(SENDING_DELAY); + display_chars(LCD_SEG_L1_3_0, itoa(hwtimer_now(), 4, 0), SEG_ON); } } diff --git a/projects/chronos_default/Jamfile b/projects/chronos_default/Jamfile index 515f82219..0198f8ae6 100644 --- a/projects/chronos_default/Jamfile +++ b/projects/chronos_default/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects chronos_default ; -Module chronos_default : main.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint ; +Module chronos_default : main.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint display_putchar ; UseModule chronos_default ; diff --git a/projects/chronos_default/main.c b/projects/chronos_default/main.c index 3894f4ae6..f521910d7 100644 --- a/projects/chronos_default/main.c +++ b/projects/chronos_default/main.c @@ -46,8 +46,6 @@ void send(radio_address_t dst, uint8_t len, uint8_t *data) { p.length = len; p.dst = dst; - display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); - display_chars(LCD_SEG_L2_5_0, (char*) itoa(p.dst, 6, 0), SEG_ON); p.data = data; msg_send(&mesg, transceiver_pid, 1); @@ -64,10 +62,7 @@ void radio(void) { if (m.type == PKT_PENDING) { p = (radio_packet_t*) m.content.ptr; - display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF); - display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON); send(p->src, p->length, p->data); - p->processing--; } @@ -92,7 +87,8 @@ int main(void) { int radio_pid; struct tm now; - now.tm_min = 5; + now.tm_hour = 3; + now.tm_min = 59; now.tm_sec = 42; rtc_set_localtime(&now); @@ -101,7 +97,7 @@ int main(void) { rtc_set_alarm(&now, RTC_ALARM_MIN); - gpioint_set(2, BUTTON_STAR_PIN, GPIOINT_RISING_EDGE, change_mode); + gpioint_set(2, BUTTON_STAR_PIN, (GPIOINT_RISING_EDGE | GPIOINT_DEBOUNCE), change_mode); radio_address_t addr = 43; memset(snd_buffer, 43, SEND_SIZE); @@ -110,12 +106,10 @@ int main(void) { transceiver_start(); transceiver_register(TRANSCEIVER_CC1100, radio_pid); - lcd_init(); - clear_display_all(); mesg.type = SET_ADDRESS; mesg.content.ptr = (char*) &tcmd; - display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_ON); + printf("CC430"); tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &addr; msg_send(&mesg, transceiver_pid, 1); @@ -128,10 +122,10 @@ int main(void) { switch (mode) { case 0: - display_chars(LCD_SEG_L1_3_0, (char*) itoa(now.tm_sec, 4, 0), SEG_ON); + printf("\n%02u:%02u", now.tm_hour, now.tm_min); break; case 1: - display_chars(LCD_SEG_L1_3_0, (char*) itoa(now.tm_min, 4, 0), SEG_ON); + printf("\n%02u", now.tm_sec); break; } } From 08295b04ca61cb320df4f927a6267b1c05da385a Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 16 Dec 2010 17:11:23 +0100 Subject: [PATCH 158/199] [cpu/cc430] * fixed some bugs in gpioint --- cpu/cc430/cc430-gpioint.c | 40 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/cpu/cc430/cc430-gpioint.c b/cpu/cc430/cc430-gpioint.c index bceb3587b..585c78e60 100644 --- a/cpu/cc430/cc430-gpioint.c +++ b/cpu/cc430/cc430-gpioint.c @@ -44,7 +44,7 @@ and the mailinglist (subscription via web site) #define BITMASK_SIZE (8) /** debouncing port interrupts */ -#define DEBOUNCE_TIMEOUT (50) +#define DEBOUNCE_TIMEOUT (150) /** interrupt callbacks */ fp_irqcb cb[INT_PORTS][BITMASK_SIZE]; @@ -55,6 +55,8 @@ uint8_t debounce_flags[INT_PORTS]; /** debounce interrupt times */ uint16_t debounce_time[INT_PORTS][BITMASK_SIZE]; +uint16_t c1 = 0, c2 = 0; + void gpioint_init(void) { uint8_t i, j; for (i = 0; i < INT_PORTS; i++) { @@ -144,7 +146,7 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { } interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { - uint8_t int_enable, istate, ifg_num; + uint8_t int_enable, ifg_num; uint16_t p1iv; __enter_isr(); @@ -152,14 +154,12 @@ interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { * Disable PORT1 IRQ */ p1iv = P1IV; - istate = disableIRQ(); int_enable = P1IE; - restoreIRQ(istate); P1IE = 0x00; + ifg_num = (p1iv >> 1) - 1; /* check interrupt source */ if (debounce_flags[0] & P1IFG) { - ifg_num = (p1iv >> 1) - 1; /* check if bouncing */ if ((hwtimer_now() - debounce_time[0][ifg_num]) > DEBOUNCE_TIMEOUT) { debounce_time[0][ifg_num] = hwtimer_now(); @@ -169,45 +169,53 @@ interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { /* TODO: check for long duration irq */ } } + else { + cb[0][ifg_num](); + } P1IFG = 0x00; - istate = disableIRQ(); P1IE = int_enable; - restoreIRQ(istate); __exit_isr(); } interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { - uint8_t int_enable, istate, ifg_num; + uint8_t int_enable, ifg_num, p2ifg; uint16_t p2iv; + uint16_t diff; __enter_isr(); /* Debounce * Disable PORT2 IRQ */ + p2ifg = P2IFG; p2iv = P2IV; - istate = disableIRQ(); int_enable = P2IE; - restoreIRQ(istate); P2IE = 0x00; + ifg_num = (p2iv >> 1) - 1; /* check interrupt source */ - if (debounce_flags[1] & P1IFG) { - ifg_num = (p2iv >> 1) - 1; + if (debounce_flags[1] & p2ifg) { /* check if bouncing */ - if ((hwtimer_now() - debounce_time[1][ifg_num]) > DEBOUNCE_TIMEOUT) { + diff = hwtimer_now() - debounce_time[1][ifg_num]; + if (diff > DEBOUNCE_TIMEOUT) { debounce_time[1][ifg_num] = hwtimer_now(); - cb[1][ifg_num](); + c1++; + if (cb[1][ifg_num] != NULL) { + cb[1][ifg_num](); + } } else { + c2++; /* TODO: check for long duration irq */ + asm volatile (" nop "); } } + else { + cb[1][ifg_num](); + } P2IFG = 0x00; - istate = disableIRQ(); P2IE = int_enable; - restoreIRQ(istate); __exit_isr(); } From b416fef56b7acff959110f78e74ce5ccf8a8fb5b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 16 Dec 2010 18:09:40 +0100 Subject: [PATCH 159/199] [cpu/cc430] * fixed debouncing for gpioint --- cpu/cc430/cc430-gpioint.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/cpu/cc430/cc430-gpioint.c b/cpu/cc430/cc430-gpioint.c index 585c78e60..460d2a487 100644 --- a/cpu/cc430/cc430-gpioint.c +++ b/cpu/cc430/cc430-gpioint.c @@ -44,7 +44,7 @@ and the mailinglist (subscription via web site) #define BITMASK_SIZE (8) /** debouncing port interrupts */ -#define DEBOUNCE_TIMEOUT (150) +#define DEBOUNCE_TIMEOUT (250) /** interrupt callbacks */ fp_irqcb cb[INT_PORTS][BITMASK_SIZE]; @@ -146,33 +146,41 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { } interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) { - uint8_t int_enable, ifg_num; + uint8_t int_enable, ifg_num, p1ifg; uint16_t p1iv; + uint16_t diff; __enter_isr(); /* Debounce * Disable PORT1 IRQ */ + p1ifg = P1IFG; p1iv = P1IV; int_enable = P1IE; P1IE = 0x00; ifg_num = (p1iv >> 1) - 1; /* check interrupt source */ - if (debounce_flags[0] & P1IFG) { + if (debounce_flags[0] & p1ifg) { /* check if bouncing */ - if ((hwtimer_now() - debounce_time[0][ifg_num]) > DEBOUNCE_TIMEOUT) { + diff = hwtimer_now() - debounce_time[0][ifg_num]; + if (diff > DEBOUNCE_TIMEOUT) { debounce_time[0][ifg_num] = hwtimer_now(); - cb[0][ifg_num](); + if (cb[0][ifg_num] != NULL) { + cb[0][ifg_num](); + } } else { /* TODO: check for long duration irq */ + asm volatile (" nop "); } } else { - cb[0][ifg_num](); + if (cb[0][ifg_num] != NULL) { + cb[0][ifg_num](); + } } - + P1IFG = 0x00; P1IE = int_enable; __exit_isr(); @@ -211,7 +219,9 @@ interrupt (PORT2_VECTOR) __attribute__ ((naked)) port2_isr(void) { } } else { - cb[1][ifg_num](); + if (cb[1][ifg_num] != NULL) { + cb[1][ifg_num](); + } } P2IFG = 0x00; From 9e58c8bcb7aa4c7c8a84368c0f7be5448c122fbb Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 16 Dec 2010 18:21:24 +0100 Subject: [PATCH 160/199] *watch: chronos watch application initial checkin --- cpu/cc430/cc430-rtc.c | 35 ++++++++++---- drivers/include/rtc.h | 4 ++ projects/watch/Jamfile | 5 ++ projects/watch/alarm_app.c | 62 ++++++++++++++++++++++++ projects/watch/alarm_app.h | 6 +++ projects/watch/clock_app.c | 58 ++++++++++++++++++++++ projects/watch/clock_app.h | 7 +++ projects/watch/main.c | 83 ++++++++++++++++++++++++++++++++ projects/watch/tests/hello-world | 13 +++++ projects/watch/watch.h | 9 ++++ 10 files changed, 272 insertions(+), 10 deletions(-) create mode 100644 projects/watch/Jamfile create mode 100644 projects/watch/alarm_app.c create mode 100644 projects/watch/alarm_app.h create mode 100644 projects/watch/clock_app.c create mode 100644 projects/watch/clock_app.h create mode 100644 projects/watch/main.c create mode 100755 projects/watch/tests/hello-world create mode 100644 projects/watch/watch.h diff --git a/cpu/cc430/cc430-rtc.c b/cpu/cc430/cc430-rtc.c index 3ef3d7c27..8895e0599 100644 --- a/cpu/cc430/cc430-rtc.c +++ b/cpu/cc430/cc430-rtc.c @@ -33,11 +33,16 @@ and the mailinglist (subscription via web site) //static volatile time_t epoch; static struct tm time_to_set; +static int set_time = 0; +int rtc_second_pid = 0; /*---------------------------------------------------------------------------*/ void rtc_init(void) { /* Set to calendar mode */ RTCCTL1 |= RTCMODE_H; + + /* enable ready interrupt (every second) */ + RTCCTL0 |= RTCRDYIE; } /*---------------------------------------------------------------------------*/ @@ -59,7 +64,8 @@ void rtc_set_localtime(struct tm* localt) { /* copy time to be set */ memcpy(&time_to_set, localt, sizeof(struct tm)); /* set interrupt to set this time after the next transition */ - RTCCTL0 |= RTCRDYIE; +// RTCCTL0 |= RTCRDYIE; + set_time = 1; } /*--------------------------------------------------------------------------- @@ -166,16 +172,25 @@ interrupt(RTC_VECTOR) __attribute__ ((naked)) rtc_isr(void) { /* RTC is save to write for up to one second now */ if (RTCIV == RTC_RTCRDYIFG) { /* disable interrupt */ - RTCCTL0 &= ~RTCRDYIE; + //RTCCTL0 &= ~RTCRDYIE; + + if (set_time) { + set_time = 0; /* set previous set time and reset it */ - RTCSEC = time_to_set.tm_sec; - RTCMIN = time_to_set.tm_min; - RTCHOUR = time_to_set.tm_hour; - RTCDAY = time_to_set.tm_mday; - RTCDOW = time_to_set.tm_wday; - RTCMON = time_to_set.tm_mon + 1; - RTCYEARL = (time_to_set.tm_year + 1900) & 0xFF; - RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08; + RTCSEC = time_to_set.tm_sec; + RTCMIN = time_to_set.tm_min; + RTCHOUR = time_to_set.tm_hour; + RTCDAY = time_to_set.tm_mday; + RTCDOW = time_to_set.tm_wday; + RTCMON = time_to_set.tm_mon + 1; + RTCYEARL = (time_to_set.tm_year + 1900) & 0xFF; + RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08; + } + if (rtc_second_pid) { + msg m; + m.type = RTC_SECOND; + msg_send_int(&m, rtc_second_pid); + } } /* RTC alarm */ else if (RTCIV == RTC_RTCAIFG) { diff --git a/drivers/include/rtc.h b/drivers/include/rtc.h index d36382cfd..b40b72b50 100644 --- a/drivers/include/rtc.h +++ b/drivers/include/rtc.h @@ -27,6 +27,8 @@ and the mailinglist (subscription via web site) #ifndef RTC_H #define RTC_H +#define RTC_SECOND 10001U + #include /** @@ -56,4 +58,6 @@ void rtc_set_localtime(struct tm* localt); */ void rtc_get_localtime(struct tm* localt); +extern int rtc_second_pid; + #endif diff --git a/projects/watch/Jamfile b/projects/watch/Jamfile new file mode 100644 index 000000000..d3484567e --- /dev/null +++ b/projects/watch/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects watch ; + +Module watch : main.c clock_app.c alarm_app.c : uart0 posix_io rtc display_putchar gpioint hwtimer board_buzzer auto_init ; + +UseModule watch ; diff --git a/projects/watch/alarm_app.c b/projects/watch/alarm_app.c new file mode 100644 index 000000000..7a9f206bb --- /dev/null +++ b/projects/watch/alarm_app.c @@ -0,0 +1,62 @@ +#include +#include + +#include +#include +#include +#include + +#include "alarm_app.h" +#include "clock_app.h" +#include "watch.h" + +static char alarm_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; + +static void alarm_thread(void) { + msg m; + + struct tm time; + + time.tm_sec = 1; + time.tm_min = 2; + time.tm_hour = 3; + + int active = 0; + + while(1) { + msg_receive(&m); + switch (m.type) { + case MSG_ACTIVATE: + { + time_print(&time); + if (active) { + } else { + } + break; + } + case MSG_DEACTIVATE: + { + break; + } + case MSG_BUTTON_HASH: + { + if (active) { + active = 0; + display_symbol(LCD_ICON_ALARM, SEG_OFF); + } else { + active = 1; + display_symbol(LCD_ICON_ALARM, SEG_ON); + } + break; + } + default: + { + printf("def alarm\n"); + } + } + } +} + +int alarm_app_init() { + return thread_create(alarm_stack, sizeof(alarm_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, alarm_thread, "alarm"); +} diff --git a/projects/watch/alarm_app.h b/projects/watch/alarm_app.h new file mode 100644 index 000000000..569be69b0 --- /dev/null +++ b/projects/watch/alarm_app.h @@ -0,0 +1,6 @@ +#ifndef __ALARM_APP_H +#define __ALARM_APP_H + +int alarm_app_init(); + +#endif /* __ALARM_APP_H */ diff --git a/projects/watch/clock_app.c b/projects/watch/clock_app.c new file mode 100644 index 000000000..761ebe17f --- /dev/null +++ b/projects/watch/clock_app.c @@ -0,0 +1,58 @@ +#include +#include + +#include +#include +#include + +#include "clock_app.h" +#include "watch.h" + +void time_print(struct tm *time) { + printf("%02i %02i%02i\n", time->tm_sec, time->tm_hour, time->tm_min); +} + +static char clock_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; + +static void clock_thread(void) { + msg m; + + int active = 0; + rtc_second_pid = thread_getpid(); + + while(1) { + msg_receive(&m); + switch (m.type) { + case RTC_SECOND: + { + if (! active) break; + } + case MSG_ACTIVATE: + { + active = 1; + struct tm now; + rtc_get_localtime(&now); + time_print(&now); + break; + } + case MSG_DEACTIVATE: + { + active = 0; + break; + } + case MSG_BUTTON_HASH: + { + printf("hashclock\n"); + break; + } + default: + { + printf("def clock\n"); + } + } + } +} + +int clock_app_init() { + return thread_create(clock_stack, sizeof(clock_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, clock_thread, "clock"); +} diff --git a/projects/watch/clock_app.h b/projects/watch/clock_app.h new file mode 100644 index 000000000..084f58866 --- /dev/null +++ b/projects/watch/clock_app.h @@ -0,0 +1,7 @@ +#ifndef __CLOCK_APP_H +#define __CLOCK_APP_H + +int clock_app_init(); +void time_print(struct tm *time); + +#endif /* __CLOCK_APP_H */ diff --git a/projects/watch/main.c b/projects/watch/main.c new file mode 100644 index 000000000..e67dbe601 --- /dev/null +++ b/projects/watch/main.c @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "watch.h" +#include "alarm_app.h" +#include "clock_app.h" + +#define NUM_APPS 2 +int napps = NUM_APPS; +int apps[NUM_APPS]; + +int button_thread = 0; +void button_star(void) { + msg m; + + if (button_thread) { + m.type = MSG_BUTTON_STAR; + msg_send(&m, button_thread, false); + } +} + +int main(void) +{ + memset(apps, '\0', sizeof(apps)); + apps[0] = clock_app_init(); + apps[1] = alarm_app_init(); + + gpioint_set(2, BUTTON_STAR_PIN, (GPIOINT_RISING_EDGE | GPIOINT_DEBOUNCE), button_star); + button_thread = thread_getpid(); + + int active_app = 0; + + msg m; + + //buzzer_beep(15, 5000); + + printf("ukleos\n"); + + m.type = MSG_ACTIVATE; + msg_send(&m, apps[active_app], true); + + while(1) { + msg_receive(&m); + + switch (m.type) { + case MSG_BUTTON_STAR: { + m.type = MSG_DEACTIVATE; + msg_send(&m, apps[active_app], true); + + active_app++; + + if (active_app == (NUM_APPS)) active_app = 0; + + m.type = MSG_ACTIVATE; + msg_send(&m, apps[active_app], true); + + // buzzer_beep(15, 5000); + + break; + } + case MSG_BUTTON_HASH: + { + m.type = MSG_BUTTON_HASH; + msg_send(&m, apps[active_app], true); + break; + } + default: + { + printf("msg\n"); + } + } + } +} diff --git a/projects/watch/tests/hello-world b/projects/watch/tests/hello-world new file mode 100755 index 000000000..acde8265f --- /dev/null +++ b/projects/watch/tests/hello-world @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "Hello World!" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" + diff --git a/projects/watch/watch.h b/projects/watch/watch.h new file mode 100644 index 000000000..c2cd7ddbe --- /dev/null +++ b/projects/watch/watch.h @@ -0,0 +1,9 @@ +#ifndef __WATCH_H +#define __WATCH_H + +#define MSG_ACTIVATE 0 +#define MSG_DEACTIVATE 1 +#define MSG_BUTTON_STAR 2 +#define MSG_BUTTON_HASH 3 + +#endif /* __WATCH_H */ From be71c14f047c5b8d1ed5069c4b97eae13abf4539 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 17 Dec 2010 13:20:29 +0100 Subject: [PATCH 161/199] [cpu/cc430] * added adc driver for cc430 --- cpu/cc430/Jamfile | 1 + cpu/cc430/cc430-adc.c | 149 ++++++++++++++++++++++++++++++++++ cpu/cc430/include/cc430-adc.h | 44 ++++++++++ 3 files changed, 194 insertions(+) create mode 100644 cpu/cc430/cc430-adc.c create mode 100644 cpu/cc430/include/cc430-adc.h diff --git a/cpu/cc430/Jamfile b/cpu/cc430/Jamfile index dafac6212..886cb4429 100644 --- a/cpu/cc430/Jamfile +++ b/cpu/cc430/Jamfile @@ -30,5 +30,6 @@ SubDir TOP cpu cc430 ; Module hwtimer_cpu : hwtimer_cc430.c : hwtimer_msp430 ; Module rtc : cc430-rtc.c ; Module gpioint : cc430-gpioint.c ; +Module adc : cc430-adc.c : hwtimer ; SubInclude TOP cpu msp430-common ; diff --git a/cpu/cc430/cc430-adc.c b/cpu/cc430/cc430-adc.c new file mode 100644 index 000000000..470725ad7 --- /dev/null +++ b/cpu/cc430/cc430-adc.c @@ -0,0 +1,149 @@ +/* ************************************************************************************************* + * + * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ************************************************************************************************* + * ADC12 functions. + * ************************************************************************************************/ + + +#include +#include +#include +#include + +uint16_t adc12_result; +uint8_t adc12_data_ready; + +/* ************************************************************************************************* + * @fn adc12_single_conversion + * @brief Init ADC12. Do single conversion. Turn off ADC12. + * @param none + * @return none + * ************************************************************************************************/ +uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel) { + /* Initialize the shared reference module */ + REFCTL0 |= REFMSTR + ref + REFON; /* Enable internal reference (1.5V or 2.5V) */ + + /* Initialize ADC12_A */ + ADC12CTL0 = sht + ADC12ON; /* Set sample time */ + ADC12CTL1 = ADC12SHP; /* Enable sample timer */ + ADC12MCTL0 = ADC12SREF_1 + channel; /* ADC input channel */ + ADC12IE = 0x001; /* ADC_IFG upon conv result-ADCMEMO */ + + eINT(); + + /* Wait 2 ticks (66us) to allow internal reference to settle */ + hwtimer_wait(2); + + /* Start ADC12 */ + ADC12CTL0 |= ADC12ENC; + + /* Clear data ready flag */ + adc12_data_ready = 0; + + /* Sampling and conversion start */ + ADC12CTL0 |= ADC12SC; + + /* Wait until ADC12 has finished */ + hwtimer_wait(5); + while (!adc12_data_ready); + + /* Shut down ADC12 */ + ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht); + ADC12CTL0 &= ~ADC12ON; + + /* Shut down reference voltage */ + REFCTL0 &= ~(REFMSTR + ref + REFON); + + ADC12IE = 0; + + /* Return ADC result */ + dINT(); + return adc12_result; +} + +/* ************************************************************************************************* + * @fn ADC12ISR + * @brief Store ADC12 conversion result. Set flag to indicate data ready. + * @param none + * @return none + * ************************************************************************************************/ +interrupt (ADC12_VECTOR) __attribute__ ((naked)) adc_isr (void) { + __enter_isr(); + switch(ADC12IV) { + case 0: + break; /* Vector 0: No interrupt */ + case 2: + break; /* Vector 2: ADC overflow */ + case 4: + break; /* Vector 4: ADC timing overflow */ + case 6: + /* Vector 6: ADC12IFG0 */ + adc12_result = ADC12MEM0; /* Move results, IFG is cleared */ + adc12_data_ready = 1; + break; + case 8: + break; /* Vector 8: ADC12IFG1 */ + case 10: + break; /* Vector 10: ADC12IFG2 */ + case 12: + break; /* Vector 12: ADC12IFG3 */ + case 14: + break; /* Vector 14: ADC12IFG4 */ + case 16: + break; /* Vector 16: ADC12IFG5 */ + case 18: + break; /* Vector 18: ADC12IFG6 */ + case 20: + break; /* Vector 20: ADC12IFG7 */ + case 22: + break; /* Vector 22: ADC12IFG8 */ + case 24: + break; /* Vector 24: ADC12IFG9 */ + case 26: + break; /* Vector 26: ADC12IFG10 */ + case 28: + break; /* Vector 28: ADC12IFG11 */ + case 30: + break; /* Vector 30: ADC12IFG12 */ + case 32: + break; /* Vector 32: ADC12IFG13 */ + case 34: + break; /* Vector 34: ADC12IFG14 */ + default: + break; + } + __exit_isr(); +} + + diff --git a/cpu/cc430/include/cc430-adc.h b/cpu/cc430/include/cc430-adc.h new file mode 100644 index 000000000..8ac19a938 --- /dev/null +++ b/cpu/cc430/include/cc430-adc.h @@ -0,0 +1,44 @@ +/* ************************************************************************************************* + * + * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ************************************************************************************************/ + +#ifndef CC430_ADC_H +#define CC430_ADC_H + +extern uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel); + +extern uint16_t adc12_result; +extern uint8_t adc12_data_ready; + +#endif From 443a5efbeac57baa56b0d56ee7a2bc5727a7ff8d Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 17 Dec 2010 13:38:03 +0100 Subject: [PATCH 162/199] [board/chronos] * introduced battery driver --- board/chronos/drivers/Jamfile | 1 + board/chronos/drivers/battery.c | 13 +++++++++++++ board/chronos/drivers/include/battery.h | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 board/chronos/drivers/battery.c create mode 100644 board/chronos/drivers/include/battery.h diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index 54d2fb4e7..286616c5d 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -5,5 +5,6 @@ HDRS += $(TOP)/board/$(CPU)/drivers/include ; Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; +Module battery : battery.c : adc hwtimer ; Module display_putchar : display_putchar.c : board_display ; diff --git a/board/chronos/drivers/battery.c b/board/chronos/drivers/battery.c new file mode 100644 index 000000000..69553fc45 --- /dev/null +++ b/board/chronos/drivers/battery.c @@ -0,0 +1,13 @@ +#include +#include +#include + +uint16_t battery_get_voltate(void) { + uint16_t voltage; + voltage = adc12_single_conversion(REFVSEL_1, ADC12SHT0_10, ADC12INCH_11); + + /* Ideally we have A11=0->AVCC=0V ... A11=4095(2^12-1)->AVCC=4V + * --> (A11/4095)*4V=AVCC --> AVCC=(A11*4)/4095 */ + voltage = (voltage * 2 * 2 * 1000) / 4095; + return voltage; +} diff --git a/board/chronos/drivers/include/battery.h b/board/chronos/drivers/include/battery.h new file mode 100644 index 000000000..6b206c6ec --- /dev/null +++ b/board/chronos/drivers/include/battery.h @@ -0,0 +1,6 @@ +#ifndef BATTERY_H +#define BATTERY_H + +uint16_t battery_get_voltate(void); + +#endif /* BATTERY_H */ From cb1d4dd041aa8d066a6ade1e5a628caf20bb8238 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 24 Jan 2011 15:52:36 +0100 Subject: [PATCH 163/199] [projects/default] * added missing transceiver init and start --- projects/default/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/default/main.c b/projects/default/main.c index 959c69461..06c8a16e7 100644 --- a/projects/default/main.c +++ b/projects/default/main.c @@ -10,6 +10,7 @@ #include #include #include +#include int shell_readc() { char c = 0; @@ -24,6 +25,8 @@ void shell_putchar(int c) { int main(void) { posix_open(uart0_handler_pid, 0); ltc4150_start(); + transceiver_init(TRANSCEIVER_CC1100); + transceiver_start(); puts("Welcome to ukleos!"); From 45337262149a4b300c53972ef71859c202e5966a Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 31 Jan 2011 18:25:20 +0100 Subject: [PATCH 164/199] * introduced energy profiling (yet in a very early state) --- board/msba2-common/drivers/msba2-ltc4150.c | 8 +- cpu/arm_common/Jamfile | 5 + cpu/arm_common/Jamrules.arm_common | 5 + cpu/arm_common/profiling.c | 109 +++++++++++++++++++++ cpu/lpc2387/lpc2387-gpioint.c | 4 +- drivers/Jamfile | 2 +- drivers/include/ltc4150.h | 1 + drivers/ltc4150.c | 10 +- sys/auto_init.c | 4 + 9 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 cpu/arm_common/profiling.c diff --git a/board/msba2-common/drivers/msba2-ltc4150.c b/board/msba2-common/drivers/msba2-ltc4150.c index c590dee8d..4e6534c02 100644 --- a/board/msba2-common/drivers/msba2-ltc4150.c +++ b/board/msba2-common/drivers/msba2-ltc4150.c @@ -45,19 +45,19 @@ and the mailinglist (subscription via web site) #include "ltc4150_arch.h" #include "gpioint.h" -void ltc4150_disable_int(void) { +void __attribute__((__no_instrument_function__)) ltc4150_disable_int(void) { gpioint_set(0, BIT4, GPIOINT_DISABLE, NULL); } -void ltc4150_enable_int(void) { +void __attribute__((__no_instrument_function__)) ltc4150_enable_int(void) { gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, <c4150_interrupt); } -void ltc4150_sync_blocking(void) { +void __attribute__((__no_instrument_function__)) ltc4150_sync_blocking(void) { while(!(FIO0PIN & BIT4)) {}; } -void ltc4150_arch_init() { +void __attribute__((__no_instrument_function__)) ltc4150_arch_init() { FIO0DIR |= BIT5; FIO0SET = BIT5; } diff --git a/cpu/arm_common/Jamfile b/cpu/arm_common/Jamfile index 0252c7578..1889eef63 100644 --- a/cpu/arm_common/Jamfile +++ b/cpu/arm_common/Jamfile @@ -30,6 +30,11 @@ SubDir TOP cpu arm_common ; Module arm_common : common.s bootloader.c VIC.c atomic.s arm_cpu.c iap.c ; UseModule arm_common ; +Module profiling : profiling.c ; +if $(PROFILING) { + UseModule profiling ; +} + Module hwtimer_cpu : hwtimer_cpu.c ; Objects syscalls.c ; diff --git a/cpu/arm_common/Jamrules.arm_common b/cpu/arm_common/Jamrules.arm_common index dac4bff7d..afb14fa24 100644 --- a/cpu/arm_common/Jamrules.arm_common +++ b/cpu/arm_common/Jamrules.arm_common @@ -40,9 +40,14 @@ LINK = $(CC) ; OPTIM = -Os ; #OPTIM = -O0 -g ; + CCFLAGS += -std=gnu99 -Wall -mcpu=arm7tdmi-s -mfloat-abi=soft -mfpu=vfp ; LINKFLAGS = -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T [ FPath $(TOP) cpu $(CPU) linkerscript.x ] ; +if $(PROFILING) = 1 { + CCFLAGS += -g -finstrument-functions ; +} + AS = $(TOOLCHAIN)as ; ASFLAGS += -mcpu=arm7tdmi-s --defsym $(CPU)=1 -mfloat-abi=soft -mfpu=vfp ; diff --git a/cpu/arm_common/profiling.c b/cpu/arm_common/profiling.c new file mode 100644 index 000000000..8bbe2c0ed --- /dev/null +++ b/cpu/arm_common/profiling.c @@ -0,0 +1,109 @@ +#include +#include +#include +#include + +#define MAX_TRACED_FUNCTIONS (32) +#define PROFILING_STACK_SIZE (16) + +typedef struct { + uint32_t address; + uint32_t time; + uint32_t start_time; + double consumption; + double consumption_start; + uint16_t counter; +} profiling_info_t; + +static profiling_info_t functions[MAX_TRACED_FUNCTIONS]; +static uint8_t profiling_stack[PROFILING_STACK_SIZE]; +static uint8_t profiling_sp = 0; + +static uint8_t traced_functions = 0; +static uint8_t profiling = 0; + +void __attribute__((__no_instrument_function__)) profiling_init(void) { + uint8_t i; + for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { + functions[i].address = 0; + functions[i].time = 0; + functions[i].consumption = 0; + functions[i].counter = 0; + } + for (i = 0; i < PROFILING_STACK_SIZE; i++) { + profiling_stack[i] = 0; + } + + ltc4150_start(); + + profiling = 1; +} + +static int16_t __attribute__((__no_instrument_function__)) get_function_index(uint32_t addr) { + uint8_t i; + for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { + if (functions[i].address == addr) { + return i; + } + } + return -1; +} + +void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter (void *func, void *caller) { + if (!profiling) { + return; + } + /* + uint8_t i; + int16_t idx = -1; + for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { + if (functions[i].address == (uint32_t) func) { + idx = i; + break; + } + } + */ + uint8_t idx = get_function_index((uint32_t) func); + if ((idx < 0) && (traced_functions < MAX_TRACED_FUNCTIONS)) { + idx = traced_functions++; + functions[idx].address = (uint32_t) func; + } + else if (idx < 0) { + return; + } + functions[idx].start_time = T0TC; + functions[idx].counter++; + functions[idx].consumption_start = ltc4150_get_total_mAh(); + // functions[idx].consumption_start = ltc4150_get_intcount(); +} + +void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit (void *func, void *caller) { + if (!profiling) { + return; + } + /* + uint8_t i; + int16_t idx = -1; + for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { + if (functions[i].address == (uint32_t) func) { + idx = i; + break; + } + } + */ + uint8_t idx = get_function_index((uint32_t) func); + if (idx >= 0) { + functions[idx].time += T0TC - functions[idx].start_time; + //functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start; + functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start; + } +} + +void profiling_stats(void) { + uint8_t i; + for (i = 0; i < traced_functions; i++) { +// printf("Function @%04lX was running %u times for %lu ticks, consuming %li ltc-ticks\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption); + printf("Function @%04lX was running %u times for %lu ticks, consuming %lf mAh\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption); + } + puts("________________________________________________________"); +} diff --git a/cpu/lpc2387/lpc2387-gpioint.c b/cpu/lpc2387/lpc2387-gpioint.c index e33fc854a..7ce594141 100644 --- a/cpu/lpc2387/lpc2387-gpioint.c +++ b/cpu/lpc2387/lpc2387-gpioint.c @@ -123,7 +123,7 @@ gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) return true; // success } /*---------------------------------------------------------------------------*/ -static void test_irq(int port, unsigned long f_mask, unsigned long r_mask, struct irq_callback* pcb) +static void __attribute__ ((__no_instrument_function__)) test_irq(int port, unsigned long f_mask, unsigned long r_mask, struct irq_callback* pcb) { /* Test each bit of rising and falling masks, if set trigger interrupt * on corresponding device */ @@ -148,7 +148,7 @@ void GPIO_IRQHandler(void) __attribute__((interrupt("IRQ"))); * Invoked whenever an activated gpio interrupt is triggered by a rising * or falling edge. */ -void GPIO_IRQHandler(void) { +void __attribute__ ((__no_instrument_function__)) GPIO_IRQHandler(void) { if( IO_INT_STAT & BIT0 ) { // interrupt(s) on PORT0 pending unsigned long int_stat_f = IO0_INT_STAT_F; // save content unsigned long int_stat_r = IO0_INT_STAT_R; // save content diff --git a/drivers/Jamfile b/drivers/Jamfile index 9713df17f..3dbeed6d7 100644 --- a/drivers/Jamfile +++ b/drivers/Jamfile @@ -29,7 +29,7 @@ SubDir TOP drivers ; Module sht11 : sht11.c : hwtimer ; -Module ltc4150 : ltc4150.c : board_ltc4150 ; +Module ltc4150 : ltc4150.c : board_ltc4150 hwtimer ; SubInclude TOP drivers cc110x ; SubInclude TOP drivers cc110x_ng ; diff --git a/drivers/include/ltc4150.h b/drivers/include/ltc4150.h index 88160c891..4a3c05515 100644 --- a/drivers/include/ltc4150.h +++ b/drivers/include/ltc4150.h @@ -11,5 +11,6 @@ double ltc4150_get_current_mA(); double ltc4150_get_total_mAh(); double ltc4150_get_avg_mA(); int ltc4150_get_interval(); +long ltc4150_get_intcount(void); #endif /* __LTC4150_H */ diff --git a/drivers/ltc4150.c b/drivers/ltc4150.c index 7c50553a8..947265f6a 100644 --- a/drivers/ltc4150.c +++ b/drivers/ltc4150.c @@ -46,11 +46,11 @@ static unsigned int last_int_time; static unsigned int last_int_duration; static unsigned int start_time; -static double int_to_coulomb(int ints) { +static double __attribute__((__no_instrument_function__)) int_to_coulomb(int ints) { return ((double)ints) / (_GFH * _R_SENSE); } -static double coulomb_to_mA(double coulomb){ +static double __attribute__((__no_instrument_function__)) coulomb_to_mA(double coulomb){ return (coulomb * 1000) / 3600; } @@ -62,7 +62,7 @@ double ltc4150_get_current_mA() { return 1000000000/(ltc4150_get_last_int_duration_us()*(_GFH * _R_SENSE)); } -double ltc4150_get_total_mAh() { +double __attribute__((__no_instrument_function__)) ltc4150_get_total_mAh() { return coulomb_to_mA(int_to_coulomb(int_count)); } @@ -74,7 +74,7 @@ int ltc4150_get_interval() { return HWTIMER_TICKS_TO_US(last_int_time - start_time); } -unsigned long ltc4150_get_intcount() { +unsigned long __attribute__((__no_instrument_function__)) ltc4150_get_intcount() { return int_count; } @@ -96,7 +96,7 @@ void ltc4150_stop() { ltc4150_disable_int(); } -void ltc4150_interrupt() +void __attribute__((__no_instrument_function__)) ltc4150_interrupt() { uint32_t now = hwtimer_now(); if (now >= last_int_time) { diff --git a/sys/auto_init.c b/sys/auto_init.c index e9e7a4d48..c142d7ef3 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -52,6 +52,10 @@ void auto_init(void) { #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); +#endif +#ifdef MODULE_PROFILING + extern void profiling_init(void); + profiling_init(); #endif main(); } From d96783a66e53132d916db1ae056e4dfa9e5dfbf9 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 31 Jan 2011 18:36:06 +0100 Subject: [PATCH 165/199] [cpu/arm_common/profiling] * fixed get_index function --- cpu/arm_common/profiling.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/cpu/arm_common/profiling.c b/cpu/arm_common/profiling.c index 8bbe2c0ed..fbdf6282f 100644 --- a/cpu/arm_common/profiling.c +++ b/cpu/arm_common/profiling.c @@ -53,17 +53,7 @@ void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter (void if (!profiling) { return; } - /* - uint8_t i; - int16_t idx = -1; - for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { - if (functions[i].address == (uint32_t) func) { - idx = i; - break; - } - } - */ - uint8_t idx = get_function_index((uint32_t) func); + int16_t idx = get_function_index((uint32_t) func); if ((idx < 0) && (traced_functions < MAX_TRACED_FUNCTIONS)) { idx = traced_functions++; functions[idx].address = (uint32_t) func; @@ -81,17 +71,7 @@ void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit (void * if (!profiling) { return; } - /* - uint8_t i; - int16_t idx = -1; - for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) { - if (functions[i].address == (uint32_t) func) { - idx = i; - break; - } - } - */ - uint8_t idx = get_function_index((uint32_t) func); + int16_t idx = get_function_index((uint32_t) func); if (idx >= 0) { functions[idx].time += T0TC - functions[idx].start_time; //functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start; From 3622d83ea98834a4785708985e27f599ee20af6c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 4 Mar 2011 16:46:20 +0100 Subject: [PATCH 166/199] [board msba2] * fixed header guards [drivers ltc4150] * added joule conversion --- board/msba2-common/include/msba2_common.h | 6 +++--- board/msba2/include/board.h | 1 + drivers/include/ltc4150.h | 1 + drivers/include/ltc4150_arch.h | 1 + drivers/ltc4150.c | 8 ++++++++ projects/default/main.c | 1 - projects/laser/main.c | 5 ++++- projects/test_cc110x_ng/Jamfile | 2 +- 8 files changed, 19 insertions(+), 6 deletions(-) diff --git a/board/msba2-common/include/msba2_common.h b/board/msba2-common/include/msba2_common.h index a9d9d3e72..fff12f965 100644 --- a/board/msba2-common/include/msba2_common.h +++ b/board/msba2-common/include/msba2_common.h @@ -24,8 +24,8 @@ and the mailinglist (subscription via web site) scatterweb@lists.spline.inf.fu-berlin.de *******************************************************************************/ -#ifndef __BOARD_H -#define __BOARD_H +#ifndef __MSBA2_COMMON_H +#define __MSBA2_COMMON_H /** * @ingroup msb_a2 @@ -48,4 +48,4 @@ and the mailinglist (subscription via web site) #define VICIntEnClear VICIntEnClr /** @} */ -#endif // __BOARD_H +#endif // __MSBA2_COMMON_H diff --git a/board/msba2/include/board.h b/board/msba2/include/board.h index bf596f0ee..2b1f28fd2 100644 --- a/board/msba2/include/board.h +++ b/board/msba2/include/board.h @@ -2,6 +2,7 @@ #define __BOARD_H #include +#include #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) diff --git a/drivers/include/ltc4150.h b/drivers/include/ltc4150.h index 4a3c05515..fdc08573a 100644 --- a/drivers/include/ltc4150.h +++ b/drivers/include/ltc4150.h @@ -9,6 +9,7 @@ void ltc4150_stop(); double ltc4150_get_current_mA(); double ltc4150_get_total_mAh(); +double ltc4150_get_total_Joule(void); double ltc4150_get_avg_mA(); int ltc4150_get_interval(); long ltc4150_get_intcount(void); diff --git a/drivers/include/ltc4150_arch.h b/drivers/include/ltc4150_arch.h index 1a6c5c630..51fc9478a 100644 --- a/drivers/include/ltc4150_arch.h +++ b/drivers/include/ltc4150_arch.h @@ -46,6 +46,7 @@ and the mailinglist (subscription via web site) #define _GFH (double)32.631375 #define _R_SENSE (double)0.330 +#define SUPPLY_VOLTAGE (5) void ltc4150_disable_int(void); void ltc4150_enable_int(void); diff --git a/drivers/ltc4150.c b/drivers/ltc4150.c index 947265f6a..9f4134b5c 100644 --- a/drivers/ltc4150.c +++ b/drivers/ltc4150.c @@ -54,6 +54,10 @@ static double __attribute__((__no_instrument_function__)) coulomb_to_mA(double c return (coulomb * 1000) / 3600; } +static double mAh_to_Joule(double mAh) { + return (SUPPLY_VOLTAGE * mAh * 3600); +} + uint32_t ltc4150_get_last_int_duration_us() { return HWTIMER_TICKS_TO_US(last_int_duration); } @@ -66,6 +70,10 @@ double __attribute__((__no_instrument_function__)) ltc4150_get_total_mAh() { return coulomb_to_mA(int_to_coulomb(int_count)); } +double ltc4150_get_total_Joule(void) { + return mAh_to_Joule(ltc4150_get_total_mAh()); +} + double ltc4150_get_avg_mA() { return (int_to_coulomb(int_count)*1000000000)/HWTIMER_TICKS_TO_US(last_int_time - start_time); } diff --git a/projects/default/main.c b/projects/default/main.c index 06c8a16e7..ccc4cfd9a 100644 --- a/projects/default/main.c +++ b/projects/default/main.c @@ -34,7 +34,6 @@ int main(void) { shell_init(&shell, NULL, shell_readc, shell_putchar); shell_run(&shell); - return 0; } diff --git a/projects/laser/main.c b/projects/laser/main.c index 902ffc308..e3c3d4f83 100644 --- a/projects/laser/main.c +++ b/projects/laser/main.c @@ -7,6 +7,8 @@ int main(void) { sht11_val_t sht11_val; + double mAh = 0; + uint8_t success = 0; puts(""); @@ -18,11 +20,12 @@ int main(void) while (1) { success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + mAh = ltc4150_get_total_mAh(); if (!success) { printf("error;error;error\n"); } else { - printf("%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp); + printf("%.2f;%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp, mAh); } LED_RED_TOGGLE; swtimer_usleep(60 * 1000*1000); diff --git a/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile index 2a13cb089..5ef69ea23 100644 --- a/projects/test_cc110x_ng/Jamfile +++ b/projects/test_cc110x_ng/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects test_cc110x_ng ; -Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer config ; +Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer config ltc4150 ; UseModule test_cc110x_ng ; From 6a96de0d2f2fb607599f40ccedd01bed7c034ebe Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 8 Mar 2011 10:54:40 +0100 Subject: [PATCH 167/199] changed msg to msg_t --- core/include/msg.h | 14 +++++++------- core/include/tcb.h | 2 +- core/msg.c | 26 +++++++++++++------------- cpu/cc430/cc430-rtc.c | 2 +- drivers/cc110x/cc1100_phy.c | 4 ++-- drivers/cc110x_ng/cc110x-rx.c | 2 +- projects/chronos_cc110x_ng/main.c | 6 +++--- projects/chronos_default/main.c | 6 +++--- projects/msb430_cc110x_ng/main.c | 6 +++--- projects/pingpong/main.c | 4 ++-- projects/pingpong_sync/main.c | 4 ++-- projects/test_cc110x_ng/main.c | 6 +++--- projects/test_swtimer_basic/main.c | 2 +- projects/watch/alarm_app.c | 2 +- projects/watch/clock_app.c | 2 +- projects/watch/main.c | 4 ++-- sys/chardev_thread.c | 2 +- sys/posix_io.c | 4 ++-- sys/shell/cc110x_ng.c | 2 +- sys/swtimer.c | 2 +- sys/transceiver.c | 6 +++--- sys/uart0.c | 2 +- 22 files changed, 55 insertions(+), 55 deletions(-) diff --git a/core/include/msg.h b/core/include/msg.h index 4d9a0b9ab..71d2d5891 100644 --- a/core/include/msg.h +++ b/core/include/msg.h @@ -35,7 +35,7 @@ typedef struct msg { char *ptr; ///< pointer content field uint32_t value; ///< value content field } content; -} msg; +} msg_t; /** @@ -54,7 +54,7 @@ typedef struct msg { * @return 0 if receiver is not waiting and block == false * @return -1 on error (invalid PID) */ -int msg_send(msg* m, unsigned int target_pid, bool block); +int msg_send(msg_t* m, unsigned int target_pid, bool block); /** @@ -68,7 +68,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block); * @return 1 if sending was successfull * @return 0 if receiver is not waiting and block == false */ -int msg_send_int(msg* m, unsigned int target_pid); +int msg_send_int(msg_t* m, unsigned int target_pid); /** @@ -79,7 +79,7 @@ int msg_send_int(msg* m, unsigned int target_pid); * * @return 1 Function always succeeds or blocks forever. */ -int msg_receive(msg* m); +int msg_receive(msg_t* m); /** * @brief Send a message, block until reply received. @@ -90,7 +90,7 @@ int msg_receive(msg* m); * @param target pid the pid of the target process * @return 1 if successful */ -int msg_send_receive(msg *m, msg *reply, unsigned int target_pid); +int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid); /** * @brief Replies to a message. @@ -103,7 +103,7 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid); * @return 1 if succcessful * qreturn 0 on error */ -int msg_reply(msg *m, msg *reply); +int msg_reply(msg_t *m, msg_t *reply); /** * @brief Initialize the current thread's message queue. @@ -111,7 +111,7 @@ int msg_reply(msg *m, msg *reply); * @param array Pointer to preallocated array of msg objects * @param num Number of msg objects in array. MUST BE POWER OF TWO! */ -int msg_init_queue(msg* array, int num); +int msg_init_queue(msg_t* array, int num); /** @} */ #endif /* __MSG_H */ diff --git a/core/include/tcb.h b/core/include/tcb.h index d5d2a6364..8ca79c190 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -48,7 +48,7 @@ typedef struct tcb { queue_node_t msg_waiters; cib_t msg_queue; - msg* msg_array; + msg_t* msg_array; const char* name; char* stack_start; diff --git a/core/msg.c b/core/msg.c index b33eda569..05ff734b8 100644 --- a/core/msg.c +++ b/core/msg.c @@ -27,7 +27,7 @@ //#define ENABLE_DEBUG #include "debug.h" -static int queue_msg(tcb *target, msg *m) { +static int queue_msg(tcb *target, msg_t *m) { int n = cib_put(&(target->msg_queue)); if (n != -1) { @@ -38,7 +38,7 @@ static int queue_msg(tcb *target, msg *m) { return 0; } -int msg_send(msg* m, unsigned int target_pid, bool block) { +int msg_send(msg_t* m, unsigned int target_pid, bool block) { if (inISR()) { return msg_send_int(m, target_pid); } @@ -90,7 +90,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { } else { DEBUG("%s: direct msg copy.\n", active_thread->name); /* copy msg to target */ - msg* target_message = (msg*)target->wait_data; + msg_t* target_message = (msg_t*)target->wait_data; *target_message = *m; sched_set_status(target, STATUS_PENDING); } @@ -101,7 +101,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { return 1; } -int msg_send_int(msg* m, unsigned int target_pid) { +int msg_send_int(msg_t* m, unsigned int target_pid) { tcb *target = (tcb*)sched_threads[target_pid]; if (target->status == STATUS_RECEIVE_BLOCKED) { @@ -110,7 +110,7 @@ int msg_send_int(msg* m, unsigned int target_pid) { m->sender_pid = target_pid; /* copy msg to target */ - msg* target_message = (msg*)target->wait_data; + msg_t* target_message = (msg_t*)target->wait_data; *target_message = *m; sched_set_status(target, STATUS_PENDING); @@ -122,7 +122,7 @@ int msg_send_int(msg* m, unsigned int target_pid) { } } -int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { +int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid) { dINT(); tcb *me = (tcb*) sched_threads[thread_pid]; sched_set_status(me, STATUS_REPLY_BLOCKED); @@ -134,7 +134,7 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { return 1; } -int msg_reply(msg *m, msg *reply) { +int msg_reply(msg_t *m, msg_t *reply) { int state = disableIRQ(); tcb *target = (tcb*)sched_threads[m->sender_pid]; @@ -146,7 +146,7 @@ int msg_reply(msg *m, msg *reply) { DEBUG("%s: msg_reply(): direct msg copy.\n", active_thread->name); /* copy msg to target */ - msg* target_message = (msg*)target->wait_data; + msg_t* target_message = (msg_t*)target->wait_data; *target_message = *reply; sched_set_status(target, STATUS_PENDING); restoreIRQ(state); @@ -155,20 +155,20 @@ int msg_reply(msg *m, msg *reply) { return 1; } -int msg_reply_int(msg *m, msg *reply) { +int msg_reply_int(msg_t *m, msg_t *reply) { tcb *target = (tcb*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name); return -1; } - msg* target_message = (msg*)target->wait_data; + msg_t* target_message = (msg_t*)target->wait_data; *target_message = *reply; sched_set_status(target, STATUS_PENDING); sched_context_switch_request = 1; return 1; } -int msg_receive(msg* m) { +int msg_receive(msg_t* m) { dINT(); DEBUG("%s: msg_receive.\n", active_thread->name); @@ -212,7 +212,7 @@ int msg_receive(msg* m) { } /* copy msg */ - msg* sender_msg = (msg*)sender->wait_data; + msg_t* sender_msg = (msg_t*)sender->wait_data; *m = *sender_msg; /* remove sender from queue */ @@ -224,7 +224,7 @@ int msg_receive(msg* m) { } } -int msg_init_queue(msg* array, int num) { +int msg_init_queue(msg_t* array, int num) { /* make sure brainfuck condition is met */ if (num && (num & (num - 1)) == 0) { tcb *me = (tcb*)active_thread; diff --git a/cpu/cc430/cc430-rtc.c b/cpu/cc430/cc430-rtc.c index 8895e0599..59afacfa9 100644 --- a/cpu/cc430/cc430-rtc.c +++ b/cpu/cc430/cc430-rtc.c @@ -187,7 +187,7 @@ interrupt(RTC_VECTOR) __attribute__ ((naked)) rtc_isr(void) { RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08; } if (rtc_second_pid) { - msg m; + msg_t m; m.type = RTC_SECOND; msg_send_int(&m, rtc_second_pid); } diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 441b7d6a2..76acfb33a 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -624,7 +624,7 @@ int cc1100_set_packet_handler(protocol_t protocol, packet_handler_t handler) static void cc1100_event_handler_function(void) { - msg m; + msg_t m; while (1) { if (cc1100_watch_dog_period != 0) { @@ -685,7 +685,7 @@ static void cc1100_event_handler_function(void) void cc1100_phy_rx_handler(void) { - msg m; + msg_t m; m.type = MSG_POLL; bool dup = false; bool res = false; diff --git a/drivers/cc110x_ng/cc110x-rx.c b/drivers/cc110x_ng/cc110x-rx.c index 7b2229169..3a5e5ba9a 100644 --- a/drivers/cc110x_ng/cc110x-rx.c +++ b/drivers/cc110x_ng/cc110x-rx.c @@ -51,7 +51,7 @@ void cc110x_rx_handler(void) { /* notify transceiver thread if any */ if (transceiver_pid) { - msg m; + msg_t m; m.type = (uint16_t) RCV_PKT_CC1100; m.content.value = rx_buffer_next; msg_send_int(&m, transceiver_pid); diff --git a/projects/chronos_cc110x_ng/main.c b/projects/chronos_cc110x_ng/main.c index 4e14c50d1..4d19a3422 100644 --- a/projects/chronos_cc110x_ng/main.c +++ b/projects/chronos_cc110x_ng/main.c @@ -22,9 +22,9 @@ char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SEND_SIZE]; -msg msg_q[RCV_BUFFER_SIZE]; +msg_t msg_q[RCV_BUFFER_SIZE]; -static msg mesg; +static msg_t mesg; static transceiver_command_t tcmd; static radio_packet_t p; @@ -48,7 +48,7 @@ void send(radio_address_t dst, uint8_t len, uint8_t *data) { void radio(void) { - msg m; + msg_t m; radio_packet_t *p; msg_init_queue(msg_q, RCV_BUFFER_SIZE); diff --git a/projects/chronos_default/main.c b/projects/chronos_default/main.c index f521910d7..6e647ad3a 100644 --- a/projects/chronos_default/main.c +++ b/projects/chronos_default/main.c @@ -27,9 +27,9 @@ char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SEND_SIZE]; -msg msg_q[RCV_BUFFER_SIZE]; +msg_t msg_q[RCV_BUFFER_SIZE]; -static msg mesg; +static msg_t mesg; static transceiver_command_t tcmd; static radio_packet_t p; @@ -52,7 +52,7 @@ void send(radio_address_t dst, uint8_t len, uint8_t *data) { } void radio(void) { - msg m; + msg_t m; radio_packet_t *p; msg_init_queue(msg_q, RCV_BUFFER_SIZE); diff --git a/projects/msb430_cc110x_ng/main.c b/projects/msb430_cc110x_ng/main.c index 019e8cb57..60719ec14 100644 --- a/projects/msb430_cc110x_ng/main.c +++ b/projects/msb430_cc110x_ng/main.c @@ -25,9 +25,9 @@ char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SND_BUFFER_SIZE][CC1100_MAX_DATA_LENGTH]; -msg msg_q[RCV_BUFFER_SIZE]; +msg_t msg_q[RCV_BUFFER_SIZE]; -static msg mesg; +static msg_t mesg; static transceiver_command_t tcmd; static radio_packet_t p; @@ -98,7 +98,7 @@ void print_buffer(char *unused) { } void radio(void) { - msg m; + msg_t m; radio_packet_t *p; uint8_t i; diff --git a/projects/pingpong/main.c b/projects/pingpong/main.c index 2c9f21457..0a4a910a9 100644 --- a/projects/pingpong/main.c +++ b/projects/pingpong/main.c @@ -5,7 +5,7 @@ void second_thread(void) { printf("second_thread starting.\n"); - msg m; + msg_t m; while(1) { msg_receive(&m); @@ -21,7 +21,7 @@ int main(void) { printf("Hello world!\n"); - msg m; + msg_t m; int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); diff --git a/projects/pingpong_sync/main.c b/projects/pingpong_sync/main.c index 8e1fd4d7d..47989a267 100644 --- a/projects/pingpong_sync/main.c +++ b/projects/pingpong_sync/main.c @@ -5,7 +5,7 @@ void second_thread(void) { printf("second_thread starting.\n"); - msg m; + msg_t m; int i = 1; while(1) { msg_receive(&m); @@ -21,7 +21,7 @@ int main(void) { printf("Hello world!\n"); - msg m; + msg_t m; int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c index 22b9485b5..1470e4fde 100644 --- a/projects/test_cc110x_ng/main.c +++ b/projects/test_cc110x_ng/main.c @@ -25,9 +25,9 @@ char radio_stack_buffer[RADIO_STACK_SIZE]; uint8_t snd_buffer[SND_BUFFER_SIZE][CC1100_MAX_DATA_LENGTH]; -msg msg_q[RCV_BUFFER_SIZE]; +msg_t msg_q[RCV_BUFFER_SIZE]; -static msg mesg; +static msg_t mesg; static transceiver_command_t tcmd; static radio_packet_t p; @@ -121,7 +121,7 @@ void set_delay(char *delay) { } void radio(void) { - msg m; + msg_t m; radio_packet_t *p; uint8_t i; diff --git a/projects/test_swtimer_basic/main.c b/projects/test_swtimer_basic/main.c index 25837a3ac..0130aa4d6 100644 --- a/projects/test_swtimer_basic/main.c +++ b/projects/test_swtimer_basic/main.c @@ -14,7 +14,7 @@ void wakeup_thread(void){ } void msg_thread(void){ - msg m; + msg_t m; msg_receive(&m); printf("%s\n",(char*)m.content.ptr); } diff --git a/projects/watch/alarm_app.c b/projects/watch/alarm_app.c index 7a9f206bb..92158382d 100644 --- a/projects/watch/alarm_app.c +++ b/projects/watch/alarm_app.c @@ -13,7 +13,7 @@ static char alarm_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; static void alarm_thread(void) { - msg m; + msg_t m; struct tm time; diff --git a/projects/watch/clock_app.c b/projects/watch/clock_app.c index 761ebe17f..f46fc35bd 100644 --- a/projects/watch/clock_app.c +++ b/projects/watch/clock_app.c @@ -15,7 +15,7 @@ void time_print(struct tm *time) { static char clock_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; static void clock_thread(void) { - msg m; + msg_t m; int active = 0; rtc_second_pid = thread_getpid(); diff --git a/projects/watch/main.c b/projects/watch/main.c index e67dbe601..94bbcc864 100644 --- a/projects/watch/main.c +++ b/projects/watch/main.c @@ -21,7 +21,7 @@ int apps[NUM_APPS]; int button_thread = 0; void button_star(void) { - msg m; + msg_t m; if (button_thread) { m.type = MSG_BUTTON_STAR; @@ -40,7 +40,7 @@ int main(void) int active_app = 0; - msg m; + msg_t m; //buzzer_beep(15, 5000); diff --git a/sys/chardev_thread.c b/sys/chardev_thread.c index 6c90928c4..11d75eac6 100644 --- a/sys/chardev_thread.c +++ b/sys/chardev_thread.c @@ -17,7 +17,7 @@ static int min(int a, int b) { } void chardev_loop(ringbuffer *rb) { - msg m; + msg_t m; int pid = thread_getpid(); diff --git a/sys/posix_io.c b/sys/posix_io.c index fd423e165..9d277af2f 100644 --- a/sys/posix_io.c +++ b/sys/posix_io.c @@ -4,7 +4,7 @@ static int _posix_fileop(int pid, int op, int flags) { - msg m; + msg_t m; m.type = op; m.content.value = flags; msg_send_receive(&m, &m, pid); @@ -16,7 +16,7 @@ static int _posix_fileop_data(int pid, int op, char* buffer, int nbytes) { r.nbytes = nbytes; r.buffer = buffer; - msg m; + msg_t m; m.type = op; m.content.ptr = (char*) &r; diff --git a/sys/shell/cc110x_ng.c b/sys/shell/cc110x_ng.c index ca192d228..ed9aa4511 100644 --- a/sys/shell/cc110x_ng.c +++ b/sys/shell/cc110x_ng.c @@ -8,7 +8,7 @@ #define TEXT_SIZE CC1100_MAX_DATA_LENGTH char text_msg[TEXT_SIZE]; -msg mesg; +msg_t mesg; transceiver_command_t tcmd; void _cc110x_ng_get_set_address_handler(char *addr) { diff --git a/sys/swtimer.c b/sys/swtimer.c index 0b998de8b..4dc248515 100644 --- a/sys/swtimer.c +++ b/sys/swtimer.c @@ -235,7 +235,7 @@ static void swtimer_action(swtimer_t *swtimer) { } case SWTIMER_MSG: { - msg m; + msg_t m; m.content.value = swtimer->action.msg.value; int result = msg_send_int(&m, swtimer->action.msg.target_pid); if (result < 0) { diff --git a/sys/transceiver.c b/sys/transceiver.c index 7fb49b6ed..d9b60b0af 100644 --- a/sys/transceiver.c +++ b/sys/transceiver.c @@ -34,7 +34,7 @@ radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; uint8_t data_buffer[TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE]; /* message buffer */ -msg msg_buffer[TRANSCEIVER_MSG_BUFFER_SIZE]; +msg_t msg_buffer[TRANSCEIVER_MSG_BUFFER_SIZE]; uint32_t response; ///< response bytes for messages to upper layer threads @@ -116,7 +116,7 @@ uint8_t transceiver_register(transceiver_type_t t, int pid) { * loop */ void run(void) { - msg m; + msg_t m; transceiver_command_t *cmd; msg_init_queue(msg_buffer, TRANSCEIVER_MSG_BUFFER_SIZE); @@ -180,7 +180,7 @@ static void receive_packet(uint16_t type, uint8_t pos) { uint8_t i = 0; transceiver_type_t t; rx_buffer_pos = pos; - msg m; + msg_t m; DEBUG("Packet received\n"); switch (type) { diff --git a/sys/uart0.c b/sys/uart0.c index 04182b082..6907fa89b 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -33,7 +33,7 @@ void uart0_handle_incoming(int c) { } void uart0_notify_thread(void) { - msg m; + msg_t m; m.type = 0; msg_send_int(&m, uart0_handler_pid); } From e9d351da8df1936a7b19614484ab591f576c97e7 Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 8 Mar 2011 11:17:57 +0100 Subject: [PATCH 168/199] changed ringbuffer to ringbuffer_t --- sys/chardev_thread.c | 2 +- sys/include/chardev_thread.h | 2 +- sys/lib/ringbuffer.c | 10 +++++----- sys/lib/ringbuffer.h | 12 ++++++------ sys/uart0.c | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sys/chardev_thread.c b/sys/chardev_thread.c index 11d75eac6..6f70af7df 100644 --- a/sys/chardev_thread.c +++ b/sys/chardev_thread.c @@ -16,7 +16,7 @@ static int min(int a, int b) { else return b; } -void chardev_loop(ringbuffer *rb) { +void chardev_loop(ringbuffer_t *rb) { msg_t m; int pid = thread_getpid(); diff --git a/sys/include/chardev_thread.h b/sys/include/chardev_thread.h index 4596cda83..bb811bddd 100644 --- a/sys/include/chardev_thread.h +++ b/sys/include/chardev_thread.h @@ -3,6 +3,6 @@ #include -void chardev_loop(ringbuffer *rb); +void chardev_loop(ringbuffer_t *rb); #endif /* __CHARDEV_THREAD_H */ diff --git a/sys/lib/ringbuffer.c b/sys/lib/ringbuffer.c index ef2116d5a..4e021942d 100755 --- a/sys/lib/ringbuffer.c +++ b/sys/lib/ringbuffer.c @@ -8,7 +8,7 @@ //#define DEBUG(...) printf (__VA_ARGS__) #define DEBUG(...) -void ringbuffer_init(ringbuffer *rb, char* buffer, unsigned int bufsize) { +void ringbuffer_init(ringbuffer_t *rb, char* buffer, unsigned int bufsize) { rb->buf = buffer; rb->start = 0; rb->end = 0; @@ -16,13 +16,13 @@ void ringbuffer_init(ringbuffer *rb, char* buffer, unsigned int bufsize) { rb->avail = 0; } -void rb_add_elements(ringbuffer* rb, char *buf, int n) { +void rb_add_elements(ringbuffer_t* rb, char *buf, int n) { for (int i = 0; i < n; i++) { rb_add_element(rb, buf[i]); } } -void rb_add_element(ringbuffer* rb, char c) { +void rb_add_element(ringbuffer_t* rb, char c) { if (rb->avail == rb->size) rb_get_element(rb); rb->buf[rb->end++] = c; @@ -31,7 +31,7 @@ void rb_add_element(ringbuffer* rb, char c) { rb->avail++; } -int rb_get_element(ringbuffer *rb) { +int rb_get_element(ringbuffer_t *rb) { if (rb->avail == 0) return -1; rb->avail--; @@ -42,7 +42,7 @@ int rb_get_element(ringbuffer *rb) { return c; } -int rb_get_elements(ringbuffer *rb, char* buf, int n) { +int rb_get_elements(ringbuffer_t *rb, char* buf, int n) { int count = 0; while (rb->avail && (count < n)) { buf[count++] = rb_get_element(rb); diff --git a/sys/lib/ringbuffer.h b/sys/lib/ringbuffer.h index 11f7222af..3e646ae79 100755 --- a/sys/lib/ringbuffer.h +++ b/sys/lib/ringbuffer.h @@ -7,12 +7,12 @@ typedef struct ringbuffer { unsigned int end; unsigned int size; unsigned int avail; -} ringbuffer; +} ringbuffer_t; -void ringbuffer_init(ringbuffer *rb, char* buffer, unsigned int bufsize); -void rb_add_element(ringbuffer *rb, char c); -void rb_add_elements(ringbuffer *rb, char *buf, int n); -int rb_get_element(ringbuffer *rb); -int rb_get_elements(ringbuffer *rb, char *buf, int n); +void ringbuffer_init(ringbuffer_t *rb, char* buffer, unsigned int bufsize); +void rb_add_element(ringbuffer_t *rb, char c); +void rb_add_elements(ringbuffer_t *rb, char *buf, int n); +int rb_get_element(ringbuffer_t *rb); +int rb_get_elements(ringbuffer_t *rb, char *buf, int n); #endif /* __RINGBUFFER_H */ diff --git a/sys/uart0.c b/sys/uart0.c index 6907fa89b..5ba90d98a 100644 --- a/sys/uart0.c +++ b/sys/uart0.c @@ -10,7 +10,7 @@ #define UART0_BUFSIZE (32) #define UART0_STACKSIZE (MINIMUM_STACK_SIZE + 256) -ringbuffer uart0_ringbuffer; +ringbuffer_t uart0_ringbuffer; int uart0_handler_pid; static char buffer[UART0_BUFSIZE]; From 5abef6daf2bcd9f625d1791fd64a76c1ef098e74 Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 8 Mar 2011 11:43:21 +0100 Subject: [PATCH 169/199] changed types irq_callback, hashtable, posix_io, s_display_flags, seq_buffer_entry, tcb, toprint to type_t" --- board/chronos/drivers/display.c | 2 +- board/chronos/drivers/include/display.h | 4 ++-- board/msba2-common/drivers/msba2-uart0.c | 8 ++++---- core/include/sched.h | 6 +++--- core/include/tcb.h | 4 ++-- core/kernel_init.c | 4 ++-- core/msg.c | 20 ++++++++++---------- core/mutex.c | 4 ++-- core/sched.c | 14 +++++++------- core/thread.c | 8 ++++---- cpu/lpc2387/lpc2387-gpioint.c | 10 +++++----- drivers/cc110x/cc1100_phy.c | 6 +++--- sys/chardev_thread.c | 4 ++-- sys/include/posix_io.h | 2 +- sys/posix_io.c | 2 +- sys/shell/ps.c | 2 +- 16 files changed, 50 insertions(+), 50 deletions(-) diff --git a/board/chronos/drivers/display.c b/board/chronos/drivers/display.c index 39774279b..063ade585 100644 --- a/board/chronos/drivers/display.c +++ b/board/chronos/drivers/display.c @@ -57,7 +57,7 @@ void display_symbol(uint8_t symbol, uint8_t mode); * Global Variable section */ /* Display flags */ -volatile s_display_flags display; +volatile s_display_flags_t display; /* Global return string for itoa function */ char itoa_str[8]; diff --git a/board/chronos/drivers/include/display.h b/board/chronos/drivers/include/display.h index 805d801d2..3b7c2e131 100644 --- a/board/chronos/drivers/include/display.h +++ b/board/chronos/drivers/include/display.h @@ -67,9 +67,9 @@ typedef union { uint16_t update_acceleration : 1; // 1 = Acceleration data was updated } flag; uint16_t all_flags; // Shortcut to all display flags (for reset) -} s_display_flags; +} s_display_flags_t; -extern volatile s_display_flags display; +extern volatile s_display_flags_t display; // Constants defined in library extern const uint8_t lcd_font[]; diff --git a/board/msba2-common/drivers/msba2-uart0.c b/board/msba2-common/drivers/msba2-uart0.c index 3107e8d40..31a9870aa 100644 --- a/board/msba2-common/drivers/msba2-uart0.c +++ b/board/msba2-common/drivers/msba2-uart0.c @@ -49,13 +49,13 @@ and the mailinglist (subscription via web site) * @note $Id$ */ -typedef struct toprint { +typedef struct toprint_t { unsigned int len; char content[]; -}toprint; +}toprint_t; #define QUEUESIZE 255 -static volatile toprint* queue[QUEUESIZE]; +static volatile toprint_t* queue[QUEUESIZE]; static volatile unsigned char queue_head = 0; static volatile unsigned char queue_tail = 0; static volatile unsigned char queue_items = 0; @@ -64,7 +64,7 @@ static volatile unsigned int actual_pos = 0; static volatile unsigned int running = 0; static volatile unsigned int fifo = 0; -static volatile toprint* actual = NULL; +static volatile toprint_t* actual = NULL; static inline void enqueue(void) { queue_items++; diff --git a/core/include/sched.h b/core/include/sched.h index ad30cfb60..bce386431 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -24,13 +24,13 @@ void sched_init(); void sched_run(); -void sched_set_status(tcb *process, unsigned int status); +void sched_set_status(tcb_t *process, unsigned int status); void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr); volatile unsigned int sched_context_switch_request; -volatile tcb *sched_threads[MAXTHREADS]; -volatile tcb *active_thread; +volatile tcb_t *sched_threads[MAXTHREADS]; +volatile tcb_t *active_thread; extern volatile int num_tasks; volatile int thread_pid; diff --git a/core/include/tcb.h b/core/include/tcb.h index 8ca79c190..9d6f5f26c 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -35,7 +35,7 @@ #define STATUS_REPLY_BLOCKED (0x0100) #define STATUS_TIMER_WAITING (0x0200) -typedef struct tcb { +typedef struct tcb_t { char* sp; uint16_t status; @@ -53,7 +53,7 @@ typedef struct tcb { const char* name; char* stack_start; int stack_size; -} tcb; +} tcb_t; /** @} */ #endif /* TCB_H_ */ diff --git a/core/kernel_init.c b/core/kernel_init.c index fc9abc751..6af76399c 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -33,8 +33,8 @@ #define ENABLE_DEBUG #include -volatile tcb *sched_threads[MAXTHREADS]; -volatile tcb *active_thread; +volatile tcb_t *sched_threads[MAXTHREADS]; +volatile tcb_t *active_thread; volatile int lpm_prevent_sleep = 0; extern void main(void); diff --git a/core/msg.c b/core/msg.c index 05ff734b8..349caf7c5 100644 --- a/core/msg.c +++ b/core/msg.c @@ -27,7 +27,7 @@ //#define ENABLE_DEBUG #include "debug.h" -static int queue_msg(tcb *target, msg_t *m) { +static int queue_msg(tcb_t *target, msg_t *m) { int n = cib_put(&(target->msg_queue)); if (n != -1) { @@ -43,7 +43,7 @@ int msg_send(msg_t* m, unsigned int target_pid, bool block) { return msg_send_int(m, target_pid); } - tcb *target = (tcb*)sched_threads[target_pid]; + tcb_t *target = (tcb_t*)sched_threads[target_pid]; m->sender_pid = thread_pid; if (m->sender_pid == target_pid) { @@ -84,7 +84,7 @@ int msg_send(msg_t* m, unsigned int target_pid, bool block) { newstatus = STATUS_SEND_BLOCKED; } - sched_set_status((tcb*)active_thread, newstatus); + sched_set_status((tcb_t*)active_thread, newstatus); DEBUG("%s: back from send block.\n", active_thread->name); } else { @@ -102,7 +102,7 @@ int msg_send(msg_t* m, unsigned int target_pid, bool block) { } int msg_send_int(msg_t* m, unsigned int target_pid) { - tcb *target = (tcb*)sched_threads[target_pid]; + tcb_t *target = (tcb_t*)sched_threads[target_pid]; if (target->status == STATUS_RECEIVE_BLOCKED) { DEBUG("msg_send_int: direct msg copy.\n"); @@ -124,7 +124,7 @@ int msg_send_int(msg_t* m, unsigned int target_pid) { int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid) { dINT(); - tcb *me = (tcb*) sched_threads[thread_pid]; + tcb_t *me = (tcb_t*) sched_threads[thread_pid]; sched_set_status(me, STATUS_REPLY_BLOCKED); me->wait_data = (void*) reply; msg_send(m, target_pid, true); @@ -137,7 +137,7 @@ int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid) { int msg_reply(msg_t *m, msg_t *reply) { int state = disableIRQ(); - tcb *target = (tcb*)sched_threads[m->sender_pid]; + tcb_t *target = (tcb_t*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", active_thread->name, target->name); restoreIRQ(state); @@ -156,7 +156,7 @@ int msg_reply(msg_t *m, msg_t *reply) { } int msg_reply_int(msg_t *m, msg_t *reply) { - tcb *target = (tcb*)sched_threads[m->sender_pid]; + tcb_t *target = (tcb_t*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name); return -1; @@ -172,7 +172,7 @@ int msg_receive(msg_t* m) { dINT(); DEBUG("%s: msg_receive.\n", active_thread->name); - tcb *me = (tcb*) sched_threads[thread_pid]; + tcb_t *me = (tcb_t*) sched_threads[thread_pid]; int n = -1; if (me->msg_array) { @@ -202,7 +202,7 @@ int msg_receive(msg_t* m) { return 1; } else { DEBUG("%s: msg_receive(): Wakeing up waiting thread.\n", active_thread->name); - tcb *sender = (tcb*)node->data; + tcb_t *sender = (tcb_t*)node->data; if (n >= 0) { /* we've already got a messgage from the queue. as there is a @@ -227,7 +227,7 @@ int msg_receive(msg_t* m) { int msg_init_queue(msg_t* array, int num) { /* make sure brainfuck condition is met */ if (num && (num & (num - 1)) == 0) { - tcb *me = (tcb*)active_thread; + tcb_t *me = (tcb_t*)active_thread; me->msg_array = array; cib_init(&(me->msg_queue), num); return 0; diff --git a/core/mutex.c b/core/mutex.c index fd4b708a3..b31f5a44a 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -61,7 +61,7 @@ void mutex_wait(struct mutex_t *mutex) { return; } - sched_set_status((tcb*)active_thread, STATUS_MUTEX_BLOCKED); + sched_set_status((tcb_t*)active_thread, STATUS_MUTEX_BLOCKED); queue_node_t n; n.priority = (unsigned int) active_thread->priority; @@ -86,7 +86,7 @@ void mutex_unlock(struct mutex_t* mutex, int yield) { if (mutex->val != 0) { if (mutex->queue.next) { queue_node_t *next = queue_remove_head(&(mutex->queue)); - tcb* process = (tcb*)next->data; + tcb_t* process = (tcb_t*)next->data; DEBUG("%s: waking up waiter %s.\n", process->name); sched_set_status(process, STATUS_PENDING); diff --git a/core/sched.c b/core/sched.c index 0563e46f4..9b33d386d 100644 --- a/core/sched.c +++ b/core/sched.c @@ -56,7 +56,7 @@ void sched_init() { void sched_run() { sched_context_switch_request = 0; - tcb *my_active_thread = (tcb*)active_thread; + tcb_t *my_active_thread = (tcb_t*)active_thread; if (my_active_thread) { if( my_active_thread->status == STATUS_RUNNING) { @@ -94,9 +94,9 @@ void sched_run() { // if (runqueues[i]) { int nextrq = number_of_lowest_bit(runqueue_bitcache); clist_node_t next = *(runqueues[nextrq]); - DEBUG("scheduler: first in queue: %s\n", ((tcb*)next.data)->name); + DEBUG("scheduler: first in queue: %s\n", ((tcb_t*)next.data)->name); clist_advance(&(runqueues[nextrq])); - my_active_thread = (tcb*)next.data; + my_active_thread = (tcb_t*)next.data; thread_pid = (volatile int) my_active_thread->pid; #if SCHEDSTATISTICS pidlist[my_active_thread->pid].laststart = time; @@ -115,16 +115,16 @@ void sched_run() { active_thread->status = STATUS_PENDING ; } } - sched_set_status((tcb*)my_active_thread, STATUS_RUNNING); + sched_set_status((tcb_t*)my_active_thread, STATUS_RUNNING); } - active_thread = (volatile tcb*) my_active_thread; + active_thread = (volatile tcb_t*) my_active_thread; DEBUG("scheduler: done.\n"); } -void sched_set_status(tcb *process, unsigned int status) { +void sched_set_status(tcb_t *process, unsigned int status) { if (status & STATUS_ON_RUNQUEUE) { if (! (process->status & STATUS_ON_RUNQUEUE)) { DEBUG("adding process %s to runqueue %u.\n", process->name, process->priority); @@ -163,7 +163,7 @@ void sched_task_exit(void) { sched_threads[active_thread->pid] = NULL; num_tasks--; - sched_set_status((tcb*)active_thread, STATUS_STOPPED); + sched_set_status((tcb_t*)active_thread, STATUS_STOPPED); active_thread = NULL; cpu_switch_context_exit(); diff --git a/core/thread.c b/core/thread.c index e087f2a9d..1a5bf82f7 100644 --- a/core/thread.c +++ b/core/thread.c @@ -39,7 +39,7 @@ unsigned int thread_getstatus(int pid) { void thread_sleep() { if ( inISR()) return; dINT(); - sched_set_status((tcb*)active_thread, STATUS_SLEEPING); + sched_set_status((tcb_t*)active_thread, STATUS_SLEEPING); thread_yield(); } @@ -54,7 +54,7 @@ int thread_wakeup(int pid) { int result = sched_threads[pid]->status; if (result == STATUS_SLEEPING) { DEBUG("thread_wakeup: Thread is sleeping.\n"); - sched_set_status((tcb*)sched_threads[pid], STATUS_RUNNING); + sched_set_status((tcb_t*)sched_threads[pid], STATUS_RUNNING); if (!isr) { eINT(); thread_yield(); @@ -83,7 +83,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f { /* allocate our thread control block at the top of our stackspace */ int total_stacksize = stacksize; - stacksize -= sizeof(tcb); + stacksize -= sizeof(tcb_t); /* align tcb address on 32bit boundary */ unsigned int tcb_address = (unsigned int) stack + stacksize; @@ -95,7 +95,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f tcb_address-=2; stacksize-=2; } - tcb *cb = (tcb*) tcb_address; + tcb_t *cb = (tcb_t*) tcb_address; if (priority >= SCHED_PRIO_LEVELS) { return -EINVAL; diff --git a/cpu/lpc2387/lpc2387-gpioint.c b/cpu/lpc2387/lpc2387-gpioint.c index 7ce594141..494172745 100644 --- a/cpu/lpc2387/lpc2387-gpioint.c +++ b/cpu/lpc2387/lpc2387-gpioint.c @@ -48,12 +48,12 @@ and the mailinglist (subscription via web site) #include "cpu.h" #include -struct irq_callback { +struct irq_callback_t { fp_irqcb callback; }; -static struct irq_callback gpioint0[32]; -static struct irq_callback gpioint2[32]; +static struct irq_callback_t gpioint0[32]; +static struct irq_callback_t gpioint2[32]; void gpioint_init(void) { @@ -68,7 +68,7 @@ void gpioint_init(void) { bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) { - struct irq_callback* cbdata; + struct irq_callback_t* cbdata; unsigned long bit; volatile unsigned long* en_f; volatile unsigned long* en_r; @@ -123,7 +123,7 @@ gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) return true; // success } /*---------------------------------------------------------------------------*/ -static void __attribute__ ((__no_instrument_function__)) test_irq(int port, unsigned long f_mask, unsigned long r_mask, struct irq_callback* pcb) +static void __attribute__ ((__no_instrument_function__)) test_irq(int port, unsigned long f_mask, unsigned long r_mask, struct irq_callback_t* pcb) { /* Test each bit of rising and falling masks, if set trigger interrupt * on corresponding device */ diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 76acfb33a..d97a3857a 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -119,10 +119,10 @@ typedef struct uint64_t m_ticks; ///< 64-bit timestamp uint8_t source; ///< Source address uint8_t identification; ///< Identification (1-bit) -} seq_buffer_entry; +} seq_buffer_entry_t; /// Sequence number buffer for this layer -static seq_buffer_entry seq_buffer[MAX_SEQ_BUFFER_SIZE]; +static seq_buffer_entry_t seq_buffer[MAX_SEQ_BUFFER_SIZE]; /// Next position to enter a new value into ::seqBuffer static uint8_t seq_buffer_pos = 0; @@ -186,7 +186,7 @@ void cc1100_phy_init() pm_init_table((pm_table_t*)&handler_table, MAX_PACKET_HANDLERS, handlers); // Clear sequence number buffer - memset(seq_buffer, 0, sizeof(seq_buffer_entry) * MAX_SEQ_BUFFER_SIZE); + memset(seq_buffer, 0, sizeof(seq_buffer_entry_t) * MAX_SEQ_BUFFER_SIZE); // Initialize mutex cc1100_mutex_pid = -1; diff --git a/sys/chardev_thread.c b/sys/chardev_thread.c index 6f70af7df..d30782926 100644 --- a/sys/chardev_thread.c +++ b/sys/chardev_thread.c @@ -22,7 +22,7 @@ void chardev_loop(ringbuffer_t *rb) { int pid = thread_getpid(); int reader_pid = -1; - struct posix_iop *r = NULL; + struct posix_iop_t *r = NULL; puts("UART0 thread started."); @@ -46,7 +46,7 @@ void chardev_loop(ringbuffer_t *rb) { m.content.value = -EINVAL; msg_reply(&m, &m); } else { - r = (struct posix_iop *)m.content.ptr; + r = (struct posix_iop_t *)m.content.ptr; } break; case CLOSE: diff --git a/sys/include/posix_io.h b/sys/include/posix_io.h index 656e1ea3e..b39bdb3a3 100644 --- a/sys/include/posix_io.h +++ b/sys/include/posix_io.h @@ -6,7 +6,7 @@ #define READ 2 #define WRITE 3 -struct posix_iop { +struct posix_iop_t { int nbytes; char *buffer; }; diff --git a/sys/posix_io.c b/sys/posix_io.c index 9d277af2f..63ec13621 100644 --- a/sys/posix_io.c +++ b/sys/posix_io.c @@ -12,7 +12,7 @@ static int _posix_fileop(int pid, int op, int flags) { } static int _posix_fileop_data(int pid, int op, char* buffer, int nbytes) { - struct posix_iop r; + struct posix_iop_t r; r.nbytes = nbytes; r.buffer = buffer; diff --git a/sys/shell/ps.c b/sys/shell/ps.c index 0848bd509..6c3226fea 100644 --- a/sys/shell/ps.c +++ b/sys/shell/ps.c @@ -27,7 +27,7 @@ void thread_print_all(void) printf("\tpid | %-21s| %-9sQ | pri | stack ( used) location | runtime | switches \n", "name", "state"); for( i = 0; i < MAXTHREADS; i++ ) { - tcb* p = (tcb*)sched_threads[i]; + tcb_t* p = (tcb_t*)sched_threads[i]; if( p != NULL ) { int state = p->status; // copy state From bc23a41a30719eb1d95105056871d9e544b0b1a6 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 18 Mar 2011 15:59:50 +0100 Subject: [PATCH 170/199] * some changes to chronos (not yet finished) --- board/chronos/drivers/Jamfile | 1 + board/chronos/drivers/battery.c | 4 +- board/chronos/drivers/include/battery.h | 2 +- cpu/cc430/cc430-adc.c | 2 - cpu/cc430/cc430-rtc.c | 2 + drivers/Jamfile | 2 + projects/chronos_default/Jamfile | 2 +- projects/chronos_default/main.c | 57 ++++++++++++++++++++----- 8 files changed, 55 insertions(+), 17 deletions(-) diff --git a/board/chronos/drivers/Jamfile b/board/chronos/drivers/Jamfile index 286616c5d..71ee1c982 100644 --- a/board/chronos/drivers/Jamfile +++ b/board/chronos/drivers/Jamfile @@ -6,5 +6,6 @@ Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; Module battery : battery.c : adc hwtimer ; +Module vti_ps_twi : vti_ps_twi.c : hwtimer ; Module display_putchar : display_putchar.c : board_display ; diff --git a/board/chronos/drivers/battery.c b/board/chronos/drivers/battery.c index 69553fc45..bae37d329 100644 --- a/board/chronos/drivers/battery.c +++ b/board/chronos/drivers/battery.c @@ -2,8 +2,8 @@ #include #include -uint16_t battery_get_voltate(void) { - uint16_t voltage; +uint32_t battery_get_voltage(void) { + uint32_t voltage; voltage = adc12_single_conversion(REFVSEL_1, ADC12SHT0_10, ADC12INCH_11); /* Ideally we have A11=0->AVCC=0V ... A11=4095(2^12-1)->AVCC=4V diff --git a/board/chronos/drivers/include/battery.h b/board/chronos/drivers/include/battery.h index 6b206c6ec..c6381b721 100644 --- a/board/chronos/drivers/include/battery.h +++ b/board/chronos/drivers/include/battery.h @@ -1,6 +1,6 @@ #ifndef BATTERY_H #define BATTERY_H -uint16_t battery_get_voltate(void); +uint32_t battery_get_voltage(void); #endif /* BATTERY_H */ diff --git a/cpu/cc430/cc430-adc.c b/cpu/cc430/cc430-adc.c index 470725ad7..3617d155c 100644 --- a/cpu/cc430/cc430-adc.c +++ b/cpu/cc430/cc430-adc.c @@ -59,7 +59,6 @@ uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel) { ADC12CTL1 = ADC12SHP; /* Enable sample timer */ ADC12MCTL0 = ADC12SREF_1 + channel; /* ADC input channel */ ADC12IE = 0x001; /* ADC_IFG upon conv result-ADCMEMO */ - eINT(); /* Wait 2 ticks (66us) to allow internal reference to settle */ @@ -88,7 +87,6 @@ uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel) { ADC12IE = 0; /* Return ADC result */ - dINT(); return adc12_result; } diff --git a/cpu/cc430/cc430-rtc.c b/cpu/cc430/cc430-rtc.c index 8895e0599..44aa93f18 100644 --- a/cpu/cc430/cc430-rtc.c +++ b/cpu/cc430/cc430-rtc.c @@ -42,7 +42,9 @@ void rtc_init(void) { RTCCTL1 |= RTCMODE_H; /* enable ready interrupt (every second) */ +#ifndef ENABLE_DEBUG RTCCTL0 |= RTCRDYIE; +#endif } /*---------------------------------------------------------------------------*/ diff --git a/drivers/Jamfile b/drivers/Jamfile index 3dbeed6d7..09eba8ba4 100644 --- a/drivers/Jamfile +++ b/drivers/Jamfile @@ -31,5 +31,7 @@ Module sht11 : sht11.c : hwtimer ; Module ltc4150 : ltc4150.c : board_ltc4150 hwtimer ; +Module vti_ps : vti_ps.c : vti_ps_twi ; + SubInclude TOP drivers cc110x ; SubInclude TOP drivers cc110x_ng ; diff --git a/projects/chronos_default/Jamfile b/projects/chronos_default/Jamfile index 0198f8ae6..0e68768aa 100644 --- a/projects/chronos_default/Jamfile +++ b/projects/chronos_default/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects chronos_default ; -Module chronos_default : main.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint display_putchar ; +Module chronos_default : main.c altitude.c : transceiver cc110x_ng rtc board_buzzer board_display auto_init gpioint display_putchar battery vti_ps ; UseModule chronos_default ; diff --git a/projects/chronos_default/main.c b/projects/chronos_default/main.c index f521910d7..6a34f6982 100644 --- a/projects/chronos_default/main.c +++ b/projects/chronos_default/main.c @@ -15,7 +15,18 @@ #include #include #include +#include +#include +#include "altitude.h" + +#define BUTTON_EVENT_STAR (0x01) +#define BUTTON_EVENT_NUM (0x02) +#define BUTTON_EVENT_UP (0x04) +#define BUTTON_EVENT_DOWN (0x08) +#define BUTTON_EVENT_BACKLIGHT (0x10) + +#define BUTTON_HANDLER_STACK_SIZE (256) #define RADIO_STACK_SIZE (512) #define SEND_SIZE CC1100_MAX_DATA_LENGTH @@ -24,6 +35,7 @@ #define SENDING_DELAY (5 * 1000) char radio_stack_buffer[RADIO_STACK_SIZE]; +char button_handler_stack_buffer[BUTTON_HANDLER_STACK_SIZE]; uint8_t snd_buffer[SEND_SIZE]; @@ -33,6 +45,8 @@ static msg mesg; static transceiver_command_t tcmd; static radio_packet_t p; +static int button_handler_pid; +static uint8_t button_event = 0; static uint8_t mode = 0; void send(radio_address_t dst, uint8_t len, uint8_t *data); @@ -73,20 +87,30 @@ void radio(void) { } } -void change_mode(void) { - buzzer_beep(15, 5000); - if (mode) { - mode = 0; - } - else { - mode = 1; +void button_handler(void) { + while (1) { + if (button_event & BUTTON_EVENT_STAR) { + buzzer_beep(15, 5000); + mode++; + button_event &= ~BUTTON_EVENT_STAR; + } + thread_sleep(); } } +void change_mode(void) { + button_event |= BUTTON_EVENT_STAR; + thread_wakeup(button_handler_pid); +} + int main(void) { int radio_pid; + uint32_t voltage; struct tm now; + ps_init(); + reset_altitude_measurement(); + now.tm_hour = 3; now.tm_min = 59; now.tm_sec = 42; @@ -97,10 +121,12 @@ int main(void) { rtc_set_alarm(&now, RTC_ALARM_MIN); + button_handler_pid = thread_create(button_handler_stack_buffer, BUTTON_HANDLER_STACK_SIZE, PRIORITY_MAIN+1, CREATE_STACKTEST, button_handler, "button_handler"); gpioint_set(2, BUTTON_STAR_PIN, (GPIOINT_RISING_EDGE | GPIOINT_DEBOUNCE), change_mode); radio_address_t addr = 43; memset(snd_buffer, 43, SEND_SIZE); + /* radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio"); transceiver_init(TRANSCEIVER_CC1100); transceiver_start(); @@ -115,17 +141,26 @@ int main(void) { msg_send(&mesg, transceiver_pid, 1); send(12, SEND_SIZE, snd_buffer); - +*/ while (1) { hwtimer_wait(SENDING_DELAY); rtc_get_localtime(&now); - + + voltage = battery_get_voltage(); switch (mode) { case 0: - printf("\n%02u:%02u", now.tm_hour, now.tm_min); + printf("\n%lu", voltage); break; case 1: - printf("\n%02u", now.tm_sec); + printf("\n%02u:%02u", now.tm_hour, now.tm_min); + break; + case 2: + start_altitude_measurement(); + printf("\n%u", sAlt.altitude); + stop_altitude_measurement(); + break; + default: + mode = 0; break; } } From 0e6e0a46473b5ef7e73f30bf4e733152404f55f3 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 25 Mar 2011 11:42:58 +0100 Subject: [PATCH 171/199] * deleted falsy comment symbols --- tools/pyterm/pyterm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pyterm/pyterm.py b/tools/pyterm/pyterm.py index 59eadcfbd..d2b58da3d 100755 --- a/tools/pyterm/pyterm.py +++ b/tools/pyterm/pyterm.py @@ -22,8 +22,8 @@ class SerCmd(cmd.Cmd): sys.stderr.write("No port specified!\n") sys.exit(-1) self.ser = serial.Serial(port=self.port, baudrate=115200, dsrdtr=0, rtscts=0) - #self.ser.setDTR(0) - #self.ser.setRTS(0) + self.ser.setDTR(0) + self.ser.setRTS(0) # start serial->console thread receiver_thread = threading.Thread(target=reader, args=(self.ser,)) From 23cd123bdbd763ea96e5bb626d49ddd9f1e619ed Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 4 Apr 2011 13:15:21 +0200 Subject: [PATCH 172/199] [core thread] * fixed wrong struct name in macro --- core/include/thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/thread.h b/core/include/thread.h index 359d778d9..77eea8d4b 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -17,7 +17,7 @@ #include /** Minimum stack size */ -#define MINIMUM_STACK_SIZE (sizeof(tcb)) +#define MINIMUM_STACK_SIZE (sizeof(tcb_t)) /** * @brief Creates a new thread. From c0af1a81893e363c0094dd2c66f3d887bcc1d649 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 4 Apr 2011 13:28:33 +0200 Subject: [PATCH 173/199] [projects WEAtHeR] * added project --- projects/WEAtHeR/Jamfile | 5 +++++ projects/WEAtHeR/main.c | 33 ++++++++++++++++++++++++++++++ projects/WEAtHeR/tests/hello-world | 13 ++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 projects/WEAtHeR/Jamfile create mode 100644 projects/WEAtHeR/main.c create mode 100755 projects/WEAtHeR/tests/hello-world diff --git a/projects/WEAtHeR/Jamfile b/projects/WEAtHeR/Jamfile new file mode 100644 index 000000000..d2eb26f50 --- /dev/null +++ b/projects/WEAtHeR/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects weather ; + +Module weather : main.c : sht11 ltc4150 swtimer auto_init ; + +UseModule weather ; diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c new file mode 100644 index 000000000..2c248b117 --- /dev/null +++ b/projects/WEAtHeR/main.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include + +int main(void) +{ + sht11_val_t sht11_val; + double mAh = 0; + + uint8_t success = 0; + + puts(""); + puts("WEAtHeR: Wireless Energy-Aware mulTi-Hop sEnsor Reading."); + puts("Printing \"temperature in °C;relative humidity;temperature compensated relative humidity\"."); + puts(""); + + ltc4150_start(); + + while (1) { + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + mAh = ltc4150_get_total_mAh(); + if (!success) { + printf("error;error;error\n"); + } + else { + printf("%.2f;%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp, mAh); + } + LED_RED_TOGGLE; + swtimer_usleep(60 * 1000*1000); + } +} diff --git a/projects/WEAtHeR/tests/hello-world b/projects/WEAtHeR/tests/hello-world new file mode 100755 index 000000000..acde8265f --- /dev/null +++ b/projects/WEAtHeR/tests/hello-world @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "Hello World!" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" + From 364905f0d6ad8332235d390b573d8e67f80a26d4 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 4 Apr 2011 20:33:18 +0200 Subject: [PATCH 174/199] [projects WEAtHeR] * updated project by adding routing functionality --- projects/WEAtHeR/Jamfile | 6 +- projects/WEAtHeR/main.c | 193 ++++++++++++++++++++++-- projects/WEAtHeR/protocol_msg_gateway.c | 54 +++++++ projects/WEAtHeR/protocol_msg_gateway.h | 18 +++ projects/WEAtHeR/weather_protocol.h | 41 +++++ projects/WEAtHeR/weather_routing.c | 60 ++++++++ projects/WEAtHeR/weather_routing.h | 17 +++ 7 files changed, 374 insertions(+), 15 deletions(-) create mode 100644 projects/WEAtHeR/protocol_msg_gateway.c create mode 100644 projects/WEAtHeR/protocol_msg_gateway.h create mode 100644 projects/WEAtHeR/weather_protocol.h create mode 100644 projects/WEAtHeR/weather_routing.c create mode 100644 projects/WEAtHeR/weather_routing.h diff --git a/projects/WEAtHeR/Jamfile b/projects/WEAtHeR/Jamfile index d2eb26f50..3576888c6 100644 --- a/projects/WEAtHeR/Jamfile +++ b/projects/WEAtHeR/Jamfile @@ -1,5 +1,5 @@ -SubDir TOP projects weather ; +SubDir TOP projects WEAtHeR ; -Module weather : main.c : sht11 ltc4150 swtimer auto_init ; +Module WEAtHeR : main.c weather_routing.c protocol_msg_gateway.c : sht11 ltc4150 cc110x gpioint swtimer shell shell_commands posix_io uart0 auto_init rtc ; -UseModule weather ; +UseModule WEAtHeR ; diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index 2c248b117..878c5bba3 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -3,31 +3,200 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "weather_routing.h" +#include "weather_protocol.h" +#include "protocol_msg_gateway.h" + +#define SHELL_STACK_SIZE (2048) +#define PH_STACK_SIZE (2048) + +/* per default not acting as data sink */ +static uint8_t data_sink = 0; +static uint8_t data_src = 0; + +char shell_stack_buffer[SHELL_STACK_SIZE]; +char ph_stack_buffer[PH_STACK_SIZE]; + +void weather_send(char* unused); +void weather_sink(char* unused); + +shell_t shell; +const shell_command_t sc[] = { + {"sender", "Enables node as data source.", weather_send}, + {"sink", "Enables node as data sink.", weather_sink}, + {NULL, NULL, NULL}}; + +void shell_runner(void) { + shell_init(&shell, sc, uart0_readc, uart0_putc); + posix_open(uart0_handler_pid, 0); + shell_run(&shell); +} + +void weather_send(char* unused) { + if (data_src) { + data_src = 0; + puts("Disabling data source mode."); + } + else { + data_src = 1; + puts("Enabling data source mode."); + } +} + +void weather_sink(char* unused) { + if (data_sink) { + data_sink = 0; + puts("Disabling data sink mode."); + } + else { + data_sink = 1; + puts("Enabling data sink mode."); + } +} -int main(void) -{ +static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { + weather_packet_header_t *header = (weather_packet_header_t*) msg; + + printf("\n\t Pkt received from phy: %u\n" + "\t -> SEQ: %u | TYPE: %u | SRC: %hu \n\n", + packet_info->phy_src, + header->seq_nr, + header->type, + header->src + ); + + /* when destination is set, but I'm not the receiver, pass to routing */ + if (!data_sink) { + if (header->type == WEATHER_DATA) { + weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + /* ;;;;;;; */ + printf("%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", + header->src, + 0, + wdp->timestamp, + 0, + wdp->temperature, + wdp->relhum, + wdp->relhum_temp, + wdp->energy); + } + + puts("Not for me, routing, baby!"); + route_packet(msg, msg_size); + return; + } + + /* in all other cases handle the packet */ + switch (header->type) { + case WEATHER_HELLO: { + if (msg_size < sizeof(weather_hello_pkt_t)) { + puts("Bad hello packet received."); + } else { + puts("Hello packet received - no handler implemented"); + } + break; + } + case WEATHER_CHAT: { + puts("\n*================================================================================*"); + printf("\tCHAT MESSAGE from %hu: %s\n\n", packet_info->phy_src, ((weather_chat_pkt_t*) msg)->mesg); + puts("*================================================================================*\n"); + break; + } + case WEATHER_DATA: { + weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + time_t local_time = rtc_time(NULL); + /* ;;;;;;; */ + printf("%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f\n", + header->src, + 1, + wdp->timestamp, + local_time, + wdp->temperature, + wdp->relhum, + wdp->relhum_temp, + wdp->energy); + break; + } + default: { + printf("Unknown packet type \"%i\" received.", header->type); + } + } +} + +/* endless loop for packet handling */ +static void protocol_handler_thread(void) { + msg_t m; + puts("Protocol handler thread started."); + + while(1) { + msg_receive(&m); + + packet_t packet; + int pos = m.content.value; + packet = packet_buffer[pos]; + + handle_packet(packet.payload, packet.msg_size, &(packet.packet_info)); + } +} + +int main(void) { + weather_data_pkt_t wdp; sht11_val_t sht11_val; - double mAh = 0; uint8_t success = 0; + + wdp.header.seq_nr = 0; + wdp.header.type = WEATHER_DATA; puts(""); puts("WEAtHeR: Wireless Energy-Aware mulTi-Hop sEnsor Reading."); - puts("Printing \"temperature in °C;relative humidity;temperature compensated relative humidity\"."); + /* ;;;;;;; */ + puts("Printing \"node id of data source;node id of sink;timestamp of measurement;timestamp at data sink;temperature in °C;relative humidity;temperature compensated relative humidity;energy value\"."); puts(""); + thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); + + /* create thread for radio packet handling */ + int pid = thread_create(ph_stack_buffer, PH_STACK_SIZE, PRIORITY_MAIN-5, CREATE_STACKTEST, protocol_handler_thread, "protocol_handler"); + set_protocol_handler_thread(pid); + ltc4150_start(); + rtc_enable(); while (1) { - success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); - mAh = ltc4150_get_total_mAh(); - if (!success) { - printf("error;error;error\n"); - } - else { - printf("%.2f;%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp, mAh); + if (data_src) { + wdp.header.src = cc1100_get_address(); + wdp.timestamp = rtc_time(NULL); + wdp.energy = ltc4150_get_total_mAh(); + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + if (!success) { + printf("error;error;error\n"); + } + else { + wdp.temperature = sht11_val.temperature; + wdp.relhum = sht11_val.relhum; + wdp.relhum_temp = sht11_val.relhum_temp; + if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)&wdp, sizeof(weather_data_pkt_t))) { + printf("Successfully sent packet: \n"); + wdp.header.seq_nr++; + } + else { + puts("Error on sending packet!"); + } + } + LED_RED_TOGGLE; } - LED_RED_TOGGLE; swtimer_usleep(60 * 1000*1000); } } diff --git a/projects/WEAtHeR/protocol_msg_gateway.c b/projects/WEAtHeR/protocol_msg_gateway.c new file mode 100644 index 000000000..1e439c5d5 --- /dev/null +++ b/projects/WEAtHeR/protocol_msg_gateway.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include "protocol_msg_gateway.h" + +#define NUM_PROTOCOL_HANDLER_PIDS 8 + +static uint16_t protocol_handler_pid; + +static int packet_buffer_next = 0; +packet_t packet_buffer[PACKET_BUFFER_SIZE]; + +static void protocol_msg_gateway(void* payload, int msg_size, protocol_t protocol, packet_info_t* packet_info) { + msg_t m; + +// if ((((int16_t) packet_info->phy_src) > (((int16_t) cc1100_get_address()) + 10)) || (((int16_t) packet_info->phy_src) < (((int16_t) cc1100_get_address()) - 10))) { + // return; + // } + if (protocol_handler_pid <= 0) { + puts("protocol_handler(): received packet without protocol handler. msg dropped."); + return; + } + + int mypos = packet_buffer_next++; + if (packet_buffer_next == PACKET_BUFFER_SIZE) packet_buffer_next = 0; + + packet_t *p = &(packet_buffer[mypos]); + p->packet_info = *packet_info; + p->msg_size = msg_size; + memcpy(p->payload, payload, msg_size); + + m.type = 0; + m.content.value = mypos; + int success = msg_send_int(&m, protocol_handler_pid); + if (! success) { + /* should set timer to retry. Dropping pkt for now. */ + puts("protocol_handler(): msg dropped."); + } +} + +void init_protocol_msg_gateway() { + cc1100_set_packet_monitor(protocol_msg_gateway); +} + +int set_protocol_handler_thread(int pid) { + protocol_handler_pid = pid; + return 0; +} diff --git a/projects/WEAtHeR/protocol_msg_gateway.h b/projects/WEAtHeR/protocol_msg_gateway.h new file mode 100644 index 000000000..dd190da99 --- /dev/null +++ b/projects/WEAtHeR/protocol_msg_gateway.h @@ -0,0 +1,18 @@ +#ifndef __PROTOCOL_MSG_GATEWAY_H +#define __PROTOCOL_MSG_GATEWAY_H + +#define PACKET_BUFFER_SIZE 32 +#define MAXIMUM_PAYLOAD_SIZE 64 + +typedef struct { + packet_info_t packet_info; + unsigned int msg_size; + char payload[MAXIMUM_PAYLOAD_SIZE]; +} packet_t; + +void init_protocol_msg_gateway(); +int set_protocol_handler_thread(int pid); + +extern packet_t packet_buffer[PACKET_BUFFER_SIZE]; + +#endif /* __PROTOCOL_MSG_GATEWAY_H */ diff --git a/projects/WEAtHeR/weather_protocol.h b/projects/WEAtHeR/weather_protocol.h new file mode 100644 index 000000000..f504204c9 --- /dev/null +++ b/projects/WEAtHeR/weather_protocol.h @@ -0,0 +1,41 @@ +#ifndef WEATHER_PROTOCOL_H_ +#define WEATHER_PROTOCOL_H_ + +#include +#include + +#define WEATHER_PROTOCOL_NR 6 + +typedef enum { + WEATHER_HELLO, + WEATHER_CHAT, + WEATHER_DATA +} packet_types; + +typedef struct { + uint16_t seq_nr; + uint8_t src; + uint8_t type; + uint8_t resevered; +} weather_packet_header_t; + +typedef struct __attribute__ ((packed)) { + weather_packet_header_t header; +} weather_hello_pkt_t; + +typedef struct { + weather_packet_header_t header; + uint8_t len; + char mesg[40]; +} weather_chat_pkt_t; + +typedef struct { + weather_packet_header_t header; + time_t timestamp; + double temperature; + double relhum; + double relhum_temp; + double energy; +} weather_data_pkt_t; + +#endif diff --git a/projects/WEAtHeR/weather_routing.c b/projects/WEAtHeR/weather_routing.c new file mode 100644 index 000000000..8c354b021 --- /dev/null +++ b/projects/WEAtHeR/weather_routing.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include "weather_protocol.h" +#include "weather_routing.h" + +static source_timestamp_t sources[MAX_SOURCES]; + +static uint8_t update_sources(uint8_t id, time_t timestamp) { + uint8_t i; + for (i = 0; i < MAX_SOURCES; i++) { + /* source id found */ + if (sources[i].id == id) { + /* more current timestamp received, updating */ + if (sources[i].timestamp < timestamp) { + sources[i].timestamp = timestamp; + return 1; + } + /* older, but still valid timestamp, not updating */ + else if (sources[i].timestamp < timestamp + MAX_INTERVAL) { + return 1; + } + /* timestamp too old, discard this packet */ + else { + puts("Timestamp too old, not routing"); + return 0; + } + } + /* source id not yet stored creating new entry */ + else if (!sources[i].id) { + sources[i].id = id; + sources[i].timestamp = timestamp; + return 1; + } + } + puts("No more sources could be stored!"); + return 0; +} + +void route_packet(void* msg, int msg_size) { + weather_packet_header_t *header = (weather_packet_header_t*) msg; + if (header->type == WEATHER_DATA) { + weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + if (!update_sources(wdp->header.src, wdp->timestamp)) { + return; + } + } + + if ((100.0 * rand()/(double) RAND_MAX) <= FLOODING_PROB) { + printf("Broadcasting packet..."); + if (cc1100_send_csmaca(0, WEATHER_PROTOCOL_NR, 0, (char*)msg, msg_size)) { + puts("successful!"); + } + else { + puts("failed!"); + } + } +} + diff --git a/projects/WEAtHeR/weather_routing.h b/projects/WEAtHeR/weather_routing.h new file mode 100644 index 000000000..14d050177 --- /dev/null +++ b/projects/WEAtHeR/weather_routing.h @@ -0,0 +1,17 @@ +#ifndef WEATHER_ROUTING_H +#define WEATHER_ROUTING_H + +#include + +#define FLOODING_PROB (100) +#define MAX_SOURCES (10) +#define MAX_INTERVAL (5 * 60) + +typedef struct { + uint8_t id; + time_t timestamp; +} source_timestamp_t; + +void route_packet(void* msg, int msg_size); + +#endif /* WEATHER_ROUTING_H */ From 430bad0d69c687e91b933d9dd9c457b0fd84d184 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 6 Apr 2011 11:09:29 +0200 Subject: [PATCH 175/199] [drivers cc110x] * fixed cc110x driver (some references where broken due to renaming of spi functions from cc1100_* to cc110x_* --- drivers/cc110x/Jamfile | 2 +- drivers/cc110x/arch_cc1100.h | 16 +++++----- drivers/cc110x/cc1100-csmaca-mac.c | 13 ++++---- drivers/cc110x/cc1100.c | 48 +++++++++++++++--------------- drivers/cc110x/cc1100_phy.c | 7 +++-- drivers/cc110x/cc1100_spi.c | 46 ++++++++++++++-------------- drivers/cc110x/cc1100_spi.h | 14 ++++----- 7 files changed, 74 insertions(+), 72 deletions(-) diff --git a/drivers/cc110x/Jamfile b/drivers/cc110x/Jamfile index b96d897d9..528cef8d1 100755 --- a/drivers/cc110x/Jamfile +++ b/drivers/cc110x/Jamfile @@ -31,5 +31,5 @@ HDRS += $(TOP)/drivers/cc110x ; Module cc110x : cc1100.c cc1100-csmaca-mac.c cc1100-defaultSettings.c cc1100_phy.c cc1100_spi.c - : board_cc1100 swtimer protocol_multiplex gpioint ; + : board_cc110x swtimer protocol_multiplex gpioint ; diff --git a/drivers/cc110x/arch_cc1100.h b/drivers/cc110x/arch_cc1100.h index ef61dd61c..7c8b018a5 100644 --- a/drivers/cc110x/arch_cc1100.h +++ b/drivers/cc110x/arch_cc1100.h @@ -38,13 +38,13 @@ and the mailinglist (subscription via web site) #include -uint8_t cc1100_txrx(uint8_t c); +uint8_t cc110x_txrx(uint8_t c); -void cc1100_gdo0_enable(void); -void cc1100_gdo0_disable(void); -void cc1100_gdo2_enable(void); -void cc1100_gdo2_disable(void); -void cc1100_init_interrupts(void); +void cc110x_gdo0_enable(void); +void cc110x_gdo0_disable(void); +void cc110x_gdo2_enable(void); +void cc110x_gdo2_disable(void); +void cc110x_init_interrupts(void); -void cc1100_before_send(void); -void cc1100_after_send(void); +void cc110x_before_send(void); +void cc110x_after_send(void); diff --git a/drivers/cc110x/cc1100-csmaca-mac.c b/drivers/cc110x/cc1100-csmaca-mac.c index fab9610cc..3dc9c3b2f 100644 --- a/drivers/cc110x/cc1100-csmaca-mac.c +++ b/drivers/cc110x/cc1100-csmaca-mac.c @@ -38,7 +38,7 @@ and the mailinglist (subscription via web site) */ #include -//#include +#include #include #include "cc1100.h" @@ -47,6 +47,7 @@ and the mailinglist (subscription via web site) #include "protocol-multiplex.h" #include "hwtimer.h" +#include /*---------------------------------------------------------------------------*/ @@ -106,9 +107,9 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit collisions_per_sec = 0; collision_state = COLLISION_STATE_MEASURE; } else if (collision_state == COLLISION_STATE_MEASURE) { - uint64_t timespan = swtimer_now() - collision_measurement_start; - if (timespan > 1000000) { - collisions_per_sec = (collision_count * 1000000) / (double) timespan; + uint64_t timespan = swtimer_now() - collision_measurement_start; + if (timespan > 1000000) { + collisions_per_sec = (collision_count * 1000000) / (double) timespan; if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) { collision_measurement_start = swtimer_now(); collision_state = COLLISION_STATE_KEEP; @@ -120,8 +121,8 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit } } } else if (collision_state == COLLISION_STATE_KEEP) { - uint64_t timespan = swtimer_now() - collision_measurement_start; - if (timespan > 5000000) { + uint64_t timespan = swtimer_now() - collision_measurement_start; + if (timespan > 5000000) { collision_state = COLLISION_STATE_INITIAL; } } diff --git a/drivers/cc110x/cc1100.c b/drivers/cc110x/cc1100.c index 5b671b3ad..7199694d2 100644 --- a/drivers/cc110x/cc1100.c +++ b/drivers/cc110x/cc1100.c @@ -160,19 +160,19 @@ volatile int wor_hwtimer_id = -1; void cc1100_disable_interrupts(void) { - cc1100_gdo2_disable(); - cc1100_gdo0_disable(); + cc110x_gdo2_disable(); + cc110x_gdo0_disable(); } -void cc1100_gdo0_irq(void) +void cc110x_gdo0_irq(void) { // Air was not free -> Clear CCA flag rflags.CAA = false; // Disable carrier sense detection (GDO0 interrupt) - cc1100_gdo0_disable(); + cc110x_gdo0_disable(); } -void cc1100_gdo2_irq(void) +void cc110x_gdo2_irq(void) { cc1100_phy_rx_handler(); } @@ -251,9 +251,9 @@ bool cc1100_spi_receive_packet(uint8_t *rxBuffer, uint8_t length) void cc1100_set_idle(void) { if (radio_state == RADIO_WOR) { // Wake up the chip from WOR/sleep - cc1100_spi_select(); + cc110x_spi_select(); hwtimer_wait(RTIMER_TICKS(122)); - cc1100_spi_unselect(); + cc110x_spi_unselect(); radio_state = RADIO_IDLE; // XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) hwtimer_wait(FS_CAL_TIME); @@ -292,9 +292,9 @@ static void wakeup_from_wor(void) return; } // Wake up the chip from WOR/sleep - cc1100_spi_select(); + cc110x_spi_select(); hwtimer_wait(RTIMER_TICKS(122)); - cc1100_spi_unselect(); + cc110x_spi_unselect(); radio_state = RADIO_IDLE; // XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms) hwtimer_wait(FS_CAL_TIME); @@ -305,7 +305,7 @@ static void wakeup_from_wor(void) */ void switch_to_wor2(void) { - if (cc1100_get_gdo2()) return; // If incoming packet, then don't go to WOR now + if (cc110x_get_gdo2()) return; // If incoming packet, then don't go to WOR now cc1100_spi_strobe(CC1100_SIDLE); // Put CC1100 to IDLE radio_state = RADIO_IDLE; // Radio state now IDLE cc1100_spi_write_reg(CC1100_MCSM2, @@ -336,7 +336,7 @@ static void hwtimer_switch_to_wor2_wrapper(void* ptr) static void switch_to_wor(void) { // Any incoming packet? - if (cc1100_get_gdo2()) + if (cc110x_get_gdo2()) { // Then don't go to WOR now return; @@ -558,16 +558,16 @@ void cc1100_hwtimer_go_receive_wrapper(void *ptr) static void reset(void) { cc1100_go_idle(); - cc1100_spi_select(); + cc110x_spi_select(); cc1100_spi_strobe(CC1100_SRES); hwtimer_wait(RTIMER_TICKS(10)); } static void power_up_reset(void) { - cc1100_spi_unselect(); - cc1100_spi_cs(); - cc1100_spi_unselect(); + cc110x_spi_unselect(); + cc110x_spi_cs(); + cc110x_spi_unselect(); hwtimer_wait(RESET_WAIT_TIME); reset(); radio_state = RADIO_IDLE; @@ -587,7 +587,7 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size) if (size > PACKET_LENGTH) return; // Disables RX interrupt etc. - cc1100_before_send(); + cc110x_before_send(); // But CC1100 in IDLE mode to flush the FIFO cc1100_spi_strobe(CC1100_SIDLE); @@ -600,7 +600,7 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size) unsigned int cpsr = disableIRQ(); cc1100_spi_strobe(CC1100_STX); // Wait for GDO2 to be set -> sync word transmitted - while (cc1100_get_gdo2() == 0) { + while (cc110x_get_gdo2() == 0) { abort_count++; if (abort_count > CC1100_SYNC_WORD_TX_TIME) { // Abort waiting. CC1100 maybe in wrong mode @@ -611,9 +611,9 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size) } restoreIRQ(cpsr); // Wait for GDO2 to be cleared -> end of packet - while (cc1100_get_gdo2() != 0); + while (cc110x_get_gdo2() != 0); // Experimental - TOF Measurement - cc1100_after_send(); + cc110x_after_send(); } /*-------------