embox

Форк
0
/
efm32_leuart.c 
151 строка · 4.8 Кб
1
/**
2
 * @file
3
 * @brief
4
 *
5
 * @author  Anton Kozlov
6
 * @date    25.03.2014
7
 */
8

9
/***************************************************************************//**
10
 * @file
11
 * @brief Provide BSP (board support package) configuration parameters.
12
 * @author Energy Micro AS
13
 * @version 3.20.3
14
 *******************************************************************************
15
 * @section License
16
 * <b>(C) Copyright 2013 Energy Micro AS, http://www.energymicro.com</b>
17
 *******************************************************************************
18
 *
19
 * Permission is granted to anyone to use this software for any purpose,
20
 * including commercial applications, and to alter it and redistribute it
21
 * freely, subject to the following restrictions:
22
 *
23
 * 1. The origin of this software must not be misrepresented; you must not
24
 *    claim that you wrote the original software.
25
 * 2. Altered source versions must be plainly marked as such, and must not be
26
 *    misrepresented as being the original software.
27
 * 3. This notice may not be removed or altered from any source distribution.
28
 * 4. The source and compiled code may only be used on Energy Micro "EFM32"
29
 *    microcontrollers and "EFR4" radios.
30
 *
31
 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
32
 * obligation to support this Software. Energy Micro AS is providing the
33
 * Software "AS IS", with no express or implied warranties of any kind,
34
 * including, but not limited to, any implied warranties of merchantability
35
 * or fitness for any particular purpose or warranties against infringement
36
 * of any proprietary rights of a third party.
37
 *
38
 * Energy Micro AS will not be liable for any consequential, incidental, or
39
 * special damages, or any other relief, or for any claim by any third party,
40
 * arising from your use of this Software.
41
 *
42
 *****************************************************************************/
43

44
#include <stdint.h>
45

46
/*#include <drivers/gpio.h>*/
47
#include <hal/reg.h>
48
#include <hal/system.h>
49
#include <drivers/diag.h>
50
#include <drivers/serial/diag_serial.h>
51
#include <embox/unit.h>
52

53
#include <drivers/serial/uart_dev.h>
54

55
#include <em_leuart.h>
56
#include <em_cmu.h>
57
#include <em_gpio.h>
58

59
#define BSP_BCC_LEUART        LEUART0
60
#define BSP_BCC_CLK           cmuClock_LEUART0
61
#define BSP_BCC_LOCATION      LEUART_ROUTE_LOCATION_LOC0
62
#define BSP_BCC_TXPORT        gpioPortD
63
#define BSP_BCC_TXPIN         4
64
#define BSP_BCC_RXPORT        gpioPortD
65
#define BSP_BCC_RXPIN         5
66
#define BSP_BCC_ENABLE_PORT   gpioPortA
67
#define BSP_BCC_ENABLE_PIN    9
68

69
static int efm32_uart_putc(struct uart *dev, int ch) {
70
	LEUART_Tx((void *) dev->base_addr, ch);
71
	return 0;
72
}
73

74
static int efm32_uart_hasrx(struct uart *dev) {
75
#if 1
76
static unsigned int neg_cnt;
77
	while (1)
78
		if (!GPIO_PinInGet(BSP_BCC_RXPORT, BSP_BCC_RXPIN)) {
79
			LEUART_Tx((void *) dev->base_addr, '0');
80
			neg_cnt++;
81
		}
82
#endif
83
	return 1;
84
}
85

86
static int efm32_uart_getc(struct uart *dev) {
87
	return LEUART_Rx((void *) dev->base_addr);
88
}
89

90
static int efm32_uart_setup(struct uart *dev, const struct uart_params *params) {
91

92
	LEUART_TypeDef      *leuart = (void *) dev->base_addr;
93
	LEUART_Init_TypeDef init    = LEUART_INIT_DEFAULT;
94

95
	/* Enable CORE LE clock in order to access LE modules */
96
	CMU_ClockEnable(cmuClock_HFPER, true);
97

98
	/* Enable CORE LE clock in order to access LE modules */
99
	CMU_ClockEnable(cmuClock_GPIO, true);
100

101
	/* Enable CORE LE clock in order to access LE modules */
102
	CMU_ClockEnable(cmuClock_CORELE, true);
103

104
	/* Select LFXO for LEUARTs (and wait for it to stabilize) */
105
	CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);
106

107
	CMU_ClockEnable(cmuClock_LEUART0, true);
108

109
	/* Do not prescale clock */
110
	CMU_ClockDivSet(cmuClock_LEUART0, cmuClkDiv_1);
111

112
	/* Configure GPIO pin for UART TX */
113
	/* To avoid false start, configure output as high. */
114
	GPIO_PinModeSet( BSP_BCC_TXPORT, BSP_BCC_TXPIN, gpioModePushPull, 1 );
115
	/* Configure GPIO pin for UART RX */
116
	GPIO_PinModeSet( BSP_BCC_RXPORT, BSP_BCC_RXPIN, gpioModeInput, 1 );
117

118
	/* Configure LEUART */
119
	init.enable = leuartDisable;
120
	init.baudrate = 9600;
121
	LEUART_Init(leuart, &init);
122

123
	/* Enable the switch that enables UART communication. */
124
	GPIO_PinModeSet( BSP_BCC_ENABLE_PORT, BSP_BCC_ENABLE_PIN, gpioModePushPull, 1 );
125
	BSP_BCC_LEUART->ROUTE |= LEUART_ROUTE_RXPEN | LEUART_ROUTE_TXPEN | BSP_BCC_LOCATION;
126

127
	/* Finally enable it */
128
	LEUART_Enable(leuart, leuartEnable);
129

130
	return 0;
131
}
132

133
static const struct uart_ops efm32_uart_ops = {
134
		.uart_getc = efm32_uart_getc,
135
		.uart_putc = efm32_uart_putc,
136
		.uart_hasrx = efm32_uart_hasrx,
137
		.uart_setup = efm32_uart_setup,
138
};
139

140
static struct uart efm32_uart0 = {
141
		.uart_ops = &efm32_uart_ops,
142
		.irq_num = 0,
143
		.base_addr = (unsigned long) LEUART0,
144
};
145

146
static const struct uart_params uart_defparams = {
147
		.baud_rate = 115200,
148
		.uart_param_flags = UART_PARAM_FLAGS_8BIT_WORD,
149
};
150

151
DIAG_SERIAL_DEF(&efm32_uart0, &uart_defparams);
152

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.