AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
osc.h
1 
18 #ifndef _AVRIO_OSC_H_
19 #define _AVRIO_OSC_H_
20 
21 #include <avrio/defs.h>
22 __BEGIN_C_DECLS
23 /* ======================================================================== */
34 /* constants ================================================================ */
35 #define OSCCAL_EEADDR 0xFF
37 #if defined(__DOXYGEN__)
38 /*
39  * __DOXYGEN__ defined
40  * Partie documentation ne devant pas être compilée.
41  * =============================================================================
42  */
43 /* internal public functions ================================================ */
47 inline uint8_t ucOscCal (void);
48 
52 inline void vOscCalibrate (uint8_t ucOscCal);
53 
63 inline int iOscCalibrateFromEE (uint16_t usEeAddr);
64 
69 #else
70 /*
71  * __DOXYGEN__ not defined
72  * Partie ne devant pas être documentée.
73  * =============================================================================
74  */
75 #include <avr/io.h>
76 #include <avr/eeprom.h>
77 
78 #ifndef OSCCAL
79 #ifdef OSCCAL0
80 #define OSCCAL OSCCAL0
81 #else
82 #error OSCCAL not defined
83 #endif
84 #endif
85 
86 // ---------------------------------------------------------------------------
87 INLINE uint8_t
88 ucOscCal (void) {
89  return OSCCAL;
90 }
91 
92 // ---------------------------------------------------------------------------
93 INLINE void
94 vOscCalibrate (uint8_t ucOscCal) {
95  OSCCAL = ucOscCal;
96 }
97 
98 // ---------------------------------------------------------------------------
99 INLINE int
100 iOscCalibrateFromEE (uint16_t usEeAddr) {
101 #ifdef AVRIO_SET_OSCCAL
102  uint8_t ucOsc = eeprom_read_byte ((const uint8_t *)usEeAddr);
103  if (ucOsc != 0xFF) {
104  vOscCalibrate (ucOsc);
105  return ucOscCal();
106  }
107 #endif
108  return -1;
109 }
110 
111 #endif /* __DOXYGEN__ not defined */
112 /* ========================================================================== */
113 __END_C_DECLS
114 #endif /* _AVRIO_OSC_H_ */
int iOscCalibrateFromEE(uint16_t usEeAddr)
Réglage du registre OSCCAL avec une valeur stockée en EEPROM.
uint8_t ucOscCal(void)
Retourne la valeur du registre OSCCAL.
void vOscCalibrate(uint8_t ucOscCal)
Modifie le registre OSCCAL.