41 #define CRM_BASE (0x80003000)
48 uint32_t PWR_SOURCE:2;
49 uint32_t PADS_1P8V_SEL:1;
51 uint32_t JTAG_SECU_OFF:1;
52 uint32_t XTAL32_EXISTS:1;
54 uint32_t XTAL_CLKDIV:6;
61 uint32_t TIMER_WU_EN:1;
66 uint32_t EXT_WU_EDGE:4;
67 uint32_t EXT_WU_POL:4;
68 uint32_t TIMER_WU_IEN:1;
69 uint32_t RTC_WU_IEN:1;
71 uint32_t EXT_WU_IEN:4;
73 uint32_t EXT_OUT_POL:4;
78 struct CRM_SLEEP_CNTL {
84 uint32_t DIG_PAD_EN:1;
95 uint32_t ARM_OFF_TIME:6;
101 struct CRM_COP_CNTL {
106 uint32_t COP_TIMEOUT:7;
108 uint32_t COP_COUNT:7;
112 uint32_t COP_SERVICE;
116 uint32_t SLEEP_SYNC:1;
117 uint32_t HIB_WU_EVT:1;
118 uint32_t DOZE_WU_EVT:1;
119 uint32_t RTC_WU_EVT:1;
120 uint32_t EXT_WU_EVT:4;
125 uint32_t VREG_BUCK_RDY:1;
126 uint32_t VREG_1P8V_RDY:1;
127 uint32_t VREG_1P5V_RDY:1;
133 struct CRM_MOD_STATUS {
158 uint32_t RTC_TIMEOUT;
162 struct CRM_CAL_CNTL {
163 uint32_t CAL_TIMEOUT:16;
171 uint32_t RINGOSC_CNTL;
172 struct CRM_RINGOSC_CNTL {
175 uint32_t ROSC_FTUNE:5;
176 uint32_t ROSC_CTUNE:4;
182 struct CRM_XTAL_CNTL {
184 uint32_t XTAL_IBIAS_SEL:4;
186 uint32_t XTAL_FTUNE:5;
187 uint32_t XTAL_CTUNE:5;
192 uint32_t XTAL32_CNTL;
193 struct CRM_XTAL32_CNTL {
194 uint32_t XTAL32_EN:1;
196 uint32_t XTAL32_GAIN:2;
202 struct CRM_VREG_CNTL {
204 uint32_t BUCK_SYNC_REC_EN:1;
205 uint32_t BUCK_BYPASS_EN:1;
206 uint32_t VREG_1P5V_EN:2;
207 uint32_t VREG_1P5V_SEL:2;
208 uint32_t VREG_1P8V_EN:1;
209 uint32_t BUCK_CLKDIV:4;
221 static volatile struct CRM_struct *
const CRM = (
void *) (CRM_BASE);
226 #define cop_timeout_ms(x) (CRM->COP_CNTLbits.COP_TIMEOUT = x/87)
227 #define cop_service() (CRM->COP_SERVICE = 0xc0de5afe)
230 #ifndef REG_NO_COMPAT
232 static volatile uint32_t *
const CRM_SYS_CNTL = ((
volatile uint32_t *) (CRM_BASE+0x00));
233 static volatile uint32_t *
const CRM_WU_CNTL = ((
volatile uint32_t *) (CRM_BASE+0x04));
234 static volatile uint32_t *
const CRM_SLEEP_CNTL = ((
volatile uint32_t *) (CRM_BASE+0x08));
235 static volatile uint32_t *
const CRM_BS_CNTL = ((
volatile uint32_t *) (CRM_BASE+0x0c));
236 static volatile uint32_t *
const CRM_COP_CNTL = ((
volatile uint32_t *) (CRM_BASE+0x10));
237 static volatile uint32_t *
const CRM_COP_SERVICE= ((
volatile uint32_t *) (CRM_BASE+0x14));
238 static volatile uint32_t *
const CRM_STATUS = ((
volatile uint32_t *) (CRM_BASE+0x18));
239 static volatile uint32_t *
const CRM_MOD_STATUS = ((
volatile uint32_t *) (CRM_BASE+0x1c));
240 static volatile uint32_t *
const CRM_WU_COUNT = ((
volatile uint32_t *) (CRM_BASE+0x20));
241 static volatile uint32_t *
const CRM_WU_TIMEOUT = ((
volatile uint32_t *) (CRM_BASE+0x24));
242 static volatile uint32_t *
const CRM_RTC_COUNT = ((
volatile uint32_t *) (CRM_BASE+0x28));
243 static volatile uint32_t *
const CRM_RTC_TIMEOUT= ((
volatile uint32_t *) (CRM_BASE+0x2c));
244 static volatile uint32_t *
const CRM_CAL_CNTL = ((
volatile uint32_t *) (CRM_BASE+0x34));
245 static volatile uint32_t *
const CRM_CAL_COUNT = ((
volatile uint32_t *) (CRM_BASE+0x38));
246 static volatile uint32_t *
const CRM_RINGOSC_CNT= ((
volatile uint32_t *) (CRM_BASE+0x3c));
247 static volatile uint32_t *
const CRM_XTAL_CNTL = ((
volatile uint32_t *) (CRM_BASE+0x40));
248 static volatile uint32_t *
const CRM_XTAL32_CNTL= ((
volatile uint32_t *) (CRM_BASE+0x44));
249 static volatile uint32_t *
const CRM_VREG_CNTL = ((
volatile uint32_t *) (CRM_BASE+0x48));
250 static volatile uint32_t *
const CRM_SW_RST = ((
volatile uint32_t *) (CRM_BASE+0x50));
253 static const int XTAL32_EXISTS = 5;
256 static const int EXT_WU_IEN = 20;
257 static const int EXT_WU_EN = 4;
258 static const int EXT_WU_EDGE = 8;
259 static const int EXT_WU_POL = 12;
260 static const int TIMER_WU_EN = 0;
261 static const int RTC_WU_EN = 1;
262 static const int TIMER_WU_IEN = 16;
263 static const int RTC_WU_IEN = 17;
266 static const int EXT_WU_EVT = 4;
267 static const int RTC_WU_EVT = 3;
270 static const int ROSC_CTUNE = 9;
271 static const int ROSC_FTUNE = 4;
272 static const int ROSC_EN = 0;
274 #define ring_osc_on() (CRM->RINGOSC_CNTLbits.ROSC_EN = 1)
275 #define ring_osc_off() (CRM->RINGOSC_CNTLbits.ROSC_EN = 0)
277 #define REF_OSC 24000000UL
278 #define NOMINAL_RING_OSC_SEC 2000
279 extern uint32_t cal_rtc_secs;
282 static const int XTAL32_GAIN = 4;
283 static const int XTAL32_EN = 0;
285 #define xtal32_on() (set_bit(*CRM_XTAL32_CNTL,XTAL32_EN))
286 #define xtal32_off() (clear_bit(*CRM_XTAL32_CNTL,XTAL32_EN))
287 #define xtal32_exists() (set_bit(*CRM_SYS_CNTL,XTAL32_EXISTS))
291 #define enable_ext_wu(kbi) (set_bit(*CRM_WU_CNTL,(EXT_WU_EN+kbi-4)))
292 #define disable_ext_wu(kbi) (clear_bit(*CRM_WU_CNTL,(EXT_WU_EN+kbi-4)))
294 #define is_ext_wu_evt(kbi) (bit_is_set(*CRM_STATUS,(EXT_WU_EVT+kbi-4)))
295 #define clear_ext_wu_evt(kbi) (set_bit(*CRM_STATUS,(EXT_WU_EVT+kbi-4)))
298 #define enable_timer_wu_irq() ((set_bit(*CRM_WU_CNTL,(TIMER_WU_IEN))))
299 #define disable_timer_wu_irq() ((clear_bit(*CRM_WU_CNTL,(TIMER_WU_IEN))))
301 #define enable_timer_wu() ((set_bit(*CRM_WU_CNTL,(TIMER_WU_EN))))
302 #define disable_timer_wu() ((clear_bit(*CRM_WU_CNTL,(TIMER_WU_EN))))
305 #define enable_rtc_wu_irq() (set_bit(*CRM_WU_CNTL,RTC_WU_IEN))
306 #define disable_rtc_wu_irq() (clear_bit(*CRM_WU_CNTL,RTC_WU_IEN))
308 #define enable_rtc_wu() ((set_bit(*CRM_WU_CNTL,(RTC_WU_EN))))
309 #define disable_rtc_wu() ((clear_bit(*CRM_WU_CNTL,(RTC_WU_EN))))
311 #define clear_rtc_wu_evt() (set_bit(*CRM_STATUS,RTC_WU_EVT))
312 #define rtc_wu_evt() (bit_is_set(*CRM_STATUS,RTC_WU_EVT))
314 #define SLEEP_MODE_HIBERNATE bit(0)
315 #define SLEEP_MODE_DOZE bit(1)
317 #define SLEEP_PAD_PWR bit(7)
318 #define SLEEP_RETAIN_MCU bit(6)
319 #define sleep_ram_retain(x) (x<<4)
320 #define SLEEP_RAM_8K sleep_ram_retain(0)
321 #define SLEEP_RAM_32K sleep_ram_retain(1)
322 #define SLEEP_RAM_64K sleep_ram_retain(2)
323 #define SLEEP_RAM_96K sleep_ram_retain(3)
325 #define pack_XTAL_CNTL(ctune4pf, ctune, ftune, ibias) \
326 (*CRM_XTAL_CNTL = ((ctune4pf << 25) | (ctune << 21) | ( ftune << 16) | (ibias << 8) | 0x52))