diff --git a/RidhaOs/Inc/ridhaOsKernel.h b/RidhaOs/Inc/ridhaOsKernel.h new file mode 100644 index 0000000..7cc7700 --- /dev/null +++ b/RidhaOs/Inc/ridhaOsKernel.h @@ -0,0 +1,15 @@ +#ifndef __R_KERNEL_H__ +#define __R_KERNEL_H__ + +#include "RIDHAOS_CONF.h" + +/* This Struct used to restore next thread and save the running thread */ +typedef struct tControlBlock +{ + int32_t * stackPt; + struct tControlBlock * nextPt; +}tControlBlock_t; + + + +#endif /* __R_THREAD_H__ */ \ No newline at end of file diff --git a/RidhaOs/RIDHAOS_CONF.h b/RidhaOs/RIDHAOS_CONF.h index fc56198..ad33d47 100644 --- a/RidhaOs/RIDHAOS_CONF.h +++ b/RidhaOs/RIDHAOS_CONF.h @@ -1,6 +1,7 @@ #ifndef __R_CONFIGURATION_H__ #define __R_CONFIGURATION_H__ + /* Here Define your MCU REGISTER MAP FILE */ #include "fsl_device_registers.h" @@ -8,8 +9,12 @@ /* SysTick Configuration for TimeBase */ extern uint32_t SystemCoreClock; -#define CPU_CLOCK_HZ SystemCoreClock -#define MAX_DELAY 0xFFFFFFFFU -#define TICK_RATE_HZ 1000 +#define CPU_CLOCK_HZ SystemCoreClock // Use Default System Clock in Hz +#define MAX_DELAY 0xFFFFFFFFU // Max Wayt Delay +#define TICK_RATE_HZ 1000 // Getting SystemCoreClock divide by 1000 to get interrupt every 1ms + +/* Thread Configuration Size and Number Max for TCB */ +#define NUM_OF_THREADS 3 +#define STACKSIZE 100 #endif /* __R_CONFIGURATION_H__ */ \ No newline at end of file diff --git a/RidhaOs/Src/ridhaOsKernel.c b/RidhaOs/Src/ridhaOsKernel.c new file mode 100644 index 0000000..92019ee --- /dev/null +++ b/RidhaOs/Src/ridhaOsKernel.c @@ -0,0 +1,16 @@ +#include "ridhaOsKernel.h" + +/* Define a fixed linked list of Stack */ +tControlBlock_t tcbs[NUM_OF_THREADS]; + +/* Define current Pointer to point to first of the list of Stack*/ +tControlBlock_t * currentPt; + +/* Each Thread will have STACKSIZE * 4. */ +int32_t TCB_STACK[NUM_OF_THREADS][STACKSIZE]; + +void ridhaOsKernalStackInit(int i) +{ + /* Set bit24 Thumb state bit to one, operate in thumb mode */ + TCB_STACK[i][STACKSIZE-1] = (1U << 24); // PSR register +} \ No newline at end of file diff --git a/RidhaOs/Src/timebase.c b/RidhaOs/Src/timebase.c index b85ac42..bd0129c 100644 --- a/RidhaOs/Src/timebase.c +++ b/RidhaOs/Src/timebase.c @@ -47,7 +47,6 @@ uint32_t get_tick(void) void timebase_init(void) { /* Reload the timer with number of cycles per second */ - /* Getting SystemCoreClock divide by 1000 to get interrupt every 1ms */ SysTick->LOAD = (SystemCoreClock / 1000) - 1; /* Clear Systick current value register */ diff --git a/RidhaOs/note.txt b/RidhaOs/note.txt new file mode 100644 index 0000000..13f669e --- /dev/null +++ b/RidhaOs/note.txt @@ -0,0 +1,46 @@ +For RidhaOs we will use Round Robin Scheduler to switch from thread to another. +For Context switch we follow these steps: + 1. Save execution of the running thread. + 2. Restore execution of the next ready thread. + +For Kernel he will be manage : + - Thread Scheduling. + - Booting. + - Inter-thread communication. + - Synchronization. + +Steps to implement RidhaOs: + 1. Configure timebase (by Default use systick). + 2. Create our Thread Control Block for Round Robin design. + +For more information: + +Scheduling Algorithm Optimization : + The Keys to have a good RTOS design you need: + - Maximize Throughput. + - Minimize Turnaround Time. + - Minimize Response Time. + - Maximize CPU Utilization. + - Minimize Scheduling Overhead. + +Popular Scheduling Algorithm: +* First Come First Serve Scheduler (FCFSS): + - Task are executed on first come, first server basis. + - Non-preemptive. + - Its implementation is based on FIFO queue. + - Poor in performance as average wait time is high. + +* Round Robin Scheduler (RRS): + - Preemptive. + - Employs time sharing, gives each thread a timeslice (quanta). + - When timesclice runs out OS preempts the thread. + +* Weighted Round Robin Scheduler (WRRS): + - Preemptive. + - Employs time sharing, gives each thread a timeslice (quanta). + - If quanta runs out OS preempts the thread. + - Threads have unequal weight. + +* Rate Monotonic Scheduler (RMS). +* Shortest Job First (SJF). +