lpc_sys.h
Go to the documentation of this file.
1 /*
2  * SocialLedge.com - Copyright (C) 2013
3  *
4  * This file is part of free software framework for embedded processors.
5  * You can use it and/or distribute it as long as this copyright header
6  * remains unmodified. The code is free for personal use and requires
7  * permission to use in a commercial product.
8  *
9  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
10  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
12  * I SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
13  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
14  *
15  * You can reach the author of this software at :
16  * p r e e t . w i k i @ g m a i l . c o m
17  */
18 
29 #ifndef LPC_SYS_H__
30 #define LPC_SYS_H__
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 #include <stdint.h>
35 #include <stdbool.h>
36 
37 #include "LPC17xx.h"
38 #include "fault_registers.h"
39 #include "rtc.h"
40 #include "sys_config.h"
41 
42 
43 
47 typedef enum {
50  boot_reset = 2,
54 } sys_boot_t;
55 
61 typedef struct
62 {
63  uint32_t used_global;
64  uint32_t used_heap;
65  uint32_t avail_heap;
66  uint32_t avail_sys;
67 
68  uint32_t num_sbrk_calls;
69  uint32_t last_sbrk_size;
70  void* last_sbrk_ptr;
72 } sys_mem_t;
73 
75 typedef void (*void_func_t)(void);
76 
78 typedef char (*char_func_t)(char);
79 
80 
81 
83 sys_boot_t sys_get_boot_type();
84 rtc_t sys_get_boot_time();
85 
95 
110 void lpc_sys_setup_system_timer(void);
111 
113 uint64_t sys_get_uptime_us(void);
114 
116 static inline uint64_t sys_get_uptime_ms(void) { return sys_get_uptime_us() / 1000; }
117 
118 
119 
127 
132 void sys_get_mem_info_str(char buffer[280]);
133 
134 
135 
141 static inline void sys_watchdog_feed()
142 {
143  LPC_WDT->WDFEED = 0xAA;
144  LPC_WDT->WDFEED = 0x55;
145 }
146 
150 static inline void sys_reboot()
151 {
157  LPC_WDT->WDFEED = 0xAA;
158  LPC_WDT->WDMOD = 0;
159 }
160 
164 static inline void sys_reboot_abnormal(void)
165 {
167  sys_reboot();
168 }
169 
173 static inline void sys_watchdog_enable()
174 {
180  LPC_WDT->WDTC = SYS_CFG_WATCHDOG_TIMEOUT_MS * 1000;
181 
186  #if(DEBUG)
187  LPC_WDT->WDMOD = 2;
188  #else
189  LPC_WDT->WDMOD = 3;
190  #endif
191  sys_watchdog_feed();
192 }
193 
194 
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 #endif /* LPC_SYS_H__ */
Cold boot (power on)
Definition: lpc_sys.h:49
This file provides access to the System&#39;s Real-time Clock that maintains time even through power-loss...
void sys_set_outchar_func(char_func_t func)
Definition: newlib_syscalls.c:62
Boot after watchdog reset after an error (or crash)
Definition: lpc_sys.h:52
char(* char_func_t)(char)
Definition: lpc_sys.h:78
This file simply provides registers that are used to detect faults. These registers should be defined...
uint64_t sys_get_uptime_us(void)
Definition: lpc_sys.cpp:103
Boot after reset condition.
Definition: lpc_sys.h:50
#define FAULT_PRESENT_VAL
Value loaded to FAULT_EXISTS upon a crash.
Definition: fault_registers.h:33
void sys_get_mem_info_str(char buffer[280])
Definition: lpc_sys.cpp:219
Boot after under-voltage.
Definition: lpc_sys.h:53
This file provides the configurable parameters for your project.
uint32_t avail_sys
Memory available to Heap (from sbrk function)
Definition: lpc_sys.h:66
void * last_sbrk_ptr
Last pointer given by the sbrk() function.
Definition: lpc_sys.h:70
CMSIS Cortex-M3 Core Peripheral Access Layer Header File for NXP LPC17xx Device Series.
uint32_t avail_heap
Memory available at Heap.
Definition: lpc_sys.h:65
sys_mem_t sys_get_mem_info()
Definition: memory.cpp:109
sys_boot_t
Definition: lpc_sys.h:47
void sys_set_inchar_func(char_func_t func)
Definition: newlib_syscalls.c:66
void * next_malloc_ptr
The next pointer that will be returned to malloc() from sbrk()
Definition: lpc_sys.h:71
void(* void_func_t)(void)
Definition: lpc_sys.h:75
uint32_t last_sbrk_size
Last size requested from the sbrk() function.
Definition: lpc_sys.h:69
uint32_t used_global
Global Memory allocated.
Definition: lpc_sys.h:63
#define FAULT_EXISTS
Fault flag is stored here.
Definition: fault_registers.h:35
#define SYS_CFG_WATCHDOG_TIMEOUT_MS
Definition: sys_config.h:89
To use the FreeRTOS so play with it a little *uses roughly of and uses roughly of RAM *The larger the the larger recording buffer *You can choose ring buffer
Definition: readme.txt:4
Definition: lpc_sys.h:61
uint32_t num_sbrk_calls
Number of calls to the sbrk() function.
Definition: lpc_sys.h:68
Definition: lpc_sys.h:48
sys_boot_t sys_get_boot_type()
Definition: low_level_init.cpp:121
Boot after watchdog reset (intentional)
Definition: lpc_sys.h:51
void lpc_sys_setup_system_timer(void)
Definition: lpc_sys.cpp:53
uint32_t used_heap
Memory granted by Heap (malloc, new etc.)
Definition: lpc_sys.h:64
#define LPC_WDT
Definition: LPC17xx.h:1010
rtc_t sys_get_boot_time()
Definition: low_level_init.cpp:125