请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:MCU-PLUS-SDK AM263X CAN 消息之后立即发送多个 CAN 消息。 但仅当发送消息之间没有延迟时、代码才会发送第一条消息。
void TorqueCalculationTask(void *pvParameters) { uint64_t throttlePosition = 10; uint64_t steeringPosition = 0; CANMessage rrMessage; CANMessage rlMessage; CANMessage frMessage; CANMessage flMessage; while (1) { // if (xSemaphoreTake(torqueValuesMutex, portMAX_DELAY)) { // readThrottle(); // Read the throttle value at each cycle throttlePosition = throttle_post_transfer; steeringPosition = steering_post_transfer; if (currentState == STATE_READY_TO_DRIVE && !brakePressed) { calculateTorque(throttlePosition, torqueValues, steeringPosition); createAMKCanMessage(0x1234, 1500, torqueValues[frontLeftInv], torqueValues[frontLeftInv+1], flMessage.message); flMessage.id = 0x105; // Set the appropriate CAN ID flMessage.message_length = 8; createAMKCanMessage(0x1234, 1500, torqueValues[frontRightInv], torqueValues[frontRightInv+1], frMessage.message); frMessage.id = 0x106; // Set the appropriate CAN ID frMessage.message_length = 8; createAMKCanMessage(0x1234, 1500, torqueValues[rearRightInv], torqueValues[rearRightInv+1], rrMessage.message); rrMessage.id = 0x107; // Set the appropriate CAN ID rrMessage.message_length = 8; createAMKCanMessage(0x1234, 1500, torqueValues[rearLeftInv], torqueValues[rearLeftInv+1], rlMessage.message); rlMessage.id = 0x108; // Set the appropriate CAN ID rlMessage.message_length = 8; // App_mcanSendCustomMsg(newMsg.id, MESSAGE_TYPE_STANDARD, MCAN_DATA_SIZE_8BYTES, newMsg.message); // if (xSemaphoreTake(canQueueMutex, portMAX_DELAY) == pdTRUE) { xQueueSendToBack(canQueue, &rrMessage, portMAX_DELAY); xQueueSendToBack(canQueue, &frMessage, portMAX_DELAY); xQueueSendToBack(canQueue, &rlMessage, portMAX_DELAY); xQueueSendToBack(canQueue, &flMessage, portMAX_DELAY); xSemaphoreGive(canQueueMutex); // } // } // xSemaphoreGive(torqueValuesMutex); } vTaskDelay(pdMS_TO_TICKS(5)); // Adjust task delay as needed } } void CanMessageSendTask(void *pvParameters) { CANMessage msg; TickType_t lastWakeTime; const TickType_t frequency = pdMS_TO_TICKS(1); while(1){ while (xQueueReceive(canQueue, &msg, portMAX_DELAY)) { vTaskSuspendAll(); App_mcanSendCustomMsg(msg.id, MESSAGE_TYPE_STANDARD, MCAN_DATA_SIZE_8BYTES, msg.message); xTaskResumeAll(); } } } int32_t App_mcanSendCustomMsg(uint32_t msgId, uint8_t msgType, uint8_t dlc, const uint8_t *data) { MCAN_TxBufElement txMsg; uint32_t bufNum = 0U; // Using first buffer for simplicity int32_t status; /* Initialize message to transmit */ MCAN_initTxBufElement(&txMsg); /* Configure message ID based on type */ if (msgType == MESSAGE_TYPE_STANDARD) { txMsg.id = (msgId & MCAN_STD_ID_MASK) << MCAN_STD_ID_SHIFT; // Standard ID txMsg.xtd = FALSE; // Indicating standard identifier } else { txMsg.id = msgId & MCAN_EXT_ID_MASK; // Extended ID txMsg.xtd = TRUE; // Indicating extended identifier } /* Configure DLC */ txMsg.dlc = dlc; /* CAN FD frame format and BRS can be configured based on application needs */ txMsg.fdf = FALSE; // Not a CAN FD frame txMsg.brs = FALSE; // Baud rate switching not used /* Copy data to the message buffer */ for (uint32_t i = 0U; i < gMcanDataSize[dlc] && i < sizeof(txMsg.data); i++) { txMsg.data[i] = data[i]; } /* Write message to Message RAM */ // MCAN_writeMsgRam(gMcanBaseAddr, MCAN_MEM_TYPE_BUF, bufNum, &txMsg); MCAN_writeMsgRam(gMcanBaseAddr, MCAN_MEM_TYPE_FIFO, bufNum, &txMsg); /* Add request for transmission */ status = MCAN_txBufAddReq(gMcanBaseAddr, bufNum); return status; }
除非我在每次传输后添加"vTaskDelay (pdms_to_ticks (1);"、否则仅发送 ID 为0x107 (第一个添加到队列中的消息)的消息。 是否有在一个 Tx 完成后发送消息而不是必须添加手动延时时间的方法?
预期消息频率约为1500Hz、因此1毫秒延迟对我来说是不可行的