/*********************************************************************//** * @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; }
/*********************************************************************//** * @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); }
void main(void) #endif { RST_CLK_DeInit(); RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0); /* Enable peripheral clocks --------------------------------------------------*/ RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_SSP1 | RST_CLK_PCLK_SSP2 | RST_CLK_PCLK_DMA),ENABLE); RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTF | RST_CLK_PCLK_PORTD), ENABLE); /* Init NVIC */ SCB->AIRCR = 0x05FA0000 | ((uint32_t)0x500); SCB->VTOR = 0x08000000; /* Disable all interrupt */ NVIC->ICPR[0] = 0xFFFFFFFF; NVIC->ICER[0] = 0xFFFFFFFF; /* Disable all DMA request */ MDR_DMA->CHNL_REQ_MASK_CLR = 0xFFFFFFFF; MDR_DMA->CHNL_USEBURST_CLR = 0xFFFFFFFF; /* Reset PORTD settings */ PORT_DeInit(MDR_PORTD); /* Reset PORTF settings */ PORT_DeInit(MDR_PORTF); /* Configure SSP2 pins: FSS, CLK, RXD, TXD */ /* Configure PORTD pins 2, 3, 5, 6 */ PORT_InitStructure.PORT_Pin = (PORT_Pin_2 | PORT_Pin_3 | PORT_Pin_5); PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_InitStructure.PORT_FUNC = PORT_FUNC_ALTER; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST; PORT_Init(MDR_PORTD, &PORT_InitStructure); PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_InitStructure.PORT_Pin = (PORT_Pin_6); PORT_Init(MDR_PORTD, &PORT_InitStructure); /* Configure SSP1 pins: FSS, CLK, RXD, TXD */ /* Configure PORTF pins 0, 1, 2, 3 */ PORT_InitStructure.PORT_Pin = (PORT_Pin_3); PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_Init(MDR_PORTF, &PORT_InitStructure); PORT_InitStructure.PORT_Pin = (PORT_Pin_0 | PORT_Pin_1 | PORT_Pin_2); PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_Init(MDR_PORTF, &PORT_InitStructure); /* Init RAM */ Init_RAM (DstBuf1, BufferSize); Init_RAM (SrcBuf1, BufferSize); Init_RAM (DstBuf2, BufferSize); Init_RAM (SrcBuf2, BufferSize); /* Reset all SSP settings */ SSP_DeInit(MDR_SSP1); SSP_DeInit(MDR_SSP2); SSP_BRGInit(MDR_SSP1,SSP_HCLKdiv16); SSP_BRGInit(MDR_SSP2,SSP_HCLKdiv16); /* SSP1 MASTER configuration ------------------------------------------------*/ SSP_StructInit (&sSSP); sSSP.SSP_SCR = 0x10; sSSP.SSP_CPSDVSR = 2; sSSP.SSP_Mode = SSP_ModeMaster; sSSP.SSP_WordLength = SSP_WordLength16b; sSSP.SSP_SPH = SSP_SPH_1Edge; sSSP.SSP_SPO = SSP_SPO_Low; sSSP.SSP_FRF = SSP_FRF_SPI_Motorola; sSSP.SSP_HardwareFlowControl = SSP_HardwareFlowControl_SSE; SSP_Init (MDR_SSP1,&sSSP); /* SSP2 SLAVE configuration ------------------------------------------------*/ sSSP.SSP_SPH = SSP_SPH_1Edge; sSSP.SSP_SPO = SSP_SPO_Low; sSSP.SSP_CPSDVSR = 12; sSSP.SSP_Mode = SSP_ModeSlave; SSP_Init (MDR_SSP2,&sSSP); /* Enable SSP1 DMA Rx and Tx request */ SSP_DMACmd(MDR_SSP1,(SSP_DMA_RXE | SSP_DMA_TXE), ENABLE); /* Enable SSP2 DMA Rx and Tx request */ SSP_DMACmd(MDR_SSP2,(SSP_DMA_RXE | SSP_DMA_TXE), ENABLE); /* Reset all DMA settings */ DMA_DeInit(); DMA_StructInit(&DMA_InitStr); /* DMA_Channel_SSP1_RX configuration ---------------------------------*/ /* Set Primary Control Data */ DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_SSP1->DR)); DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf1; DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncNo; DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncHalfword; DMA_PriCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_PriCtrlStr.DMA_Mode = DMA_Mode_Basic; DMA_PriCtrlStr.DMA_CycleSize = BufferSize; DMA_PriCtrlStr.DMA_NumContinuous = DMA_Transfers_4; DMA_PriCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged; DMA_PriCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged; /* Set Channel Structure */ DMA_InitStr.DMA_PriCtrlData = &DMA_PriCtrlStr; DMA_InitStr.DMA_Priority = DMA_Priority_High; DMA_InitStr.DMA_UseBurst = DMA_BurstClear; DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY; /* Init DMA channel */ DMA_Init(DMA_Channel_SSP1_RX, &DMA_InitStr); /* DMA_Channel_SSP2_RX configuration ---------------------------------*/ /* Set Primary Control Data */ DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_SSP2->DR)); DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf2; /* Init DMA channel */ DMA_Init(DMA_Channel_SSP2_RX, &DMA_InitStr); /* DMA_Channel_SSP1_TX configuration ---------------------------------*/ /* Set Primary Control Data */ DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)SrcBuf1; DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_SSP1->DR)); DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncHalfword; DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncNo; DMA_InitStr.DMA_Priority = DMA_Priority_Default; /* Init DMA channel */ DMA_Init(DMA_Channel_SSP1_TX, &DMA_InitStr); /* DMA_Channel_SSP2_TX configuration ---------------------------------*/ /* Set Primary Control Data */ DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)SrcBuf2; DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_SSP2->DR)); /* Init DMA channel */ DMA_Init(DMA_Channel_SSP2_TX, &DMA_InitStr); /* Enable SSP1 */ SSP_Cmd(MDR_SSP1, ENABLE); /* Enable SSP2 */ SSP_Cmd(MDR_SSP2, ENABLE); /* Transfer complete */ while((SSP_GetFlagStatus(MDR_SSP1, SSP_FLAG_BSY))) { } while((SSP_GetFlagStatus(MDR_SSP2, SSP_FLAG_BSY))) { } /* Check the corectness of written dada */ TransferStatus1 = Verif_mem ((BufferSize), SrcBuf1, DstBuf2); TransferStatus2 = Verif_mem ((BufferSize), SrcBuf2, DstBuf1); /* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received are correct */ /* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received are different */ while(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 }