SikendeRTOS
RTOS for ARM Cortex M3+ SoCs designed and written from scratch
main.c
Go to the documentation of this file.
1
6#include "OS.h"
7#include "UART0.h"
8#include "Interpreter.h"
9#include <stdint.h>
10#include "cpu.h"
11
12
13// number of threads created by main
15
16// mutex for access to red LED on board
18
19
23void Flash_Green(void)
24{
25 while(1)
26 {
28 OS_Suspend();
29
30 }
31}
32
33
34
38void Flash_Blue(void)
39{
40 while(1)
41 {
43 OS_Sleep(3);
44 }
45}
46
47
48
52void Flash_Red(void)
53{
54 while(1)
55 {
59 }
60}
61
62
63
67void Flash_Red2(void)
68{
69 while(1)
70 {
74 }
75}
76
77
78
83{
84 while(1){
86 }
87}
88
89
90
94void DummyThread(void){
95 volatile int dummyCount = 0;
96 while(1){
97 dummyCount++;
98 }
99}
100
101
102
106int main(void)
107{
108 CLOCK_Init();
109 LED_Init();
110 OS_Init();
112 OS_Fifo_Init();
113
114 // create initial foreground threads
117
118 // create initial foreground threads
121
122 // create initial foreground threads
125
126 // create initial foreground threads
127 if(OS_AddThread(&Flash_Blue, 2))
129
130 // create initial foreground threads
131 if(OS_AddThread(&Flash_Red, 2))
133
136
137 // this should never run
138 //while(1){}
139 return 0; // this never executes
140}
141
142
143
148 PF1 = 0x02;
149 PF2 = 0x04;
150 PF3 = 0x08;
151 while(1);
152}
#define GREEN_LED
Definition: cpu.h:23
#define RED_LED
Definition: cpu.h:27
#define PF2
Definition: cpu.h:20
#define BLUE_BLINK
Definition: cpu.h:26
#define GREEN_BLINK
Definition: cpu.h:24
#define BLUE_LED
Definition: cpu.h:25
#define RED_BLINK
Definition: cpu.h:28
#define PF1
Definition: cpu.h:19
void LED_Init(void)
Initialize development board LEDS, example function.
Definition: cpu.c:26
#define PF3
Definition: cpu.h:21
void CLOCK_Init(void)
Initialize system clock (PLL)
Definition: cpu.c:15
Runs on TM4C123 Command line interface.
void Interpreter(void)
Definition: Interpreter.c:51
Functions for OS.
void OS_bWait(Sema4Type *semaPt)
Wait on semaphore, binary.
Definition: OS.c:499
void OS_Suspend(void)
This function suspends current thread by forcing context switch call.
Definition: OS.c:343
INT8 OS_AddThread(void(*task)(void), INT32U priority)
This function decides next thread to run, now uses priority scheduler.
Definition: OS.c:386
void OS_MailBox_Init(void)
Initialize mailbox for OS.
Definition: OS.c:701
void OS_Fifo_Init(void)
Definition: OS.c:646
void OS_bSignal(Sema4Type *semaPt)
Signal semaphore to be free, set to 1.
Definition: OS.c:514
void OS_Launch(INT32U theTimeSlice)
This function starts the scheduler and enables interrupts.
Definition: OS.c:285
void OS_Sleep(INT32U sleepTime)
This function puts a thread to sleep.
Definition: OS.c:528
void OS_Init(void)
initialize operating system, disable interrupts until OS_Launch initialize OS controlled I/O: serial,...
Definition: OS.c:188
void OS_InitSemaphore(Sema4Type *semaPt, INT32 value)
Initialize semaphore to given value.
Definition: OS.c:456
void OS_ASM_Wait(Sema4Type *semaPt)
Spinlock semaphore wait using ARM exclusion.
void OS_ASM_Signal(Sema4Type *semaPt)
Spinlock semaphore signal using ARM exclusion.
#define TIME_2MS
Definition: OSConfig.h:14
void Flash_Green(void)
Blink Green LED.
Definition: main.c:23
void HardFault_Handler(void)
HArdfault Handler Sets LEDS to white to indicate fault, assumes LEDS already initialized.
Definition: main.c:147
Sema4Type Mutex_REDLED
Definition: main.c:17
int ThreadsCreated
Definition: main.c:14
void Flash_Red2(void)
Blink Red LED.
Definition: main.c:67
int main(void)
Example usecase of RTOS.
Definition: main.c:106
void DummyThread(void)
Dummy Thread, Prevent OS crash if no threads running.
Definition: main.c:94
void WrapInterpreter(void)
Run interpreter using UART0 (in USB debugger)
Definition: main.c:82
void Flash_Blue(void)
Blink Blue LED.
Definition: main.c:38
void Flash_Red(void)
Blink Red LED.
Definition: main.c:52
Definition: OS.h:16