diff --git a/projects/test_shell/Jamfile b/projects/test_shell/Jamfile index d4f1e9c00d..f97d6bfe4a 100644 --- a/projects/test_shell/Jamfile +++ b/projects/test_shell/Jamfile @@ -6,6 +6,6 @@ SubDir TOP projects test_shell ; -Module test_shell : test_shell.c : shell posix_io shell_auto_init ps uart0 ; +Module test_shell : test_shell.c : shell posix_io ps uart0 ; UseModule test_shell ; diff --git a/projects/test_shell/test_shell.c b/projects/test_shell/test_shell.c index bfdc480f42..7499c9b85b 100644 --- a/projects/test_shell/test_shell.c +++ b/projects/test_shell/test_shell.c @@ -18,9 +18,6 @@ void print_testend(char* str) { printf("[TEST_END]\n"); } -//extern int uart0_init(); -//extern int uart0_handler_pid; - int shell_readc() { char c = 0; posix_read(uart0_handler_pid, &c, 1); @@ -31,6 +28,12 @@ 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) { //printf("Moin. build on %s %s SVN-Revision: %s\n", kernel_builddate, kernel_buildtime, kernel_svnrevision); printf("test_shell.\n"); @@ -41,10 +44,8 @@ int main(void) { shell_t shell; shell_init(&shell, shell_readc, shell_putchar); - shell_auto_init(&shell); - - shell_register_cmd(&shell, "start_test", print_teststart); - shell_register_cmd(&shell, "end_test", print_testend); + + shell.command_list = shell_commands; shell_run(&shell); diff --git a/sys/include/shell.h b/sys/include/shell.h index 4af18a6e67..daa739b531 100644 --- a/sys/include/shell.h +++ b/sys/include/shell.h @@ -32,10 +32,15 @@ and the mailinglist (subscription via web site) * @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 { - struct hashtable *h; + const shell_command_t *command_list; int (*readchar)(void); void (*put_char)(int); } shell_t; @@ -51,7 +56,7 @@ void shell_init(shell_t *shell, int(*read_char)(void), void (*put_char)(int)); * @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_register_cmd(shell_t *shell, char* name, void (*handler)(char* args)); /** * @brief Endless loop that waits for command and executes handler. diff --git a/sys/shell/Jamfile b/sys/shell/Jamfile index deb2a8065b..195b04fd8c 100644 --- a/sys/shell/Jamfile +++ b/sys/shell/Jamfile @@ -27,7 +27,8 @@ SubDir TOP sys shell ; -Module shell : shell.c : hashtable hash_string ; -Module ps : ps.c ; -Module shell_auto_init : shell_auto_init.c : shell ; +Module shell : shell.c ; +Module shell_commands : shell_commands.c : shell ; + +Module ps : ps.c ; diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 863a2a108a..6a960b47f0 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -46,9 +46,21 @@ 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; + + 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) { char* 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; if (command) { - handler = hashtable_search(shell->h, command); + handler = find_handler(shell->command_list, command); if (handler) { handler(line); } else { @@ -103,13 +115,8 @@ void shell_run(shell_t *shell) { } 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->put_char = put_char; } -void shell_register_cmd(shell_t *shell, char* name, void (*handler)(char* args)) { - hashtable_insert(shell->h, name, handler); -} - /** @} */ diff --git a/sys/shell/shell_auto_init.c b/sys/shell/shell_auto_init.c deleted file mode 100644 index 5cdf802f13..0000000000 --- a/sys/shell/shell_auto_init.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -#ifdef MODULE_PS -#include -#endif - -void shell_auto_init(shell_t *s) { -#ifdef MODULE_PS -shell_register_cmd(s, "ps", _ps_handler); -#endif -} diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c new file mode 100644 index 0000000000..5223597d6c --- /dev/null +++ b/sys/shell/shell_commands.c @@ -0,0 +1,9 @@ +#include + +const shell_command_t _shell_command_list[] = { +#ifdef MODULE_PS + {"ps", ps_handler}, +#endif + {NULL, NULL} +}; + diff --git a/sys/uart0.c b/sys/uart0.c new file mode 100644 index 0000000000..e6ad35bc38 --- /dev/null +++ b/sys/uart0.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +#include + +#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); +}