|
|
@ -72,14 +72,18 @@ static int RS485_2_Send(char *_pBuffer, uint32_t _iSize) |
|
|
#ifndef CONFIG_UART_IT_IDLEDMA |
|
|
#ifndef CONFIG_UART_IT_IDLEDMA |
|
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
|
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
|
|
{ |
|
|
{ |
|
|
if (huart->Instance == LPUART1) |
|
|
if (huart->Instance == USART1) |
|
|
{ |
|
|
{ |
|
|
UART_RX_IRQHandler(g_ptRS485_1); |
|
|
UART_RX_IRQHandler(g_ptRS485_1); |
|
|
} |
|
|
} |
|
|
else if (huart->Instance == USART1) |
|
|
else if (huart->Instance == USART3) |
|
|
{ |
|
|
{ |
|
|
UART_RX_IRQHandler(g_ptRS485_2); |
|
|
UART_RX_IRQHandler(g_ptRS485_2); |
|
|
} |
|
|
} |
|
|
|
|
|
else if (huart->Instance == LPUART1) |
|
|
|
|
|
{ |
|
|
|
|
|
//UART_RX_IRQHandler(g_ptRS485_2);
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
@ -100,12 +104,12 @@ static int check_Spoolend(char *_pBuffer, uint32_t _iSize) |
|
|
|
|
|
|
|
|
static void decode_RS485_1(const char *_pBuffer, uint32_t _iSize) |
|
|
static void decode_RS485_1(const char *_pBuffer, uint32_t _iSize) |
|
|
{ |
|
|
{ |
|
|
rd_ComSend(g_ptRS485_1, (char *)_pBuffer, _iSize); |
|
|
//rd_ComWrite(g_ptRS485_1, (char *)_pBuffer, _iSize);
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void decode_RS485_2(const char *_pBuffer, uint32_t _iSize) |
|
|
static void decode_RS485_2(const char *_pBuffer, uint32_t _iSize) |
|
|
{ |
|
|
{ |
|
|
rd_ComSend(g_ptRS485_2, (char *)_pBuffer, _iSize); |
|
|
//rd_ComWrite(g_ptRS485_2, (char *)_pBuffer, _iSize);
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void decode_Spoolend(const char *_pBuffer, uint32_t _iSize) |
|
|
static void decode_Spoolend(const char *_pBuffer, uint32_t _iSize) |
|
|
@ -136,42 +140,42 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Myprint_Init(void) |
|
|
//void Myprint_Init(void)
|
|
|
{ |
|
|
//{
|
|
|
TUartUserData *ptUartUserData = UART_userdata_init(1, 115200, 4096); |
|
|
// TUartUserData *ptUartUserData = UART_userdata_init(3, 115200, 4096);
|
|
|
g_ptRS485_2 = rd_ComCreate(NULL, NULL, RS485_2_Send, ptUartUserData->m_buf_size, ptUartUserData); |
|
|
// g_ptRS485_2 = rd_ComCreate(NULL, NULL, RS485_1_Send, ptUartUserData->m_buf_size, ptUartUserData);
|
|
|
UART_IT_init(g_ptRS485_2); |
|
|
// UART_IT_init(g_ptRS485_2);
|
|
|
} |
|
|
//}
|
|
|
|
|
|
//
|
|
|
int Myprint_putchar(uint8_t ch) |
|
|
//int Myprint_putchar(uint8_t ch)
|
|
|
{ |
|
|
//{
|
|
|
char tx_buf[2]; |
|
|
// char tx_buf[2];
|
|
|
|
|
|
//
|
|
|
if (ch == '\n') |
|
|
// if (ch == '\n')
|
|
|
{ |
|
|
// {
|
|
|
// 遇到换行,发送 \r\n
|
|
|
// // 遇到换行,发送 \r\n
|
|
|
tx_buf[0] = '\r'; |
|
|
// tx_buf[0] = '\r';
|
|
|
tx_buf[1] = '\n'; |
|
|
// tx_buf[1] = '\n';
|
|
|
if (rd_ComSend(g_ptRS485_2, tx_buf, 2) < 0) return EOF; |
|
|
// if (rd_ComSend(g_ptRS485_2, tx_buf, 2) < 0) return EOF;
|
|
|
return 2; |
|
|
// return 2;
|
|
|
} |
|
|
// }
|
|
|
else |
|
|
// else
|
|
|
{ |
|
|
// {
|
|
|
// 普通字符
|
|
|
// // 普通字符
|
|
|
tx_buf[0] = ch; |
|
|
// tx_buf[0] = ch;
|
|
|
if (rd_ComSend(g_ptRS485_2, tx_buf, 1) < 0) return EOF; |
|
|
// if (rd_ComSend(g_ptRS485_2, tx_buf, 1) < 0) return EOF;
|
|
|
return 1; |
|
|
// return 1;
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
void SpoolendInit(void) |
|
|
void SpoolendInit(void) |
|
|
{ |
|
|
{ |
|
|
TUartUserData *ptUartUserData = UART_userdata_init(0, 115200, 512); |
|
|
TUartUserData *ptUartUserData = UART_userdata_init(1, 115200, 512); |
|
|
g_ptRS485_1 = rd_ComCreate(check_RS485_1, decode_RS485_1, RS485_1_Send, ptUartUserData->m_buf_size, ptUartUserData); |
|
|
g_ptRS485_1 = rd_ComCreate(NULL, NULL, RS485_1_Send, ptUartUserData->m_buf_size, ptUartUserData); // 仿照My_print,check和decode传NULL
|
|
|
UART_IT_init(g_ptRS485_1); |
|
|
UART_IT_init(g_ptRS485_1); |
|
|
// TUartUserData *ptUartUserData1 = UART_userdata_init(0, 115200, 512);
|
|
|
TUartUserData *ptUartUserData1 = UART_userdata_init(3, 115200, 512); |
|
|
// g_ptRS485_2 = rd_ComCreate(check_RS485_2, decode_RS485_2, RS485_2_Send, ptUartUserData1->m_buf_size, ptUartUserData1);
|
|
|
g_ptRS485_2 = rd_ComCreate(NULL, NULL, RS485_2_Send, ptUartUserData1->m_buf_size, ptUartUserData1); // 仿照My_print,check和decode传NULL
|
|
|
// UART_IT_init(g_ptRS485_2);
|
|
|
UART_IT_init(g_ptRS485_2); |
|
|
TCANUserData *ptCANUserData = CAN_userdata_init(&hfdcan1, 8, 0); |
|
|
TCANUserData *ptCANUserData = CAN_userdata_init(&hfdcan1, 8, 0); |
|
|
g_ptFDCAN1 = rd_ComCreate(check_Spoolend, decode_Spoolend, FDCAN1_Send, CONFIG_UART_BUFFER_SIZE, ptCANUserData); |
|
|
g_ptFDCAN1 = rd_ComCreate(check_Spoolend, decode_Spoolend, FDCAN1_Send, CONFIG_UART_BUFFER_SIZE, ptCANUserData); |
|
|
CAN_IT_init(g_ptFDCAN1); |
|
|
CAN_IT_init(g_ptFDCAN1); |
|
|
@ -179,26 +183,39 @@ void SpoolendInit(void) |
|
|
|
|
|
|
|
|
void SpoolendTask(void) |
|
|
void SpoolendTask(void) |
|
|
{ |
|
|
{ |
|
|
|
|
|
static int iCount = 0; |
|
|
char pcBuffer1[52] = {0}; |
|
|
char pcBuffer1[52] = {0}; |
|
|
// char pcBuffer2[52] = {0};
|
|
|
char pcBuffer2[52] = {0}; |
|
|
char pcBuffer3[52] = {0}; |
|
|
char pcBuffer3[52] = {0}; |
|
|
__disable_irq(); |
|
|
__disable_irq(); |
|
|
rd_ComRead(g_ptRS485_1, pcBuffer1, sizeof(pcBuffer1)); |
|
|
int i485_1 = rd_ComRead(g_ptRS485_1, pcBuffer1, sizeof(pcBuffer1)); |
|
|
// rd_ComRead(g_ptRS485_2, pcBuffer2, sizeof(pcBuffer2));
|
|
|
int i485_2 = rd_ComRead(g_ptRS485_2, pcBuffer2, sizeof(pcBuffer2)); |
|
|
rd_ComRead(g_ptFDCAN1, pcBuffer3, sizeof(pcBuffer3)); |
|
|
rd_ComRead(g_ptFDCAN1, pcBuffer3, sizeof(pcBuffer3)); |
|
|
__enable_irq(); |
|
|
__enable_irq(); |
|
|
printf("Hello world\n"); |
|
|
|
|
|
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin); |
|
|
|
|
|
|
|
|
|
|
|
// HAL_GPIO_TogglePin(K1_GPIO_Port, K1_Pin);
|
|
|
if (i485_1 > 0) rd_ComWrite(g_ptRS485_1, pcBuffer1, i485_1); |
|
|
// HAL_GPIO_TogglePin(K2_GPIO_Port, K2_Pin);
|
|
|
if (i485_2 > 0) rd_ComWrite(g_ptRS485_2, pcBuffer2, i485_2); |
|
|
// HAL_GPIO_TogglePin(K3_GPIO_Port, K3_Pin);
|
|
|
// rd_ComIDWrite(g_ptFDCAN1, 1, "Hello\n", 6);
|
|
|
// HAL_GPIO_TogglePin(K4_GPIO_Port, K4_Pin);
|
|
|
|
|
|
// HAL_GPIO_TogglePin(K5_GPIO_Port, K5_Pin);
|
|
|
if (iCount > 50000) |
|
|
|
|
|
{ |
|
|
|
|
|
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(K1_GPIO_Port, K1_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(K2_GPIO_Port, K2_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(K3_GPIO_Port, K3_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(K4_GPIO_Port, K4_Pin); |
|
|
|
|
|
HAL_GPIO_TogglePin(K5_GPIO_Port, K5_Pin); |
|
|
|
|
|
iCount = 0; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
iCount++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rd_ComSendProc(g_ptRS485_1); |
|
|
|
|
|
rd_ComSendProc(g_ptRS485_2); |
|
|
rd_ComSendProc(g_ptFDCAN1); |
|
|
rd_ComSendProc(g_ptFDCAN1); |
|
|
HAL_Delay(500); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|