mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
* misc shell improvements
This commit is contained in:
parent
8b91cd790b
commit
5a4524539d
@ -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;
|
||||
|
@ -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 ;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <thread.h>
|
||||
#include <kernel.h>
|
||||
#include <hwtimer.h>
|
||||
#include <ps.h>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user