Skip to content

Commit a4fadf2

Browse files
committed
example: freertos: add esp8266_wifi example
Signed-off-by: Watson Zeng <[email protected]>
1 parent 27ae498 commit a4fadf2

File tree

8 files changed

+996
-1
lines changed

8 files changed

+996
-1
lines changed

board/iotdk/common/iotdk_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
static void iotdk_mux_init(void)
6363
{
64-
pmode_mux_config(PMA_GPIO | PMB_SPI | PMC_GPIO);
64+
pmode_mux_config(PMA_GPIO | PMB_SPI | PMC_UART);
6565
arduino_pin_mux(ARDUINO_A4, ARDUINO_FUNC_2ND);
6666
}
6767

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd.
3+
All rights reserved
4+
5+
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6+
7+
***************************************************************************
8+
* *
9+
* FreeRTOS provides completely free yet professionally developed, *
10+
* robust, strictly quality controlled, supported, and cross *
11+
* platform software that has become a de facto standard. *
12+
* *
13+
* Help yourself get started quickly and support the FreeRTOS *
14+
* project by purchasing a FreeRTOS tutorial book, reference *
15+
* manual, or both from: http://www.FreeRTOS.org/Documentation *
16+
* *
17+
* Thank you! *
18+
* *
19+
***************************************************************************
20+
21+
This file is part of the FreeRTOS distribution.
22+
23+
FreeRTOS is free software; you can redistribute it and/or modify it under
24+
the terms of the GNU General Public License (version 2) as published by the
25+
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
26+
27+
>>! NOTE: The modification to the GPL is included to allow you to distribute
28+
>>! a combined work that includes FreeRTOS without being obliged to provide
29+
>>! the source code for proprietary components outside of the FreeRTOS
30+
>>! kernel.
31+
32+
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
33+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34+
FOR A PARTICULAR PURPOSE. Full license text is available from the following
35+
link: http://www.freertos.org/a00114.html
36+
37+
1 tab == 4 spaces!
38+
39+
***************************************************************************
40+
* *
41+
* Having a problem? Start by reading the FAQ "My application does *
42+
* not run, what could be wrong?" *
43+
* *
44+
* http://www.FreeRTOS.org/FAQHelp.html *
45+
* *
46+
***************************************************************************
47+
48+
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
49+
license and Real Time Engineers Ltd. contact details.
50+
51+
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
52+
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
53+
compatible FAT file system, and our tiny thread aware UDP/IP stack.
54+
55+
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
56+
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
57+
licenses offer ticketed support, indemnification and middleware.
58+
59+
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
60+
engineered and independently SIL3 certified version for use in safety and
61+
mission critical applications that require provable dependability.
62+
63+
1 tab == 4 spaces!
64+
*/
65+
66+
#ifndef FREERTOS_CONFIG_H
67+
#define FREERTOS_CONFIG_H
68+
69+
#include <stdio.h>
70+
/*-----------------------------------------------------------
71+
* Application specific definitions.
72+
*
73+
* These definitions should be adjusted for your particular hardware and
74+
* application requirements.
75+
*
76+
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
77+
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
78+
*
79+
* See http://www.freertos.org/a00110.html.
80+
*----------------------------------------------------------*/
81+
82+
#define configUSE_PREEMPTION 1
83+
#define configUSE_IDLE_HOOK 0
84+
#define configUSE_TICK_HOOK 0
85+
#define configCPU_CLOCK_HZ ( ( unsigned long ) BOARD_CPU_CLOCK )
86+
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
87+
#define configMAX_PRIORITIES ( 10 )
88+
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 104 )
89+
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 16 * 1024 ) )
90+
#define configMAX_TASK_NAME_LEN ( 10 )
91+
#define configUSE_TRACE_FACILITY 0
92+
#define configUSE_16_BIT_TICKS 0
93+
#define configIDLE_SHOULD_YIELD 1
94+
#define configUSE_MUTEXES 1
95+
96+
/* Co-routine definitions. */
97+
#define configUSE_CO_ROUTINES 0
98+
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
99+
100+
101+
/* Set the following definitions to 1 to include the API function, or zero
102+
to exclude the API function. */
103+
104+
#define INCLUDE_vTaskPrioritySet 1
105+
#define INCLUDE_uxTaskPriorityGet 1
106+
#define INCLUDE_vTaskDelete 1
107+
#define INCLUDE_vTaskCleanUpResources 0
108+
#define INCLUDE_vTaskSuspend 1
109+
#define INCLUDE_vTaskDelayUntil 1
110+
#define INCLUDE_vTaskDelay 1
111+
#define INCLUDE_xTaskGetCurrentTaskHandle 1
112+
113+
#endif /* FREERTOS_CONFIG_H */
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/* ------------------------------------------
2+
* Copyright (c) 2018, Synopsys, Inc. All rights reserved.
3+
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
7+
* 1) Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
10+
* 2) Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
14+
* 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
15+
* be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
--------------------------------------------- */
30+
31+
#include "embARC_error.h"
32+
#include "string.h"
33+
#include "board.h"
34+
#include "at_parser.h"
35+
//#include "embARC_error.h"
36+
37+
#define DBG_MORE
38+
#include "embARC_debug.h"
39+
40+
/* if \r\n is needed to be attached at the end of AT comand, define AT_ADD_POSTFIX
41+
* otherwise comment out this line
42+
*/
43+
#define AT_ADD_POSTFIX
44+
45+
#define AT_PREFIX "AT"
46+
#define AT_POSTFIX "\r\n"
47+
48+
#define AT_TIMENOW() OSP_GET_CUR_MS()
49+
50+
#define AT_MAX_LEN 128
51+
#define AT_MAX_PARAMETER 8
52+
53+
54+
int32_t at_parser_init(AT_PARSER_DEF_PTR obj, uint32_t baudrate){
55+
obj->psio = ez_sio_open(obj->uart_id, baudrate, AT_TX_BUFSIZE, AT_RX_BUFSIZE);
56+
dbg_printf(DBG_MORE_INFO, "[%s]%d: obj->psio 0x%x -> 0x%x\r\n", __FUNCTION__, __LINE__, obj->psio, *obj->psio);
57+
return (obj->psio != NULL) ? AT_OK : AT_ERROR;
58+
}
59+
60+
void at_parser_deinit(AT_PARSER_DEF_PTR obj){
61+
ez_sio_close(obj->psio);
62+
return;
63+
}
64+
65+
int32_t at_read(AT_PARSER_DEF_PTR obj, char *buf, uint32_t cnt)
66+
{
67+
return ez_sio_read(obj->psio, buf, cnt);
68+
}
69+
70+
int32_t at_write(AT_PARSER_DEF_PTR obj, char *buf, uint32_t cnt)
71+
{
72+
return ez_sio_write(obj->psio, buf, cnt);
73+
}
74+
75+
/*
76+
* please use NULL as last parameter
77+
*/
78+
int32_t at_send_cmd(AT_PARSER_DEF_PTR obj, AT_MODE mode, AT_STRING command, ...){
79+
va_list vl;
80+
char at_out[AT_MAX_LEN] = AT_PREFIX;
81+
char * str = command;
82+
if(str == NULL){
83+
dbg_printf(DBG_MORE_INFO, "[%s]%d: command is NULL, send AT test command\r\n", __FUNCTION__, __LINE__);
84+
} else {
85+
strcat(at_out,"+");
86+
strcat(at_out, command);
87+
switch(mode){
88+
case AT_LIST:
89+
strcat(at_out, "=?");
90+
break;
91+
case AT_READ:
92+
strcat(at_out, "?");
93+
break;
94+
case AT_WRITE:
95+
strcat(at_out, "=");
96+
va_start(vl, command);
97+
for(int i = 0; i < AT_MAX_PARAMETER; i++){
98+
str = va_arg(vl, AT_STRING);
99+
if(str == NULL){
100+
break;
101+
}
102+
if(i != 0){
103+
strcat(at_out, ",");
104+
}
105+
strcat(at_out, str);
106+
}
107+
va_end(vl);
108+
break;
109+
case AT_EXECUTE:
110+
default:
111+
break;
112+
}
113+
}
114+
#ifdef AT_ADD_POSTFIX
115+
strcat(at_out, AT_POSTFIX);
116+
#endif /*AT_ADD_POSTFIX*/
117+
dbg_printf(DBG_LESS_INFO, "[%s]%d: at_out: \"%s\" (%d)\r\n", __FUNCTION__, __LINE__, at_out, strlen(at_out));
118+
return at_write(obj, at_out, strlen(at_out));
119+
}
120+
121+
/* make sure the buf is large enough*/
122+
int32_t at_get_reply(AT_PARSER_DEF_PTR obj, char *buf, uint32_t timeout)
123+
{
124+
uint32_t cur_ofs = 0;
125+
uint32_t read_cnt;
126+
uint32_t cur_time;
127+
cur_time = AT_TIMENOW();
128+
do {
129+
read_cnt = at_read(obj, &buf[cur_ofs], 1);
130+
cur_ofs += read_cnt;
131+
buf[cur_ofs] = '\0';
132+
if ((strstr(buf, AT_OK_STR)!= NULL) || (strstr(buf, AT_ERROR_STR)!= NULL)){
133+
break;
134+
}
135+
} while((AT_TIMENOW()-cur_time) < timeout);
136+
buf[cur_ofs] = '\0';
137+
dbg_printf(DBG_LESS_INFO, "[%s]%d: \"%s\" (%d)\r\n", __FUNCTION__, __LINE__, buf, strlen(buf));
138+
if (strstr(buf, AT_OK_STR)!= NULL){
139+
return AT_OK;
140+
}
141+
return AT_ERROR;
142+
}
143+
144+
int32_t at_test(AT_PARSER_DEF_PTR obj){
145+
char rcv_buf[64];
146+
at_send_cmd(obj, AT_LIST, NULL);
147+
return at_get_reply(obj, rcv_buf, AT_NORMAL_TIMEOUT);
148+
}
149+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* ------------------------------------------
2+
* Copyright (c) 2018, Synopsys, Inc. All rights reserved.
3+
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
7+
* 1) Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
10+
* 2) Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
14+
* 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
15+
* be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
--------------------------------------------- */
30+
31+
#ifndef _AT_PARSER_H_
32+
#define _AT_PARSER_H_
33+
34+
#include "ez_sio.h"
35+
#include "embARC_error.h"
36+
37+
#define AT_OK 0
38+
#define AT_ERROR -1
39+
#define AT_OK_STR "OK"
40+
#define AT_ERROR_STR "ERROR"
41+
42+
#define AT_RX_BUFSIZE 512
43+
#define AT_TX_BUFSIZE 128
44+
45+
#define AT_NORMAL_TIMEOUT 100
46+
#define AT_LONG_TIMEOUT 5000
47+
#define AT_EXTRA_TIMEOUT 20000
48+
49+
typedef enum {
50+
AT_LIST,
51+
AT_READ,
52+
AT_WRITE,
53+
AT_EXECUTE
54+
}AT_MODE;
55+
56+
typedef char * AT_STRING;
57+
58+
/** HM1X object type */
59+
typedef struct {
60+
uint32_t uart_id;
61+
EZ_SIO *psio;
62+
} AT_PARSER_DEF, *AT_PARSER_DEF_PTR;
63+
64+
#define AT_PARSER_DEFINE(NAME, UART_ID) \
65+
AT_PARSER_DEF __ ## NAME = { \
66+
.uart_id = UART_ID, \
67+
.psio = NULL, \
68+
}; \
69+
AT_PARSER_DEF_PTR NAME = &__ ## NAME
70+
71+
int32_t at_parser_init(AT_PARSER_DEF_PTR obj, uint32_t baudrate);
72+
void at_parser_deinit(AT_PARSER_DEF_PTR obj);
73+
int32_t at_read(AT_PARSER_DEF_PTR obj, char *buf, uint32_t cnt);
74+
int32_t at_write(AT_PARSER_DEF_PTR obj, char *buf, uint32_t cnt);
75+
int32_t at_send_cmd(AT_PARSER_DEF_PTR obj, AT_MODE mode, AT_STRING command, ...);
76+
int32_t at_get_reply(AT_PARSER_DEF_PTR obj, char *buf, uint32_t timeout);
77+
78+
int32_t at_test(AT_PARSER_DEF_PTR obj);
79+
80+
#endif /*_AT_PARSER_H_*/

0 commit comments

Comments
 (0)