void gpio_set_gpio_pin(unsigned int pin, uint8_t port) { GPIO_SetValue(port, 0x01<<pin); }
/*********************************************************************//** * @brief Initialize CS pin as GPIO function to drive /CS pin * due to definition of CS_PORT_NUM and CS_PORT_NUM * @param None * @return None ***********************************************************************/ void CS_Init(void) { GPIO_SetDir(CS_PORT_NUM, (1<<CS_PIN_NUM), 1); GPIO_SetValue(CS_PORT_NUM, (1<<CS_PIN_NUM)); }
void gpio_init() { SPI_CFG_Type spiInitialization; PINSEL_CFG_Type PinSelCfg; /*----------------------------------------------------------------- *--------------------------PORT 0--------------------------------- *----------------------------------------------------------------- */ GPIO_SetDir(0, 0xFFFFFFFF, OUTPUT); PinSelCfg.Portnum = PINSEL_PORT_0; // PinSelCfg.Pinnum = PINSEL_PIN_0; // PinSelCfg.Funcnum = PINSEL_FUNC_3; // PinSelCfg.OpenDrain = 0; // PinSelCfg.Pinmode = 0; // PINSEL_ConfigPin(&PinSelCfg); // // PinSelCfg.Pinnum = PINSEL_PIN_1; // PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Pinnum = PINSEL_PIN_2; PinSelCfg.Funcnum = PINSEL_FUNC_1; PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP; PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Pinnum = PINSEL_PIN_3; PINSEL_ConfigPin(&PinSelCfg); GPIO_SetDir(0, 0x01<<22, INPUT); PinSelCfg.Pinnum = PINSEL_PIN_10; PinSelCfg.Funcnum = PINSEL_FUNC_2; PinSelCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN; PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE; PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Pinnum = PINSEL_PIN_11; PINSEL_ConfigPin(&PinSelCfg); //SET FMC_I2C1 in Hi-Z GPIO_SetDir(0, 0x01<<19, INPUT); GPIO_SetDir(0, 0x01<<20, INPUT); // PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE; // PinSelCfg.Funcnum = PINSEL_FUNC_3; // PinSelCfg.Pinnum = PINSEL_PIN_19; // PINSEL_ConfigPin(&PinSelCfg); // // PinSelCfg.Pinnum = PINSEL_PIN_20; // PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Funcnum = PINSEL_FUNC_1; PinSelCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN; PinSelCfg.Pinnum = PINSEL_PIN_27; PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Pinnum = PINSEL_PIN_28; PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Pinnum = PINSEL_PIN_29; PinSelCfg.Funcnum = PINSEL_FUNC_1; PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE; PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Pinnum = PINSEL_PIN_30; PINSEL_ConfigPin(&PinSelCfg); /*----------------------------------------------------------------- *---------------------END OF PORT 0------------------------------- *----------------------------------------------------------------- *----------------------------------------------------------------- * ------------------------PORT 1---------------------------------- * ---------------------------------------------------------------- */ GPIO_SetDir(1, 0xFFFFFFFF, OUTPUT); GPIO_SetDir(1, ( 0x01<<IPMI_GA0 | 0x01<<IPMI_GA1 | 0x01<<IPMI_GA2 ), INPUT); GPIO_SetValue(LED_PORT, (0x01<<_IPMI_BLLED|0x01<<_IPMI_LED1|0x01<<_IPMI_LED2) ); // PinSelCfg.Portnum = PINSEL_PORT_1; // PinSelCfg.Pinnum = PINSEL_PIN_30; // PinSelCfg.Funcnum = PINSEL_FUNC_2; // PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL; // PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE; // PINSEL_ConfigPin(&PinSelCfg); GPIO_SetDir(ENA_PORT, 0x001<<ENA_PIN, INPUT); GPIO_SetDir(2, 0x0400, INPUT); GPIO_SetDir(IPMI_EJTHDL_PORT, 0x001<<IPMI_EJTHDL, INPUT); GPIO_SetDir(1, 0x01<<22, INPUT); GPIO_SetDir(PGOOD_PORT, 0x01<<PGOOD_PIN, INPUT); gpio_clr_gpio_pin(_IPMI_BLLED, LED_PORT); // turn on blue LED ASAP gpio_clr_gpio_pin(UC_PWRENOUT, UC_PWRENOUT_PORT); // turn off power enable PinSelCfg.Pinnum = PINSEL_PIN_15; PinSelCfg.Portnum = PINSEL_PORT_0; PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinSelCfg.Funcnum = PINSEL_FUNC_3; PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Pinnum = PINSEL_PIN_18; PINSEL_ConfigPin(&PinSelCfg); GPIO_SetDir(1, 0x01<<26, OUTPUT); GPIO_SetValue(1, 0x01<<26); GPIO_SetDir(0, 0x01<<21, OUTPUT); GPIO_SetDir(0, 0x01<<16, OUTPUT); GPIO_SetValue(0, 0x01<<16); GPIO_SetValue(0, 0x01<<21); GPIO_SetDir(PORT_EN_0, 0x01<<EN_P1V2, OUTPUT); GPIO_SetDir(PORT_EN_0, 0x01<<EN_P1V8, OUTPUT); GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC2_P3V3, OUTPUT); GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC1_P3V3, OUTPUT); GPIO_SetDir(PORT_EN_0, 0x01<<EM_FMC1_P12V, OUTPUT); GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC2_P12V, OUTPUT); GPIO_SetDir(PORT_EN_1, 0x01<<EN_FMC1_PVADJ, OUTPUT); GPIO_SetDir(PORT_EN_1, 0x01<<EN_FMC2_PVADJ, OUTPUT); GPIO_SetDir(PORT_EN_1, 0x01<<EN_P3V3, OUTPUT); GPIO_SetDir(PORT_EN_1, 0x01<<EN_1V5_VTT, OUTPUT); GPIO_SetDir(PORT_EN_1, 0x01<<EN_RTM_CONN, OUTPUT); GPIO_SetDir(PORT_EN_0, 0x01<<RTM_PRESENCE, INPUT); GPIO_SetDir(PORT_EN_3, 0x01<<EN_P1V0, OUTPUT); setDC_DC_ConvertersON(); spiInitialization.CPOL = SPI_CPOL_LO; spiInitialization.CPHA = SPI_CPHA_FIRST; spiInitialization.Databit = SPI_DATABIT_10; spiInitialization.DataOrder = SPI_DATA_MSB_FIRST; spiInitialization.ClockRate = 10000000; SPI_Init(LPC_SPI, &spiInitialization); LPC_SPI->SPCR = 0xA24; GPIO_ClearValue(0, 0x01<<16); SPI_SendData(LPC_SPI, 0x0125); while(! ( SPI_CheckStatus( SPI_GetStatus(LPC_SPI), SPI_STAT_SPIF) )); GPIO_SetValue(0, 0x01<<16); GPIO_ClearValue(0, 0x01<<16); SPI_SendData(LPC_SPI, 0x0025); while(! ( SPI_CheckStatus( SPI_GetStatus(LPC_SPI), SPI_STAT_SPIF) )); GPIO_SetValue(0, 0x01<<16); //SCANSTA JTAG GPIO_SetDir(2, 0x0FF, OUTPUT); GPIO_SetValue(2, 0x080); GPIO_ClearValue(2, 0x07F); SPI_ConfigStructInit(&spiInitialization); //FPGA_SPI GPIO_SetDir(1, 0x01<<20, INPUT); GPIO_SetDir(1, 0x01<<21, INPUT); GPIO_SetDir(1, 0x01<<23, INPUT); GPIO_SetDir(1, 0x01<<24, INPUT); // SET PROGRAM_B AS OUTPUT // AND SET THIS PIN HIGH GPIO_SetDir(0, 0x01<<17, INPUT); // SET DONE PIN AS INPUT // turn on pull-up GPIO_SetDir(0, 0x01<<22, INPUT); //////////////////////////////////////// // P0_6 - FCS_B - use as FPGA - RST //////////////////////////////////////// GPIO_SetDir(0, 0x01<<6, INPUT); //GPIO_ClearValue(0, 0x01<<6); /////////////////////////////////////// GPIO_SetDir(0, 0x01<<7, INPUT); GPIO_SetDir(0, 0x01<<8, INPUT); #ifdef AMC_CPU_COM_Express GPIO_SetDir(0, 0x01<<9, OUTPUT); #else GPIO_SetDir(0, 0x01<<9, INPUT); #endif /////////////////////////////////////// //FMC STATUS PORTS /////////////////////////////////////// GPIO_SetDir(1, 0x1<<14, INPUT); GPIO_SetDir(1, 0x1<<15, INPUT); GPIO_SetDir(1, 0x1<<16, INPUT); GPIO_SetDir(1, 0x1<<17, INPUT); GPIO_SetDir(1, 0x1<<18, INPUT); GPIO_SetDir(1, 0x1<<19, INPUT); /////////////////////////////////////// // FPGA Reset Button EXTI_InitTypeDef EXTICfg; /* Initialize EXT pin and register */ /* P2.12 as /EINT2*/ PinSelCfg.Funcnum = PINSEL_FUNC_1; PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinSelCfg.Pinnum = FPGA_RST_SW; PinSelCfg.Portnum = FPGA_RST_SW_PORT; PINSEL_ConfigPin(&PinSelCfg); PinSelCfg.Funcnum = PINSEL_FUNC_0; PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinSelCfg.Pinnum = FPGA_RESETn; PinSelCfg.Portnum = FPGA_RESETn_PORT; PINSEL_ConfigPin(&PinSelCfg); GPIO_SetDir(FPGA_RESETn_PORT, 1<<FPGA_RESETn, OUTPUT); EXTI_Init(); EXTICfg.EXTI_Line = EXTI_EINT2; EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE; EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE; EXTI_ClearEXTIFlag(EXTI_EINT2); EXTI_Config(&EXTICfg); GPIO_IntCmd(0, 0x01 << FPGA_RST_SW, 1); NVIC_SetPriorityGrouping(0); NVIC_SetPriority(EINT2_IRQn, 4); NVIC_EnableIRQ(EINT2_IRQn); }
/*********************************************************************//** * @brief Initialize CS pin as GPIO function to drive /CS pin * due to definition of CS_PORT_NUM and CS_PORT_NUM * @param None * @return None ***********************************************************************/ void SPI_SlaveSelectInit (void) { GPIO_SetDir(CS_PORT_NUM, (1<<CS_PIN_NUM), 1); GPIO_SetValue(CS_PORT_NUM, (1<<CS_PIN_NUM)); }
static portTASK_FUNCTION( vConductorUpdateTask, pvParameters ) { uint8_t rxLen, status; uint8_t Buffer[vtI2CMLen]; uint8_t *valPtr = &(Buffer[0]); // Get the parameters vtConductorStruct *param = (vtConductorStruct *) pvParameters; // Get the I2C device pointer vtI2CStruct *devPtr = param->dev; // Get the LCD information pointer vtTempStruct *tempData = param->tempData; myNavStruct *navData = param->navData; myMapStruct *mapData = param->mapData; uint8_t recvMsgType; mapStruct.mappingFlag = 0; uint8_t i2cRoverMoveStop[] = {0x05, 0x00}; // 255 will always be a bad message countDefArray[255] = BadMsg; uint8_t i; for(i = 0; i < 255; i++) { countDefArray[i] = CleanMsg; } uint8_t i2cRoverMoveStop[] = {0x05, 0x00}; // Like all good tasks, this should never exit for(;;) { // Wait for a message from an I2C operation if (vtI2CDeQ(devPtr,vtI2CMLen,Buffer,&rxLen,&recvMsgType,&status) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } // Decide where to send the message // This just shows going to one task/queue, but you could easily send to // other Q/tasks for other message types // This isn't a state machine, it is just acting as a router for messages // If it is the initialization message if ( recvMsgType == vtI2CMsgTypeTempInit ) { SendTempValueMsg(tempData,recvMsgType,Buffer,portMAX_DELAY); } else { // Switch on the definition of the incoming count switch(countDefArray[Buffer[0]]) { case RoverMsgSensorAllData: { //printf("SensorData\n"); GPIO_ClearValue(0,0x78000); GPIO_SetValue(0, 0x48000); SendMapValueMsg(mapData,RoverMsgSensorAllData, Buffer, portMAX_DELAY); if (!speedRun) SendNavValueMsg(navData,0x11,Buffer,portMAX_DELAY); break; } case RoverMsgSensorForwardRight: { //SendTempValueMsg(tempData,recvMsgType,Buffer,portMAX_DELAY); break; } case RoverMsgMotorLeftData: { //printf("MotorLeftData\n"); GPIO_ClearValue(0,0x78000); GPIO_SetValue(0, 0x40000); SendTempValueMsg(tempData,RoverMsgMotorLeftData,Buffer,portMAX_DELAY); if (!speedRun) SendNavValueMsg(navData,RoverMsgMotorLeftData,Buffer,portMAX_DELAY); SendMapValueMsg(mapData,RoverMsgMotorLeftData,Buffer,portMAX_DELAY); break; } case RoverMsgMotorLeft90: { printf("RoverData\n"); break; // SendTempValueMsg(tempData,recvMsgType,Buffer,portMAX_DELAY); } case BadMsg: { printf("Bad Message; Restart Pics\n"); break; } default: { //printf("ConductDefault\n"); SendMapValueMsg(mapData,0x11,Buffer,portMAX_DELAY); break; } } if(Buffer[6] == 1) { if (vtI2CEnQ(devPtr,vtI2CMsgTypeTempRead1,0x4F,sizeof(i2cRoverMoveStop),i2cRoverMoveStop,10) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } mapStruct.mappingFlag = 0; mapStruct.timerFlag = 0; restart_nav(); printf("\nFINISH LINE DETECTED!\n"); stopGettingMotor("DATASTOP"); } } // Clear the count defition countDefArray[Buffer[0]] = CleanMsg; // Check if retransmission is needed if ( countDefArray[Buffer[0]-3] == RoverMsgMotorLeft90 ) { printf("Retrans of motor\n"); SendNavValueMsg(navData,0x89,Buffer,portMAX_DELAY); } // Check to see if the last five have been retrieved /*uint8_t i; for (i = Buffer[0]-1; i > Buffer[0] - 5; i--) { printf("Buf Check: %d\n", i); if ( countDefArray[i] == RoverMsgMotorLeft90 ) { printf("Retrans of motor\n"); SendNavValueMsg(navData,0x89,Buffer,portMAX_DELAY); } }*/ } }
/************************************************************************* main ==== **************************************************************************/ int main(void) { // USB: Init // CAS -> Initialization of KbdInputReport to initial values (0,0,0,0,..) HIDDKbdInputReport_Initialize (&KbdInputReport); // CAS -> Variable used to simulate the pressing of Letter A (0x04) int i; DBG("Initialising USB stack\n"); // CAS -> Variable used to simulate the pressing of Letter A (0x04) // USBInit() // USBHwInit() HW Init // -> Set Pins for USB, AHBClock, ACK generate interrupts // USBHwRegisterDevIntHandler(HandleUsbReset) // -> Define un handler (HandleUsbReset). // // initialize stack USBInit(); // register device descriptors USBRegisterDescriptors(abDescriptors); // register HID standard request handler USBRegisterCustomReqHandler(HIDHandleStdReq); // register class request handler USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData); // register endpoint (2?). Interrupt In Endpoint USBHwRegisterEPIntHandler(INTR_IN_EP, NULL); // register frame handler USBHwRegisterFrameHandler(HandleFrame); DBG("Starting USB communication\n"); // connect to bus USBHwConnect(TRUE); //RC5: Init GPIO_SetDir(0,1<<4,1); GPIO_SetDir(0,1<<5,1); GPIO_SetValue(0,1<<5); GPIO_SetValue(0,1<<4); RC5_Init(); // main() Loop: // call USB interrupt handler continuously // CodeRed - either read mouse, or provide "fake mouse readings" while (1) { for (i=0; i<10; i++) { // RC5 if (RC5_flag) // wait for RC5 code { if((RC5_System==0)&&(RC5_Command==1)){ GPIO_ClearValue(0,1<<4); for(i=0;i<1000000;i++); GPIO_SetValue(0,1<<4); for(i=0;i<1000000;i++); } if((RC5_System==0)&&(RC5_Command==5)){ GPIO_ClearValue(0,1<<5); for(i=0;i<1000000;i++); GPIO_SetValue(0,1<<5); for(i=0;i<1000000;i++); } RC5_flag = 0; printf( "RC5 = %d %d\n", RC5_System, RC5_Command); } // RC5 USBHwISR(); if (i < 5) { KbdInputReport.Key_1 = 0x04; } else { KbdInputReport.Key_1 = 0x00; } } } return 0; }
/** * @brief The same with GPIO_SetValue() */ void FIO_SetValue(uint8_t portNum, uint32_t bitValue) { GPIO_SetValue(portNum, bitValue); }
void LED_On(uint32_t led) { GPIO_SetValue(LED_PORT_NUM, led); }
/*********************************************************************//** * @brief c_entry: Main UART program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { // UART Configuration structure variable UART_CFG_Type UARTConfigStruct; // UART FIFO configuration Struct variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; // Pin configuration for UART0 PINSEL_CFG_Type PinCfg; uint32_t len; uint32_t led_mask[] = { 1<<28, 1<<29, 1UL<<31, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6 }; uint8_t buffer,i; //Initialize for 8 led bank GPIO_SetDir(1, 0xB0000000, 1); /* LEDs on PORT1 defined as Output */ GPIO_SetDir(2, 0x0000007C, 1); /* LEDs on PORT2 defined as Output */ GPIO_ClearValue(1, 0xB0000000); GPIO_ClearValue(2, 0x0000007C); #if (UART_PORT == 0) /* * Initialize UART0 pin connect */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 2; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg);//P0.2 TXD0 #endif #if (UART_PORT == 1) /* * Initialize UART1 pin connect */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 0; PinCfg.Portnum = 2; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 1; PINSEL_ConfigPin(&PinCfg); #endif /* * Initialize UART3 pin connect */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 26; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg);//P0.26 RXD3 /* Initialize UART Configuration parameter structure to default state: * Baudrate = 9600bps * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UARTConfigStruct); // Initialize UART0 & UART3 peripheral with given to corresponding parameter UART_Init(TEST_UART, &UARTConfigStruct); UART_Init(TEST_IRDA, &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); // Initialize FIFO for UART0 & UART3 peripheral UART_FIFOConfig(TEST_UART, &UARTFIFOConfigStruct); UART_FIFOConfig(TEST_IRDA, &UARTFIFOConfigStruct); //Configure and enable IrDA mode on UART UART_IrDACmd(TEST_IRDA,ENABLE); // Enable UART Transmit UART_TxCmd(TEST_UART, ENABLE); // print welcome screen print_menu(); /* Read some data from the buffer */ while (1) { len=0; while(len==0) { len = UART_Receive(TEST_IRDA, &buffer, 1, NONE_BLOCKING); } if(buffer!=0) { for(i=0;i<8;i++) { if((buffer>>i)&0x01){//set if(i<3) GPIO_SetValue(1, led_mask[i]); else GPIO_SetValue(2, led_mask[i]); } else { //clear if(i<3) GPIO_ClearValue(1, led_mask[i]); else GPIO_ClearValue(2, led_mask[i]); } } } else //clear 8 led bank {
void LED_simple_all_colors(){ //simple all colors TIM_Cmd(LPC_TIM0,DISABLE); // To start timer 0 // while(1){ for (uint8_t i=0;i<16;i++){ // xprintf(OK "%d",i+1);FFL_(); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); for (uint8_t j=0;j<11;j++){ SSP_SendData(LED_SPI_CHN, 0x0000); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); } // SSP_SendData(LED_SPI_CHN, 0x0001<<i); SSP_SendData(LED_SPI_CHN, 0x1249); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); for (uint8_t k=0;k<0;k++){ SSP_SendData(LED_SPI_CHN, 0x0000); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); } GPIO_SetValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_OE_PORT, LED_OE_BIT);//LED's on. active low delay_ms(150); }; for (uint8_t i=0;i<16;i++){ // xprintf(OK "%d",i+1);FFL_(); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); for (uint8_t j=0;j<11;j++){ SSP_SendData(LED_SPI_CHN, 0x0000); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); } // SSP_SendData(LED_SPI_CHN, 0x0001<<i); SSP_SendData(LED_SPI_CHN, 0x2492); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); for (uint8_t k=0;k<0;k++){ SSP_SendData(LED_SPI_CHN, 0x0000); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); } GPIO_SetValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_OE_PORT, LED_OE_BIT);//LED's on. active low delay_ms(150); }; for (uint8_t i=0;i<16;i++){ xprintf(OK "%d",i+1);FFL_(); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); for (uint8_t j=0;j<11;j++){ SSP_SendData(LED_SPI_CHN, 0x0000); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); } // SSP_SendData(LED_SPI_CHN, 0x0001<<i); SSP_SendData(LED_SPI_CHN, 0x4924); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); for (uint8_t k=0;k<0;k++){ SSP_SendData(LED_SPI_CHN, 0x0000); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); } GPIO_SetValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_OE_PORT, LED_OE_BIT);//LED's on. active low delay_ms(150); }; for (uint8_t i=0;i<16;i++){ // xprintf(OK "%d",i+1);FFL_(); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); for (uint8_t j=0;j<11;j++){ SSP_SendData(LED_SPI_CHN, 0x0000); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); } // SSP_SendData(LED_SPI_CHN, 0x0001<<i); SSP_SendData(LED_SPI_CHN, 0xffff); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); for (uint8_t k=0;k<0;k++){ SSP_SendData(LED_SPI_CHN, 0x0000); while(LED_SPI_CHN->SR & SSP_STAT_BUSY); } GPIO_SetValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT); GPIO_ClearValue(LED_OE_PORT, LED_OE_BIT);//LED's on. active low delay_ms(150); }; // }; TIM_Cmd(LPC_TIM0,ENABLE); // To start timer 0 LED_PATTERN=0; }
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 }
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; }*/ } }