-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
261 lines (223 loc) · 8.68 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/******************************************************************************
* File Name: main.c
*
* Description: This is the source code for CE229265 - Amazon FreeRTOS Example:
* Wi-Fi Scan
*
* Related Document: See README.md
*
*
*******************************************************************************
* Copyright 2019-2021, Cypress Semiconductor Corporation (an Infineon company) or
* an affiliate of Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related
* materials ("Software") is owned by Cypress Semiconductor Corporation
* or one of its affiliates ("Cypress") and is protected by and subject to
* worldwide patent protection (United States and foreign),
* United States copyright laws and international treaty provisions.
* Therefore, you may use this Software only as provided in the license
* agreement accompanying the software package from which you
* obtained this Software ("EULA").
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software
* source code solely for use in connection with Cypress's
* integrated circuit products. Any reproduction, modification, translation,
* compilation, or representation of this Software except as specified
* above is prohibited without the express written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer
* of such system or application assumes all risk of such use and in doing
* so agrees to indemnify Cypress against all liability.
*******************************************************************************/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#ifdef CY_USE_LWIP
#include "lwip/tcpip.h"
#endif
/* Demo includes */
#include "aws_demo.h"
/* AWS library includes. */
#include "iot_system_init.h"
#include "iot_logging_task.h"
#include "iot_wifi.h"
#include "aws_clientcredential.h"
#include "aws_application_version.h"
/* BSP & Abstraction inclues */
#include "cybsp.h"
#include "cy_retarget_io.h"
/* Logging Task Defines. */
#define mainLOGGING_MESSAGE_QUEUE_LENGTH ( 15 )
#define mainLOGGING_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 8 )
/* The task delay for allowing the lower priority logging task to print out Wi-Fi
* failure status before blocking indefinitely. */
#define mainLOGGING_WIFI_STATUS_DELAY pdMS_TO_TICKS( 1000 )
/* The name of the devices for xApplicationDNSQueryHook. */
#define mainDEVICE_NICK_NAME "cypress_kit"
/**
* @brief Application task startup hook for applications using Wi-Fi. If you are not
* using Wi-Fi, then start network dependent applications in the vApplicationIPNetorkEventHook
* function. If you are not using Wi-Fi, this hook can be disabled by setting
* configUSE_DAEMON_TASK_STARTUP_HOOK to 0.
*/
void vApplicationDaemonTaskStartupHook( void );
/**
* @brief Initializes the board.
*/
static void prvMiscInitialization( void );
/**
* @brief Initialize the user application.
*/
void InitApplication(void);
/*-----------------------------------------------------------*/
/**
* @brief Application runtime entry point.
*/
int main( void )
{
/* Perform any hardware initialization that does not require the RTOS to be
* running. */
prvMiscInitialization();
/* Create tasks that are not dependent on the Wi-Fi being initialized. */
xLoggingTaskInitialize( mainLOGGING_TASK_STACK_SIZE,
tskIDLE_PRIORITY,
mainLOGGING_MESSAGE_QUEUE_LENGTH );
/* Start the scheduler. Initialization that requires the OS to be running,
* including the Wi-Fi initialization, is performed in the RTOS daemon task
* startup hook. */
vTaskStartScheduler();
return 0;
}
/*-----------------------------------------------------------*/
static void prvMiscInitialization( void )
{
cy_rslt_t result = cybsp_init();
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
}
/*-----------------------------------------------------------*/
void vApplicationDaemonTaskStartupHook( void )
{
/* FIX ME: Perform any hardware initialization, that require the RTOS to be
* running, here. */
/* FIX ME: If your MCU is using Wi-Fi, delete surrounding compiler directives to
* enable the unit tests and after MQTT, Bufferpool, and Secure Sockets libraries
* have been imported into the project. If you are not using Wi-Fi, see the
* vApplicationIPNetworkEventHook function. */
if( SYSTEM_Init() == pdPASS )
{
#ifdef CY_USE_LWIP
/* Initialize lwIP stack. This needs the RTOS to be up since this function will spawn
* the tcp_ip thread.
*/
tcpip_init(NULL, NULL);
#endif
InitApplication();
}
}
/*-----------------------------------------------------------*/
/**
* @brief User defined Idle task function.
*
* @note Do not make any blocking operations in this function.
*/
void vApplicationIdleHook( void )
{
/* FIX ME. If necessary, update to application idle periodic actions. */
static TickType_t xLastPrint = 0;
TickType_t xTimeNow;
const TickType_t xPrintFrequency = pdMS_TO_TICKS( 5000 );
xTimeNow = xTaskGetTickCount();
if( ( xTimeNow - xLastPrint ) > xPrintFrequency )
{
xLastPrint = xTimeNow;
}
}
void vApplicationTickHook()
{
}
/*-----------------------------------------------------------*/
/**
* @brief User defined application hook to process names returned by the DNS server.
*/
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )
BaseType_t xApplicationDNSQueryHook( const char * pcName )
{
/* FIX ME. If necessary, update to applicable DNS name lookup actions. */
BaseType_t xReturn;
/* Determine if a name lookup is for this node. Two names are given
* to this node: that returned by pcApplicationHostnameHook() and that set
* by mainDEVICE_NICK_NAME. */
if( strcmp( pcName, pcApplicationHostnameHook() ) == 0 )
{
xReturn = pdPASS;
}
else if( strcmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */
/*-----------------------------------------------------------*/
/**
* @brief User defined assertion call. This function is plugged into configASSERT.
* See FreeRTOSConfig.h to define configASSERT to something different.
*/
void vAssertCalled(const char * pcFile,
uint32_t ulLine)
{
/* FIX ME. If necessary, update to applicable assertion routine actions. */
const uint32_t ulLongSleep = 1000UL;
volatile uint32_t ulBlockVariable = 0UL;
volatile char * pcFileName = (volatile char *)pcFile;
volatile uint32_t ulLineNumber = ulLine;
(void)pcFileName;
(void)ulLineNumber;
printf("vAssertCalled %s, %ld\n", pcFile, (long)ulLine);
fflush(stdout);
/* Setting ulBlockVariable to a non-zero value in the debugger will allow
* this function to be exited. */
taskDISABLE_INTERRUPTS();
{
while (ulBlockVariable == 0UL)
{
vTaskDelay( pdMS_TO_TICKS( ulLongSleep ) );
}
}
taskENABLE_INTERRUPTS();
}
/*-----------------------------------------------------------*/
/**
* @brief User defined application hook need by the FreeRTOS-Plus-TCP library.
*/
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
const char * pcApplicationHostnameHook(void)
{
/* FIX ME: If necessary, update to applicable registration name. */
/* This function will be called during the DHCP: the machine will be registered
* with an IP address plus this name. */
return clientcredentialIOT_THING_NAME;
}
#endif