00001 00038 #ifndef CLK_XMEGA_OSC_H_INCLUDED 00039 #define CLK_XMEGA_OSC_H_INCLUDED 00040 00041 #include <regs/xmega_osc.h> 00042 00048 #ifndef __ASSEMBLY__ 00049 00050 #include <assert.h> 00051 #include <types.h> 00052 00059 __always_inline static void osc_enable_internal(uint8_t id) 00060 { 00061 uint8_t ctrl; 00062 00063 ctrl = osc_read_reg(CTRL); 00064 ctrl |= 1 << id; 00065 osc_write_reg(CTRL, ctrl); 00066 } 00067 00077 #ifdef BOARD_XOSC_HZ 00078 __always_inline static void osc_enable_external(uint8_t id) 00079 { 00080 assert(id == OSC_ID_XOSC); 00081 00082 osc_write_reg(XOSCCTRL, OSC_BF(FRQRANGE, BOARD_XOSC_RANGE) 00083 | OSC_BF(XOSCSEL, BOARD_XOSC_TYPE)); 00084 } 00085 #else 00086 ERROR_FUNC(osc_no_external, "No external oscillator on the selected board"); 00087 00088 static inline void osc_enable_external(uint8_t id) 00089 { 00090 osc_no_external(); 00091 } 00092 #endif 00093 00094 __always_inline static void osc_disable(uint8_t id) 00095 { 00096 uint8_t ctrl; 00097 00098 ctrl = osc_read_reg(CTRL); 00099 ctrl &= ~(1 << id); 00100 osc_write_reg(CTRL, ctrl); 00101 } 00102 00103 static inline bool osc_is_running(uint8_t id) 00104 { 00105 return osc_read_reg(STATUS) & (1 << id); 00106 } 00107 00108 #endif /* __ASSEMBLY__ */ 00109 00111 00112 #endif /* CLK_XMEGA_OSC_H_INCLUDED */
1.6.3