|
#define | HAL_DEFINE_GLOBAL_ARRAY(gns) |
|
#define | HAL_GET_DEV(gns, index) (void *) hal_getDev((uintptr_t **) &_devs, &_devs_end, index) |
|
#define | HAL_LOCK(data, waittime, errcode) |
|
#define | HAL_UNLOCK(data, errcode) |
|
#define | HAL_DEFINE_DEVICE_ENTRY(gns, ns, p) extern struct gns##_generic const * const ns##_##p |
|
#define | HAL_ADDDEV(gns, ns, p) struct gns##_generic SECTION(".rodata.devs") USED NO_REORDER const * const ns##_##p = (void const *) &p |
|
#define | HAL_ADD(ns, p) HAL_ADDDEV(hal, ns, p) |
|
#define | HAL_GET_GLOBAL_DEV(index) HAL_GET_DEV(hal, index) |
|
#define | HAL_NAME(n) |
|
#define | HAL_GET_ID(gns, ns, p) |
|
This is the abstract Hardware Abstraction Layer Interface (HAL) is the main Interface for all Driver. All Driver shall implement the Interface.
All Driver Interfaces implemented the hal struct and have a init Function and a deinit Function. The init function return a Handler to access the instances of the driver. The deinit function disable the driver instance.
Each Driver has the possibility to make the instances threadsave. With the function lock and unlock the Driver can lock an unlock the instances.
All Pointer to all Instants stored in a separated Section sored by driver type (like uart, pwm, timer, ..)
For driver without a specified type a generic Array is created named hal use HAL_ADD() Macro to create a new entry.
The Linker Script must contain DEV_DEFAULT().
All driver instants are static allocated.
◆ HAL_ADD
Add some Devices without Global Namespace like a instances of MPU9250 Driver
◆ HAL_ADDDEV
#define HAL_ADDDEV |
( |
|
gns, |
|
|
|
ns, |
|
|
|
p |
|
) |
| struct gns##_generic SECTION(".rodata.devs") USED NO_REORDER const * const ns##_##p = (void const *) &p |
Add Device Entry to Device Array
- Parameters
-
gns | Global Namespace of Driver like uart, pwm, ... |
ns | Namespace of Driver |
p | Pointer to Driver Struct |
◆ HAL_DEFINE_DEVICE_ENTRY
#define HAL_DEFINE_DEVICE_ENTRY |
( |
|
gns, |
|
|
|
ns, |
|
|
|
p |
|
) |
| extern struct gns##_generic const * const ns##_##p |
Define Device Entry
- Parameters
-
gns | Global Namespace of Driver like uart, pwm, ... |
ns | Namespace of Driver |
p | Pointer to Driver Struct |
◆ HAL_DEFINE_GLOBAL_ARRAY
#define HAL_DEFINE_GLOBAL_ARRAY |
( |
|
gns | ) |
|
Value: extern uintptr_t *_devs; \
extern uintptr_t *_devs_end
Define Global Array for Namespace
- Parameters
-
◆ HAL_GET_DEV
#define HAL_GET_DEV |
( |
|
gns, |
|
|
|
index |
|
) |
| (void *) hal_getDev((uintptr_t **) &_devs, &_devs_end, index) |
◆ HAL_GET_GLOBAL_DEV
Get device form global Namespace
◆ HAL_GET_ID
#define HAL_GET_ID |
( |
|
gns, |
|
|
|
ns, |
|
|
|
p |
|
) |
| |
Value: ({ \
HAL_DEFINE_DEVICE_ENTRY(gns, ns, p); \
uint32_t ret; \
ret = (uint32_t) ((((uintptr_t) (&ns##_##p)) - ((uintptr_t) (&_devs))) / sizeof(uintptr_t)); \
ret; \
})
Get Unique ID based on driver pointer
- Parameters
-
gns | Namespace like uart |
ns | Namespace of Driver |
p | Pointer to Driver Struct |
◆ HAL_LOCK
#define HAL_LOCK |
( |
|
data, |
|
|
|
waittime, |
|
|
|
errcode |
|
) |
| |
Value: do { \
int32_t lock_ret =
hal_lock(data, waittime); \
if (lock_ret != 1) { \
return errcode; \
}; \
} while(0)
Lock Driver
- Parameters
-
data | Driver Struct like hal |
waittime | Max Waittime see xSemaphoreTakeRecursive() |
errcode | Error Code automatically returned |
◆ HAL_NAME
◆ HAL_UNLOCK
#define HAL_UNLOCK |
( |
|
data, |
|
|
|
errcode |
|
) |
| |
Value: do { \
if (unlock_ret != 1) { \
return errcode; \
} \
} while(0)
Unlock Driver
- Parameters
-
data | Driver Struct like hal |
errcode | Error Code automatically returned |
◆ HAL_DEFINE_GLOBAL_ARRAY()
HAL_DEFINE_GLOBAL_ARRAY |
( |
hal |
| ) |
|
◆ hal_deinit()
int32_t hal_deinit |
( |
void * |
data | ) |
|
|
inline |
Deinit Hal Driver
- Parameters
-
data | Driver Struct like hal |
- Returns
- -1 on error 0 on ok
◆ hal_getDev()
uintptr_t* hal_getDev |
( |
uintptr_t ** |
devs, |
|
|
uintptr_t ** |
end, |
|
|
uint32_t |
index |
|
) |
| |
|
inline |
Get Device form global Array
- Parameters
-
devs | Array |
end | Last Position in Array |
index | Index in Array |
- Returns
- NULL if index to big else pointer to dev
◆ hal_init()
int32_t hal_init |
( |
void * |
data | ) |
|
|
inline |
Init Hal driver
- Parameters
-
data | Driver Struct like hal |
- Returns
- -1 on error 0 on ok
◆ hal_isInit()
bool hal_isInit |
( |
void * |
data | ) |
|
|
inline |
Check Driver is Init
- Parameters
-
data | Driver Struct like hal |
- Returns
- true = on is init false on is not init
◆ hal_lock()
int32_t hal_lock |
( |
void * |
data, |
|
|
TickType_t |
waittime |
|
) |
| |
|
inline |
Lock Driver
- Parameters
-
data | Driver Struct like hal |
waittime | Max Waittime see xSemaphoreTakeRecursive() |
- Returns
- 0 on error 1 on ok like xSemaphoreTakeRecursive()
◆ hal_unlock()
int32_t hal_unlock |
( |
void * |
data | ) |
|
|
inline |
Unlock Driver
- Parameters
-
data | Driver Struct like hal |
- Returns
- 0 on error 1 on ok like xSemaphoreTakeRecursive()