pic24_clockfreq.h

Go to the documentation of this file.
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 
00031 // Documentation for this file. If the \file tag isn't present,
00032 // this file won't be documented.
00070 #ifndef _PIC24_CLOCKFREQ_H_
00071 #define _PIC24_CLOCKFREQ_H_
00072 
00096 #ifndef CLOCK_CONFIG
00097 #define CLOCK_CONFIG SIM_CLOCK
00098 #endif
00099 
00101 
00132 //  Table entries are:
00133 //      #define name                    Unique index  FNOSC_SEL     FCY        POSCMD_SEL   POSC_FREQ  Processor                           configClock name                           Magic number of 498
00134 //      ------------------------------  ------------  ------------  ---------  ----------   ---------  ----------------------------------  ----------------                           -------------------
00135 #define SIM_CLOCK                       0,            -1,            1000000L, POSCMD_NONE,       -1,  1,                                  configClockSim,                            498
00136 #define FRCPLL_FCY16MHz                 1,            FNOSC_FRCPLL, 16000000L, POSCMD_NONE,       -1,  (PIC24F_DEFINED || PIC24FK_DEFINED),  configClockFRCPLL_FCY16MHz,                498
00137 #define FRC_FCY4MHz                     2,            FNOSC_FRC,     4000000L, POSCMD_NONE,       -1,  (PIC24F_DEFINED || PIC24FK_DEFINED),  configClockFRC_FCY4MHz,                    498
00138 #define PRI_NO_PLL_7372KHzCrystal       3,            FNOSC_PRI,     3686400L, POSCMD_XT,   7372800L,  (PIC24F_DEFINED || PIC24FK_DEFINED || PIC24H_DEFINED || dsPIC33F_DEFINED), configClockPRI_NO_PLL_7372KHzCrystal,      498
00139 #define FRC_FCY3685KHz                  4,            FNOSC_FRC,     3685000L, POSCMD_NONE,       -1,  (PIC24H_DEFINED || dsPIC33F_DEFINED),                     configClockFRC_FCY3685KHz,                 498
00140 #define FRCPLL_FCY40MHz                 5,            FNOSC_FRCPLL, 40000000L, POSCMD_NONE,       -1,  (PIC24H_DEFINED || dsPIC33F_DEFINED),                     configClockFRCPLL_FCY40MHz,                498
00141 #define PRIPLL_7372KHzCrystal_40MHzFCY  6,            FNOSC_PRIPLL, 40000000L, POSCMD_XT,   7372800L,  (PIC24H_DEFINED || dsPIC33F_DEFINED),                     configClockPRIPLL_7372KHzCrystal_40MHzFCY, 498
00142 #define PRIPLL_8MHzCrystal_40MHzFCY     7,            FNOSC_PRIPLL, 40000000L, POSCMD_XT,   8000000L,  (PIC24H_DEFINED || dsPIC33F_DEFINED),                     configClockPRIPLL_8MHzCrystal_40MHzFCY,    498
00143 #define PRIPLL_8MHzCrystal_16MHzFCY     8,            FNOSC_PRIPLL, 16000000L, POSCMD_XT,   8000000L,  (PIC24F_DEFINED || PIC24FK_DEFINED),                     configClockPRIPLL_8MHzCrystal_16MHzFCY,    498
00144 #define PRI_8MHzCrystal_4MHzFCY         9,            FNOSC_PRI,     4000000L, POSCMD_XT,   8000000L,  (PIC24F_DEFINED || PIC24FK_DEFINED || PIC24H_DEFINED || dsPIC33F_DEFINED), configClockPRI_8MHzCrystal_4MHzFCY,        498
00146 
00147 
00148 #ifndef __DOXYGEN__ // The following non-standard #if confuses Doxygen
00149 // Check to make sure the CLOCK_CONFIG choice selected
00150 // exists and is valid. Otherwise, the compiler emits some very
00151 // confusing errors. Cute hack: the last value in the #define
00152 // above (the magic number) is what the #if tests in gcc.
00153 #if (CLOCK_CONFIG != 498)
00154 #error ***********************************************************************
00155 #error * Value chosen for CLOCK_CONFIG does not exist or is not valid!       *
00156 #error * This produces very confusing compiler errors below.                 *
00157 #error ***********************************************************************
00158 #endif
00159 #endif
00160 
00161 // For some reason, primary oscillator selections are named
00162 // POSCMD_xx in the PIC24H and POSCMOD_xx in the PIC24F.
00163 // Work around this.
00164 // Hopefully, this will be defined in PIC24F headers at some point
00166 #ifndef POSCMD_EC
00167 #define POSCMD_EC   POSCMOD_EC
00168 #define POSCMD_XT   POSCMOD_XT
00169 #define POSCMD_HS   POSCMOD_HS
00170 #define POSCMD_NONE POSCMOD_NONE
00171 #endif
00173 
00174 // Turn clock config type info the right #defines, using
00175 // a three step process:
00176 // Step 1. Just use another macro to turn params (viewied as one argument here)
00177 //         to multiple arguments to the underscore version of the macro
00179 #define GET_CLOCK_CONFIG_INDEX(params)    _GET_CLOCK_CONFIG_INDEX(params)
00180 #define GET_FNOSC_SEL(params)             _GET_FNOSC_SEL(params)
00181 #define GET_FCY(params)                   _GET_FCY(params)
00182 #define GET_POSCMD_SEL(params)            _GET_POSCMD_SEL(params)
00183 #define GET_POSC_FREQ(params)             _GET_POSC_FREQ(params)
00184 #define GET_IS_SUPPORTED(params)          _GET_IS_SUPPORTED(params)
00185 #define GET_CONFIG_DEFAULT_CLOCK(params)  _GET_CONFIG_DEFAULT_CLOCK(params)
00186 
00187 // Step 2. Return the desired parameter, now that params are seen as
00188 //         individual arguments.
00189 #define _GET_CLOCK_CONFIG_INDEX(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClock, magic)        ndx
00190 #define _GET_FNOSC_SEL(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic)             oscSel
00191 #define _GET_FCY(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic)                   Fcy
00192 #define _GET_POSCMD_SEL(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic)            posCmdSel
00193 #define _GET_POSC_FREQ(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic)             poscFreq
00194 #define _GET_IS_SUPPORTED(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic)          isSupported
00195 #define _GET_CONFIG_DEFAULT_CLOCK(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic)  configClockFunc
00196 // Step 3. Call the macros above to set constants based on the
00197 //         clock config selected.
00199 #define CLOCK_CONFIG_INDEX      GET_CLOCK_CONFIG_INDEX(CLOCK_CONFIG)
00200 #define FNOSC_SEL               GET_FNOSC_SEL(CLOCK_CONFIG)
00201 #define FCY                     GET_FCY(CLOCK_CONFIG)
00202 #define POSCMD_SEL              GET_POSCMD_SEL(CLOCK_CONFIG)
00203 #define POSC_FREQ               GET_POSC_FREQ(CLOCK_CONFIG)
00204 #define CONFIG_DEFAULT_CLOCK()  GET_CONFIG_DEFAULT_CLOCK(CLOCK_CONFIG)()
00205 
00206 // Verify that the current processor is supported by the clock
00207 // configuration chosen.
00208 // 1. Set up some #defines as booleans which tell which processor
00209 //    is selected for this compile.
00211 #ifdef __PIC24F__
00212 #define PIC24F_DEFINED 1
00213 #else
00214 #define PIC24F_DEFINED 0
00215 #endif
00216 #ifdef __PIC24H__
00217 #define PIC24H_DEFINED 1
00218 #else
00219 #define PIC24H_DEFINED 0
00220 #endif
00221 #ifdef __dsPIC33F__
00222 #define dsPIC33F_DEFINED 1
00223 #else
00224 #define dsPIC33F_DEFINED 0
00225 #endif
00226 #ifdef __PIC24FK__
00227 #define PIC24FK_DEFINED 1
00228 #else
00229 #define PIC24FK_DEFINED 0
00230 #endif
00231 
00232 // 2. Check to see if this clock configuration supports that processor.
00233 #if !GET_IS_SUPPORTED(CLOCK_CONFIG)
00234 #error The clock configuration chosen is not supported by this processor.
00235 #endif
00236 // 3. Check that the primary oscillator type chosen works for the
00237 //    oscilallator frequency selected. If the primary
00238 #if (POSCMD_SEL == POSCMD_XT) && ( (POSC_FREQ < 3500000L) || (POSC_FREQ > 10000000L) )
00239 #error The XT oscialltor chosen in POSCMD_SEL does not support this frequency!
00240 #error Valid ranges are from 3.5 MHz to 10 MHz.
00241 #endif
00242 #if (POSCMD_SEL == POSCMD_HS) && ( (POSC_FREQ < 10000000L) || (POSC_FREQ > 32000000L) )
00243 #error The HS oscialltor chosen in POSCMD_SEL does not support this frequency!
00244 #error Valid ranges are from 10 MHz to 32 MHz.
00245 #endif
00247 
00250 
00251 
00323 
00324 
00325 
00327 
00338 #define IS_CLOCK_CONFIG(clockConfig) _GET_CLOCK_CONFIG_INDEX(clockConfig) == CLOCK_CONFIG_INDEX
00339 
00344 #define GET_OSC_SEL_BITS(bits) _GET_OSC_SEL_BITS(bits)
00346 #if defined(__PIC24H__) || defined (__PIC24FK__) || defined(__dsPIC33F__) || defined(__DOXYGEN__)
00347 #define _GET_OSC_SEL_BITS(bits) ((bits >> 0) & 0x07)
00348 #elif defined (__PIC24F__) 
00349 #define _GET_OSC_SEL_BITS(bits) ((bits >> 8) & 0x07)
00350 #else
00351 #error Unknown processor
00352 #endif
00353 // Note: putting the \ endcond here causes Doxygen 1.5.6
00354 // to complain. ???
00357 #define OSC_SEL_BITS GET_OSC_SEL_BITS(FNOSC_SEL)
00358 
00359 // Double check to make sure the oscillator selection above is valid.
00360 #if ( (OSC_SEL_BITS < 0) || (OSC_SEL_BITS > 7) )
00361 #error Invalid oscillator selection FNOSC_SEL.
00362 #endif
00363 
00369 #if GET_IS_SUPPORTED(SIM_CLOCK)
00370 
00378 void configClockSim(void);
00379 #endif
00380 
00381 #if GET_IS_SUPPORTED(FRCPLL_FCY16MHz)
00382 void configClockFRCPLL_FCY16MHz(void);
00383 #endif
00384 
00385 #if GET_IS_SUPPORTED(FRC_FCY4MHz)
00386 void configClockFRC_FCY4MHz(void);
00387 #endif
00388 
00389 #if GET_IS_SUPPORTED(PRI_NO_PLL_7372KHzCrystal)
00390 void configClockPRI_NO_PLL_7372KHzCrystal(void);
00391 #endif
00392 
00393 #if GET_IS_SUPPORTED(FRC_FCY3685KHz)
00394 void configClockFRC_FCY3685KHz(void);
00395 #endif
00396 
00397 #if GET_IS_SUPPORTED(FRCPLL_FCY40MHz)
00398 void configClockFRCPLL_FCY40MHz(void);
00399 #endif
00400 
00401 #if GET_IS_SUPPORTED(PRI_NO_PLL_7372KHzCrystal)
00402 void configClockPRIPLL_7372KHzCrystal_40MHzFCY(void);
00403 #endif
00404 
00405 #if GET_IS_SUPPORTED(PRIPLL_8MHzCrystal_40MHzFCY)
00406 void configClockPRIPLL_8MHzCrystal_40MHzFCY(void);
00407 #endif
00408 
00409 #if GET_IS_SUPPORTED(PRIPLL_8MHzCrystal_16MHzFCY)
00410 void configClockPRIPLL_8MHzCrystal_16MHzFCY(void);
00411 #endif
00412 
00413 #if GET_IS_SUPPORTED(PRI_8MHzCrystal_4MHzFCY)
00414 void configClockPRI_8MHzCrystal_4MHzFCY(void);
00415 #endif
00416 
00417 
00419 
00423 static inline void configClock() {
00424   CONFIG_DEFAULT_CLOCK();
00425 }
00426 
00427 
00440 void switchClock(uint8 u8_source);
00441 
00442 #endif

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9