1 / 44

PALOS: Power Aware Light-weight Operating System (Pseudo-realtime, Application-specific, Light-weight Operating System)

PALOS: Power Aware Light-weight Operating System (Pseudo-realtime, Application-specific, Light-weight Operating System). Andreas Savvides EE Department, Yale University December 6, 2003 Work in Progress… Based on initial tutorial by Sung Park Electrical Engineering Departments

preston
Télécharger la présentation

PALOS: Power Aware Light-weight Operating System (Pseudo-realtime, Application-specific, Light-weight Operating System)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PALOS:Power Aware Light-weight Operating System(Pseudo-realtime, Application-specific, Light-weight Operating System) Andreas Savvides EE Department, Yale University December 6, 2003 Work in Progress… Based on initial tutorial by Sung Park Electrical Engineering Departments University of California, Los Angeles September 18, 2002

  2. PALOS Hardware Overview: MK-2 ARM/THUMB 40MHz Running uCos-ii RS-485 & External Power ADXL 202E MEMS Accelerometer MCU I/F Host Computer, GPS, etc UI: Pushbuttons

  3. Medusa MK-2 Architecture

  4. A Simple Embedded Program

  5. Features of RTOS (hard) • Structure - OS components and user defined Tasks • Multi-tasking • Provides hard time guarantee • Schedulability test guarantees task deadline • Priority Support • Pre-emption of tasks

  6. Drawbacks of RTOS • Interrupt latency of context switching may introduce inefficiency • Pre-emption requires extra attention to shared memory • RTOS is difficult to debug • Commercial RTOS • Portability can be difficult • License Fee • Learning Curve

  7. Do we need RTOS in Wireless Sensor Network? • Application Specific – Need for RTOS • Sensor network monitoring plane’s position and orientation – a missed deadline could lead to plane crash • Sensor network monitoring nuclear plant – a missed deadline could lead to nuclear melt down • Other cases • If a missed deadline results in minor degradation of performance or data qaulity, we can live without an RTOS • As a research organization, we are more concerned about algorithms and development flexibility -> need to address possible migration to RTOS

  8. PALOS: Pseudo-Realtime (soft) • Structure: OS functions and user defined Tasks • Multi-tasking (Event-Driven) • Each tasks is a routine which processes events that are stored in event queues • Supports Inter-task Communication • By queuing events to other tasks, the data between tasks can be exchanged

  9. PALOS: Pseudo-Realtime (soft) • Instead of hard-realtime, palos provides soft-realtime gaurantee (best-effort) • Tasks cannot be pre-emptied (by other tasks) • Tasks run one after the other • No shared memory protection required • Has mechanisms to provide priority, stopping and resuming of tasks

  10. PALOS architecture

  11. PALOS features • Stripped Core • Code Size: 956 Bytes • Mem Size: 548 Bytes • ATmega128 • FLASH size(Code): 128Kbytes • RAM Size (Memory): 4Kbytes. • Typical( 3 drivers, 3 user tasks) • Code Size: 8 KBytes • Mem Size: 1.3 KBytes

  12. Compared to tinyOS • Notion of well-defined tasks • Inter-task communication through the use of separate event queues • More elaborate scheduling scheme where multiple tasks can be periodically or aperiodically scheduled • Easier to debug (minimum use of macros)

  13. PALOS Core • Processor independent algorithms • Provides means of managing event queues and exchanging events among tasks • Provides means of task execution control(slowing, stopping, and resuming) • Supports a scheduler: periodic, and aperiodic functions can be scheduled

  14. Tasks • A task belongs to the palos main control loop • Each task has an entry in palos task table (along with eventQs)

  15. Inter-task Communication • Events are exchanged using the service provided by PALOS core

  16. Scheduling with Software Timer • Periodic or aperiodic events can be scheduled using Delta Q and Timer Interrupt • When event expires appropriate event handler is called

  17. Event Driven Task • Typical task routine • while (eventQ != isEmpty){ • dequeue event; • process event; • }

  18. Task Execution Control • Execution Control using task counter • A task counter is associated with each task • Counters are initialized to pre-defined values • Counters are decremented 1) every main control loop iteration (relative timing) 2) by timer interrupts (exact timing) • When counter reaches zero, the task routine is called. The counter is reset to reload value.

  19. Task Execution Control • Normal Task: Set the counter to 0 and reload value to 0 • Task slow down: Set the counter to large positive value • Task Suspension: Set the counter to pre-set value (e.x. –1) • Task Resumption: Reset the counter to positive value

  20. PALOS v0.1 implementation – Task Table Structure • /* Generic event queue structure */ • typedef struct { • SHORT (*initHandler)(void); • SHORT (*taskHandler)(void); • SHORT execCounter; /* Counter to be used for task speed control */ • /* when counter reaches zero the task is executed */ • SHORT reloadCounter; /* execCouter is reset the reload counter value after it */ • /* reaches zero */ • SHORT maxEvent; /* stores max number of events that can be processed per */ • /* iteration. can be used to give priority */ • BOOL isExactTiming; /* indicates whether the counter is decremented */ • /* following exact timing */ • USHORT header; /* header ptr */ • USHORT trailer; /* trailer ptr */ • USHORT eventStrSize; /* member structure size */ • USHORT maxQsize; /* max number queue size */ • USHORT curQsize; /* current queue size */ • CHAR isValid; /* indicates whether this is valid entry */ • void *event; • } taskStr;

  21. PALOS v0.1 implementation – Main Control Loop • // main loop • while (1){ // run each task in order • for (i=0; i< globalTaskID; i++){ • isExact = qArray[i].isExactTiming; • tmpCntr=qArray[i].execCounter; • if ( tmpCntr != TASK_DISABLED) { /* task is not disabled */ • if ( tmpCntr ) { /* counter hasn't expired */ • if (!isExact) • qArray[i].execCounter--; • } • else { /* exec counter expired */ • if (isExact) • PALOSSCHED_TIMER_INTR_DISABLE; • qArray[i].execCounter = qArray[i].reloadCounter; • if (isExact) • PALOSSCHED_TIMER_INTR_ENABLE; • /* run the task routine */ • (*qArray[i].taskHandler)(); • } • } • } • }

  22. PALOS Core functions • SHORT palosEvent_register(SHORT (*initFunc)(void), SHORT (*taskFunc)(void), LONG xCounter, LONG rCounter, USHORT maxEv, • BOOL exactTiming,USHORT eventStrSize, USHORT maxQsize, void *ev); • SHORT palosEvent_putEvent( USHORT taskID, void *ev, CHAR isAtomic); • SHORT palosEvent_getEvent( USHORT taskID, void *ev, CHAR isAtomic); • SHORT palosEvent_start(USHORT taskID, LONG excCntr, LONG reldCntr); • SHORT palosEvent_stop(USHORT taskID); • SHORT palosEvent_maxEvent(USHORT taskID, USHORT maxEv); • SHORT palosEvent_exactTiming(USHORT taskID, BOOL exactTiming); • SHORT palosSched_schedule( USHORT tid, ULONG param, hndlrWrapper *tmrHandler, ULONG ticks, CHAR isPeriodic); • SHORT palosSched_cancel( USHORT tid, hndlrWrapper *tmrHandler );

  23. PALOS architecture – Drivers and Managers

  24. Drivers (HAL) • Abstracts hardware (processor-specific and platform-specific) from the task level • The layering supports portability • Processors: ATmega103, ATmega128L, TMS320, STrongThumb • Platforms: iBadge, MICA, MK2 • Examples: • Processor-specific: UART, SPI, Timers.. • Platform-specific: RFM, LEDs, Sensors

  25. Managers (Optional) • Extra abstraction layer that handles a protocol or handshaking with external modules • iBadge: Bluetooth Manager

  26. UART0 Driver • void UART0_Init(); • void UART0_Enable(); • void UART0_Disable(); • UCHAR UART0_NewData(); • UCHAR UART0_GetByte(); • USHORT UART0_Get2Bytes(); • UCHAR UART0_GetNBytes( UCHAR * ptr_ch, UCHAR nN ); • USHORT UART0_Check2Bytes(); • UCHAR UART0_GetError(); • UCHAR UART0_FreeSpace(); • BOOL UART0_WriteByte( UCHAR ch ); • BOOL UART0_Write2Bytes( USHORT sh ); • BOOL UART0_WriteNBytes( UCHAR * ptr_ch, UCHAR nN );

  27. Task Implementation with PALOS • Need to define event structure • Implement initialization function • Implement main task function • Implement initTask() • Performs system initialization • Registers different task to PALOS core • Implement initSched() • Initial scheduling of events

  28. Task Implementation with PALOS • if ( tmpCntr != TASK_DISABLED) { • /* task is not disabled */ • if ( tmpCntr ) { • /* counter hasn't expired */ • if (!isExact) • qArray[i].execCounter--; • } • else { /* exec counter expired */ • if (isExact) • PALOSSCHED_TIMER_INTR_DISABLE; • qArray[i].execCounter = qArray[i].reloadCounter; • if (isExact) • PALOSSCHED_TIMER_INTR_ENABLE; • /* run the task routine */ • (*qArray[i].taskHandler)(); • } • } • } • } • /* should never get here */ • return; • } • void main(void) • { • SHORT i; • USHORT tmpCntr; • BOOL isExact; • // event handler initialization • palosEvent_init(); • // The user's task is registered and • // scheduled by this function • initTask(); • // initialize each function • for (i=0; i< globalTaskID; i++){ • (*qArray[i].initHandler)(); • } • // User needs to define this function to • // schedule events • initSched(); • // main loop • while (1){ // run each task in order • for (i=0; i< globalTaskID; i++){ • isExact = qArray[i].isExactTiming; • tmpCntr=qArray[i].execCounter;

  29. Example Application for MICA node • StringIn Task: gets string from stdin • StringOut Task: outputs string to stdout • Menu Task: runs the menu state machine to control the frequency of LED flashing frequency

  30. stringOutTask.h • /* stringOut task event structure */ • typedef struct { • UCHAR *str; /* pointer to string */ • UCHAR size; /* size of the string */ • USHORT eventID; • ULONG eventParam; • hndlrWrapper stringOut_TXdone; /* handler called when tx is done */ • } stringOut_Event;

  31. stringOutTask.c • SHORT stringOut_task() { • UCHAR availSize; • while ((stringOut_hoqValid == true) || • (palosEvent_getEvent(stringOutID, &stringOut_hoq, TASK_NON_ATOMIC) • !=PALOSEVENT_QEMPTY)){ • availSize = UART0_FreeSpace(); • if ( stringOut_hoq.size <= availSize ) { • UART0_WriteNBytes(stringOut_hoq.str, stringOut_hoq.size); • HANDLER_CALL(stringOut_hoq.stringOut_TXdone, stringOut_hoq.eventID, stringOut_hoq.eventParam); • stringOut_hoqValid=false; • } • else { • UART0_WriteNBytes(stringOut_hoq.str, availSize); • stringOut_hoq.str += availSize; • stringOut_hoq.size -= availSize; • stringOut_hoqValid=true; • break; • } • } • return PALOSEVENT_TASK_DONE; • } • SHORT stringOut_init() { • stringOut_hoqValid=false; • // stringOut initialization • UART0_Init(); • return 0; • }

  32. initTask.c : initTask() • void initTask() { • SYS_Init(); • stringOutID=palosEvent_register(stringOut_init, stringOut_task, • STRINGOUT_DEF_CNTR, STRINGOUT_DEF_RCNTR, • STRINGOUT_DEF_MAXEVENT, false, • sizeof(stringOut_Event), STRINGOUT_Q_SIZE, • (void *)stringOutEvent); • stringInID=palosEvent_register(stringIn_init, stringIn_task, • STRINGIN_DEF_CNTR, STRINGIN_DEF_RCNTR, • STRINGIN_DEF_MAXEVENT, false, • sizeof(stringIn_Event), STRINGIN_Q_SIZE, • (void *)stringInEvent); • menuID=palosEvent_register(menu_init, menu_task, • MENU_DEF_CNTR, MENU_DEF_RCNTR, • MENU_DEF_MAXEVENT, false, • sizeof(menu_Event), MENU_Q_SIZE, • (void *)menuEvent); • palosSchedID=palosEvent_register(palosSched_init, palosSched_task, • PALOSSCHED_DEF_CNTR, PALOSSCHED_DEF_RCNTR, • PALOSSCHED_DEF_MAXEVENT, false, • sizeof(palosSched_Event), PALOSSCHED_EVENTQ_SIZE, • (void *)tEvent); • }

  33. initTask.c : initSched() • void initSched() { • //schedule an event • stringOut_msg(initMsg, MENU_START,0, HANDLER_WRAP(menu_handler)); • } • stringOutTask.c : • void stringOut_msg(CHAR *str, USHORT id, ULONG param, hndlrWrapper *hnd){ • stringOut_Event outgoingMsgEvent; • outgoingMsgEvent.str=str; • outgoingMsgEvent.size=strLength(str); • outgoingMsgEvent.eventID=id; • outgoingMsgEvent.eventParam=param; • HANDLER_COPY(&(outgoingMsgEvent.stringOut_TXdone), hnd); • palosEvent_putEvent(stringOutID, &outgoingMsgEvent, TASK_NON_ATOMIC); • }

  34. MICA demo

  35. menuTask.c • void menu_ledsched(USHORT id, ULONG param){ • CHAR tmpID; • tmpID=(CHAR)id; • switch(tmpID){ • case LEDCHOICE_RED: • redToggle(); • break; • case LEDCHOICE_GREEN: • greenToggle(); • break; • case LEDCHOICE_YELLOW: • yellowToggle(); • break; • default: /* shouldn't get here */ • redOn(); • yellowOn(); • greenOn(); • break; • } • } • case MENU_FREQ_CHECK: • periodVal=strToShort(incomingMsg); • if ( periodVal > 0 && periodVal <=10000) { • palosSched_cancel(ledChoice, HANDLER_WRAP(menu_ledsched)); • palosSched_schedule(ledChoice, 0, HANDLER_WRAP(menu_ledsched), • periodVal, PALOSSCHED_PERIODIC); • stringOut_msg(msg5, MENU_RESTART_TX, 0, HANDLER_WRAP( menu_handler)); • }

  36. PALOS Development Environment • Directory Structure

  37. PALOS Development Environment • Compiler: CVAVR (possible port to AVR-GCC) • Current release v.01 • https://sourceforge.net/project/showfiles.php?group_id=61125 • If you want to do development • Needs to obtain account from http://sourceforge.net • Email me your account id and what part of the code you will be working on • Need to use CVS client to access CVS repository

  38. Installing CVS client under Windows • Windows CVS client setup(wincvs) • Download and install wincvs from http://prdownloads.sourceforge.net/cvsgui/WinCvs13b8.zip?download • Download and install ssh from http://prdownloads.sourceforge.net/sfsetup/ssh-1.2.14-win32bin.zip?download • Download and install sourcefourge setup utility “sfssetup” from http://prdownloads.sourceforge.net/sfsetup/sfsetup-1.3.zip?download

  39. Setting up wincvs • PALOS CVS Repository Setup: Admin->Preferences

  40. Setting up wincvs • Checking Out Palos0.1 module: Create->Check Out Module

  41. Software Engineering Practices • Make use of CVS for development coordination (also backup and revision control) • If you write something, make it modular(drivers, task, library) • Spend extra time to refine the interface so that other people can easily use it • Write a simple example code that can test your contributed module • More you contribute, more useful it becomes  Everybody counts!

  42. Contributions Needed • Communication Module: • RFM driver, Encoding and Decoding Task, MAC layer etc.. • Drivers • SPI, timer0, timer2, watchdog timer, ADC, etc.. • Tasks • Sensing, Networking related tasks • PALOS core • Random number generator, and other library functions • Porting to AVR-GCC

  43. References • Michael Melkonian, “Get by Without an RTOS”, Embedded Systems Programming Mag, vol 3. No. 10 Sept., 2000 • Jack W. Crenshaw, “Mea Culpa (Is RTOS needed?)”, http://www.embedded.com/story/OEG20020222S0023 • Karl Fogel, “Open Source Development with CVS”, http://cvsbook.red-bean.com/ • CVS FAQ, http://www.cs.utah.edu/dept/old/texinfo/cvs/FAQ.txt

More Related