esos_skel.c - basic ESOS template¶
ESOS application program similar to the “Echo” program echo.c in Chapter 8. (See Figure 8.6 in the text.) This version of “echo” program which waits for UART1 RX character and echos it back to UART1 TX with all lowercase letters converted to uppercase. Use this program to test your UART connection under ESOS.
Application also has a flashing LED on RB15. Flashing LED is generated by a user task that runs simultaneously with the echo task above.
Note
Demonstrates multitasking in ESOS
- INCLUDEs go here (First include the main esos.h file)
- After that, the user can include what they need
#include "esos.h"
#ifdef __linux
#include "esos_pc.h"
#include "esos_pc_stdio.h"
INCLUDE these so that printf() and our PC hacks work
#include <stdio.h>
#include <sys/select.h>
#include <termios.h>
#include <unistd.h>
#else
#include "esos_pic24.h"
#include "esos_pic24_rs232.h"
#endif
DEFINEs go here
#ifndef __linux
#define CONFIG_LED1() CONFIG_RB15_AS_DIG_OUTPUT()
#define LED1 _LATB15
#else
#define CONFIG_LED1() printf("called CONFIG_LED1()\n");
uint8_t LED1 = TRUE; // LED1 is initially "on"
#endif
PROTOTYPEs go here
- GLOBALs go here
- Generally, the user-created semaphores will be defined/allocated here
#ifdef __linux
- Simulate the timer ISR found on a MCU
- The PC doesn’t have a timer ISR, so this task will periodically call the timer services callback instead. USED ONLY FOR DEVELOPMENT AND TESTING ON PC. Real MCU hardware doesn’t need this task
ESOS_USER_TASK( __simulated_isr ) {
ESOS_TASK_BEGIN();
while (TRUE) {
call the ESOS timer services callback just like a real H/W ISR would
__esos_tmrSvcsExecute();
ESOS_TASK_WAIT_TICKS( 1 );
} // endof while(TRUE)
ESOS_TASK_END();
} // end child_task
#endif
/************************************************************************
* User supplied functions
************************************************************************
*/
/**
* An ESOS task to mimic the heartbeat LED found
* in the PIC24 support library code used in Chapters 8-13.
*
* Toggle LED1, wait 250ms, repeat forever.
*
* \note Since this heartbeat is performed in an ESOS task,
* a flashing LED indicates that the ESOS scheduler is still
* running properly. If the LED quits flashing, the ESOS
* scheduler is no longer rotating through the runnable task
* list. The most likely reason is that some task has ceased
* "yielding" the processor, and is caught in some deadlock
* or otherwise infinite loop.
* \hideinitializer
*/
ESOS_USER_TASK(heartbeat_LED) {
ESOS_TASK_BEGIN();
while (TRUE) {
LED1 = !LED1;
#ifdef __linux
if (LED1) {
printf("\a");
fflush(stdout);
}
#endif
ESOS_TASK_WAIT_TICKS( 500 );
} // endof while(TRUE)
ESOS_TASK_END();
} // end upper_case()
/**
* Read a single character from the "in" stream, convert lowercase
* letters to uppercase, and send those chars back out the "out" stream
*/
ESOS_USER_TASK(upper_case) {
static uint8_t u8_char;
ESOS_TASK_BEGIN();
while (TRUE) {
ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM();
ESOS_TASK_WAIT_ON_GET_UINT8(u8_char);
ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM();
if ((u8_char >= 'a') & (u8_char <= 'z')) {
u8_char = u8_char - 'a' + 'A';
}
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM();
ESOS_TASK_WAIT_ON_SEND_UINT8(u8_char);
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM();
} // endof while(TRUE)
ESOS_TASK_END();
} // end upper_case()
/****************************************************
* user_init()
****************************************************
*/
void user_init(void) {
Call the hardware-provided routines to print the HELLO_MSG to the screen. Must use this call because the ESOS communications subsystems is not yet fully initialized, since this call is in user_init()
In general, users should call hardware-specific function like this.
__esos_unsafe_PutString( HELLO_MSG );
#ifdef __linux
register our little ESOS task to mimic MCU’s TIMER T1 IRQ which kicks off the ESOS S/W timers when they expire
esos_RegisterTask( __simulated_isr );
#endif
configure our hardware to support to support our application
CONFIG_LED1();
user_init() should register at least one user task
esos_RegisterTask(heartbeat_LED);
esos_RegisterTask(upper_case);
} // end user_init()