SikendeRTOS
RTOS for ARM Cortex M3+ SoCs designed and written from scratch
OS.c File Reference

Contains functions to run OS. More...

#include "cpu.h"
#include "startup.h"
#include "Timer.h"
#include "Switch.h"
#include "OS.h"
Include dependency graph for OS.c:

Go to the source code of this file.

Data Structures

struct  Tcb
 

Typedefs

typedef struct Tcb tcbType
 

Functions

void StartOS (void)
 
void OS_EnableInterrupts (void)
 
void OS_DisableInterrupts (void)
 
void OS_SystemTimeHandler (void)
 
void Peripheral_Init (void)
 This function initializes extra IO used by OS, add new inits here. More...
 
void OS_SystemPriority (void)
 Set priority of Systick and PendSV (Context Switch handlers) More...
 
void OS_Init (void)
 initialize operating system, disable interrupts until OS_Launch initialize OS controlled I/O: serial, ADC, systick, LaunchPad I/O and timers More...
 
void LinkTCB (tcbType *newThread)
 LinkTCB Add TCB to doubly Linked List, copy pasta ee 312. More...
 
void UnLinkTCB (void)
 UnLinkTCB Remove thread form Doubly LL of TCB, copy pasta. More...
 
void AddBlockedToSemaphore (Sema4Type *semaPt)
 Add TCB to blocked Linked list of semaphore. More...
 
tcbTypeRemoveBlockedFromSemaphore (Sema4Type *semaPt)
 Remove TCB from blocked list, assuiming thread already blocked, else rip program. More...
 
void UnBlockTCB (Sema4Type *semaPt)
 Remove TCB from blocked list. More...
 
void BlockTCB (Sema4Type *semaPt)
 Add current TCB to blocked list then yield, ratatatat. More...
 
void OS_Launch (INT32U theTimeSlice)
 This function starts the scheduler and enables interrupts. More...
 
void OS_Scheduler (void)
 This function runs next highest priority thread, PRIORITY SCHEDULER. More...
 
void SysTick_Handler (void)
 This function decides next thread to run. More...
 
void OS_Suspend (void)
 This function suspends current thread by forcing context switch call. More...
 
void OS_AddPriorityThread (tcbType *newThread)
 This function decides next thread to run, now uses priority scheduler. More...
 
INT8 OS_AddThread (void(*task)(void), INT32U priority)
 This function decides next thread to run, now uses priority scheduler. More...
 
INT32U OS_IdThread (void)
 Get current thread ID. More...
 
void OS_InitSemaphore (Sema4Type *semaPt, INT32 value)
 Initialize semaphore to given value. More...
 
void OS_Wait (Sema4Type *semaPt)
 semaphore value decrement More...
 
void OS_Signal (Sema4Type *semaPt)
 This function(Spinlock) will signal that a mutual exclusion is taking place in a function. More...
 
void OS_bWait (Sema4Type *semaPt)
 This function implements binary wait. More...
 
void OS_bSignal (Sema4Type *semaPt)
 This function implements binary signal. More...
 
void OS_Sleep (INT32U sleepTime)
 This function puts a thread to sleep. More...
 
void OS_Kill (void)
 This function kill/deletes current thread from schedule. More...
 
INT8 OS_AddPeriodicThread (void(*task)(void), INT32U period, INT32U priority)
 Adds periodic background thread. Cannot spin, sleep, die, rest, etc. cause it's ISR, depends on hardware for number of tasks possible No ID for this thread, must have mid-high priority to run properly. More...
 
INT8 OS_AddSW1Task (void(*task)(void), INT32U priority)
 This function adds a thread to run and its priority when a button is pressed. More...
 
INT8 OS_AddSW2Task (void(*task)(void), INT32U priority)
 This function adds a thread to run and its priority when a button is pressed. More...
 
void OS_Fifo_Init (void)
 
INT8 OS_Fifo_Put (FIFO_t data)
 
