ISSDK  1.8
IoT Sensing Software Development Kit
host_demo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file: host_demo.c
11  * @brief The host_demo.c file implements the ISSDK HOST I/O Demo.
12  */
13 
14 /* SDK Includes */
15 #include "pin_mux.h"
16 #include "clock_config.h"
17 #include "board.h"
18 
19 /* CMSIS Includes */
20 #include "Driver_USART.h"
21 
22 /* ISSDK Includes */
23 #include "issdk_hal.h"
24 #include "gpio_driver.h"
25 #include "host_io_uart.h"
26 #include "systick_utils.h"
27 #include "auto_detection_service.h"
28 
29 /*******************************************************************************
30  * Macros
31  ******************************************************************************/
32 /*! @brief Unique Name for this application which should match the target GUI pkg name. */
33 #define APPLICATION_NAME "HOST_DEMO"
34 /*! @brief Version to distinguish between instances the same application based on target Shield and updates. */
35 #define APPLICATION_VERSION "1.0"
36 
37 /*******************************************************************************
38  * Global Variables
39  ******************************************************************************/
42 
43 /*******************************************************************************
44  * Functions
45  ******************************************************************************/
46 /* Handler for Device Info and Streaming Control Commands. */
48  uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
49 {
50  /* If it is Host requesting Device Info, send Board Name and Shield Name. */
51  if (tag == HOST_PRO_INT_DEV_TAG)
52  { /* Byte 1 : Payload - Length of APPLICATION_NAME (b)
53  * Bytes=b : Payload Application Name
54  * Byte b+1 : Payload - Length of BOARD_NAME (s)
55  * Bytes=s : Payload Board Name
56  * Byte b+s+2 : Payload - Length of SHIELD_NAME (v)
57  * Bytes=v : Payload Shield Name */
58 
59  size_t appNameLen = strlen(embAppName);
60  size_t boardNameLen = strlen(boardString);
61  size_t shieldNameLen = strlen(shieldString);
62 
63  if (respBufferSize >= boardNameLen + shieldNameLen + appNameLen + 3)
64  { /* We have sufficient buffer. */
65  *hostMsgSize = 0;
66  }
67  else
68  {
69  return false;
70  }
71 
72  hostResponse[*hostMsgSize] = appNameLen;
73  *hostMsgSize += 1;
74 
75  memcpy(hostResponse + *hostMsgSize, embAppName, appNameLen);
76  *hostMsgSize += appNameLen;
77 
78  hostResponse[*hostMsgSize] = boardNameLen;
79  *hostMsgSize += 1;
80 
81  memcpy(hostResponse + *hostMsgSize, boardString, boardNameLen);
82  *hostMsgSize += boardNameLen;
83 
84  hostResponse[*hostMsgSize] = shieldNameLen;
85  *hostMsgSize += 1;
86 
87  memcpy(hostResponse + *hostMsgSize, shieldString, shieldNameLen);
88  *hostMsgSize += shieldNameLen;
89 
90  return true;
91  }
92 
93  return false;
94 }
95 
96 /*!
97  * @brief Main function
98  */
99 int main(void)
100 {
101  int32_t status;
102  uint8_t bannerLength, bannerString[256];
103 
104  ARM_DRIVER_USART *pUartDriver = &HOST_S_DRIVER;
106 
107  /*! Initialize the MCU hardware. */
110 
111  /* Create the Short Application Name String for ADS. */
112  sprintf(embAppName, "%s:%s", APPLICATION_NAME, APPLICATION_VERSION);
113 
114  /* Run ADS. */
116 
117  /* Create the Full Application Name String. */
119 
120  /* Build Banner String. */
121  bannerLength = sprintf((char *)bannerString,
122  "\r\n Application Name [%s] \r\n Board Name [%s] \r\n Shield Name [%s] \r\n",
124  /*! Initialize GREEN LED pin used by FRDM board */
125  pGpioDriver->pin_init(&GREEN_LED, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
126 
127  /*! Initialize the UART driver. */
128  status = pUartDriver->Initialize(HOST_S_SIGNAL_EVENT);
129  if (ARM_DRIVER_OK != status)
130  {
131  return -1;
132  }
133 
134  /*! Set the UART Power mode. */
135  status = pUartDriver->PowerControl(ARM_POWER_FULL);
136  if (ARM_DRIVER_OK != status)
137  {
138  return -1;
139  }
140 
141  /*! Set UART Baud Rate. */
142  status = pUartDriver->Control(ARM_USART_MODE_ASYNCHRONOUS, BOARD_DEBUG_UART_BAUDRATE);
143  if (ARM_DRIVER_OK != status)
144  {
145  return -1;
146  }
147 
148  /*! Initialize Host I/O. */
149  Host_IO_Init(pUartDriver, NULL, NULL, NULL, 0);
150 
151  /* Send Info Messages to Host. */
152  Host_IO_Send(bannerString, bannerLength, HOST_FORMAT_PLAIN);
153 
154  for (;;) /* Forever loop */
155  { /* Call UART Non-Blocking Receive. */
157  SMC_SetPowerModeWait(SMC); /* Power save, wait if nothing to do. */
158  pGpioDriver->toggle_pin(&GREEN_LED);
159  }
160 }
uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress)
Definition: host_io_uart.c:100
void Host_IO_Receive(host_cmd_proc_fn_t process_host_command, uint8_t encoding)
Definition: host_io_uart.c:207
int32_t status
The host_io_uart.h file contains the Host Protocol interface definitions and configuration.
bool process_host_command(uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
Definition: host_demo.c:47
#define APPLICATION_NAME
Unique Name for this application which should match the target GUI pkg name.
Definition: host_demo.c:33
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:38
#define SMC
Definition: lpc54114.h:118
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define HOST_S_SIGNAL_EVENT
Definition: frdm_k64f.h:94
char shieldString[ADS_MAX_STRING_LENGTH]
Definition: host_demo.c:40
#define BOARD_DEBUG_UART_BAUDRATE
Definition: board.h:31
#define BOARD_BootClockRUN
Definition: clock_config.h:19
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
Definition: gpio_driver.c:177
void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding)
Definition: host_io_uart.c:136
GENERIC_DRIVER_GPIO * pGpioDriver
char boardString[ADS_MAX_STRING_LENGTH]
Definition: host_demo.c:40
#define HOST_PRO_INT_DEV_TAG
Definition: host_io_uart.h:59
void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength)
The function to register Application Name and initialte ADS.
char embAppName[ADS_MAX_STRING_LENGTH]
Definition: host_demo.c:41
void(* toggle_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:48
#define ADS_MAX_STRING_LENGTH
#define APPLICATION_VERSION
Version to distinguish between instances the same application based on target Shield and updates...
Definition: host_demo.c:35
int main(void)
Main function.
Definition: host_demo.c:99
void BOARD_SystickEnable(void)
Function to enable systicks framework.
Definition: systick_utils.c:35
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:155
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
Definition: Driver_GPIO.h:41
ARM Systick Utilities.
gpioHandleKSDK_t GREEN_LED
Definition: frdm_k64f.c:188
#define SHIELD_NAME
#define HOST_S_DRIVER
Definition: frdm_k64f.h:93