Update README and add support for autoretransmit enable/disable

This commit is contained in:
Ethan Zonca 2018-12-31 14:24:46 -05:00
parent 4f71d65de4
commit 23061febec
4 changed files with 57 additions and 3 deletions

View File

@ -1,8 +1,32 @@
# CANtact Firmware
# CANable/CANtact Firmware
[![Build Status](https://travis-ci.org/linklayer/cantact-fw.svg?branch=master)](https://travis-ci.org/linklayer/cantact-fw)
This repository contains sources for the slcan CANtact firmware modified for the CANable USB to CAN adapter.
This repository contains sources for CANtact firmware.
## Supported Commands
- `O` - Open channel
- `C` - Close channel
- `S0` - Set bitrate to 10k
- `S1` - Set bitrate to 20k
- `S2` - Set bitrate to 50k
- `S3` - Set bitrate to 100k
- `S4` - Set bitrate to 125k
- `S5` - Set bitrate to 250k
- `S6` - Set bitrate to 500k
- `S7` - Set bitrate to 750k
- `S8` - Set bitrate to 1M
- `M0` - Set mode to normal mode (default)
- `M1` - Set mode to silent mode
- `A0` - Disable automatic retransmission
- `A1` - Enable automatic retransmission (default)
- `TIIIIIIIILDD...` - Transmit data frame (Extended ID) [ID, length, data]
- `tIIILDD...` - Transmit data frame (Standard ID) [ID, length, data]
- `RIIIIIIIIL` - Transmit remote frame (Extended ID) [ID, length]
- `rIIIL` - Transmit remote frame (Standard ID) [ID, length]
Note: Channel configuration commands must be sent before opening the channel. The channel must be opened before transmitting frames.
This firmware currently does not provide any ACK/NACK feedback for serial commands.
## Building

View File

@ -23,6 +23,7 @@ void can_enable(void);
void can_disable(void);
void can_set_bitrate(enum can_bitrate bitrate);
void can_set_silent(uint8_t silent);
void can_set_autoretransmit(uint8_t autoretransmit);
uint32_t can_tx(CanTxMsgTypeDef *tx_msg);
uint32_t can_rx(CanRxMsgTypeDef *rx_msg, uint32_t timeout);

View File

@ -166,6 +166,23 @@ void can_set_silent(uint8_t silent)
}
// Set CAN peripheral to silent mode
void can_set_autoretransmit(uint8_t autoretransmit)
{
if (bus_state == ON_BUS)
{
// cannot set silent mode while on bus
return;
}
if (autoretransmit)
{
can_handle.Init.NART = DISABLE;
} else {
can_handle.Init.NART = ENABLE;
}
}
// Send a message on the CAN bus (blocking)
uint32_t can_tx(CanTxMsgTypeDef *tx_msg)
{

View File

@ -154,6 +154,18 @@ int8_t slcan_parse_str(uint8_t *buf, uint8_t len)
}
return 0;
} else if (buf[0] == 'a' || buf[0] == 'A') {
// set autoretry command
if (buf[1] == 1)
{
// mode 1: autoretry enabled (default)
can_set_autoretransmit(1);
} else {
// mode 0: autoretry disabled
can_set_autoretransmit(0);
}
return 0;
} else if (buf[0] == 't' || buf[0] == 'T') {
// transmit data frame command
frame.RTR = CAN_RTR_DATA;