-
Notifications
You must be signed in to change notification settings - Fork 5
/
FreeRTOS_FE.c
75 lines (74 loc) · 2.13 KB
/
FreeRTOS_FE.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "FreeRTOS.h"
#include "task.h"
#include "portmacro.h"
#include "RTOS_BE.h"
void TickSignalHandler(int sig){
(void)sig;
void* current = NULL, *next = NULL;
int cur_idx = -1, next_idx = -1;
if(PMCU_IsInterruptEnabled() == 1 && PMCU_IsServicingTick() != 1){
if(PMCU_SingleTryLock() == 0){
PMCU_EnterServicingTick();
xTaskIncrementTick();
current = xTaskGetCurrentTaskHandle();
cur_idx = PMCU_Find_Idx(current);
vTaskSwitchContext();
next = xTaskGetCurrentTaskHandle();
next_idx = PMCU_Find_Idx(next);
if(cur_idx != next_idx){
PMCU_Schedule(cur_idx, next_idx);
}else{
PMCU_SingleUnlock();
}
PMCU_ExitServicingTick();
}else{
PMCU_SetPending();
}
}else{
PMCU_SetPending();
}
}
portSTACK_TYPE *pxPortInitialiseStack(portSTACK_TYPE *pxTopOfStack, void(* pxCode)(void*), void *pvParameters ){
PMCU_CreateNewThread(pxTopOfStack, pxCode, pvParameters, TickSignalHandler);
return pxTopOfStack;
}
portBASE_TYPE xPortStartScheduler( void ){
void *first_task = xTaskGetCurrentTaskHandle();
PMCU_StartScheduler(first_task, portTICK_RATE_MICROSECONDS);
// should never reach here
return 1;
}
void vPortEndScheduler( void ){
PMCU_EndScheduler();
}
void PMCU_FE_Yield(){
void *cur = NULL, *next = NULL;
int cur_idx = -1, next_idx = -1;
PMCU_SingleLock();
cur = xTaskGetCurrentTaskHandle();
cur_idx = PMCU_Find_Idx(cur);
vTaskSwitchContext();
next = xTaskGetCurrentTaskHandle();
next_idx = PMCU_Find_Idx(next);
if(cur_idx != next_idx){
PMCU_Schedule(cur_idx, next_idx);
}else{
PMCU_SingleUnlock();
}
}
void vPortDisableInterrupts( void ){
PMCU_DisableInterrupts();
}
void vPortEnableInterrupts( void ){
PMCU_EnableInterrupts();
}
void vPortEnterCritical( void ){
PMCU_EnterCritical();
}
void vPortExitCritical( void ){
PMCU_ExitCritical();
}
void vPortAddTaskHandle( void *pxTaskHandle ){
PMCU_Add_Task_ID(pxTaskHandle);
}
void FE_Thread_Exit(){}