NetBurner 3.5.6
PDF Version
hal.h
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
54
75
96
124void ForceReboot(bool fromIRQ = false) __attribute__((noreturn));
125
126
127
142int HalStorage_Save(uint8_t area, void *pData, int len, int offset = 0);
143
158int HalStorage_SavePartial(uint8_t area, void *pData, int len, int offset);
159
170int HalStorage_Prepare(uint8_t area, int len, int offset = 0);
171
181int HalStorage_Finalize(uint8_t area);
182
196int HalStorage_Erase(uint8_t area, int len = -1, int offset = 0);
197
205int HalStorage_GetAllocated(uint8_t area);
206
217
227
236int HalStorage_WriteOffset(uint8_t area);
237
249int HalStorage_AddressOffset(uint8_t area, void *pWhere);
250
258void FlashErase(void *pWhere, int len);
259
268void FlashProgram(void *pWhere, void *pWhat, int len);
269
282void FlashProgramAppImage(void *pWhere, void *pWhat, int len);
283
289
295
301uint32_t spaceleft();
302
314extern void (*watchdog_service_function)(void);
315
322extern uint16_t HalGetTickFraction(void);
323
324#ifdef GATHER_RANDOM_USE_HW
331extern bool HalHWRandRdy(void);
332
338extern uint32_t HalGetHWRand32(void);
339#endif
340
346extern uint32_t HalTickMaxCount;
347
358void StdioCheckIntc(void);
359
366
367#if defined(NB_SSL_SUPPORTED) || defined(NB_SSH_SUPPORTED)
368
381
382// TODO: Should there be a HalDeviceKeyValid() ?
383
392
402
411
421
422
423uint16_t HalGetDeviceFormat();
424
435bool HalSaveNewDeviceCert(const uint8_t *cert, uint16_t certlen, uint8_t format = SSL_FILETYPE_PEM);
436
447bool HalSaveNewDeviceKey(const uint8_t *key, uint16_t keylen, uint8_t format = SSL_FILETYPE_PEM);
448
456#endif /* defined(NB_SSL_SUPPORTED) || defined(NB_SSH_SUPPORTED) */
457
458#endif /* _NB_HAL_H_ */
459
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.
void ForceReboot(bool fromIRQ=false)
Initiates an immediate hardware-level system reset of the NetBurner device.
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 core system hardware components during the boot sequence.
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...
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 hardware components that require configuration data to be loaded.