100 lines
1.6 KiB
C
100 lines
1.6 KiB
C
|
/**
|
|||
|
* @author R<EFBFBD>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,
|
|||
|
STCA_PROCESS
|
|||
|
} CAN_STATES;
|
|||
|
|
|||
|
typedef enum {
|
|||
|
evCAinit = 10, // TODO change this number (< 256)
|
|||
|
evCAnewMsg,
|
|||
|
evCAsend
|
|||
|
} CAN_EVENTS;
|
|||
|
|
|||
|
typedef void (*CAN_CALLBACK)(uint8_t, uint8_t, 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);
|
|||
|
|
|||
|
/***********
|
|||
|
* 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
|