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 || 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
00150
00151
00152
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
00162
00163
00164
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
00175
00176
00177
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
00188
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
00197
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
00207
00208
00209
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
00233 #if !GET_IS_SUPPORTED(CLOCK_CONFIG)
00234 #error The clock configuration chosen is not supported by this processor.
00235 #endif
00236
00237
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
00354
00357 #define OSC_SEL_BITS GET_OSC_SEL_BITS(FNOSC_SEL)
00358
00359
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