-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
302 lines (245 loc) · 6.91 KB
/
Copy pathmain.c
File metadata and controls
302 lines (245 loc) · 6.91 KB
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* ACRONET Project
* http://www.acronet.cc
*
* Copyright ( C ) 2014 Acrotec srl
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the EUPL v.1.1 license. See http://ec.europa.eu/idabc/eupl.html for details.
*/
#include "Acronet/setup.h"
#include "Acronet/HAL/hal_interface.h"
#include "asf.h"
#include <stdio.h>
#include "calendar.h"
#include <conf_usart_serial.h>
#include "config/conf_usart_serial.h"
#include "Acronet/globals.h"
#include "Acronet/datalogger/datalogger.h"
//
//#include "Acronet/drivers/StatusLED/status_led.h"
#include "Acronet/drivers/PowerSwitch/powerswitch.h"
//#include "Acronet/drivers/SIM/sim900.h"
//
//#include "Acronet/services/taskman/taskman.h"
//#include "Acronet/services/config/config.h"
//
//#include "Acronet/drivers/SP336/SP336.h"
//
//#include "Acronet/Sensors/raingauge/pulse_raingauge.h"
//#include "Acronet/Sensors/LB150/LB150.h"
//#include "Acronet/Sensors/MBXXXX/MBXXXX.h"
//
//#include "Acronet/services/CAP/cap_common.h"
//
//
//#include "Acronet/setup.h"
//#include "Acronet/services/DB/DB.h"
static void simple_logger_test(void);
int main (void)
{
//Setting this variable we can decide the amount of info to send
//at the Debug facility. Compiling the firmware in Release may
//disable it
g_log_verbosity = VERBOSE; //NORMAL;
/* Initialize the board.
* The board-specific conf_board.h file contains the configuration of
* the board initialization.
*/
sleepmgr_init();
sysclk_init();
board_init();
//VBusMon_init();
pmic_init();
pmic_set_scheduling(PMIC_SCH_ROUND_ROBIN);
pmic_set_vector_location(PMIC_VEC_APPLICATION);
powerSwitch_init();
//Enables the Event module
sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_EVSYS);
//After that the Debug facilty has been configured
//report the Power On event on it
debug_string_1P(NORMAL,PSTR ("\r\n\r\n****************** POWER ON ******************"));
if(g_log_verbosity>=NORMAL) {
debug_string(NORMAL,PSTR ("MCU Revision : "),PGM_STRING);
usart_putchar(USART_DEBUG,'A'+(MCU.REVID & 0x0F));
debug_string(NORMAL,g_szCRLF,true);
}
////Initialize the RTC
////// Workaround for known issue: Enable RTC32 sysclk
//sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
//while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm) {
////// Wait for RTC32 sysclk to become stable
//}
//
////sysclk_rtcsrc_enable(SYSCLK_RTCSRC_TOSC32);
//
//
//rtc_init();
debug_string_1P(NORMAL,PSTR("\r\n\r\nBUILD VERSION : "));
debug_string_1P(NORMAL,g_szGIT_TAG);
debug_string_1P(NORMAL,PSTR("\r\nFW CONFIGURATION : "));
debug_string_1P(NORMAL,g_szPRJ_TAG);
hal_rtc_init();
debug_string(NORMAL,PSTR("\r\nEnabling oscillator for DFLL\r\n"),PGM_STRING);
irqflags_t flags = cpu_irq_save();
OSC.XOSCCTRL |= 0x02;
OSC.CTRL |= 0x08;
do {} while (!(OSC.STATUS & 0x08));
cpu_irq_restore(flags);
osc_enable_autocalibration(OSC_ID_RC32MHZ,OSC_ID_XOSC);
cpu_irq_enable();
debug_string(NORMAL,PSTR("oscillator OK\r\n"),PGM_STRING);
//the code in the DEBUG definition block is
//here just for testing purposes
#ifdef DEBUG
char buf[64];
debug_string(NORMAL,PSTR("\r\nsizeof(void *) = "),PGM_STRING);
itoa(sizeof(void *),buf,10);
debug_string(NORMAL,buf,RAM_STRING);
debug_string(NORMAL,PSTR("\r\nsizeof(flash_addr_t) = "),PGM_STRING);
itoa(sizeof(flash_addr_t),buf,10);
debug_string(NORMAL,buf,RAM_STRING);
//#ifndef SIM900_USART_POLLED
//debug_string(NORMAL,PSTR ("\r\nSince you compiled in DEBUG we start the GPRS UART in main\r\n"),true);
//usart_interruptdriver_initialize(&sim900_usart_data,USART_GPRS,USART_INT_LVL_LO);
////usart_set_dre_interrupt_level(USART_SERIAL_GPRS,USART_INT_LVL_LO);
//usart_set_rx_interrupt_level(USART_GPRS,USART_INT_LVL_LO);
//usart_set_tx_interrupt_level(USART_GPRS,USART_INT_LVL_OFF);
//#endif
#endif
hal_PCALXXXX_Init();
simple_logger_test();
#if 1
if(0==dl_init()) {
dl_run();
}
#else
dl_dump_db2();
#endif
while (1)
{
gpio_toggle_pin(STATUS_LED_PIN);
delay_ms(500);
}
}
static void simple_logger_test(void)
{
return;
uint8_t buf[32];
char sz[128];
const uint8_t ibeg = '1';
const uint8_t iend = ':';
uint8_t i;
for(i = ibeg;i<iend;i++) {
buf[i-ibeg]=i;
}
buf[iend-ibeg] = 0;
int l = iend-ibeg;
uint32_t iv = 0xFFFFFFFF;
crc_set_initial_value(iv);
uint32_t v = crc_io_checksum(buf,l,CRC_32BIT);
sprintf_P(sz,PSTR("%s -> %d -> %lX\r\n"),buf,l,v);
debug_string(NORMAL,sz,RAM_STRING);
while (1)
{
gpio_toggle_pin(STATUS_LED_PIN);
delay_ms(500);
}
return;
}
//#define SWITCH_PIN IOPORT_CREATE_PIN(PORTD, 1)
//
//#define UART_IRIDIUM_9602 &USARTD1
//#define UART_TX_IRIDIUM_9602 IOPORT_CREATE_PIN(PORTD,7)
//#define UART_RX_IRIDIUM_9602 IOPORT_CREATE_PIN(PORTD,6)
//
//static void simple_logger_test(void)
//{
//return;
//
//char szBUF[128];
//cfg_get_gprs_apn("vodafone IT",szBUF,64);
//debug_string(NORMAL,szBUF,RAM_STRING);
//debug_string_P(NORMAL,g_szCRLF);
//
//cfg_get_gprs_apn("I TIM",szBUF,64);
//debug_string(NORMAL,szBUF,RAM_STRING);
//debug_string_P(NORMAL,g_szCRLF);
//
//cfg_get_gprs_apn("ok",szBUF,64);
//debug_string(NORMAL,szBUF,RAM_STRING);
//debug_string_P(NORMAL,g_szCRLF);
//
//cfg_get_gprs_apn("vodafone IT",szBUF,64);
//debug_string(NORMAL,szBUF,RAM_STRING);
//debug_string_P(NORMAL,g_szCRLF);
//
//
//while(1) {
//delay_ms(1500);
//gpio_toggle_pin(SWITCH_PIN);// ioport_configure_pin(SWITCH_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
//status_led_toggle();
//}
//
//return;
//
//ioport_configure_pin(UART_TX_IRIDIUM_9602, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
//ioport_configure_pin(UART_RX_IRIDIUM_9602, IOPORT_DIR_INPUT);
//
//// USART options.
//const usart_rs232_options_t USART_SERIAL_OPTIONS = {
//.baudrate = 19200,
//.charlength = USART_CHAR_LENGTH,
//.paritytype = USART_PARITY,
//.stopbits = USART_STOP_BIT
//};
//
//
////Configure the Debug facilty
//sysclk_enable_module(SYSCLK_PORT_D,PR_USART1_bm);
//usart_init_rs232(UART_IRIDIUM_9602, &USART_SERIAL_OPTIONS);
//
//usart_set_rx_interrupt_level(UART_IRIDIUM_9602,USART_INT_LVL_LO);
//usart_set_tx_interrupt_level(UART_IRIDIUM_9602,USART_INT_LVL_OFF);
//
//usart_rx_enable(UART_IRIDIUM_9602);
//usart_tx_enable(UART_IRIDIUM_9602);
//
//
//
//
//delay_s(5);
//
//while(1) {
//usart_putchar(UART_IRIDIUM_9602,'A');
//usart_putchar(UART_IRIDIUM_9602,'T');
//usart_putchar(UART_IRIDIUM_9602,'\r');
//usart_putchar(UART_IRIDIUM_9602,'\n');
//delay_ms(2000);
//}
//
//
//return;
//ioport_configure_pin(SWITCH_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
//while(1) {
//delay_ms(1500);
//gpio_toggle_pin(SWITCH_PIN);// ioport_configure_pin(SWITCH_PIN, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
//status_led_toggle();
//}
////
////
//// return;
//powerSwitch_init();
//powerSwitch_toggle();
//delay_ms(5000);
//MBXXXX_init();
//MBXXXX_enable();
//while(1) { MBXXXX_Yield();gpio_toggle_pin(STATUS_LED_PIN);delay_ms(100); }
//}
/*
ISR(USARTD1_RXC_vect)
{
usart_putchar(USART_DEBUG,usart_getchar(&USARTD1));
}
*/