1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge branch 'master' of ssh://ukleos.des-mesh.net/home/git/ukleos

Conflicts:
	sys/Jamfile
This commit is contained in:
Oliver Hahm 2010-10-04 15:57:40 +02:00
commit c8315c4270
28 changed files with 215 additions and 78 deletions

View File

@ -60,6 +60,8 @@ LOCATE on $(TARGET:S=.hex) = bin ;
Doc doc ; # build the documentation Doc doc ; # build the documentation
Flash flash : $(TARGET:S=.hex) ; Flash flash : $(TARGET:S=.hex) ;
Reset reset ; Reset reset ;
Terminal term ;
Test test : all ;
Debug debug : $(TARGET) ; Debug debug : $(TARGET) ;
ListModules listmodules ; ListModules listmodules ;

View File

@ -39,6 +39,8 @@ SUFFIX ?= "" ; # must be at least "" !!!
TARGET = "$(BOARD)-$(PROJECT)$(SUFFIX)$(SUFEXE)" ; # main target binary TARGET = "$(BOARD)-$(PROJECT)$(SUFFIX)$(SUFEXE)" ; # main target binary
OPENOCD_IF ?= olimex-jtag-tiny-a ; OPENOCD_IF ?= olimex-jtag-tiny-a ;
TERMINAL ?= board/msba2/tools/bin/pseudoterm ;
if $(NT) || $(OS) = CYGWIN { if $(NT) || $(OS) = CYGWIN {
PORT = $(PORT:E=1) ; PORT = $(PORT:E=1) ;
} else { } else {

View File

@ -172,12 +172,30 @@ actions Flash
$(FLASHER) $(FLASHFLAGS) $(>) $(FLASHER) $(FLASHFLAGS) $(>)
} }
#
# Run all tests for active project
rule Test
{
Depends $(<) : $(>) ;
}
actions Test
{
for tst in projects/$(PROJECT)/tests/*; do $tst; done
}
# Reset connected sensor node # Reset connected sensor node
actions Reset actions Reset
{ {
$(RESET) > /dev/null 2>&1 $(RESET) > /dev/null 2>&1
} }
# run a terminal
#
actions Terminal
{
$(TERMINAL) $(TERMOPTS) $(PORT)
}
# #
# Run debug server # Run debug server
rule Debug rule Debug

View File

@ -29,5 +29,5 @@ CPU = lpc2387 ;
HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ;
FLASHER = $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; FLASHER ?= $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ;
FLASHFLAGS = --basedir $(TOP)/board/msba2/tools --id "MSB-A2" --ports "$(PORT)" ; FLASHFLAGS ?= --basedir $(TOP)/board/msba2/tools --id "MSB-A2" --ports "$(PORT)" ;

View File

@ -25,7 +25,7 @@ and the mailinglist (subscription via web site)
*******************************************************************************/ *******************************************************************************/
/** /**
* @ingroup pttu * @ingroup msba2
* @{ * @{
*/ */

View File

@ -3,4 +3,5 @@ SubDir TOP board msba2 drivers ;
Module board_cc1100 : msba2-cc1100.c ; Module board_cc1100 : msba2-cc1100.c ;
Module board_hal : msba2-hal.c ; Module board_hal : msba2-hal.c ;
Module board_ltc4150 : msba2-ltc4150.c : gpioint ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ;
Module board_common : msba2-uart0.c msba2-uart0_thread.c : ringbuffer ; Module board_common : msba2-uart0.c : ringbuffer ;
Module board_uart : msba2-uart0_thread.c : chardev_thread ringbuffer ;

View File

@ -36,9 +36,7 @@ and the mailinglist (subscription via web site)
#include "lpc23xx.h" #include "lpc23xx.h"
#include "VIC.h" #include "VIC.h"
#include <msg.h> #include <board_uart0.h>
#include <ringbuffer.h>
#include "uart0.h"
/** /**
* @file * @file
@ -67,9 +65,6 @@ static volatile unsigned int fifo = 0;
static volatile toprint* actual = NULL; static volatile toprint* actual = NULL;
int uart0_handler_pid = 0;
extern ringbuffer uart0_ringbuffer;
static inline void enqueue(void) { static inline void enqueue(void) {
queue_items++; queue_items++;
queue_tail++; queue_tail++;
@ -109,14 +104,6 @@ int uart_active(void){
return (running || fifo); return (running || fifo);
} }
static void notify_handler() {
if (uart0_handler_pid) {
msg m;
m.type = 0;
msg_send_int(&m, uart0_handler_pid);
}
}
void stdio_flush(void) void stdio_flush(void)
{ {
U0IER &= ~BIT1; // disable THRE interrupt U0IER &= ~BIT1; // disable THRE interrupt
@ -142,14 +129,16 @@ void UART0_IRQHandler(void)
case UIIR_CTI_INT: // Character Timeout Indicator case UIIR_CTI_INT: // Character Timeout Indicator
case UIIR_RDA_INT: // Receive Data Available case UIIR_RDA_INT: // Receive Data Available
do { #ifdef MODULE_UART0
int c = U0RBR; if (uart0_handler_pid) {
rb_add_element(&uart0_ringbuffer, c); do {
} while (U0LSR & ULSR_RDR); int c = U0RBR;
uart0_handle_incoming(c);
notify_handler(); } while (U0LSR & ULSR_RDR);
uart0_notify_thread();
}
#endif
break; break;
default: default:
U0LSR; U0LSR;
U0RBR; U0RBR;

View File

@ -12,6 +12,7 @@
#include <stddef.h> #include <stddef.h>
void* _malloc(size_t size); void* _malloc(size_t size);
void* _realloc(void *ptr, size_t size);
void _free (void* ptr); void _free (void* ptr);
/** @} */ /** @} */

View File

@ -13,6 +13,8 @@
* @author Kaspar Schleiser <kaspar@schleiser.de> * @author Kaspar Schleiser <kaspar@schleiser.de>
*/ */
#include <kernel.h>
/** /**
* @brief Creates a new thread. * @brief Creates a new thread.

View File

@ -35,6 +35,13 @@ void *_malloc(size_t size) {
} }
} }
void *_realloc(void *ptr, size_t size) {
void* newptr = _malloc(size);
memcpy(newptr, ptr, size);
free(ptr);
return newptr;
}
void _free(void* ptr) { void _free(void* ptr) {
DEBUG("_free(): block at 0x%X lost.\n", (unsigned int)ptr); DEBUG("_free(): block at 0x%X lost.\n", (unsigned int)ptr);
} }

View File

@ -4,6 +4,7 @@
#include "oneway_malloc.h" #include "oneway_malloc.h"
#define malloc _malloc #define malloc _malloc
#define realloc _realloc
#define free _free #define free _free
#endif /* __MALLOC_H */ #endif /* __MALLOC_H */

View File

@ -2,7 +2,7 @@
set timeout 5 set timeout 5
spawn board/msba2/tools/bin/pseudoterm $env(PORT) spawn pseudoterm $env(PORT)
exec jam reset exec jam reset

5
projects/hello-world/tests/hello-world.py Normal file → Executable file
View File

@ -1,8 +1,11 @@
#!/usr/bin/python
import pexpect import pexpect
import os import os
import subprocess import subprocess
child = pexpect.spawn ("board/msba2/tools/bin/pseudoterm %s" % os.environ["PORT"]) # testing hello world
child = pexpect.spawn ("pseudoterm %s" % os.environ["PORT"])
null = open('/dev/null', 'wb') null = open('/dev/null', 'wb')
subprocess.call(['jam', 'reset'], stdout=null) subprocess.call(['jam', 'reset'], stdout=null)

View File

@ -6,6 +6,6 @@
SubDir TOP projects test_shell ; SubDir TOP projects test_shell ;
Module test_shell : test_shell.c : shell posix_io ; Module test_shell : test_shell.c : shell posix_io ps uart0 ;
UseModule test_shell ; UseModule test_shell ;

View File

@ -6,9 +6,9 @@
#include <string.h> #include <string.h>
#include <malloc.h> #include <malloc.h>
#include <uart0.h>
#include <posix_io.h> #include <posix_io.h>
#include <shell.h> #include <shell.h>
#include <board_uart0.h>
void print_teststart(char* str) { void print_teststart(char* str) {
printf("[TEST_START]\n"); printf("[TEST_START]\n");
@ -18,28 +18,34 @@ void print_testend(char* str) {
printf("[TEST_END]\n"); printf("[TEST_END]\n");
} }
//extern int uart0_init();
//extern int uart0_handler_pid;
int shell_readc() { int shell_readc() {
char c = 0; char c = 0;
posix_read(uart0_handler_pid, &c, 1); posix_read(uart0_handler_pid, &c, 1);
return c; return c;
} }
void shell_putchar(int c) {
putchar(c);
}
const shell_command_t shell_commands[] = {
{"start_test", print_teststart},
{"end_test", print_testend},
{NULL, NULL}
};
int main(void) { int main(void) {
//printf("Moin. build on %s %s SVN-Revision: %s\n", kernel_builddate, kernel_buildtime, kernel_svnrevision); //printf("Moin. build on %s %s SVN-Revision: %s\n", kernel_builddate, kernel_buildtime, kernel_svnrevision);
printf("test_shell.\n"); printf("test_shell.\n");
uart0_init(); board_uart0_init();
posix_open(uart0_handler_pid, 0); posix_open(uart0_handler_pid, 0);
shell_t shell; shell_t shell;
shell_init(&shell, shell_readc); shell_init(&shell, shell_readc, shell_putchar);
shell_register_cmd(&shell, "start_test", print_teststart); shell.command_list = shell_commands;
shell_register_cmd(&shell, "end_test", print_testend);
shell_run(&shell); shell_run(&shell);

View File

@ -2,7 +2,7 @@
set timeout 5 set timeout 5
spawn board/msba2/tools/bin/pseudoterm $env(PORT) spawn pseudoterm $env(PORT)
expect { expect {
">$" {} ">$" {}

View File

@ -2,7 +2,7 @@
set timeout 1 set timeout 1
spawn board/msba2/tools/bin/pseudoterm $env(PORT) spawn pseudoterm $env(PORT)
sleep 1 sleep 1

View File

@ -1,8 +1,8 @@
#!/usr/bin/expect #!/usr/bin/expect
set timeout 1 set timeout 2
spawn board/msba2/tools/bin/pseudoterm $env(PORT) spawn pseudoterm $env(PORT)
sleep 1 sleep 1
@ -13,7 +13,7 @@ expect {
send "some_definately_unknown_command\n" send "some_definately_unknown_command\n"
expect { expect {
"shell: command not found." {} "shell: command "some_definately_unknown_command" not found." {}
timeout { exit 1 } timeout { exit 1 }
} }

View File

@ -29,10 +29,17 @@ SubDir TOP sys ;
Module swtimer : swtimer.c : hwtimer ; Module swtimer : swtimer.c : hwtimer ;
Module posix_io : posix_io.c ; Module posix_io : posix_io.c ;
<<<<<<< HEAD
Module shell : shell.c : hashtable hash_string ; Module shell : shell.c : hashtable hash_string ;
Module ps : ps.c ; Module ps : ps.c ;
=======
>>>>>>> 355988f8cfa6d2d86fbdb7993fa6823943ca23c6
Module auto_init : auto_init.c ; Module auto_init : auto_init.c ;
Module chardev_thread : chardev_thread.c : ringbuffer ;
Module uart0 : uart0.c : ringbuffer chardev_thread ;
SubInclude TOP sys net ; SubInclude TOP sys net ;
SubInclude TOP sys lib ; SubInclude TOP sys lib ;
SubInclude TOP sys shell ;

View File

@ -1,36 +1,22 @@
#include <thread.h> #include <thread.h>
#include <kernel.h> #include <kernel.h>
#include <msg.h> #include <msg.h>
#include <board.h>
#include <ringbuffer.h> #include <ringbuffer.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <irq.h> #include <irq.h>
#include <posix_io.h> #include <posix_io.h>
#include "uart0.h"
//#define ENABLE_DEBUG //#define ENABLE_DEBUG
#include <debug.h> #include <debug.h>
static char buffer[UART0_BUFSIZE];
ringbuffer uart0_ringbuffer;
static void uart0_loop();
void 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");
uart0_handler_pid = pid;
puts("uart0_init() [OK]");
}
static int min(int a, int b) { static int min(int a, int b) {
if (b>a) return a; if (b>a) return a;
else return b; else return b;
} }
static void uart0_loop() { void chardev_loop(ringbuffer *rb) {
msg m; msg m;
int pid = thread_getpid(); int pid = thread_getpid();
@ -80,11 +66,11 @@ static void uart0_loop() {
} }
} }
if (uart0_ringbuffer.avail && (r != NULL)) { if (rb->avail && (r != NULL)) {
int state = disableIRQ(); int state = disableIRQ();
int nbytes = min(r->nbytes, uart0_ringbuffer.avail); int nbytes = min(r->nbytes, rb->avail);
DEBUG("uart0_thread: sending %i bytes to pid %i\n", nbytes, reader_pid); DEBUG("uart0_thread: sending %i bytes to pid %i\n", nbytes, reader_pid);
rb_get_elements(&uart0_ringbuffer, r->buffer, nbytes); rb_get_elements(rb, r->buffer, nbytes);
r->nbytes = nbytes; r->nbytes = nbytes;
m.sender_pid = reader_pid; m.sender_pid = reader_pid;

10
sys/include/board_uart0.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __BOARD_UART0_H
#define __BOARD_UART0_H
extern int uart0_handler_pid;
void board_uart0_init();
void uart0_handle_incoming(int c);
void uart0_notify_thread();
#endif /* __BOARD_UART0_H */

View File

@ -0,0 +1,8 @@
#ifndef __CHARDEV_THREAD_H
#define __CHARDEV_THREAD_H
#include <ringbuffer.h>
void chardev_loop(ringbuffer *rb);
#endif /* __CHARDEV_THREAD_H */

View File

@ -24,25 +24,31 @@ and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/ *******************************************************************************/
#ifndef __SIMPLE_SHELL_H #ifndef __SHELL_H
#define __SIMPLE_SHELL_H #define __SHELL_H
/** /**
* @defgroup shell Simple Shell Interpreter * @defgroup shell Simple Shell Interpreter
* @ingroup feuerware * @ingroup feuerware
*/ */
#include "hashtable.h" //#include "hashtable.h"
typedef struct shell_commant_t {
char* name;
void (*handler)(char*);
} shell_command_t;
typedef struct shell_t { typedef struct shell_t {
struct hashtable *h; const shell_command_t *command_list;
int (*readchar)(void); int (*readchar)(void);
void (*put_char)(int);
} shell_t; } shell_t;
/** /**
* @brief Initialize a shell object * @brief Initialize a shell object
*/ */
void shell_init(shell_t *shell, int(*readchar)(void)); void shell_init(shell_t *shell, int(*read_char)(void), void (*put_char)(int));
/** /**
* @brief Register a new command handler for a shell. * @brief Register a new command handler for a shell.
@ -50,11 +56,14 @@ void shell_init(shell_t *shell, int(*readchar)(void));
* @param name Name of the command to register. * @param name Name of the command to register.
* @param handler Function pointer to handler that takes the complete command line as parameter. * @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_register_cmd(shell_t *shell, char* name, void (*handler)(char* args));
/** /**
* @brief Endless loop that waits for command and executes handler. * @brief Endless loop that waits for command and executes handler.
*/ */
void shell_run(shell_t *shell); void shell_run(shell_t *shell);
#endif /* __SIMPLE_SHELL_H */
void shell_auto_init(shell_t *shell);
#endif /* __SHELL_H */

34
sys/shell/Jamfile Normal file
View File

@ -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$
SubDir TOP sys shell ;
Module shell : shell.c ;
Module shell_commands : shell_commands.c : shell ;
Module ps : ps.c ;

View File

@ -46,9 +46,21 @@ and the mailinglist (subscription via web site)
#include <stdio.h> #include <stdio.h>
#include <malloc.h> #include <malloc.h>
#include <stdlib.h> #include <stdlib.h>
#include <hash_string.h>
#include <shell.h> #include <shell.h>
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 {
command_list++;
}
}
return NULL;
}
static void handle_input_line(shell_t *shell, char* line) { static void handle_input_line(shell_t *shell, char* line) {
char* saveptr; char* saveptr;
char* command = strtok_r(line, " ", &saveptr); char* command = strtok_r(line, " ", &saveptr);
@ -56,7 +68,7 @@ static void handle_input_line(shell_t *shell, char* line) {
void (*handler)(char*) = NULL; void (*handler)(char*) = NULL;
if (command) { if (command) {
handler = hashtable_search(shell->h, command); handler = find_handler(shell->command_list, command);
if (handler) { if (handler) {
handler(line); handler(line);
} else { } else {
@ -77,8 +89,7 @@ int readline(shell_t *shell, char* buf, int size) {
} }
c = shell->readchar(); c = shell->readchar();
shell->put_char(c);
write(STDOUT_FILENO, &c, 1);
if (c == 13) continue; if (c == 13) continue;
@ -95,7 +106,7 @@ void shell_run(shell_t *shell) {
char line_buf[255]; char line_buf[255];
while(1) { while(1) {
write(STDOUT_FILENO, ">", 1); shell->put_char('>');
int res = readline(shell, line_buf, sizeof(line_buf)); int res = readline(shell, line_buf, sizeof(line_buf));
if (! res ) { if (! res ) {
handle_input_line(shell, strdup(line_buf)); handle_input_line(shell, strdup(line_buf));
@ -103,13 +114,9 @@ void shell_run(shell_t *shell) {
} }
} }
void shell_init(shell_t *shell, int(*readchar)(void)) { void shell_init(shell_t *shell, int(*readchar)(void), void(*put_char)(int)) {
shell->h = create_hashtable(16, (unsigned int (*)(void*)) hash_string, (int (*) (void*,void*)) cmp_string);
shell->readchar = readchar; shell->readchar = readchar;
} shell->put_char = put_char;
void shell_register_cmd(shell_t *shell, char* name, void (*handler)(char* args)) {
hashtable_insert(shell->h, name, handler);
} }
/** @} */ /** @} */

View File

@ -0,0 +1,9 @@
#include <shell.h>
const shell_command_t _shell_command_list[] = {
#ifdef MODULE_PS
{"ps", ps_handler},
#endif
{NULL, NULL}
};

35
sys/uart0.c Normal file
View File

@ -0,0 +1,35 @@
#include <chardev_thread.h>
#include <ringbuffer.h>
#include <stdio.h>
#include <thread.h>
#include <msg.h>
#include <board_uart0.h>
#define UART0_BUFSIZE 32
ringbuffer uart0_ringbuffer;
int uart0_handler_pid;
static char buffer[UART0_BUFSIZE];
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");
uart0_handler_pid = pid;
puts("uart0_init() [OK]");
}
void uart0_handle_incoming(int c) {
rb_add_element(&uart0_ringbuffer, c);
}
void uart0_notify_thread() {
msg m;
m.type = 0;
msg_send_int(&m, uart0_handler_pid);
}