diff --git a/RBcore/drv_interface.c b/RBcore/drv_interface.c index 7cc9a17..c0111dd 100644 --- a/RBcore/drv_interface.c +++ b/RBcore/drv_interface.c @@ -278,7 +278,7 @@ void Drv_InterfaceInit(void) const osThreadAttr_t motor_task_attributes = { .name = MODULE_NAME_MOTOR, .stack_size = THREAD_DEFAULT_STACK, - .priority = (osPriority_t) osPriorityRealtime1, + .priority = (osPriority_t) osPriorityRealtime2, }; (void)osThreadNew(MotorTask, NULL, &motor_task_attributes); diff --git a/library/ringbuffer/ringbuffer.c b/library/ringbuffer/ringbuffer.c index 46958ee..40d9d14 100644 --- a/library/ringbuffer/ringbuffer.c +++ b/library/ringbuffer/ringbuffer.c @@ -395,6 +395,7 @@ int rd_RingbufferGetchar(rd_ringbuf_t *rb, char *ch) int rd_RingbufferDataLen(rd_ringbuf_t *rb) { if (!rb) return RD_INVALUE; + int iRet = 0; unsigned short wi = ATOMIC_LOAD(&rb->m_sWriteIndex, unsigned short, ATOMIC_ORDER_ACQUIRE); unsigned short ri = ATOMIC_LOAD(&rb->m_sReadIndex, unsigned short, ATOMIC_ORDER_RELAXED); @@ -402,14 +403,24 @@ int rd_RingbufferDataLen(rd_ringbuf_t *rb) unsigned char rb_m = ATOMIC_LOAD(&rb->m_bReadMirror, unsigned char, ATOMIC_ORDER_RELAXED); if (wi == ri) { - return (wb == rb_m) ? 0 : rb->m_iBufsize; + iRet = (wb == rb_m) ? 0 : rb->m_iBufsize; } if (wb == rb_m) { - return wi - ri; + iRet = wi - ri; } else { - return rb->m_iBufsize - (ri - wi); + iRet = rb->m_iBufsize - (ri - wi); } + + if (iRet >= 0) + { + return iRet; + } + else + { + log_e("wb = %d, rb_m = %d, wi = %d, ri = %d", wb, rb_m, wi, ri); + return 0; + } } /** diff --git a/project/paint_robot_new/paint_robot_new.c b/project/paint_robot_new/paint_robot_new.c index 99f4fad..ad75a6a 100644 --- a/project/paint_robot_new/paint_robot_new.c +++ b/project/paint_robot_new/paint_robot_new.c @@ -868,7 +868,10 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg) MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_POWER_DISABLE, NULL, 0); MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0); - g_Is_All_Button_Reset = 0; + if (g_stMK32.IsOnline == 0) + { + g_Is_All_Button_Reset = 0; + } break; } diff --git a/project/paint_robot_new/paint_robot_new_motors.c b/project/paint_robot_new/paint_robot_new_motors.c index f10176c..b0dc3a9 100644 --- a/project/paint_robot_new/paint_robot_new_motors.c +++ b/project/paint_robot_new/paint_robot_new_motors.c @@ -243,6 +243,7 @@ void MotorTask(void *argument) { static int LS_Motor_Config_Count = 0; static int iStatusQueryCycle = 0; + static int iLastiCount = 0; if (LS_Motor_Config_Count <= 200) { @@ -253,10 +254,17 @@ void MotorTask(void *argument) Rd_Delay(4); } + int iCurrentCount = Rd_GetTime(); + if (iCurrentCount - iLastiCount >= 1000) + { + log_e("Send motor timeout (%d) !", iCurrentCount - iLastiCount); + } + MotorMgr_SetTargetSpeed(g_apstMotors[0], g_aiMotorSpeed[0]); Rd_Delay(4); MotorMgr_SetTargetSpeed(g_apstMotors[1], g_aiMotorSpeed[1]); Rd_Delay(4); + iLastiCount = Rd_GetTime(); if (++iStatusQueryCycle >= 10) {