40 #define PRINTF(...) printf(__VA_ARGS__)
45 uint32_t cal_rtc_secs;
47 void sleep(uint32_t opts, uint32_t mode)
53 *CRM_SLEEP_CNTL = opts;
54 *CRM_SLEEP_CNTL = (opts | mode);
57 while(!bit_is_set(*CRM_STATUS,0)) {
continue; }
59 set_bit(*CRM_STATUS,0);
66 while(!bit_is_set(*CRM_STATUS,0)) {
continue; }
68 set_bit(*CRM_STATUS,0);
79 void enable_32khz_xtal(
void)
81 static volatile uint32_t rtc_count;
82 PRINTF(
"enabling 32kHz crystal\n\r");
96 rtc_count = *CRM_RTC_COUNT;
97 PRINTF(
"waiting for xtal\n\r");
98 while(*CRM_RTC_COUNT == rtc_count) {
102 PRINTF(
"32kHZ xtal started\n\r");
106 void cal_ring_osc(
void)
109 PRINTF(
"performing ring osc cal\n\r");
110 PRINTF(
"crm_status: 0x%0x\n\r",*CRM_STATUS);
111 PRINTF(
"sys_cntl: 0x%0x\n\r",*CRM_SYS_CNTL);
112 *CRM_CAL_CNTL = (1<<16) | (20000);
113 while((*CRM_STATUS & (1<<9)) == 0);
114 PRINTF(
"ring osc cal complete\n\r");
115 PRINTF(
"cal_count: 0x%0x\n\r",*CRM_CAL_COUNT);
116 cal_factor = (REF_OSC*1000) / *CRM_CAL_COUNT;
117 cal_rtc_secs = (NOMINAL_RING_OSC_SEC * cal_factor)/100;
118 PRINTF(
"cal factor: %d\n\r", cal_factor);
119 PRINTF(
"hib_wake_secs: %d\n\r", cal_rtc_secs);
120 set_bit(*CRM_STATUS,9);