FIFO_t OS_Fifo_Get (void)
 
INT32U OS_Fifo_Size (void)
 Gets current size of FiFo. More...
 
void OS_MailBox_Init (void)
 Initializes communication channel for OS. More...
 
void OS_MailBox_Send (INT32U data)
 This function will be called from a foreground thread It will spin/block if the MailBox contains data not yet received. More...
 
INT32U OS_MailBox_Recv (void)
 This function will be called from a foreground thread It will spin/block if the MailBox is empty. More...
 
INT32U OS_Time (void)
 
INT32U OS_TimeDifference (INT32U start, INT32U stop)
 
void OS_ClearMsTime (void)
 
INT32U OS_ReadMsTime (void)
 

Variables

tcbTypeRunPt
 Contains currently running thread. More...
 
tcbTypeNextRunPt
 Contains next thread to run. More...
 
INT32 PriorityTotal [PRIORITYLEVELS] = {0}
 
INT32 PriorityAvailable [PRIORITYLEVELS] = {0}
 
tcbTypePriorityPtr [PRIORITYLEVELS] = {0}
 
tcbTypePriorityLastPtr [PRIORITYLEVELS] = {0}
 

Detailed Description

Contains functions to run OS.

Definition in file OS.c.

Typedef Documentation

◆ tcbType

typedef struct Tcb tcbType

Definition at line 65 of file OS.c.

Function Documentation

◆ AddBlockedToSemaphore()

void AddBlockedToSemaphore ( Sema4Type semaPt)

Add TCB to blocked Linked list of semaphore.

AddBlockedToSema4

Parameters
semaPtptr to semaphore

Definition at line 229 of file OS.c.

Here is the caller graph for this function:

◆ BlockTCB()

void BlockTCB ( Sema4Type semaPt)

Add current TCB to blocked list then yield, ratatatat.

BlockTCB

Parameters
semaPtptr to semaphore

Definition at line 271 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LinkTCB()

void LinkTCB ( tcbType newThread)

LinkTCB Add TCB to doubly Linked List, copy pasta ee 312.

Definition at line 201 of file OS.c.

Here is the caller graph for this function:

◆ OS_AddPeriodicThread()

INT8 OS_AddPeriodicThread ( void(*)(void)  task,
INT32U  period,
INT32U  priority 
)

Adds periodic background thread. Cannot spin, sleep, die, rest, etc. cause it's ISR, depends on hardware for number of tasks possible No ID for this thread, must have mid-high priority to run properly.

OS_AddPeriodicThread

Parameters
tasktask to run in background
period
priority5-0 only, else you'll break OS :(
Returns
successful - 1, Fail - 0

Definition at line 593 of file OS.c.

Here is the call graph for this function:

◆ OS_AddPriorityThread()

void OS_AddPriorityThread ( tcbType newThread)

This function decides next thread to run, now uses priority scheduler.

OS_AddThread

Parameters
newThread

Definition at line 357 of file OS.c.

◆ OS_AddSW1Task()

INT8 OS_AddSW1Task ( void(*)(void)  task,
INT32U  priority 
)

This function adds a thread to run and its priority when a button is pressed.

OS_AddSW1Task

Parameters
taskfunction/thread to run when button pressed
priority
Returns
success or fail

Definition at line 626 of file OS.c.

Here is the call graph for this function:

◆ OS_AddSW2Task()

INT8 OS_AddSW2Task ( void(*)(void)  task,
INT32U  priority 
)

This function adds a thread to run and its priority when a button is pressed.

OS_AddSW2Task

Parameters
taskfunction/thread to run when button pressed
priority
Returns
success or fail

Definition at line 638 of file OS.c.

Here is the call graph for this function:

◆ OS_AddThread()

INT8 OS_AddThread ( void(*)(void)  task,
INT32U  priority 
)

This function decides next thread to run, now uses priority scheduler.

OS_AddThread

Parameters
task
stackSize
priority
Returns
1-success, 0-fail

