Vous êtes sur la page 1sur 11

A RTOS

G Anand
anandg.embedd@gmail.com

RTOS is simple and powerful for standalone embedded systems. Simple


kernel handles task switching and task stack for multi-tasking. It can be handled
easily by the programmer for self-programing. Boot loaded RTOS kernel can
reduce the compiler compiling time.
ARTOS is introduced to simplify the operations when compared to other
RTOSs. Interrupt latency is the main problem which is faced by other RTOSs. In
this ARTOS a new method is used to avoid interrupt latency. Normally all
interrupts access same location in the stack. So interrupt-2 couldnt access that
location until the execution of the interrupt-1. In order to avoid this delay the
function to be handled by interrupt-1 will be assigned to another stack variable as a
handling function. So program control leaves interrupt 1 and starts to concentrate
on the handling function. Inside the handling function user can define their
program. Now at the same time, interrupt-2 get serviced and also interrupt 1 will
be implemented. In conventional RTOS, only after creation of all tasks,
implementation will be performed. ARTOS is designed in-order to perform
simultaneous operations. In ARTOS tasks can be created at any point of time. Task
creation and implementation can be performed simultaneously. In the process of
interrupt handling, to enable and disable Interrupt we need to write coding. But in
ARTOS interrupt enable and disable are created as a function. Now it will be easy
to access interrupt enable and disable. Thus ARTOS will be user-friendly. ARTOS
library functions are explained below.

ARTOS 2016

FEATURES
Task Priority
All the task ruined at least one time in every kernel routine (Total Task
switching)
LOW: This priority tasks will be called once after HIGH priority
task. It works on the basis of auto task switching. Every time the task
can be switched between TMR0 interrupt act. If for loop based delay
is used in the task, then it will be difficult to predict the time because
of auto switching process. In-order to avoid the task switching in the
task in which for loop is used, ARTOS_LOCK () function can be
used.
HIGH: This priority tasks will be called once before LOW priority
task. It works on the basis of auto task switching. Every time the task
can be switched between TMR0 interrupt act. If for loop based delay
is used in the task, then it will be difficult to predict the time because
of auto switching process. In-order to avoid the task switching in the
task in which for loop is used, ARTOS_LOCK () function can be
used.
REALTIME: This priority tasks will be called multiple times after
each HIGH and LOW priority tasks. Its used to debugger task for
fetch task status from each calling task. It is a Controlled task. It
works on the basis of manual task switching. If once the task resource
is allocated to real time priority tasks, then the process will not move
to another task. If there is a need to switch the task, then use
ARTOS_Idle () function (switching to the next task).
ARTOS 2016

Semaphore
All processors internal resources are accessed by semaphore.
Example: Consider the processor has single serial port. If the same
resource is accessed by 2 tasks simultaneously, then data interference
will be occurred in serial port.
To avoid this CONNECT and DISCONNECT instructions can be
used. If one task is already connected to the serial port, other tasks
should wait to establish connection to that resource.

IPC (Inter Process Communication)


Pointer based IPC. Only the Variable address will be transferred from
one process to another process. Thus any data type and large data can
be accessed from another task
Perfect address handling is done with the help of global and heap
variables.
Semaphore based data communication.

Interrupt Handling
Easy to access interrupt functions
All interrupts are enabled and disabled by inbuilt functions and
interrupt event handles header functions.
Software nested interrupt sequence
Interrupt Priority
LOW: Handle has individual stack. It processes newly arrived
LOW and HIGH priority interrupts. If HIGH or LOW interrupt
comes into play while one low priority interrupt is in process,
then current interrupt context has been saved and jump to next

ARTOS 2016

interrupt. All the interrupts are processes in the manner last in


first out.
HIGH: Handle has individual stack. It processes newly arrived
HIGH priority interrupt. If one interrupt is processing at the
same time another HIGH interrupts comes into play, then the
Current interrupt context has been saved and jump to next
interrupt. All the interrupts are processed in the manner last in
first out.
REALTIME: Handle has no individual stack. All the interrupts
are processed in the manner last in first out.
If user enabled the TMR interrupt, it generates interrupt event
handling function and call this function every interrupt occur.
TMR0 interrupt is reserved for kernel routine. This interrupt event can
be used for fixed kernel time. If the time of this interrupt kernel is
changed, only the time will be changed and the other system
operations will not be affected.

UART function
Interrupt based TX an RX
Buffered receiver which doesnt listen every time while receiving
Semaphore based UART functions like sending and receiving
operations using byte and string.

System Timer
Inbuilt HR: MIN: SEC: MSEC: USEC task for perfect timer
operation.
Get system time sample for timeout operation.
Use Kernel Timer (TMR0) , so dont need special timer
ARTOS 2016

LOW priority task only.


Auto prediction of the function stack top
Main routine is like individual task. This task is handled by ARTOS_INIT
function
Inbuilt library
GSM
Audio reader
LCD
ALARM
Multi data type EEPROM ( int, char, string..)
Seven Segment
DS1307 (Timer chip)
Bounce Button
Soft button
Universal IR decoder

FUNCTIONS

int8

