When debugging code it can be handy to examine/alter variables and to check the state of input lines. So your main program can run and you have access to alter variables and run functions from a terminal. In this sample the main program is just a loop that flashes an LED. In that loop a periodic call is made to ShellTC which handles any commands from the serial terminal. The code is a bit quirky(it was originally written for a very resource limited device) but it works well enough to be useful, hence its published. More details in the main.cpp
.
main.cpp
- Committer:
- jont
- Date:
- 2012-10-25
- Revision:
- 0:87e65dabdb95
- Child:
- 2:1a5802e3eb30
File content as of revision 0:87e65dabdb95:
/* Copyright (c) <year> <copyright holders>, MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "mbed.h" #include "shell.h" #include "mon.h" #include "sio.h" DigitalOut myled(LED1); DigitalOut myled3(LED3); //Define the A2D convertor Pins AnalogIn a2d1(p15); AnalogIn a2d2(p16); AnalogIn a2d3(p17); AnalogIn a2d4(p18); AnalogIn a2d5(p19); AnalogIn a2d6(p20); int main() { setbuf(stdout, NULL); // no buffering for this filehandle, this stop the weird //behaviour with things not being dfiplaye untill a character was received. printf("Welcome to jont@ninelocks.com debug helper\n"); serialInit(); //Init our flow control mechanism ShellInit(); //Init our command shell system while(1) { myled = 1; wait(0.2); myled = 0; wait(0.2); ShellTC(); //give our monitor prog chance to do something //brain dead pic compiler wont let us do this from an IRQ... } }