NetBurner 3.5.0
PDF Version
 
hal.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
23#ifndef _NB_HAL_H_
24#define _NB_HAL_H_
25
26#include <stdint.h>
27
28#if defined(NB_SSL_SUPPORTED) || defined(NB_SSH_SUPPORTED)
29// SSL For Hashing Certs
30#include <crypto/ssl.h>
31#include <crypto/wolfssl/ssl.h>
32#endif /* defined(NB_SSL_SUPPORTED) || defined(NB_SSH_SUPPORTED) */
33
34enum HalStorage_t
35{
36 HalStore_Config = 0x01,
37 HalStore_Cert = 0x02,
38 HalStore_UserParams = 0x03,
39 HalStore_App = 0x04,
40 HalStore_FileSys = 0xFC
41};
42
43enum HalError_t : int
44{
45 HALSTORE_NO_ERROR = 0,
46 HALSTORE_ERR_UNKNOWN = -1,
47 HALSTORE_BADARG = -2,
48 HALSTORE_TOOBIG = -3,
49 HALSTORE_NOTSUPPORTED = -4,
50 HALSTORE_NOTAVAILABLE = -5,
51 HALSTORE_NOTREADY = -6,
52};
53
59
65
70void ForceReboot(bool bFromException = false) __attribute__((noreturn));
71
86int HalStorage_Save(uint8_t area, void *pData, int len, int offset = 0);
87
102int HalStorage_SavePartial(uint8_t area, void *pData, int len, int offset);
103
114int HalStorage_Prepare(uint8_t area, int len, int offset = 0);
115
125int HalStorage_Finalize(uint8_t area);
126
140int HalStorage_Erase(uint8_t area, int len = -1, int offset = 0);
141
149int HalStorage_GetAllocated(uint8_t area);
150
161
171
180int HalStorage_WriteOffset(uint8_t area);
181
193int HalStorage_AddressOffset(uint8_t area, void *pWhere);
194
202void FlashErase(void *pWhere, int len);
203
212void FlashProgram(void *pWhere, void *pWhat, int len);
213
226void FlashProgramAppImage(void *pWhere, void *pWhat, int len);
227
233
239
245uint32_t spaceleft();
246
258extern void (*watchdog_service_function)(void);
259
266extern uint16_t HalGetTickFraction(void);
267
268#ifdef GATHER_RANDOM_USE_HW
275extern bool HalHWRandRdy(void);
276
282extern uint32_t HalGetHWRand32(void);
283#endif
284
290extern uint32_t HalTickMaxCount;
291
302void StdioCheckIntc(void);
303
310
311#if defined(NB_SSL_SUPPORTED) || defined(NB_SSH_SUPPORTED)
312
325
326// TODO: Should there be a HalDeviceKeyValid() ?
327
336
346
355
365
366
367uint16_t HalGetDeviceFormat();
368
379bool HalSaveNewDeviceCert(const uint8_t *cert, uint16_t certlen, uint8_t format = SSL_FILETYPE_PEM);
380
391bool HalSaveNewDeviceKey(const uint8_t *key, uint16_t keylen, uint8_t format = SSL_FILETYPE_PEM);
392
400#endif /* defined(NB_SSL_SUPPORTED) || defined(NB_SSH_SUPPORTED) */
401
402#endif /* _NB_HAL_H_ */
403
int HalStorage_WriteOffset(uint8_t area)
Get the offset of the next byte that can be written in the given persistent storage area.
uint16_t HalGetDeviceCertLen()
Get the length of the stored certificate.
void FlashProgramAppImage(void *pWhere, void *pWhat, int len)
Write an application image to flash memory.
void HalEraseDeviceCertAndKey()
Clear the device certificate and key from persistent storage.
bool HalSaveNewDeviceCert(const uint8_t *cert, uint16_t certlen, uint8_t format=SSL_FILETYPE_PEM)
Save a device certificate in persistent storage.
uint32_t spaceleft()
Report how much free unallocated space is left in dynamic memory.
void DisableCache()
Disable the instruction and data cache.
int HalStorage_GetMaxAllocation(uint8_t area)
Obtain the maximum size that may be allocated to the given persistent storage area....
int HalStorage_Prepare(uint8_t area, int len, int offset=0)
Prepare a storage area for writing new data. For platforms with direct flash mapping this function is...
void EnableCache()
Enable the instruction and data cache.
void FlashErase(void *pWhere, int len)
Erases the flash memory.
int HalStorage_Erase(uint8_t area, int len=-1, int offset=0)
Erase all or part of a storage area. Note: due to physical storage granularities, the total area eras...
bool HalDeviceCertValid()
Determine if the stored certificate is valid.
bool HalSaveNewDeviceKey(const uint8_t *key, uint16_t keylen, uint8_t format=SSL_FILETYPE_PEM)
Save a device key in persistent storage.
void HardwareSetup()
Initializes the system hardware such as the timer, cache and clock speed.
int HalStorage_Save(uint8_t area, void *pData, int len, int offset=0)
Save a blob to a specific persistent storage area as defined by the platform. This routine will perfo...
void(* watchdog_service_function)(void)
Watchdog callback service function.
uint8_t * HalGetDeviceCert()
Get a pointer to the stored certificate.
int HalStorage_Finalize(uint8_t area)
Finalize a storage area after writing new data. This will perform any final completion or cleanup rou...
int HalStorage_GetAllocated(uint8_t area)
Obtain the total size allocated to the given persistent storage area.
void SysLogCheckIntc(void)
This is just like the StdioCheckIntc() function, except that the results are displayed via UDP.
uint16_t HalGetTickFraction(void)
Returns the fraction of the current system time tick.
int HalStorage_SavePartial(uint8_t area, void *pData, int len, int offset)
Save a blob to a specific persistent storage area as defined by the platform. This routine requires t...
void ForceReboot(bool bFromException=false)
Forces the system hardware to perform a soft reset.
int HalStorage_RemainingSpace(uint8_t area)
Obtain the number of remaining bytes available to be written in the given persistent storage area.
uint16_t HalGetDeviceKeyLen()
Get the length of the stored key.
void FlashProgram(void *pWhere, void *pWhat, int len)
Program flash memory.
int HalStorage_AddressOffset(uint8_t area, void *pWhere)
Get the offset within a persistent storage area of an address. A platform may map any address to any ...
uint8_t * HalGetDeviceKey()
Get a pointer to the stored certificate.
uint32_t HalTickMaxCount
Rollover value for the system hardware tick timer.
void StdioCheckIntc(void)
Check STDIO interrupt sources.
void PostConfigHardwareInit()
Initializes the system hardware that depend on config variables such as the watchdog.
NetBurner SSL/TLS API.