ATMega128 with FreeRTOS

Renoster requires a fairly integrate control system, with several tasks required to run almost simultaneously, e.g. position calculation, way point tracking, mapping etc. and others need to be able to interrupt those in the event of possible danger, e.g. collision detection, tilt detection etc. A preemptive multitasking OS such as FreeRTOS provides all these features.

FreeRTOS has several official ports available including the ATMega32, which was surprisingly easy to port to the ATMega128.

The starting point was CYPAX.net which had a great demo. However it does not include an AVRStudio project. But getting it working in AVR Studio was very simple.

1. Download FreeRTOS

2. Extract, e.g. C:\Development\Renoster\Embedded\FreeRTOS

3. Create a new AVRStudio project

4. Add the following files to your project

C:\Development\Renoster\Embedded\FreeRTOS\Source\croutine.c
C:\Development\Renoster\Embedded\FreeRTOS\Source\list.c
C:\Development\Renoster\Embedded\FreeRTOS\Source\queue.c
C:\Development\Renoster\Embedded\FreeRTOS\Source\tasks.c
C:\Development\Renoster\Embedded\FreeRTOS\Source\portable\MemMang\heap_1.c
C:\Development\Renoster\Embedded\FreeRTOS\Source\portable\GCC\ATMega323\port.c

FreeRTOSConfig.h from the demo from CPAX.net, remember to update as needed.

5. Add the following to the Include File Search Path in Project Options 

C:\Development\Renoster\Embedded\FreeRTOS\Source\include\
C:\Development\Renoster\Embedded\FreeRTOS\Source\
C:\Development\Renoster\Embedded\FreeRTOS\Source\portable\GCC\ATMega323\
 

Lastly a simple test:

  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include <string.h>
  6. #include <math.h>
  7. #include <avr/io.h>
  8. #include <avr/interrupt.h>
  9. #include <avr/eeprom.h>
  10. #include <avr/pgmspace.h>
  11.  
  12. //FreeRTOS include files
  13. #include "FreeRTOS.h"
  14. #include "task.h"
  15. #include "croutine.h"
  16.  
  17. void LedHeartBeatTask()
  18. {
  19. DDRG |= 1;
  20.  
  21. for(;;)
  22. {
  23. PORTG |= _BV(PG0);
  24. vTaskDelay(500);
  25. PORTG &= ~_BV(PG0);
  26. vTaskDelay(500);
  27. }
  28. }
  29.  
  30. void StartLedHeartBeatTask(unsigned portBASE_TYPE Priority)
  31. {
  32. // Spawn the task.
  33. xTaskCreate(LedHeartBeatTask, (signed portCHAR *)"LedHeartBeatTask", configMINIMAL_STACK_SIZE, NULL, Priority, NULL );
  34. }
  35.  
  36. portSHORT main(void)
  37. {
  38. //Start Tasks
  39. StartLedHeartBeatTask(tskIDLE_PRIORITY + 1);
  40.  
  41. //RunSchedular
  42. vTaskStartScheduler();
  43.  
  44. return 0;
  45. }

Sample project files: