failed approach

This commit is contained in:
2020-11-19 18:24:03 +01:00
parent e25fd2f9b9
commit dd4cacb538
324 changed files with 57839 additions and 11 deletions

View File

@ -0,0 +1,29 @@
#ifndef GS_UTIL_LINUX_DRIVERS_CAN_CAN_H
#define GS_UTIL_LINUX_DRIVERS_CAN_CAN_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
/**
@file
Linux CAN interface.
@note Only 1 filter/mask can be set, using gs_can_set_standard_filter_mask() or gs_can_set_extended_filter_mask()
*/
#include <gs/util/drivers/can/can.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Open and initialize a CAN handle.
@param[in] ifname name of CAN interface.
@param[out] handle opened CAN handle.
@return_gs_error_t
*/
gs_error_t gs_can_open(const char * ifname, int * handle);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,146 @@
#ifndef GS_UTIL_LINUX_DRIVERS_GPIO_H
#define GS_UTIL_LINUX_DRIVERS_GPIO_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
@brief GPIO interface
GPIO interface provides a generic interface where specific GPIO drivers can be plugged in.
*/
#include <gs/util/error.h>
#include <gs/util/drivers/gpio/gpio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
GomSpace linux driver GPIO get value
@param[in] gpio The gpio to read
@param[in] value Returned GPIO value (true/false = High/Low)
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (*gs_gpio_get_t)(gs_gpio_t gpio, bool *value, void * driver_data);
/**
GomSpace linux driver GPIO get value without error check
@param[in] gpio The gpio to read
@param[in] driver_data data to specific driver
@return GPIO value (true/false = High/Low)
*/
typedef bool (*gs_gpio_get_nc_t)(gs_gpio_t gpio, void * driver_data);
/**
GomSpace linux driver GPIO set value
@param[in] gpio The gpio to set
@param[in] value GPIO value (true/false = High/Low)
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (*gs_gpio_set_t)(gs_gpio_t gpio, bool value, void * driver_data);
/**
GomSpace linux driver GPIO set value without error check
@param[in] gpio The gpio to set
@param[in] value GPIO value (true/false = High/Low)
@param[in] driver_data data to specific driver
*/
typedef void (*gs_gpio_set_nc_t)(gs_gpio_t gpio, bool value, void * driver_data);
/**
GomSpace linux driver initialize GPIO as an external interrupt pin
@param[in] gpio The gpio to configure
@param[in] conf Configuration of interrupt pin
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (*gs_gpio_init_as_interrupt_t)(gs_gpio_t gpio, const gs_interrupt_conf_t * conf, void * driver_data);
/**
Every port.
*/
#define GS_GPIO_ALL_PORTS UINT16_MAX
/**
Every pin.
*/
#define GS_GPIO_ALL_PINS UINT16_MAX
/**
GPIO driver.
*/
typedef struct {
/**
Function for handling GPIO get.
*/
gs_gpio_get_t get_handler;
/**
Function for handling GPIO get no check.
*/
gs_gpio_get_nc_t get_nc_handler;
/**
Function for handling GPIO set.
*/
gs_gpio_set_t set_handler;
/**
Function for handling GPIO set no check.
*/
gs_gpio_set_nc_t set_nc_handler;
/**
Function for handling GPIO initialize as interrupt.
*/
gs_gpio_init_as_interrupt_t init_as_interrupt_handler;
} gs_gpio_driver_t;
/**
GPIO driver entry
*/
typedef struct {
/**
GPIO port, to which the driver is used (if GS_GPIO_ALL_PORTS, then all ports uses this driver).
*/
uint16_t port;
/**
GPIO pin, to which the driver is used (if GS_GPIO_ALL_PINS, then all pins uses this driver).
*/
uint16_t pin;
/**
GPIO driver.
*/
const gs_gpio_driver_t * driver;
/**
Driver specific data.
*/
void * driver_data;
} gs_gpio_driver_entry_t;
/**
Register a driver.
A specific driver can be assigned to a port and pin or it can be assigned to all pins and/or all ports.
The latest registered driver, which fit the GPIO, is the one used.
@param[in] driver_entry driver and configuration to be registered
@return_gs_error_t
*/
gs_error_t gs_gpio_register_driver(const gs_gpio_driver_entry_t * driver_entry);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,91 @@
#ifndef LIB_LIBUTIL_INCLUDE_GS_UTIL_LINUX_DRIVERS_GPIO_GPIO_SYSFS_H_
#define LIB_LIBUTIL_INCLUDE_GS_UTIL_LINUX_DRIVERS_GPIO_GPIO_SYSFS_H_
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
@brief Linux GPIO driver based on sysfs.
This driver needs to be registered in the generic GPIO linux driver @see 'gs/util/linux/drivers/gpio/gpio.h'
*/
#include <gs/util/linux/drivers/gpio/gpio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
GPIO sysfs driver data.
@note Driver takes no driver data, so a NULL pointer is valid
*/
typedef void * gs_gpio_sysfs_driver_data_t;
/**
GPIO sysfs driver interface.
*/
extern const gs_gpio_driver_t gs_gpio_sysfs_driver;
/**
GPIO sysfs initialize
@param[in] gpio The gpio to initialize
@param[in] output Direction of pin (True/False = Output/Input)
@param[in] init_value Pin state if configured as output (True/False = High/Low)
@param[in] active_low if set pin is configured as active low (so a gs_gpio_sysfs_set with 1 will actually set value low)
@return_gs_error_t
*/
gs_error_t gs_gpio_sysfs_initialize(gs_gpio_t gpio, bool output, bool init_value, bool active_low);
/**
GPIO sysfs get value
@param[in] gpio The gpio to read
@param[in] value Returned GPIO value (true/false = High/Low)
@param[in] driver_data data to driver (not used)
@return_gs_error_t
*/
gs_error_t gs_gpio_sysfs_get(gs_gpio_t gpio, bool *value, void * driver_data);
/**
GPIO sysfs get value without error check
@param[in] gpio The gpio to read
@param[in] driver_data data to driver (not used)
@return GPIO value (true/false = High/Low)
*/
bool gs_gpio_sysfs_get_nc(gs_gpio_t gpio, void * driver_data);
/**
GPIO sysfs set value
@param[in] gpio The gpio to set
@param[in] value GPIO value (true/false = High/Low)
@param[in] driver_data data to driver (not used)
@return_gs_error_t
*/
gs_error_t gs_gpio_sysfs_set(gs_gpio_t gpio, bool value, void * driver_data);
/**
GPIO sysfs set value without error check
@param[in] gpio The gpio to set
@param[in] value GPIO value (true/false = High/Low)
@param[in] driver_data data to driver (not used)
*/
void gs_gpio_sysfs_set_nc(gs_gpio_t gpio, bool value, void * driver_data);
/**
Initialize GPIO sysfs as an external interrupt pin
@param[in] gpio The gpio to configure
@param[in] conf Configuration of interrupt pin
@param[in] driver_data data to driver (not used)
@return_gs_error_t
*/
gs_error_t gs_gpio_sysfs_init_as_interrupt(gs_gpio_t gpio, const gs_interrupt_conf_t * conf, void * driver_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,125 @@
#ifndef LIB_LIBUTIL_INCLUDE_GS_UTIL_LINUX_DRIVERS_GPIO_GPIO_VIRTUAL_H_
#define LIB_LIBUTIL_INCLUDE_GS_UTIL_LINUX_DRIVERS_GPIO_GPIO_VIRTUAL_H_
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
@brief Linux GPIO driver to be used in unit tests.
This driver needs to be registered in the generic GPIO linux driver @see 'gs/util/linux/drivers/gpio/gpio.h'
*/
#include <gs/util/linux/drivers/gpio/gpio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
GPIO virtual driver data.
@note Driver takes no driver data, so a NULL pointer is valid
*/
typedef void * gs_gpio_virtual_driver_data_t;
/**
GPIO virtual driver interface.
*/
extern const gs_gpio_driver_t gs_gpio_virtual_driver;
/**
GPIO virtual driver entry, where all ports and pins are routed to virtual driver
*/
extern const gs_gpio_driver_entry_t gs_gpio_virtual_driver_entry_all;
/**
GPIO virtual initialize
@param[in] gpio The gpio to initialize
@param[in] output Direction of pin (True/False = Output/Input)
@param[in] value Pin state if configured as output (True/False = High/Low)
@return_gs_error_t
*/
gs_error_t gs_gpio_virtual_initialize(gs_gpio_t gpio, bool output, bool value);
/**
GPIO virtual get value
@param[in] gpio The gpio to read
@param[in] value Returned GPIO value (true/false = High/Low)
@param[in] driver_data data to driver (not used)
@return_gs_error_t
*/
gs_error_t gs_gpio_virtual_get(gs_gpio_t gpio, bool *value, void * driver_data);
/**
GPIO virtual get value without error check
@param[in] gpio The gpio to read
@param[in] driver_data data to driver (not used)
@return GPIO value (true/false = High/Low)
*/
bool gs_gpio_virtual_get_nc(gs_gpio_t gpio, void * driver_data);
/**
GPIO virtual set value
@param[in] gpio The gpio to set
@param[in] value GPIO value (true/false = High/Low)
@param[in] driver_data data to driver (not used)
@return_gs_error_t
*/
gs_error_t gs_gpio_virtual_set(gs_gpio_t gpio, bool value, void * driver_data);
/**
GPIO virtual set value without error check
@param[in] gpio The gpio to set
@param[in] value GPIO value (true/false = High/Low)
@param[in] driver_data data to driver (not used)
*/
void gs_gpio_virtual_set_nc(gs_gpio_t gpio, bool value, void * driver_data);
/**
Initialize GPIO virtual as an external interrupt pin
@param[in] gpio The gpio to configure
@param[in] conf Configuration of interrupt pin
@param[in] driver_data data to driver (not used)
@return_gs_error_t
*/
gs_error_t gs_gpio_virtual_init_as_interrupt(gs_gpio_t gpio, const gs_interrupt_conf_t * conf, void * driver_data);
/**
Force set a pin
This sets a pin regardless if it is configured as input, output or interrupt
If the pin is configured as interrupt, the registered ISR's will be called within this function,
if the transition matches (rising/falling)
@note This function is specific to this driver and is should not be registered.
@param[in] gpio The gpio to set
@param[in] value GPIO value (true/false = High/Low)
@return_gs_error_t
*/
gs_error_t gs_gpio_virtual_force_set(gs_gpio_t gpio, bool value);
/**
Get transitions
This gives the number of transitions ((high -> low) + (low -> high)),
since last time this function was called at this pin. This function resets the counter of the pin.
An even number means, that the pin has the same state as it was initialized to.
@note This function is specific to this driver and should not be registered
@param[in] gpio The gpio, of which transitions are given
@param[out] transitions Number of transitions
@return
*/
gs_error_t gs_gpio_virtual_get_transistions(gs_gpio_t gpio, uint32_t * transitions);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,198 @@
#ifndef LIB_LIBUTIL_INCLUDE_GS_UTIL_LINUX_DRIVERS_I2C_I2C_H_
#define LIB_LIBUTIL_INCLUDE_GS_UTIL_LINUX_DRIVERS_I2C_I2C_H_
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
@brief Linux I2C plugin driver
*/
#include <gs/util/drivers/i2c/master.h>
#include <gs/util/drivers/i2c/slave.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
GomSpace linux driver I2C master transaction.
@see 'gs/util/drivers/i2c/master.h'
@param[in] device I2C device
@param[in] addr I2C address
@param[in] tx tx buffer
@param[in] txlen bytes to be sent
@param[out] rx rx buffer
@param[in] rxlen bytes to be received
@param[in] timeout_ms timeout in milliseconds
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (* gs_i2c_master_transaction_t)(uint8_t device, uint8_t addr, const void * tx, size_t txlen,
void * rx, size_t rxlen, int timeout_ms, void * driver_data);
/**
GomSpace linux driver I2C slave start.
@see 'gs/util/drivers/i2c/slave.h'
@param[in] device I2C device
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (* gs_i2c_slave_start_t)(uint8_t device, void * driver_data);
/**
GomSpace linux driver I2C set rx callback
@see 'gs/util/drivers/i2c/slave.h'
@param[in] device I2C device
@param[in] rx rx callback
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (* gs_i2c_slave_set_rx_t)(uint8_t device, gs_i2c_slave_receive_t rx, void * driver_data);
/**
GomSpace linux driver I2C slave set 'get_rx_buffer' callback.
@see 'gs/util/drivers/i2c/slave.h'
@param[in] device I2C device
@param[in] get_rx_buf get_rx_buf callback
@param[in] buf_length length of buffer received by calling callback
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (* gs_i2c_slave_set_get_rx_buf_t)(uint8_t device, gs_i2c_slave_get_rx_buf_t get_rx_buf, size_t buf_length, void * driver_data);
/**
GomSpace linux driver I2C slave set slave response.
@see 'gs/util/drivers/i2c/slave.h'
@param[in] device I2C device
@param[in] tx tx buffer
@param[in] tx_length bytes to be send
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (* gs_i2c_slave_set_response_t)(uint8_t device, const uint8_t * tx, size_t tx_length, void * driver_data);
/**
Every I2C device ([0 : 254]).
*/
#define GS_I2C_ALL_DEVICES 255
/**
Every I2C address (0 : 127]).
*/
#define GS_I2C_ALL_ADDR 255
/**
I2C master driver.
*/
typedef struct {
/**
Function for handling master transactions.
*/
gs_i2c_master_transaction_t master_transaction_handler;
} gs_i2c_master_driver_t;
/**
I2C master driver entry
*/
typedef struct {
/**
I2C device, to which the driver is used (if GS_I2C_ALL_DEVICES, then all devices uses this driver).
*/
uint8_t device;
/**
I2C addr, to which the driver is used (if GS_I2C_ALL_ADDR, then all addr on given device uses this driver).
*/
uint8_t addr;
/**
I2C master driver.
*/
const gs_i2c_master_driver_t * driver;
/**
Driver specific data.
*/
void * driver_data;
} gs_i2c_master_driver_entry_t;
/**
I2C slave driver
*/
typedef struct {
/**
Function for handling slave start.
*/
gs_i2c_slave_start_t start_handler;
/**
Function for handling the 'setting of rx callback'.
*/
gs_i2c_slave_set_rx_t set_rx_handler;
/**
Function for handling setting of an 'rx buff get' function.
*/
gs_i2c_slave_set_get_rx_buf_t set_get_rx_buf_handler;
/**
Function for handling 'set response'.
*/
gs_i2c_slave_set_response_t set_response_handler;
} gs_i2c_slave_driver_t;
/**
I2C slave driver entry.
*/
typedef struct {
/**
I2C device, to which the driver is used (if GS_I2C_ALL_DEVICES, then all devices uses this driver).
*/
uint8_t device;
/**
I2C slave driver.
*/
const gs_i2c_slave_driver_t * driver;
/**
Driver specific data.
*/
void * driver_data;
} gs_i2c_slave_driver_entry_t;
/**
Register a master driver.
A specific driver can be assigned to a specific address and device
or it can be registered to every address on a device or every address on every device.
The latest registered driver, which fit the device an address, is the one used.
@param[in] driver_entry driver and configuration to be registered
@return_gs_error_t
*/
gs_error_t gs_i2c_master_register_driver(const gs_i2c_master_driver_entry_t * driver_entry);
/**
Register a slave driver
A specific driver can be assigned to a specific device or a driver can be assigned to every device.
The latest registered driver, which fit the device, is the one used.
@param[in] driver_entry driver and configuration to be registered
@return_gs_error_t
*/
gs_error_t gs_i2c_slave_register_driver(const gs_i2c_slave_driver_entry_t * driver_entry);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,175 @@
#ifndef LIB_LIBUTIL_INCLUDE_GS_UTIL_LINUX_DRIVERS_SPI_SPI_H_
#define LIB_LIBUTIL_INCLUDE_GS_UTIL_LINUX_DRIVERS_SPI_SPI_H_
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
Linux SPI plugin driver
*/
#include <gs/util/drivers/spi/master.h>
#include <gs/util/drivers/spi/slave.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Linux driver SPI master transactions.
@see 'gs/util/drivers/spi/master.h'
@param[in] slave SPI slave
@param[in] trans Pointer to transactions
@param[in] count Number of transactions (rx and/or tx) to complete
@param[in] timeout_ms timeout in milliseconds, primarily for locking the SPI device.
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (*gs_spi_master_transactions_t)(uint8_t slave, gs_spi_master_trans_t *trans, size_t count,
int timeout_ms, void * driver_data);
/**
Linux driver SPI slave start.
@see 'gs/util/drivers/spi/slave.h'
@param[in] device SPI device (handle)
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (* gs_spi_slave_start_t)(uint8_t device, void * driver_data);
/**
Linux driver SPI set rx callback
@see 'gs/util/drivers/spi/slave.h'
@param[in] device SPI device (handle).
@param[in] rx Rx callback.
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (* gs_spi_slave_set_rx_t)(uint8_t device, gs_spi_slave_receive_t rx, void * driver_data);
/**
Linux driver SPI slave set slave response.
@see 'gs/util/drivers/spi/slave.h'
@param[in] device SPI device (handle).
@param[in] offset offset (in bytes) for the response, counted from start of request, i.e. offset of 2 means data will be sent as the 3rd byte.
@param[in] tx pointer to data. NOTE: data is not copied due to performance, so data must stay valid until the response has been sent.
@param[in] size size of data.
@param[in] driver_data data to specific driver
@return_gs_error_t
*/
typedef gs_error_t (* gs_spi_slave_set_response_t)(uint8_t device, size_t offset, const uint8_t * tx, size_t size, void * driver_data);
/**
Every SPI slave ([0 : 254]).
*/
#define GS_SPI_ALL_SLAVES 255
/**
Every SPI device (0 : 254]).
*/
#define GS_SPI_ALL_DEVICES 255
/**
SPI master driver.
*/
typedef struct {
/**
Function for handling master transactions.
*/
gs_spi_master_transactions_t master_transactions_handler;
} gs_spi_master_driver_t;
/**
SPI master driver entry
*/
typedef struct {
/**
SPI slave, to which the driver is used (if #GS_SPI_ALL_SLAVES, then all slaves uses this driver).
*/
uint8_t slave;
/**
SPI master driver.
*/
const gs_spi_master_driver_t * driver;
/**
Driver specific data.
*/
void * driver_data;
} gs_spi_master_driver_entry_t;
/**
SPI slave driver
*/
typedef struct {
/**
Function for handling slave start.
*/
gs_spi_slave_start_t start_handler;
/**
Function for handling the 'setting of rx callback'.
*/
gs_spi_slave_set_rx_t set_rx_handler;
/**
Function for handling 'set response'.
*/
gs_spi_slave_set_response_t set_response_handler;
} gs_spi_slave_driver_t;
/**
SPI slave driver entry.
*/
typedef struct {
/**
SPI device, to which the driver is used (if #GS_SPI_ALL_DEVICES, then all devices uses this driver).
*/
uint8_t device;
/**
SPI slave driver.
*/
const gs_spi_slave_driver_t * driver;
/**
Driver specific data.
*/
void * driver_data;
} gs_spi_slave_driver_entry_t;
/**
Register a master driver.
A specific driver can be assigned to a slave or it can be assigned to every slave.
The latest registered driver, which fit the slave, is the one used.
@param[in] driver_entry driver and configuration to be registered
@return_gs_error_t
*/
gs_error_t gs_spi_master_register_driver(const gs_spi_master_driver_entry_t * driver_entry);
/**
Register a slave driver
A specific driver can be assigned to a specific device or a driver can be assigned to every device.
The latest registered driver, which fit the device, is the one used.
@param[in] driver_entry driver and configuration to be registered
@return_gs_error_t
*/
gs_error_t gs_spi_slave_register_driver(const gs_spi_slave_driver_entry_t * driver_entry);
#ifdef __cplusplus
}
#endif
#endif