/**********************************************************************
|
* Copyright: (C)2023 LingYun IoT System Studio
|
* Author: GuoWenxue<guowenxue@gmail.com> QQ: 281143292
|
* Description: ISKBoard RS232/TTL/RS485 Hardware Abstract Layer driver
|
*
|
* ChangeLog:
|
* Version Date Author Description
|
* V1.0.0 2023.04.3 GuoWenxue Release initial version
|
***********************************************************************/
|
#ifndef INC_COMPORT_H_
|
#define INC_COMPORT_H_
|
|
/* Library includes. */
|
#include "stm32l4xx_hal.h"
|
|
|
/* Demo application includes. */
|
#include <stdio.h>
|
#include "usart.h"
|
#include "ringbuf.h"
|
|
|
#define COMM_RXBUFSIZE 1024
|
|
typedef struct comport_s
|
{
|
int fd; /* compatible with Linux API */
|
char devname[32]; /* UART device name */
|
UART_HandleTypeDef *huart; /* STM32 UART Handler */
|
uint8_t *rxch; /* receive data in interrupt handler */
|
ring_buffer_t rb; /* receive data ring buffer */
|
} comport_t;
|
|
comport_t *comport_init(UART_HandleTypeDef *huart, uint8_t *rxch, uint8_t *rxbuf, size_t size);
|
comport_t *comport_open(UART_HandleTypeDef *huart);
|
void comport_flush(comport_t *comport);
|
extern int comport_send(comport_t *comport, char *data, int bytes);
|
extern int comport_recv(comport_t *comport, char *buf, int size, uint32_t timeout);
|
extern void comport_term(comport_t *comport);
|
|
|
extern comport_t *rs485_open(UART_HandleTypeDef *huart);
|
extern int rs485_send(comport_t *comport, char *data, int bytes);
|
extern int rs485_recv(comport_t *comport, char *buf, int size, uint32_t timeout);
|
extern void rs485_term(comport_t *comport);
|
|
#endif /* INC_WIRED_H_ */
|