[style] format files by clang-format

This commit is contained in:
jzlv 2021-06-20 12:25:46 +08:00
parent 47ce9f871c
commit d427e7fdda
1131 changed files with 7338846 additions and 422042 deletions

View file

@ -1,24 +1,24 @@
/**
* @file uart_interface.c
* @brief
*
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*
*/
#include "hal_gpio.h"
@ -28,45 +28,34 @@
#define USB_OUT_RINGBUFFER_SIZE (8 * 1024)
#define UART_RX_RINGBUFFER_SIZE (8 * 1024)
#define UART_TX_DMA_SIZE (4095)
#define UART_TX_DMA_SIZE (4095)
uint8_t usb_rx_mem[USB_OUT_RINGBUFFER_SIZE] __attribute__((section(".system_ram")));
uint8_t uart_rx_mem[UART_RX_RINGBUFFER_SIZE] __attribute__((section(".system_ram")));
uint8_t src_buffer[UART_TX_DMA_SIZE] __attribute__((section(".tcm_code")));
struct device* uart1;
struct device* dma_ch2;
struct device *uart1;
struct device *dma_ch2;
Ring_Buffer_Type usb_rx_rb;
Ring_Buffer_Type uart1_rx_rb;
void uart_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
{
if (state == UART_EVENT_RX_FIFO)
{
if (size && size < Ring_Buffer_Get_Empty_Length(&uart1_rx_rb))
{
if (state == UART_EVENT_RX_FIFO) {
if (size && size < Ring_Buffer_Get_Empty_Length(&uart1_rx_rb)) {
Ring_Buffer_Write(&uart1_rx_rb, (uint8_t *)args, size);
}
else
{
} else {
MSG("RF\r\n");
}
}
else if (state == UART_EVENT_RTO)
{
if (size && size < Ring_Buffer_Get_Empty_Length(&uart1_rx_rb))
{
} else if (state == UART_EVENT_RTO) {
if (size && size < Ring_Buffer_Get_Empty_Length(&uart1_rx_rb)) {
Ring_Buffer_Write(&uart1_rx_rb, (uint8_t *)args, size);
}
else
{
} else {
MSG("RTO\r\n");
}
}
else if (state == UART_RX_FER_IT)
{
} else if (state == UART_RX_FER_IT) {
MSG("ov\r\n");
}
}
@ -75,8 +64,7 @@ void uart1_init(void)
uart_register(UART1_INDEX, "uart1", DEVICE_OFLAG_RDWR);
uart1 = device_find("uart1");
if (uart1)
{
if (uart1) {
device_open(uart1, DEVICE_OFLAG_DMA_TX | DEVICE_OFLAG_INT_RX); //uart0 tx dma mode
device_control(uart1, DEVICE_CTRL_SUSPEND, NULL);
device_set_callback(uart1, uart_irq_callback);
@ -85,14 +73,14 @@ void uart1_init(void)
dma_register(DMA0_CH2_INDEX, "ch2", DEVICE_OFLAG_RDWR);
dma_ch2 = device_find("ch2");
if (dma_ch2)
{
if (dma_ch2) {
device_open(dma_ch2, 0);
//device_set_callback(dma_ch2, NULL);
//device_control(dma_ch2, DEVICE_CTRL_SET_INT, NULL);
}
//device_control(uart1, DEVICE_CTRL_ATTACH_TX_DMA, dma_ch2);
//device_control(uart1, DEVICE_CTRL_ATTACH_TX_DMA, dma_ch2);
}
void uart1_config(uint32_t baudrate, uart_databits_t databits, uart_parity_t parity, uart_stopbits_t stopbits)
@ -102,20 +90,13 @@ void uart1_config(uint32_t baudrate, uart_databits_t databits, uart_parity_t par
cfg.stopbits = stopbits;
cfg.parity = parity;
if (databits == 5)
{
if (databits == 5) {
cfg.databits = UART_DATA_LEN_5;
}
else if (databits == 6)
{
} else if (databits == 6) {
cfg.databits = UART_DATA_LEN_6;
}
else if (databits == 7)
{
} else if (databits == 7) {
cfg.databits = UART_DATA_LEN_7;
}
else if (databits == 8)
{
} else if (databits == 8) {
cfg.databits = UART_DATA_LEN_8;
}
@ -175,8 +156,7 @@ void uart_ringbuffer_init(void)
Ring_Buffer_Init(&uart1_rx_rb, uart_rx_mem, UART_RX_RINGBUFFER_SIZE, ringbuffer_lock, ringbuffer_unlock);
}
static dma_control_data_t uart_dma_ctrl_cfg =
{
static dma_control_data_t uart_dma_ctrl_cfg = {
.bits.fix_cnt = 0,
.bits.dst_min_mode = 0,
.bits.dst_add_mode = 0,
@ -189,8 +169,7 @@ static dma_control_data_t uart_dma_ctrl_cfg =
.bits.I = 0,
.bits.TransferSize = 4095
};
static dma_lli_ctrl_t uart_lli_list =
{
static dma_lli_ctrl_t uart_lli_list = {
.src_addr = (uint32_t)src_buffer,
.dst_addr = DMA_ADDR_UART1_TDR,
.nextlli = 0
@ -198,21 +177,17 @@ static dma_lli_ctrl_t uart_lli_list =
void uart_send_from_ringbuffer(void)
{
if(Ring_Buffer_Get_Length(&usb_rx_rb))
{
if (!device_control(dma_ch2, DMA_CHANNEL_GET_STATUS, NULL))
{
if (Ring_Buffer_Get_Length(&usb_rx_rb)) {
if (!device_control(dma_ch2, DMA_CHANNEL_GET_STATUS, NULL)) {
uint32_t avalibleCnt = Ring_Buffer_Read(&usb_rx_rb, src_buffer, UART_TX_DMA_SIZE);
if (avalibleCnt)
{
if (avalibleCnt) {
dma_channel_stop(dma_ch2);
uart_dma_ctrl_cfg.bits.TransferSize = avalibleCnt;
memcpy(&uart_lli_list.cfg, &uart_dma_ctrl_cfg, sizeof(dma_control_data_t));
device_control(dma_ch2,DMA_CHANNEL_UPDATE,(void*)((uint32_t)&uart_lli_list));
device_control(dma_ch2, DMA_CHANNEL_UPDATE, (void *)((uint32_t)&uart_lli_list));
dma_channel_start(dma_ch2);
}
}
}
}