This repository has been archived by the owner on Dec 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
81 lines (64 loc) · 2.32 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
#include "LPC43xx.h" // Device header
#include "cmsis_os.h" // ARM::CMSIS:RTOS:Keil RTX
#include "rl_net.h" // Keil.MDK-Pro::Network:CORE
#ifdef RTE_Network_Interface_PPP
extern int Init_CommunicationThread(void);
extern osThreadId tid_CommunicationThread;
#endif
extern int Init_TLSThread(void);
extern osThreadId tid_TLSThread;
int main(void) {
osKernelInitialize(); // Initialize CMSIS-RTOS
SystemCoreClockUpdate(); // Update the clock variable in case we need it
#ifdef RTE_Network_Interface_PPP
netInitialize(); // Initialize the network stack
osDelay(500); // Allow the network stack to be initialized
// Init_CommunicationThread();
#endif
Init_TLSThread();
osKernelStart(); // Start thread execution
// Signal the communication thread after 5 seconds of running
// This functionality can be replaced by an kind of interrupt
// example: RTC wakeup alarm, button press, physical timer timeout etc.
osDelay(5000);
#ifdef RTE_Network_Interface_PPP
// osSignalSet(tid_CommunicationThread, 0x01);
#endif
osSignalSet(tid_TLSThread, 0x01);
}
uint32_t get_time_since_epoch(void) {
return 1457456116;//TODO: change this to read from RTC module and convert to epoch
}
#include "stdio.h"
void hex_dump(FILE* f, void *addr, int len) {
int i;
unsigned char buff[17];
unsigned char *pc = (unsigned char*)addr;
if (len == 0 || len < 0) return;
// Process every byte in the data.
for (i = 0; i < len; i++) {
// Multiple of 16 means new line (with line offset).
if ((i % 16) == 0) {
// Just don't print ASCII for the zeroth line.
if (i != 0)
fprintf(f, " %s\n", buff);
// Output the offset.
fprintf(f, " %04x: ", i);
}
// Now the hex code for the specific character.
fprintf(f, " %02x", pc[i]);
// And store a printable ASCII character for later.
if ((pc[i] < 0x20) || (pc[i] > 0x7e))
buff[i % 16] = '.';
else
buff[i % 16] = pc[i];
buff[(i % 16) + 1] = '\0';
}
// Pad out last line if not exactly 16 characters.
while ((i % 16) != 0) {
fprintf(f, " ");
i++;
}
// And print the final ASCII bit.
printf (" %s\n", buff);
}