ISSDK  1.7
IoT Sensing Software Development Kit
host_interface_service.c
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 /**
35 * @file host_interface_service.c
36 * @brief The dhost_interface_servicec file implements host interface functions
37 */
38 #include <stddef.h>
39 #include <stdint.h>
40 #include <string.h>
41 #include <stdbool.h>
42 #include "host_interface_service.h"
43 
44 /*******************************************************************************
45  * Variables
46  ******************************************************************************/
48 
49 /*******************************************************************************
50  * Functions
51  *****************************************************************************/
53  comm_type_t type,
54  void *pCommInstance,
55  comm_instance_type_t inType,
56  Host_Event_t event,
57  void *pInData)
58 {
60 
61  if (type == COMM_UART)
62  {
63  pHandle->pCommInterface = &commUART;
64  }
65  comm_interface_t *pCommInt = pHandle->pCommInterface;
66  pHandle->event = event;
67  pHandle->pInData = pInData;
68  pHandle->instanceType = inType;
69  // call interface function with appropriate comm instance.
70  status = pCommInt->Init(&pHandle->commHandle, (void *)pCommInstance, pHandle->event, pHandle->pInData);
71 
72  return status;
73 }
74 
75 int32_t HOST_Configure(host_interface_handle_t *pHandle, void *pConfigData)
76 {
78 
79  comm_interface_t *pCommInt = pHandle->pCommInterface;
80  status = pCommInt->Configure(&pHandle->commHandle, pConfigData);
81  return status;
82 }
83 
84 int32_t HOST_Send(host_interface_handle_t *pHandle, uint8_t *pData, uint32_t size)
85 {
87 
88  comm_interface_t *pCommInt = pHandle->pCommInterface;
89  status = pCommInt->Send(&pHandle->commHandle, pData, size);
90  return status;
91 }
92 
94  host_interface_handle_t *pHandle, uint8_t *pData, uint32_t *pRecvSize, uint32_t size, BlockRead_t process)
95 {
97 
98  comm_interface_t *pCommInt = pHandle->pCommInterface;
99  // Call Host Data format specified callback for block read data
100  if ((process != NULL) && (pHandle->instanceType == COMM_BLOCKING))
101  {
102  process(pHandle, pData);
103  status = HOST_INTERFACE_OK;
104  }
105  else
106  {
107  status = pCommInt->Receive(&pHandle->commHandle, pData, size);
108  }
109  return status;
110 }
int32_t HOST_Configure(host_interface_handle_t *pHandle, void *pConfigData)
The function to Configure the Host.
int32_t status
#define HOST_INTERFACE_OK
The host_interface_service.h file describes the structures and definitions for the host...
int32_t HOST_Initialize(host_interface_handle_t *pHandle, comm_type_t type, void *pCommInstance, comm_instance_type_t inType, Host_Event_t event, void *pInData)
The function to Initialize the Host.
int32_t HOST_Receive(host_interface_handle_t *pHandle, uint8_t *pData, uint32_t *pRecvSize, uint32_t size, BlockRead_t process)
The function to receive data from the host.
comm_interface_t * pCommInterface
COMM_Send_t * Send
enum _comm_instance_type_ comm_instance_type_t
COMM_Receive_t * Receive
COMM_Config_t * Configure
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
uint32_t size
int32_t HOST_Send(host_interface_handle_t *pHandle, uint8_t *pData, uint32_t size)
The function to Send the data to the host.
enum _comm_type_ comm_type_t
void(* BlockRead_t)(host_interface_handle_t *pHandle, void *pData)
comm_instance_type_t instanceType
void(* Host_Event_t)(uint32_t event)
comm_interface_t commUART
Definition: comm_if_uart.c:92
COMM_Init_t * Init