ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fsl_uart_driver.c
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: fsl_uart_driver.c
4 *
5 * Copyright (c) 2014, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file fsl_uart_driver.c
10 * @brief \b fsl_uart_driver.c implements uart driver layer.
11 */
12 #include "fsl_uart_driver.h"
13 #include "isf_fsl_uart_PEx.h"
14 #include "PE_Types.h"
15 #include "PE_Error.h"
16 #include "mqxlite.h"
17 #include "lwmem.h"
18 #include "isf_util.h"
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 
25 /*******************************************************************************
26  * Variables
27  ******************************************************************************/
28 
29 
30 /*******************************************************************************
31  * Code
32  ******************************************************************************/
33 
34  /***********************************************************************
35  *
36  * Function Name : uart_init
37  * Description : initializes the uart driver.
38  * This function will initialize the uart driver, set the parity and start/stop bit.
39  *
40  ***************************************************************************/
41 uart_status_t uart_init(uint32_t uartInstance, uart_state_t * uartState,
42  const uart_user_config_t * uartUserConfig)
43 {
44 
45  if((uartState == NULL) || (uartInstance >= gSys_NumUARTBuses)){
47  }
48  uartState->instance = uartInstance;
49  uartState->pDeviceHandle = uart_instance_tbl[uartInstance].fnUARTLLDInit(uartState);
50  _lwevent_create(&uartState->uartEventHandler, LWEVENT_AUTO_CLEAR);
51  return kStatus_UART_Success;
52 
53 }
54 /***********************************************************************
55  *
56  * Function Name : uart_send_data
57  * Description : Blocking write transaction on the UART bus.
58  *
59  *
60  ***************************************************************************/
61 uart_status_t uart_send_data(uart_state_t * uartState, const uint8_t * sendBuffer,
62  uint32_t txByteCount, uint32_t timeout)
63 {
64 
65  if((uartState == NULL) || (uartState->instance >= gSys_NumUARTBuses)){
67  }
68  _mqx_uint event = 0;
69  if(ERR_OK != uart_instance_tbl[uartState->instance].fnUARTLLDWrite(uartState->pDeviceHandle, (uint8_t*)sendBuffer, txByteCount)){
70  return kStatus_UART_Error;
71  }
72  // wait for the transfer to complete.
73  event = _lwevent_wait_ticks(&uartState->uartEventHandler, UART_PEX_WRITE_EVENT_SUCCESS | UART_PEX_WRITE_EVENT_ERROR,
74  FALSE, timeout);
75  if((_lwevent_get_signalled() & UART_PEX_WRITE_EVENT_ERROR) || (LWEVENT_WAIT_TIMEOUT == event)){
76  return kStatus_UART_Error;
77  }
78  return kStatus_UART_Success;
79 }
80 /***********************************************************************
81  *
82  * Function Name : uart_send_data_async
83  * Description : Non blocking write transaction on the UART bus.
84  *
85  *
86  ***************************************************************************/
87 
88 uart_status_t uart_send_data_async(uart_state_t * uartState, const uint8_t * sendBuffer,
89  uint32_t txByteCount)
90 {
91  if((uartState == NULL) || (uartState->instance >= gSys_NumUARTBuses)){
93  }
94  return kStatus_UART_Success;
95 }
96 /***********************************************************************
97  *
98  * Function Name : uart_receive_data
99  * Description : Blocking receive call for the UART.
100  *
101  ***************************************************************************/
102 uart_status_t uart_receive_data(uart_state_t * uartState, uint8_t * rxBuffer,
103  uint32_t requestedByteCount, uint32_t timeout)
104 
105 {
106  if((uartState == NULL) || (uartState->instance >= gSys_NumUARTBuses)){
108  }
109  _mqx_uint event = 0;
110  if(ERR_OK != uart_instance_tbl[uartState->instance].fnUARTCLLDRead(uartState->pDeviceHandle, rxBuffer, requestedByteCount)){
111  return kStatus_UART_Error;
112  }
113  // wait for the receive to complete.
114  event = _lwevent_wait_ticks(&uartState->uartEventHandler, UART_PEX_READ_EVENT_SUCCESS | UART_PEX_READ_EVENT_ERROR,
115  FALSE, timeout);
116  if((_lwevent_get_signalled() & UART_PEX_READ_EVENT_ERROR) || (LWEVENT_WAIT_TIMEOUT == event)){
117  return kStatus_UART_Error;
118  }
119  return kStatus_UART_Success;
120 }
121 /***********************************************************************
122  *
123  * Function Name : uart_receive_data
124  * Description : Non-Blocking receive call for the UART.
125  *
126  ***************************************************************************/
127 uart_status_t uart_receive_data_async(uart_state_t * uartState, uint8_t * rxBuffer,
128  uint32_t requestedByteCount)
129 {
130  if((uartState == NULL) || (uartState->instance >= gSys_NumUARTBuses)){
132  }
133  return kStatus_UART_Success;
134 }
135 
136 
137 /*******************************************************************************
138  * EOF
139  ******************************************************************************/
140 
User configuration structure for UART driver.
uart_status_t uart_receive_data_async(uart_state_t *uartState, uint8_t *rxBuffer, uint32_t requestedByteCount)
This function gets (receives) data from the UART module using a non-blocking method.
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
This structure contains i2c LLD function pointers.
uint32_t instance
fnUARTRead_t fnUARTCLLDRead
#define FALSE
Definition: isf_types.h:56
fsl_uart_driver.h defines structures and types for the i2c master driver.
#define UART_PEX_READ_EVENT_SUCCESS
#define UART_PEX_WRITE_EVENT_SUCCESS
fnUARTWrite_t fnUARTLLDWrite
Runtime state of the UART driver.
uart_status_t uart_send_data_async(uart_state_t *uartState, const uint8_t *sendBuffer, uint32_t txByteCount)
This function sends (transmits) data through the UART module using a non-blocking method...
The isf_util.h file contains the utility method declarations and macros.
uart_status_t uart_init(uint32_t uartInstance, uart_state_t *uartState, const uart_user_config_t *uartUserConfig)
This function initializes a UART instance for operation.
fnUARTInit_t fnUARTLLDInit
enum _uart_status uart_status_t
Error codes for the UART driver.
uart_status_t uart_receive_data(uart_state_t *uartState, uint8_t *rxBuffer, uint32_t requestedByteCount, uint32_t timeout)
This function gets (receives) data from the UART module using a blocking method.
uart_status_t uart_send_data(uart_state_t *uartState, const uint8_t *sendBuffer, uint32_t txByteCount, uint32_t timeout)
This function sends (transmits) data out through the UART module using a blocking method...
LDD_TDeviceData * pDeviceHandle
LWEVENT_STRUCT uartEventHandler
uart_instance_PEx uart_instance_tbl[]
Lookup table for the LLD instance.
#define UART_PEX_WRITE_EVENT_ERROR
#define UART_PEX_READ_EVENT_ERROR
uint8 gSys_NumUARTBuses