00001 /* 00002 * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")" 00003 * All rights reserved. 00004 * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University) 00005 * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University) 00006 * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University) 00007 * 00008 * Permission to use, copy, modify, and distribute this software and its 00009 * documentation for any purpose, without fee, and without written agreement is 00010 * hereby granted, provided that the above copyright notice, the following 00011 * two paragraphs and the authors appear in all copies of this software. 00012 * 00013 * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR 00014 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00015 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS" 00016 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00021 * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO 00022 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 00023 * 00024 * Please maintain this header in its entirety when copying/modifying 00025 * these files. 00026 * 00027 * 00028 */ 00029 00043 // INCLUDEs go here (First include the main esos.h file) 00044 // After that, the user can include what they need 00045 #include "esos.h" 00046 #ifdef __linux 00047 #include "esos_pc.h" 00048 #include "esos_pc_stdio.h" 00049 00050 // INCLUDE these so that printf() and our PC hacks work 00051 #include <stdio.h> 00052 #include <sys/select.h> 00053 #include <termios.h> 00054 #include <unistd.h> 00055 #else 00056 #include "esos_pic24.h" 00057 #include "esos_pic24_rs232.h" 00058 #endif 00059 00060 // DEFINEs go here 00061 #ifndef __linux 00062 #define CONFIG_LED1() CONFIG_RB15_AS_DIG_OUTPUT() 00063 #define LED1 _LATB15 00064 #else 00065 #define CONFIG_LED1() printf("called CONFIG_LED1()\n"); 00066 uint8 LED1 = TRUE; // LED1 is initially "on" 00067 #endif 00068 00069 // PROTOTYPEs go here 00070 00071 // GLOBALs go here 00072 // Generally, the user-created semaphores will be defined/allocated here 00073 //static uint8 psz_CRNL[3]= {0x0D, 0x0A, 0}; 00074 00075 00076 #ifdef __linux 00077 /* 00078 * Simulate the timer ISR found on a MCU 00079 * The PC doesn't have a timer ISR, so this task will periodically 00080 * call the timer services callback instead. 00081 * USED ONLY FOR DEVELOPMENT AND TESTING ON PC. 00082 * Real MCU hardware doesn't need this task 00083 */ 00084 ESOS_USER_TASK( __simulated_isr ) { 00085 ESOS_TASK_BEGIN(); 00086 while (TRUE) { 00087 // call the ESOS timer services callback just like a real H/W ISR would 00088 __esos_tmrSvcsExecute(); 00089 ESOS_TASK_WAIT_TICKS( 1 ); 00090 00091 } // endof while(TRUE) 00092 ESOS_TASK_END(); 00093 } // end child_task 00094 #endif 00095 00096 /************************************************************************ 00097 * User supplied functions 00098 ************************************************************************ 00099 */ 00100 00116 ESOS_USER_TASK(heartbeat_LED) { 00117 ESOS_TASK_BEGIN(); 00118 while (TRUE) { 00119 LED1 = !LED1; 00120 #ifdef __linux 00121 if (LED1) { 00122 printf("\a"); 00123 fflush(stdout); 00124 } 00125 #endif 00126 ESOS_TASK_WAIT_TICKS( 500 ); 00127 } // endof while(TRUE) 00128 ESOS_TASK_END(); 00129 } // end upper_case() 00130 00135 ESOS_USER_TASK(echo1) { 00136 static uint8 u8_char; 00137 00138 ESOS_TASK_BEGIN(); 00139 while (TRUE) { 00140 ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM(); 00141 ESOS_TASK_WAIT_ON_GET_UINT8( u8_char ); 00142 ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM(); 00143 u8_char++; 00144 ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM(); 00145 ESOS_TASK_WAIT_ON_SEND_UINT8( u8_char ); 00146 ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM(); 00147 } // endof while(TRUE) 00148 ESOS_TASK_END(); 00149 } // end upper_case() 00150 00151 /**************************************************** 00152 * user_init() 00153 **************************************************** 00154 */ 00155 void user_init(void) { 00156 00157 // Call the hardware-provided routines to print the 00158 // HELLO_MSG to the screen. Must use this call because 00159 // the ESOS communications subsystems is not yet fully 00160 // initialized, since this call is in user_init() 00161 // 00162 // In general, users should call hardware-specific 00163 // function like this. 00164 __esos_unsafe_PutString( HELLO_MSG ); 00165 00166 #ifdef __linux 00167 // register our little ESOS task to mimic MCU's TIMER T1 IRQ which kicks off 00168 // the ESOS S/W timers when they expire 00169 esos_RegisterTask( __simulated_isr ); 00170 #endif 00171 00172 // configure our hardware to support to support our application 00173 CONFIG_LED1(); 00174 00175 // user_init() should register at least one user task 00176 esos_RegisterTask(heartbeat_LED); 00177 esos_RegisterTask(echo1); 00178 00179 } // end user_init()