/************************************************************* Function: void RS232SendMsg(void) Description: RS232发送数据函数,用于启动发送 Calls: GPDMA_Setup GPDMA_ChannelCmd Called By: Input: RS232Tx.Buff RS232Tx.Len Output: 无 Return: 无 Others: 无 *************************************************************/ void RS232SendMsg ( void ) { GPDMACfgTx.ChannelNum = 0; // Source memory GPDMACfgTx.SrcMemAddr = ( uint32_t ) &RS232Tx.Buff; // Transfer size GPDMACfgTx.TransferSize = RS232Tx.Len; // Destination connection GPDMACfgTx.DstConn = RS232_TX_PIN; GPDMA_Setup ( &GPDMACfgTx ); // Enable GPDMA channel 0 GPDMA_ChannelCmd ( 0, ENABLE ); }
/************************************************************* Function: void RS485Ch2SendMsg(void) Description: RS485发送数据函数,用于启动发送 Calls: GPDMA_Setup GPDMA_ChannelCmd Called By: Input: RS485Tx2.Buff RS485Tx2.Len Output: 无 Return: 无 Others: 无 *************************************************************/ void RS485Ch2SendMsg ( void ) { GPDMACfgTx.ChannelNum = 2; // Source memory GPDMACfgTx.SrcMemAddr = ( uint32_t ) &RS485Tx2.Buff; // Transfer size GPDMACfgTx.TransferSize = RS485Tx2.Len; // Destination connection GPDMACfgTx.DstConn = GPDMA_CONN_UART2_Tx; GPDMA_Setup ( &GPDMACfgTx ); // Enable GPDMA channel 0 GPDMA_ChannelCmd ( 2, ENABLE ); RS485Tx2.Flag = 1; }
/*********************************************************************//** * @brief Main GPDMA program body **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; // 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 /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* GPDMA block section -------------------------------------------- */ /* Initialize buffer */ _DBG_("Initialize Buffer..."); Buffer_Init(); /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = DMA_SRC; // Destination memory GPDMACfg.DstMemAddr = DMA_DST; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; _DBG_("Start transfer..."); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); /* Verify buffer */ Buffer_Verify(); _DBG(compl_menu); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief Main SSP program body **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; PINSEL_CFG_Type PinCfg; // 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 /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initializing SSP device section ------------------------------------------------------ */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP0, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP0, ENABLE); /* GPDMA Interrupt configuration section ------------------------------------------------- */ /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Initializing Buffer section ----------------------------------------------------------- */ Buffer_Init(); /* Initialize GPDMA controller */ GPDMA_Init(); /* 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 -------------------------------------------------------------*/ /* DMA Channel 0 */ GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t) &dma_src; // Destination memory - Not used GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = sizeof(dma_src); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = GPDMA_CONN_SSP0_Tx; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback0); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Configure GPDMA channel 1 -------------------------------------------------------------*/ /* DMA Channel 1 */ GPDMACfg.ChannelNum = 1; // Source memory - not used GPDMACfg.SrcMemAddr = 0; // Destination memory - Not used GPDMACfg.DstMemAddr = (uint32_t) &dma_dst; // Transfer size GPDMACfg.TransferSize = sizeof(dma_dst); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_SSP0_Rx; // Destination connection - not used GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback1); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; _DBG_("Start transfer..."); // Enable Tx and Rx DMA on SSP0 SSP_DMACmd (LPC_SSP0, SSP_DMA_RX, ENABLE); SSP_DMACmd (LPC_SSP0, SSP_DMA_TX, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); /* Wait for GPDMA processing complete */ while (((Channel0_TC == 0) && (Channel0_Err == 0)) \ || ((Channel1_TC == 0) && (Channel1_Err ==0))); /* Verify buffer */ Buffer_Verify(); _DBG_("Verify complete!"); /* Loop forever */ while(1); return 1; }
/************************************************************* Function: void UartInit(uint8_t num,uint32_t baudrate,uint8_t parity) Description: 串口初始化函数用于初始化RS232及RS485 将UART配置为中断接收,DMA发送,RS485自动切换方向 Calls: Called By: main() Input: num 串口号0、1、2 baudrate 波特率 parity 校验方式 Output: 无 Return: 无 Others: 无 *************************************************************/ void UartInit ( uint8_t num, uint32_t baudrate, uint8_t parity ) { // uint32_t idx; // RS485 configuration UART1_RS485_CTRLCFG_Type rs485cfg; // UART Configuration structure variable UART_CFG_Type UARTConfigStruct; // UART FIFO configuration Struct variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; GPDMA_Channel_CFG_Type GPDMACfg; UART_ConfigStructInit ( &UARTConfigStruct ); UARTConfigStruct.Baud_rate = baudrate; UARTConfigStruct.Parity = parity; UART_FIFOConfigStructInit ( &UARTFIFOConfigStruct ); // Enable DMA mode in UART UARTFIFOConfigStruct.FIFO_DMAMode = ENABLE; // Destination memory - don't care GPDMACfgTx.DstMemAddr = 0; // Transfer width - don't care GPDMACfgTx.TransferWidth = 0; // Transfer type GPDMACfgTx.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - don't care GPDMACfgTx.SrcConn = 0; // Linker List Item - unused GPDMACfgTx.DMALLI = 0; rs485cfg.AutoDirCtrl_State = ENABLE; rs485cfg.DirCtrlPol_Level = SET; rs485cfg.DelayValue = 50; rs485cfg.NormalMultiDropMode_State = ENABLE; rs485cfg.AutoAddrDetect_State = DISABLE; rs485cfg.Rx_State = ENABLE; if ( num == 0 ) { //PINSEL_ConfigPin(0,2,1); //UART0 //PINSEL_ConfigPin(0,3,1); //UART0 PINSEL_ConfigPin ( 0, 25, 0x03 ); PINSEL_ConfigPin ( 0, 26, 0xb3 ); // Initalize UART0 peripheral with given to corresponding parameter UART_Init ( RS232_UART, &UARTConfigStruct ); // Initialize FIFO for UART0 peripheral UART_FIFOConfig ( RS232_UART, &UARTFIFOConfigStruct ); // Enable UART Transmit UART_TxCmd ( RS232_UART, ENABLE ); // channel 0 GPDMACfgTx.ChannelNum = 0; // Source memory GPDMACfgTx.SrcMemAddr = ( uint32_t ) &RS232Tx.Buff; // Transfer size GPDMACfgTx.TransferSize = sizeof ( RS232Tx.Buff ); // Destination connection GPDMACfgTx.DstConn = RS232_TX_PIN; RS232Tx.Flag = 0; RS232_Err = 0; UART_IntConfig ( RS232_UART, UART_INTCFG_RBR, ENABLE ); UART_IntConfig ( RS232_UART, UART_INTCFG_RLS, ENABLE ); NVIC_SetPriority ( RS232_IRQN, ( ( 0x01 << 3 ) | 0x01 ) ); NVIC_EnableIRQ ( RS232_IRQN ); RS232Rx.Flag = 0 ; RS232Rx.Len = 0 ; RS232Rx.Idx = 0 ; } if ( num == 1 ) { PINSEL_ConfigPin ( 2, 0, 2 ); PINSEL_ConfigPin ( 2, 1, 2 ); PINSEL_ConfigPin ( 2, 5, 2 ); //U1_DTR rs485cfg.DirCtrlPin = UART1_RS485_DIRCTRL_DTR; UART_Init ( ( LPC_UART_TypeDef * ) LPC_UART1, &UARTConfigStruct ); UART_FIFOConfig ( ( LPC_UART_TypeDef * ) LPC_UART1, &UARTFIFOConfigStruct ); UART_RS485Config ( ( LPC_UART_TypeDef * ) LPC_UART1, &rs485cfg ); // Enable UART Transmit UART_TxCmd ( ( LPC_UART_TypeDef * ) LPC_UART1, ENABLE ); GPDMACfgTx.ChannelNum = 1; // Source memory GPDMACfgTx.SrcMemAddr = ( uint32_t ) &RS485Tx1.Buff; // Transfer size GPDMACfgTx.TransferSize = sizeof ( RS485Tx1.Buff ); // Destination connection GPDMACfgTx.DstConn = GPDMA_CONN_UART1_Tx; /* Reset terminal counter */ RS485Tx1.Flag = 0; /* Reset Error counter */ RS4851_Err = 0; /* Enable UART Rx interrupt */ UART_IntConfig ( ( LPC_UART_TypeDef * ) LPC_UART1, UART_INTCFG_RBR, ENABLE ); /* Enable UART line status interrupt */ UART_IntConfig ( ( LPC_UART_TypeDef * ) LPC_UART1, UART_INTCFG_RLS, ENABLE ); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority ( UART1_IRQn, ( ( 0x01 << 3 ) | 0x01 ) ); /* Enable Interrupt for UART0 channel */ NVIC_EnableIRQ ( UART1_IRQn ); } if ( num == 2 ) { PINSEL_ConfigPin ( 2, 8, 2 ); PINSEL_ConfigPin ( 2, 9, 2 ); PINSEL_ConfigPin ( 2, 6, 4 ); //U2_OE UART_Init ( LPC_UART2, &UARTConfigStruct ); UART_FIFOConfig ( LPC_UART2, &UARTFIFOConfigStruct ); UART_RS485Config ( ( LPC_UART_TypeDef * ) LPC_UART2, &rs485cfg ); // Enable UART Transmit UART_TxCmd ( LPC_UART2, ENABLE ); GPDMACfgTx.ChannelNum = 2; // Source memory GPDMACfgTx.SrcMemAddr = ( uint32_t ) &RS485Tx2.Buff; // Transfer size GPDMACfgTx.TransferSize = sizeof ( RS485Tx2.Buff ); // Destination connection GPDMACfgTx.DstConn = GPDMA_CONN_UART2_Tx; /* Reset terminal counter */ RS485Tx2.Flag = 0; /* Reset Error counter */ RS4852_Err = 0; /* Enable UART Rx interrupt */ UART_IntConfig ( LPC_UART2, UART_INTCFG_RBR, ENABLE ); /* Enable UART line status interrupt */ UART_IntConfig ( LPC_UART2, UART_INTCFG_RLS, ENABLE ); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority ( UART2_IRQn, ( ( 0x01 << 3 ) | 0x01 ) ); /* Enable Interrupt for UART0 channel */ NVIC_EnableIRQ ( UART2_IRQn ); } /* Initialize GPDMA controller */ GPDMA_Init(); /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ ( DMA_IRQn ); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority ( DMA_IRQn, ( ( 0x01 << 3 ) | 0x01 ) ); // Setup channel with given parameter GPDMA_Setup ( &GPDMACfgTx ); // Enable interrupt for DMA NVIC_EnableIRQ ( DMA_IRQn ); // Enable GPDMA channel 0 //GPDMA_ChannelCmd(0, ENABLE); CRC_Init ( CRC_POLY_CRC16 ); }
/*********************************************************************//** * @brief c_entry: Main DAC program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; DAC_CONVERTER_CFG_Type DAC_ConverterConfigStruct; GPDMA_LLI_Type DMA_LLI_Struct; uint32_t tmp; uint32_t i; uint32_t sin_0_to_90_16_samples[16]={\ 0,1045,2079,3090,4067,\ 5000,5877,6691,7431,8090,\ 8660,9135,9510,9781,9945,10000\ }; uint32_t dac_sine_lut[NUM_SINE_SAMPLE]; /* * Init DAC pin connect * AOUT on P0.26 */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 26; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); //Prepare DAC sine look up table for(i=0;i<NUM_SINE_SAMPLE;i++) { if(i<=15) { dac_sine_lut[i] = 512 + 512*sin_0_to_90_16_samples[i]/10000; if(i==15) dac_sine_lut[i]= 1023; } else if(i<=30) { dac_sine_lut[i] = 512 + 512*sin_0_to_90_16_samples[30-i]/10000; } else if(i<=45) { dac_sine_lut[i] = 512 - 512*sin_0_to_90_16_samples[i-30]/10000; } else { dac_sine_lut[i] = 512 - 512*sin_0_to_90_16_samples[60-i]/10000; } dac_sine_lut[i] = (dac_sine_lut[i]<<6); } //Prepare DMA link list item structure DMA_LLI_Struct.SrcAddr= (uint32_t)dac_sine_lut; DMA_LLI_Struct.DstAddr= (uint32_t)&(LPC_DAC->DACR); DMA_LLI_Struct.NextLLI= (uint32_t)&DMA_LLI_Struct; DMA_LLI_Struct.Control= DMA_SIZE | (2<<18) //source width 32 bit | (2<<21) //dest. width 32 bit | (1<<26) //source increment ; /* GPDMA block section -------------------------------------------- */ /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t)(dac_sine_lut); // Destination memory - unused GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = GPDMA_CONN_DAC; // Linker List Item - unused GPDMACfg.DMALLI = (uint32_t)&DMA_LLI_Struct; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); DAC_ConverterConfigStruct.CNT_ENA =SET; DAC_ConverterConfigStruct.DMA_ENA = SET; DAC_Init(LPC_DAC); /* set time out for DAC*/ tmp = (PCLK_DAC_IN_MHZ*1000000)/(SINE_FREQ_IN_HZ*NUM_SINE_SAMPLE); DAC_SetDMATimeOut(LPC_DAC,tmp); DAC_ConfigDAConverterControl(LPC_DAC, &DAC_ConverterConfigStruct); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); while (1); return 1; }
/** * @brief Main program body */ int c_entry(void) { PINSEL_CFG_Type PinCfg; GPDMA_Channel_CFG_Type GPDMACfg; uint32_t adc_value, tmp; // 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 /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* GPDMA block section -------------------------------------------- */ /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* * Init LPC_ADC pin connect * AD0.2 on P0.25 */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 25; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); /* Configuration for ADC : * Frequency at 1Mhz * ADC channel 2, generate interrupt to make a request for DMA source */ ADC_Init(LPC_ADC, 1000000); ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,SET); ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,SET); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = (uint32_t) &adc_value; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_ADC; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); while (1) { // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); ADC_StartCmd(LPC_ADC,ADC_START_NOW); /* Wait for GPDMA processing complete */; while ((Channel0_TC == 0) ); // Disable GPDMA channel 0 GPDMA_ChannelCmd(0, DISABLE); //Display the result of conversion on the UART0 _DBG("ADC value on channel 2: "); _DBD32(ADC_DR_RESULT(adc_value)); _DBG_(""); // Wait for a while for(tmp = 0; tmp < 1000000; tmp++); // Re-setup channel GPDMA_Setup(&GPDMACfg, GPDMA_Callback); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; } ADC_DeInit(LPC_ADC); return 1; }
void LED_init(){ GPIO_SetDir(LED_OE_PORT, LED_OE_BIT, 1); GPIO_SetValue(LED_OE_PORT, LED_OE_BIT);//turn off leds active low LatchIn();//reset GPIO_SetDir(LED_LE_PORT, LED_LE_BIT, 1); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); //reset all arrays for (uint8_t tmp=0;tmp<no_SEQ_BITS;tmp++){ SEQ_BIT[tmp] = BITORDER[tmp]; SEQ_TIME[tmp] = BITTIME[BITORDER[tmp]]; } resetLeds(); calulateLEDMIBAMBits(); // Initialize SPI pin connect PINSEL_CFG_Type PinCfg; /* LE1 */ PinCfg.Funcnum = PINSEL_FUNC_0; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLDOWN; PinCfg.Pinnum = LED_LE_PIN; PinCfg.Portnum = LED_LE_PORT; PINSEL_ConfigPin(&PinCfg); /* SSEL1 */ PinCfg.Funcnum = PINSEL_FUNC_0; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLDOWN; PinCfg.Pinnum = LED_OE_PIN; PinCfg.Portnum = LED_OE_PORT; PINSEL_ConfigPin(&PinCfg); /* SCK1 */ PinCfg.Funcnum = PINSEL_FUNC_2; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Pinnum = LED_SCK_PIN; PinCfg.Portnum = LED_SCK_PORT; PINSEL_ConfigPin(&PinCfg); /* MISO1 */ PinCfg.Funcnum = PINSEL_FUNC_2; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Pinnum = LED_MISO_PIN; PinCfg.Portnum = LED_MISO_PORT; PINSEL_ConfigPin(&PinCfg); PinCfg.Funcnum = PINSEL_FUNC_2; /* MOSI1 */ PinCfg.Funcnum = PINSEL_FUNC_2; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Pinnum = LED_MOSI_PIN; PinCfg.Portnum = LED_MOSI_PORT; PINSEL_ConfigPin(&PinCfg); /* initialize SSP configuration structure */ SSP_CFG_Type SSP_ConfigStruct; SSP_ConfigStruct.CPHA = SSP_CPHA_SECOND; SSP_ConfigStruct.CPOL = SSP_CPOL_LO; SSP_ConfigStruct.ClockRate = SSP_SPEED; // TLC5927 max freq = 30Mhz SSP_ConfigStruct.FrameFormat = SSP_FRAME_SPI; SSP_ConfigStruct.Databit = SSP_DATABIT_16; SSP_ConfigStruct.Mode = SSP_MASTER_MODE; SSP_Init(LED_SPI_CHN, &SSP_ConfigStruct); SSP_Cmd(LED_SPI_CHN, ENABLE); // Enable SSP peripheral // Setup LED interupt // xprintf(INFO "LED TIM0_ConfigMatch");FFL_(); TIM_TIMERCFG_Type TIM0_ConfigStruct; TIM_MATCHCFG_Type TIM0_MatchConfigStruct; TIM0_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; // Initialize timer 0, prescale count time of 1us //1000000uS = 1S TIM0_ConfigStruct.PrescaleValue = 1; TIM0_MatchConfigStruct.MatchChannel = 0; // use channel 0, MR0 TIM0_MatchConfigStruct.IntOnMatch = TRUE; // Enable interrupt when MR0 matches the value in TC register TIM0_MatchConfigStruct.ResetOnMatch = TRUE; //Enable reset on MR0: TIMER will reset if MR0 matches it TIM0_MatchConfigStruct.StopOnMatch = FALSE; //Stop on MR0 if MR0 matches it TIM0_MatchConfigStruct.ExtMatchOutputType = TIM_EXTMATCH_NOTHING; TIM0_MatchConfigStruct.MatchValue = BITTIME[0]; // Set Match value, count value of 1000000 (1000000 * 1uS = 1000000us = 1s --> 1 Hz) TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM0_ConfigStruct); // Set configuration for Tim_config and Tim_MatchConfig TIM_ConfigMatch(LPC_TIM0,&TIM0_MatchConfigStruct); NVIC_SetPriority(TIMER0_IRQn, 0); NVIC_EnableIRQ(TIMER0_IRQn); // xprintf(OK "LED TIM0_ConfigMatch");FFL_(); // Setup LED Latch interupt // xprintf(INFO "LED TIM1_ConfigMatch");FFL_(); TIM_TIMERCFG_Type TIM1_ConfigStruct; TIM_MATCHCFG_Type TIM1_MatchConfigStruct; TIM1_ConfigStruct.PrescaleOption = TIM_PRESCALE_TICKVAL; // Initialize timer 0, prescale count time of 1us //1000000uS = 1S TIM1_ConfigStruct.PrescaleValue = 1; TIM1_MatchConfigStruct.MatchChannel = 0; // use channel 0, MR0 TIM1_MatchConfigStruct.IntOnMatch = TRUE; // Enable interrupt when MR0 matches the value in TC register TIM1_MatchConfigStruct.ResetOnMatch = TRUE; //Enable reset on MR0: TIMER will reset if MR0 matches it TIM1_MatchConfigStruct.StopOnMatch = TRUE; //Stop on MR0 if MR0 matches it TIM1_MatchConfigStruct.ExtMatchOutputType = TIM_EXTMATCH_NOTHING; TIM1_MatchConfigStruct.MatchValue = LED_Latch_interupt_delay; // Set Match value, count value of 1000000 (1000000 * 1uS = 1000000us = 1s --> 1 Hz) TIM_Init(LPC_TIM1, TIM_TIMER_MODE,&TIM1_ConfigStruct); // Set configuration for Tim_config and Tim_MatchConfig TIM_ConfigMatch(LPC_TIM1,&TIM1_MatchConfigStruct); NVIC_SetPriority(TIMER1_IRQn, 0); NVIC_EnableIRQ(TIMER1_IRQn); // xprintf(OK "LED TIM1_ConfigMatch");FFL_(); // Speed timer // xprintf(INFO "LED TIM2_ConfigMatch");FFL_(); TIM_TIMERCFG_Type TIM2_ConfigStruct; TIM_MATCHCFG_Type TIM2_MatchConfigStruct; TIM2_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; // Initialize timer 0, prescale count time of 1us //1000000uS = 1S TIM2_ConfigStruct.PrescaleValue = 1000; TIM2_MatchConfigStruct.MatchChannel = 0; // use channel 0, MR0 TIM2_MatchConfigStruct.IntOnMatch = TRUE; // Enable interrupt when MR0 matches the value in TC register TIM2_MatchConfigStruct.ResetOnMatch = TRUE; //Enable reset on MR0: TIMER will reset if MR0 matches it TIM2_MatchConfigStruct.StopOnMatch = FALSE; //Stop on MR0 if MR0 matches it TIM2_MatchConfigStruct.ExtMatchOutputType = TIM_EXTMATCH_NOTHING; TIM2_MatchConfigStruct.MatchValue = 256; // Set Match value, count value of 1000000 (1000000 * 1uS = 1000000us = 1s --> 1 Hz) TIM_Init(LPC_TIM2, TIM_TIMER_MODE,&TIM2_ConfigStruct); // Set configuration for Tim_config and Tim_MatchConfig TIM_ConfigMatch(LPC_TIM2,&TIM2_MatchConfigStruct); NVIC_SetPriority(TIMER2_IRQn, 0); NVIC_EnableIRQ(TIMER2_IRQn); // xprintf(OK "LED TIM2_ConfigMatch");FFL_(); #ifdef DMA // GPDMA_Channel_CFG_Type GPDMACfg; NVIC_SetPriority(DMA_IRQn, 0); // set according to main.c NVIC_EnableIRQ(DMA_IRQn); GPDMA_Init(); // Initialize GPDMA controller */ NVIC_DisableIRQ (DMA_IRQn); // Disable interrupt for DMA NVIC_SetPriority(DMA_IRQn, 0); // set according to main.c GPDMACfg.ChannelNum = 0; // DMA Channel 0 GPDMACfg.SrcMemAddr = 0; // Source memory - not used - will be sent in interrupt so independent bit Linker Lists can be chosen GPDMACfg.DstMemAddr = 0; // Destination memory - not used - only used when destination is memory GPDMACfg.TransferSize = 1; // Transfer size GPDMACfg.TransferWidth = GPDMA_WIDTH_HALFWORD; // Transfer width - not used GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Transfer type GPDMACfg.SrcConn = 0; // Source connection - not used GPDMACfg.DstConn = GPDMA_CONN_SSP0_Tx; // Destination connection - not used GPDMACfg.DMALLI = (uint32_t) &LinkerList[0][0][0]; // Linker List Item - Pointer to linker list GPDMA_Setup(&GPDMACfg); // Setup channel with given parameter // Linker list 32bit Control uint32_t LinkerListControl = 0; LinkerListControl = GPDMA_DMACCxControl_TransferSize((uint32_t)GPDMACfg.TransferSize) \ | GPDMA_DMACCxControl_SBSize((uint32_t)GPDMA_BSIZE_1) \ | GPDMA_DMACCxControl_DBSize((uint32_t)GPDMA_BSIZE_1) \ | GPDMA_DMACCxControl_SWidth((uint32_t)GPDMACfg.TransferWidth) \ | GPDMA_DMACCxControl_DWidth((uint32_t)GPDMACfg.TransferWidth) \ | GPDMA_DMACCxControl_SI; uint8_t reg, bit, linkerListNo, buf; for (buf=0;buf<BUFFERS;buf++){ for (bit=0;bit<BITS;bit++){ linkerListNo=0; for (reg=5; 0<reg;reg--,linkerListNo++){ // xprintf("bit:%d reg:%d SrcAddr:0x%x DstAddr:0x%x NextLLI:0x%x linkerListNo:0x%x\n",bit,reg,(uint32_t) &LED_PRECALC[reg][bit][buf],(uint32_t) &LPC_SSP0->DR,(uint32_t) &LinkerList[linkerListNo+1][bit][buf],linkerListNo); LinkerList[linkerListNo][bit][buf].SrcAddr = (uint32_t) &LED_PRECALC[reg][bit][buf]; /**< Source Address */ LinkerList[linkerListNo][bit][buf].DstAddr = (uint32_t) &LPC_SSP0->DR; /**< Destination address */ LinkerList[linkerListNo][bit][buf].NextLLI = (uint32_t) &LinkerList[linkerListNo+1][bit][buf]; /**< Next LLI address, otherwise set to '0' */ LinkerList[linkerListNo][bit][buf].Control = LinkerListControl; // xprintf("SrcAddr:0x%x DstAddr:0x%x NextLLI:0x%x\n",(uint32_t) &LinkerList[linkerListNo][bit][buf].SrcAddr,(uint32_t) &LinkerList[linkerListNo][bit][buf].DstAddr,(uint32_t) &LinkerList[linkerListNo][bit][buf].NextLLI,(uint32_t) &LinkerList[linkerListNo][bit][buf].Control); } // if (reg==0){ // xprintf("bit:%d reg:%d SrcAddr:0x%x DstAddr:0x%x NextLLI:0x%x linkerListNo:0x%x\n",bit,reg,(uint32_t) &LED_PRECALC[reg][bit][buf],(uint32_t) &LPC_SSP0->DR,(uint32_t) &LinkerList[linkerListNo+1][bit][buf],linkerListNo); LinkerList[linkerListNo][bit][buf].SrcAddr = (uint32_t) &LED_PRECALC[reg][bit][buf]; /**< Source Address */ LinkerList[linkerListNo][bit][buf].DstAddr = (uint32_t) &LPC_SSP0->DR; /**< Destination address */ LinkerList[linkerListNo][bit][buf].NextLLI = (uint32_t) &LinkerList[linkerListNo+1][bit][buf];/**< Next LLI address, otherwise set to '0' */ LinkerList[linkerListNo][bit][buf].Control = LinkerListControl; linkerListNo++; // xprintf("SrcAddr:0x%x DstAddr:0x%x NextLLI:0x%x\n",(uint32_t) &LinkerList[linkerListNo][bit][buf].SrcAddr,(uint32_t) &LinkerList[linkerListNo][bit][buf].DstAddr,(uint32_t) &LinkerList[linkerListNo][bit][buf].NextLLI,(uint32_t) &LinkerList[linkerListNo][bit][buf].Control); // } for (reg=11; reg>6;reg--,linkerListNo++){ // xprintf("bit:%d reg:%d SrcAddr:0x%x DstAddr:0x%x NextLLI:0x%x linkerListNo:0x%x\n",bit,reg,(uint32_t) &LED_PRECALC[reg][bit][buf],(uint32_t) &LPC_SSP0->DR,(uint32_t) &LinkerList[linkerListNo+1][bit][buf],linkerListNo); LinkerList[linkerListNo][bit][buf].SrcAddr = (uint32_t) &LED_PRECALC[reg][bit][buf]; /**< Source Address */ LinkerList[linkerListNo][bit][buf].DstAddr = (uint32_t) &LPC_SSP0->DR; /**< Destination address */ LinkerList[linkerListNo][bit][buf].NextLLI = (uint32_t) &LinkerList[linkerListNo+1][bit][buf]; /**< Next LLI address, otherwise set to '0' */ LinkerList[linkerListNo][bit][buf].Control = LinkerListControl; // xprintf("SrcAddr:0x%x DstAddr:0x%x NextLLI:0x%x\n",(uint32_t) &LinkerList[linkerListNo][bit][buf].SrcAddr,(uint32_t) &LinkerList[linkerListNo][bit][buf].DstAddr,(uint32_t) &LinkerList[linkerListNo][bit][buf].NextLLI,(uint32_t) &LinkerList[linkerListNo][bit][buf].Control); } // if (reg==7){ // xprintf("bit:%d reg:%d SrcAddr:0x%x DstAddr:0x%x NextLLI:0x%x linkerListNo:0x%x\n",bit,reg,(uint32_t) &LED_PRECALC[reg][bit][buf],(uint32_t) &LPC_SSP0->DR,(uint32_t) &LinkerList[linkerListNo+1][bit][buf],linkerListNo); LinkerList[linkerListNo][bit][buf].SrcAddr = (uint32_t) &LED_PRECALC[reg][bit][buf]; /**< Source Address */ LinkerList[linkerListNo][bit][buf].DstAddr = (uint32_t) &LPC_SSP0->DR; /**< Destination address */ LinkerList[linkerListNo][bit][buf].NextLLI = 0; /**< Next LLI address, otherwise set to '0' */ LinkerList[linkerListNo][bit][buf].Control = LinkerListControl; linkerListNo++; // xprintf("SrcAddr:0x%x DstAddr:0x%x NextLLI:0x%x NextLLI_V:0x%x\n",(uint32_t) &LinkerList[linkerListNo][bit][buf].SrcAddr,(uint32_t) &LinkerList[linkerListNo][bit][buf].DstAddr,(uint32_t) &LinkerList[linkerListNo][bit][buf].NextLLI,LinkerList[linkerListNo][bit][buf].NextLLI); // } } } SSP_DMACmd (LED_SPI_CHN, SSP_DMA_TX, ENABLE); // Enable Tx DMA on SSP0 // GPDMA_ChannelCmd(0, ENABLE); // Enable GPDMA channel 0 NVIC_EnableIRQ (DMA_IRQn); // Enable interrupt for DMA xprintf(OK "DMA Setup");FFL_(); TIM_Cmd(LPC_TIM0,ENABLE); // To start timer 0 // TIM_Cmd(LPC_TIM1,ENABLE); // To start timer 1 //done at DMA end TIM_Cmd(LPC_TIM2,ENABLE); // To start timer 2 xprintf(OK "TIM_Cmd(LPC_TIM0/2,ENABLE);");FFL_(); // Start LED Pattern uint8_t pot = 65; Set_LED_Pattern(1,121,pot); xprintf(OK "LED Pattern Started");FFL_(); #endif #ifdef RxDMA // SSP Rx DMA GPDMA_Channel_CFG_Type GPDMACfg1; /* Configure GPDMA channel 1 -------------------------------------------------------------*/ GPDMACfg1.ChannelNum = 1; // DMA Channel 0 GPDMACfg1.SrcMemAddr = 0; // Source memory - not used - will be sent in interrupt so independent bit Linker Lists can be chosen GPDMACfg1.DstMemAddr = (uint32_t) &LED_PRECALC1[0][0]; // Destination memory - not used - only used when destination is memory GPDMACfg1.TransferSize = 1; // Transfer size GPDMACfg1.TransferWidth = GPDMA_WIDTH_HALFWORD; // Transfer width GPDMACfg1.TransferType = GPDMA_TRANSFERTYPE_P2M; // Transfer type GPDMACfg1.SrcConn = GPDMA_CONN_SSP0_Rx; // Source connection - not used GPDMACfg1.DstConn = 0; // Destination connection - not used GPDMACfg1.DMALLI = 0; // Linker List Item - Pointer to linker list GPDMA_Setup(&GPDMACfg1); // Setup channel with given parameter Channel1_TC = 0; // Reset terminal counter Channel1_Err = 0; // Reset Error counter xprintf(OK "DMA Rx Setup");FFL_(); // SSP_DMACmd (LED_SPI_CHN, SSP_DMA_RX, ENABLE); // Enable Tx DMA on SSP0 // GPDMA_ChannelCmd(1, ENABLE); // Enable GPDMA channel 0 #endif }
/*********************************************************************//** * @brief c_entry: Main ADC program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { volatile uint32_t tmp; #if !__DMA_USED__ uint32_t adc_value; #endif uint8_t quit; EXTI_InitTypeDef EXTICfg; #if __DMA_USED__ GPDMA_Channel_CFG_Type GPDMACfg; #endif 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(); /* * Init ADC pin connect * AD0.2 on P0.25 */ PINSEL_ConfigPin(BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO); PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE); #ifdef LPC177x_8x_ADC_BURST_MULTI /* * Init ADC pin connect * AD0.3 on P0.26 */ PINSEL_ConfigPin(0, 26, 1); PINSEL_SetAnalogPinMode(0,26,ENABLE); #endif /* Configuration for ADC: * select: ADC channel 2 * ADC channel 3 * ADC conversion rate = 400KHz */ ADC_Init(LPC_ADC, 400000); ADC_ChannelCmd(LPC_ADC,BRD_ADC_PREPARED_CHANNEL,ENABLE); #ifdef LPC177x_8x_ADC_BURST_MULTI ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_n,ENABLE); #endif #ifdef LPC177x_8x_ADC_INJECT_TEST //Config P2.10 as EINT0 PINSEL_ConfigPin(2,10,1); EXTI_Init(); EXTICfg.EXTI_Line = EXTI_EINT0; /* edge sensitive */ EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE; EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE; EXTI_Config(&EXTICfg); GPIO_SetDir(LED_PORT,LED_PIN,1); GPIO_SetValue(LED_PORT,LED_PIN); NVIC_EnableIRQ(EINT0_IRQn); #endif #if __DMA_USED__ /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = (uint32_t)s_buf; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_ADC; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); while(1) { for(tmp = 0; tmp < 0x1000; tmp++); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; for(tmp = 0; tmp < DMA_SIZE; tmp++) { s_buf[tmp] = 0; } //Start burst conversion ADC_BurstCmd(LPC_ADC,ENABLE); GPDMA_Setup(&GPDMACfg); // Enable GPDMA channel 1 GPDMA_ChannelCmd(0, ENABLE); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0)); GPDMA_ChannelCmd(0, DISABLE); for(tmp = 0; tmp < DMA_SIZE; tmp++) { if(s_buf[tmp] & ADC_GDR_DONE_FLAG) { _DBG("ADC value on channel "); _DBD(ADC_GDR_CH(s_buf[tmp])); _DBG(": "); _DBD32(ADC_GDR_RESULT(s_buf[tmp]));_DBG_(""); } } if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } #else //Start burst conversion ADC_BurstCmd(LPC_ADC,ENABLE); while(1) { adc_value = ADC_ChannelGetData(LPC_ADC,BRD_ADC_PREPARED_CHANNEL); _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL); _DBG(": "); _DBD32(adc_value); _DBG_(""); #ifdef LPC177x_8x_ADC_BURST_MULTI adc_value = ADC_ChannelGetData(LPC_ADC,_ADC_CHANNEL_n); _DBG("ADC value on channel 3: "); _DBD32(adc_value); _DBG_(""); #endif // Wait for a while for(tmp = 0; tmp < 1500000; tmp++); if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } #endif /*__DMA_USED__*/ _DBG_("Demo termination!!!"); ADC_DeInit(LPC_ADC); GPIO_Deinit(); }
/*********************************************************************//** * @brief c_entry: Main DAC program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { DAC_CONVERTER_CFG_Type DAC_ConverterConfigStruct; uint32_t dac_value = 0; volatile uint32_t i; /* GPDMA block section -------------------------------------------- */ /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01 << 3) | 0x01)); DAC_ConverterConfigStruct.CNT_ENA =SET; DAC_ConverterConfigStruct.DMA_ENA = SET; DAC_Init(0); /* set time out for DAC*/ DAC_SetDMATimeOut(0, 0xFFFF); DAC_ConfigDAConverterControl(0, &DAC_ConverterConfigStruct); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t)(&dac_value); // Destination memory - unused GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = GPDMA_CONN_DAC; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Wait for GPDMA processing complete */ while (1) { // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); while ((Channel0_TC == 0) ); // Disable GPDMA channel 0 GPDMA_ChannelCmd(0, DISABLE); dac_value ++; if (dac_value == 0x3FF) dac_value = 0; //delay for(i=0;i<100000;i++); /* Reset terminal counter */ Channel0_TC = 0; // Re-setup channel GPDMA_Setup(&GPDMACfg); } }
/*********************************************************************//** * @brief c_entry: Main SSP program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { #if __DMA_USED__ GPDMA_Channel_CFG_Type GPDMACfg; #else SSP_DATA_SETUP_Type xferConfig; #endif /* * Initialize SSP pin connect * P0.15 - SCK; * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ #if (_SSP_NO_USING == 0) PINSEL_ConfigPin(0, 15, 2); PINSEL_ConfigPin(0, 16, 2); PINSEL_ConfigPin(0, 17, 2); PINSEL_ConfigPin(0, 18, 2); #elif (_SSP_NO_USING == 1) PINSEL_ConfigPin(0, 6, 2); PINSEL_ConfigPin(0, 7, 2); PINSEL_SetFilter(0, 7, 0); PINSEL_ConfigPin(0, 8, 2); PINSEL_SetFilter(0, 8, 0); PINSEL_ConfigPin(0, 9, 2); PINSEL_SetFilter(0, 9, 0); #else PINSEL_ConfigPin(1, 0, 4); PINSEL_ConfigPin(1, 8, 4); PINSEL_ConfigPin(1, 1, 4); PINSEL_ConfigPin(1, 4, 4); #endif /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP, ENABLE); _DBG_("Press '1' to start transfer..."); while (_DG != '1'); /* Initialize Buffer */ _DBG_("Init buffer"); Buffer_Init(); _DBG_("Start transfer..."); #if __DMA_USED__ /* Initialize GPDMA controller */ GPDMA_Init(); /* 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 -------------------------------------------------------------*/ /* DMA Channel 0 */ GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t) &Tx_Buf; // Destination memory - Not used GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = sizeof(Tx_Buf); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = SSP_TX_SRC_DMA_CONN; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Configure GPDMA channel 1 -------------------------------------------------------------*/ /* DMA Channel 1 */ GPDMACfg.ChannelNum = 1; // Source memory - not used GPDMACfg.SrcMemAddr = 0; // Destination memory - Not used GPDMACfg.DstMemAddr = (uint32_t) &Rx_Buf; // Transfer size GPDMACfg.TransferSize = sizeof(Rx_Buf); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = SSP_RX_SRC_DMA_CONN; // Destination connection - not used GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; // Enable Tx and Rx DMA on SSP0 SSP_DMACmd (LPC_SSP, SSP_DMA_RX, ENABLE); SSP_DMACmd (LPC_SSP, SSP_DMA_TX, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); /* Wait for GPDMA processing complete */ while (((Channel0_TC == 0) && (Channel0_Err == 0)) \ || ((Channel1_TC == 0) && (Channel1_Err ==0))); #else xferConfig.tx_data = Tx_Buf; xferConfig.rx_data = Rx_Buf; xferConfig.length = BUFFER_SIZE; SSP_ReadWrite(LPC_SSP, &xferConfig, SSP_TRANSFER_POLLING); #endif // Verify buffer after transferring Buffer_Verify(); _DBG_("Verify complete!"); /* Loop forever */ 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; }
/*********************************************************************//** * @brief c_entry: Main ADC program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; volatile uint32_t adc_value, tmp; uint8_t quit; /* Initialize debug via UART0 * ?115200bps * ?8 data bit * ?No parity * ?1 stop bit * ?No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initialize ADC ----------------------------------------------------*/ /* Settings for AD input pin */ PINSEL_ConfigPin (BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO); PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE); /* Configuration for ADC : * ADC conversion rate = 400KHz */ ADC_Init(LPC_ADC, 400000); ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, ENABLE); ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE); /* GPDMA block section -------------------------------------------- */ /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = (uint32_t) &adc_value; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_ADC; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); while (1) { // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); ADC_StartCmd(LPC_ADC, ADC_START_NOW); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0)); // Disable GPDMA channel 0 GPDMA_ChannelCmd(0, DISABLE); //Display the result of conversion on the UART _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL); _DBG(" is: "); _DBD32(ADC_DR_RESULT(adc_value)); _DBG_(""); // Wait for a while for(tmp = 0; tmp < 1000000; tmp++); /* GPDMA Re-setup */ GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } _DBG_("Demo termination!!!"); ADC_DeInit(LPC_ADC); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* GPDMA block section -------------------------------------------- */ /* Initialize buffer */ _DBG_("Initialize Buffer..."); Buffer_Init(); /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = DMA_SRC; // Destination memory GPDMACfg.DstMemAddr = DMA_DST; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; _DBG_("Start transfer..."); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); /* Verify buffer */ Buffer_Verify(); _DBG(compl_menu); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main UART program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { uint8_t *rx_char; uint32_t idx; // UART Configuration structure variable UART_CFG_Type UARTConfigStruct; // UART FIFO configuration Struct variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; GPDMA_Channel_CFG_Type GPDMACfg; // Pin configuration for UART0 PINSEL_CFG_Type PinCfg; /* * Initialize UART0 pin connect */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 2; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 3; PINSEL_ConfigPin(&PinCfg); /* Initialize UART Configuration parameter structure to default state: * Baudrate = 9600bps * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UARTConfigStruct); // Initialize UART0 peripheral with given to corresponding parameter UART_Init(LPC_UART0, &UARTConfigStruct); /* Initialize FIFOConfigStruct to default state: * - FIFO_DMAMode = DISABLE * - FIFO_Level = UART_FIFO_TRGLEV0 * - FIFO_ResetRxBuf = ENABLE * - FIFO_ResetTxBuf = ENABLE * - FIFO_State = ENABLE */ UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); // Enable DMA mode in UART UARTFIFOConfigStruct.FIFO_DMAMode = ENABLE; // Initialize FIFO for UART0 peripheral UART_FIFOConfig(LPC_UART0, &UARTFIFOConfigStruct); // Enable UART Transmit UART_TxCmd(LPC_UART0, ENABLE); /* GPDMA Interrupt configuration section ------------------------------------------------- */ /* Initialize GPDMA controller */ GPDMA_Init(); /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t) &menu1; // Destination memory - don't care GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = sizeof(menu1); // Transfer width - don't care GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - don't care GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = GPDMA_CONN_UART0_Tx; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); // Setup GPDMA channel -------------------------------- // channel 1 GPDMACfg.ChannelNum = 1; // Source memory - don't care GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = (uint32_t) &rx_buf; // Transfer size GPDMACfg.TransferSize = sizeof(rx_buf); // Transfer width - don't care GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_UART0_Rx; // Destination connection - don't care GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Make sure GPDMA channel 1 is disabled GPDMA_ChannelCmd(1, DISABLE); /* Wait for GPDMA on UART0 Tx processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); // Main loop - echos back to the terminal while (1) { /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); // Enable GPDMA channel 1 GPDMA_ChannelCmd(1, ENABLE); // Clear Rx buffer using DMA for (idx = 0; idx < RX_BUF_SIZE; idx++){ rx_buf[idx] = 0; } // now, start receive character using GPDMA rx_char = (uint8_t *) &rx_buf; while ((Channel1_TC == 0) && (Channel1_Err == 0)){ // Check whether if there's any character received, then print it back if (*rx_char != 0) { UART_Send(LPC_UART0, rx_char, 1, BLOCKING); rx_char++; } } } // DeInitialize UART0 peripheral UART_DeInit(LPC_UART0); /* Loop forever */ while(1); return 1; }
void initI2SDMA(uint32_t txblock, uint32_t rxblock) { I2S_DMAConf_Type I2SDMACfg; GPDMA_Channel_CFG_Type GPDMACfg; /* 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)); /* Setup GPDMA channel --------------------------------*/ /* channel 0 */ GPDMACfg.ChannelNum = 0; /* Source memory */ GPDMACfg.SrcMemAddr = txblock; /* Destination memory */ GPDMACfg.DstMemAddr = 0; /* Transfer size */ GPDMACfg.TransferSize = TRANSFER_SIZE; /* Transfer width */ GPDMACfg.TransferWidth = 0; /* Transfer type */ GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; /* Source connection - unused */ GPDMACfg.SrcConn = 0; /* Destination connection - I2S */ GPDMACfg.DstConn = GPDMA_CONN_I2S_Channel_0; /* Linker List Item - unused */ GPDMACfg.DMALLI = 0; /* Setup channel with given parameter */ GPDMA_Setup(&GPDMACfg); // Setup GPDMA channel -------------------------------- // channel 1 GPDMACfg.ChannelNum = 1; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = rxblock; // Transfer size GPDMACfg.TransferSize = TRANSFER_SIZE; // 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; /* Setup channel with given parameter */ GPDMA_Setup(&GPDMACfg); /* Enable GPDMA channel 0*/ GPDMA_ChannelCmd(0, ENABLE); /* Enable GPDMA channel 1 */ GPDMA_ChannelCmd(1, ENABLE); /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); //Setup DMA I2SDMACfg.DMAIndex = I2S_DMA_1; I2SDMACfg.depth = 4; I2S_DMAConfig(LPC_I2S, &I2SDMACfg, I2S_TX_MODE); I2SDMACfg.DMAIndex = I2S_DMA_2; I2SDMACfg.depth = 8; I2S_DMAConfig(LPC_I2S, &I2SDMACfg, I2S_RX_MODE); //Enable DMA I2S_DMACmd(LPC_I2S, I2S_DMA_1, I2S_TX_MODE, ENABLE); I2S_DMACmd(LPC_I2S, I2S_DMA_2, I2S_RX_MODE, ENABLE); }
void TIMER0_IRQHandler(void){ // xprintf("TIMER0_IRQ"); if (TIM_GetIntStatus(LPC_TIM0,TIM_MR0_INT)){ TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT); #if 0 if(TOG[0]) // FIO_SetValue(LED_LE_PORT, LED_LE_BIT); GPIO_SetValue(LED_4_PORT, LED_4_BIT); else // FIO_ClearValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_4_PORT, LED_4_BIT); TOG[0]=!TOG[0]; // TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT); // return; #endif // xprintf(INFO "RIT N=%d B=%x NXT_T=%d TX=%x\n",SENDSEQ,SEND_BIT,DELAY_TIME,LED_PRECALC[0][SEND_BIT]); //Setup new timing for next Timer DELAY_TIME=SEQ_TIME[SENDSEQ]; SEND_BIT=SEQ_BIT[SENDSEQ]; //Retart sequence if required SENDSEQ++; SENDSEQ>=no_SEQ_BITS ? SENDSEQ=0 : 0; #ifdef DMA // xprintf("SEND_BIT:%d\n",SEND_BIT); // xprintf("DELAY_TIME:%d\n",DELAY_TIME); GPDMACfg.DMALLI = (uint32_t) &LinkerList[0][SEND_BIT][BufferNo]; GPDMA_Setup(&GPDMACfg); GPDMA_ChannelCmd(0, ENABLE); #endif TIM_UpdateMatchValue(LPC_TIM0,0,DELAY_TIME); FIO_SetValue(LED_OE_PORT, LED_OE_BIT); #ifdef RxDMA GPDMA_ChannelCmd(1, ENABLE); uint8_t reg; for(reg=6; 0<reg;reg--){ xprintf("%d ",reg-1); #if 0 if(BUFFER==1) SSP_SendData(LED_SPI_CHN, LED_PRECALC1[reg][SEND_BIT]); else SSP_SendData(LED_SPI_CHN, LED_PRECALC2[reg][SEND_BIT]); #endif //WaitForSend();//Wait if TX buffer full //while(LED_SPI_CHN->SR & SSP_STAT_BUSY); while(SSP_GetStatus(LED_SPI_CHN, SSP_STAT_BUSY)){ }; SSP_SendData(LED_SPI_CHN, LED_PRECALC[reg-1][SEND_BIT]); xprintf("%4x ",(LED_PRECALC[reg-1][SEND_BIT])); } for(reg=12; reg>6;reg--){ xprintf("%d ",reg-1); #if 0 if(BUFFER==1) SSP_SendData(LED_SPI_CHN, LED_PRECALC1[reg][SEND_BIT]); else SSP_SendData(LED_SPI_CHN, LED_PRECALC2[reg][SEND_BIT]); #endif //WaitForSend();//Wait if TX buffer full while(SSP_GetStatus(LED_SPI_CHN, SSP_STAT_BUSY)){ } SSP_SendData(LED_SPI_CHN, LED_PRECALC[reg-1][SEND_BIT]); // if (reg==7){ xprintf("%4x ",(LED_PRECALC[reg-1][SEND_BIT])); // } } LatchIn(); #endif /* UPDATE_COUNT+=1; ATE_COUNT=0; LED_UPDATE_REQUIRED=1; }*/ } }