add queue length and buffer transmit functions
This commit is contained in:
parent
887f92167d
commit
7de8bbdc3b
56
can-halal.c
56
can-halal.c
@ -100,48 +100,51 @@ HAL_StatusTypeDef ftcan_init(FDCAN_HandleTypeDef *handle) {
|
|||||||
return HAL_FDCAN_Start(hcan);
|
return HAL_FDCAN_Start(hcan);
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_StatusTypeDef ftcan_transmit(uint16_t id, const uint8_t *data,
|
static FDCAN_TxHeaderTypeDef * fdcan_initialize_tx_header(FDCAN_TxHeaderTypeDef * header, uint16_t id, size_t datalen) {
|
||||||
size_t datalen) {
|
header->Identifier = id;
|
||||||
static FDCAN_TxHeaderTypeDef header;
|
header->IdType = FDCAN_STANDARD_ID;
|
||||||
header.Identifier = id;
|
header->TxFrameType = FDCAN_DATA_FRAME;
|
||||||
header.IdType = FDCAN_STANDARD_ID;
|
|
||||||
header.TxFrameType = FDCAN_DATA_FRAME;
|
|
||||||
switch (datalen) {
|
switch (datalen) {
|
||||||
case 0:
|
case 0:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_0;
|
header->DataLength = FDCAN_DLC_BYTES_0;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_1;
|
header->DataLength = FDCAN_DLC_BYTES_1;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_2;
|
header->DataLength = FDCAN_DLC_BYTES_2;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_3;
|
header->DataLength = FDCAN_DLC_BYTES_3;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_4;
|
header->DataLength = FDCAN_DLC_BYTES_4;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_5;
|
header->DataLength = FDCAN_DLC_BYTES_5;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_6;
|
header->DataLength = FDCAN_DLC_BYTES_6;
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_7;
|
header->DataLength = FDCAN_DLC_BYTES_7;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
default:
|
default:
|
||||||
header.DataLength = FDCAN_DLC_BYTES_8;
|
header->DataLength = FDCAN_DLC_BYTES_8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
header.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
|
header->ErrorStateIndicator = FDCAN_ESI_PASSIVE;
|
||||||
header.BitRateSwitch = FDCAN_BRS_OFF;
|
header->BitRateSwitch = FDCAN_BRS_OFF;
|
||||||
header.FDFormat = FDCAN_CLASSIC_CAN;
|
header->FDFormat = FDCAN_CLASSIC_CAN;
|
||||||
header.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
|
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) {
|
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);
|
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
|
#endif
|
||||||
|
|
||||||
__weak void ftcan_msg_received_cb(uint16_t id, size_t datalen,
|
__weak void ftcan_msg_received_cb(uint16_t id, size_t datalen,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user