1 /*
2  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 /**
9 * @file comm_interface.h
10 * @brief The comm_interface.h file describes the interface definition for the
11  communication interface. Each commaunication instance needs to implement comm interface.
12 */
13 
14 #ifndef COMM_INTERFACE_H_
15 #define COMM_INTERFACE_H_
16 #include <stddef.h>
17 #include <stdint.h>
18 #include <stdbool.h>
19 
20 #define COMM_INTERFACE_OK 0 ///< Operation succeeded
21 
22 /*******************************************************************************
23  * Definitions
24  ******************************************************************************/
25 
26 /* @brief This defines the communication interface handle
27  */
28 typedef struct _comm_handle_
29 {
30     void *pComm;     /*!< pointer to a specific communication channel.*/
31     uint32_t status; /*!< Current Comm status.*/
32 } comm_handle_t;
33 
34 /* @brief This defines the communication interface control config
35  */
36 typedef struct _comm_control_
37 {
38     uint32_t control; /*!< The Control TAG.*/
39     uint32_t arg;     /*!< The Control Arguement value.*/
40 } comm_control_t;
41 
42 /* @brief This defines the different commmunication types
43  */
44 typedef enum _comm_type_
45 {
46     COMM_UART,
47     COMM_BLUETOOTH,
48     COMM_I2C,
49     COMM_SOCKET,
50     COMM_NFC,
51 } comm_type_t;
52 
53 /* @brief This defines the different commmunication types
54  */
55 typedef enum _comm_instance_type_
56 {
57     COMM_BLOCKING,    // Blocking Read and Write Calls
58     COMM_NONBLOCKING, // NonBlocking Read and Write Calls
59 } comm_instance_type_t;
60 
61 /*  Interface functions Signature.*/
62 typedef void (*COMM_Event_t)(uint32_t event); /*< Pointer to Comm Event.*/
63 /*! @brief       The interface function to get the capability of the communication interface.*/
64 typedef int32_t(COMM_GetCapabilities_t)(comm_handle_t *pHandle);
65 /*! @brief       The interface function to initialize the communication interface.*/
66 typedef int32_t(COMM_Init_t)(comm_handle_t *pHandle, void *pCommInstance, COMM_Event_t event, void *pInitializeData);
67 /*! @brief       The interface function to configure the communication interface.*/
68 typedef int32_t(COMM_Config_t)(comm_handle_t *pHandle, void *pConfigData);
69 /*! @brief       The interface function to send data through the communication interface.*/
70 typedef int32_t(COMM_Send_t)(comm_handle_t *pHandle, void *pData, uint32_t size);
71 /*! @brief       The interface function to receive data through the communication interface.*/
72 typedef int32_t(COMM_Receive_t)(comm_handle_t *pHandle, void *pData, uint32_t size);
73 /*! @brief       The interface function to get the status of the comm.*/
74 typedef int32_t(COMM_GetStatus_t)(comm_handle_t *pHandle);
75 
76 /* @brief This defines the function pointers for the comm interface.
77  */
78 typedef struct _comm_interface_
79 {
80     COMM_GetCapabilities_t *GetCapabilities; /*!< Pointer to the communication GetCapabilities() function. */
81     COMM_Init_t *Init;                       /*!< Pointer to the communication Initialize() function. */
82     COMM_Config_t *Configure;                /*!< Pointer to the communication Configure() function. */
83     COMM_Send_t *Send;                       /*!< Pointer to the communication send() function. */
84     COMM_Receive_t *Receive;                 /*!< Pointer to the communication receive() function. */
85     COMM_GetStatus_t *GetStatus;             /*!< Pointer to the adapter GetStatus() function. */
86 } comm_interface_t;
87 #endif // COMM_INTERFACE_H_
88