guowenxue
2024-06-25 5fc803d51ca097f07b4efbe0290ccc540b0660df
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
  ******************************************************************************
  * File Name          : USART.h
  * Description        : This file provides code for the configuration
  *                      of the USART instances.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __usart_H
#define __usart_H
#ifdef __cplusplus
 extern "C" {
#endif
 
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
typedef enum
{
    RS485_RECV = 0, 
    RS485_SEND
}RS485DirCtrl_e;
 
#define RS485_DIR_PORT GPIOA
#define RS485_DIR_PIN GPIO_PIN_1
/* RS485 TX/RX Control */
#define RS485_TX_ENABLE()   HAL_Delay(100);\
                            HAL_GPIO_WritePin(RS485_DIR_PORT, RS485_DIR_PIN, GPIO_PIN_SET);\
                            HAL_Delay(100);
 
#define RS485_RX_ENABLE()   HAL_Delay(100);\
                            HAL_GPIO_WritePin(RS485_DIR_PORT, RS485_DIR_PIN, GPIO_PIN_RESET);\
                            HAL_Delay(100);
 
#define PRINTF(...)            VcomSend(__VA_ARGS__)
#define ECHO_ERROR(x) PRINTF("[%s][%d]:%s\r\n", __FUNCTION__, __LINE__, x)
 
#pragma pack(1)
 
#define FreeUart1Buffer()           Debug_Rxbuffer.Locked = 0; Debug_Rxbuffer.RxSize=0
#define Uart1BufferIsEmpty           (Debug_Rxbuffer.RxSize == 0 ? 1 : 0)
#define Uart1BufferIsReadable()     (Debug_Rxbuffer.Locked ? 1 : 0)
 
//#define LockUart3Buffer()           Uart3_Rxbuffer.Locked = 1
//#define FreeUart3Buffer()           Uart3_Rxbuffer.Locked = 0; Uart3_Rxbuffer.RxSize=0; memset(Uart3_Rxbuffer.RxBuffer, 0x0, UART_RINGBUF_SIZE)
//#define Uart3BufferIsEmpty           (Uart3_Rxbuffer.RxSize == 0 ? 1 : 0)
//#define Uart3BufferIsReadable()     (Uart3_Rxbuffer.Locked ? 1 : 0)
 
#define UART_RINGBUF_SIZE     255
typedef struct Uart_Rxbuffer_s
{
  uint8_t               RxBuffer[UART_RINGBUF_SIZE];  /* UART receive buffer*/
  uint32_t              RxSize;      /* Current data length in UART receive buffer */
  uint32_t              Time;     /* Last receive time */
  uint8_t               Locked;   /* Buffer is busy */
}Uart_Rxbuffer_t;
 
typedef struct
{
    uint8_t *pRear;            //ÔÚÖжϺ¯ÊýÖиü¸Ä
    uint8_t *pFront;            //ÔÚÖ÷Ñ­»·Öиü¸Ä
} UartBuffer_t;
 
#pragma pack()
 
extern Uart_Rxbuffer_t Debug_Rxbuffer;
//extern Uart_Rxbuffer_t Uart3_Rxbuffer;
 
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;
 
void Board_USART1Init(void);
void Board_USART1DeInit(void);
void Board_USART1RX_Enable(void);
void Board_USART1RX_Disable(void);
 
void Board_USART2Init(void);
void Board_USART2DeInit(void);
int8_t Board_USART2Recv(uint8_t *pFmt, uint16_t u16TimeOut);
int8_t Board_USART2end(const uint8_t *pFmt, uint8_t u8Len);
 
//int8_t Board_USART2Test(void);
 
 
 
void VcomSend( char *format, ... );
 
 
#ifdef __cplusplus
}
#endif
#endif /*__ usart_H */
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/