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 00037 // INCLUDEs go here (First include the main esos.h file) 00038 // After that, the user can include what they need 00039 #include "esos.h" 00040 #ifdef __linux 00041 #include "esos_pc.h" 00042 #include "esos_pc_stdio.h" 00043 00044 // INCLUDE these so that printf() and our PC hacks work 00045 #include <stdio.h> 00046 #include <sys/select.h> 00047 #include <termios.h> 00048 #include <unistd.h> 00049 #else 00050 #include "esos_pic24.h" 00051 #include "esos_pic24_rs232.h" 00052 #endif 00053 00054 // DEFINEs go here 00055 #ifndef __linux 00056 #define CONFIG_LED1() CONFIG_RB15_AS_DIG_OUTPUT() 00057 #define LED1 _LATB15 00058 #else 00059 #define CONFIG_LED1() printf("Called CONFIG_LED1()\n"); 00060 uint8 LED1 = TRUE; // LED1 is initially "on" 00061 #endif 00062 00063 // PROTOTYPEs go here 00064 00065 // GLOBALs go here 00066 // Generally, the user-created semaphores will be defined/allocated here 00067 static uint8 psz_CRNL[3]= {0x0D, 0x0A, 0}; 00068 00069 00070 #ifdef __linux 00071 /* 00072 * Simulate the timer ISR found on a MCU 00073 * The PC doesn't have a timer ISR, so this task will periodically 00074 * call the timer services callback instead. 00075 * USED ONLY FOR DEVELOPMENT AND TESTING ON PC. 00076 * Real MCU hardware doesn't need this task 00077 */ 00078 ESOS_USER_TASK( __simulated_isr ) { 00079 ESOS_TASK_BEGIN(); 00080 while (TRUE) { 00081 // call the ESOS timer services callback just like a real H/W ISR would 00082 __esos_tmrSvcsExecute(); 00083 ESOS_TASK_WAIT_TICKS( 1 ); 00084 00085 } // endof while(TRUE) 00086 ESOS_TASK_END(); 00087 } // end child_task 00088 #endif 00089 00090 /************************************************************************ 00091 * User supplied functions 00092 ************************************************************************ 00093 */ 00094 00095 /* 00096 * An ESOS task to mimic the heartbeat LED found 00097 * in the PIC24 support library code used in Chapters 8-13. 00098 * 00099 * Toggle LED1, wait 250ms, repeat forever. 00100 * 00101 * \note Since this heartbeat is performed in an ESOS task, 00102 * a flashing LED indicates that the ESOS scheduler is still 00103 * running properly. If the LED quits flashing, the ESOS 00104 * scheduler is no longer rotating through the runnable task 00105 * list. The most likely reason is that some task has ceased 00106 * "yielding" the processor, and is caught in some deadlock 00107 * or otherwise infinite loop. 00108 * \hideinitializer 00109 */ 00110 ESOS_USER_TASK(heartbeat_LED) { 00111 ESOS_TASK_BEGIN(); 00112 while (TRUE) { 00113 LED1 = !LED1; 00114 00115 #ifdef __linux 00116 if (LED1) { 00117 printf("\a"); 00118 fflush(stdout); 00119 } 00120 #endif 00121 00122 ESOS_TASK_WAIT_TICKS( 500 ); 00123 } // endof while(TRUE) 00124 ESOS_TASK_END(); 00125 } // end heartbeat_LED task 00126 00127 /**************************************************** 00128 * user_init() 00129 **************************************************** 00130 */ 00131 void user_init(void) { 00132 00133 // Call the hardware-provided routines to print the 00134 // HELLO_MSG to the screen. Must use this call because 00135 // the ESOS communications subsystems is not yet fully 00136 // initialized, since this call is in user_init() 00137 // 00138 // In general, users should call hardware-specific 00139 // function like this. 00140 00141 __esos_unsafe_PutString( HELLO_MSG ); 00142 00143 #ifdef __linux 00144 // register our little ESOS task to mimic MCU's TIMER T1 IRQ which kicks off 00145 // the ESOS S/W timers when they expire 00146 esos_RegisterTask( __simulated_isr ); 00147 #endif 00148 00149 // configure our hardware as needed by the tasks 00150 CONFIG_LED1(); 00151 00152 // user_init() should register at least one user task 00153 esos_RegisterTask(heartbeat_LED); 00154 00155 } // end user_init()