/*********************************************************************//** * @brief Initialize external NOR FLASH memory * @param[in] None * @return None **********************************************************************/ void NORFLASHInit( void ) { TIM_TIMERCFG_Type TIM_ConfigStruct; EMC_STATIC_MEM_Config_Type config; /************************************************************************** * Initialize EMC for NOR FLASH **************************************************************************/ config.CSn = 0; config.AddressMirror = 0; config.ByteLane = 1; config.DataWidth = 16; config.ExtendedWait = 0; config.PageMode = 0; config.WaitWEn = 2; config.WaitOEn = 2; config.WaitWr = 0x1f; config.WaitPage = 0x1f; config.WaitRd = 0x1f; config.WaitTurn = 0x1f; StaticMem_Init(&config); // init timer TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; TIM_ConfigStruct.PrescaleValue = 1; // Set configuration for Tim_config and Tim_MatchConfig TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct); TIM_Waitms(100); //delay time TIM_Waitms(10); return; }
// -------------------------------------------------- // Initialize external SDRAM memory Micron K4S561632J, 256Mbit(8M x 32) void Init_SDRAM( void ) { volatile uint32_t i; volatile unsigned long Dummy; EMC_DYN_MEM_Config_Type config; TIM_TIMERCFG_Type TIM_ConfigStruct; TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; TIM_ConfigStruct.PrescaleValue = 1; // Set configuration for Tim_config and Tim_MatchConfig TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct); config.ChipSize = 256; config.AddrBusWidth = 32; config.AddrMap = EMC_ADD_MAP_ROW_BANK_COL; config.CSn = 0; config.DataWidth = 16; config.TotalSize = SDRAM_SIZE; config.CASLatency= 3; config.RASLatency= 3; config.Active2ActivePeriod =EMC_NS2CLK( SDRAM_TRC); config.ActiveBankLatency =EMC_NS2CLK( SDRAM_TRRD); config.AutoRefrehPeriod = EMC_NS2CLK( SDRAM_TRFC); config.DataIn2ActiveTime = SDRAM_TDAL + EMC_NS2CLK( SDRAM_TRP); config.DataOut2ActiveTime = SDRAM_TAPR; config.WriteRecoveryTime = SDRAM_TWR; config.ExitSelfRefreshTime = EMC_NS2CLK( SDRAM_TXSR); config.LoadModeReg2Active = SDRAM_TMRD; config.PrechargeCmdPeriod = EMC_NS2CLK( SDRAM_TRP); config.ReadConfig = 1; // Command delayed strategy, using EMCCLKDELAY config.RefreshTime = EMC_NS2CLK( SDRAM_REFRESH) >> 4; config.Active2PreChargeTime = EMC_NS2CLK( SDRAM_TRAS); config.SeftRefreshExitTime = EMC_NS2CLK( SDRAM_TXSR); DynMem_Init(&config); EMC_DynCtrlSDRAMInit(EMC_DYNAMIC_CTRL_SDRAM_NOP); // Issue NOP command TIM_Waitms(100); // wait 200ms EMC_DynCtrlSDRAMInit(EMC_DYNAMIC_CTRL_SDRAM_PALL); // Issue Pre-charge command for(i = 0; i < 0x80; i++); // wait 128 AHB clock cycles TIM_Waitms(100); EMC_DynCtrlSDRAMInit(EMC_DYNAMIC_CTRL_SDRAM_MODE); // Issue MODE command Dummy = *((volatile uint32_t *)(SDRAM_BASE_ADDR | (0x32<<13))); // Mode Register Setting //Timing for 48/60/72MHZ Bus EMC_DynCtrlSDRAMInit(EMC_DYNAMIC_CTRL_SDRAM_NORMAL); // Issue NORMAL command //enable buffers EMC_DynMemConfigB(0, EMC_DYNAMIC_CFG_BUFF_ENABLED); for(i = 100000; i;i--); TIM_DeInit(LPC_TIM0); }
/**************************************************************************//** * * @brief Starts the I2C monitor * * @retval CMD_STATUS_OK If successfully started * @retval CMD_STATUS_ERR_* If the I2C monitor could not be started * *****************************************************************************/ cmd_status_t monitor_i2c_Start(void) { if (!validConfiguration) { // no point in arming if the configuration is invalid return CMD_STATUS_ERR_MON_I2C_NOT_CONFIGURED; } CLR_MEAS_PIN_1(); TIM_Init(LPC_TIMER3, TIM_TIMER_MODE, &timerCfg); TIM_Cmd(LPC_TIMER3, ENABLE); circbuff_Reset(pSampleBuffer); bytesToCapture = pSampleBuffer->size / SAMPLE_SIZE; pSampleData = (uint32_t*)pSampleBuffer->data; done = FALSE; I2C_IntCmd(LPC_I2C0, TRUE); I2C_MonitorModeCmd(LPC_I2C0, ENABLE); while (!done) { TIM_Waitms(10); } return CMD_STATUS_OK; }
int main (void) { TIM_TIMERCFG_Type timerCfg; uint8_t joyState = 0; /* Initialize devices */ // initialize timer TIM_ConfigStructInit(TIM_TIMER_MODE, &timerCfg); TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &timerCfg); console_init(); joystick_init(); while(1) { joyState = joystick_read(); if (joyState & JOYSTICK_UP) { console_sendString((uint8_t*)"Up "); } if (joyState & JOYSTICK_DOWN) { console_sendString((uint8_t*)"Down "); } if (joyState & JOYSTICK_LEFT) { console_sendString((uint8_t*)"Left "); } if (joyState & JOYSTICK_RIGHT) { console_sendString((uint8_t*)"Right "); } if (joyState & JOYSTICK_CENTER) { console_sendString((uint8_t*)"Center "); } if (joyState != 0) { console_sendString((uint8_t*)"\r\n"); } TIM_Waitms(200); } }
void hw_wait_ms (int ms) { TIM_Waitms(ms); }
void InitLcdController (void) { TIM_TIMERCFG_Type TIM_ConfigStruct; uint8_t i2c_buf[2]; /* Transmit setup */ I2C_M_SETUP_Type txsetup; TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; TIM_ConfigStruct.PrescaleValue = 1; // Set configuration for Tim_config and Tim_MatchConfig TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct); init_i2c(100000); txsetup.sl_addr7bit = I2C_PCA9532_ADDR; txsetup.tx_data = i2c_buf; txsetup.tx_length = 2; txsetup.rx_data = NULL; txsetup.rx_length = 0; txsetup.retransmissions_max = 3; // "v1,cc0,c31,d50,o,d200,c51,cc100"; // 1st letter 2nd letter Meaning // c c Send command to update PWM // d Send command to update the status for Display Enable Pin // 3 Send command to update the status for 3V3 pin // 5 Send command to update the status for 5V pin // d Number Delay in a number of miliseconds // o open the LCD // v Sequence version info // PWM setting SetPWM(0); // 3V3 pin i2c_buf[0] = LSn(LCD_3V3_PIN_NUM); txsetup.tx_length = 1; txsetup.rx_data = &i2c_buf[1]; txsetup.rx_length = 1; if (I2C_MasterTransferData((en_I2C_unitId)I2CDEV, &txsetup, I2C_TRANSFER_POLLING) != SUCCESS){ return; } i2c_buf[1]&= ~0x03<<(BITn(LCD_3V3_PIN_NUM)); i2c_buf[1]|= LCD_OUT_LED<<(BITn(LCD_3V3_PIN_NUM)); txsetup.tx_length = 2; txsetup.rx_data = NULL; txsetup.rx_length = 0; if (I2C_MasterTransferData((en_I2C_unitId)I2CDEV, &txsetup, I2C_TRANSFER_POLLING) != SUCCESS){ return; } TIM_Waitms(250); // 5V pin i2c_buf[0] = LSn(LCD_5V_PIN_NUM); txsetup.tx_length = 1; txsetup.rx_data = &i2c_buf[1]; txsetup.rx_length = 1; if (I2C_MasterTransferData((en_I2C_unitId)I2CDEV, &txsetup, I2C_TRANSFER_POLLING) != SUCCESS){ return; } i2c_buf[1]&= ~(0x03 << (BITn(LCD_5V_PIN_NUM))); i2c_buf[1]|= LCD_OUT_LED <<(BITn(LCD_5V_PIN_NUM)); txsetup.tx_length = 2; txsetup.rx_data = NULL; txsetup.rx_length = 0; if (I2C_MasterTransferData((en_I2C_unitId)I2CDEV, &txsetup, I2C_TRANSFER_POLLING) != SUCCESS){ return; } // Set PWM SetPWM(100); TIM_DeInit(LPC_TIM0); }
void monitor_i2c_Test(void) { cmd_status_t result; int i; int j; sample_t* pData; monitor_i2c_Init(); testCfg.clockrate = 100000; testCfg.bytesToCapture = 1000; circbuff_Init(&testBuffer, 0x20000000, testCfg.bytesToCapture * SAMPLE_SIZE); result = monitor_i2c_Configure(&testBuffer, &testCfg); if (result != CMD_STATUS_OK) { log_i("Failed to configure I2C monitor. Error code %d. Entering infinite loop...\r\n", result); while(1); } log_i("Starting I2C monitor...\r\n"); j = 1; while (j--) { result = monitor_i2c_Start(); if (result != CMD_STATUS_OK) { log_i("Failed to configure I2C monitor. Error code %d. Entering infinite loop...\r\n", result); break; } log_i("Got I2C data...\r\n"); log_i("Timestamp Data Status Extra\r\n"); log_i("--------- ---- ------ -----\r\n"); pData = (sample_t*)testBuffer.data; for (i = 0; i < testCfg.bytesToCapture; i++) { switch (pData[i].data) { case 0xc0: case 0xac: log_i("%9u 0x%02x 0x%02x W:%02xh\r\n", pData[i].timestamp, pData[i].data, pData[i].status, pData[i].data>>1); break; case 0xc1: case 0xad: log_i("%9u 0x%02x 0x%02x R:%02xh\r\n", pData[i].timestamp, pData[i].data, pData[i].status, pData[i].data>>1); break; default: log_i("%9u 0x%02x 0x%02x\r\n", pData[i].timestamp, pData[i].data, pData[i].status); break; } TIM_Waitms(2);// to prevent lost printouts } } if (j==0) { log_i("Done sampling, entering infinite loop...\r\n"); } while(1); }
/*********************************************************************//** * @brief Initialize external SDRAM memory Micron sdram_h57v2562gtr * 256Mbit(16M x 16) * @param[in] None * @return None **********************************************************************/ void SDRAMInit( void ) { volatile uint32_t i; volatile unsigned long Dummy; TIM_TIMERCFG_Type TIM_ConfigStruct; TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; TIM_ConfigStruct.PrescaleValue = 1; // Set configuration for Tim_config and Tim_MatchConfig TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct); /* Enable External Memory Controller power/clock */ LPC_SC->PCONP |= 0x00000800; LPC_SC->EMCDLYCTL = 0x00001010; LPC_EMC->Control = 0x00000001; LPC_EMC->Config = 0x00000000; SDRAM_GPIO_Config(); LPC_SC->EMCCLKSEL=1; LPC_EMC->DynamicRP=EMC_NS2CLK(SDRAM_TRP); /* 20ns, */ LPC_EMC->DynamicRAS = EMC_NS2CLK(SDRAM_TRAS); /* 42ns to 100K ns, */ LPC_EMC->DynamicSREX = 1 - 1; /* tSRE, 1clk, */ LPC_EMC->DynamicAPR = SDRAM_TAPR - 1; /* Not found!!! Estimated as 2clk, */ LPC_EMC->DynamicDAL = EMC_NS2CLK(SDRAM_TRP) + 2; /* tDAL = tRP + tDPL = 20ns + 2clk */ LPC_EMC->DynamicWR = SDRAM_TWR - 1; /* 2CLK, */ LPC_EMC->DynamicRC = EMC_NS2CLK(63); /* H57V2562GTR-75C tRC=63ns(min)*/ LPC_EMC->DynamicRFC = EMC_NS2CLK(63); /* H57V2562GTR-75C tRFC=tRC */ LPC_EMC->DynamicXSR = SDRAM_TXSR-1; /* exit self-refresh to active*/ LPC_EMC->DynamicRRD = EMC_NS2CLK(63); /* 3clk, tRRD=15ns(min) */ LPC_EMC->DynamicMRD = SDRAM_TMRD - 1; /* 2clk, tMRD=2clk(min) */ LPC_EMC->DynamicReadConfig = 0x00000001; /* Command delayed strategy, using EMCCLKDELAY */ /* H57V2562GTR-75C: tCL=3CLK, tRCD=20ns(min), 3 CLK=24ns */ LPC_EMC->DynamicRasCas0 = 0x303; LPC_EMC->DynamicConfig0 = 0x680; TIM_Waitms(100); LPC_EMC->DynamicControl = 0x00000183; /* Issue NOP command */ TIM_Waitms(200); /* wait 200ms */ LPC_EMC->DynamicControl = 0x00000103; /* Issue PALL command */ LPC_EMC->DynamicRefresh = 0x00000002; /* ( n * 16 ) -> 32 clock cycles */ for(i = 0; i < 0x80; i++); /* wait 128 AHB clock cycles */ /* 64ms/8192=7.8125us, nx16x8.33ns<7.8125us, n<58.6*/ LPC_EMC->DynamicRefresh = EMC_SDRAM_REFRESH(64); LPC_EMC->DynamicControl = 0x00000083; /* Issue MODE command */ Dummy = *((volatile uint16_t *)(SDRAM_BASE_ADDR | (0x33<<12))); /* 8 burst, 3 CAS latency */ LPC_EMC->DynamicControl = 0x00000000; /* Issue NORMAL command */ LPC_EMC->DynamicConfig0 |= 0x80000; /* enable buffer */ TIM_Waitms(1); TIM_DeInit(LPC_TIM0); }