Compare commits
No commits in common. "master" and "servoMotorCommuV0.1" have entirely different histories.
master
...
servoMotor
|
@ -78,7 +78,7 @@ static void creat_task_servo_recv_task(void)
|
||||||
(INT8U ) TASK_RECV_VERT_SERVO_PRIO,
|
(INT8U ) TASK_RECV_VERT_SERVO_PRIO,
|
||||||
(INT16U ) TASK_RECV_VERT_SERVO_PRIO,
|
(INT16U ) TASK_RECV_VERT_SERVO_PRIO,
|
||||||
(OS_STK *)&task_recv_vert_servo_stk[0],
|
(OS_STK *)&task_recv_vert_servo_stk[0],
|
||||||
(INT32U ) TASK_RECV_HORI_SERVO_STK_SIZE,
|
(INT32U ) task_recv_vert_servo_stk,
|
||||||
(void *) 0,
|
(void *) 0,
|
||||||
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
|
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
|
||||||
#if (OS_TASK_NAME_EN > 0)
|
#if (OS_TASK_NAME_EN > 0)
|
||||||
|
|
|
@ -9,11 +9,14 @@ BSP_OS_SEM g_vertSpeedSem;
|
||||||
BSP_OS_SEM g_horiSpeedMutex;
|
BSP_OS_SEM g_horiSpeedMutex;
|
||||||
BSP_OS_SEM g_vertSpeedMutex;
|
BSP_OS_SEM g_vertSpeedMutex;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t memBuffer[linkListNodeLen * sendDataBufNumber * 2] = {0};
|
uint16_t memBuffer[linkListNodeLen * sendDataBufNumber * 2] = {0};
|
||||||
OS_MEM *g_memPtr;
|
OS_MEM *g_memPtr;
|
||||||
|
|
||||||
ptzServoLinkList g_servoMotorLinkList = {0};
|
ptzServoLinkList g_servoMotorLinkList = {0};
|
||||||
|
|
||||||
|
|
||||||
//发送云台实际转速
|
//发送云台实际转速
|
||||||
void ptz_send_speed(char dev, char speed)
|
void ptz_send_speed(char dev, char speed)
|
||||||
{
|
{
|
||||||
|
@ -59,71 +62,16 @@ void ptz_send_speed(char dev, char speed)
|
||||||
\param[out] none
|
\param[out] none
|
||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void servoHoriLinkListMemPut(uint8_t motorType)
|
void servoLinkListMemPut(linkList *data)
|
||||||
{
|
{
|
||||||
//水平电机
|
if (data == NULL) {
|
||||||
if (motorType == horiMotorType) {
|
return;
|
||||||
//当前发送完成的数据为高优先级链表中的数据
|
|
||||||
if (g_servoMotorLinkList.horiMotor.linkListNum == highPriority) {
|
|
||||||
if (g_servoMotorLinkList.horiMotor.LinkListHead_H != NULL) {
|
|
||||||
linkList *ptr;
|
|
||||||
ptr = g_servoMotorLinkList.horiMotor.LinkListHead_H;
|
|
||||||
if (ptr->next != NULL) {
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListHead_H = ptr->next;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListHead_H = NULL;
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListTail_H = NULL;
|
|
||||||
}
|
|
||||||
OSMemPut(g_memPtr, (uint8_t *)ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//当前发送完成的数据为低优先级链表中的数据
|
|
||||||
else if (g_servoMotorLinkList.horiMotor.linkListNum == lowPriority) {
|
|
||||||
if (g_servoMotorLinkList.horiMotor.LinkListHead_L != NULL) {
|
|
||||||
linkList *ptr;
|
|
||||||
ptr = g_servoMotorLinkList.horiMotor.LinkListHead_L;
|
|
||||||
if (ptr->next != NULL) {
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListHead_L = ptr->next;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListHead_L = NULL;
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListTail_L = NULL;
|
|
||||||
}
|
|
||||||
OSMemPut(g_memPtr, (uint8_t *)ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (motorType == vertMotorType) {
|
|
||||||
if (g_servoMotorLinkList.vertMotor.linkListNum == highPriority) {
|
|
||||||
if (g_servoMotorLinkList.vertMotor.LinkListHead_H != NULL) {
|
|
||||||
linkList *ptr;
|
|
||||||
ptr = g_servoMotorLinkList.vertMotor.LinkListHead_H;
|
|
||||||
if (ptr->next != NULL) {
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListHead_H = ptr->next;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListHead_H = NULL;
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListTail_H = NULL;
|
|
||||||
}
|
|
||||||
OSMemPut(g_memPtr, (uint8_t *)ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (g_servoMotorLinkList.vertMotor.linkListNum == lowPriority) {
|
|
||||||
if (g_servoMotorLinkList.vertMotor.LinkListHead_L != NULL) {
|
|
||||||
linkList *ptr;
|
|
||||||
ptr = g_servoMotorLinkList.vertMotor.LinkListHead_L;
|
|
||||||
if (ptr->next != NULL) {
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListHead_L = ptr->next;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListHead_L = NULL;
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListTail_L = NULL;
|
|
||||||
}
|
|
||||||
OSMemPut(g_memPtr, (uint8_t *)ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkList *ptr;
|
||||||
|
ptr = data;
|
||||||
|
data = data->next;
|
||||||
|
OSMemPut(g_memPtr, (uint8_t *)ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -157,9 +105,6 @@ void servoSendData(uint8_t motor,uint8_t *data, uint8_t dataLen, uint8_t priorit
|
||||||
|
|
||||||
//保存数据到链表节点
|
//保存数据到链表节点
|
||||||
ptr = OSMemGet(g_memPtr, &err);
|
ptr = OSMemGet(g_memPtr, &err);
|
||||||
if (ptr == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ptr->length = dataLen;
|
ptr->length = dataLen;
|
||||||
memcpy(ptr->data, data, dataLen);
|
memcpy(ptr->data, data, dataLen);
|
||||||
|
|
||||||
|
@ -171,32 +116,18 @@ void servoSendData(uint8_t motor,uint8_t *data, uint8_t dataLen, uint8_t priorit
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priority == highPriority) {
|
if (priority == highPriority) {
|
||||||
if (g_servoMotorLinkList.horiMotor.LinkListTail_H == NULL) {
|
g_servoMotorLinkList.horiMotor.LinkListTail_H = ptr;
|
||||||
g_servoMotorLinkList.horiMotor.LinkListTail_H = ptr;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListTail_H->next = ptr;
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListTail_H = ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_servoMotorLinkList.horiMotor.LinkListHead_H == NULL) {
|
if (g_servoMotorLinkList.horiMotor.LinkListHead_H == NULL) {
|
||||||
g_servoMotorLinkList.horiMotor.LinkListHead_H
|
g_servoMotorLinkList.horiMotor.LinkListHead_H
|
||||||
= g_servoMotorLinkList.horiMotor.LinkListTail_H;
|
= g_servoMotorLinkList.horiMotor.LinkListTail_H;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (g_servoMotorLinkList.horiMotor.LinkListTail_L == NULL) {
|
g_servoMotorLinkList.horiMotor.LinkListTail_L = ptr;
|
||||||
g_servoMotorLinkList.horiMotor.LinkListTail_L = ptr;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListTail_L->next = ptr;
|
|
||||||
g_servoMotorLinkList.horiMotor.LinkListTail_L = ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_servoMotorLinkList.horiMotor.LinkListHead_L == NULL) {
|
if (g_servoMotorLinkList.horiMotor.LinkListHead_L == NULL) {
|
||||||
g_servoMotorLinkList.horiMotor.LinkListHead_L
|
g_servoMotorLinkList.horiMotor.LinkListHead_L
|
||||||
= g_servoMotorLinkList.horiMotor.LinkListTail_L;
|
= g_servoMotorLinkList.horiMotor.LinkListTail_L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//释放信号量,通知能发送一次
|
//释放信号量,通知能发送一次
|
||||||
|
@ -209,28 +140,14 @@ void servoSendData(uint8_t motor,uint8_t *data, uint8_t dataLen, uint8_t priorit
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priority == highPriority) {
|
if (priority == highPriority) {
|
||||||
if (g_servoMotorLinkList.vertMotor.LinkListTail_H == NULL) {
|
g_servoMotorLinkList.vertMotor.LinkListTail_H = ptr;
|
||||||
g_servoMotorLinkList.vertMotor.LinkListTail_H = ptr;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListTail_H->next = ptr;
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListTail_H = ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_servoMotorLinkList.vertMotor.LinkListHead_H == NULL) {
|
if (g_servoMotorLinkList.vertMotor.LinkListHead_H == NULL) {
|
||||||
g_servoMotorLinkList.vertMotor.LinkListHead_H
|
g_servoMotorLinkList.vertMotor.LinkListHead_H
|
||||||
= g_servoMotorLinkList.vertMotor.LinkListTail_H;
|
= g_servoMotorLinkList.vertMotor.LinkListTail_H;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (g_servoMotorLinkList.vertMotor.LinkListTail_L == NULL) {
|
g_servoMotorLinkList.vertMotor.LinkListTail_L = ptr;
|
||||||
g_servoMotorLinkList.vertMotor.LinkListTail_L = ptr;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListTail_L->next = ptr;
|
|
||||||
g_servoMotorLinkList.vertMotor.LinkListTail_L = ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_servoMotorLinkList.vertMotor.LinkListHead_L == NULL) {
|
if (g_servoMotorLinkList.vertMotor.LinkListHead_L == NULL) {
|
||||||
g_servoMotorLinkList.vertMotor.LinkListHead_L
|
g_servoMotorLinkList.vertMotor.LinkListHead_L
|
||||||
= g_servoMotorLinkList.vertMotor.LinkListTail_L;
|
= g_servoMotorLinkList.vertMotor.LinkListTail_L;
|
||||||
|
@ -259,8 +176,8 @@ static void ptz_hori_servo_task()
|
||||||
// 高优先级链表中数据先发送
|
// 高优先级链表中数据先发送
|
||||||
if (g_servoMotorLinkList.horiMotor.LinkListHead_H != NULL) {
|
if (g_servoMotorLinkList.horiMotor.LinkListHead_H != NULL) {
|
||||||
//发送数据
|
//发送数据
|
||||||
CommuTransData(H_MOTOR, g_servoMotorLinkList.horiMotor.LinkListHead_H->data
|
|
||||||
, g_servoMotorLinkList.horiMotor.LinkListHead_H->length);
|
|
||||||
|
|
||||||
g_servoMotorLinkList.horiMotor.linkListNum = highPriority;
|
g_servoMotorLinkList.horiMotor.linkListNum = highPriority;
|
||||||
continue;
|
continue;
|
||||||
|
@ -269,8 +186,8 @@ static void ptz_hori_servo_task()
|
||||||
// 高优先级链表中无数据时,发送低优先级中的数据
|
// 高优先级链表中无数据时,发送低优先级中的数据
|
||||||
if (g_servoMotorLinkList.horiMotor.LinkListHead_L != NULL) {
|
if (g_servoMotorLinkList.horiMotor.LinkListHead_L != NULL) {
|
||||||
//发送数据
|
//发送数据
|
||||||
CommuTransData(H_MOTOR, g_servoMotorLinkList.horiMotor.LinkListHead_L->data
|
|
||||||
, g_servoMotorLinkList.horiMotor.LinkListHead_L->length);
|
|
||||||
|
|
||||||
g_servoMotorLinkList.horiMotor.linkListNum = lowPriority;
|
g_servoMotorLinkList.horiMotor.linkListNum = lowPriority;
|
||||||
}
|
}
|
||||||
|
@ -297,17 +214,17 @@ static void ptz_vert_servo_task()
|
||||||
// 高优先级链表中数据先发送
|
// 高优先级链表中数据先发送
|
||||||
if (g_servoMotorLinkList.vertMotor.LinkListHead_H != NULL) {
|
if (g_servoMotorLinkList.vertMotor.LinkListHead_H != NULL) {
|
||||||
g_servoMotorLinkList.vertMotor.linkListNum = highPriority;
|
g_servoMotorLinkList.vertMotor.linkListNum = highPriority;
|
||||||
CommuTransData(V_MOTOR, g_servoMotorLinkList.vertMotor.LinkListHead_H->data
|
|
||||||
, g_servoMotorLinkList.vertMotor.LinkListHead_H->length);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 高优先级链表中无数据时,发送低优先级中的数据
|
// 高优先级链表中无数据时,发送低优先级中的数据
|
||||||
if (g_servoMotorLinkList.vertMotor.LinkListHead_L != NULL) {
|
if (g_servoMotorLinkList.vertMotor.LinkListHead_L != NULL) {
|
||||||
g_servoMotorLinkList.vertMotor.linkListNum = highPriority;
|
g_servoMotorLinkList.vertMotor.linkListNum = highPriority;
|
||||||
CommuTransData(V_MOTOR, g_servoMotorLinkList.vertMotor.LinkListHead_L->data
|
|
||||||
, g_servoMotorLinkList.vertMotor.LinkListHead_L->length);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -369,101 +286,7 @@ static void creat_task_vert_servo_task(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void horiServoTimeOut()
|
|
||||||
{
|
|
||||||
OSSemPost(g_horiSpeedMutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vertServoTimeOut()
|
|
||||||
{
|
|
||||||
OSSemPost(g_vertSpeedMutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
BSP_OS_TMR horiServoSoftWareTim;
|
|
||||||
BSP_OS_TMR vertServoSoftWareTim;
|
|
||||||
void servoCommSoftWareTimInit()
|
|
||||||
{
|
|
||||||
CPU_INT08U ServoSoftWareTimErr;
|
|
||||||
horiServoSoftWareTim = OSTmrCreate(10
|
|
||||||
, 10
|
|
||||||
, OS_TMR_OPT_PERIODIC
|
|
||||||
, (OS_TMR_CALLBACK)horiServoTimeOut
|
|
||||||
, (void *)0
|
|
||||||
, "tmr1"
|
|
||||||
, &ServoSoftWareTimErr);
|
|
||||||
|
|
||||||
if ((ServoSoftWareTimErr == OS_ERR_NONE)) {
|
|
||||||
pdebug(DEBUG_LEVEL_INFO,"create horiServoSoftWareTim success...\n\r");
|
|
||||||
} else {
|
|
||||||
pdebug(DEBUG_LEVEL_FATAL,"create horiServoSoftWareTim failed...\n\r");
|
|
||||||
}
|
|
||||||
|
|
||||||
vertServoSoftWareTim = OSTmrCreate(10
|
|
||||||
, 10
|
|
||||||
, OS_TMR_OPT_PERIODIC
|
|
||||||
, (OS_TMR_CALLBACK)vertServoTimeOut
|
|
||||||
, (void *)0
|
|
||||||
, "tmr2"
|
|
||||||
, &ServoSoftWareTimErr);
|
|
||||||
|
|
||||||
if ((ServoSoftWareTimErr == OS_ERR_NONE)) {
|
|
||||||
pdebug(DEBUG_LEVEL_INFO,"create vertServoSoftWareTim success...\n\r");
|
|
||||||
} else {
|
|
||||||
pdebug(DEBUG_LEVEL_FATAL,"create vertServoSoftWareTim failed...\n\r");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief 停止软件定时器
|
|
||||||
\param[in] motor:电机
|
|
||||||
horiMotorType 水平电机
|
|
||||||
vertMotorType 俯仰电机
|
|
||||||
\param[out] none
|
|
||||||
\retval none
|
|
||||||
*/
|
|
||||||
void stopTimeOut(uint8_t motorType)
|
|
||||||
{
|
|
||||||
if (motorType == horiMotorType) {
|
|
||||||
CPU_INT08U err;
|
|
||||||
OSTmrStop(horiServoSoftWareTim, OS_TMR_OPT_NONE, (void *)0, &err);
|
|
||||||
if (err != OS_ERR_NONE) {
|
|
||||||
pdebug(DEBUG_LEVEL_FATAL,"start horiServoSoftWareTim failed...\n\r");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (motorType == vertMotorType) {
|
|
||||||
CPU_INT08U err;
|
|
||||||
OSTmrStop(vertServoSoftWareTim, OS_TMR_OPT_NONE, (void *)0, &err);
|
|
||||||
if (err != OS_ERR_NONE) {
|
|
||||||
pdebug(DEBUG_LEVEL_FATAL,"start vertServoSoftWareTim failed...\n\r");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief 启动软件定时器
|
|
||||||
\param[in] motor:电机
|
|
||||||
horiMotorType 水平电机
|
|
||||||
vertMotorType 俯仰电机
|
|
||||||
\param[out] none
|
|
||||||
\retval none
|
|
||||||
*/
|
|
||||||
void startTimeOut(uint8_t motorType)
|
|
||||||
{
|
|
||||||
if (motorType == horiMotorType) {
|
|
||||||
CPU_INT08U err;
|
|
||||||
OSTmrStart(horiServoSoftWareTim, &err);
|
|
||||||
if (err != OS_ERR_NONE) {
|
|
||||||
pdebug(DEBUG_LEVEL_FATAL,"start horiServoSoftWareTim failed...\n\r");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (motorType == vertMotorType) {
|
|
||||||
CPU_INT08U err;
|
|
||||||
OSTmrStart(vertServoSoftWareTim, &err);
|
|
||||||
if (err != OS_ERR_NONE) {
|
|
||||||
pdebug(DEBUG_LEVEL_FATAL,"start vertServoSoftWareTim failed...\n\r");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_speed_module(void)
|
void init_speed_module(void)
|
||||||
{
|
{
|
||||||
|
@ -501,15 +324,6 @@ void init_speed_module(void)
|
||||||
|
|
||||||
creat_task_hori_servo_task();
|
creat_task_hori_servo_task();
|
||||||
creat_task_vert_servo_task();
|
creat_task_vert_servo_task();
|
||||||
|
|
||||||
servoCommSoftWareTimInit();
|
|
||||||
|
|
||||||
OSTimeDlyHMSM(0u, 0u, 0u, 500u);//等待硬件初始化成功
|
|
||||||
|
|
||||||
uint8_t buffer[20] = {0};
|
|
||||||
uint8_t buffer_len = 0;
|
|
||||||
buffer_len = WriteMotorOneReg_buffer(H_MOTOR, H02_CONTR_MODE_SELEC, 0, buffer);
|
|
||||||
servoSendData(horiMotorType, buffer, buffer_len, lowPriority);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,10 +67,8 @@ extern ptzServoLinkList g_servoMotorLinkList;
|
||||||
void ptz_send_speed(char dev, char speed);
|
void ptz_send_speed(char dev, char speed);
|
||||||
void init_speed_module(void);
|
void init_speed_module(void);
|
||||||
|
|
||||||
|
void servoLinkListMemPut(linkList *data);
|
||||||
void servoSendData(uint8_t motor,uint8_t *data, uint8_t dataLen, uint8_t priority);
|
void servoSendData(uint8_t motor,uint8_t *data, uint8_t dataLen, uint8_t priority);
|
||||||
void servoHoriLinkListMemPut(uint8_t motorType);
|
|
||||||
void stopTimeOut(uint8_t motorType);
|
|
||||||
void startTimeOut(uint8_t motorType);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -334,51 +334,24 @@ void USART2_IRQHandler(void)
|
||||||
//释放信号量,通知接收到一包数据,任务可以处理了
|
//释放信号量,通知接收到一包数据,任务可以处理了
|
||||||
OSSemPost(g_horiMotorMutex);
|
OSSemPost(g_horiMotorMutex);
|
||||||
CommuInfo_t *pCommuDeal = g_commuInfoBuff[H_MOTOR].pCommuInfo;
|
CommuInfo_t *pCommuDeal = g_commuInfoBuff[H_MOTOR].pCommuInfo;
|
||||||
|
|
||||||
dma_interrupt_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, DMA_CHXCTL_FTFIE);
|
|
||||||
/* 切换使用接收缓冲区,这样上层的解析永远从第一个字节起*/
|
/* 切换使用接收缓冲区,这样上层的解析永远从第一个字节起*/
|
||||||
if ( pCommuDeal->pDmaRsvBuffSelect == DMA_RSVBUFF_SELECT1 )
|
if ( pCommuDeal->pDmaRsvBuffSelect == DMA_RSVBUFF_SELECT1 )
|
||||||
{
|
{
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT2;
|
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT2;
|
||||||
dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo
|
dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff2);
|
||||||
// dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff2);
|
dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
||||||
// dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
dma_memory_address_config(g_MotorDmaBuff[H_MOTOR].dmaNo
|
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch
|
|
||||||
, DMA_MEMORY_1
|
|
||||||
, (uint32_t)(pCommuDeal->pDmaRsvBuff2));
|
|
||||||
dma_transfer_number_config(g_MotorDmaBuff[H_MOTOR].dmaNo
|
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch
|
|
||||||
, DMA_BUFF_SIZE);
|
|
||||||
dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;
|
|
||||||
// dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
|
||||||
// dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff1);
|
|
||||||
// dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
// dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
|
||||||
// dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff2);
|
|
||||||
// dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
|
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;
|
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;
|
||||||
dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
||||||
dma_memory_address_config(g_MotorDmaBuff[H_MOTOR].dmaNo
|
dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff1);
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch
|
dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
||||||
, DMA_MEMORY_0
|
dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
||||||
, (uint32_t)(pCommuDeal->pDmaRsvBuff1));
|
|
||||||
dma_transfer_number_config(g_MotorDmaBuff[H_MOTOR].dmaNo
|
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch
|
|
||||||
, DMA_BUFF_SIZE);
|
|
||||||
dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
|
||||||
}
|
}
|
||||||
dma_interrupt_flag_clear(g_MotorDmaBuff[H_MOTOR].dmaNo
|
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch, DMA_INT_FLAG_FTF);
|
|
||||||
dma_interrupt_enable(g_MotorDmaBuff[H_MOTOR].dmaNo
|
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch, DMA_CHXCTL_FTFIE);
|
|
||||||
|
|
||||||
|
|
||||||
/*计算在DMA缓冲区需要获取的数据长度*/
|
/*计算在DMA缓冲区需要获取的数据长度*/
|
||||||
// DmaIdleNum = dma_transfer_number_get(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//获取的是还有多少个没传输,而不是已经传输了多少
|
// DmaIdleNum = dma_transfer_number_get(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//获取的是还有多少个没传输,而不是已经传输了多少
|
||||||
|
@ -406,45 +379,23 @@ void DMA0_Channel1_IRQHandler(void)
|
||||||
/* 切换使用接收缓冲区,这样上层的解析永远从第一个字节起*/
|
/* 切换使用接收缓冲区,这样上层的解析永远从第一个字节起*/
|
||||||
if ( pCommuDeal->pDmaRsvBuffSelect == DMA_RSVBUFF_SELECT1 )
|
if ( pCommuDeal->pDmaRsvBuffSelect == DMA_RSVBUFF_SELECT1 )
|
||||||
{
|
{
|
||||||
// pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT2;
|
|
||||||
// dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
|
||||||
// dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff2);
|
|
||||||
// dmaStruct.number = DMA_BUFF_SIZE;
|
|
||||||
// dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
// dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
|
||||||
// dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff2);
|
|
||||||
// dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
|
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT2;
|
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT2;
|
||||||
dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
||||||
dma_memory_address_config(g_MotorDmaBuff[H_MOTOR].dmaNo
|
dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff2);
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch
|
dmaStruct.number = DMA_BUFF_SIZE;
|
||||||
, DMA_MEMORY_1
|
dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
||||||
, (uint32_t)(pCommuDeal->pDmaRsvBuff2));
|
|
||||||
dma_transfer_number_config(g_MotorDmaBuff[H_MOTOR].dmaNo
|
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch
|
|
||||||
, DMA_BUFF_SIZE);
|
|
||||||
dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;
|
|
||||||
// dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
|
||||||
// dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff1);
|
|
||||||
// dmaStruct.number = DMA_BUFF_SIZE;
|
|
||||||
// dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
// dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;
|
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;
|
||||||
dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
dma_channel_disable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
||||||
dma_memory_address_config(g_MotorDmaBuff[H_MOTOR].dmaNo
|
dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff1);
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch
|
dmaStruct.number = DMA_BUFF_SIZE;
|
||||||
, DMA_MEMORY_0
|
dma_single_data_mode_init(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, &dmaStruct);
|
||||||
, (uint32_t)(pCommuDeal->pDmaRsvBuff1));
|
dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
||||||
dma_transfer_number_config(g_MotorDmaBuff[H_MOTOR].dmaNo
|
|
||||||
, g_MotorDmaBuff[H_MOTOR].dmaRxch
|
|
||||||
, DMA_BUFF_SIZE);
|
|
||||||
dma_channel_enable(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,7 +556,7 @@ bool CommuTransData(uint8_t motorNo, uint8_t* buffer, int32_t len)
|
||||||
pCommuDeal->dmaTranFlag = DMA_TRANS_BUSY;
|
pCommuDeal->dmaTranFlag = DMA_TRANS_BUSY;
|
||||||
CommuDmaTra(motorNo, buffer, len);
|
CommuDmaTra(motorNo, buffer, len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,40 +80,6 @@ bool MotorReplyForWrite(uint8_t motorNo, uint8_t* userBuff, uint8_t len)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
从机地址 功能码 寄存器地址高 寄存器地址低 数据高位 数据低位 crc校验高位 crc校验低位
|
|
||||||
01H 06H 02H 00H 00H 01H 49H B2H
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @brief 伺服电机速度模式写单个寄存器
|
|
||||||
* @param motorNo:写垂直电机还是水平电机
|
|
||||||
* @param regAddr:要写的寄存器
|
|
||||||
* @param data:要向寄存器写入的数据
|
|
||||||
* @param frameBuff: 用来发送的数组
|
|
||||||
* @return 写入frameBuff的长度
|
|
||||||
*/
|
|
||||||
uint8_t WriteMotorOneReg_buffer(uint8_t motorNo, uint16_t regAddr, uint16_t data, uint8_t *frameBuff)
|
|
||||||
{
|
|
||||||
uint16_t crc;
|
|
||||||
if ( motorNo == H_MOTOR )
|
|
||||||
{
|
|
||||||
frameBuff[0] = H_MOTOR_ADDR;//由于采用一主一从模式,所以水平电机垂直电机从机地址都是0x01,云台后期也不会扩展
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
frameBuff[0] = V_MOTOR_ADDR;
|
|
||||||
}
|
|
||||||
frameBuff[1] = WRITE_ONE_REG;
|
|
||||||
frameBuff[2] = regAddr >> WRITE_ONE_REG_BUFFNUM;
|
|
||||||
frameBuff[3] = regAddr & 0xff;
|
|
||||||
frameBuff[4] = data >> WRITE_ONE_REG_BUFFNUM;
|
|
||||||
frameBuff[5] = data & 0xff;
|
|
||||||
crc = ModbusCRC16(frameBuff, WRITE_ONE_REG_BUFFNUM - 2);
|
|
||||||
frameBuff[6] = crc & 0xff;
|
|
||||||
frameBuff[7] = crc >> WRITE_ONE_REG_BUFFNUM;
|
|
||||||
|
|
||||||
return 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 伺服电机驱动初始化
|
* @brief 伺服电机驱动初始化
|
||||||
|
@ -128,22 +94,22 @@ void servoMotorInit(void)
|
||||||
V_MOTOR_OPEN;
|
V_MOTOR_OPEN;
|
||||||
|
|
||||||
CommuDrvInit();//伺服电机RS485通讯初始化
|
CommuDrvInit();//伺服电机RS485通讯初始化
|
||||||
// OSTimeDlyHMSM(0u, 0u, 0u, 500u);//等待硬件初始化成功
|
OSTimeDlyHMSM(0u, 0u, 0u, 500u);//等待硬件初始化成功
|
||||||
// WriteMotorOneReg(H_MOTOR, H02_CONTR_MODE_SELEC, 0);//H0200,选择速度模式
|
WriteMotorOneReg(H_MOTOR, H02_CONTR_MODE_SELEC, 0);//H0200,选择速度模式
|
||||||
// OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
||||||
|
|
||||||
// WriteMotorOneReg(H_MOTOR, H04_DO1_FUNC_SELEC, 19);
|
WriteMotorOneReg(H_MOTOR, H04_DO1_FUNC_SELEC, 19);
|
||||||
// OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
||||||
|
|
||||||
// WriteMotorOneReg(H_MOTOR, H06_SPEED_COMMU_SET_VALUE, 100);//速度设置为100rpm
|
WriteMotorOneReg(H_MOTOR, H06_SPEED_COMMU_SET_VALUE, 100);//速度设置为100rpm
|
||||||
// OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
||||||
|
|
||||||
// WriteMotorOneReg(H_MOTOR, H06_SPEED_UP_SLOPE_VALUE, 3000);//加速度3000
|
WriteMotorOneReg(H_MOTOR, H06_SPEED_UP_SLOPE_VALUE, 3000);//加速度3000
|
||||||
// OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
||||||
|
|
||||||
// WriteMotorOneReg(H_MOTOR, H06_SPEED_DOWN_SLOPE_VALUE, 2000);//减速度2000
|
WriteMotorOneReg(H_MOTOR, H06_SPEED_DOWN_SLOPE_VALUE, 2000);//减速度2000
|
||||||
// OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
||||||
|
|
||||||
// WriteMotorOneReg(H_MOTOR, H03_DI1_LOGICAL_SELEC, 1);//只启动水平电机
|
WriteMotorOneReg(H_MOTOR, H03_DI1_LOGICAL_SELEC, 1);//只启动水平电机
|
||||||
// OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
OSTimeDlyHMSM(0u, 0u, 0u, 5u);
|
||||||
}
|
}
|
|
@ -78,6 +78,6 @@ bool MotorReplyForWrite(uint8_t motorNo, uint8_t* userBuff, uint8_t len);
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void servoMotorInit(void);
|
void servoMotorInit(void);
|
||||||
uint8_t WriteMotorOneReg_buffer(uint8_t motorNo, uint16_t regAddr, uint16_t data, uint8_t *frameBuff);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -741,7 +741,7 @@
|
||||||
<data>
|
<data>
|
||||||
<extensions></extensions>
|
<extensions></extensions>
|
||||||
<cmdline></cmdline>
|
<cmdline></cmdline>
|
||||||
<hasPrio>56</hasPrio>
|
<hasPrio>1</hasPrio>
|
||||||
<buildSequence>inputOutputBased</buildSequence>
|
<buildSequence>inputOutputBased</buildSequence>
|
||||||
</data>
|
</data>
|
||||||
</settings>
|
</settings>
|
||||||
|
@ -826,7 +826,7 @@
|
||||||
</option>
|
</option>
|
||||||
<option>
|
<option>
|
||||||
<name>IlinkIcfFile</name>
|
<name>IlinkIcfFile</name>
|
||||||
<state>D:\psx\Pan-Tilt\1.software\HY\new_ptz\servoMotor\BSP\IAR\GD32F450xE.icf</state>
|
<state>D:\CompanyCode\newPro\servoMotor_xr\BSP\IAR\GD32F450xE.icf</state>
|
||||||
</option>
|
</option>
|
||||||
<option>
|
<option>
|
||||||
<name>IlinkIcfFileSlave</name>
|
<name>IlinkIcfFileSlave</name>
|
||||||
|
|
Loading…
Reference in New Issue