2024-11-06 19:58:23 -08:00
|
|
|
/*
|
|
|
|
* cdc.h
|
|
|
|
*
|
|
|
|
* Created on: Nov 6, 2024
|
|
|
|
* Author: true
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef USER_USB_CDC_H_
|
|
|
|
#define USER_USB_CDC_H_
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-07 00:25:15 -08:00
|
|
|
// CDC buffer
|
|
|
|
#define DEF_CDC_SEND_HOST_BUF_LEN ( 2 * 512 ) // device to host buffer size
|
|
|
|
#define DEF_CDC_FROM_HOST_BUF_LEN ( 2 * 512 ) // host to device buffer size
|
|
|
|
#define DEF_USB_FS_PACKET_LEN 64 // USB full speed mode packet size for CDC data
|
|
|
|
#define DEF_CDC_FROM_HOST_BUF_NUM_MAX (DEF_CDC_FROM_HOST_BUF_LEN / DEF_USB_FS_PACKET_LEN) // Serial x transmit buffer size
|
|
|
|
|
|
|
|
// CDC default settings
|
2024-11-06 19:58:23 -08:00
|
|
|
#define DEF_CDC_BAUDRATE 115200 /* Default baud rate for serial port */
|
|
|
|
#define DEF_CDC_STOPBIT 0 /* Default stop bit for serial port */
|
|
|
|
#define DEF_CDC_PARITY 0 /* Default parity bit for serial port */
|
|
|
|
#define DEF_CDC_DATABIT 8 /* Default data bit for serial port */
|
|
|
|
|
|
|
|
|
2024-11-07 00:25:15 -08:00
|
|
|
|
2024-11-06 19:58:23 -08:00
|
|
|
typedef struct __attribute__((packed)) _UART_CTL
|
|
|
|
{
|
2024-11-07 00:25:15 -08:00
|
|
|
uint16_t send_host_ptr; // data location for data being added to the buffer
|
|
|
|
uint16_t send_host_idx; // data location for data being sent over USB
|
|
|
|
volatile uint16_t send_host_count; // amount of data to send
|
|
|
|
|
|
|
|
uint16_t from_host_ptr;
|
|
|
|
uint16_t from_host_idx;
|
|
|
|
uint16_t from_host_count;
|
2024-11-06 19:58:23 -08:00
|
|
|
|
|
|
|
volatile uint16_t Tx_LoadNum; /* Serial x data send buffer load number */
|
|
|
|
volatile uint16_t Tx_DealNum; /* Serial x data send buffer processing number */
|
2024-11-07 00:25:15 -08:00
|
|
|
volatile uint16_t from_host_remain; /* Serial x data send buffer remaining unprocessed number */
|
|
|
|
volatile uint16_t Tx_PackLen[DEF_CDC_FROM_HOST_BUF_NUM_MAX]; /* The current packet length of the serial x data send buffer */
|
|
|
|
uint8_t from_host_flag; /* Serial x data send status */
|
|
|
|
uint8_t pad1;
|
2024-11-06 19:58:23 -08:00
|
|
|
uint16_t Tx_CurPackLen; /* The current packet length sent by serial port x */
|
|
|
|
uint16_t Tx_CurPackPtr; /* Pointer to the packet currently being sent by serial port x */
|
|
|
|
|
2024-11-07 00:25:15 -08:00
|
|
|
uint8_t usb_send_host_flag; /* Serial xUSB packet being uploaded flag */
|
|
|
|
uint8_t usb_send_host_zero_flag; /* Serial xUSB data needs to upload 0-length packet flag */
|
|
|
|
uint8_t usb_from_host_stop_flag; /* Serial xUSB packet stop down flag */
|
|
|
|
uint8_t pad2;
|
2024-11-06 19:58:23 -08:00
|
|
|
|
2024-11-07 00:25:15 -08:00
|
|
|
uint8_t cdc_cfg[ 8 ]; /* Serial x parameter configuration (default baud rate is 115200, 1 stop bit, no parity, 8 data bits) */
|
|
|
|
uint8_t usb_send_flag; /* Serial x interrupt upload status */
|
|
|
|
uint8_t pad3;
|
2024-11-06 19:58:23 -08:00
|
|
|
uint16_t USB_Int_UpTimeCount; /* Serial x interrupt upload timing */
|
|
|
|
} CDC_CTL, *PCDC_CTL;
|
|
|
|
|
|
|
|
/***********************************************************************************************************************/
|
|
|
|
/* Constant, variable extents */
|
|
|
|
/* The following are serial port transmit and receive related variables and buffers */
|
|
|
|
extern volatile CDC_CTL Cdc; /* Serial x control related structure */
|
2024-11-07 00:25:15 -08:00
|
|
|
extern __attribute__((aligned(4))) uint8_t cdc_from[DEF_CDC_FROM_HOST_BUF_LEN];
|
|
|
|
extern __attribute__((aligned(4))) uint8_t cdc_send[DEF_CDC_SEND_HOST_BUF_LEN];
|
2024-11-06 19:58:23 -08:00
|
|
|
/***********************************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CDC_USB_Init(void);
|
2024-11-07 00:25:15 -08:00
|
|
|
void cdc_from_host_process(void);
|
|
|
|
void cdc_send_host_process(void);
|
|
|
|
|
|
|
|
int usb_cdc_puts(char *buf, int cnt);
|
|
|
|
int usb_cdc_gets(char *buf, int cnt);
|
2024-11-06 19:58:23 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* USER_USB_CDC_H_ */
|