void tick_stop(void) { avic_disable_int(INT_EPIT1); /* Disable insterrupt */ EPITCR1 &= ~(EPITCR_OCIEN | EPITCR_EN); /* Disable counter */ EPITSR1 = EPITSR_OCIF; /* Clear pending */ ccm_module_clock_gating(CG_EPIT1, CGM_OFF); /* Turn off module clock */ }
void tick_start(unsigned int interval_in_ms) { ccm_module_clock_gating(CG_EPIT1, CGM_ON_RUN_WAIT); /* EPIT1 module clock ON - before writing regs! */ EPITCR1 &= ~(EPITCR_OCIEN | EPITCR_EN); /* Disable the counter */ CCM_WIMR0 &= ~CCM_WIMR0_IPI_INT_EPIT1; /* Clear wakeup mask */ /* mcu_main_clk = 528MHz = 27MHz * 2 * ((9 + 7/9) / 1) * CLKSRC = ipg_clk = 528MHz / 4 / 2 = 66MHz, * EPIT Output Disconnected, * Enabled in wait mode * Prescale 1/2640 for 25KHz * Reload from modulus register, * Compare interrupt enabled, * Count from load value */ EPITCR1 = EPITCR_CLKSRC_IPG_CLK | EPITCR_WAITEN | EPITCR_IOVW | ((2640-1) << EPITCR_PRESCALER_POS) | EPITCR_RLD | EPITCR_OCIEN | EPITCR_ENMOD; EPITLR1 = interval_in_ms*25; /* Count down from interval */ EPITCMPR1 = 0; /* Event when counter reaches 0 */ EPITSR1 = EPITSR_OCIF; /* Clear any pending interrupt */ avic_enable_int(INT_EPIT1, INT_TYPE_IRQ, INT_PRIO_DEFAULT, EPIT1_HANDLER); EPITCR1 |= EPITCR_EN; /* Enable the counter */ }
void usb_enable(bool on) { /* Module clock should be on since since this could be called with * OFF initially and writing module registers would hardlock otherwise. */ ccm_module_clock_gating(CG_USBOTG, CGM_ON_RUN_WAIT); enable_transceiver(true); if (on) { usb_core_init(); } else { usb_core_exit(); enable_transceiver(false); ccm_module_clock_gating(CG_USBOTG, CGM_OFF); } }
static void stop_timer(bool clock_off) { /* Ensure clock gating on (before touching any module registers) */ ccm_module_clock_gating(CG_EPIT2, CGM_ON_RUN_WAIT); /* Disable insterrupt */ avic_disable_int(INT_EPIT2); /* Clear wakeup mask */ CCM_WIMR0 &= ~CCM_WIMR0_IPI_INT_EPIT2; /* Disable counter */ EPITCR2 &= ~(EPITCR_OCIEN | EPITCR_EN); /* Clear pending */ EPITSR2 = EPITSR_OCIF; if (clock_off) { /* Final stop, not reset; don't clock module any longer */ ccm_module_clock_gating(CG_EPIT2, CGM_OFF); } }
void button_init_device(void) { #ifdef BOOTLOADER /* Can be called more than once in the bootloader */ if (initialized) return; initialized = true; #endif /* Enable keypad clock */ ccm_module_clock_gating(CG_KPP, CGM_ON_RUN_WAIT); /* 1. Enable number of rows in keypad (KPCR[4:0]) * * Configure the rows/cols in KPP * LSB nybble in KPP is for 5 rows * MSB nybble in KPP is for 3 cols */ KPP_KPCR |= 0x1f; /* 2. Write 0's to KPDR[10:8] */ KPP_KPDR &= ~(0x7 << 8); /* 3. Configure the keypad columns as open-drain (KPCR[10:8]). */ KPP_KPCR |= (0x7 << 8); /* 4. Configure columns as output, rows as input (KDDR[10:8,4:0]) */ KPP_KDDR = (KPP_KDDR | (0x7 << 8)) & ~0x1f; /* 5. Clear the KPKD Status Flag and Synchronizer chain. * 6. Set the KDIE control bit bit. */ KPP_KPSR = KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKD; power_button_update(!(mc13783_read(MC13783_INTERRUPT_SENSE1) & MC13783_ONOFD1S)); mc13783_enable_event(MC13783_ONOFD1_EVENT, true); #ifdef HAVE_HEADPHONE_DETECTION headphone_init(); #endif }
/** Public routines **/ void INIT_ATTR sdma_init(void) { int i; unsigned long acr; ccm_module_clock_gating(CG_SDMA, CGM_ON_RUN_WAIT); /* Reset the controller */ SDMA_RESET |= SDMA_RESET_RESET; while (SDMA_RESET & SDMA_RESET_RESET); /* No channel enabled, all priorities 0 */ for (i = 0; i < CH_NUM; i++) { SDMA_CHNENBL(i) = 0; SDMA_CHNPRI(i) = 0; } /* Ensure no ints pending */ SDMA_INTR = 0xffffffff; /* Nobody owns any channel (yet) */ SDMA_HOSTOVR = 0xffffffff; SDMA_DSPOVR = 0xffffffff; SDMA_EVTOVR = 0xffffffff; SDMA_MC0PTR = 0x00000000; /* 32-word channel contexts, use default bootscript address */ SDMA_CHN0ADDR = SDMA_CHN0ADDR_SMSZ | 0x0050; avic_enable_int(INT_SDMA, INT_TYPE_IRQ, INT_PRIO_SDMA, SDMA_HANDLER); /* SDMA core must run at the proper frequency based upon the AHB/IPG * ratio */ acr = (ccm_get_ahb_clk() / ccm_get_ipg_clk()) < 2 ? SDMA_CONFIG_ACR : 0; /* No dsp, no debug * Static context switching - TLSbo86520L SW Workaround for SDMA Chnl0 * access issue */ SDMA_CONFIG = acr; /* Tell SDMA where the host channel table is */ SDMA_MC0PTR = (unsigned long)ccb_array; ccb_array[0].status.opened_init = 1; ccb_array[0].curr_bd_ptr = &c0_buffer_desc.bd; ccb_array[0].base_bd_ptr = &c0_buffer_desc.bd; ccb_array[0].channel_desc = NULL; /* No channel descriptor */ /* Command channel owned by AP */ set_channel_ownership(0, CH_OWNSHP_MCU); sdma_channel_set_priority(0, 1); /* Load SDMA script code */ set_buffer_descriptor(&c0_buffer_desc.bd, C0_SETPM, BD_DONE | BD_WRAP | BD_EXTD, RAM_CODE_SIZE, (void *)addr_virt_to_phys(MCU_START_ADDR), (void *)RAM_CODE_START_ADDR); SDMA_HSTART = 1ul; sdma_channel_wait_nonblocking(0); /* No dsp, no debug, dynamic context switching */ SDMA_CONFIG = acr | SDMA_CONFIG_CSM_DYNAMIC; }