/*********************************************************************//** * @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 UART PINSEL_CFG_Type PinCfg; uint32_t idx,len; __IO FlagStatus exitflag; uint8_t buffer,temp; #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 PinCfg.Pinnum = 3; PINSEL_ConfigPin(&PinCfg);//P0.3 RXD0 #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 = 25; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg);//P0.25 TXD3 /* 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); UART_TxCmd(TEST_IRDA, ENABLE); // print welcome screen print_menu(); // Reset exit flag exitflag = RESET; idx=0;buffer=0; /* Read some data from the buffer */ while (exitflag == RESET) { if(idx==0) { UART_Send(TEST_UART, menu5, sizeof(menu5), BLOCKING); } len=0; while(len==0) { len = UART_Receive(TEST_UART, &temp, 1, NONE_BLOCKING); } if(temp==27) { UART_Send(TEST_UART, menu4, sizeof(menu4), BLOCKING); exitflag=SET; } else if(temp=='r') { idx=0;buffer=0; print_menu(); UART_Send(TEST_IRDA, &buffer, 1, BLOCKING); } else { idx++; switch(temp) { case '0': buffer=(buffer<<4)|0x00;break; case '1': buffer=(buffer<<4)|0x01;break; case '2': buffer=(buffer<<4)|0x02;break; case '3': buffer=(buffer<<4)|0x03;break; case '4': buffer=(buffer<<4)|0x04;break; case '5': buffer=(buffer<<4)|0x05;break; case '6': buffer=(buffer<<4)|0x06;break; case '7': buffer=(buffer<<4)|0x07;break; case '8': buffer=(buffer<<4)|0x08;break; case '9': buffer=(buffer<<4)|0x09;break; case 'a': buffer=(buffer<<4)|0x0A;break; case 'A': buffer=(buffer<<4)|0x0A;break; case 'b': buffer=(buffer<<4)|0x0B;break; case 'B': buffer=(buffer<<4)|0x0B;break; case 'c': buffer=(buffer<<4)|0x0C;break; case 'C': buffer=(buffer<<4)|0x0C;break; case 'd': buffer=(buffer<<4)|0x0D;break; case 'D': buffer=(buffer<<4)|0x0D;break; case 'e': buffer=(buffer<<4)|0x0E;break; case 'E': buffer=(buffer<<4)|0x0E;break; case 'f': buffer=(buffer<<4)|0x0F;break; case 'F': buffer=(buffer<<4)|0x0F;break; default: idx=0;buffer=0;break; } if(idx==2) { temp=buffer>>4; if(temp <= 9)temp=temp+ 0x30; else temp=temp+0x37; UART_Send(TEST_UART, &temp, 1, BLOCKING); temp=(buffer&0x0F); if(temp <= 9)temp=temp+ 0x30; else temp=temp+0x37; UART_Send(TEST_UART, &temp, 1, BLOCKING); UART_Send(TEST_IRDA, &buffer, 1, BLOCKING); idx=0;buffer=0; } } }
/* * See the serial2.h header file. */ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) { xComPortHandle xReturn; UART_InitTypeDef xUART1_Init; GPIO_InitTypeDef GPIO_InitStructure; /* Create the queues used to hold Rx characters. */ xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* Create the semaphore used to wake a task waiting for space to become available in the FIFO. */ vSemaphoreCreateBinary( xTxFIFOSemaphore ); /* If the queue/semaphore was created correctly then setup the serial port hardware. */ if( ( xRxedChars != serINVALID_QUEUE ) && ( xTxFIFOSemaphore != serINVALID_QUEUE ) ) { /* Pre take the semaphore so a task will block if it tries to access it. */ xSemaphoreTake( xTxFIFOSemaphore, 0 ); /* Configure the UART. */ xUART1_Init.UART_WordLength = UART_WordLength_8D; xUART1_Init.UART_StopBits = UART_StopBits_1; xUART1_Init.UART_Parity = UART_Parity_No; xUART1_Init.UART_BaudRate = ulWantedBaud; xUART1_Init.UART_HardwareFlowControl = UART_HardwareFlowControl_None; xUART1_Init.UART_Mode = UART_Mode_Tx_Rx; xUART1_Init.UART_FIFO = UART_FIFO_Enable; /* Enable the UART1 Clock */ SCU_APBPeriphClockConfig( __UART1, ENABLE ); /* Enable the GPIO3 Clock */ SCU_APBPeriphClockConfig( __GPIO3, ENABLE ); /* Configure UART1_Rx pin GPIO3.2 */ GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; GPIO_Init( GPIO3, &GPIO_InitStructure ); /* Configure UART1_Tx pin GPIO3.3 */ GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ; GPIO_Init( GPIO3, &GPIO_InitStructure ); portENTER_CRITICAL(); { /* Configure the UART itself. */ UART_DeInit( UART1 ); UART_Init( UART1, &xUART1_Init ); UART_ITConfig( UART1, UART_IT_Receive | UART_IT_Transmit, ENABLE ); UART1->ICR = serCLEAR_ALL_INTERRUPTS; UART_LoopBackConfig( UART1, DISABLE ); UART_IrDACmd( IrDA1, DISABLE ); /* Configure the VIC for the UART interrupts. */ VIC_Config( UART1_ITLine, VIC_IRQ, 9 ); VIC_ITCmd( UART1_ITLine, ENABLE ); UART_Cmd( UART1, ENABLE ); lTaskWaiting = pdFALSE; } portEXIT_CRITICAL(); } else { xReturn = ( xComPortHandle ) 0; } /* This demo file only supports a single port but we have to return something to comply with the standard demo header file. */ return xReturn; }
/*********************************************************************//** * @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 {