TTK4155 Lab Node 1
Term project in the NTNU course TTK4155 Embedded and Industrial Computer Systems Design
Loading...
Searching...
No Matches
can.h
Go to the documentation of this file.
1
8
9#ifndef INCLUDE_CAN_H_
10#define INCLUDE_CAN_H_
11
12#include <avr/io.h>
13#include <stdbool.h>
14#include <stdint.h>
15
16#include "spi.h"
17
18#define CAN_ID_ERROR 0x01
19#define CAN_ID_GAMEOVER 0x02
20#define CAN_ID_GAMESTART 0x03
21#define CAN_ID_JOYPOS 0x04
22#define CAN_ID_RESET 0x05
23#define CAN_ID_READY 0x06
24#define CAN_ID_SCORE 0x07
25#define CAN_ID_DEFAULT 0x08
26
27#define CAN_RXQ_SIZE 8
28
33struct can_msg {
34 uint8_t adress;
35 uint8_t num_df;
36 uint8_t data;
37};
38
43struct can_device {
45};
46
53struct CAN_frame {
54 uint32_t id;
55 uint8_t dlc;
56 char data[8];
57 uint8_t extended;
58 uint8_t rtr;
60};
61
62//------------------//
63// GENERAL CAN //
64//------------------//
65
74int8_t can_init(struct can_device *dev);
75
86int8_t can_write(struct can_device *dev, struct CAN_frame msg);
87
97int8_t can_read_rx0(struct can_device *dev, struct CAN_frame *out);
98
108int8_t can_read_rx1(struct can_device *dev, struct CAN_frame *out);
109
118int can_rxq_add(struct CAN_frame *msg);
119
126int can_rxq_pull(struct CAN_frame *out);
127
128int8_t can_reset(struct can_device *dev, uint8_t address,
129 struct CAN_frame data_frame);
130
131//------------------//
132// MSCP2515 //
133//------------------//
134
135int8_t MCP2515_init(struct can_device *dev);
136int8_t MCP2515_read(struct can_device *dev, uint8_t rx_buf_num, uint8_t *out);
137int8_t MCP2515_write(struct can_device *dev, uint8_t addr, uint8_t data);
138int8_t MCP2515_request_to_send(struct can_device *dev, uint8_t tx_buf_num);
139int8_t MCP2515_bit_modify(struct can_device *dev, uint8_t reg, uint8_t mask,
140 uint8_t set_val);
141int8_t MCP2515_reset(struct can_device *dev);
142int8_t MCP2515_read_status(struct can_device *dev, uint8_t *out);
143
144#endif // INCLUDE_CAN_H_
145
int can_rxq_add(struct CAN_frame *msg)
Add a CAN frame to the internal receive queue.
Definition can.c:159
int8_t can_write(struct can_device *dev, struct CAN_frame msg)
Write a CAN frame to the MCP2515 transmit buffer.
Definition can.c:49
int8_t can_reset(struct can_device *dev, uint8_t address, struct CAN_frame data_frame)
int8_t MCP2515_read_status(struct can_device *dev, uint8_t *out)
Definition can.c:399
int8_t MCP2515_bit_modify(struct can_device *dev, uint8_t reg, uint8_t mask, uint8_t set_val)
Definition can.c:379
int8_t MCP2515_request_to_send(struct can_device *dev, uint8_t tx_buf_num)
Definition can.c:371
int8_t can_init(struct can_device *dev)
Initialize a CAN device.
Definition can.c:22
int8_t can_read_rx1(struct can_device *dev, struct CAN_frame *out)
Read a message from RX buffer 1.
Definition can.c:127
int8_t MCP2515_read(struct can_device *dev, uint8_t rx_buf_num, uint8_t *out)
Definition can.c:354
int8_t MCP2515_write(struct can_device *dev, uint8_t addr, uint8_t data)
Definition can.c:318
int8_t MCP2515_init(struct can_device *dev)
Definition can.c:217
int can_rxq_pull(struct CAN_frame *out)
Pull a CAN frame from the internal receive queue.
Definition can.c:171
int8_t MCP2515_reset(struct can_device *dev)
Definition can.c:390
int8_t can_read_rx0(struct can_device *dev, struct CAN_frame *out)
Read a message from RX buffer 0.
Definition can.c:95
spi_slave
Identifiers for available SPI slave devices.
Definition spi.h:15
SPI driver.
Represents a full CAN frame for sending/receiving.
Definition can.h:53
uint8_t extended
Definition can.h:57
uint8_t rtr
Definition can.h:58
uint8_t dlc
Definition can.h:55
uint32_t id
Definition can.h:54
char data[8]
Definition can.h:56
Represents a CAN device, storing the SPI slave controlling the MCP2515.
Definition can.h:43
enum spi_slave spi
Definition can.h:44
Represents a simple CAN message with an address, data count, and a single byte of data.
Definition can.h:33
uint8_t data
Definition can.h:36
uint8_t num_df
Definition can.h:35
uint8_t adress
Definition can.h:34