| ISF 2.1 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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
23 extern uint8 gSys_NumUARTBuses;
24 extern uart_instance_PEx uart_instance_tbl[];
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)){
46 return kStatus_UART_InvalidInstanceNumber;
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)){
66 return kStatus_UART_InvalidInstanceNumber;
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)){
92 return kStatus_UART_InvalidInstanceNumber;
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)){
107 return kStatus_UART_InvalidInstanceNumber;
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)){
131 return kStatus_UART_InvalidInstanceNumber;
132 }
133 return kStatus_UART_Success;
134 }
135
136
137 /*******************************************************************************
138 * EOF
139 ******************************************************************************/
140
UartUserConfig
User configuration structure for UART driver.
Definition: fsl_uart_driver.h:58
uart_receive_data_async
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.
Definition: fsl_uart_driver.c:127
kStatus_UART_Success
Definition: fsl_uart_hal.h:23
uint8
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
uart_instance_PEx
This structure contains i2c LLD function pointers.
Definition: isf_fsl_uart_PEx.h:26
UartState::instance
uint32_t instance
Definition: fsl_uart_driver.h:41
uart_instance_PEx::fnUARTCLLDRead
fnUARTRead_t fnUARTCLLDRead
Definition: isf_fsl_uart_PEx.h:28
FALSE
#define FALSE
Definition: isf_types.h:56
fsl_uart_driver.h
fsl_uart_driver.h defines structures and types for the i2c master driver.
UART_PEX_READ_EVENT_SUCCESS
#define UART_PEX_READ_EVENT_SUCCESS
Definition: fsl_uart_driver.h:48
UART_PEX_WRITE_EVENT_SUCCESS
#define UART_PEX_WRITE_EVENT_SUCCESS
Definition: fsl_uart_driver.h:46
uart_instance_PEx::fnUARTLLDWrite
fnUARTWrite_t fnUARTLLDWrite
Definition: isf_fsl_uart_PEx.h:29
UartState
Runtime state of the UART driver.
Definition: fsl_uart_driver.h:40
uart_send_data_async
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...
Definition: fsl_uart_driver.c:88
isf_util.h
The isf_util.h file contains the utility method declarations and macros.
uart_init
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.
Definition: fsl_uart_driver.c:41
uart_instance_PEx::fnUARTLLDInit
fnUARTInit_t fnUARTLLDInit
Definition: isf_fsl_uart_PEx.h:27
uart_status_t
enum _uart_status uart_status_t
Error codes for the UART driver.
uart_receive_data
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.
Definition: fsl_uart_driver.c:102
uart_send_data
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...
Definition: fsl_uart_driver.c:61
kStatus_UART_Error
Definition: fsl_uart_hal.h:44
UartState::pDeviceHandle
LDD_TDeviceData * pDeviceHandle
Definition: fsl_uart_driver.h:42
UartState::uartEventHandler
LWEVENT_STRUCT uartEventHandler
Definition: fsl_uart_driver.h:43
uart_instance_tbl
uart_instance_PEx uart_instance_tbl[]
Lookup table for the LLD instance.
Definition: isf_fsl_uart_PEx.c:24
UART_PEX_WRITE_EVENT_ERROR
#define UART_PEX_WRITE_EVENT_ERROR
Definition: fsl_uart_driver.h:47
UART_PEX_READ_EVENT_ERROR
#define UART_PEX_READ_EVENT_ERROR
Definition: fsl_uart_driver.h:49
isf_fsl_uart_PEx.h
gSys_NumUARTBuses
uint8 gSys_NumUARTBuses
Definition: isf_sysconf_comms.c:63
kStatus_UART_InvalidInstanceNumber
Definition: fsl_uart_hal.h:39
- © Freescale Semiconductor, Inc. 2015. All Rights Reserved.