![]() |
ISF
2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
|
isf_uart_adapter.c implements uart protocol adapter. More...
#include "isf.h"
#include "isf_uart_adapter.h"
#include "isf_uart_types.h"
#include "isf_devmsg.h"
#include "isf_util.h"
#include "isf_protocol_adapter.h"
Go to the source code of this file.
Macros | |
#define | ISF_LOCK_DEFAULT (0) |
Functions | |
isf_status_t | uart_adapter_init (comm_Id_t aBusId, busHandle_t *apBusHandle) |
This function initializes a uart bus. More... | |
isf_status_t | uart_adapter_configure (busHandle_t *apBusHandle, uart_user_config_t *apBusConfig) |
This function reconfigures an already initialized bus. More... | |
comm_State_t | uart_adapter_get_state (busHandle_t *apBusHandle) |
This function returns the current bus state. More... | |
isf_status_t | uart_adapter_get_config (busHandle_t *apBusHandle, void *apBusConfig) |
This function returns the current bus configuration. More... | |
isf_status_t | uart_adapter_acquire_lock (busHandle_t *apBusHandle, isf_duration_t aTimeout) |
This function locks the bus for exclusive access. More... | |
isf_status_t | uart_adapter_release_lock (busHandle_t *apBusHandle) |
This function releases exclusive bus access. More... | |
isf_status_t | uart_adapter_start (busHandle_t *apBusHandle) |
This function starts a bus. More... | |
isf_status_t | uart_adapter_stop (busHandle_t *apBusHandle) |
This function stops the given uart bus. More... | |
isf_status_t | uart_adapter_get_endpoint (busHandle_t *apBusHandle, void *apDevice, void **apEndpointHandle) |
This function creates a endpoint at a already initialized bus. More... | |
isf_status_t | uart_adapter_release_endpoint (uart_Endpoint_t *apEndpoint) |
This function closes a particular endpoint. More... | |
isf_status_t | uart_adapter_write (void *apEndpointHandle, int32 offset, void *pWriteBuffer, uint32 buffsize, uint32 nByteWrite, uart_writeFlags_t aFlags) |
This function writes to a uart device. More... | |
isf_status_t | uart_adapter_read (void *apEndpointHandle, int32 offset, void *pReadBuffer, uint32 buffsize, uint32 nByteRead, uart_readFlags_t aFlags) |
This function reads from a uart device. More... | |
uart_status_t | uart_user_init (uint32_t instance, const uart_UserDefinedVars_t *userDefinedVars) |
Initializes UART User defined parameters. More... | |
Variables | |
const uart_UserDefinedVars_t * | g_uartUserDefinedVars [UART_INSTANCE_COUNT] |
uint8 | gSys_NumUartBuses |
uart_busHandle_t | uart_busHandle [] |
mutex_t | uart_lock [] |
mutex_t | uart_rdlock [] |
isf_uart_adapter.c implements uart protocol adapter.
File:isf_uart_adapter.c
Copyright (c) 2015, Freescale Semiconductor, Inc.
Definition in file isf_uart_adapter.c.
#define ISF_LOCK_DEFAULT (0) |
Definition at line 21 of file isf_uart_adapter.c.
Referenced by uart_adapter_init().
isf_status_t uart_adapter_acquire_lock | ( | busHandle_t * | apBusHandle, |
isf_duration_t | aTimeout | ||
) |
This function locks the bus for exclusive access.
uart_adapter_acquire_lock() serializes multi-client access. While holding the bus lock, no other clients may perform any bus operations. Therefore, it is important to release the lock with uart_adapter_release_lock() as soon as practical.
[in] | apBusHandle | The handle of the bus to be started. |
[in] | aTimeout | The time to wait for the lock before returning without the lock. The timeout parameter may be set to zero to wait for calls that fail to return without acquiring the lock, or wait as long as necessary for the lock to be acquired. |
ISF_SUCCESS | is returned when the bus lock is acquired. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized channel. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
Definition at line 142 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busConfig, COMM_ERROR_NULL_PTR, ISF_SUCCESS, busHandle_struct::pHandle, uart_BusConfig_struct::timeout, and UART_LOCK_COMMON.
isf_status_t uart_adapter_configure | ( | busHandle_t * | apBusHandle, |
uart_user_config_t * | apBusConfig | ||
) |
This function reconfigures an already initialized bus.
A bus may be reconfigured after initialization. Calls to uart_adapter_configure() after initialization will override any previous configuration values and must be made while the bus state is COMM_STATE_STOPPED. The typical usage involves retrieving the current configuration using uart_adapter_get_config(), making modifications to the returned configuration, and then calling uart_adapter_configure() with the updated configuration. The bus is implicitly locked during the configuration.
[in] | apBusHandle | The handle of the bus to be configured. |
[in] | apBusConfig | The configuration value for the bus to be configured. |
ISF_SUCCESS | is returned when the bus was reconfigured successfully. |
COMM_ERROR_STOP | is returned when the bus was not STOPPED. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
Definition at line 75 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busConfig, uart_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, COMM_ERROR_STOP, COMM_STATE_INIT, COMM_STATE_STOPPED, uart_BusConfig_struct::config, ISFUartState::instance, ISF_SUCCESS, busHandle_struct::pHandle, uart_BusConfig_struct::timeout, uart_userDefinedVars_struct::timeout, UART_LOCK_COMMON, UART_LOCK_READ, and uart_BusHandle_struct::uartHandle.
isf_status_t uart_adapter_get_config | ( | busHandle_t * | apBusHandle, |
void * | apBusConfig | ||
) |
This function returns the current bus configuration.
A bus may be queried for the current configuration.
[in] | apBusHandle | The handle of the bus to be queried. |
[out] | apBusConfig | The address of a bus configuration to be filled. |
ISF_SUCCESS | is returned when the bus configuration is retrieved successfully. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized bus. |
Definition at line 124 of file isf_uart_adapter.c.
References COMM_ERROR_NULL_PTR, ISF_SUCCESS, and busHandle_struct::pHandle.
isf_status_t uart_adapter_get_endpoint | ( | busHandle_t * | apBusHandle, |
void * | apDevice, | ||
void ** | apEndpointHandle | ||
) |
This function creates a endpoint at a already initialized bus.
The uart_adapter_get_endpoint() function may be used to get a handle to a intialized device.
[in] | apBusHandle | The handle of the bus to be opened. |
[in] | apDevice | The known information of the device to be opened. |
[out] | apEndpointHandle | The address of a apEndpointHandle to be filled. |
ISF_SUCCESS | is returned when the device is located and a valid handle is returned. |
COMM_ERROR_NOEXIST | is returned when a device does not exist at the specified bus. |
COMM_ERROR_INIT | is returned when the channel handle refers to a non-initialized channel. |
COMM_ERROR_STOP | is returned when the channel has not been started. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
Definition at line 225 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busConfig, uart_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, COMM_ERROR_STOP, COMM_STATE_OK, ISF_SUCCESS, uart_deviceEndpoint_struct::pBusHandle, busHandle_struct::pHandle, uart_BusConfig_struct::timeout, and UART_LOCK_COMMON.
comm_State_t uart_adapter_get_state | ( | busHandle_t * | apBusHandle | ) |
This function returns the current bus state.
A bus may be queried for its current state.
[in] | apBusHandle | The handle of the bus to be queried. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
Definition at line 110 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, and busHandle_struct::pHandle.
isf_status_t uart_adapter_init | ( | comm_Id_t | aBusId, |
busHandle_t * | apBusHandle | ||
) |
This function initializes a uart bus.
A bus must be initialized prior to use. Initialization creates the bus and initializes the data structures required to manage the bus.
[in] | aBusId | The ID of the bus to initialize. This is an index into the array of known uart buses that can be used. |
[out] | apBusHandle | The handle to the bus to be initialized. |
ISF_SUCCESS | is returned when the bus is initialized successfully and the apBusHandle structure reference has been populated with initialized uart bus data. |
COMM_ERROR_NOEXIST | is returned when the supplied bus identifier does not exist. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_INIT | is returned when the bus could not be initialized. |
Definition at line 43 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busState, COMM_ERROR_NOEXIST, COMM_STATE_INIT, COMM_STATE_NO_INIT, gSys_NumUartBuses, ISFUartState::instance, ISF_LOCK_DEFAULT, ISF_SUCCESS, busHandle_struct::nLock, busHandle_struct::nRdLock, busHandle_struct::pHandle, busHandle_struct::pLock, busHandle_struct::pRdLock, uart_lock, uart_rdlock, and uart_BusHandle_struct::uartHandle.
isf_status_t uart_adapter_read | ( | void * | apEndpointHandle, |
int32 | offset, | ||
void * | apReadBuffer, | ||
uint32 | aBuffsize, | ||
uint32 | aNbyteRead, | ||
uart_readFlags_t | aFlags | ||
) |
This function reads from a uart device.
uart_adapter_read() reads data from the specified device. It wait for the requested number of bytes to be read from the UART receive buffer. The device is implicitly locked during the read.
[in] | apEndpointHandle | The handle to the device endpoint for. |
[in] | offset | The read offset/sub address from which the data to be read. |
[in] | apReadBuffer | The buffer address where any returned data is placed. |
[in] | aBuffsize | The size of the buffer passed. |
[in] | aNbyteRead | The number of bytes to read from the device. |
[in] | aFlags | The read flag that change the mode of read of operation. |
ISF_SUCCESS | is returned when data from the device was read successfully. |
COMM_ERROR_BUF_SIZE | is returned when the provided buffer is too small to hold all the data or the number of bytes read is zero. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
COMM_ERROR_LOCK | is returned when a lock could not be acquired properly. |
Definition at line 319 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busConfig, uart_BusHandle_struct::busState, COMM_ERROR_BUF_SIZE, COMM_ERROR_INIT, COMM_ERROR_NULL_PTR, COMM_STATE_OK, ISFUartState::instance, ISF_SUCCESS, uart_deviceEndpoint_struct::pBusHandle, busHandle_struct::pHandle, uart_BusConfig_struct::timeout, UART_ASYNC, UART_LOCK_READ, UART_MODE_DMA, UART_MODE_INT, uart_BusHandle_struct::uartHandle, and uart_userDefinedVars_struct::uartMode.
isf_status_t uart_adapter_release_endpoint | ( | uart_Endpoint_t * | apEndpoint | ) |
This function closes a particular endpoint.
The uart_adapter_release_endpoint() function is used when no further communication with the device is needed. A closed device should not be passed to uart_adapter_write() or uart_adapter_write().
[in] | apEndpoint | The address of the end point where the endpoint is established. |
ISF_SUCCESS | is returned when the device changes to closed. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
Definition at line 253 of file isf_uart_adapter.c.
References COMM_ERROR_NULL_PTR, and ISF_SUCCESS.
isf_status_t uart_adapter_release_lock | ( | busHandle_t * | apBusHandle | ) |
This function releases exclusive bus access.
uart_adapter_release_lock() is used to relinquish exclusive access on a particular bus. It is the inverse of uart_adapter_acquire_lock().
[in] | apBusHandle | The handle of the bus to unlock. |
ISF_SUCCESS | is returned when the bus released successfully. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized channel. |
COMM_ERROR_LOCK | is returned when no lock was held on the specified bus. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
Definition at line 159 of file isf_uart_adapter.c.
References COMM_ERROR_NULL_PTR, ISF_SUCCESS, and UART_LOCK_COMMON.
isf_status_t uart_adapter_start | ( | busHandle_t * | apBusHandle | ) |
This function starts a bus.
uart_adapter_start() enables communications with an initialized bus.
[in] | apBusHandle | The handle of the bus to be started. |
ISF_SUCCESS | is returned when the bus was started successfully. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized channel. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
Definition at line 175 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busConfig, uart_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, COMM_STATE_OK, ISFUartState::instance, busHandle_struct::pHandle, uart_BusConfig_struct::timeout, UART_LOCK_COMMON, and uart_BusHandle_struct::uartHandle.
isf_status_t uart_adapter_stop | ( | busHandle_t * | apBusHandle | ) |
This function stops the given uart bus.
uart_adapter_stop() disables an initialized bus and stops communications with the channel.
[in] | apBusHandle | The handle of the bus to be stopped. |
ISF_SUCCESS | is returned when the bus is successfully stopped. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized channel. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
Definition at line 200 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busConfig, uart_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, COMM_STATE_STOPPED, ISFUartState::instance, busHandle_struct::pHandle, uart_BusConfig_struct::timeout, UART_LOCK_COMMON, and uart_BusHandle_struct::uartHandle.
isf_status_t uart_adapter_write | ( | void * | apEndpointHandle, |
int32 | offset, | ||
void * | apWriteBuffer, | ||
uint32 | aBuffsize, | ||
uint32 | aNbyteWrite, | ||
uart_writeFlags_t | aFlags | ||
) |
This function writes to a uart device.
uart_adapter_write () writes data to the specified device. The device is implicitly locked during the write.
[in] | apEndpointHandle | The handle to the device endpoint to which to write is performed. |
[in] | offset | The read offset/sub address from which the data to be write. |
[in] | apWriteBuffer | The buffer address where write data is placed. |
[in] | aBuffsize | The size of the buffer passed. |
[in] | aNbyteWrite | The number of bytes to write to the device. |
[in] | aFlags | The write flag that change the mode of read of operation. |
ISF_SUCCESS | is returned when the device was written successfully. |
COMM_ERROR_STOP | is returned when the write is invoked on a stopped channel. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
COMM_ERROR_LOCK | is returned when a lock could not be acquired properly. |
Definition at line 268 of file isf_uart_adapter.c.
References uart_BusHandle_struct::busConfig, uart_BusHandle_struct::busState, COMM_ERROR_BUF_SIZE, COMM_ERROR_INIT, COMM_ERROR_NULL_PTR, COMM_STATE_OK, ISFUartState::instance, ISF_SUCCESS, uart_deviceEndpoint_struct::pBusHandle, busHandle_struct::pHandle, uart_BusConfig_struct::timeout, UART_ASYNC, UART_LOCK_COMMON, UART_MODE_INT, uart_BusHandle_struct::uartHandle, and uart_userDefinedVars_struct::uartMode.
uart_status_t uart_user_init | ( | uint32_t | instance, |
const uart_UserDefinedVars_t * | userDefinedVars | ||
) |
Initializes UART User defined parameters.
This function initializes the run-time state structure to provide the user defined UART settings.
instance | The UART instance to be initialized. |
userDefinedVars | The UART user defined parameters such as timeout and UART Type. |
Definition at line 432 of file isf_uart_adapter.c.
Referenced by Components_Init().
const uart_UserDefinedVars_t* g_uartUserDefinedVars[UART_INSTANCE_COUNT] |
Definition at line 26 of file isf_uart_adapter.c.
uint8 gSys_NumUartBuses |
Definition at line 45 of file isf_sysconf_comms.c.
Referenced by uart_adapter_init().
uart_busHandle_t uart_busHandle[] |
Definition at line 46 of file isf_sysconf_comms.c.
mutex_t uart_lock[] |
Definition at line 47 of file isf_sysconf_comms.c.
Referenced by uart_adapter_init().
mutex_t uart_rdlock[] |
Definition at line 48 of file isf_sysconf_comms.c.
Referenced by uart_adapter_init().