-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
257 lines (232 loc) · 7.74 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
/********************************************************************
* Copyright Simcom(shanghai)co. Ltd. *
*---------------------------------------------------------------------
* FileName : app_demo_timer.c
* version : 0.10
* Description :
* Authors : maobin
* Notes :
*---------------------------------------------------------------------
*
* HISTORY OF CHANGES
*---------------------------------------------------------------------
*0.10 2012-09-24, maobin, create originally.
*
*--------------------------------------------------------------------
* File Description
* AT+CEAT=parma1,param2
* param1 param2
* 1 1 Test millisecond level timer, Start timer1 timer2 timer3
* 1 2 Stop timer1, timer2, timer3
*
* 2 1 Test microsecond level timer, Start gpt timer
* 2 2 Stop gpt timer
*
* 3 1 Get elapsed time from the boot to the present
* 3 2 Get time interval with the last time
*
* 4 1 Test RTC, get current rtc value
* 4 2 Set rtc value
*
*--------------------------------------------------------------------
********************************************************************/
/********************************************************************
* Include Files
********************************************************************/
#include <stdio.h>
#include <string.h>
#include "eat_modem.h"
#include "eat_interface.h"
#include "eat_uart.h"
#include "eat_timer.h"
#include "eat_socket.h"
#include "eat_clib_define.h" //only in main.c
#include "app_at_cmd_envelope.h"
#include "inc.h"
/********************************************************************
* Macros
********************************************************************/
#define EAT_UART_RX_BUF_LEN_MAX 2048
#define EAT_MEM_MAX_SIZE 10*1024//100*1024
/********************************************************************
* Types
********************************************************************/
typedef void (*app_user_func)(void*);
/********************************************************************
* Extern Variables (Extern /Global)
********************************************************************/
/********************************************************************
* Local Variables: STATIC
********************************************************************/
//static u8 rx_buf[EAT_UART_RX_BUF_LEN_MAX + 1] = {0};
//static u32 gpt_timer_counter = 0;
//static u32 time1 = 0;
static u8 s_memPool[EAT_MEM_MAX_SIZE];
//static s8 socket_id = 0;
/********************************************************************
* External Functions declaration
********************************************************************/
extern void APP_InitRegions(void);
/********************************************************************
* Local Function declaration
********************************************************************/
void app_main(void *data);
void app_func_ext1(void *data);
extern void app_at_cmd_envelope(void *data);
/********************************************************************
* Local Function
********************************************************************/
#pragma arm section rodata = "APP_CFG"
APP_ENTRY_FLAG
#pragma arm section rodata
#pragma arm section rodata="APPENTRY"
const EatEntry_st AppEntry =
{
app_main,
app_func_ext1,
(app_user_func)app_at_cmd_envelope,//app_user1,
(app_user_func)EAT_NULL,//app_user2,
(app_user_func)EAT_NULL,//app_user3,
(app_user_func)EAT_NULL,//app_user4,
(app_user_func)EAT_NULL,//app_user5,
(app_user_func)EAT_NULL,//app_user6,
(app_user_func)EAT_NULL,//app_user7,
(app_user_func)EAT_NULL,//app_user8,
EAT_NULL,
EAT_NULL,
EAT_NULL,
EAT_NULL,
EAT_NULL,
EAT_NULL
};
#pragma arm section rodata
void app_func_ext1(void *data)
{
/*This function can be called before Task running ,configure the GPIO,uart and etc.
Only these api can be used:
eat_uart_set_debug: set debug port
eat_pin_set_mode: set GPIO mode
eat_uart_set_at_port: set AT port
*/
eat_uart_set_debug(EAT_UART_1);
eat_uart_set_at_port(EAT_UART_2);// UART1 is as AT PORT
}
static u8 buf[64] = {0};
/*
* core initialization is ok?
* check wether core return "Call Ready" // and "SMS Ready"
* core_init==1,true; otherwise,false
*/
typedef u8 core_init_t;
eat_bool core_is_ready(const char * str)
{
static core_init_t core_init = 0;
const char * p = str;
const char * pStr[]={"Call Ready","SMS Ready"};
while(p){
while(AT_CMD_CR == *p || AT_CMD_LF == *p)
{
p++;
}
if(!strncmp(pStr[0],p,strlen(pStr[0]))) /*call ready */
core_init++; // +1
p = (char *)strchr(p,AT_CMD_LF);
}
if(1 == core_init)
{
core_init = 0;
return EAT_TRUE;
}
else
return EAT_FALSE;
}
void app_main(void *data)
{
EatEvent_st event;
u16 len = 0;
EatUartConfig_st uart_config;
eat_bool ret;
APP_InitRegions();//Init app RAM
APP_init_clib(); //C library initialize, second step
#if 0
if(eat_uart_open(EAT_UART_1 ) == EAT_FALSE)
{
eat_trace("[%s] uart(%d) open fail!", __FUNCTION__, EAT_UART_1);
}
uart_config.baud = EAT_UART_BAUD_115200;
uart_config.dataBits = EAT_UART_DATA_BITS_8;
uart_config.parity = EAT_UART_PARITY_NONE;
uart_config.stopBits = EAT_UART_STOP_BITS_1;
if(EAT_FALSE == eat_uart_set_config(EAT_UART_1, &uart_config))
{
eat_trace("[%s] uart(%d) set config fail!", __FUNCTION__, EAT_UART_1);
}
#endif
log_0("app_main ENTRY");
Gpio_init();
ret = eat_mem_init(s_memPool,EAT_MEM_MAX_SIZE);
if (!ret)
log_0("ERROR: eat memory initial error!");
eat_timer_start(TIMER_SOFT_RESET,600000);
at_cluster();
while(EAT_TRUE)
{
eat_get_event(&event);
log_2("MSG id%x", event.event);
switch(event.event)
{
case EAT_EVENT_TIMER :
{
EatTimer_enum timer_id = event.data.timer.timer_id;
timer_hdlr(timer_id);
}
break;
case EAT_EVENT_INT :
log_0("INTERRUPT IS COMING");
if(get_key())/*donw = 1 */
key_hdlr();
break;
case EAT_EVENT_USER_MSG:
{
u8 data = event.data.user_msg.data[0];
set_debounce(data);
}
break;
case EAT_EVENT_KEY:
{
eat_bool press = event.data.key.is_pressed;
log_0("power key");
pwrkey_hdlr(press);
}
break;
case EAT_EVENT_MDM_READY_WR:
break;
case EAT_EVENT_UART_READY_RD:
log_2("EAT_EVENT_UART_READY_RD");
break;
case EAT_EVENT_MDM_READY_RD:
{
len = 0;
/* boot info(such as:RDY ;+CFUN: 1 ;+CPIN: READY)
* will be sent to here(main task);
*/
len = eat_modem_read(buf, 2048); /*necessary:Read it out*/
buf[len] = 0;
log_2("main task buf (%s)",buf);
#if 0
if(core_is_ready(buf))
{
eat_trace("core is ready");
eat_timer_start(TIMER_SOFT_RESET,600000);
at_cluster();
}
#endif
}
break;
case EAT_EVENT_UART_SEND_COMPLETE :
break;
default:
break;
}
}
}