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 00045 // INCLUDEs go here (First include the main esos.h file) 00046 // After that, the user can include what they need 00047 #include "esos.h" 00048 #ifdef __linux 00049 #include "esos_pc.h" 00050 #include "esos_pc_stdio.h" 00051 00052 // INCLUDE these so that printf() and our PC hacks work 00053 #include <stdio.h> 00054 #include <sys/select.h> 00055 #include <termios.h> 00056 #include <unistd.h> 00057 #else 00058 #include "esos_pic24.h" 00059 #include "esos_pic24_rs232.h" 00060 #endif 00061 00062 // DEFINEs go here 00063 #ifndef __linux 00064 #define CONFIG_LED1() CONFIG_RB15_AS_DIG_OUTPUT() 00065 #define LED1 _LATB15 00066 #else 00067 #define CONFIG_LED1() printf("called CONFIG_LED1()\n"); 00068 uint8 LED1 = TRUE; // LED1 is initially "on" 00069 #endif 00070 00071 // PROTOTYPEs go here 00072 00073 // GLOBALs go here 00074 // Generally, the user-created semaphores will be defined/allocated here 00075 static uint8 psz_CRNL[3]= {0x0D, 0x0A, 0}; 00076 00077 00078 #ifdef __linux 00079 /* 00080 * Simulate the timer ISR found on a MCU 00081 * The PC doesn't have a timer ISR, so this task will periodically 00082 * call the timer services callback instead. 00083 * USED ONLY FOR DEVELOPMENT AND TESTING ON PC. 00084 * Real MCU hardware doesn't need this task 00085 */ 00086 ESOS_USER_TASK( __simulated_isr ) { 00087 ESOS_TASK_BEGIN(); 00088 while (TRUE) { 00089 // call the ESOS timer services callback just like a real H/W ISR would 00090 __esos_tmrSvcsExecute(); 00091 ESOS_TASK_WAIT_TICKS( 1 ); 00092 00093 } // endof while(TRUE) 00094 ESOS_TASK_END(); 00095 } // end child_task 00096 #endif 00097 00098 /************************************************************************ 00099 * User supplied functions 00100 ************************************************************************ 00101 */ 00102 00118 ESOS_USER_TASK(heartbeat_LED) { 00119 ESOS_TASK_BEGIN(); 00120 while (TRUE) { 00121 LED1 = !LED1; 00122 #ifdef __linux 00123 if (LED1) { 00124 printf("\a"); 00125 fflush(stdout); 00126 } 00127 #endif 00128 ESOS_TASK_WAIT_TICKS( 500 ); 00129 } // endof while(TRUE) 00130 ESOS_TASK_END(); 00131 } // end upper_case() 00132 00137 ESOS_USER_TASK(upper_case) { 00138 static uint8 u8_char; 00139 00140 ESOS_TASK_BEGIN(); 00141 while (TRUE) { 00142 ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM(); 00143 ESOS_TASK_WAIT_ON_GET_UINT8(u8_char); 00144 ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM(); 00145 if ((u8_char >= 'a') & (u8_char <= 'z')) { 00146 u8_char = u8_char - 'a' + 'A'; 00147 } 00148 ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM(); 00149 ESOS_TASK_WAIT_ON_SEND_UINT8(u8_char); 00150 ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM(); 00151 } // endof while(TRUE) 00152 ESOS_TASK_END(); 00153 } // end upper_case() 00154 00155 /**************************************************** 00156 * user_init() 00157 **************************************************** 00158 */ 00159 void user_init(void) { 00160 00161 // Call the hardware-provided routines to print the 00162 // HELLO_MSG to the screen. Must use this call because 00163 // the ESOS communications subsystems is not yet fully 00164 // initialized, since this call is in user_init() 00165 // 00166 // In general, users should call hardware-specific 00167 // function like this. 00168 __esos_unsafe_PutString( HELLO_MSG ); 00169 00170 #ifdef __linux 00171 // register our little ESOS task to mimic MCU's TIMER T1 IRQ which kicks off 00172 // the ESOS S/W timers when they expire 00173 esos_RegisterTask( __simulated_isr ); 00174 #endif 00175 00176 // configure our hardware to support to support our application 00177 CONFIG_LED1(); 00178 00179 // user_init() should register at least one user task 00180 esos_RegisterTask(heartbeat_LED); 00181 esos_RegisterTask(upper_case); 00182 00183 } // end user_init()