src.dualinventive.com/fw/dncm/libdi_fw/include/di_fw/can.h

120 lines
3.4 KiB
C
Executable File

/**
* @file di_fw/can.h
* @brief Firmware helpers for the DI-CAN stack
* @copyright 2016 Dual Inventive Technology Centre B.V.
*/
#ifndef INCLUDE_DI_FW_CAN_H_
#define INCLUDE_DI_FW_CAN_H_
#include <stdint.h>
#include <stdbool.h>
#include <di/can.h>
#include <di_fw/os.h>
#include <di_fw/periodic.h>
#include <di_fw/can/config.h>
enum di_fw_charger;
enum di_fw_batteries;
/**
* Initialize DI-CAN stack
* @note di_device_uid_set needs be set before calling this function
* @note di_fw_can_start will start the threads
* @param uid pointer to the node id of the can
*/
void di_fw_can_init(const char *uid);
/**
* Initialize the DI-CAN stack NET subsystem
*/
void di_fw_can_net_init(void);
/**
*
*/
void di_fw_can_init_for_drv(const char *uid, CANDriver *drv);
/**
* Send battery voltage and state
* @param battery Battery
* @param voltage Measured voltage
* @param state Batterystate. Use enum di_device_battery_state
*/
void di_fw_can_rpc_send_battery(enum di_fw_batteries battery, double voltage, uint8_t state);
/**
* Send charger voltage and state
* @param charger ID
* @param voltage Measured voltage
* @param state charger state. Use enum di_device_charger_state.
*/
void di_fw_can_rpc_send_charger(enum di_fw_charger charger, double voltage, uint8_t state);
/**
* Get CAN context of first registered di_fw CANDriver
* @return returns pointer to can context
*/
struct di_can_ctx *di_fw_can_get_ctx(void);
/**
* Get CAN context based on CANDriver
* @param drv ChibiOS CANxN driver address, when NULL given the first registered di_fw CANDriver is returned
*/
struct di_can_ctx *di_fw_can_get_ctx_for_drv(const CANDriver *drv);
/**
* Exclude RPC message type for first registered CAN driver
* @param drv CAN driver to configure filter for
* @param exclude Filter state (true filters, false passtrough)
*/
void di_fw_can_exclude_rpc_messages(const bool exclude);
/**
* Exclude RPC message type for specific CAN driver
* @param drv CAN driver to configure filter for
* @param exclude Filter state (true filters, false passtrough)
*/
void di_fw_can_exclude_rpc_messages_for_drv(const CANDriver *drv, const bool exclude);
/**
* Check if RPC message type is filtered (for the first driver)
* @return true when filter is enabled, false when disabled
*/
bool di_fw_can_is_rpc_msgtype_filtered(void);
/**
* Check if RPC message type is filtered
* @param drv CAN driver to check filter for (when NULL, first driver is used, when invalid driver address
* the first driver is used)
* @return true when filter is enabled, false when disabled
*/
bool di_fw_can_is_rpc_msgtype_filtered_for_drv(const CANDriver *drv);
/**
* Check if RPC messages may be send
* * Device is connected
* * Time is synchronized
* @return true when RPC messages may be send, false otherwise
*/
bool di_fw_can_rpc_may_send(void);
/**
* CAN stack NET subsystem periodic
* For network discovery and updates the following application can message callbacks must be registered:
* * DI_CAN_NET_CALLBACK_HEARTBEAT_PUBLISH_ITEM
* * DI_CAN_NET_DISCOVER_CALLBACK_REQUEST_ITEM
* * DI_CAN_NET_DISCOVER_CALLBACK_REPLY_ITEM
* @param ev Periodic event
* @note ev->private_data must be set to a valid di_can_ctx!
*/
void di_fw_can_net_periodic_execute(struct di_fw_periodic_event *ev);
#ifndef DI_FW_CAN_RECV_TIMEOUT_MS
#error DI_FW_CAN_RECV_TIMEOUT_MS undefined
#endif
#ifndef DI_FW_CAN_RECV_STACK_SIZE
#error DI_FW_CAN_RECV_STACK_SIZE undefined
#endif
#endif /* INCLUDE_DI_FW_CAN_H_ */