发送接收修改完毕,等待测试
This commit is contained in:
parent
d9df2548c5
commit
a2bbae0271
|
@ -21,7 +21,10 @@ static void ptz_recv_hori_servo_task()
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
OSSemPend(g_horiMotorMutex, 0, &err);
|
OSSemPend(g_horiMotorMutex, 0, &err);
|
||||||
|
if ( MotorReplyForWrite(H_MOTOR) == true )
|
||||||
|
{
|
||||||
|
OSSemPost(g_horiSpeedMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -289,8 +289,6 @@ static void creat_task_vert_servo_task(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void init_speed_module(void)
|
void init_speed_module(void)
|
||||||
{
|
{
|
||||||
g_horiSpeedSem = OSSemCreate(0);
|
g_horiSpeedSem = OSSemCreate(0);
|
||||||
|
@ -327,14 +325,12 @@ 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();
|
||||||
|
// creat_task_test();
|
||||||
|
|
||||||
|
|
||||||
OSTimeDlyHMSM(0u, 0u, 0u, 500u);//等待硬件初始化成功
|
OSTimeDlyHMSM(0u, 0u, 0u, 500u);//等待硬件初始化成功
|
||||||
|
servoSendData(horiMotorType, WriteMotorOneReg(H_MOTOR, H02_CONTR_MODE_SELEC, 0)
|
||||||
uint8_t buffer[20] = {0};
|
, WRITE_ONE_REG_FRAME_NUM, lowPriority);
|
||||||
uint8_t buffer_len = 0;
|
|
||||||
buffer_len = WriteMotorOneReg_buffer(H_MOTOR, H02_CONTR_MODE_SELEC, 0, buffer);
|
|
||||||
servoSendData(horiMotorType, buffer, buffer_len, lowPriority);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -99,11 +99,9 @@ static MotorCommuDmaHwInfo_t g_MotorDmaBuff[] =
|
||||||
********************************************************************************************************
|
********************************************************************************************************
|
||||||
*/
|
*/
|
||||||
/* dma接收缓冲区 */
|
/* dma接收缓冲区 */
|
||||||
static uint8_t g_horiDmaRxBuff1[DMA_BUFF_SIZE] = {0};//水平电机DMA接受缓存区1
|
static uint8_t g_horiDmaRxBuff[DMA_BUFF_SIZE] = {0};//水平电机DMA接受缓存区
|
||||||
static uint8_t g_horiDmaRxBuff2[DMA_BUFF_SIZE] = {0};//水平电机DMA接受缓存区2
|
|
||||||
|
|
||||||
static uint8_t g_vertDmaRxBuff1[DMA_BUFF_SIZE] = {0};//垂直电机DMA接受缓存区1
|
static uint8_t g_vertDmaRxBuff[DMA_BUFF_SIZE] = {0};//垂直电机DMA接受缓存区
|
||||||
static uint8_t g_vertDmaRxBuff2[DMA_BUFF_SIZE] = {0};//垂直电机DMA接受缓存区2
|
|
||||||
/* 处理串口通讯与数据缓冲的数据结构 */
|
/* 处理串口通讯与数据缓冲的数据结构 */
|
||||||
static CommuInfo_t g_horiCommuDeal; //水平电机
|
static CommuInfo_t g_horiCommuDeal; //水平电机
|
||||||
static CommuInfo_t g_vertCommuDeal; //垂直电机
|
static CommuInfo_t g_vertCommuDeal; //垂直电机
|
||||||
|
@ -111,22 +109,19 @@ static CommuInfo_t g_vertCommuDeal; //
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
CommuInfo_t* pCommuInfo; //串口通讯与数据缓冲相关的数据结构
|
CommuInfo_t* pCommuInfo; //串口通讯与数据缓冲相关的数据结构
|
||||||
uint8_t* dmaRxBuff1; //dma接受缓存区1指针
|
uint8_t* dmaRxBuff; //dma接受缓存区指针
|
||||||
uint8_t* dmaRxBuff2; //dma接受缓存区2指针
|
|
||||||
}CommuHwInfo_t;//方便缓冲区初始化的结构体
|
}CommuHwInfo_t;//方便缓冲区初始化的结构体
|
||||||
static CommuHwInfo_t g_commuInfoBuff[] =
|
static CommuHwInfo_t g_commuInfoBuff[] =
|
||||||
{
|
{
|
||||||
//水平电机
|
//水平电机
|
||||||
{
|
{
|
||||||
.pCommuInfo = &g_horiCommuDeal,
|
.pCommuInfo = &g_horiCommuDeal,
|
||||||
.dmaRxBuff1 = g_horiDmaRxBuff1,
|
.dmaRxBuff = g_horiDmaRxBuff,
|
||||||
.dmaRxBuff2 = g_horiDmaRxBuff2,
|
|
||||||
},
|
},
|
||||||
//垂直电机串口5
|
//垂直电机串口5
|
||||||
{
|
{
|
||||||
.pCommuInfo = &g_vertCommuDeal,
|
.pCommuInfo = &g_vertCommuDeal,
|
||||||
.dmaRxBuff1 = g_vertDmaRxBuff1,
|
.dmaRxBuff = g_vertDmaRxBuff,
|
||||||
.dmaRxBuff2 = g_vertDmaRxBuff2,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -219,7 +214,7 @@ static void DmaCofig(void)
|
||||||
//dma配置
|
//dma配置
|
||||||
dma_deinit(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch);
|
dma_deinit(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch);
|
||||||
dmaStruct.direction = DMA_PERIPH_TO_MEMORY;
|
dmaStruct.direction = DMA_PERIPH_TO_MEMORY;
|
||||||
dmaStruct.memory0_addr = (uint32_t)(g_commuInfoBuff[i].pCommuInfo->pDmaRsvBuff1);
|
dmaStruct.memory0_addr = (uint32_t)(g_commuInfoBuff[i].pCommuInfo->pDmaRsvBuff);
|
||||||
dmaStruct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
|
dmaStruct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
|
||||||
dmaStruct.number = DMA_BUFF_SIZE;
|
dmaStruct.number = DMA_BUFF_SIZE;
|
||||||
dmaStruct.periph_addr = g_MotorDmaBuff[i].periphAddr;
|
dmaStruct.periph_addr = g_MotorDmaBuff[i].periphAddr;
|
||||||
|
@ -229,11 +224,11 @@ static void DmaCofig(void)
|
||||||
dma_memory_width_config(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, DMA_MEMORY_WIDTH_8BIT);
|
dma_memory_width_config(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, DMA_MEMORY_WIDTH_8BIT);
|
||||||
dma_periph_width_config(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, DMA_PERIPH_WIDTH_8BIT);
|
dma_periph_width_config(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, DMA_PERIPH_WIDTH_8BIT);
|
||||||
dma_single_data_mode_init(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, &dmaStruct);
|
dma_single_data_mode_init(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, &dmaStruct);
|
||||||
dma_circulation_disable(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch);//非循环模式
|
dma_circulation_enable(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch);//循环模式
|
||||||
dma_channel_subperipheral_select(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, g_MotorDmaBuff[i].dmaPeriph);
|
dma_channel_subperipheral_select(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, g_MotorDmaBuff[i].dmaPeriph);
|
||||||
//中断配置
|
//中断配置
|
||||||
nvic_irq_enable(g_MotorDmaBuff[i].dmaRxIrq, 4, 2);
|
// nvic_irq_enable(g_MotorDmaBuff[i].dmaRxIrq, 4, 2);
|
||||||
dma_interrupt_enable(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, DMA_CHXCTL_FTFIE);
|
// dma_interrupt_enable(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch, DMA_CHXCTL_FTFIE);
|
||||||
dma_channel_enable(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch);
|
dma_channel_enable(g_MotorDmaBuff[i].dmaNo, g_MotorDmaBuff[i].dmaRxch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,9 +252,7 @@ static void CommuStructInit()
|
||||||
CommuInfo_t *pCommuDeal = g_commuInfoBuff[i].pCommuInfo;
|
CommuInfo_t *pCommuDeal = g_commuInfoBuff[i].pCommuInfo;
|
||||||
pCommuDeal->dmaTranFlag = DMA_TRANS_IDLE;
|
pCommuDeal->dmaTranFlag = DMA_TRANS_IDLE;
|
||||||
pCommuDeal->dmaSize = DMA_BUFF_SIZE;
|
pCommuDeal->dmaSize = DMA_BUFF_SIZE;
|
||||||
pCommuDeal->pDmaRsvBuff1 = g_commuInfoBuff[i].dmaRxBuff1;
|
pCommuDeal->pDmaRsvBuff = g_commuInfoBuff[i].dmaRxBuff;
|
||||||
pCommuDeal->pDmaRsvBuff2 = g_commuInfoBuff[i].dmaRxBuff2;
|
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;//默认使用缓冲区1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,37 +314,25 @@ void DMA0_Channel3_IRQHandler(void)
|
||||||
* @return
|
* @return
|
||||||
***********************************************************
|
***********************************************************
|
||||||
*/
|
*/
|
||||||
|
static uint16_t g_horiLastPos;
|
||||||
|
static uint16_t g_horiNowPos;
|
||||||
void USART2_IRQHandler(void)
|
void USART2_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* 串口的接收空闲中断方式进行了数据缓存。*/
|
/* 串口的接收空闲中断方式进行了数据缓存。*/
|
||||||
dma_single_data_parameter_struct dmaStruct;
|
|
||||||
if(RESET != usart_interrupt_flag_get(g_motorCommuBuff[H_MOTOR].uartNo, USART_INT_FLAG_IDLE))
|
if(RESET != usart_interrupt_flag_get(g_motorCommuBuff[H_MOTOR].uartNo, USART_INT_FLAG_IDLE))
|
||||||
{
|
{
|
||||||
/* clear IDLE flag */
|
/* clear IDLE flag */
|
||||||
usart_interrupt_flag_clear(g_motorCommuBuff[H_MOTOR].uartNo, USART_INT_FLAG_IDLE); //第一步,读取stat0寄存器,清除IDLE标志位
|
usart_interrupt_flag_clear(g_motorCommuBuff[H_MOTOR].uartNo, USART_INT_FLAG_IDLE); //第一步,读取stat0寄存器,清除IDLE标志位
|
||||||
usart_data_receive(g_motorCommuBuff[H_MOTOR].uartNo); //第二步,读取数据寄存器,清除IDLE标志位
|
usart_data_receive(g_motorCommuBuff[H_MOTOR].uartNo); //第二步,读取数据寄存器,清除IDLE标志位
|
||||||
|
|
||||||
|
// CommuInfo_t *pCommuDeal = g_commuInfoBuff[H_MOTOR].pCommuInfo;
|
||||||
|
|
||||||
|
g_horiLastPos = g_horiNowPos;
|
||||||
|
g_horiNowPos = DMA_BUFF_SIZE - dma_transfer_number_get(g_MotorDmaBuff[H_MOTOR].dmaNo,
|
||||||
|
g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
||||||
|
|
||||||
//释放信号量,通知接收到一包数据,任务可以处理了
|
//释放信号量,通知接收到一包数据,任务可以处理了
|
||||||
OSSemPost(g_horiMotorMutex);
|
OSSemPost(g_horiMotorMutex);
|
||||||
CommuInfo_t *pCommuDeal = g_commuInfoBuff[H_MOTOR].pCommuInfo;
|
|
||||||
/* 切换使用接收缓冲区,这样上层的解析永远从第一个字节起*/
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*计算在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);//获取的是还有多少个没传输,而不是已经传输了多少
|
||||||
|
@ -361,40 +342,14 @@ void USART2_IRQHandler(void)
|
||||||
|
|
||||||
void DMA0_Channel1_IRQHandler(void)
|
void DMA0_Channel1_IRQHandler(void)
|
||||||
{
|
{
|
||||||
dma_single_data_parameter_struct dmaStruct;
|
|
||||||
/*
|
/*
|
||||||
* 配合串口1的接收空闲中断。功能是复位DMA的偏移量
|
|
||||||
* 1、为了串口1的空闲中断在处理数据时防止越界,将 pUartAttr->DamOffset置为0;
|
* 注意:DMA为正常模式,那么当完成一次拷贝后,DMA会自动disable掉。
|
||||||
* 2、DMA为循环方式进行数据搬运的,当搬运完配置的Cnt后,会进入此中断处理函数,
|
|
||||||
* 3、当有数据过来时,数据将会拷贝到缓冲区的起始位置;
|
|
||||||
* 4、注意:如果DMA为正常模式,那么当完成一次拷贝后,DMA会自动disable掉。
|
|
||||||
*/
|
*/
|
||||||
if(dma_interrupt_flag_get(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, DMA_INT_FLAG_FTF))
|
if(dma_interrupt_flag_get(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, DMA_INT_FLAG_FTF))
|
||||||
{
|
{
|
||||||
dma_interrupt_flag_clear(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, DMA_INT_FLAG_FTF);
|
dma_interrupt_flag_clear(g_MotorDmaBuff[H_MOTOR].dmaNo, g_MotorDmaBuff[H_MOTOR].dmaRxch, DMA_INT_FLAG_FTF);
|
||||||
|
|
||||||
CommuInfo_t *pCommuDeal = g_commuInfoBuff[H_MOTOR].pCommuInfo;
|
|
||||||
//释放信号量,通知接收到一包数据,任务可以处理了
|
|
||||||
OSSemPost(g_horiMotorMutex);
|
|
||||||
/* 切换使用接收缓冲区,这样上层的解析永远从第一个字节起*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,9 +391,10 @@ void DMA1_Channel7_IRQHandler(void)
|
||||||
* @return
|
* @return
|
||||||
***********************************************************
|
***********************************************************
|
||||||
*/
|
*/
|
||||||
|
static uint16_t g_vertLastPos;
|
||||||
|
static uint16_t g_vertNowPos;
|
||||||
void USART5_IRQHandler(void)
|
void USART5_IRQHandler(void)
|
||||||
{
|
{
|
||||||
dma_single_data_parameter_struct dmaStruct;
|
|
||||||
/* 串口的接收空闲中断方式进行了数据缓存。*/
|
/* 串口的接收空闲中断方式进行了数据缓存。*/
|
||||||
if(RESET != usart_interrupt_flag_get(g_motorCommuBuff[V_MOTOR].uartNo, USART_INT_FLAG_IDLE))
|
if(RESET != usart_interrupt_flag_get(g_motorCommuBuff[V_MOTOR].uartNo, USART_INT_FLAG_IDLE))
|
||||||
{
|
{
|
||||||
|
@ -446,69 +402,26 @@ void USART5_IRQHandler(void)
|
||||||
usart_interrupt_flag_clear(g_motorCommuBuff[V_MOTOR].uartNo, USART_INT_FLAG_IDLE); //第一步,读取stat0寄存器,清除IDLE标志位
|
usart_interrupt_flag_clear(g_motorCommuBuff[V_MOTOR].uartNo, USART_INT_FLAG_IDLE); //第一步,读取stat0寄存器,清除IDLE标志位
|
||||||
usart_data_receive(g_motorCommuBuff[V_MOTOR].uartNo); //第二步,读取数据寄存器,清除IDLE标志位
|
usart_data_receive(g_motorCommuBuff[V_MOTOR].uartNo); //第二步,读取数据寄存器,清除IDLE标志位
|
||||||
|
|
||||||
|
g_vertLastPos = g_vertNowPos;
|
||||||
|
g_vertNowPos = DMA_BUFF_SIZE - dma_transfer_number_get(g_MotorDmaBuff[H_MOTOR].dmaNo,
|
||||||
|
g_MotorDmaBuff[H_MOTOR].dmaRxch);
|
||||||
//释放信号量,通知接收到一包数据,任务可以处理了
|
//释放信号量,通知接收到一包数据,任务可以处理了
|
||||||
OSSemPost(g_horiMotorMutex);
|
OSSemPost(g_vertMotorMutex);
|
||||||
CommuInfo_t *pCommuDeal = g_commuInfoBuff[V_MOTOR].pCommuInfo;
|
|
||||||
/* 切换使用接收缓冲区,这样上层的解析永远从第一个字节起*/
|
|
||||||
if ( pCommuDeal->pDmaRsvBuffSelect == DMA_RSVBUFF_SELECT1 )
|
|
||||||
{
|
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT2;
|
|
||||||
dma_channel_disable(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
|
||||||
dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff2);
|
|
||||||
dma_single_data_mode_init(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
dma_channel_enable(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;
|
|
||||||
dma_channel_disable(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
|
||||||
dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff1);
|
|
||||||
dma_single_data_mode_init(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
dma_channel_enable(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// uint8_t rx_OK = 0;
|
|
||||||
void DMA1_Channel1_IRQHandler(void)
|
void DMA1_Channel1_IRQHandler(void)
|
||||||
{
|
{
|
||||||
dma_single_data_parameter_struct dmaStruct;
|
|
||||||
/*
|
/*
|
||||||
* 配合串口1的接收空闲中断。功能是复位DMA的偏移量
|
* 注意:如果DMA为正常模式,那么当完成一次拷贝后,DMA会自动disable掉。
|
||||||
* 1、为了串口1的空闲中断在处理数据时防止越界,将 pUartAttr->DamOffset置为0;
|
|
||||||
* 2、DMA为循环方式进行数据搬运的,当搬运完配置的Cnt后,会进入此中断处理函数,
|
|
||||||
* 3、当有数据过来时,数据将会拷贝到缓冲区的起始位置;
|
|
||||||
* 4、注意:如果DMA为正常模式,那么当完成一次拷贝后,DMA会自动disable掉。
|
|
||||||
*/
|
*/
|
||||||
if(dma_interrupt_flag_get(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch, DMA_INT_FLAG_FTF))
|
if(dma_interrupt_flag_get(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch, DMA_INT_FLAG_FTF))
|
||||||
{
|
{
|
||||||
dma_interrupt_flag_clear(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch, DMA_INT_FLAG_FTF);
|
dma_interrupt_flag_clear(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch, DMA_INT_FLAG_FTF);
|
||||||
|
|
||||||
CommuInfo_t *pCommuDeal = g_commuInfoBuff[V_MOTOR].pCommuInfo;
|
// CommuInfo_t *pCommuDeal = g_commuInfoBuff[V_MOTOR].pCommuInfo;
|
||||||
//释放信号量,通知接收到一包数据,任务可以处理了
|
//释放信号量,通知接收到一包数据,任务可以处理了
|
||||||
OSSemPost(g_horiMotorMutex);
|
// OSSemPost(g_vertMotorMutex);
|
||||||
/* 切换使用接收缓冲区,这样上层的解析永远从第一个字节起*/
|
|
||||||
if ( pCommuDeal->pDmaRsvBuffSelect == DMA_RSVBUFF_SELECT1 )
|
|
||||||
{
|
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT2;
|
|
||||||
dma_channel_disable(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
|
||||||
dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff2);
|
|
||||||
dmaStruct.number = DMA_BUFF_SIZE;
|
|
||||||
dma_single_data_mode_init(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
dma_channel_enable(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pCommuDeal->pDmaRsvBuffSelect = DMA_RSVBUFF_SELECT1;
|
|
||||||
dma_channel_disable(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch);//切换缓冲区,配置缓冲区长度需要先禁用DMA
|
|
||||||
dmaStruct.memory0_addr = (uint32_t)(pCommuDeal->pDmaRsvBuff1);
|
|
||||||
dmaStruct.number = DMA_BUFF_SIZE;
|
|
||||||
dma_single_data_mode_init(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch, &dmaStruct);
|
|
||||||
dma_channel_enable(g_MotorDmaBuff[V_MOTOR].dmaNo, g_MotorDmaBuff[V_MOTOR].dmaRxch);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -539,6 +452,13 @@ void CommuDrvInit(void)
|
||||||
*/
|
*/
|
||||||
bool CommuTransData(uint8_t motorNo, uint8_t* buffer, int32_t len)
|
bool CommuTransData(uint8_t motorNo, uint8_t* buffer, int32_t len)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/*简易判断*/
|
||||||
|
if( buffer == NULL || len == 0 )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*485切换为发送*/
|
||||||
if( motorNo == H_MOTOR )
|
if( motorNo == H_MOTOR )
|
||||||
{
|
{
|
||||||
H_COMMU_RS485_TX;
|
H_COMMU_RS485_TX;
|
||||||
|
@ -563,20 +483,43 @@ bool CommuTransData(uint8_t motorNo, uint8_t* buffer, int32_t len)
|
||||||
/**
|
/**
|
||||||
* @brief 从接收循环缓冲区中读取指定长度的数据到用户数组
|
* @brief 从接收循环缓冲区中读取指定长度的数据到用户数组
|
||||||
* @param motorNo:电机号,H_MOTOR:水平电机,V_MOTOR:垂直电机
|
* @param motorNo:电机号,H_MOTOR:水平电机,V_MOTOR:垂直电机
|
||||||
* @param userBuff:从接收循环缓冲区中接收数据的数组
|
* @param userBuff:从接收缓冲区中接收数据的数组
|
||||||
* @param len:接收数据的长度
|
* @param len:接收数据的长度
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void CommuRsvData(uint8_t motorNo, uint8_t* userBuff, uint32_t len)
|
bool CommuRsvData(uint8_t motorNo, uint8_t* userBuff, uint32_t len)
|
||||||
{
|
{
|
||||||
|
|
||||||
CommuInfo_t *pCommuDeal = g_commuInfoBuff[motorNo].pCommuInfo;
|
CommuInfo_t *pCommuDeal = g_commuInfoBuff[motorNo].pCommuInfo;
|
||||||
if ( pCommuDeal->pDmaRsvBuffSelect == DMA_RSVBUFF_SELECT1 )
|
/*简易判断*/
|
||||||
|
if( userBuff == NULL || len == 0 )
|
||||||
{
|
{
|
||||||
memcpy(userBuff, pCommuDeal->pDmaRsvBuff2, len);
|
return false;
|
||||||
|
}
|
||||||
|
/*接收DMA缓冲区数据*/
|
||||||
|
if ( motorNo == H_MOTOR )
|
||||||
|
{
|
||||||
|
if ( ( (g_horiLastPos + len) % DMA_BUFF_SIZE ) != g_horiNowPos )//假如是写寄存器,电机返回消息正常是8字节,但如果是写错误,则返回非8字节错误码
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for(uint8_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
*(userBuff+i) = pCommuDeal->pDmaRsvBuff[g_horiLastPos];
|
||||||
|
g_horiLastPos = (g_horiLastPos + 1) % DMA_BUFF_SIZE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(userBuff, pCommuDeal->pDmaRsvBuff1, len);
|
if ( ( (g_vertLastPos + len) % DMA_BUFF_SIZE ) != g_vertNowPos )//假如是写寄存器,电机返回消息正常是8字节,但如果是写错误,则返回非8字节错误码
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
for(uint8_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
*(userBuff+i) = pCommuDeal->pDmaRsvBuff[g_vertLastPos];
|
||||||
|
g_horiLastPos = (g_vertLastPos + 1) % DMA_BUFF_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,16 +13,12 @@ typedef struct
|
||||||
{
|
{
|
||||||
int16_t dmaTranFlag; /*dma发送是否在工作的标志位*/
|
int16_t dmaTranFlag; /*dma发送是否在工作的标志位*/
|
||||||
int32_t dmaSize; /*DMA接收缓冲区的大小*/
|
int32_t dmaSize; /*DMA接收缓冲区的大小*/
|
||||||
uint8_t *pDmaRsvBuff1; /*指向接收DMA缓冲区1的首地址*/
|
uint8_t *pDmaRsvBuff; /*指向接收DMA缓冲区的首地址*/
|
||||||
uint8_t *pDmaRsvBuff2; /*指向接收DMA缓冲区2的首地址*/
|
|
||||||
uint8_t pDmaRsvBuffSelect; /*表示当前正在使用哪个接收缓冲区*/
|
|
||||||
}CommuInfo_t;
|
}CommuInfo_t;
|
||||||
|
|
||||||
#define DMA_TRANS_IDLE 0//dma当前未在发送数据
|
#define DMA_TRANS_IDLE 0//dma当前未在发送数据
|
||||||
#define DMA_TRANS_BUSY 1//dma当前正在发送数据
|
#define DMA_TRANS_BUSY 1//dma当前正在发送数据
|
||||||
#define DMA_BUFF_SIZE 64//dma缓冲区大小
|
#define DMA_BUFF_SIZE 64//dma缓冲区大小
|
||||||
#define DMA_RSVBUFF_SELECT1 (uint8_t)(0)//当前使用dma接收缓冲区1
|
|
||||||
#define DMA_RSVBUFF_SELECT2 (uint8_t)(1)//当前使用dma接收缓冲区2
|
|
||||||
|
|
||||||
//extern CommuInfo_t g_commuDeal;//来自motorCommu.c
|
//extern CommuInfo_t g_commuDeal;//来自motorCommu.c
|
||||||
|
|
||||||
|
@ -63,7 +59,7 @@ bool CommuTransData(uint8_t motorNo, uint8_t* buffer, int32_t len);
|
||||||
* @param len:接收数据的长度
|
* @param len:接收数据的长度
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void CommuRsvData(uint8_t motorNo, uint8_t* userBuff, uint32_t len);
|
bool CommuRsvData(uint8_t motorNo, uint8_t* userBuff, uint32_t len);
|
||||||
|
|
||||||
|
|
||||||
///*用于结构体数组赋值,方便外部使用此结构体数组*/
|
///*用于结构体数组赋值,方便外部使用此结构体数组*/
|
||||||
|
|
|
@ -16,8 +16,6 @@ static void MotorSwitchGpioCofig(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t g_writeOneRegBuff[WRITE_ONE_REG_BUFFNUM];//由于写寄存器,电机返回的数据和写入的数据完全一致,故设此数组
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
从机地址 功能码 寄存器地址高 寄存器地址低 数据高位 数据低位 crc校验高位 crc校验低位
|
从机地址 功能码 寄存器地址高 寄存器地址低 数据高位 数据低位 crc校验高位 crc校验低位
|
||||||
|
@ -28,92 +26,121 @@ static uint8_t g_writeOneRegBuff[WRITE_ONE_REG_BUFFNUM];//
|
||||||
* @param motorNo:写垂直电机还是水平电机
|
* @param motorNo:写垂直电机还是水平电机
|
||||||
* @param regAddr:要写的寄存器
|
* @param regAddr:要写的寄存器
|
||||||
* @param data:要向寄存器写入的数据
|
* @param data:要向寄存器写入的数据
|
||||||
* @return false:写失败,当前DMA正在发送数据
|
* @return 返回数组地址
|
||||||
*/
|
*/
|
||||||
bool WriteMotorOneReg(uint8_t motorNo, uint16_t regAddr, uint16_t data)
|
static uint8_t g_writeOneRegBuff[WRITE_ONE_REG_FRAME_NUM];
|
||||||
|
uint8_t* WriteMotorOneReg(uint8_t motorNo, uint16_t regAddr, uint16_t data)
|
||||||
{
|
{
|
||||||
uint8_t frameBuff[WRITE_ONE_REG_BUFFNUM] = {0};
|
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
if ( motorNo == H_MOTOR )
|
if ( motorNo == H_MOTOR )
|
||||||
{
|
{
|
||||||
frameBuff[0] = H_MOTOR_ADDR;//由于采用一主一从模式,所以水平电机垂直电机从机地址都是0x01,云台后期也不会扩展
|
g_writeOneRegBuff[0] = H_MOTOR_ADDR;//由于采用一主一从模式,所以水平电机垂直电机从机地址都是0x01,云台后期也不会扩展
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
frameBuff[0] = V_MOTOR_ADDR;
|
g_writeOneRegBuff[0] = V_MOTOR_ADDR;
|
||||||
}
|
}
|
||||||
frameBuff[1] = WRITE_ONE_REG;
|
g_writeOneRegBuff[1] = WRITE_ONE_REG;
|
||||||
frameBuff[2] = regAddr >> WRITE_ONE_REG_BUFFNUM;
|
g_writeOneRegBuff[2] = regAddr >> 8;
|
||||||
frameBuff[3] = regAddr & 0xff;
|
g_writeOneRegBuff[3] = regAddr & 0xff;
|
||||||
frameBuff[4] = data >> WRITE_ONE_REG_BUFFNUM;
|
g_writeOneRegBuff[4] = data >> 8;
|
||||||
frameBuff[5] = data & 0xff;
|
g_writeOneRegBuff[5] = data & 0xff;
|
||||||
crc = ModbusCRC16(frameBuff, WRITE_ONE_REG_BUFFNUM - 2);
|
crc = ModbusCRC16(g_writeOneRegBuff, WRITE_ONE_REG_FRAME_NUM - 2);
|
||||||
frameBuff[6] = crc & 0xff;
|
g_writeOneRegBuff[6] = crc & 0xff;
|
||||||
frameBuff[7] = crc >> WRITE_ONE_REG_BUFFNUM;
|
g_writeOneRegBuff[7] = crc >> 8;
|
||||||
|
return g_writeOneRegBuff;
|
||||||
if ( CommuTransData(motorNo, frameBuff, WRITE_ONE_REG_BUFFNUM) == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
memcpy(g_writeOneRegBuff, frameBuff, WRITE_ONE_REG_BUFFNUM);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 写单个寄存器成功后,电机会返回一帧与写格式完全一致的数据
|
* @brief 写单个寄存器成功后,电机会返回一帧与写格式完全一致的数据
|
||||||
* @param motorNo:写垂直电机还是水平电机
|
* @param motorNo:写垂直电机还是水平电机
|
||||||
* @param userBuff:用来接收返回的数据的数组
|
|
||||||
* @param len:接收的数据长度,对于此函数必须为WRITE_ONE_REG_BUFFNUM
|
|
||||||
* @return false:错误,读出的内容与写入的内容不一致
|
* @return false:错误,读出的内容与写入的内容不一致
|
||||||
*/
|
*/
|
||||||
bool MotorReplyForWrite(uint8_t motorNo, uint8_t* userBuff, uint8_t len)
|
bool MotorReplyForWrite(uint8_t motorNo)
|
||||||
{
|
{
|
||||||
CommuRsvData(motorNo, userBuff, len);
|
static uint8_t motorReplybuff[WRITE_ONE_REG_FRAME_NUM];
|
||||||
for( uint8_t i = 0; i < len; i++ )
|
/*提取数据失败*/
|
||||||
|
if ( CommuRsvData(motorNo, motorReplybuff, WRITE_ONE_REG_FRAME_NUM) == false )
|
||||||
{
|
{
|
||||||
if ( userBuff[i] != g_writeOneRegBuff[i] )
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for( uint8_t i = 0; i < WRITE_ONE_REG_FRAME_NUM; i++ )
|
||||||
|
{
|
||||||
|
/*提取的数据不对*/
|
||||||
|
if ( motorReplybuff[i] != g_writeOneRegBuff[i] )
|
||||||
{
|
{
|
||||||
memset(g_writeOneRegBuff, 0x00, len);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memset(g_writeOneRegBuff, 0x00, len);
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
从机地址 功能码 寄存器地址高 寄存器地址低 数据高位 数据低位 crc校验高位 crc校验低位
|
从机地址 功能码 寄存器地址高 寄存器地址低 reg数量高位 数量低位 crc校验高位 crc校验低位
|
||||||
01H 06H 02H 00H 00H 01H 49H B2H
|
01H 03H 0BH 00H 00H 01H 86H 2EH
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @brief 伺服电机速度模式写单个寄存器
|
* @brief 伺服电机速度模式读单个寄存器
|
||||||
* @param motorNo:写垂直电机还是水平电机
|
* @param motorNo:读垂直电机还是水平电机
|
||||||
* @param regAddr:要写的寄存器
|
* @param regAddr:要读的寄存器
|
||||||
* @param data:要向寄存器写入的数据
|
* @return 返回数组地址
|
||||||
* @param frameBuff: 用来发送的数组
|
|
||||||
* @return 写入frameBuff的长度
|
|
||||||
*/
|
*/
|
||||||
uint8_t WriteMotorOneReg_buffer(uint8_t motorNo, uint16_t regAddr, uint16_t data, uint8_t *frameBuff)
|
static uint8_t g_readOneRegBuff[READ_ONE_REG_FRAME_NUM];
|
||||||
|
uint8_t* ReadMotorOneReg(uint8_t motorNo, uint16_t regAddr)
|
||||||
{
|
{
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
if ( motorNo == H_MOTOR )
|
if ( motorNo == H_MOTOR )
|
||||||
{
|
{
|
||||||
frameBuff[0] = H_MOTOR_ADDR;//由于采用一主一从模式,所以水平电机垂直电机从机地址都是0x01,云台后期也不会扩展
|
g_readOneRegBuff[0] = H_MOTOR_ADDR;//由于采用一主一从模式,所以水平电机垂直电机从机地址都是0x01,云台后期也不会扩展
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
frameBuff[0] = V_MOTOR_ADDR;
|
g_readOneRegBuff[0] = V_MOTOR_ADDR;
|
||||||
}
|
}
|
||||||
frameBuff[1] = WRITE_ONE_REG;
|
g_readOneRegBuff[1] = READ_ONE_REG;
|
||||||
frameBuff[2] = regAddr >> WRITE_ONE_REG_BUFFNUM;
|
g_readOneRegBuff[2] = regAddr >> 8;
|
||||||
frameBuff[3] = regAddr & 0xff;
|
g_readOneRegBuff[3] = regAddr & 0xff;
|
||||||
frameBuff[4] = data >> WRITE_ONE_REG_BUFFNUM;
|
g_readOneRegBuff[4] = 0x00;
|
||||||
frameBuff[5] = data & 0xff;
|
g_readOneRegBuff[5] = 0x01;
|
||||||
crc = ModbusCRC16(frameBuff, WRITE_ONE_REG_BUFFNUM - 2);
|
crc = ModbusCRC16(g_readOneRegBuff, READ_ONE_REG_FRAME_NUM - 2);
|
||||||
frameBuff[6] = crc & 0xff;
|
g_readOneRegBuff[6] = crc & 0xff;
|
||||||
frameBuff[7] = crc >> WRITE_ONE_REG_BUFFNUM;
|
g_readOneRegBuff[7] = crc >> 8;
|
||||||
|
return g_readOneRegBuff;
|
||||||
return 8;
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
从机地址 功能码 返回数据字节数 返回数据高位 返回数据低位 crc校验高位 crc校验低位
|
||||||
|
01H 03H 02H 00H 00H B8H 44H
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @brief 读单个寄存器命令发送成功后,电机会返回一帧7字节的数据
|
||||||
|
* @param motorNo:写垂直电机还是水平电机
|
||||||
|
* @param data:写垂直电机还是水平电机
|
||||||
|
* @return false:错误,读出的内容与写入的内容不一致
|
||||||
|
*/
|
||||||
|
bool MotorReplyForRead(uint8_t motorNo, uint16_t* data)
|
||||||
|
{
|
||||||
|
/*简易判断*/
|
||||||
|
if ( data == NULL )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
static uint8_t motorReplybuff[WRITE_ONE_REG_FRAME_NUM - 1];
|
||||||
|
/*提取数据失败*/
|
||||||
|
if ( CommuRsvData(motorNo, motorReplybuff, WRITE_ONE_REG_FRAME_NUM - 1) == false )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*data = motorReplybuff[3];
|
||||||
|
*data = (*data << 8) | motorReplybuff[4];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 伺服电机驱动初始化
|
* @brief 伺服电机驱动初始化
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
#define WRITE_ONE_REG 0X06//写单个寄存器
|
#define WRITE_ONE_REG 0X06//写单个寄存器
|
||||||
#define WRITE_MULT_CONSE_REG 0x10//写多个连续的寄存器
|
#define WRITE_MULT_CONSE_REG 0x10//写多个连续的寄存器
|
||||||
|
|
||||||
#define WRITE_ONE_REG_BUFFNUM 8//写单个寄存器,数据帧的字节个数
|
#define WRITE_ONE_REG_FRAME_NUM 8//写单个寄存器,数据帧的字节个数
|
||||||
|
#define READ_ONE_REG_FRAME_NUM 8//读单个寄存器,数据帧的字节个数
|
||||||
/*
|
/*
|
||||||
********************************************************************************************************
|
********************************************************************************************************
|
||||||
* 寄存器参数
|
* 寄存器参数
|
||||||
|
@ -61,23 +62,35 @@
|
||||||
* @param data:要向寄存器写入的数据
|
* @param data:要向寄存器写入的数据
|
||||||
* @return false:写失败,当前DMA正在发送数据
|
* @return false:写失败,当前DMA正在发送数据
|
||||||
*/
|
*/
|
||||||
bool WriteMotorOneReg(uint8_t motorNo, uint16_t regAddr, uint16_t data);
|
uint8_t* WriteMotorOneReg(uint8_t motorNo, uint16_t regAddr, uint16_t data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 写单个寄存器成功后,电机会返回一帧与写格式完全一致的数据
|
* @brief 写单个寄存器成功后,电机会返回一帧与写格式完全一致的数据
|
||||||
* @param motorNo:写垂直电机还是水平电机
|
* @param motorNo:写垂直电机还是水平电机
|
||||||
* @param userBuff:用来接收返回的数据的数组
|
|
||||||
* @param len:接收的数据长度,对于此函数必须为WRITE_ONE_REG_BUFFNUM
|
|
||||||
* @return false:错误,读出的内容与写入的内容不一致
|
* @return false:错误,读出的内容与写入的内容不一致
|
||||||
*/
|
*/
|
||||||
bool MotorReplyForWrite(uint8_t motorNo, uint8_t* userBuff, uint8_t len);
|
bool MotorReplyForWrite(uint8_t motorNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 伺服电机速度模式读单个寄存器
|
||||||
|
* @param motorNo:读垂直电机还是水平电机
|
||||||
|
* @param regAddr:要读的寄存器
|
||||||
|
* @return 返回数组地址
|
||||||
|
*/
|
||||||
|
uint8_t* ReadMotorOneReg(uint8_t motorNo, uint16_t regAddr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读单个寄存器命令发送成功后,电机会返回一帧7字节的数据
|
||||||
|
* @param motorNo:写垂直电机还是水平电机
|
||||||
|
* @param data:写垂直电机还是水平电机
|
||||||
|
* @return false:错误,读出的内容与写入的内容不一致
|
||||||
|
*/
|
||||||
|
bool MotorReplyForRead(uint8_t motorNo, uint16_t* data);
|
||||||
/**
|
/**
|
||||||
* @brief 伺服电机驱动初始化
|
* @brief 伺服电机驱动初始化
|
||||||
* @param
|
* @param
|
||||||
* @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