11/*
2- * File : serial.c
3- * This file is part of RT-Thread RTOS
4- * COPYRIGHT (C) 2020, Shenzhen Academy of Aerospace Technology
5- *
6- * The license and distribution terms for this file may be
7- * found in the file LICENSE in this distribution or at
8- * http://www.rt-thread.org/license/LICENSE
9- *
10- * Change Logs:
11- * Date Author Notes
12- * 2020-10-16 Dystopia the first version
13- */
2+ Copyright 2020 Shenzhen Academy of Aerospace Technology
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+
16+ Change Logs:
17+ Date Author Notes
18+ 2020-10-16 Dystopia the first version
19+ */
1420
1521#include <rthw.h>
1622#include <rtthread.h>
@@ -27,16 +33,16 @@ struct bm3803_uart
2733 int irq ;
2834};
2935
30- static void bm3803_uart_isr (int tt , void * param )
36+ static void bm3803_uart_isr (int tt , void * param )
3137{
32- struct bm3803_uart * uart ;
38+ struct bm3803_uart * uart ;
3339 struct rt_serial_device * serial ;
34- struct uart_reg * uart_base ;
40+ struct uart_reg * uart_base ;
3541
36- serial = (struct rt_serial_device * )param ;
42+ serial = (struct rt_serial_device * )param ;
3743 uart = (struct bm3803_uart * )serial -> parent .user_data ;
3844 uart_base = uart -> uart_base ;
39-
45+
4046 if (uart_base -> uartstatus & 0x1 )
4147 {
4248 rt_hw_serial_isr (serial , RT_SERIAL_EVENT_RX_IND );
@@ -47,8 +53,8 @@ static void bm3803_uart_isr(int tt, void* param)
4753
4854static rt_err_t bm3803_configure (struct rt_serial_device * serial , struct serial_configure * cfg )
4955{
50- struct bm3803_uart * uart ;
51- struct uart_reg * uart_base ;
56+ struct bm3803_uart * uart ;
57+ struct uart_reg * uart_base ;
5258
5359 RT_ASSERT (serial != RT_NULL );
5460 uart = (struct bm3803_uart * )serial -> parent .user_data ;
@@ -57,25 +63,25 @@ static rt_err_t bm3803_configure(struct rt_serial_device *serial, struct serial_
5763
5864 if (cfg -> baud_rate == BAUD_RATE_115200 )
5965 {
60- uart_base -> uartscaler = ((((CPU_FREQ * 10 ) / (8 * 115200 )) - 5 ) / 10 );
66+ uart_base -> uartscaler = ((((CPU_FREQ * 10 ) / (8 * 115200 )) - 5 ) / 10 );
6167 }
6268 else if (cfg -> baud_rate == BAUD_RATE_9600 )
6369 {
64- uart_base -> uartscaler = ((((CPU_FREQ * 10 ) / (8 * 9600 )) - 5 ) / 10 );
70+ uart_base -> uartscaler = ((((CPU_FREQ * 10 ) / (8 * 9600 )) - 5 ) / 10 );
6571 }
6672 else
6773 {
6874 NOT_IMPLEMENTED ();
6975 }
70-
76+
7177 uart_base -> uartctrl |= 0x3 ;
7278
7379 return RT_EOK ;
7480}
7581
7682static rt_err_t bm3803_control (struct rt_serial_device * serial , int cmd , void * arg )
7783{
78- struct bm3803_uart * uart ;
84+ struct bm3803_uart * uart ;
7985
8086 RT_ASSERT (serial != RT_NULL );
8187 uart = (struct bm3803_uart * )serial -> parent .user_data ;
@@ -97,13 +103,13 @@ static rt_err_t bm3803_control(struct rt_serial_device *serial, int cmd, void *a
97103
98104static int bm3803_putc (struct rt_serial_device * serial , char c )
99105{
100- struct bm3803_uart * uart ;
101- struct uart_reg * uart_base ;
102-
106+ struct bm3803_uart * uart ;
107+ struct uart_reg * uart_base ;
108+
103109 RT_ASSERT (serial != RT_NULL );
104110 uart = (struct bm3803_uart * )serial -> parent .user_data ;
105111 uart_base = uart -> uart_base ;
106-
112+
107113 while (!(uart_base -> uartstatus & 0x4 ));
108114 uart_base -> uartdata = c ;
109115
@@ -113,13 +119,13 @@ static int bm3803_putc(struct rt_serial_device *serial, char c)
113119static int bm3803_getc (struct rt_serial_device * serial )
114120{
115121 int ch ;
116- struct bm3803_uart * uart ;
117- struct uart_reg * uart_base ;
122+ struct bm3803_uart * uart ;
123+ struct uart_reg * uart_base ;
118124
119125 RT_ASSERT (serial != RT_NULL );
120126 uart = (struct bm3803_uart * )serial -> parent .user_data ;
121- uart_base = uart -> uart_base ;
122-
127+ uart_base = uart -> uart_base ;
128+
123129 ch = -1 ;
124130 if (uart_base -> uartstatus & 0x1 )
125131 {
@@ -131,7 +137,7 @@ static int bm3803_getc(struct rt_serial_device *serial)
131137
132138static const struct rt_uart_ops bm3803_uart_ops =
133139{
134- bm3803_configure ,
140+ bm3803_configure ,
135141 bm3803_control ,
136142 bm3803_putc ,
137143 bm3803_getc ,
@@ -141,7 +147,7 @@ static const struct rt_uart_ops bm3803_uart_ops =
141147#ifdef RT_USING_UART1
142148struct bm3803_uart uart1 =
143149{
144- (void * )UART1_BASE ,
150+ (void * )UART1_BASE ,
145151 UART1_TT ,
146152};
147153struct rt_serial_device serial1 ;
@@ -152,7 +158,7 @@ int rt_hw_serial_init(void)
152158 struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT ;
153159
154160#ifdef RT_USING_UART1
155- volatile struct lregs * regs = (struct lregs * )PREGS ;
161+ volatile struct lregs * regs = (struct lregs * )PREGS ;
156162 serial1 .ops = & bm3803_uart_ops ;
157163 serial1 .config = config ;
158164 /* configure gpio direction */
@@ -166,8 +172,8 @@ int rt_hw_serial_init(void)
166172 rt_hw_interrupt_mask (uart1 .irq );
167173 /* register UART1 device */
168174 rt_hw_serial_register (& serial1 , "uart1" ,
169- RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
170- & uart1 );
175+ RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
176+ & uart1 );
171177#endif
172178 return 0 ;
173179}
0 commit comments