Start implment os kernel
This commit is contained in:
parent
dff43f451c
commit
e857fc9dee
15
RidhaOs/Inc/ridhaOsKernel.h
Normal file
15
RidhaOs/Inc/ridhaOsKernel.h
Normal file
@ -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__ */
|
||||
@ -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__ */
|
||||
16
RidhaOs/Src/ridhaOsKernel.c
Normal file
16
RidhaOs/Src/ridhaOsKernel.c
Normal file
@ -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
|
||||
}
|
||||
@ -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 */
|
||||
|
||||
46
RidhaOs/note.txt
Normal file
46
RidhaOs/note.txt
Normal file
@ -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).
|
||||
|
||||
Loading…
Reference in New Issue
Block a user