ARTOS_Init(uint16

Main_ThreadID,int8 *Main_Stack,uint16

Main_Stack_Depth,uint8 Main_Task_Priority);
This function should be called before calling other functions (i.e at
initial stage). In our ARTOS, creation and implementation of tasks are
performed simultaneously. For this simultaneous operation init function
should be declared at first. Consider the main function consists of 2 tasks.
Main()
{
ARTOS 2016

int8

ARTOS_Init(uint16

Main_ThreadID,int8 *Main_Stack,uint16

Main_Stack_Depth,uint8 Main_Task_Priority);
Task 1
----------------------Task 2
}
Used to back up the main task context
First task 1 will be created and implemented initially. Task 1 will be
interrupted after particular time delay and the program control switch into
task 2 creation and implementation. This will be interrupted after particular
time delay and the program control has switched to task 1. Thus the
simultaneous operation can be achieved.
Default delay time is 500 micro seconds. We can change this delay
time according to our need. In other versions of RTOS first we should create
task in the main function. Only after creation of all tasks OS starts to
implement them. If the OS starts to implement the tasks, then it will never
return to the main function.
To declare init function we need to assign thread ID(uint16
Main_ThreadID),

stack

name(int8

*Main_Stack),

stack

size(uint16

Main_Stack_Depth) and priority(uint8 Main_Task_Priority).


Thread ID
It should be 16 bit number. Avoid assigning FF as main thread ID
because some inbuilt function has used FF as their thread ID.

ARTOS 2016

Stack name and size:


These arguments are used to define stack to store temporal variables
of the main function. This stack does not include particular task variable. If
we implement the tasks only after creation then there is no need to keep
track of main function. We are performing creation and implementation of
tasks simultaneously. So we need to keep track of main function. For this
purpose, a stack should be defined to store temporal variables of the main
function. This stack does not include particular task variable.
Priority:
There are 3 priorities in our system design. They are low priority, high
priority and real_time priority. In these, real_time priority has most
significance than other priorities. Second most significant priority is High
priority. Least significant priority is Low priority.
If 2 tasks (task 1- high priority, task 2- Low priority) are waiting for
the input from the same source, then the task will get the input from the
source according to their priority. Normally after particular delay, program
control will be switched into another task. If we assign the priority as
realtime_priority then the program control will not be switched into another
task after particular delay. Only after completing the task program control
will be switched into another task.
void ARTOS_ASM_delay(uint8 Nnop);
This function is used to provide assembly delay. It indicates number of nooperation to be performed.

ARTOS 2016

int8 ARTOS_ChangePriority(uint8 Thread_Priority);


This function is used to change the priority of the task (thread) at any
step.
int8 ARTOS_Create( uint16 Thread_ID,__Thread Thread_ADDR ,int8
*Stack,uint16 Stack_Depth,int8 *IPC, int8 Thread_Priority );
Create function is used to generate new task. To generate new task thread id,
thread address, stack name, stack size, pointer value and thread priority
should be given as input arguments.
Uint16 Thread_ID: Should be 16 bit number
Thread_ADDR: Address allocated for the task
int8 *Stack(name), uint16 Stack_Depth(size):
Stack is used to store the variables associated with the task. We need
to assign name and size of the stack.
int8 *IPC(pointer value):
Pointer value is used to address the location of the variables used. The
change made in the variable will be updated in the address location(denoted
by the pointer) directly.
int8 ARTOS_Start( uint16 Thread_ID );
This function is used to start the implementation of the task which is
created and stored in the buffer. After creating each task we need to declare
ARTOS 2016

start operation to implement that task. We can start any task from any step
using the ID of the task.
int8 ARTOS_Stop( uint16 Thread_ID );
This function is used to stop the implementation of the task. Normally
after particular delay, program control will be switched into another task.
Once the program control get the stop command of particular task, then the
program control should not get into task until the task is started by using
start function We can stop any task from any step using the ID of the task.
int8 ARTOS_Delete( uint16 Thread_ID );
This function is used to delete the particular task using task ID(thread
ID). This function clear the memory associated with the task.
void ARTOS_Return();
This function is used to return the output of a function.
Return value = 0 indicates the output of a function has returned successfully
Return value = negative number indicates the return of output is
unsuccessful
void ARTOS_Idle();
This function is used to idle the function for one cycle.
Main()
{

ARTOS 2016

int8 ARTOS_Init(uint16 Main_ThreadID,int8 *Main_Stack,uint16


Main_Stack_Depth,uint8 Main_Task_Priority);
Task 1
----------------------Task 2
-----------Idle function
-----------Task 3
----------------------Task 4
----------------------}
First task 1 will implemented. It will get interrupted after particular delay
time. And the program control will be switched into task 2. In task 2 we
have idle function. So task 2 will not be performed. Program control will be
switched into task 3. task 3 will be performed and it will get interrupted after
particular delay time. Then the program control will be switched into task 4.

ARTOS 2016

It will get interrupted after particular delay time. Then the program control
will be switched into task 1. Then the
void ARTOS_Delay(uint16 delay_ms);
This function is used provide delay. We should pass delay time as
argument of this function.
void ARTOS_Lock();
Normally after particular delay, program control will be switched into
another task. Lock function is used to avoid this switching. So the program
control moved to next task only after completing the task which has lock
function. This will be helpful to avoid switching in-case of low and high
priority tasks.
void ARTOS_UnLock();
This function is used to unlock the task which was locked.

ARTOS 2016

Vous aimerez peut-être aussi