// shell.c #include <912d60.h> #include #include #include #include #include "kernel.h" #include "semlib.h" // FUNCTION PROTOTYPES void shellcmd_help(char *argv1); void shellcmd_tcb(void); void shellcmd_rcb(void); void shellcmd_ticks(void); void shellcmd_start_task(unsigned char id); /*void shellcmd_stop_task(unsigned char id); void shellcmd_set_task_priority(unsigned char id, unsigned char priority); void shellcmd_quit_shell(void);*/ // GLOBAL VARIABLES extern unsigned long int system_tick; extern unsigned int current; // current task id number // LOCAL GLOBAL VARIABLES (context is this file only) extern char error_msg[6][25]; void shell(void) { // LOCAL CONSTANTS #define cmd_size (32+1) // LOCAL ENUMERATIONS enum command_type { help = 1, tcb, rcb, ticks, start, stop, priority, quit }; // LOCAL VARIABLES char command[cmd_size], i, j, **argv, *cursor1, *cursor2; int cmd_length, argc; enum command_type cmd; // INITIALIZE SHELL sem_get(COM1); // get comm port 1 semaphore INTR_ON(); // enable interrupts // SHELL COMMAND LINE INTERPRETER while (1) { i = 0; cursor1 = command; cursor2 = command; // put a PROMPT putchar('>'); putchar('>'); putchar(' '); // GET AND ECHO THE COMMAND on the console while (((command[i]=getchar()) != 0xD) && (i -- required arguments"); puts("[] -- optional arguments\n"); puts("help [cmd] -- help on a specific command"); puts("tcb [task_id] -- prints task control block"); puts("rcb [task_id] -- prints resource control block"); puts("ticks -- shows system tick"); puts("start -- start a task"); puts("stop -- stop a task"); puts("priority -- change prio"); puts("quit -- quit the shell (carefull!)"); putchar('\n'); } else if (argc == 2) shellcmd_help(argv[1]); break; case tcb: if (argc == 1) shellcmd_tcb(); else if (argc > 1) puts(error_msg[0]); break; case rcb: puts(error_msg[0]); break; case ticks: if (argc > 1) puts(error_msg[1]); else shellcmd_ticks(); break; case start: if ((argc != 2) || (!isdigit(*argv[1]))) puts(error_msg[1]); else shellcmd_start_task(atoi(argv[1])); break; case stop: puts(error_msg[0]); break; case priority: puts(error_msg[0]); break; case quit: puts(error_msg[0]); break; default: break; }} // end switch/if // free the argc and argv array memory for (i=0; i