Go Down

Topic: DuinOS: Small and Simple OS based on FreeRTOS (Read 6 times) previous topic - next topic

LAVco

Feb 25, 2011, 01:38 am Last Edit: Feb 25, 2011, 02:54 am by LAVco Reason: 1
Continuation of the original thread located here; http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256745982

Well I've been making some progress with the FreeRTOS port for Arduino.

- Ethernet Library works

Polling three sensors using bitbang, serial interface, and web server on my Mega - Serial and Ethernet are non interrupt mode at the moment.  Pretty impressive what can be packed into an 8-bit MCU.  

A few modifications are needed with the DuinOS files but basically it strips all of the Arduino friendly functions/macros used to call the native FreeRTOS functions.  I am using the native FreeRTOS API functions for simplicity.  It simply doesn't make sense to re-invent the wheel considering documentation already exists.

Here is a code snippet:
Code: [Select]
static void vNetSvcTask(void *pvParameters) {
 /* The parameters are not used. */
 ( void ) pvParameters;
 
 /* Initialize the web server library
    with the IP address and port you want to use
    (port 80 is default for HTTP): */
 WebServer webserver(PREFIX, 80);
 
 /*  */
 portENTER_CRITICAL();
 {
   /* start the Ethernet connection and the server */
   Ethernet.begin(mac, ip);
   
   /* web server related */
   
   /* setup our default command that will be run when the user accesses
    * the root page on the server */
   webserver.setDefaultCommand(&vHomeCmd);
 
   /* setup our default command that will be run when the user accesses
    * a page NOT on the server */
   webserver.setFailureCommand(&vFailCmd);
 
   /* run the same command if you try to load /index.html, a common
    * default page name */
   webserver.addCommand("message.xml",  &vXmlCmd);
   webserver.addCommand("index.html",   &vHomeCmd);
   webserver.addCommand("setup.html",   &vSetupCmd);
   webserver.addCommand("units.html",   &vUnitsCmd);
   webserver.addCommand("serial.html",  &vSerialCmd);
   webserver.addCommand("network.html", &vNetworkCmd);
   webserver.addCommand("status.html",  &vStatusCmd);
 
   /* start the webserver */
   webserver.begin();
 }
 portEXIT_CRITICAL();

 /* Cycle for ever, delaying then checking all the other tasks are still
    operating without error. */
 for( ;; ) {
   char buff[64];
   int len = 64;
   
   /* process incoming connections one at a time forever */
   webserver.processConnection(buff, &len);
 }
}

int main(void) {

 /* init mcu */
 init();
 
 /* init net-sensor to defaults */
 vInitConfig();
 
 // Pin change interrupt control register - enables interrupt vectors
 // Bit 2 = enable PC vector 2 (PCINT23..16)
 // Bit 1 = enable PC vector 1 (PCINT14..8)
 // Bit 0 = enable PC vector 0 (PCINT7..0)
 //PCICR |= (1 << PCIE0);
   
 // Pin change mask registers decide which pins are enabled as triggers
 //PCMSK0 |= (1 << PCINT5);

 // enable interrupts
 //interrupts();

 
 /* create tasks */
 xTaskCreate(vShtReadTask, (signed portCHAR *) "ShtRead", 304, NULL, NORMAL_PRIORITY, &xShtReadHandle);
 xTaskCreate(vMsReadTask,  (signed portCHAR *) "MsRead",  304, NULL, NORMAL_PRIORITY, &xMsReadHandle);
 xTaskCreate(vNetSvcTask,  (signed portCHAR *) "NetSvc",  700, NULL, NORMAL_PRIORITY, &xNetSvcHandle);
 xTaskCreate(vPrintTask,   (signed portCHAR *) "SPrint",  208, NULL, NORMAL_PRIORITY, NULL);
 
 /* start scheduler */
 vTaskStartScheduler();
 
 /* will only get here if there was insufficient memory  */
 for( ;; );
 
 return 1;
}


DuinOS.h
Code: [Select]
#ifndef DuinOS__h
#define DuinOS__h

#ifndef FREERTOS_ARDUINO
 #define FREERTOS_ARDUINO 1
#endif

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdlib.h>
#include <string.h>

//#ifdef GCC_MEGA_AVR
/* EEPROM routines used only with the WinAVR compiler. */
#include <avr/eeprom.h>
//#endif

/* Scheduler include files. */
#include "DuinOS/FreeRTOS.h"
#include "DuinOS/task.h"

#ifdef __cplusplus
} // extern "C"
#endif

//extern unsigned portBASE_TYPE mainLoopPriority;

//In small devices, we use only 3 priorities:
#define LOW_PRIORITY (tskIDLE_PRIORITY)
#define NORMAL_PRIORITY (tskIDLE_PRIORITY + 1)
#define HIGH_PRIORITY (tskIDLE_PRIORITY + 2)

// leave this for arduino libraries
#define delay(ticks) vTaskDelay(ticks)

#endif


main.cpp (just saves you from having to include header files but this file can be removed altogether)
Code: [Select]
#include <WProgram.h>

// add DuinOS support

#include "DuinOS.h"


Next is to get serial and Ethernet working using Interrupts to take full advantage of the RTOS.

Well that's all for now.
Common sense is not so common...

Bima

Hi,

I have just downloaded the DuinOS and was trying to get it working on the Arduino mega 2560 but with no success. has anyone had any success with the arduino 2560?

Thanks

rama.stefan

Hi!

Has anyone managed to work with Arduino+ DuinOS+ Ethernet Library, using the Arduino IDE?
What needs to be modified in the Ethernet Library?

Thank you in advance!

LAVco

rama.stefan the DuinOS files would need to modified to accept the Mega 2560.  There isn't much of a difference between them.

Bima yes, the Ethernet library works "as is" provided no other SPI devices are being used.  The Ethernet library needs to be initialized within the task declaration using the portENTER_CRITICAL() call as shown in my posted example (e.g. vNetSvcTask).  Also, this was tested and is being used on a mega and not the Uno (limited RAM).

Eric
Common sense is not so common...

Bima

Hi LAVco,

I have changed the contents of boards.txt on the arduino mega 2560 to use the arduino.DuinOS core and also I have modified FreeRTOSConfig.h to include the AVR Atmega 2560 with the same settings as the 1280. Then I tried the simple blinking example, it would compile but the LED is not blinking when I upload it on the board.

Go Up