111 lines
2.0 KiB
C
111 lines
2.0 KiB
C
/**
|
|
* @author Rémi Heredero
|
|
* @version 1.0.0
|
|
* @date August 2023
|
|
* @file can_interface.h
|
|
*/
|
|
#ifndef CAN_H
|
|
#define CAN_H
|
|
|
|
#include "../xf/xf.h"
|
|
|
|
typedef enum {
|
|
STCA_INIT = 10,
|
|
STCA_PROCESS
|
|
} CAN_STATES;
|
|
|
|
typedef enum {
|
|
evCAinit = 10,
|
|
evCAnewMsg,
|
|
evCAnewRTR,
|
|
evCAsend4,
|
|
evCAsend2,
|
|
evCAsend1,
|
|
evCAsend0,
|
|
evCAsendRTR
|
|
} CAN_EVENTS;
|
|
|
|
typedef void (*CAN_CALLBACK)(uint8_t, uint8_t, bool, uint32_t);
|
|
|
|
typedef struct {
|
|
CAN_STATES state;
|
|
uint8_t sender;
|
|
CAN_CALLBACK receiveCan;
|
|
} CAN;
|
|
|
|
CAN CAN_myself;
|
|
|
|
/**
|
|
* Initialize the CAN
|
|
* @param me the CAN itself
|
|
*/
|
|
void CAN_init();
|
|
|
|
/**
|
|
* Start the CAN state machine
|
|
*/
|
|
void CAN_startBehaviour();
|
|
|
|
|
|
/**
|
|
* Process the event
|
|
* @param ev the event to process
|
|
* @return true if the event is processed
|
|
*/
|
|
bool CAN_processEvent(Event* ev);
|
|
|
|
/*************
|
|
* Callbacks *
|
|
*************/
|
|
|
|
|
|
/**
|
|
* Set the callback function to call when the CAN is entering state read
|
|
* @param f the function to call
|
|
*/
|
|
void CAN_onReceiveCan(CAN_CALLBACK f);
|
|
|
|
/************
|
|
* EMITTERS *
|
|
************/
|
|
|
|
/**
|
|
* Handler for receiving new can message during.
|
|
* This function is done during interrupt
|
|
*/
|
|
void CAN_newMsg();
|
|
|
|
/**
|
|
* Put a new can message on the queue
|
|
* @param idRecipient id for the recipient
|
|
* @param idMsg id for the message
|
|
* @param data 4 bytes of data to send
|
|
*/
|
|
void CAN_Send(uint8_t idRecipient, uint8_t idMsg, uint32_t data);
|
|
|
|
void CAN_send_4_bytes(uint8_t idRecipient, uint8_t idMsg, uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3);
|
|
void CAN_send_2_bytes(uint8_t idRecipient, uint8_t idMsg, uint16_t data);
|
|
void CAN_send_1_byte(uint8_t idRecipient, uint8_t idMsg, uint8_t data);
|
|
void CAN_send_0_byte(uint8_t idRecipient, uint8_t idMsg);
|
|
void CAN_send_rtr(uint8_t idRecipient, uint8_t idMsg);
|
|
|
|
/***********
|
|
* SETTERS *
|
|
***********/
|
|
|
|
/**
|
|
* Set the sender of this firmware
|
|
* @param idSender id of the sender
|
|
* 1 CONTROL
|
|
* 2 JOYSTICK
|
|
* 3 DISPLAY
|
|
* 4 DRIVE
|
|
* 5 STEERING
|
|
* 6 SUPPLY
|
|
* 7 UNDEFINED YET
|
|
* 0 BROADCAST/DEBUG
|
|
*/
|
|
void CAN_setSender(uint8_t idSender);
|
|
|
|
#endif
|