static void lpc_timer_start_master_us(EXO* exo, TIMER timer, unsigned int us) { //timers operate on M3 clock unsigned int clock = lpc_power_get_core_clock_inside(); #ifdef LPC11Uxx unsigned int psc, cnt, clk; if (timer < TC32B0) { clk = clock / 1000000 * us; //convert value to clock units psc = clk / 0x8000; if (!psc) psc = 1; cnt = clk / psc; if (cnt < 2) cnt = 2; if (cnt > 0x10000) cnt = 0x10000; lpc_timer_start_master_clk(exo, timer, psc, cnt); } else #endif //LPC11Uxx { //for 32 bit timers routine is different and much more easy - psc is always 1us lpc_timer_start_master_clk(exo, timer, clock / 1000000, us); } }
void lpc_eep_init(CORE* core) { LPC_EEPROM->PWRDWN |= LPC_EEPROM_PWRDWN_Msk; //EEPROM operates on M3 clock LPC_EEPROM->CLKDIV = lpc_power_get_core_clock_inside() / EEP_CLK - 1; sleep_us(100); LPC_EEPROM->PWRDWN &= ~LPC_EEPROM_PWRDWN_Msk; }
static inline void lpc_eep_read(CORE* core, IPC* ipc) { IO* io = (IO*)ipc->param2; #ifdef LPC18xx if (ipc->param1 + ipc->param3 > EEP_SIZE) { error(ERROR_OUT_OF_RANGE); return; } io_data_write(io, (void*)(ipc->param1 + EEP_BASE), ipc->param3); #else //LPC11Uxx LPC_IAP_TYPE iap; req[1] = ipc->param1; req[2] = (unsigned int)io_data(io); req[3] = ipc->param3; //EEPROM operates on M3 clock req[4] = lpc_power_get_core_clock_inside() / 1000; if (!lpc_iap(&iap, IAP_CMD_READ_EEPROM)) return; io->data_size = ipc->param3; #endif //LPC18xx }
static inline void lpc_eep_write(CORE* core, IPC* ipc) { IO* io = (IO*)ipc->param2; #ifdef LPC18xx unsigned int addr, count, processed, cur, i; if (ipc->param1 + io->data_size > EEP_SIZE) { error(ERROR_OUT_OF_RANGE); return; } for(count = (io->data_size + 3) >> 2, processed = 0, addr = (ipc->param1 + EEP_BASE) & ~3; count; count -= cur, processed += (cur << 2), addr += (cur << 2)) { cur = (EEP_PAGE_SIZE - (addr & (EEP_PAGE_SIZE - 1))) >> 2; if (cur > count) cur = count; for (i = 0; i < cur; ++i) ((uint32_t*)addr)[i] = ((uint32_t*)(io_data(io) + processed))[i]; LPC_EEPROM->INTSTATCLR = LPC_EEPROM_INTSTATCLR_PROG_CLR_ST_Msk; LPC_EEPROM->CMD = LPC_EEPROM_CMD_ERASE_PROGRAM; while ((LPC_EEPROM->INTSTAT & LPC_EEPROM_INTSTAT_END_OF_PROG_Msk) == 0) { sleep_ms(1); } } #else //LPC11Uxx LPC_IAP_TYPE iap; req[1] = ipc->param1; req[2] = (unsigned int)io_data(io); req[3] = io->data_size; //EEPROM operates on M3 clock req[4] = lpc_power_get_core_clock_inside() / 1000; iap(req, resp); if (!lpc_iap(&iap, IAP_CMD_WRITE_EEPROM)) return; #endif //LPC18xx }
void lpc_timer_adjust(EXO* exo) { __TIMER_REGS[SECOND_TIMER]->PR = (lpc_power_get_core_clock_inside() / S1_US) - 1; __TIMER_REGS[SECOND_TIMER]->TCR |= TIMER0_TCR_CEN_Msk; }