I'm having problems figuring out my tasks and what
the OS is doing.
There are three solutions, in increasing complexity:
- Show what task is running on the LED's
- Change the debugging state and dump the task state somewhere in
your program
- Use the second serial port, port1, to monitor tasks
1. Show what task is running
on the LED's
The file ucos.h defines the variable "extern BOOLEAN OSShowTasksOnLeds".
If you set this variable to a non zero value, the LED's will reflect
the current task number in binary format. You then convert the binary
number shown on LED's to the proper task number. For those using Windows,
the Windows calculator can do binary conversions in scientific mode.
2. Change the debugging state
and dump the task state somewhere in your program
All of the functions in this section require that you define some constants
in ../nburn/include/predef.h. The two constants are: UCOS_TASKLIST and
UCOS_STACKCHECK.
IMPORTANT!!!!!!!!
Any time you make a change in predef.h, you MUST rebuild the system
library AND
your project.
To rebuild the system library:
- Type cd /nburn/system (or wherever you installed the
system files)
- Type make clean
- Type make
To rebuild your project:
- Go to your project directory
- Type make clean
- Type make
Now that the system library and your project have been rebuilt, each
of the following functions will dump information to the main serial
port on the CFV2-40 (port 0, the DB-9 connector):
void OSDumpTasks( void )
This function requires UCOS_STACKCHECK
Example Report:
Prio State Ticks Call Stack
63 |Ready |forever |at: 0200653a
50 |Running
40 |Timer | 433 |020067ba->0200a114-><END>
39 |Fifo | 3
|02007446->02002e64-><END>
38 |Fifo |forever |02007446->02005644-><END>
45 |Semaphore|forever |02006c3c->020097f4->02008442-><END>
What does this report mean?
- The Prio column is the task number or task priority. The higher
the number the lower the priority.
- The second column is the current state of the task.
In this example:
Task 63 is the idle task and it is ready to run but not currently running;
it is stopped at address 0x200653a. Using the adder2line function described
on page 2 we determine that task 63 is stopped at: ucos.c line 190,
the OSTaskIdle( ) function.
Task 50 (user) is the currently running function and that is all we
can tell about the currently running task.
Task 40 (TCP_PRIO) is waiting at a timer. It has 433 ticks before it
will wake up.
The task is stopped at 020067ba (ucos.c line 322), in function: OSTimeDly(WORD
ticks) and this was called from 0200a114 (tcp.cpp line 1371).
Task 38 (ETHER_SEND_PRIO) is waiting for a fifo with 3 time ticks left
before it times out. The task is stopped at 02007446 (ucos.c line 886
OSFifoPend) and it was called from 02005644 (ethernet.cpp line 870).
Task 45 (HTTP_PRIO) is waiting forever for a semaphore. The task is
stopped at 02006c3c (ucos.c line 541 OSSemPend), was called from 020097f4
(tcp.cpp line 947 accept), which was called from 02008442 (http.cpp
line 320).
void OSDumpTCBStacks(
void )
This function requires UCOS_STACKCHECK
Example Report:
uC/OS Stacks
Prio StackPtr Stack Bottom Free Now Minimum Free
63 | 0x2046980 | 0x20449cc | 2029 | 2029
50 | 0x2044444 | 0x20426a0 | 1897 | 1278
40 | 0x2029550 | 0x20275d2 | 2015 | 2015
39 | 0x202012c | 0x201e1d8 | 2005 | 2002
38 | 0x2023c3c | 0x2021cca | 2012 | 2012
45 | 0x2025bf0 | 0x2023d08 | 1978 | 1978
This shows the task, it's current stack position, and the minimum free
space on the stack.
If this number EVER reads 0 you have had a stack overflow and need to
make your stack bigger.
void ShowTaskList(void)
This function requires UCOS_TASKLIST. The value t =
Example report:
at t= 226 Switched to Task 39
at t= 226 Switched to Task 50
at t= 23A Switched to Task 39
at t= 23A Switched to Task 50
at t= 24E Switched to Task 39
at t= 24E Switched to Task 50
at t= 262 Switched to Task 39
at t= 262 Switched to Task 50
at t= 276 Switched to Task 39
at t= 276 Switched to Task 50
at t= 28A Switched to Task 39
at t= 28A Switched to Task 50
at t= 29E Switched to Task 39
at t= 29E Switched to Task 50
at t= 2B2 Switched to Task 39
at t= 2B2 Switched to Task 50
at t= 2C6 Switched to Task 39
at t= 2C6 Switched to Task 50
at t= 2DA Switched to Task 39
at t= 2DA Switched to Task 50
at t= 2EE Switched to Task 39
at t= 2EE Switched to Task 50
at t= 302 Switched to Task 39
at t= 302 Switched to Task 50
at t= 316 Switched to Task 39
at t= 316 Switched to Task 50
at t= 32A Switched to Task 39
at t= 32A Switched to Task 50
at t= 33E Switched to Task 39
at t= 33E Switched to Task 50
at t= 352 Switched to Task 39
at t= 352 Switched to Task 50
3. Use the second serial port,
port1, to monitor tasks
This method used the files dbgmon.h and dbgmon.c, located in \nburn\include
and \nburn\system:
- Put dbgmon.c and dbgmon.h in your project directory
- Include dbgmon.c in your makefile (e.g. CSRCS=dbgmon.c)
- Add the following lines to your program so it gets called at startup:
/* Open the debug routine on port 1, the second serial port */
OpenDBGSerial(1, 115200). The first parameter is the port number,
and the second parameter is the baud rate.
Now you may send commands to the second serial port for debugging.
The current version supports two commands:
? - Tell me where the program is currently executing.
Example Report:
Trap occurred
Vector=41FMT =00 SR=2000 FS=00
Faulted PC=FFC001B6
D0: 00000001 00000002 00000000 00000000 0202044C 00000001 00000000 00000001
A0: 00000000 0202044C 0202044C 0202043C 00000001 00000000 02044EB8 02044E90
This shows that the system was running at 0xFFC001B6 when it was interrupted.
You may try running addr2line to determine what module it was in, but
in this example that did not work. Address above FFC00000 are a special
case. The code above FFC00000 is stored in the monitor flash, and not
the program file. The only functions that use this code are the simple
stdio getchar and putchar functions. In this case it is getchar, so
when we ran the example query the main program was waiting for a character.
U - Dump the uC/OS task state.
Example Report:
uC/OS Tasks
Prio State Ticks Call Stack
3F |Ready |forever |at: 020022AE
32 |Running | |at:
FFC001B6
28 |Timer |0223 |020024CA->0200A308-><END>
27 |Fifo |0011 |02003100->02004E70-><END>
26 |Fifo |forever |02003100->02007650-><END>
2D |Semaphore|forever |02002900->020099E8->02008636-><END>
This display is identical to the display shown in the OSDumpTasks(
) example, WITH ONE BIG CHANGE - The task priority and timer functions
are in hexadecimal.
|