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 00030 // Documentation for this file. If the \file tag isn't present, 00031 // this file won't be documented. 00038 //#include "esos_irq.h" 00039 #include "esos_pic24.h" 00040 00041 volatile uint32 esos_tick_count; 00042 volatile uint8 sub_tick; 00043 00044 // prototype for the ESOS timer service function 00045 extern void __esos_tmrSvcsExecute(void); 00046 00047 /****************************************************/ 00048 /* 00049 * \brief Increments the ESOS system tick 00050 * 00051 * \pre TMR1 is initialized with __esos_hw_InitSystemTick 00052 * 00053 * This ISR provides the mechanism for incrementing ESOS's 00054 * 1.0ms system tick. Using Timer 1, we can call this ISR 00055 * every 1.0ms and increment esos_tick_count. Or, we can 00056 * have T1 call this ISR every X ms, and increment the 00057 * value esos_tick_count by X 00058 * 00059 * \note The ESOS system tick will overflow in 2^32 msec 00060 ********************************************************/ 00061 void _ISRFAST _T1Interrupt (void) { 00062 esos_tick_count++; // increment the ESOS system tick by 00063 _T1IF = 0; // clear the timer interrupt bit 00064 __esos_tmrSvcsExecute(); // let ESOS implement the S/w tmr service 00065 } 00066 00067 /****************************************************/ 00068 /* 00069 * \brief Initializes the ESOS system tick. 00070 * 00071 * \pre None assumed 00072 * 00073 * \post Sets up the PIC24 MCU's Timer1 to generate the 1.0ms tick 00074 * required by ESOS. 00075 * 00076 * The (platform-independent) ESOS initialization code will 00077 * call this function to setup and init the hardware (PIC24 00078 * MCU, in this case) to create the required IRQs to generate 00079 * the 1.0ms ESOS system tick. 00080 * 00081 * \note We can either generate an IRQ every 1.0ms or longer period, 00082 * we just need to make sure that ISR that increments the tick 00083 * count is consistent. 00084 ********************************************************/ 00085 void __esos_hw_InitSystemTick(void) { 00086 00087 // FOR NOW, we will init our usual PIC24 development setup here. 00088 // THIS REALLY DOESN'T BELONG HERE!!!!!!! 00089 configClock(); //config clock 00090 00091 /* Configure Timer1 to: 00092 ** operate during IDLE, use a 64x prescaler, and the internal clock 00093 */ 00094 T1CON = T1_IDLE_CON + T1_PS_1_64 + T1_SOURCE_INT; 00095 00096 PR1 = MS_TO_TICKS(1, 64); // 1 ms interrupt interval 00097 TMR1 = 0; // clear T1's count 00098 _T1IF = 0; // clear interrupt flag 00099 00100 /* set T1's priority to be the highest possible for a PIC24 user IRQ 00101 ** User IRQs (if used) will be a lower IRQ priority, so the tick will 00102 ** get serviced in a timely manner 00103 */ 00104 _T1IP = 7; 00105 _T1IE = 1; // enable the interrupt 00106 T1CONbits.TON = 1; // turn on the timer 00107 00108 } // end __esos_hw_InitSystemTick() 00109 00110 /****************************************************/ 00111 /* 00112 * \brief Returns the ESOS system tick count. 00113 * 00114 * \pre ESOS system tick is running/working. 00115 * 00116 * \return A 32-bit value of the number of ESOS system ticks 00117 * since the system has booted. 00118 * 00119 ********************************************************/ 00120 uint32 __esos_hw_GetSystemTickCount(void) { 00121 return esos_tick_count; 00122 } // end __esos_hw_GetSystemTickCount() 00123