]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/T-HEAD_CB2201_CDK/driver/uart.c
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Demo / T-HEAD_CB2201_CDK / driver / uart.c
1 /*
2  * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
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 #include <stdio.h>
17 #include <stdint.h>
18 #include "soc.h"
19 #include "pin_name.h"
20 #include "drv_usart.h"
21 #include "ck_sys_freq.h"
22
23 #define CONSOLE_TXD PA10_ADC2_TXD0
24 #define CONSOLE_RXD PA11_ACMP0N_ADC3_RXD0
25 static usart_handle_t console_handle = NULL;
26 extern int32_t csi_usart_putchar(usart_handle_t handle, uint8_t ch);
27
28 int putchar(int ch)
29 {
30     if (ch == '\n') {
31         csi_usart_putchar(console_handle, '\r');
32     }
33
34     csi_usart_putchar(console_handle, ch);
35
36     return 0;
37 }
38
39 int fputc(int ch, FILE *fp)
40 {
41     if (ch == '\n') {
42         csi_usart_putchar(console_handle, '\r');
43     }
44
45     csi_usart_putchar(console_handle, ch);
46
47     return 0;
48 }
49
50
51 void usart_event_cb(usart_event_e event, void *cb_arg)
52 {
53     //do nothing
54 }
55
56 void console_init()
57 {
58     int ret;
59
60     console_handle = csi_usart_initialize(CONSOLE_TXD, CONSOLE_RXD, usart_event_cb, 0);
61
62     if (!console_handle) {
63         return;
64     }
65
66     ret = csi_usart_config(console_handle,
67                            SYSTEM_CLOCK,
68                            115200,
69                            USART_MODE_ASYNCHRONOUS,
70                            USART_PARITY_NONE,
71                            USART_STOP_BITS_1,
72                            USART_DATA_BITS_8);
73
74     if (ret < 0) {
75         return;
76     }
77 }
78
79 void console_init_ree(uint32_t sysclk)
80 {
81     int ret;
82
83
84     console_handle = csi_usart_initialize(CONSOLE_TXD, CONSOLE_RXD, usart_event_cb, 0);
85
86     if (!console_handle) {
87         return;
88     }
89
90     ret = csi_usart_config(console_handle,
91                            sysclk,
92                            115200,
93                            USART_MODE_ASYNCHRONOUS,
94                            USART_PARITY_NONE,
95                            USART_STOP_BITS_1,
96                            USART_DATA_BITS_8);
97
98     if (ret < 0) {
99         return;
100     }
101 }