can_wizard/main/can.h

59 lines
1.7 KiB
C
Raw Normal View History

2023-11-22 11:48:03 +00:00
#ifndef MAIN_CAN_H
#define MAIN_CAN_H
#include "driver/twai.h"
2023-11-28 05:55:08 +00:00
#include "hal/twai_types.h"
2023-11-22 11:48:03 +00:00
#include "sdkconfig.h"
2023-11-26 05:34:12 +00:00
#include "freertos/semphr.h"
#include <stdint.h>
#include <list.h>
2023-11-22 11:48:03 +00:00
2023-11-25 08:01:19 +00:00
typedef struct {
char status[30];
int tec;
int rec;
int color;
bool extd;
} can_prompt_t;
typedef enum {
CAN_NOT_INSTALLED = 0,
CAN_STOPPED = 1,
CAN_ERROR_ACTIVE = 2,
CAN_ERROR_PASSIVE = 3,
CAN_BUF_OFF = 4,
CAN_RECOVERING = 5,
} can_state_e;
typedef struct {
bool enabled;
List* filters;
bool sw_filtering;
} adv_filt_t;
2023-11-26 05:34:12 +00:00
typedef struct {
can_state_e state;
uint32_t msgs_to_tx; /**< Number of messages queued for transmission or awaiting transmission completion */
uint32_t msgs_to_rx; /**< Number of messages in RX queue waiting to be read */
uint32_t tx_error_counter; /**< Current value of Transmit Error Counter */
uint32_t rx_error_counter; /**< Current value of Receive Error Counter */
uint32_t tx_failed_count; /**< Number of messages that failed transmissions */
uint32_t rx_missed_count; /**< Number of messages that were lost due to a full RX queue (or errata workaround if enabled) */
uint32_t rx_overrun_count; /**< Number of messages that were lost due to a RX FIFO overrun */
uint32_t arb_lost_count; /**< Number of instances arbitration was lost */
uint32_t bus_error_count; /**< Number of instances a bus error has occurred */
} can_status_t;
2023-11-25 08:01:19 +00:00
2023-11-26 05:34:12 +00:00
extern SemaphoreHandle_t can_mutex;
extern volatile can_status_t curr_can_state;
2023-11-28 11:40:41 +00:00
extern bool auto_recovery;
2023-11-28 15:26:16 +00:00
extern bool is_error_passive;
extern adv_filt_t adv_filters;
2023-11-25 08:01:19 +00:00
2023-11-22 11:48:03 +00:00
// functions
void can_task(void* arg);
void can_msg_to_str(twai_message_t *can_msg, char *start_str, char *out_str);
2023-11-22 11:48:03 +00:00
#endif // MAIN_CAN_H