/*********************************************************************//** * @brief Print Message via COM1 * param[in] msg: point to CAN_MSG_Type object that will be printed * @return none **********************************************************************/ void PrintMessage(CAN_MSG_Type* CAN_Msg) { uint32_t data; _DBG("Message ID: "); _DBH32(CAN_Msg->id); _DBG_(""); _DBG("Message length: "); _DBH32(CAN_Msg->len); _DBG_(" BYTES"); _DBG("Message type: "); if(CAN_Msg->type==DATA_FRAME) { _DBG_("DATA FRAME "); } else _DBG_("REMOTE FRAME "); _DBG("Message format: "); if(CAN_Msg->format==STD_ID_FORMAT) { _DBG_("STANDARD ID FRAME FORMAT"); } else _DBG_("EXTENDED ID FRAME FORMAT"); _DBG("Message dataA: "); data = (CAN_Msg->dataA[0])|(CAN_Msg->dataA[1]<<8)|(CAN_Msg->dataA[2]<<16)|(CAN_Msg->dataA[3]<<24); _DBH32(data); _DBG_(""); data = (CAN_Msg->dataB[0])|(CAN_Msg->dataB[1]<<8)|(CAN_Msg->dataB[2]<<16)|(CAN_Msg->dataB[3]<<24); _DBG("Message dataB: "); _DBH32(data); _DBG_(""); _DBG_(""); }
/*********************************************************************//** * @brief TIMER1 interrupt handler sub-routine * @param[in] None * @return None **********************************************************************/ void TIMER1_IRQHandler(void) { if (TIM_GetIntCaptureStatus(LPC_TIM1,0)) { TIM_ClearIntCapturePending(LPC_TIM1,0); _DBG("Time capture: "); _DBH32(TIM_GetCaptureValue(LPC_TIM1,0));_DBG_(""); } }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return None **********************************************************************/ void c_entry (void) { uint8_t* pDest = (uint8_t*)VTOR_OFFSET; uint8_t* pSource = NULL; GPIO_Init(); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); GPIO_SetDir(BRD_LED_1_CONNECTED_PORT, BRD_LED_1_CONNECTED_MASK, 1); _DBG(" Remapping Vector Table at address: "); _DBH32(VTOR_OFFSET); _DBG_(""); NVIC_SetVTOR(VTOR_OFFSET); /* Copy Vector Table from 0x00000000 to new address * In ROM mode: Vector Interrupt Table is initialized at 0x00000000 * In RAM mode: Vector Interrupt Table is initialized at 0x10000000 * Aligned: 256 words */ #ifdef __RAM_MODE__ //Run in RAM mode pSource = (void*)0x10000000; memcpy(pDest,pSource , 256*4); #else pSource = (void*)0x00000000; memcpy(pDest,pSource , 256*4); #endif _DBG_(" If Vector Table remapping is successful, LED P2.10 will blink by using\n\r SysTick interrupt"); //Initialize System Tick with 100ms time interval /* Input parameter for SysTick in range 0..174 ms */ SYSTICK_InternalInit(100); //Enable System Tick interrupt SYSTICK_IntCmd(ENABLE); //Enable System Tick Counter SYSTICK_Cmd(ENABLE); while(1); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); //Use P0.0 to test System Tick interrupt GPIO_SetDir(1, (1<<28), 1); //Set P0.0 as output _DBG("Remapping Vector Table at address: "); _DBH32(VTOR_OFFSET); _DBG_(""); NVIC_SetVTOR(VTOR_OFFSET); /* Copy Vector Table from 0x00000000 to new address * In ROM mode: Vector Interrupt Table is initialized at 0x00000000 * In RAM mode: Vector Interrupt Table is initialized at 0x10000000 * Aligned: 256 words */ #if(__RAM_MODE__==0)//Run in ROM mode memcpy(VTOR_OFFSET, 0x00000000, 256*4); #else memcpy(VTOR_OFFSET, 0x10000000, 256*4); #endif _DBG_("If Vector Table remapping is successful, LED P1.28 will blink by using SysTick interrupt"); //Initialize System Tick with 100ms time interval SYSTICK_InternalInit(100); //Enable System Tick interrupt SYSTICK_IntCmd(ENABLE); //Enable System Tick Counter SYSTICK_Cmd(ENABLE); while(1); return 1; }
/*********************************************************************//** * @brief c_entry: main function * @param[in] none * @return int **********************************************************************/ int c_entry(void) { /* Main Program */ uint32_t temp; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu _DBG(menu); /* test Bit-banding SRAM first --------------------------------------------------------- */ _DBG_("Test bit-band SRAM... "); //read variable at VAR_ADDRESS temp = (*(volatile uint32_t *)(VAR_ADDRESS)); //print temp value _DBG("The value at address "); _DBH32(VAR_ADDRESS); _DBG(": "); _DBH32(temp); _DBG_(""); /* Use bitband function to read VAR_BIT value */ temp = BITBAND_SRAM_GetBit(VAR_ADDRESS,VAR_BIT); _DBG("Use bit-band function to get value at bit 3: ");_DBG_(""); _DBH32(temp); _DBG_(""); /* clear bit */ BITBAND_SRAM_ClearBit(VAR_ADDRESS,VAR_BIT); /* re-read temp value */ temp = (*(volatile uint32_t *)(VAR_ADDRESS)); _DBG("Value after clear bit 3 value by using bit-band function: ");_DBG_(""); _DBH32(temp); _DBG_(""); /* Set bit */ BITBAND_SRAM_SetBit(VAR_ADDRESS,VAR_BIT); /* re-read temp value */ temp = (*(volatile uint32_t *)(VAR_ADDRESS)); _DBG("Value after set bit 3 value by using bit-band function: ");_DBG_(""); _DBH32(temp); _DBG_(""); _DBG_(""); /* Then, test Bit-banding PERI --------------------------------------------------------- */ _DBG_("Test bit-band PERIPHERAL... "); LPC_SPI->SPCR =(1<<5)|(1<<3)|(10<<8); /* Read the current value of peripheral register */ temp = (*(volatile uint32_t *)(PERI_ADDRESS)); _DBG("The value of peripheral register at "); _DBH32(PERI_ADDRESS); _DBG(": ");_DBG_(""); _DBH32(temp); _DBG_(""); /* Use bitband function to read VAR_BIT value */ temp = BITBAND_PERI_GetBit(PERI_ADDRESS,PERI_BIT); _DBG("Use bit-band function to get value at bit 5: ");_DBG_(""); _DBH32(temp); _DBG_(""); /* clear bit */ BITBAND_PERI_ClearBit(PERI_ADDRESS,PERI_BIT); /* re-read temp value */ temp = (*(volatile uint32_t *)(PERI_ADDRESS)); _DBG("Peripheral register after clear bit 5 value by using bit-band function: ");_DBG_(""); _DBH32(temp); _DBG_(""); /* Set bit */ BITBAND_PERI_SetBit(PERI_ADDRESS,PERI_BIT); /* re-read temp value */ temp = (*(volatile uint32_t *)(PERI_ADDRESS)); _DBG("Peripheral register after set bit 5 value by using bit-band function: ");_DBG_(""); _DBH32(temp); _DBG_(""); while (1); return 0; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Main Program */ I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; PINSEL_CFG_Type PinCfg; uint32_t i; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu screen print_menu(); /* Initialize I2S peripheral ------------------------------------*/ /* Pin configuration: * Assign: - P0.4 as I2SRX_CLK * - P0.5 as I2SRX_WS * - P0.6 as I2SRX_SDA * - P0.7 as I2STX_CLK * - P0.8 as I2STX_WS * - P0.9 as I2STX_SDA */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 4; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 5; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); Buffer_Init(); I2S_Init(LPC_I2S); /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); I2S_SetBitRate(LPC_I2S, 0, I2S_RX_MODE); I2S_Stop(LPC_I2S, I2S_TX_MODE); I2S_Stop(LPC_I2S, I2S_RX_MODE); NVIC_EnableIRQ(I2S_IRQn); /* RX FIFO depth is 1, TX FIFO depth is 8. */ I2S_IRQConfig(LPC_I2S,I2S_TX_MODE,8); I2S_IRQConfig(LPC_I2S,I2S_RX_MODE,1); I2S_IRQCmd(LPC_I2S,I2S_RX_MODE,ENABLE); I2S_Start(LPC_I2S); /* I2S transmit ---------------------------------------------------*/ while ( I2SWriteLength < BUFFER_SIZE ) { while(I2S_GetLevel(LPC_I2S, I2S_TX_MODE)==TXFIFO_FULL); I2S_Send(LPC_I2S, I2STXBuffer[I2SWriteLength++]); } I2STXDone = 1; /* Wait for transmit/receive complete */ while ( !I2SRXDone || !I2STXDone ); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Verify RX and TX Buffer */ if(Buffer_Verify()) { _DBG_("Verify Buffer: OK..."); } else { _DBG_("Verify Buffer: ERROR..."); } return 0; }
/****************************************************************************** ** Main Function main() ******************************************************************************/ void c_entry (void) { uint8_t error = 0; st_Mci_CardId cidval; en_Mci_CardType cardType; debug_frmwrk_init(); _DBG_("");_DBG(mciCidCardMenu);_DBG_(""); #if MCI_DMA_ENABLED /* on DMA channel 0, source is memory, destination is MCI FIFO. */ /* On DMA channel 1, source is MCI FIFO, destination is memory. */ GPDMA_Init(); #endif /* For the SD card I tested, the minimum required block length is 512 */ /* For MMC, the restriction is loose, due to the variety of SD and MMC card support, ideally, the driver should read CSD register to find the right speed and block length for the card, and set them accordingly. In this driver example, it will support both MMC and SD cards, and it does read the information by send SEND_CSD to poll the card status, however, to simplify the example, it doesn't configure them accordingly based on the CSD register value. This is not intended to support all the SD and MMC cards. */ if(MCI_Init(BRD_MCI_POWERED_ACTIVE_LEVEL) != MCI_FUNC_OK) { _DBG_("MCI_Init FAILED"); while( 1 ); /* fatal error */ } cardType = MCI_GetCardType(); switch (cardType) { case MCI_SDHC_SDXC_CARD: _DBG_("Currently the SDXC/SDHC CARD ver2.0 is being used"); break; case MCI_SDSC_V2_CARD: _DBG_("Currently the SD CARD ver2.0 is being used"); break; case MCI_SDSC_V1_CARD: _DBG_("Currently the SD CARD ver1.0 is being used"); break; case MCI_MMC_CARD: _DBG_("Currently the MMC CARD is being used"); break; case MCI_CARD_UNKNOWN: _DBG_("No CARD is being plugged, Please check!!!"); error = 1; break; } if(error) while(1); if (MCI_GetCID(&cidval) != MCI_FUNC_OK) { _DBG_("Get CID Failed"); while ( 1 ); /* fatal error */ } else { _DBG("\n\r\t- Manufacture ID: ");_DBH32(cidval.MID);_DBG_(""); _DBG("\n\r\t- OEM/Application ID: ");_DBH32(cidval.OID);_DBG_(""); _DBG("\n\r\t- Product Name: ");_DBH(cidval.PNM_H);_DBH32_(cidval.PNM_L);_DBG_(""); _DBG("\n\r\t- Product Revision: ");_DBH32(cidval.PRV);_DBG_(""); _DBG("\n\r\t- Product Serial Number: ");_DBH32(cidval.PSN);_DBG_(""); _DBG("\n\r\t- Manufacturing Date: ");_DBH32(cidval.MDT);_DBG_(""); } while(1); }
/*********************************************************************//** * @brief Main I2S program body **********************************************************************/ int c_entry (void) { /* Main Program */ uint32_t i; uint8_t ch; uint8_t dummy=0; I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; I2S_PinCFG_Type I2S_PinStruct; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif NVIC_SetPriorityGrouping(0x06); debug_frmwrk_init(); print_menu(); _DBG_("Press '1' to initialize buffer..."); while(_DG !='1'); Buffer_Init(); _DBG_("Transmit Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2STXBuffer[i]);_DBG_(""); } _DBG_("Receive Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Initializes pin corresponding to I2S function */ I2S_PinStruct.CLK_Pin=I2S_STX_CLK_P0_7; I2S_PinStruct.WS_Pin=I2S_STX_WS_P0_8; I2S_PinStruct.SDA_Pin=I2S_STX_SDA_P0_9; I2S_PinStruct.MCLK_Pin=I2S_TX_MCLK_P4_29; PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_clk_pin[I2S_PinStruct.CLK_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_ws_pin[I2S_PinStruct.WS_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_sda_pin[I2S_PinStruct.SDA_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_tx_mclk_pin[I2S_PinStruct.MCLK_Pin])); // Configure pinsel for I2S_RX I2S_PinStruct.CLK_Pin=I2S_SRX_CLK_P0_4; I2S_PinStruct.WS_Pin=I2S_SRX_WS_P0_5; I2S_PinStruct.SDA_Pin=I2S_SRX_SDA_P0_6; I2S_PinStruct.MCLK_Pin=I2S_RX_MCLK_P4_28; PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_clk_pin[I2S_PinStruct.CLK_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_ws_pin[I2S_PinStruct.WS_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_sda_pin[I2S_PinStruct.SDA_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_rx_mclk_pin[I2S_PinStruct.MCLK_Pin])); I2S_Init(LPC_I2S); //Setup for I2S: RX is similar with TX /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz (x=8,y=51 - automatic setting) * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_0; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ClkConfig.fpin = I2S_4PIN_ENABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); /* Set up frequency and bit rate*/ I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); // I2S_SetBitRate(I2S, 1, I2S_RX_MODE); I2S_Start(LPC_I2S); _DBG_("Press '2' to start I2S transfer process..."); while(_DG !='2'); _DBG_("I2S Start ..."); while(I2STXDone == 0||I2SRXDone == 0){ if(I2STXDone ==0){ while (I2S_GetLevel(LPC_I2S,I2S_TX_MODE)!=0x00); I2S_Send(LPC_I2S,I2STXBuffer[I2SWriteLength]); I2SWriteLength +=1; if(I2SWriteLength == BUFFER_SIZE) I2STXDone = 1; } if(I2SRXDone == 0) { while(I2S_GetLevel(LPC_I2S,I2S_RX_MODE)==0x00); if(dummy == 0) //dummy receive { i = I2S_Receive(LPC_I2S); if(i!=0) { *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = i; I2SReadLength +=1; dummy = 1; } } else { *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = I2S_Receive(LPC_I2S); I2SReadLength +=1; } if(I2SReadLength == BUFFER_SIZE) I2SRXDone = 1; } } _DBG_("I2S Finish..."); _DBG_("Receive Buffer data: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } if(Buffer_Verify()) { _DBG_("Verify Buffer: OK..."); } else { _DBG_("Verify Buffer: ERROR..."); } while(1); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { uint32_t i; GPDMA_Channel_CFG_Type GPDMACfg; I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; I2S_DMAConf_Type I2S_DMAStruct; PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu screen print_menu(); //Initialize buffer Buffer_Init(); _DBG_("Press '1' to initialize buffer..."); while(_DG !='1'); _DBG_("Transmit Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2STXBuffer[i]);_DBG_(""); } _DBG_("Receive Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Pin configuration: * Assign: - P0.4 as I2SRX_CLK * - P0.5 as I2SRX_WS * - P0.6 as I2SRX_SDA * - P0.7 as I2STX_CLK * - P0.8 as I2STX_WS * - P0.9 as I2STX_SDA */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 4; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 5; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); /* Initialize I2S */ I2S_Init(LPC_I2S); //Setup for I2S: RX is similar with TX /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); /* Set up frequency and bit rate*/ I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); I2S_SetBitRate(LPC_I2S, 0, I2S_RX_MODE); _DBG_("Press '2' to initialize DMA..."); while(_DG !='2'); /* GPDMA Interrupt configuration section ------------------------------------------------- */ /* Initialize GPDMA controller */ GPDMA_Init(); LPC_GPDMA->DMACConfig = 0x01; /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* * Configure GPDMA channel 0 ------------------------------------------------------------- * Used for I2S Transmit */ // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = DMA_SRC; // Destination memory GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = BUFFER_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = GPDMA_CONN_I2S_Channel_0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); _DBG_("DMA Channel 0 setting finised..."); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* * Configure GPDMA channel 1 ------------------------------------------------------------- * Used for UART0 Receive */ // Setup GPDMA channel -------------------------------- // channel 1 GPDMACfg.ChannelNum = 1; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = DMA_DST; // Transfer size GPDMACfg.TransferSize = BUFFER_SIZE+1; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection - unused GPDMACfg.SrcConn = GPDMA_CONN_I2S_Channel_1; // Destination connection GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); _DBG_("DMA Channel 1 setting finised..."); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; // Enable GPDMA channel 0 & 1 GPDMA_ChannelCmd(0, ENABLE); GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); _DBG_("Press '3' to start I2S transfer process..."); while(_DG !='3'); _DBG_("I2S Start..."); I2S_DMAStruct.DMAIndex = I2S_DMA_2; I2S_DMAStruct.depth = 8; I2S_DMAConfig(LPC_I2S, &I2S_DMAStruct, I2S_RX_MODE); I2S_DMAStruct.DMAIndex = I2S_DMA_1; I2S_DMAStruct.depth = 1; I2S_DMAConfig(LPC_I2S, &I2S_DMAStruct, I2S_TX_MODE); I2S_Start(LPC_I2S); I2S_DMACmd(LPC_I2S, I2S_DMA_2, I2S_RX_MODE, ENABLE); I2S_DMACmd(LPC_I2S, I2S_DMA_1, I2S_TX_MODE, ENABLE); while ((Channel0_TC == 0)||(Channel1_TC == 0) ); _DBG_("I2S Finish..."); _DBG_("Receive Buffer data: ..."); for(i=0;i<BUFFER_SIZE+1;i++) { _DBH32(I2SRXBuffer[i]); if(I2SRXBuffer[i]==0) { _DBG_(" ->Dummy data"); } else _DBG_(""); } I2S_DeInit(LPC_I2S); while(1); return 1; }
int main(void) { uint16_t major, minor, build; char *type; int i, res, count, count2; volatile uint32_t d; // insert a small delay so power supply can stabilize for (d=0; d<2500000; d++); #ifdef KEIL pixyInit(SRAM3_LOC, &LR0[0], sizeof(LR0)); #else pixyInit(); #endif #if 0 i = 0; char *foo; while(1) { foo = new (std::nothrow) char[128]; if (foo==NULL) { _DBG("full\n"); break; } else { _DBH32((int)foo); _DBG(" "); _DBH32(i); _DBG("\n"); } i++; } while(1); #endif // main init of hardware plus a version-dependent number for the parameters that will // force a format of parameter between version numbers. #ifndef LEGO rcs_init(); #endif cc_init(g_chirpUsb); ser_init(); exec_init(g_chirpUsb); #if 0 exec_addProg(&g_progBlobs); ptLoadParams(); exec_addProg(&g_progPt); exec_addProg(&g_progVideo, true); #if 0 cam_setMode(CAM_MODE1); while(1) periodic(); #endif #endif #if 1 // load programs exec_addProg(&g_progBlobs); #ifndef LEGO // need to call this to get the pan/tilt parameters to display. // We can make some properties modal, meaning they are only diaplayed when the program is running. // We might want to do this here, but this is good for now. ptLoadParams(); exec_addProg(&g_progPt); #endif #if 0 chaseLoadParams(); exec_addProg(&g_progChase); #endif exec_addProg(&g_progVideo, true); #if 1 // this code formats if the version has changed for (i=0, count=0, count2=0; i<25; i++) { res = prm_get("fwver", &major, &minor, &build, END); if (res>=0 && major==FW_MAJOR_VER && minor==FW_MINOR_VER && build==FW_BUILD_VER) count++; res = prm_get("fwtype", &type, END); if (res>=0 && strcmp(type, FW_TYPE)==0) count2++; } if (count==0 || count2==0) prm_format(); #endif // check version prm_add("fwver", PRM_FLAG_INTERNAL, "", UINT16(FW_MAJOR_VER), UINT16(FW_MINOR_VER), UINT16(FW_BUILD_VER), END); prm_add("fwtype", PRM_FLAG_INTERNAL, "", STRING(FW_TYPE), END); exec_loop(); #endif #if 0 #define DELAY 1000000 rcs_setFreq(100); rcs_setLimits(0, -200, 200); rcs_setLimits(1, -200, 200); while(1) { rcs_setPos(0, 0); delayus(DELAY); rcs_setPos(0, 500); delayus(DELAY); rcs_setPos(0, 1000); delayus(DELAY); rcs_setPos(1, 0); delayus(DELAY); rcs_setPos(1, 500); delayus(DELAY); rcs_setPos(1, 1000); delayus(DELAY); } #endif #if 0 while(1) { g_chirpUsb->service(); handleButton(); } #endif }
/*********************************************************************//** * @brief c_entry: Main I2S program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { uint32_t i; uint32_t dummy=0; I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu screen print_menu(); Buffer_Init(); /* Pin configuration: * Assign: - P0.4 as I2SRX_CLK * - P0.5 as I2SRX_WS * - P0.6 as I2SRX_SDA * - P0.7 as I2STX_CLK * - P0.8 as I2STX_WS * - P0.9 as I2STX_SDA */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 4; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 5; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); I2S_Init(LPC_I2S); //Setup for I2S: RX is similar with TX /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz (x=8,y=51 - automatic setting) * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); /* Set up frequency and bit rate*/ I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); I2S_SetBitRate(LPC_I2S, 0, I2S_RX_MODE); I2S_Start(LPC_I2S); while(I2STXDone == 0||I2SRXDone == 0){ if(I2STXDone ==0){ I2S_Send(LPC_I2S,I2STXBuffer[I2SWriteLength]); I2SWriteLength +=1; if(I2SWriteLength == BUFFER_SIZE) I2STXDone = 1; } if(I2SRXDone == 0) { while(I2S_GetLevel(LPC_I2S,I2S_RX_MODE)==0x00); if(dummy == 0) //dummy receive { i = I2S_Receive(LPC_I2S); dummy = 1; } else { *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = I2S_Receive(LPC_I2S); I2SReadLength +=1; } if(I2SReadLength == BUFFER_SIZE) I2SRXDone = 1; } } /* print received data */ _DBG_("Receive Buffer data: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Validate received data */ if(Buffer_Verify()) { _DBG_("Verify Buffer: OK..."); } else { _DBG_("Verify Buffer: ERROR..."); } I2S_DeInit(LPC_I2S); while(1); }
/*********************************************************************//** * @brief The entry of the program * * @param[in]None * * @return None. * **********************************************************************/ void c_entry (void) { uint32_t result[4]; uint8_t ver_major, ver_minor; uint32_t i; uint8_t *ptr; uint32_t flash_prog_area_sec_start; uint32_t flash_prog_area_sec_end; IAP_STATUS_CODE status; // Initialize debug_frmwrk_init(); for (i = 0;i < sizeof(buffer);i++) { buffer[i] = (uint8_t)i; } flash_prog_area_sec_start = GetSecNum(FLASH_PROG_AREA_START); flash_prog_area_sec_end = GetSecNum(FLASH_PROG_AREA_START + FLASH_PROG_AREA_SIZE); _DBG_(menu); status = ReadPartID(result); if(status != CMD_SUCCESS) { _DBG("Read Part ID failed with code is ");_DBD(status);_DBG_(""); while(1); } _DBG("PartID: ");_DBH32(result[0]);_DBG_(""); status = ReadBootCodeVer(&ver_major, &ver_minor); if(status != CMD_SUCCESS) { _DBG("Read Boot Code Version failed with code is ");_DBD(status);_DBG_(""); while(1); } _DBG("Boot Code Version: ");_DBD(ver_major);_DBG(".");_DBD(ver_minor);_DBG_(""); status = ReadDeviceSerialNum(result); if(status != CMD_SUCCESS) { _DBG("Read UID failed with code is ");_DBD(status);_DBG_(""); while(1); } _DBG("UID: "); for(i = 0; i < 4; i++) { _DBD32(result[i]); if(i<3) _DBG("-"); } _DBG_(""); status = EraseSector(flash_prog_area_sec_start, flash_prog_area_sec_end); if(status != CMD_SUCCESS) { _DBG("Erase chip failed with code is ");_DBD(status);_DBG_(""); while(1); } status = BlankCheckSector(flash_prog_area_sec_start, flash_prog_area_sec_end, &result[0], &result[1]); if(status != CMD_SUCCESS) { _DBG("Blank Check failed with code is ");_DBD(status);_DBG_(""); if(status == SECTOR_NOT_BLANK) { _DBG(">>>>The first non-blank sector is sector "); _DBD(flash_prog_area_sec_start + result[0]); _DBG_(""); } while(1); } _DBG_("Erase chip: Success"); /* Be aware that Program and ErasePage take long time to complete!!! If bigger RAM is present, allocate big buffer and reduce the number of Program blocks. */ /* Program flash block by block until the end of the flash. */ for ( i = 0; i < FLASH_PROG_AREA_SIZE/BUFF_SIZE; i++ ) { ptr = (uint8_t*)(FLASH_PROG_AREA_START + i*BUFF_SIZE); status = CopyRAM2Flash(ptr, buffer,IAP_WRITE_1024); if(status != CMD_SUCCESS) { _DBG("Program chip failed with code is ");_DBD(status);_DBG_(""); while(1); } } // Compare for ( i = 0; i < FLASH_PROG_AREA_SIZE/BUFF_SIZE; i++ ) { ptr = (uint8_t*)(FLASH_PROG_AREA_START + i*BUFF_SIZE); status = Compare(ptr, buffer,BUFF_SIZE); if(status != CMD_SUCCESS) { _DBG("Compare memory failed with code is ");_DBD(status);_DBG_(""); while(1); } } _DBG_("Program chip: Success"); _DBG_("Demo termination"); while (1); }