27static INT32U NumOfThreads = 0;
32static INT64U OS_SystemTime = 0;
37static INT64U OS_SystemTimeMS;
82static INT32U Get_Idx = 0, Put_Idx = 0;
103static void SetInitialStack(
INT32U i){
126static void SetThreads(
void){
141static void OS_SleepHandler(
void){
208 newThread->
prev = endPtr;
209 endPtr->
next = newThread;
396 for(idxFreeTCB = 0; idxFreeTCB <
NUMTHREADS; idxFreeTCB++){
398 if(tcbs[idxFreeTCB].
status == -1){
404 if(NumOfThreads == 0){
405 tcbs[NumOfThreads].
next = &tcbs[0];
406 tcbs[NumOfThreads].
prev = &tcbs[0];
421 tcbs[idxFreeTCB].
prev = endPtr;
422 endPtr->
next = &tcbs[idxFreeTCB];
425 SetInitialStack(idxFreeTCB);
430 tcbs[idxFreeTCB].
status = 0;
431 tcbs[idxFreeTCB].
id = idxFreeTCB;
458 semaPt->
Value = value;
472 if (semaPt->
Value < 0){
487 if(semaPt->
Value < 1){
502 if (semaPt->
Value < 0){
517 if(semaPt->
Value < 1){
560 while (curPtr !=
RunPt){
594 static INT8U NumberOfPeriodicTasks = 0;
596 if (NumberOfPeriodicTasks == 0){
598 }
else if (NumberOfPeriodicTasks == 1){
600 }
else if (NumberOfPeriodicTasks == 2){
602 }
else if (NumberOfPeriodicTasks == 3){
604 }
else if (NumberOfPeriodicTasks == 4){
606 }
else if (NumberOfPeriodicTasks == 5){
608 }
else if (NumberOfPeriodicTasks == 6){
610 }
else if (NumberOfPeriodicTasks == 7){
616 NumberOfPeriodicTasks++;
648 Put_Idx = Get_Idx = 0;
664 OS_FIFO[Put_Idx] = data;
680 if(Put_Idx == Get_Idx)
return 0;
682 data = OS_FIFO[Get_Idx];
751 return (start - stop);
753 return (0xFFFFFFFF - stop + start);
768 return OS_SystemTimeMS;
void OS_SystemTimeHandler(void)
void OS_Signal(Sema4Type *semaPt)
This function(Spinlock) will signal that a mutual exclusion is taking place in a function.
INT8 OS_AddPeriodicThread(void(*task)(void), INT32U period, INT32U priority)
Adds periodic background thread. Cannot spin, sleep, die, rest, etc. cause it's ISR,...
void OS_EnableInterrupts(void)
void OS_AddPriorityThread(tcbType *newThread)
This function decides next thread to run, now uses priority scheduler.
INT32 PriorityTotal[PRIORITYLEVELS]
void OS_bWait(Sema4Type *semaPt)
This function implements binary wait.
void Peripheral_Init(void)
This function initializes extra IO used by OS, add new inits here.
void OS_Suspend(void)
This function suspends current thread by forcing context switch call.
INT32U OS_Fifo_Size(void)
Gets current size of FiFo.
void OS_DisableInterrupts(void)
INT8 OS_AddThread(void(*task)(void), INT32U priority)
This function decides next thread to run, now uses priority scheduler.
void UnBlockTCB(Sema4Type *semaPt)
Remove TCB from blocked list.
INT8 OS_Fifo_Put(FIFO_t data)
tcbType * PriorityPtr[PRIORITYLEVELS]
INT32U OS_IdThread(void)
Get current thread ID.
tcbType * NextRunPt
Contains next thread to run.
tcbType * PriorityLastPtr[PRIORITYLEVELS]
void LinkTCB(tcbType *newThread)
LinkTCB Add TCB to doubly Linked List, copy pasta ee 312.
INT32 PriorityAvailable[PRIORITYLEVELS]
void OS_Scheduler(void)
This function runs next highest priority thread, PRIORITY SCHEDULER.
void OS_MailBox_Init(void)
Initializes communication channel for OS.
INT32U OS_ReadMsTime(void)
void OS_Kill(void)
This function kill/deletes current thread from schedule.
void OS_MailBox_Send(INT32U data)
This function will be called from a foreground thread It will spin/block if the MailBox contains data...
INT32U OS_MailBox_Recv(void)
This function will be called from a foreground thread It will spin/block if the MailBox is empty.
INT32U OS_TimeDifference(INT32U start, INT32U stop)
tcbType * RunPt
Contains currently running thread.
void OS_SystemPriority(void)
Set priority of Systick and PendSV (Context Switch handlers)
void OS_bSignal(Sema4Type *semaPt)
This function implements binary signal.
void OS_Wait(Sema4Type *semaPt)
semaphore value decrement
void UnLinkTCB(void)
UnLinkTCB Remove thread form Doubly LL of TCB, copy pasta.
INT8 OS_AddSW2Task(void(*task)(void), INT32U priority)
This function adds a thread to run and its priority when a button is pressed.
void SysTick_Handler(void)
This function decides next thread to run.
void OS_Launch(INT32U theTimeSlice)
This function starts the scheduler and enables interrupts.
void OS_Sleep(INT32U sleepTime)
This function puts a thread to sleep.
INT8 OS_AddSW1Task(void(*task)(void), INT32U priority)
This function adds a thread to run and its priority when a button is pressed.
void OS_Init(void)
initialize operating system, disable interrupts until OS_Launch initialize OS controlled I/O: serial,...
void OS_ClearMsTime(void)
void AddBlockedToSemaphore(Sema4Type *semaPt)
Add TCB to blocked Linked list of semaphore.
void OS_InitSemaphore(Sema4Type *semaPt, INT32 value)
Initialize semaphore to given value.
void BlockTCB(Sema4Type *semaPt)
Add current TCB to blocked list then yield, ratatatat.
tcbType * RemoveBlockedFromSemaphore(Sema4Type *semaPt)
Remove TCB from blocked list, assuiming thread already blocked, else rip program.
#define STACKSIZE
max size of stack
#define FIFO_SIZE
Size of OS FIFO in 32 bit words.
#define PRIORITYLEVELS
number of priorities
#define NUMTHREADS
max number of threads
void SW1_Init(void(*task)(void), INT32U priority)
void SW2_Init(void(*task)(void), INT32U priority)
Periodic Timer setup for TM4c123.
void Timer0A_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer1B_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer4A_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer4B_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer2B_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer1A_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer0B_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer3A_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer3B_Init(void(*task)(void), uint32_t period, uint32_t priority)
void Timer2A_Init(void(*task)(void), uint32_t period, uint32_t priority)
void SysTick_Init(uint32_t period)
Contains Enable/Disable Interrupts, Start/EndCritical from startup file Used to control global ISR fl...
INT32U StartCritical(void)
Start Criticat Sections, Disable Global Interrupts.
void EndCritical(INT32U sr)
End of critical section (ISR = prev ISR) @parameter sr previously saved PSR.
void EnableInterrupts(void)
Enable Global Interrupts (ISR = 0)
void DisableInterrupts(void)
Disable Global Interrupts (ISR = 1)
struct Tcb * blockThreads
struct Tcb * nextPriority
#define NVIC_ST_CURRENT_R
#define NVIC_INT_CTRL_PEND_SV