Hardware Abstraction Layer for FreeRTOS
Collaboration diagram for Driver View form Example driver:

Macros

#define EXAMPLE_ALREDY_INITED   1
 
#define example_lock(u, w, e)   HAL_LOCK(u, w, e)
 
#define example_unlock(u, e)   HAL_UNLOCK(u, e)
 
#define EXAMPLE_ADDDEV(ns, p)   HAL_ADDDEV(example, ns, p)
 
#define EXAMPLE_GET_DEV(index)   HAL_GET_DEV(example, index)
 
#define EXAMPLE_OPS(ns)
 
#define EXAMPLE_INIT_DEV(ns)   .gen.ops = &ns##_example_ops,
 
#define EXAMPLE_INIT(ns, index)   static struct example *ns##_example_init(uint32_t index)
 
#define EXAMPLE_DEINIT(ns, p)   static int32_t ns##_example_deinit(struct example *p)
 
#define EXAMPLE_FUNCNAME(ns, p, param)   static int32_t ns##_example_funcname(struct example *p, uint32_t param)
 

Functions

int32_t example_genericInit (struct example *example)
 
 HAL_DEFINE_GLOBAL_ARRAY (example)
 

Detailed Description

This is the Driver View form Example Driver.

This is a implementation of a driver

/* SPDX-License-Identifier: MIT */
/*
* Author: Andreas Werner <kernel@andy89.org>
* Date: 2016
*/
#include <stdio.h>
#include <system.h>
#include <hal.h>
#include <example.h>
#define EXAMPLE_PRV
#include <example_prv.h>
struct example {
struct example_generic gen;
uint32_t index;
};
EXAMPLE_INIT(exDev0, index) {
int32_t ret;
struct example *ex = EXAMPLE_GET_DEV(index);
if (ex == NULL) {
return NULL;
}
if (ret < 0) {
return NULL;
}
if (ret == EXAMPLE_ALREDY_INITED) {
return ex;
}
ex->index = index;
return ex;
}
EXAMPLE_DEINIT(exDev0, ex) {
ex->gen.init = false;
return 0;
}
EXAMPLE_FUNCNAME(exDev0, ex, param) {
printf("%s: index: %lu param: %lu", __FUNCTION__, ex->index, param);
return 0;
}
EXAMPLE_OPS(exDev0);
static struct example ex0 = {
HAL_NAME("Example 0 Driver 0")
};
EXAMPLE_ADDDEV(exDev0, ex0);
static struct example ex1 = {
HAL_NAME("Example 0 Driver 1")
};
EXAMPLE_ADDDEV(exDev0, ex1);

Driver with board specific like the MPU9247 has special macros to create new Instances. (for example: MPU9250_ADDDEV())

Macro Definition Documentation

◆ EXAMPLE_ADDDEV

#define EXAMPLE_ADDDEV (   ns,
 
)    HAL_ADDDEV(example, ns, p)

Add Driver Instance

Parameters
nsDriver namespace
pPointer to driver instance

◆ EXAMPLE_ALREDY_INITED

#define EXAMPLE_ALREDY_INITED   1

Error Code Returned if Already inited

◆ EXAMPLE_DEINIT

#define EXAMPLE_DEINIT (   ns,
 
)    static int32_t ns##_example_deinit(struct example *p)

Define example_deinit() Implementation

Parameters
nsDriver namespace Variablenname
pInstance Variablenname

◆ EXAMPLE_FUNCNAME

#define EXAMPLE_FUNCNAME (   ns,
  p,
  param 
)    static int32_t ns##_example_funcname(struct example *p, uint32_t param)

Define example_funcname() Implementation

Parameters
nsDriver namespace Variablenname
pInstance Variablenname
paramParam Variablenname

◆ EXAMPLE_GET_DEV

#define EXAMPLE_GET_DEV (   index)    HAL_GET_DEV(example, index)

Simple function for access a dev from driver

Parameters
indexindex
Returns
see HAL_GET_DEV

◆ EXAMPLE_INIT

#define EXAMPLE_INIT (   ns,
  index 
)    static struct example *ns##_example_init(uint32_t index)

Define example_init() Implementation

Parameters
nsDriver namespace Variablenname
indexIndex Variablenname

◆ EXAMPLE_INIT_DEV

#define EXAMPLE_INIT_DEV (   ns)    .gen.ops = &ns##_example_ops,

Init Driver Struct

Parameters
nsDriver Namespace

◆ example_lock

#define example_lock (   u,
  w,
 
)    HAL_LOCK(u, w, e)

Lock Driver if THREAD_SAVE is not defined this instruction has no function

◆ EXAMPLE_OPS

#define EXAMPLE_OPS (   ns)
Value:
static const struct example_ops ns##_example_ops = { \
.example_init = &ns##_example_init,\
.example_deinit = &ns##_example_deinit,\
.example_funcname = &ns##_example_funcname, \
}

Define Operation

Parameters
nsDriver Namespace

◆ example_unlock

#define example_unlock (   u,
 
)    HAL_UNLOCK(u, e)

Unlock Driver if THREAD_SAVE is not defined this instruction has no function

Function Documentation

◆ example_genericInit()

int32_t example_genericInit ( struct example *  example)

Generic Init Function

Check Driver Already inited and init mutex if active

Parameters
exampleInstants of Driver
Returns
EXAMPLE_ALREDY_INITED on alredy init 0 on not init < 0 error

◆ HAL_DEFINE_GLOBAL_ARRAY()

HAL_DEFINE_GLOBAL_ARRAY ( example  )
hal.h
example_prv.h
EXAMPLE_ALREDY_INITED
#define EXAMPLE_ALREDY_INITED
Definition: example_prv.h:31
example_genericInit
int32_t example_genericInit(struct example *example)
EXAMPLE_INIT_DEV
#define EXAMPLE_INIT_DEV(ns)
Definition: example_prv.h:93
EXAMPLE_ADDDEV
#define EXAMPLE_ADDDEV(ns, p)
Definition: example_prv.h:60
EXAMPLE_GET_DEV
#define EXAMPLE_GET_DEV(index)
Definition: example_prv.h:70
example_generic
Definition: example.h:86
example_ops
Definition: example.h:54
EXAMPLE_INIT
#define EXAMPLE_INIT(ns, index)
Definition: example_prv.h:100
example_ops::example_init
struct example *(* example_init)(uint32_t index)
Definition: example.h:60
EXAMPLE_FUNCNAME
#define EXAMPLE_FUNCNAME(ns, p, param)
Definition: example_prv.h:113
EXAMPLE_DEINIT
#define EXAMPLE_DEINIT(ns, p)
Definition: example_prv.h:106
system.h
example.h
HAL_NAME
#define HAL_NAME(n)
Definition: hal.h:239
EXAMPLE_OPS
#define EXAMPLE_OPS(ns)
Definition: example_prv.h:84