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:
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
#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)
#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.