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@3:6a35fb789679, 2015-02-04 (annotated)
- Committer:
- jont
- Date:
- Wed Feb 04 21:07:52 2015 +0000
- Revision:
- 3:6a35fb789679
- Parent:
- 2:1a5802e3eb30
- Child:
- 4:107d2d3294da
lets try removing the direct uart code and use getch, it may hang
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jont | 0:87e65dabdb95 | 1 | /* Copyright (c) <year> <copyright holders>, MIT License |
jont | 0:87e65dabdb95 | 2 | * |
jont | 0:87e65dabdb95 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
jont | 0:87e65dabdb95 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
jont | 0:87e65dabdb95 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
jont | 0:87e65dabdb95 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
jont | 0:87e65dabdb95 | 7 | * furnished to do so, subject to the following conditions: |
jont | 0:87e65dabdb95 | 8 | * |
jont | 0:87e65dabdb95 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
jont | 0:87e65dabdb95 | 10 | * substantial portions of the Software. |
jont | 0:87e65dabdb95 | 11 | * |
jont | 0:87e65dabdb95 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
jont | 0:87e65dabdb95 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
jont | 0:87e65dabdb95 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
jont | 0:87e65dabdb95 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jont | 0:87e65dabdb95 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
jont | 0:87e65dabdb95 | 17 | */ |
jont | 0:87e65dabdb95 | 18 | #include "mbed.h" |
jont | 0:87e65dabdb95 | 19 | #include "shell.h" |
jont | 0:87e65dabdb95 | 20 | #include "mon.h" |
jont | 0:87e65dabdb95 | 21 | #include "sio.h" |
jont | 0:87e65dabdb95 | 22 | DigitalOut myled(LED1); |
jont | 0:87e65dabdb95 | 23 | DigitalOut myled3(LED3); |
jont | 0:87e65dabdb95 | 24 | |
jont | 0:87e65dabdb95 | 25 | //Define the A2D convertor Pins |
jont | 3:6a35fb789679 | 26 | #ifdef TARGET_LPC1768 |
jont | 0:87e65dabdb95 | 27 | AnalogIn a2d1(p15); |
jont | 0:87e65dabdb95 | 28 | AnalogIn a2d2(p16); |
jont | 0:87e65dabdb95 | 29 | AnalogIn a2d3(p17); |
jont | 0:87e65dabdb95 | 30 | AnalogIn a2d4(p18); |
jont | 0:87e65dabdb95 | 31 | AnalogIn a2d5(p19); |
jont | 0:87e65dabdb95 | 32 | AnalogIn a2d6(p20); |
jont | 3:6a35fb789679 | 33 | #endif |
jont | 3:6a35fb789679 | 34 | #ifdef TARGET_KL25Z |
jont | 3:6a35fb789679 | 35 | |
jont | 3:6a35fb789679 | 36 | AnalogIn a2d1(PTB0); |
jont | 3:6a35fb789679 | 37 | AnalogIn a2d2(PTB1); |
jont | 3:6a35fb789679 | 38 | AnalogIn a2d3(PTB2); |
jont | 3:6a35fb789679 | 39 | AnalogIn a2d4(PTB3); |
jont | 3:6a35fb789679 | 40 | AnalogIn a2d5(PTC1); |
jont | 3:6a35fb789679 | 41 | AnalogIn a2d6(PTC2); |
jont | 3:6a35fb789679 | 42 | |
jont | 3:6a35fb789679 | 43 | |
jont | 3:6a35fb789679 | 44 | #endif |
jont | 0:87e65dabdb95 | 45 | |
jont | 0:87e65dabdb95 | 46 | int main() { |
jont | 0:87e65dabdb95 | 47 | setbuf(stdout, NULL); |
jont | 0:87e65dabdb95 | 48 | // no buffering for this filehandle, this stop the weird |
jont | 0:87e65dabdb95 | 49 | //behaviour with things not being dfiplaye untill a character was received. |
jont | 0:87e65dabdb95 | 50 | printf("Welcome to jont@ninelocks.com debug helper\n"); |
jont | 0:87e65dabdb95 | 51 | serialInit(); //Init our flow control mechanism |
jont | 0:87e65dabdb95 | 52 | ShellInit(); //Init our command shell system |
jont | 0:87e65dabdb95 | 53 | |
jont | 0:87e65dabdb95 | 54 | |
jont | 0:87e65dabdb95 | 55 | while(1) { |
jont | 0:87e65dabdb95 | 56 | myled = 1; |
jont | 2:1a5802e3eb30 | 57 | wait(0.5); |
jont | 0:87e65dabdb95 | 58 | myled = 0; |
jont | 2:1a5802e3eb30 | 59 | wait(0.5); |
jont | 0:87e65dabdb95 | 60 | ShellTC(); //give our monitor prog chance to do something |
jont | 0:87e65dabdb95 | 61 | //brain dead pic compiler wont let us do this from an IRQ... |
jont | 0:87e65dabdb95 | 62 | } |
jont | 0:87e65dabdb95 | 63 | |
jont | 0:87e65dabdb95 | 64 | } |