凌云物联网实验室ISKBoard(IoT Starter Kits Board)开发板项目源码
guowenxue
2023-04-03 32806da6f5647ac637fa7d48aa9c221b091ab35e
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
/*
 * comport.h
 *
 *  Created on: Feb 15, 2023
 *      Author: Think
 */
 
#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_ */