Data Structures | |
| struct | thread_s |
| Thread structure definition. More... | |
Defines | |
| #define | MAX_THREADS 10 |
| Maximum number of allowed threads. | |
| #define | IDLE_STACK_SIZE 256 |
| Size of stack for initial/idle thread. | |
| #define | START_STACK_SIZE 128 |
| Size of stack for start thread. | |
| #define | MSECS_PER_SLEEP_TICK 31 |
| The msec period of a single prescaled sleep clock tick. | |
| #define | SLEEP_TICK_OVERFLOW 4 |
| MSECS_PER_SLEEP_TICK should really be 31.25 Divide your number by SLEEP_TICK_OVERFLOW and add it to the result for more precise math. | |
| #define | MSECS_MAX_SLEEP 8000 |
| The msec period of the maximum sleep time (256 * 32). | |
| #define | STACK_MIN MIN_STACK_SIZE |
| Minimum stack size. | |
| #define | STACK_SMALL STACK_MIN * 2 |
| Small stack size. | |
| #define | STACK_MEDIUM STACK_MIN * 3 |
| Medium stack size. | |
| #define | STACK_LARGE STACK_MIN * 4 |
| Large stack size. | |
| #define | HEAP_TOP MEMORY_BASE + (MEMORY_SIZE - IDLE_STACK_SIZE) |
| Address just past top of heap. | |
| #define | THREAD_OK 0 |
| Thread returns ok. | |
| #define | NO_MORE_THREADS 1 |
| Thread manager has no more threads left. | |
| #define | NO_MORE_MEMORY 2 |
| Thread manager has run out of memory. | |
| #define | BAD_THREAD_PRIORITY 3 |
| Bad thread priority specified. | |
| #define | CONTEXT_SWITCH_DISABLED 0 |
| State that disables context switching. | |
| #define | CONTEXT_SWITCH_ENABLED 1 |
| State that enables context switching. | |
| #define | mos_thread_set_suspend_state(state) _current_thread->suspend_state = state |
| Set the suspend state of the current running thread this is the minimum sleep state allowed by the active thread. | |
| #define | mos_thread_get_suspend_state() _current_thread->suspend_state |
| Get the suspend state of the current running thread. | |
| #define | mos_thread_get_port() _current_thread->port |
| Get the port the current thread will block on. | |
| #define | mos_thread_set_port(port) _current_thread->port = port |
| Set the port the current thread is blocked on. | |
| #define | mos_thread_suspend() mos_thread_suspend_state (SUSPEND_STATE_IDLE); |
| Block the currently running thread. | |
| #define | mos_thread_current() _current_thread |
| Get a pointer to the currently executing thread. | |
Typedefs | |
| typedef thread_s | mos_thread_t |
| Thread structure definition. | |
Enumerations | |
| enum | { EMPTY = 0, RUNNING, READY, BLOCKED, SLEEPING } |
| Thread states. More... | |
| enum | { PRIORITY_KERNEL = 0, PRIORITY_SLEEP, PRIORITY_HIGH, PRIORITY_NORMAL, PRIORITY_IDLE, NUM_PRIORITIES } |
| Thread priorities. More... | |
| enum | { SUSPEND_STATE_IDLE = 0, SUSPEND_STATE_SLEEP, SUSPEND_STATE_MAX } |
| Suspend states. More... | |
Functions | |
| void | sched_init (void) |
| void | mos_sched_start (void) |
| uint8_t | mos_thread_new (void(*function_start)(void), memtype_t stack_size, uint8_t priority) |
| Create a new thread and put it on the ready queue. | |
| uint8_t | mos_thread_new_havestack (void(*function_start)(void), memtype_t stack_size, stackval_t *stack_addr, uint8_t priority) |
| Create a new thread with the given stack and put it on the ready queue. | |
| void | mos_thread_exit (void) |
| Terminate the calling thread. | |
| void | mos_thread_suspend_state (uint8_t state) |
| Suspend to a specific state. | |
| void | mos_thread_resume (mos_thread_t *thread) |
| Resume a blocked thread. | |
| void | mos_thread_sleep (uint32_t sleeptime) |
| Put the currently running thread to sleep. Units are in ms Minimum sleeptime is 128 ms (will be promoted). | |
| void | mos_single_threaded (void) |
| Put the kernel in single-threaded operation mode. | |
| void | mos_multi_threaded (void) |
| Put the kernel in multi-threaded operation mode. | |
| int | context_switch_enabled (void) |
| Return whether context switching is enabled or not. | |
| int | mos_check_sleep_time (uint8_t sleep_time) |
| Enable interrupts if we are not nested in another disable_ints call. Disable interrupts. | |
|
|
|
|
|
Definition at line 63 of file msched.h.
|
|
|
Definition at line 106 of file msched.h. 00106 { 00108 PRIORITY_KERNEL = 0, 00110 PRIORITY_SLEEP, 00112 PRIORITY_HIGH, 00114 PRIORITY_NORMAL, 00116 PRIORITY_IDLE, 00118 NUM_PRIORITIES 00119 };
|
|
|
Definition at line 122 of file msched.h. 00122 { 00124 SUSPEND_STATE_IDLE = 0, 00126 SUSPEND_STATE_SLEEP, 00128 SUSPEND_STATE_MAX 00129 };
|
|
|
|
|
|
For internal use only. Start scheduling threads. Must add thread(s) before calling start. (NOTE: This function never returns.) |
|
||||||||||||||||
|
Note: There is no memory protection so watch your stack sizes.
|
|
||||||||||||||||||||
|
Note: There is no memory protection so watch your stack sizes. Also, this thread should not exit, or the memory allocator will try to free the stack.
|
|
|
|
|
|
|
|
|
For internal use only. Init the scheduler. Must call this before adding any threads. |
1.4.6