Definition at line 386 of file OS.c.

Here is the caller graph for this function:

◆ OS_bSignal()

void OS_bSignal ( Sema4Type semaPt)

This function implements binary signal.

Signal semaphore to be free, set to 1.

OS_bSignal

Parameters
semaPtsemaphore passed in

Definition at line 514 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_bWait()

void OS_bWait ( Sema4Type semaPt)

This function implements binary wait.

Wait on semaphore, binary.

OS_bWait

Parameters
semaPtsemaphore passed in

Definition at line 499 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_ClearMsTime()

void OS_ClearMsTime ( void  )

OS_ClearMsTime Clear ms time

Definition at line 760 of file OS.c.

Here is the caller graph for this function:

◆ OS_DisableInterrupts()

void OS_DisableInterrupts ( void  )
Here is the caller graph for this function:

◆ OS_EnableInterrupts()

void OS_EnableInterrupts ( void  )
Here is the caller graph for this function:

◆ OS_Fifo_Get()

FIFO_t OS_Fifo_Get ( void  )

OS_Fifo_Get Retrieves data from OS Fifo

Returns
1 for success, 0 for fail

Definition at line 676 of file OS.c.

Here is the call graph for this function:

◆ OS_Fifo_Init()

void OS_Fifo_Init ( void  )

OS_Fifo_Init Initializes Fifo to be empty, ignored for lab 2, divisible by 2

Definition at line 646 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_Fifo_Put()

INT8 OS_Fifo_Put ( FIFO_t  data)

OS_Fifo_Put Adds data to FiFo

Parameters
data
Returns
success - 1, Fail - 0

Definition at line 659 of file OS.c.

◆ OS_Fifo_Size()

INT32U OS_Fifo_Size ( void  )

Gets current size of FiFo.

OS_Fifo_Size

Returns
size of current FIFO buffer

Definition at line 691 of file OS.c.

◆ OS_IdThread()

INT32U OS_IdThread ( void  )

Get current thread ID.

OS_IdThread

Returns
id of thread

Definition at line 448 of file OS.c.

◆ OS_Init()

void OS_Init ( void  )

initialize operating system, disable interrupts until OS_Launch initialize OS controlled I/O: serial, ADC, systick, LaunchPad I/O and timers

OS_Init

Definition at line 188 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_InitSemaphore()

void OS_InitSemaphore ( Sema4Type semaPt,
INT32  value 
)

Initialize semaphore to given value.

OS_InitSemaphore

Parameters
semaPtsemaphore ptr

Definition at line 456 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_Kill()

void OS_Kill ( void  )

This function kill/deletes current thread from schedule.

OS_Kill

Definition at line 542 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_Launch()

void OS_Launch ( INT32U  theTimeSlice)

This function starts the scheduler and enables interrupts.

OS_Launch

Parameters
theTimeSliceperiod of round robin scheduler

Definition at line 285 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_MailBox_Init()

void OS_MailBox_Init ( void  )

Initializes communication channel for OS.

Initialize mailbox for OS.

OS_MailBox_Init

Definition at line 701 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_MailBox_Recv()

INT32U OS_MailBox_Recv ( void  )

This function will be called from a foreground thread It will spin/block if the MailBox is empty.

OS_MailBox_Recv Remove mail from the mailbox

Returns
data from Mailbox

Definition at line 729 of file OS.c.

Here is the call graph for this function:

◆ OS_MailBox_Send()

void OS_MailBox_Send ( INT32U  data)

This function will be called from a foreground thread It will spin/block if the MailBox contains data not yet received.

OS_MailBox_Send Enter mail into the Mailbox

Parameters
datadata to put into mailbox

Definition at line 715 of file OS.c.

Here is the call graph for this function:

◆ OS_ReadMsTime()

INT32U OS_ReadMsTime ( void  )

OS_MsTime

Returns
time in ms

Definition at line 767 of file OS.c.

Here is the caller graph for this function:

◆ OS_Scheduler()

