ISSDK  1.7
IoT Sensing Software Development Kit
host_demo.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 /**
36  * @file: host_demo.c
37  * @brief The host_demo.c file implements the ISSDK HOST I/O Demo.
38  */
39 
40 /* SDK Includes */
41 #include "board.h"
42 #include "pin_mux.h"
43 #include "clock_config.h"
44 
45 /* CMSIS Includes */
46 #include "Driver_USART.h"
47 
48 /* ISSDK Includes */
49 #include "issdk_hal.h"
50 #include "gpio_driver.h"
51 #include "host_io_uart.h"
52 #include "systick_utils.h"
53 #include "auto_detection_service.h"
54 
55 /*******************************************************************************
56  * Macros
57  ******************************************************************************/
58 /*! @brief Unique Name for this application which should match the target GUI pkg name. */
59 #define APPLICATION_NAME "HOST_DEMO"
60 /*! @brief Version to distinguish between instances the same application based on target Shield and updates. */
61 #define APPLICATION_VERSION "1.0"
62 
63 /*******************************************************************************
64  * Global Variables
65  ******************************************************************************/
68 
69 /*******************************************************************************
70  * Functions
71  ******************************************************************************/
72 /* Handler for Device Info and Streaming Control Commands. */
74  uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
75 {
76  /* If it is Host requesting Device Info, send Board Name and Shield Name. */
77  if (tag == HOST_PRO_INT_DEV_TAG)
78  { /* Byte 1 : Payload - Length of APPLICATION_NAME (b)
79  * Bytes=b : Payload Application Name
80  * Byte b+1 : Payload - Length of BOARD_NAME (s)
81  * Bytes=s : Payload Board Name
82  * Byte b+s+2 : Payload - Length of SHIELD_NAME (v)
83  * Bytes=v : Payload Shield Name */
84 
85  size_t appNameLen = strlen(embAppName);
86  size_t boardNameLen = strlen(boardString);
87  size_t shieldNameLen = strlen(shieldString);
88 
89  if (respBufferSize >= boardNameLen + shieldNameLen + appNameLen + 3)
90  { /* We have sufficient buffer. */
91  *hostMsgSize = 0;
92  }
93  else
94  {
95  return false;
96  }
97 
98  hostResponse[*hostMsgSize] = appNameLen;
99  *hostMsgSize += 1;
100 
101  memcpy(hostResponse + *hostMsgSize, embAppName, appNameLen);
102  *hostMsgSize += appNameLen;
103 
104  hostResponse[*hostMsgSize] = boardNameLen;
105  *hostMsgSize += 1;
106 
107  memcpy(hostResponse + *hostMsgSize, boardString, boardNameLen);
108  *hostMsgSize += boardNameLen;
109 
110  hostResponse[*hostMsgSize] = shieldNameLen;
111  *hostMsgSize += 1;
112 
113  memcpy(hostResponse + *hostMsgSize, shieldString, shieldNameLen);
114  *hostMsgSize += shieldNameLen;
115 
116  return true;
117  }
118 
119  return false;
120 }
121 
122 /*!
123  * @brief Main function
124  */
125 int main(void)
126 {
127  int32_t status;
128  uint8_t bannerLength, bannerString[256];
129 
130  ARM_DRIVER_USART *pUartDriver = &HOST_S_DRIVER;
132 
133  /*! Initialize the MCU hardware. */
136 
137  /* Create the Short Application Name String for ADS. */
138  sprintf(embAppName, "%s:%s", APPLICATION_NAME, APPLICATION_VERSION);
139 
140  /* Run ADS. */
142 
143  /* Create the Full Application Name String. */
145 
146  /* Build Banner String. */
147  bannerLength = sprintf((char *)bannerString,
148  "\r\n Application Name [%s] \r\n Board Name [%s] \r\n Shield Name [%s] \r\n",
150  /*! Initialize GREEN LED pin used by FRDM board */
151  pGpioDriver->pin_init(&GREEN_LED, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
152 
153  /*! Initialize the UART driver. */
154  status = pUartDriver->Initialize(HOST_S_SIGNAL_EVENT);
155  if (ARM_DRIVER_OK != status)
156  {
157  return -1;
158  }
159 
160  /*! Set the UART Power mode. */
161  status = pUartDriver->PowerControl(ARM_POWER_FULL);
162  if (ARM_DRIVER_OK != status)
163  {
164  return -1;
165  }
166 
167  /*! Set UART Baud Rate. */
168  status = pUartDriver->Control(ARM_USART_MODE_ASYNCHRONOUS, BOARD_DEBUG_UART_BAUDRATE);
169  if (ARM_DRIVER_OK != status)
170  {
171  return -1;
172  }
173 
174  /*! Initialize Host I/O. */
175  Host_IO_Init(pUartDriver, NULL, NULL, NULL, 0);
176 
177  /* Send Info Messages to Host. */
178  Host_IO_Send(bannerString, bannerLength, HOST_FORMAT_PLAIN);
179 
180  for (;;) /* Forever loop */
181  { /* Call UART Non-Blocking Receive. */
183  SMC_SetPowerModeWait(SMC); /* Power save, wait if nothing to do. */
184  pGpioDriver->toggle_pin(&GREEN_LED);
185  }
186 }
#define HOST_S_SIGNAL_EVENT
Definition: frdm_k64f.h:120
void Host_IO_Receive(host_cmd_proc_fn_t process_host_command, uint8_t encoding)
Definition: host_io_uart.c:233
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
Definition: Driver_GPIO.h:67
#define BOARD_BootClockRUN
Definition: clock_config.h:45
char embAppName[ADS_MAX_STRING_LENGTH]
Definition: host_demo.c:67
int32_t status
void(* toggle_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:74
#define SHIELD_NAME
char boardString[ADS_MAX_STRING_LENGTH]
Definition: host_demo.c:66
#define ADS_MAX_STRING_LENGTH
#define HOST_PRO_INT_DEV_TAG
Definition: host_io_uart.h:85
GENERIC_DRIVER_GPIO * pGpioDriver
gpioHandleKSDK_t GREEN_LED
Definition: frdm_k64f.c:214
bool process_host_command(uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
Definition: host_demo.c:73
void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding)
Definition: host_io_uart.c:162
char shieldString[ADS_MAX_STRING_LENGTH]
Definition: host_demo.c:66
void BOARD_SystickEnable(void)
Function to enable systicks framework.
Definition: systick_utils.c:70
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
Definition: gpio_driver.c:203
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define BOARD_DEBUG_UART_BAUDRATE
Definition: board.h:57
int main(void)
Main function.
Definition: host_demo.c:125
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:64
#define APPLICATION_VERSION
Version to distinguish between instances the same application based on target Shield and updates...
Definition: host_demo.c:61
ARM Systick Utilities.
void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength)
The function to register Application Name and initialte ADS.
uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress)
Definition: host_io_uart.c:126
#define SMC
Definition: lpc54114.h:144
The host_io_uart.h file contains the Host Protocol interface definitions and configuration.
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
Definition: lpc54114.c:181
#define APPLICATION_NAME
Unique Name for this application which should match the target GUI pkg name.
Definition: host_demo.c:59
#define HOST_S_DRIVER
Definition: frdm_k64f.h:119