static int cyg_hal_plf_serial_control(channel_data_t *chan, __comm_control_cmd_t func, ...) { Xuint16 opt; int ret = 0; led(1); if (!chan->dev_ok) return ret; switch (func) { case __COMMCTL_IRQ_ENABLE: opt = XUartNs550_GetOptions(&chan->dev) | XUN_OPTION_DATA_INTR; XUartNs550_SetOptions(&chan->dev, opt); HAL_INTERRUPT_UNMASK(chan->isr_vector); chan->int_state = 1; break; case __COMMCTL_IRQ_DISABLE: ret = chan->int_state; chan->int_state = 0; opt = XUartNs550_GetOptions(&chan->dev) & ~XUN_OPTION_DATA_INTR; XUartNs550_SetOptions(&chan->dev, opt); HAL_INTERRUPT_MASK(chan->isr_vector); break; case __COMMCTL_DBG_ISR_VECTOR: ret = chan->isr_vector; break; case __COMMCTL_SET_TIMEOUT: { va_list ap; va_start(ap, func); ret = chan->msec_timeout; chan->msec_timeout = va_arg(ap, cyg_uint32); va_end(ap); } default: break; } return ret; }
/** * * This function does a minimal test on the UART 16450/550 device and driver as a * design example. The purpose of this function is to illustrate how to use * the XUartNs550 component. * * This function sends data and expects to receive the data thru the UART * using the local loopback mode of the UART hardware. * * This function polls the UART and does not require the use of interrupts. * * @param DeviceId is the XPAR_<uartns550_instance>_DEVICE_ID value from * xparameters.h. * * @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful. * * @note This function polls the UART such that it may be not return * if the hardware is not working correctly. * ****************************************************************************/ int UartNs550PolledExample(u16 DeviceId) { int Status; unsigned int SentCount; unsigned int ReceivedCount = 0; u16 Index; u16 Options; /* * Initialize the UART Lite driver so that it's ready to use, * specify the device ID that is generated in xparameters.h */ Status = XUartNs550_Initialize(&UartNs550, DeviceId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly */ Status = XUartNs550_SelfTest(&UartNs550); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the local loopback so data that is sent will be received, * and keep the FIFOs enabled */ Options = XUN_OPTION_LOOPBACK | XUN_OPTION_FIFOS_ENABLE; XUartNs550_SetOptions(&UartNs550, Options); /* * Initialize the send buffer bytes with a pattern to send and the * the receive buffer bytes to zero */ for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) { SendBuffer[Index] = '0' + Index; RecvBuffer[Index] = 0; } /* * Send the buffer thru the UART waiting till the data can be * sent (block), if the specified number of bytes was not sent * successfully, then an error occurred */ SentCount = XUartNs550_Send(&UartNs550, SendBuffer, TEST_BUFFER_SIZE); if (SentCount != TEST_BUFFER_SIZE) { return XST_FAILURE; } /* * Receive the number of bytes which is transfered. * Data may be received in fifo with some delay hence we continuously * check the receive fifo for valid data and update the receive buffer * accordingly. */ while (1) { ReceivedCount += XUartNs550_Recv(&UartNs550, RecvBuffer + ReceivedCount, TEST_BUFFER_SIZE - ReceivedCount); if (ReceivedCount == TEST_BUFFER_SIZE) { break; } } /* * Check the receive buffer data against the send buffer and verify the * data was correctly received */ for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) { if (SendBuffer[Index] != RecvBuffer[Index]) { return XST_FAILURE; } } /* * Clean up the options */ Options = XUartNs550_GetOptions(&UartNs550); Options = Options & ~(XUN_OPTION_LOOPBACK | XUN_OPTION_FIFOS_ENABLE); XUartNs550_SetOptions(&UartNs550, Options); return XST_SUCCESS; }