凌云物联网实验室ISKBoard(IoT Starter Kits Board)开发板项目源码
guowenxue
2023-04-04 0a714938963508d0a9792481c60863c56dc07e53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**********************************************************************
*   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_ */