|
|
|
@ -61,7 +61,7 @@
|
|
|
|
|
mission critical applications that require provable dependability.
|
|
|
|
|
|
|
|
|
|
1 tab == 4 spaces!
|
|
|
|
|
*/
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART2.
|
|
|
|
@ -73,10 +73,11 @@
|
|
|
|
|
example of an efficient implementation. An efficient implementation should
|
|
|
|
|
use the DMA, and only use FreeRTOS API functions when enough has been
|
|
|
|
|
received to warrant a task being unblocked to process the data.
|
|
|
|
|
*/
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Scheduler includes. */
|
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
|
#include "task.h"
|
|
|
|
|
#include "queue.h"
|
|
|
|
|
#include "semphr.h"
|
|
|
|
|
#include "comtest2.h"
|
|
|
|
@ -84,35 +85,104 @@
|
|
|
|
|
/* Demo application includes. */
|
|
|
|
|
#include "serial.h"
|
|
|
|
|
|
|
|
|
|
/* Xilinx includes. */
|
|
|
|
|
#include "xuartps.h"
|
|
|
|
|
#include "xscugic.h"
|
|
|
|
|
#include "xil_exception.h"
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
static XUartPs xUARTInstance;
|
|
|
|
|
extern XScuGic xInterruptController;
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
static void prvISRHandler( void *pvUnused, uint32_t ulEvent, uint32_t ulUnused2 );
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* See the serial2.h header file.
|
|
|
|
|
*/
|
|
|
|
|
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
|
|
|
|
|
xComPortHandle xSerialPortInitMinimal( uint32_t ulWantedBaud, UBaseType_t uxQueueLength )
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
BaseType_t xStatus;
|
|
|
|
|
XUartPs_Config *pxConfig;
|
|
|
|
|
|
|
|
|
|
/* Look up the UART configuration then initialise the dirver. */
|
|
|
|
|
pxConfig = XUartPs_LookupConfig( XPAR_XUARTPS_0_DEVICE_ID );
|
|
|
|
|
configASSERT( pxConfig );
|
|
|
|
|
|
|
|
|
|
xStatus = XUartPs_CfgInitialize( &xUARTInstance, pxConfig, pxConfig->BaseAddress );
|
|
|
|
|
configASSERT( xStatus == XST_SUCCESS );
|
|
|
|
|
|
|
|
|
|
XUartPs_SetBaudRate( &xUARTInstance, ulWantedBaud );
|
|
|
|
|
|
|
|
|
|
XUartPs_SetOperMode( &xUARTInstance, XUARTPS_OPER_MODE_NORMAL );
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
|
|
|
|
|
BaseType_t xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
TickType_t xTimeOnEntering;
|
|
|
|
|
const TickType_t xDelay = 10UL / portTICK_PERIOD_MS;
|
|
|
|
|
BaseType_t xReturn = 0;
|
|
|
|
|
|
|
|
|
|
xTimeOnEntering = xTaskGetTickCount();
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
/* Only wanting to receive one key press at a time. */
|
|
|
|
|
if( XUartPs_Recv( &xUARTInstance, pcRxedChar, sizeof( pcRxedChar ) ) != 0 )
|
|
|
|
|
{
|
|
|
|
|
xReturn = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vTaskDelay( xDelay );
|
|
|
|
|
}
|
|
|
|
|
} while( ( xTaskGetTickCount() - xTimeOnEntering ) <= xBlockTime );
|
|
|
|
|
|
|
|
|
|
return xReturn;
|
|
|
|
|
}
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
|
|
|
|
|
{
|
|
|
|
|
static const xTxDelay = 10UL / portTICK_PERIOD_MS;
|
|
|
|
|
uint32_t ulBytesSent = 0UL;
|
|
|
|
|
|
|
|
|
|
( void ) pxPort;
|
|
|
|
|
|
|
|
|
|
while( ulBytesSent < usStringLength )
|
|
|
|
|
{
|
|
|
|
|
ulBytesSent += XUartPs_Send( &xUARTInstance, pcString + ulBytesSent, usStringLength - ulBytesSent );
|
|
|
|
|
|
|
|
|
|
while( XUartPs_IsSending( &xUARTInstance ) )
|
|
|
|
|
{
|
|
|
|
|
vTaskDelay( xTxDelay );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
|
|
|
|
|
{
|
|
|
|
|
static const xTxDelay = 10UL / portTICK_PERIOD_MS;
|
|
|
|
|
|
|
|
|
|
XUartPs_Send( &xUARTInstance, &cOutChar, sizeof( cOutChar ) );
|
|
|
|
|
|
|
|
|
|
while( XUartPs_IsSending( &xUARTInstance ) )
|
|
|
|
|
{
|
|
|
|
|
vTaskDelay( xTxDelay );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
void vSerialClose( xComPortHandle xPort )
|
|
|
|
|
void vSerialClose(xComPortHandle xPort)
|
|
|
|
|
{
|
|
|
|
|
/* Not supported as not required by the demo application. */
|
|
|
|
|
}
|
|
|
|
|