Начало
This commit is contained in:
parent
238e5d74da
commit
e5a3b543e0
|
|
@ -42,7 +42,7 @@ typedef struct {
|
|||
osMessageQueueId_t rxDataSnifferQueue0;
|
||||
osMessageQueueId_t rxDataSnifferQueue1;
|
||||
|
||||
osMessageQueueId_t txAccessQueue;
|
||||
osMessageQueueId_t txAccessQueue[3];
|
||||
|
||||
} tCanSerialPortFrameArtery;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include "CanSerialPortFrame.h"
|
||||
#include "memory.h"
|
||||
#include "at32f435_437_misc.h"
|
||||
#include "FreeRTOSConfig.h"
|
||||
|
||||
|
||||
static void vCanSerialPortFrameInitNVICEnable(can_type *CANx, uint8_t irqSubPriority) {
|
||||
|
||||
|
|
@ -106,6 +108,10 @@ void vCanSerialPortFrameInit(
|
|||
|
||||
env->can = CANx;
|
||||
|
||||
env->txAccessQueue[0] = osMutexNew(NULL);
|
||||
env->txAccessQueue[1] = osMutexNew(NULL);
|
||||
env->txAccessQueue[2] = osMutexNew(NULL);
|
||||
|
||||
if (!env->reInit) {
|
||||
env->reInit = true;
|
||||
vCanSerialPortFrameInitStructure(env, CANx, rxBufferLength0, rxSnifferLength0, rxBufferLength1,
|
||||
|
|
@ -467,48 +473,55 @@ uint16_t vCanSerialPortFrameTransmit(tCanSerialPortFrameArtery *env, uint8_t *da
|
|||
}
|
||||
*/
|
||||
|
||||
uint16_t vCanSerialPortFrameTransmit(tCanSerialPortFrameArtery *env, uint8_t *data, uint16_t size, uint32_t timeout) {
|
||||
uint16_t sent = 0;
|
||||
uint32_t endMs = SystemGetMs() + timeout;
|
||||
|
||||
uint16_t fullSize = size / 8;
|
||||
uint8_t tailSize = size % 8;
|
||||
uint16_t vCanSerialPortFrameTransmit(tCanSerialPortFrameArtery *env, uint8_t *data, uint16_t size, uint32_t adr,
|
||||
uint8_t canType, uint8_t mailBox, uint32_t timeout) {
|
||||
|
||||
uint8_t transmit_mailbox;
|
||||
can_tx_message_type TxMessage;
|
||||
configASSERT(mailBox < 3);
|
||||
|
||||
if (osMutexAcquire(env->txAccessQueue[mailBox], 1000) == osOK) {
|
||||
uint16_t sent = 0;
|
||||
uint32_t endMs = SystemGetMs() + timeout;
|
||||
|
||||
uint16_t fullSize = size / 8;
|
||||
uint8_t tailSize = size % 8;
|
||||
|
||||
uint8_t transmit_mailbox;
|
||||
can_tx_message_type TxMessage;
|
||||
|
||||
|
||||
if (env->canTypeFrame == CAN_STD_ID) {
|
||||
TxMessage.standard_id = env->id;
|
||||
TxMessage.extended_id = 0;
|
||||
TxMessage.id_type = CAN_ID_STANDARD;
|
||||
}
|
||||
if (canType == CAN_STD_ID) {
|
||||
TxMessage.standard_id = adr;
|
||||
TxMessage.extended_id = 0;
|
||||
TxMessage.id_type = CAN_ID_STANDARD;
|
||||
}
|
||||
|
||||
if (env->canTypeFrame == CAN_EXT_ID) {
|
||||
TxMessage.standard_id = 0;
|
||||
TxMessage.extended_id = env->id;
|
||||
TxMessage.id_type = CAN_ID_EXTENDED;
|
||||
}
|
||||
if (canType == CAN_EXT_ID) {
|
||||
TxMessage.standard_id = 0;
|
||||
TxMessage.extended_id = adr;
|
||||
TxMessage.id_type = CAN_ID_EXTENDED;
|
||||
}
|
||||
|
||||
TxMessage.frame_type = CAN_TFT_DATA;
|
||||
TxMessage.dlc = 8;
|
||||
TxMessage.frame_type = CAN_TFT_DATA;
|
||||
TxMessage.dlc = 8;
|
||||
|
||||
while (size && ((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
while (size && ((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
|
||||
uint16_t len = 0;
|
||||
for (uint16_t i = 0; i < fullSize; ++i) {
|
||||
uint16_t len = 0;
|
||||
for (uint16_t i = 0; i < fullSize; ++i) {
|
||||
|
||||
memcpy(TxMessage.data, &data[len], 8);
|
||||
len += 8;
|
||||
memcpy(TxMessage.data, &data[len], 8);
|
||||
len += 8;
|
||||
|
||||
transmit_mailbox = can_message_transmitExt(env->can, &TxMessage, CAN_TX_MAILBOX0);
|
||||
transmit_mailbox = can_message_transmitExt(env->can, &TxMessage, mailBox);
|
||||
|
||||
while (can_transmit_status_get(env->can, (can_tx_mailbox_num_type) transmit_mailbox) !=
|
||||
CAN_TX_STATUS_SUCCESSFUL) {
|
||||
while (can_transmit_status_get(env->can, (can_tx_mailbox_num_type) transmit_mailbox) !=
|
||||
CAN_TX_STATUS_SUCCESSFUL) {
|
||||
|
||||
if (!((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
return sent;
|
||||
}
|
||||
if (!((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
osMutexRelease(env->txAccessQueue[mailBox]);
|
||||
return sent;
|
||||
}
|
||||
|
||||
// if ((can_flag_get(env->can, CAN_BOF_FLAG) != RESET) ||
|
||||
// (can_flag_get(env->can, CAN_EPF_FLAG) != RESET) ||
|
||||
|
|
@ -516,121 +529,43 @@ uint16_t vCanSerialPortFrameTransmit(tCanSerialPortFrameArtery *env, uint8_t *da
|
|||
// return sent;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
sent += 8;
|
||||
size -= 8;
|
||||
}
|
||||
|
||||
if (tailSize) {
|
||||
TxMessage.dlc = tailSize;
|
||||
memcpy(TxMessage.data, &data[len], tailSize);
|
||||
|
||||
transmit_mailbox = can_message_transmitExt(env->can, &TxMessage, CAN_TX_MAILBOX0);
|
||||
|
||||
can_transmit_status_type status = can_transmit_status_get(env->can,
|
||||
(can_tx_mailbox_num_type) transmit_mailbox);
|
||||
|
||||
while (status != CAN_TX_STATUS_SUCCESSFUL) {
|
||||
|
||||
status = can_transmit_status_get(env->can, (can_tx_mailbox_num_type) transmit_mailbox);
|
||||
|
||||
if (!((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
return sent;
|
||||
}
|
||||
|
||||
sent += 8;
|
||||
size -= 8;
|
||||
}
|
||||
|
||||
sent += tailSize;
|
||||
size -= tailSize;
|
||||
}
|
||||
if (tailSize) {
|
||||
TxMessage.dlc = tailSize;
|
||||
memcpy(TxMessage.data, &data[len], tailSize);
|
||||
|
||||
}
|
||||
transmit_mailbox = can_message_transmitExt(env->can, &TxMessage, mailBox);
|
||||
|
||||
return sent;
|
||||
}
|
||||
can_transmit_status_type status = can_transmit_status_get(env->can,
|
||||
(can_tx_mailbox_num_type) transmit_mailbox);
|
||||
|
||||
uint16_t vCanSerialPortFrameTransmit1(tCanSerialPortFrameArtery *env, uint8_t *data, uint16_t size, uint32_t timeout) {
|
||||
uint16_t sent = 0;
|
||||
uint32_t endMs = SystemGetMs() + timeout;
|
||||
while (status != CAN_TX_STATUS_SUCCESSFUL) {
|
||||
|
||||
uint16_t fullSize = size / 8;
|
||||
uint8_t tailSize = size % 8;
|
||||
status = can_transmit_status_get(env->can, (can_tx_mailbox_num_type) transmit_mailbox);
|
||||
|
||||
uint8_t transmit_mailbox;
|
||||
can_tx_message_type TxMessage;
|
||||
if (!((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
osMutexRelease(env->txAccessQueue[mailBox]);
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
||||
if (env->canTypeFrame == CAN_STD_ID) {
|
||||
TxMessage.standard_id = env->id1;
|
||||
TxMessage.extended_id = 0;
|
||||
TxMessage.id_type = CAN_ID_STANDARD;
|
||||
}
|
||||
|
||||
if (env->canTypeFrame == CAN_EXT_ID) {
|
||||
TxMessage.standard_id = 0;
|
||||
TxMessage.extended_id = env->id1;
|
||||
TxMessage.id_type = CAN_ID_EXTENDED;
|
||||
}
|
||||
|
||||
TxMessage.frame_type = CAN_TFT_DATA;
|
||||
TxMessage.dlc = 8;
|
||||
|
||||
while (size && ((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
|
||||
uint16_t len = 0;
|
||||
for (uint16_t i = 0; i < fullSize; ++i) {
|
||||
|
||||
memcpy(TxMessage.data, &data[len], 8);
|
||||
len += 8;
|
||||
|
||||
transmit_mailbox = can_message_transmitExt(env->can, &TxMessage, CAN_TX_MAILBOX1);
|
||||
|
||||
while (can_transmit_status_get(env->can, (can_tx_mailbox_num_type) transmit_mailbox) !=
|
||||
CAN_TX_STATUS_SUCCESSFUL) {
|
||||
|
||||
if (!((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
return sent;
|
||||
}
|
||||
|
||||
// if ((can_flag_get(env->can, CAN_BOF_FLAG) != RESET) ||
|
||||
// (can_flag_get(env->can, CAN_EPF_FLAG) != RESET) ||
|
||||
// (can_flag_get(env->can, CAN_EAF_FLAG) != RESET)) {
|
||||
// return sent;
|
||||
// }
|
||||
|
||||
sent += tailSize;
|
||||
size -= tailSize;
|
||||
}
|
||||
|
||||
sent += 8;
|
||||
size -= 8;
|
||||
}
|
||||
|
||||
if (tailSize) {
|
||||
TxMessage.dlc = tailSize;
|
||||
memcpy(TxMessage.data, &data[len], tailSize);
|
||||
|
||||
transmit_mailbox = can_message_transmitExt(env->can, &TxMessage, CAN_TX_MAILBOX1);
|
||||
|
||||
can_transmit_status_type status = can_transmit_status_get(env->can,
|
||||
(can_tx_mailbox_num_type) transmit_mailbox);
|
||||
|
||||
while (status != CAN_TX_STATUS_SUCCESSFUL) {
|
||||
|
||||
status = can_transmit_status_get(env->can, (can_tx_mailbox_num_type) transmit_mailbox);
|
||||
|
||||
if (!((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
|
||||
return sent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sent += tailSize;
|
||||
size -= tailSize;
|
||||
}
|
||||
|
||||
osMutexRelease(env->txAccessQueue[mailBox]);
|
||||
return sent;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
tSerialPortFrameIO CanPortFrame_GetIo(tCanSerialPortFrameArtery *env) {
|
||||
|
|
@ -638,8 +573,7 @@ tSerialPortFrameIO CanPortFrame_GetIo(tCanSerialPortFrameArtery *env) {
|
|||
.env = env,
|
||||
.receive0 = (SerialPortFrameIOTransaction) vCanSerialPortFrameReceive0,
|
||||
.receive1 = (SerialPortFrameIOTransaction) vCanSerialPortFrameReceive1,
|
||||
.transmit = (SerialPortFrameIOTransaction) vCanSerialPortFrameTransmit,
|
||||
.transmit1 = (SerialPortFrameIOTransaction) vCanSerialPortFrameTransmit1
|
||||
.transmit = (SerialPortFrameIOTransmitTransaction) vCanSerialPortFrameTransmit,
|
||||
};
|
||||
return io;
|
||||
}
|
||||
|
|
@ -649,8 +583,7 @@ tSerialPortFrameIO CanPort_GetSnifferIo(tCanSerialPortFrameArtery *env) {
|
|||
.env = env,
|
||||
.receive0 = (SerialPortFrameIOTransaction) vCanSerialPortFrameReceiveSniffer0,
|
||||
.receive1 = (SerialPortFrameIOTransaction) vCanSerialPortFrameReceiveSniffer1,
|
||||
.transmit = (SerialPortFrameIOTransaction) vCanSerialPortFrameTransmit,
|
||||
.transmit1 = (SerialPortFrameIOTransaction) vCanSerialPortFrameTransmit1
|
||||
.transmit = (SerialPortFrameIOTransmitTransaction) vCanSerialPortFrameTransmit,
|
||||
};
|
||||
return io;
|
||||
}
|
||||
Loading…
Reference in New Issue