00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00133
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, configClockFRCPLL_FCY16MHz, 498
00137 #define FRC_FCY4MHz 2, FNOSC_FRC, 4000000L, POSCMD_NONE, -1, PIC24F_DEFINED, configClockFRC_FCY4MHz, 498
00138 #define PRI_NO_PLL_7372KHzCrystal 3, FNOSC_PRI, 3686400L, POSCMD_XT, 7372800L, (PIC24F_DEFINED || PIC24H_DEFINED), configClockPRI_NO_PLL_7372KHzCrystal, 498
00139 #define FRC_FCY3685KHz 4, FNOSC_FRC, 3685000L, POSCMD_NONE, -1, PIC24H_DEFINED, configClockFRC_FCY3685KHz, 498
00140 #define FRCPLL_FCY40MHz 5, FNOSC_FRCPLL, 40000000L, POSCMD_NONE, -1, PIC24H_DEFINED, configClockFRCPLL_FCY40MHz, 498
00141 #define PRIPLL_7372KHzCrystal_40MHzFCY 6, FNOSC_PRIPLL, 40000000L, POSCMD_XT, 7372800L, PIC24H_DEFINED, configClockPRIPLL_7372KHzCrystal_40MHzFCY, 498
00142 #define PRIPLL_8MHzCrystal_40MHzFCY 7, FNOSC_PRIPLL, 40000000L, POSCMD_XT, 8000000L, PIC24H_DEFINED, configClockPRIPLL_8MHzCrystal_40MHzFCY, 498
00143 #define PRIPLL_8MHzCrystal_16MHzFCY 8, FNOSC_PRIPLL, 16000000L, POSCMD_XT, 8000000L, PIC24F_DEFINED, configClockPRIPLL_8MHzCrystal_16MHzFCY, 498
00145
00146
00147 #ifndef __DOXYGEN__ // The following non-standard #if confuses Doxygen
00148
00149
00150
00151
00152 #if (CLOCK_CONFIG != 498)
00153 #error ***********************************************************************
00154 #error * Value chosen for CLOCK_CONFIG does not exist or is not valid! *
00155 #error * This produces very confusing compiler errors below. *
00156 #error ***********************************************************************
00157 #endif
00158 #endif
00159
00160
00161
00162
00163
00165 #ifndef POSCMD_EC
00166 #define POSCMD_EC POSCMOD_EC
00167 #define POSCMD_XT POSCMOD_XT
00168 #define POSCMD_HS POSCMOD_HS
00169 #define POSCMD_NONE POSCMOD_NONE
00170 #endif
00172
00173
00174
00175
00176
00178 #define GET_CLOCK_CONFIG_INDEX(params) _GET_CLOCK_CONFIG_INDEX(params)
00179 #define GET_FNOSC_SEL(params) _GET_FNOSC_SEL(params)
00180 #define GET_FCY(params) _GET_FCY(params)
00181 #define GET_POSCMD_SEL(params) _GET_POSCMD_SEL(params)
00182 #define GET_POSC_FREQ(params) _GET_POSC_FREQ(params)
00183 #define GET_IS_SUPPORTED(params) _GET_IS_SUPPORTED(params)
00184 #define GET_CONFIG_DEFAULT_CLOCK(params) _GET_CONFIG_DEFAULT_CLOCK(params)
00185
00186
00187
00188 #define _GET_CLOCK_CONFIG_INDEX(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClock, magic) ndx
00189 #define _GET_FNOSC_SEL(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic) oscSel
00190 #define _GET_FCY(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic) Fcy
00191 #define _GET_POSCMD_SEL(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic) posCmdSel
00192 #define _GET_POSC_FREQ(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic) poscFreq
00193 #define _GET_IS_SUPPORTED(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic) isSupported
00194 #define _GET_CONFIG_DEFAULT_CLOCK(ndx, oscSel, Fcy, posCmdSel, poscFreq, isSupported, configClockFunc, magic) configClockFunc
00195
00196
00198 #define CLOCK_CONFIG_INDEX GET_CLOCK_CONFIG_INDEX(CLOCK_CONFIG)
00199 #define FNOSC_SEL GET_FNOSC_SEL(CLOCK_CONFIG)
00200 #define FCY GET_FCY(CLOCK_CONFIG)
00201 #define POSCMD_SEL GET_POSCMD_SEL(CLOCK_CONFIG)
00202 #define POSC_FREQ GET_POSC_FREQ(CLOCK_CONFIG)
00203 #define CONFIG_DEFAULT_CLOCK() GET_CONFIG_DEFAULT_CLOCK(CLOCK_CONFIG)()
00204
00205
00206
00207
00208
00210 #ifdef __PIC24F__
00211 #define PIC24F_DEFINED 1
00212 #else
00213 #define PIC24F_DEFINED 0
00214 #endif
00215 #ifdef __PIC24H__
00216 #define PIC24H_DEFINED 1
00217 #else
00218 #define PIC24H_DEFINED 0
00219 #endif
00220
00221 #if !GET_IS_SUPPORTED(CLOCK_CONFIG)
00222 #error The clock configuration chosen is not supported by this processor.
00223 #endif
00224
00225
00226 #if (POSCMD_SEL == POSCMD_XT) && ( (POSC_FREQ < 3500000L) || (POSC_FREQ > 10000000L) )
00227 #error The XT oscialltor chosen in POSCMD_SEL does not support this frequency!
00228 #error Valid ranges are from 3.5 MHz to 10 MHz.
00229 #endif
00230 #if (POSCMD_SEL == POSCMD_HS) && ( (POSC_FREQ < 10000000L) || (POSC_FREQ > 32000000L) )
00231 #error The HS oscialltor chosen in POSCMD_SEL does not support this frequency!
00232 #error Valid ranges are from 10 MHz to 32 MHz.
00233 #endif
00235
00238
00239
00311
00312
00313
00315
00326 #define IS_CLOCK_CONFIG(clockConfig) _GET_CLOCK_CONFIG_INDEX(clockConfig) == CLOCK_CONFIG_INDEX
00327
00332 #define GET_OSC_SEL_BITS(bits) _GET_OSC_SEL_BITS(bits)
00334 #if defined(__PIC24H__) || defined(__DOXYGEN__)
00335 #define _GET_OSC_SEL_BITS(bits) ((bits >> 0) & 0x07)
00336 #elif defined (__PIC24F__)
00337 #define _GET_OSC_SEL_BITS(bits) ((bits >> 8) & 0x07)
00338 #else
00339 #error Unknown processor
00340 #endif
00341
00342
00345 #define OSC_SEL_BITS GET_OSC_SEL_BITS(FNOSC_SEL)
00346
00347
00348 #if ( (OSC_SEL_BITS < 0) || (OSC_SEL_BITS > 7) )
00349 #error Invalid oscillator selection FNOSC_SEL.
00350 #endif
00351
00357 #if GET_IS_SUPPORTED(SIM_CLOCK)
00358
00366 void configClockSim(void);
00367 #endif
00368
00369 #if GET_IS_SUPPORTED(FRCPLL_FCY16MHz)
00370 void configClockFRCPLL_FCY16MHz(void);
00371 #endif
00372
00373 #if GET_IS_SUPPORTED(FRC_FCY4MHz)
00374 void configClockFRC_FCY4MHz(void);
00375 #endif
00376
00377 #if GET_IS_SUPPORTED(PRI_NO_PLL_7372KHzCrystal)
00378 void configClockPRI_NO_PLL_7372KHzCrystal(void);
00379 #endif
00380
00381 #if GET_IS_SUPPORTED(FRC_FCY3685KHz)
00382 void configClockFRC_FCY3685KHz(void);
00383 #endif
00384
00385 #if GET_IS_SUPPORTED(FRCPLL_FCY40MHz)
00386 void configClockFRCPLL_FCY40MHz(void);
00387 #endif
00388
00389 #if GET_IS_SUPPORTED(PRI_NO_PLL_7372KHzCrystal)
00390 void configClockPRIPLL_7372KHzCrystal_40MHzFCY(void);
00391 #endif
00392
00393 #if GET_IS_SUPPORTED(PRIPLL_8MHzCrystal_40MHzFCY)
00394 void configClockPRIPLL_8MHzCrystal_40MHzFCY(void);
00395 #endif
00396
00397 #if GET_IS_SUPPORTED(PRIPLL_8MHzCrystal_16MHzFCY)
00398 void configClockPRIPLL_8MHzCrystal_16MHzFCY(void);
00399 #endif
00400
00401
00403
00407 static inline void configClock() {
00408 CONFIG_DEFAULT_CLOCK();
00409 }
00410
00411
00424 void switchClock(uint8 u8_source);
00425
00426 #endif