This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CustomMallocInit(HEAP_INFO_t *pHeapInfo) | |
{ | |
pHeapInfo->alloc_dll = &(pHeapInfo->dummy1); | |
pHeapInfo->alloc_dll->next = NULL; | |
pHeapInfo->alloc_dll->prev = NULL; | |
pHeapInfo->avail_dll = &(pHeapInfo->dummy2); | |
pHeapInfo->avail_dll->prev = NULL; | |
pHeapInfo->avail_dll->next = pHeapInfo->pHeap; | |
pHeapInfo->avail_dll->next->blkSize = pHeapInfo->heapSz - sizeof(BD_t); | |
pHeapInfo->avail_dll->next->next = NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Initializes the heap. It internally created a BD and places at start of the | |
* heap. The BD is added to avail_dll. | |
* @param pHeapInfo: Pointer to the current heap info. | |
**/ | |
void CustomMallocInit(HEAP_INFO_t *pHeapInfo); | |
/* | |
* Mimics the malloc function(i.e provides the requested memory). Returns NULL in | |
* case is it not possible to allocate the requested memory. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct BD_t | |
{ | |
int blkSize; | |
struct BD_t *prev; | |
struct BD_t *next; | |
} BD_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* premptive_scheduler.c | |
* | |
* Created on: Apr 26, 2020 | |
* Author: Sudeep Chandrasekaran | |
*/ | |
#include <stdint.h> | |
#include <stdbool.h> | |
#include "premptive_scheduler.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void portable_delay_cycles(unsigned long n) | |
{ | |
while (n--) | |
{ | |
asm volatile (""); | |
} | |
} | |
volatile void Task0() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__attribute__((naked)) void LaunchScheduler(void) | |
{ | |
/// R0 contains the address of currentPt | |
__asm("LDR R0, =pCurntTcb"); | |
/// R2 contains the address in currentPt(value of currentPt) | |
__asm("LDR R2, [R0]"); | |
/// Load the SP reg with the stacked SP value | |
__asm("LDR R4, [R2]"); | |
__asm("MOV SP, R4"); | |
/// Pop registers R8-R11(user saved context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void OsInitThreadStack() | |
{ | |
/// Enter critical section | |
/// Disable interrupts | |
__asm("CPSID I"); | |
/// Make the TCB linked list circular | |
tcbs[0].nextPt = &tcbs[1]; | |
tcbs[1].nextPt = &tcbs[0]; | |
/// Setup stack for task0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__attribute__((naked)) void SysTick_Handler(void) | |
{ | |
/// STEP 1 - SAVE THE CURRENT TASK CONTEXT | |
/// At this point the processor has already pushed PSR, PC, LR, R12, R3, R2, R1 and R0 | |
/// onto the stack. We need to push the rest(i.e R4, R5, R6, R7, R8, R9, R10 & R11) to save the | |
/// context of the current task. | |
/// Disable interrupts | |
__asm("CPSID I"); | |
/// Push registers R4 to R7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
while(1) | |
{ | |
LED1_TURN_ON(); | |
LED2_TURN_ON(); | |
delay_seconds(1); | |
LED1_TURN_OFF(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void PumpTask() | |
{ | |
while(1) | |
{ | |
if(GetTimeSinceLastToggle() ≥ 30) | |
{ | |
TurnPumpOn(); | |
} | |
} | |
} |
NewerOlder