void OS_Scheduler ( void  )

This function runs next highest priority thread, PRIORITY SCHEDULER.

OS_Scheduler

Definition at line 300 of file OS.c.

Here is the caller graph for this function:

◆ OS_Signal()

void OS_Signal ( Sema4Type semaPt)

This function(Spinlock) will signal that a mutual exclusion is taking place in a function.

OS_Signal

Parameters
semaPt

Definition at line 483 of file OS.c.

Here is the call graph for this function:

◆ OS_Sleep()

void OS_Sleep ( INT32U  sleepTime)

This function puts a thread to sleep.

OS_Sleep

Parameters
sleepTimetime to put thread to sleep

Definition at line 528 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OS_Suspend()

void OS_Suspend ( void  )

This function suspends current thread by forcing context switch call.

OS_Suspend

Definition at line 343 of file OS.c.

Here is the caller graph for this function:

◆ OS_SystemPriority()

void OS_SystemPriority ( void  )

Set priority of Systick and PendSV (Context Switch handlers)

OS_SystemtPriority

Definition at line 178 of file OS.c.

◆ OS_SystemTimeHandler()

void OS_SystemTimeHandler ( void  )

Definition at line 160 of file OS.c.

◆ OS_Time()

INT32U OS_Time ( void  )

OS_Time

Returns
OS time in 1/BUS_CLK increments

Definition at line 740 of file OS.c.

◆ OS_TimeDifference()

INT32U OS_TimeDifference ( INT32U  start,
INT32U  stop 
)

OS_TimeDifference

Parameters
start
stop
Returns
time difference

Definition at line 749 of file OS.c.

◆ OS_Wait()

void OS_Wait ( Sema4Type semaPt)

semaphore value decrement

OS_Wait

Parameters
semaPtpointer to semaphore
Returns
none

Definition at line 468 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Peripheral_Init()

void Peripheral_Init ( void  )

This function initializes extra IO used by OS, add new inits here.

Peripheral_Init

Definition at line 167 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveBlockedFromSemaphore()

tcbType * RemoveBlockedFromSemaphore ( Sema4Type semaPt)

Remove TCB from blocked list, assuiming thread already blocked, else rip program.

RemoveBlockedFromSemaphore

Parameters
semaPtptr to semaphore
Returns
tcb that is no longer blocked from list

Definition at line 250 of file OS.c.

Here is the caller graph for this function:

◆ StartOS()

void StartOS ( void  )
Here is the caller graph for this function:

◆ SysTick_Handler()

void SysTick_Handler ( void  )

This function decides next thread to run.

SysTick_Handler

Definition at line 332 of file OS.c.

Here is the call graph for this function:

◆ UnBlockTCB()

void UnBlockTCB ( Sema4Type semaPt)

Remove TCB from blocked list.

UnBlockTCB

Parameters
semaPtptr to semaphore

Definition at line 261 of file OS.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnLinkTCB()

void UnLinkTCB ( void  )

UnLinkTCB Remove thread form Doubly LL of TCB, copy pasta.

Definition at line 218 of file OS.c.

Here is the caller graph for this function:

Variable Documentation

◆ NextRunPt

tcbType * NextRunPt

Contains next thread to run.

Definition at line 76 of file OS.c.

◆ PriorityAvailable

INT32 PriorityAvailable[PRIORITYLEVELS] = {0}

Definition at line 89 of file OS.c.

◆ PriorityLastPtr

tcbType* PriorityLastPtr[PRIORITYLEVELS] = {0}

Definition at line 93 of file OS.c.

◆ PriorityPtr

tcbType* PriorityPtr[PRIORITYLEVELS] = {0}

Definition at line 91 of file OS.c.

◆ PriorityTotal

INT32 PriorityTotal[PRIORITYLEVELS] = {0}

Definition at line 87 of file OS.c.

◆ RunPt

tcbType * RunPt

Contains currently running thread.

Definition at line 71 of file OS.c.