add queue length and buffer transmit functions
This commit is contained in:
parent
887f92167d
commit
7de8bbdc3b
58
can-halal.c
58
can-halal.c
@ -100,48 +100,51 @@ HAL_StatusTypeDef ftcan_init(FDCAN_HandleTypeDef *handle) {
|
||||
return HAL_FDCAN_Start(hcan);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef ftcan_transmit(uint16_t id, const uint8_t *data,
|
||||
size_t datalen) {
|
||||
static FDCAN_TxHeaderTypeDef header;
|
||||
header.Identifier = id;
|
||||
header.IdType = FDCAN_STANDARD_ID;
|
||||
header.TxFrameType = FDCAN_DATA_FRAME;
|
||||
static FDCAN_TxHeaderTypeDef * fdcan_initialize_tx_header(FDCAN_TxHeaderTypeDef * header, uint16_t id, size_t datalen) {
|
||||
header->Identifier = id;
|
||||
header->IdType = FDCAN_STANDARD_ID;
|
||||
header->TxFrameType = FDCAN_DATA_FRAME;
|
||||
switch (datalen) {
|
||||
case 0:
|
||||
header.DataLength = FDCAN_DLC_BYTES_0;
|
||||
header->DataLength = FDCAN_DLC_BYTES_0;
|
||||
break;
|
||||
case 1:
|
||||
header.DataLength = FDCAN_DLC_BYTES_1;
|
||||
header->DataLength = FDCAN_DLC_BYTES_1;
|
||||
break;
|
||||
case 2:
|
||||
header.DataLength = FDCAN_DLC_BYTES_2;
|
||||
header->DataLength = FDCAN_DLC_BYTES_2;
|
||||
break;
|
||||
case 3:
|
||||
header.DataLength = FDCAN_DLC_BYTES_3;
|
||||
header->DataLength = FDCAN_DLC_BYTES_3;
|
||||
break;
|
||||
case 4:
|
||||
header.DataLength = FDCAN_DLC_BYTES_4;
|
||||
header->DataLength = FDCAN_DLC_BYTES_4;
|
||||
break;
|
||||
case 5:
|
||||
header.DataLength = FDCAN_DLC_BYTES_5;
|
||||
header->DataLength = FDCAN_DLC_BYTES_5;
|
||||
break;
|
||||
case 6:
|
||||
header.DataLength = FDCAN_DLC_BYTES_6;
|
||||
header->DataLength = FDCAN_DLC_BYTES_6;
|
||||
break;
|
||||
case 7:
|
||||
header.DataLength = FDCAN_DLC_BYTES_7;
|
||||
header->DataLength = FDCAN_DLC_BYTES_7;
|
||||
break;
|
||||
case 8:
|
||||
default:
|
||||
header.DataLength = FDCAN_DLC_BYTES_8;
|
||||
header->DataLength = FDCAN_DLC_BYTES_8;
|
||||
break;
|
||||
}
|
||||
header.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
|
||||
header.BitRateSwitch = FDCAN_BRS_OFF;
|
||||
header.FDFormat = FDCAN_CLASSIC_CAN;
|
||||
header.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
|
||||
header->ErrorStateIndicator = FDCAN_ESI_PASSIVE;
|
||||
header->BitRateSwitch = FDCAN_BRS_OFF;
|
||||
header->FDFormat = FDCAN_CLASSIC_CAN;
|
||||
header->TxEventFifoControl = FDCAN_NO_TX_EVENTS;
|
||||
|
||||
return HAL_FDCAN_AddMessageToTxFifoQ(hcan, &header, data);
|
||||
return header;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef ftcan_transmit(uint16_t id, const uint8_t *data, size_t datalen) {
|
||||
static FDCAN_TxHeaderTypeDef header;
|
||||
return HAL_FDCAN_AddMessageToTxFifoQ(hcan, fdcan_initialize_tx_header(&header, id, datalen), data);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef ftcan_add_filter(uint16_t id, uint16_t mask) {
|
||||
@ -217,6 +220,19 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *handle,
|
||||
|
||||
ftcan_msg_received_cb(header.Identifier, datalen, data);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef ftcan_get_tx_queue_length(uint32_t *length) {
|
||||
if (length == NULL) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
*length = HAL_FDCAN_GetTxFifoFreeLevel(hcan);
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef ftcan_transmit_buffer(uint16_t id, const uint8_t *data, size_t datalen, uint32_t buffer_index) {
|
||||
static FDCAN_TxHeaderTypeDef header;
|
||||
return HAL_FDCAN_AddMessageToTxBuffer(hcan, fdcan_initialize_tx_header(&header, id, datalen), data, buffer_index);
|
||||
}
|
||||
#endif
|
||||
|
||||
__weak void ftcan_msg_received_cb(uint16_t id, size_t datalen,
|
||||
@ -271,4 +287,4 @@ uint8_t *ftcan_marshal_unsigned(uint8_t *data, uint64_t val, size_t num_bytes) {
|
||||
|
||||
uint8_t *ftcan_marshal_signed(uint8_t *data, int64_t val, size_t num_bytes) {
|
||||
return ftcan_marshal_unsigned(data, val, num_bytes);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user