DS80C400 Silicon Software: Task Scheduler Information
The DS80C400 Silicon Software provides a task scheduler to simplify the implementation of
applications such as Serial-to_ethernet. The implementation is optimized for size and a
small number of tasks. To allow for customization, the task scheduler supports hooks. To
summarize the features:
- Full task support
- Hooks for threads (user can supply save/restore state functions)
- Preemptive
- Priority-based, supports an Idle Task
The tasks are organized as a ring of Task Control Blocks (TCBs). Each TCB has attributes such
as Priority and the Task ID. The following picture shows a configuration with 4
tasks:
A TCB consists of...
- Priority: Priority of this task (8 bits). Minimum priority is 1, maximum is FFh, normal (default) is 80h.
- ID: ID of the task (8 bits). Note that 0 is an invalid task ID.
- Next: Pointer to the next task in the ring.
- Flags: 8 bits indicating the process is runnable (all clear) or waiting for an event
- Bit 0 - Sleeping
- Bit 1 - Waiting for IO
- Bit 2 - Waiting for DHCP established
- Bit 3..7 - Available for user code
- Wakeup Time: Time value (5 bytes) when task should wake up
- State Size: Size of the state buffer
- State Pointer: Storage for SFRs, stack, PC on task swaps
System Timer
Timer 0 runs as the system timer for the silicon software. The reload for timer 0 can be set using
the task library function task_settickreload. The default reload equates to a time of roughly
1 millisecond on a 14.7456 MHz crystal. This interval is referred to as a timer tick. Timer 0 runs
as a high priority interrupt.
Task Scheduler
Every four timer ticks (or if the need_sched bit is set), the task scheduler is run if:
- No low-priority interrupts are in progress
- The application is currently in a critical section (wos_crit_count != 0)
If the task scheduler cannot run due to either of these exceptions, the need_sched bit is set
so future timer ticks will try to run the scheduler. The task scheduler is also run whenever a task
is suspended or put to sleep.
Context Switches
On a context switch, the following are preserved in the TSB:
- Directs 00h - 68h, excluding 20h
- Stack and Stack Pointer
- Program Counter
- Interrupt Enable (ie)
- Data pointer 0
- Data pointer 1
- DPS
- B
- PSW
- ACC
Critical Sections
Critical sections are intended to protect short tasks that must not be interrupted, such as using
the math accelerator unit. Do not create critical sections lasting longer than 100-200us. Doing so
may cause unpredictable behavior.