| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- #pragma once
- #include "s600.h"
- #include "s600_can.h"
- #include "byte_queue.h"
- #define S600_UART_USE_DMA 1
- #define S600_UART_USE_CACHE 1
- #define S600_UART_CACHE_TIMES 200
- #define CH_START 0xF5
- #define CH_END 0xF6
- #define CH_ESC 0xF7
- #define CH_ESC_START 0x05
- #define CH_ESC_END 0x06
- #define CH_ESC_ESC 0x07
- #define S600_UART_FRAME_SIZE 2048
- #ifdef CONFIG_BOARD_S600
- #define S600_UART_TX_MEM_SIZE 512
- #define S600_UART_RX_MEM_SIZE 512
- #else
- #define S600_UART_TX_MEM_SIZE 1024
- #define S600_UART_RX_MEM_SIZE 1024
- #endif
- #define S600_UART_MAIN_TX_MEM_SIZE 2048
- #define S600_UART_MAIN_RX_MEM_SIZE 2048
- typedef enum {
- CMD_CAN = 0,
- CMD_PING,
- CMD_VERSION,
- CMD_PRINT_ADD,
- CMD_PRINT_END,
- CMD_PWM_SET_ENABLE, // 5
- CMD_PWM_SET_VALUE,
- CMD_UART0,
- CMD_UART1,
- CMD_UART2,
- CMD_UART3, // 10
- CMD_UART4,
- CMD_UART_CONFIG,
- CMD_GPIO_INIT,
- CMD_GPIO_INPUT_BIT_GET,
- CMD_GPIO_OUTPUT_BIT_SET, // 15
- CMD_GPIO_OUTPUT_BIT_GET,
- CMD_GPIO_INPUT_PORT_GET,
- CMD_GPIO_OUTPUT_PORT_SET,
- CMD_GPIO_OUTPUT_PORT_GET,
- CMD_ADC, // 20
- CMD_DAC0,
- CMD_DAC1,
- CMD_DAC_SET_ENABLE,
- CMD_DAC_SET_VOLUME,
- CMD_DAC_SET_RATE, // 25
- CMD_SINGLE_COMM_CONFIG,
- CMD_SINGLE_COMM_DATA,
- CMD_SPI_LED_INIT,
- CMD_SPI_LED_COMMIT,
- CMD_SPI_LED_CLEAR, // 30
- CMD_SPI_LED_SET_COLOR,
- CMD_REG_RW,
- CMD_MEM_RW,
- CMD_I2C_INIT,
- CMD_I2C_RW, // 35
- CMD_EXTI_INIT,
- CMD_EXTI_NOTIFY,
- } short_command_t;
- typedef enum {
- S600_UART0,
- S600_UART1,
- S600_UART2,
- S600_UART3,
- S600_UART4,
- S600_UART_COUNT
- } s600_uart_t;
- typedef struct s600_uart_device {
- u32 com;
- u32 tx_dma;
- u32 rx_dma;
- dma_channel_enum tx_dma_ch;
- dma_channel_enum rx_dma_ch;
- #if S600_UART_USE_CACHE
- u8 cache[64];
- u8 cache_len;
- u8 cache_times;
- #endif
- u8 *tx_cache;
- u8 *rx_cache;
- u16 tx_cache_size;
- u16 rx_cache_size;
- u16 tx_length;
- u16 rx_index;
- byte_queue_t tx_queue;
- byte_queue_t rx_queue;
- void (*do_cache_data)(struct s600_uart_device *uart, u8 *buff, u16 size);
- void (*on_data_received)(u8 *buff, u16 size);
- void (*tx_poll)(struct s600_uart_device *uart);
- void (*rx_poll)(struct s600_uart_device *uart);
- } s600_uart_device_t;
- typedef struct {
- u8 *buff;
- u16 size;
- } s600_uart_message_t;
- extern s600_uart_device_t s600_uarts[];
- extern void s600_uart_received(s600_uart_device_t *uart, u8 *buff, u16 length);
- extern void s600_uart0_received(u8 *buff, u16 length);
- extern void s600_uart1_received(u8 *buff, u16 length);
- extern void s600_uart2_received(u8 *buff, u16 length);
- extern void s600_uart3_received(u8 *buff, u16 length);
- extern void s600_uart4_received(u8 *buff, u16 length);
- void s600_uart_init(s600_uart_device_t *uart);
- void s600_uart_dma_tx(s600_uart_device_t *uart);
- void s600_uart_dma_rx(s600_uart_device_t *uart);
- void s600_uart_write(s600_uart_device_t *uart, const u8 *buff, u16 size);
- u16 s600_uart_read(s600_uart_device_t *uart, u8 *buff, u16 size);
- void s600_uart_write_byte(s600_uart_device_t *uart, u8 value);
- u16 s600_uart_write_available(s600_uart_device_t *uart);
- bool s600_uart_write_full(s600_uart_device_t *uart, const u8 *buff, u16 size);
- void s600_uart_message_init(s600_uart_message_t *msg, const void *buff, u16 size);
- void s600_uart_write_messages(s600_uart_device_t *uart, const s600_uart_message_t *msgs, u8 count);
- void s600_uart_rcu_config(void);
- void s600_uart_poll(void);
- void s600_uart_send_command(u8 cmd, const void *buff, u16 size);
- void s600_uart_send_command_u8(u8 cmd, u8 value);
- void s600_uart_send_command_bool(u8 cmd, bool value);
- void s600_uart_send_can_frame(const s600_can_frame_t *frame);
- void s600_uart_send_can_pack(const s600_can_pack_t *pack);
- __STATIC_INLINE s600_uart_device_t *s600_uart_get_main(void)
- {
- return s600_uarts + CONFIG_UART_MAIN;
- }
|