Jan 21, 2014

An RTOS from the ground up

Just developed an RTOS from the ground up. It is still in the primitive stage but has got all the requirements of an RTOS. I used gcc toolchain to compile the sources and an Atmega328P (AVR) microcontroller to test it.

Source code is made available in my github. https://github.com/arunkumarv31/rtos

I have four infinite functions and the RTOS scheduler select the tasks to run and switches among them.
We can create tasks like this

createTask ( &function_1, "fun_one", 1, 200 );
 

createTask ( &function_2, "fun_two", 2, 200 );
.

.
createTask ( &function_n, "fun_three", n, 200 );


where the first parameter is the address of the function / task, the second parameter is its name. This name is used as the task identifier to change the attributes of a task, the third parameter is the priority of the task and the last parameter is the stack space required for the task.

A user function / task can be something like this. usually it will be an infinite loop.

void function_2 ( void )
{
  while (1)
  {
      changePriority ( "fun_one", 3 );
      changePriority ( "fun_two", 5 );
      changePriority ( "fun_three", 2 );
      changePriority ( "fun_four", 4 );
     
      printf ( "function_2\n" );
  }
}


The scheduler follows "fixed priority pre-emptive scheduling". And it always executes the highest priority task. So to give multitasking effect, i.e to preempt the current task and to execute other tasks we need to change the priority of the other tasks  in the current task with changePriority( "fun_one", 2 ) method.

If two or more tasks has the same priority which is the highest priority then ithe scheduler will execute the task first created.

changeStatus ( "fun_three", WAIT ) is used to change the status of a task. Here I have three status RUN, TERMINATE and WAIT.

deleteTask ( "fun_two" ) will delete the task and it will no longer be available to execute.

Jan 13, 2014

Saving SP in atmega328p

Context switching is one of the core component of parallel processing. I was trying to implement one such. Storing the SP to data space is something noteworthy.

For Web Developer

  open -a "Google Chrome" --args --disable-web-security