A simple serial shell running on its own thread (stack is statically allocated).
Dependents: FRDM_K64F_IOT lpc1768_blinky
A simple serial shell running on its own thread. The thread is not started until a call to start(). A start() call creates a thread either using static allocation (pre-defined stack size).
Sample Usage
#include "mbed.h"
#include "rtos.h"
#include "Shell.h"
Serial pc(p9,p10);
#define SHELL_STACK_SIZ 1024
// Pre-allocate the shell's stack (on global mem)
unsigned char shellStack[SHELL_STACK_SIZ];
Shell shell(&pc);
// Shell Commands
/**
* \brief Gets the amount of free memory
* \param none
* \return none
**/
static void cmd_mem(Stream * strm, int argc, char * argv[])
{
// In order to get free mem within RTOS
// we need to get the main thread's stack pointer
// and subtract it with the top of the heap
// ------+-------------------+ Last Address of RAM (INITIAL_SP)
// | Scheduler Stack |
// +-------------------+
// | Main Thread Stack |
// | | |
// | v |
// +-------------------+ <- bottom_of_stack/__get_MSP()
// RAM | |
// | Available RAM |
// | |
// +-------------------+ <- top_of_heap
// | ^ |
// | | |
// | Heap |
// +-------------------+ <- __end__ / HEAP_START (linker defined var)
// | ZI |
// +-------------------+
// | ZI: Shell Stack |
// +-------------------+
// | ZI: Idle Stack |
// +-------------------+
// | ZI: Timer Stack |
// +-------------------+
// | RW |
// ------+===================+ First Address of RAM
// | |
// Flash | |
//
uint32_t bottom_of_stack = __get_MSP();
char * top_of_heap = (char *) malloc(sizeof(char));
uint32_t diff = bottom_of_stack - (uint32_t) top_of_heap;
free((void *) top_of_heap);
strm->printf("Available Memory : %d bytes\r\n",
diff);
}
int main() {
// Start the shell
pc.printf("Starting debug shell ...\r\n");
shell.addCommand("mem", cmd_mem);
shell.start(osPriorityNormal, SHELL_STACK_SIZ, shellStack);
while(1) {
wait(0.2);
}
}
Revision 2:3db531afe4fc, committed 2015-04-29
- Comitter:
- vpcola
- Date:
- Wed Apr 29 06:13:20 2015 +0000
- Parent:
- 1:25fa46a375dd
- Commit message:
- Removed unused headers;
Changed in this revision
| Shell.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Shell.cpp Tue Apr 28 16:57:50 2015 +0000
+++ b/Shell.cpp Wed Apr 29 06:13:20 2015 +0000
@@ -11,7 +11,7 @@
#include "Shell.h"
-#include "Utility.h"
+
static char *_strtok(char *str, const char *delim, char **saveptr)
{