This repository has been archived on 2024-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
SummerSchool2-Controller/306-controller_interface.X/middleware/can_interface.h

111 lines
2.0 KiB
C
Raw Permalink Normal View History

/**
* @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 {
2023-09-04 13:22:16 +00:00
STCA_INIT = 10,
STCA_PROCESS
} CAN_STATES;
typedef enum {
2023-08-24 13:48:37 +00:00
evCAinit = 10,
evCAnewMsg,
2023-09-04 06:43:14 +00:00
evCAnewRTR,
2023-08-30 14:19:42 +00:00
evCAsend4,
evCAsend2,
evCAsend1,
2023-09-04 06:43:14 +00:00
evCAsend0,
evCAsendRTR
} CAN_EVENTS;
2023-09-04 06:43:14 +00:00
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);
2023-08-30 14:19:42 +00:00
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);
2023-08-30 14:20:41 +00:00
void CAN_send_1_byte(uint8_t idRecipient, uint8_t idMsg, uint8_t data);
2023-08-30 14:19:42 +00:00
void CAN_send_0_byte(uint8_t idRecipient, uint8_t idMsg);
2023-09-04 06:43:14 +00:00
void CAN_send_rtr(uint8_t idRecipient, uint8_t idMsg);
2023-08-30 14:19:42 +00:00
/***********
* 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