Skip to content

Commit

Permalink
fix(can/ak..ctrl): reduce the feedback dislocation
Browse files Browse the repository at this point in the history
  • Loading branch information
logeexpluoqi committed Mar 10, 2021
1 parent 7942073 commit 4d50565
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
31 changes: 15 additions & 16 deletions Communication/can/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,42 @@ void can1_init()
uint8_t can_send_msg(CanMsgTypedef msg)
{
uint8_t mbox;
uint8_t state = 0;
uint8_t i = 0;
CanTxMsg TxMessage;

TxMessage.StdId = msg.std_id; // standard ID identify
TxMessage.ExtId = msg.ext_id; // extend ID identify
TxMessage.IDE = msg.ide; // indentifier extension
TxMessage.RTR = msg.rtr; // remote transmission request
TxMessage.DLC = msg.dlc; // data length code

for (i = 0; i < msg.dlc; i++)
{
TxMessage.Data[i] = msg.send_data[i]; // send a frame
}
mem_cpy(msg.send_data, TxMessage.Data, 8);
mbox = CAN_Transmit(CAN1, &TxMessage);
i = 0;
while ((CAN_TransmitStatus(CAN1, mbox) == CAN_TxStatus_Failed) && (i < 500))
while ((CAN_TransmitStatus(CAN1, mbox) == CAN_TxStatus_Failed) && (i <= 50))
{
i++; // wait for send finish
}
if (i >= 500)
{
return 1;
}
if (i >= 50)
state = 1;
else
state = 0;

return 0;
return state;
}

uint8_t can_receive_msg(uint8_t *msg)
{
uint32_t i;
uint8_t rx_mbox = 0;
CanRxMsg RxMessage;
if (CAN_MessagePending(CAN1, CAN_FIFO0) != 0)

rx_mbox = CAN_MessagePending(CAN1, CAN_FIFO0);
if (rx_mbox != 0)
{
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage); // read receive data from fifo
for (i = 0; i < RxMessage.DLC; i++)
{
msg[i] = RxMessage.Data[i];
}
CAN_FIFORelease(CAN1, CAN_FIFO0);
mem_cpy(RxMessage.Data, msg, RxMessage.DLC);
return RxMessage.DLC;
}
else
Expand Down
3 changes: 1 addition & 2 deletions Tasks/ak_motor_ctrl_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "msg_codec.h"
#include "ak_motor.h"
#include "delay.h"
#include "oled_task.h"

static msgbox_akmotor_t* akmotor;
static uint8_t ak_motor_upload_cache[62] = {0};
Expand All @@ -30,7 +29,6 @@ state_t ak_motor_ctrl_task()
{
if(akmotor[i].exist == 1)
{
delay_us(330); // this delay is necessary for CAN bus transmmit
switch(mode)
{
case EN_MOTOR_MODE:
Expand Down Expand Up @@ -94,6 +92,7 @@ state_t ak_motor_ctrl_task()
}
akmotor[motor_num].exist = 0;
motor_num = motor_num + 1;
delay_us(330); // this delay is necessary for CAN bus transmmit
}
}
msgbox_task_en(TASK_DISABLE);
Expand Down

0 comments on commit 4d50565

Please sign in to comment.