Skip to content

Commit fe42154

Browse files
tswaehnnashif
authored andcommitted
soc: sensry: udma, pad renaming
Before that fix the names for UDMA could be misleading. With that fix the namespace is clear and easy to follow. Same applies for peripheral addresses and pad config. Signed-off-by: Sven Ginka <[email protected]>
1 parent 795644f commit fe42154

File tree

7 files changed

+307
-296
lines changed

7 files changed

+307
-296
lines changed

drivers/serial/uart_sy1xx.c

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ struct sy1xx_uart_config {
2020
typedef struct {
2121
uint16_t data_len;
2222
uint8_t *data;
23-
} uartTransfer_t;
23+
} sy1xx_uartTransfer_t;
2424

2525
typedef enum {
2626
DRIVERS_UART_STOP_1,
2727
DRIVERS_UART_STOP_1_5,
2828
DRIVERS_UART_STOP_2
29-
} uart_stop_t;
29+
} sy1xx_uart_stop_t;
3030

3131
typedef enum {
3232
DRIVERS_UART_PAR_NONE,
3333
DRIVERS_UART_PAR_EVEN,
3434
DRIVERS_UART_PAR_ODD,
3535
DRIVERS_UART_PAR_MARK,
3636
DRIVERS_UART_PAR_SPACE
37-
} uart_parity_t;
37+
} sy1xx_uart_parity_t;
3838

3939
typedef struct {
4040
uint32_t baudrate;
41-
uart_stop_t stopbits;
42-
uart_parity_t parity;
43-
} uartConfig_t;
41+
sy1xx_uart_stop_t stopbits;
42+
sy1xx_uart_parity_t parity;
43+
} sy1xx_uartConfig_t;
4444

4545
#define DEVICE_MAX_BUFFER_SIZE (512)
4646

@@ -50,10 +50,10 @@ struct sy1xx_uart_data {
5050
};
5151

5252
/* prototypes */
53-
static int32_t drivers_uart_read(const struct device *dev, uartTransfer_t *request);
54-
static int32_t drivers_uart_write(const struct device *dev, uartTransfer_t *request);
53+
static int32_t sy1xx_uart_read(const struct device *dev, sy1xx_uartTransfer_t *request);
54+
static int32_t sy1xx_uart_write(const struct device *dev, sy1xx_uartTransfer_t *request);
5555

56-
static int32_t drivers_uart_configure(const struct device *dev, uartConfig_t *uart_cfg)
56+
static int32_t sy1xx_uart_configure(const struct device *dev, sy1xx_uartConfig_t *uart_cfg)
5757
{
5858
struct sy1xx_uart_config *config = (struct sy1xx_uart_config *)dev->config;
5959

@@ -66,7 +66,7 @@ static int32_t drivers_uart_configure(const struct device *dev, uartConfig_t *ua
6666
* and then will restart from 0, so we must give div - 1 as
6767
* divider
6868
*/
69-
int32_t divider = soc_get_peripheral_clock() / uart_cfg->baudrate - 1;
69+
uint32_t divider = sy1xx_soc_get_peripheral_clock() / uart_cfg->baudrate - 1;
7070

7171
/*
7272
* [31:16]: clock divider (from SoC clock)
@@ -85,17 +85,17 @@ static int32_t drivers_uart_configure(const struct device *dev, uartConfig_t *ua
8585
volatile uint32_t setup = 0x0306 | uart_cfg->parity;
8686

8787
setup |= ((divider) << 16);
88-
UDMA_WRITE_REG(config->base, UDMA_SETUP_REG, setup);
88+
SY1XX_UDMA_WRITE_REG(config->base, SY1XX_UDMA_SETUP_REG, setup);
8989

9090
/* start initial reading request to get the dma running */
9191
uint8_t dummy_data[10];
9292

93-
uartTransfer_t dummy_request = {
93+
sy1xx_uartTransfer_t dummy_request = {
9494
.data_len = 10,
9595
.data = (uint8_t *)dummy_data,
9696
};
9797

98-
drivers_uart_read(dev, &dummy_request);
98+
sy1xx_uart_read(dev, &dummy_request);
9999
return 0;
100100
}
101101

@@ -105,7 +105,7 @@ static int32_t drivers_uart_configure(const struct device *dev, uartConfig_t *ua
105105
* - 0: OK
106106
* - > 0: Busy
107107
*/
108-
int32_t drivers_uart_read(const struct device *dev, uartTransfer_t *request)
108+
int32_t sy1xx_uart_read(const struct device *dev, sy1xx_uartTransfer_t *request)
109109
{
110110
struct sy1xx_uart_config *config = (struct sy1xx_uart_config *)dev->config;
111111
struct sy1xx_uart_data *data = (struct sy1xx_uart_data *)dev->data;
@@ -125,7 +125,7 @@ int32_t drivers_uart_read(const struct device *dev, uartTransfer_t *request)
125125
int32_t ret = 0;
126126

127127
/* rx is ready */
128-
int32_t remaining_bytes = UDMA_READ_REG(config->base, UDMA_RX_SIZE_REG);
128+
int32_t remaining_bytes = SY1XX_UDMA_READ_REG(config->base, SY1XX_UDMA_RX_SIZE_REG);
129129
int32_t bytes_transferred = (DEVICE_MAX_BUFFER_SIZE - remaining_bytes);
130130

131131
if (bytes_transferred > 0) {
@@ -140,10 +140,10 @@ int32_t drivers_uart_read(const struct device *dev, uartTransfer_t *request)
140140
request->data_len = bytes_transferred;
141141

142142
/* stop and restart receiving */
143-
UDMA_CANCEL_RX(config->base);
143+
SY1XX_UDMA_CANCEL_RX(config->base);
144144

145145
/* start another read request, with maximum buffer size */
146-
UDMA_START_RX(config->base, (int32_t)data->read, DEVICE_MAX_BUFFER_SIZE, 0);
146+
SY1XX_UDMA_START_RX(config->base, (int32_t)data->read, DEVICE_MAX_BUFFER_SIZE, 0);
147147

148148
/* return: some data received */
149149
ret = 0;
@@ -162,7 +162,7 @@ int32_t drivers_uart_read(const struct device *dev, uartTransfer_t *request)
162162
* - 0: OK
163163
* - > 0: Busy
164164
*/
165-
int32_t drivers_uart_write(const struct device *dev, uartTransfer_t *request)
165+
int32_t sy1xx_uart_write(const struct device *dev, sy1xx_uartTransfer_t *request)
166166
{
167167
struct sy1xx_uart_config *config = (struct sy1xx_uart_config *)dev->config;
168168
struct sy1xx_uart_data *data = (struct sy1xx_uart_data *)dev->data;
@@ -180,15 +180,15 @@ int32_t drivers_uart_write(const struct device *dev, uartTransfer_t *request)
180180
return -2;
181181
}
182182

183-
if (0 == UDMA_IS_FINISHED_TX(config->base)) {
183+
if (0 == SY1XX_UDMA_IS_FINISHED_TX(config->base)) {
184184
/* writing not finished => busy */
185185
return 1;
186186
}
187187

188-
uint32_t remaining_bytes = UDMA_GET_REMAINING_TX(config->base);
188+
uint32_t remaining_bytes = SY1XX_UDMA_GET_REMAINING_TX(config->base);
189189

190190
if (remaining_bytes != 0) {
191-
UDMA_CANCEL_TX(config->base);
191+
SY1XX_UDMA_CANCEL_TX(config->base);
192192
return -3;
193193
}
194194

@@ -198,7 +198,7 @@ int32_t drivers_uart_write(const struct device *dev, uartTransfer_t *request)
198198
}
199199

200200
/* start new transmission */
201-
UDMA_START_TX(config->base, (uint32_t)data->write, request->data_len, 0);
201+
SY1XX_UDMA_START_TX(config->base, (uint32_t)data->write, request->data_len, 0);
202202

203203
/* success */
204204
return 0;
@@ -207,14 +207,14 @@ int32_t drivers_uart_write(const struct device *dev, uartTransfer_t *request)
207207
/*
208208
* it should be avoided to read single characters only
209209
*/
210-
static int sensry_uart_poll_in(const struct device *dev, unsigned char *c)
210+
static int sy1xx_uart_poll_in(const struct device *dev, unsigned char *c)
211211
{
212-
uartTransfer_t request = {
212+
sy1xx_uartTransfer_t request = {
213213
.data_len = 1,
214214
.data = c,
215215
};
216216

217-
if (0 == drivers_uart_read(dev, &request)) {
217+
if (0 == sy1xx_uart_read(dev, &request)) {
218218
return 0;
219219
}
220220

@@ -224,21 +224,21 @@ static int sensry_uart_poll_in(const struct device *dev, unsigned char *c)
224224
/*
225225
* it should be avoided to write single characters only
226226
*/
227-
static void sensry_uart_poll_out(const struct device *dev, unsigned char c)
227+
static void sy1xx_uart_poll_out(const struct device *dev, unsigned char c)
228228
{
229-
uartTransfer_t request = {
229+
sy1xx_uartTransfer_t request = {
230230
.data_len = 1,
231231
.data = &c,
232232
};
233233

234234
while (1) {
235-
if (0 == drivers_uart_write(dev, &request)) {
235+
if (0 == sy1xx_uart_write(dev, &request)) {
236236
break;
237237
}
238238
}
239239
}
240240

241-
static int sensry_uart_err_check(const struct device *dev)
241+
static int sy1xx_uart_err_check(const struct device *dev)
242242
{
243243
int err = 0;
244244

@@ -256,47 +256,51 @@ static int sy1xx_uart_init(const struct device *dev)
256256
}
257257

258258
/* UDMA clock enable */
259-
drivers_udma_enable_clock(DRIVERS_UDMA_UART, config->inst);
259+
sy1xx_udma_enable_clock(SY1XX_UDMA_MODULE_UART, config->inst);
260260

261261
/* PAD config */
262262
uint32_t pad_config_tx =
263-
PAD_CONFIG(0, PAD_SMT_DISABLE, PAD_SLEW_LOW, PAD_PULLUP_DIS, PAD_PULLDOWN_DIS,
264-
PAD_DRIVE_2PF, PAD_PMOD_NORMAL, PAD_DIR_OUTPUT);
263+
SY1XX_PAD_CONFIG(0, SY1XX_PAD_SMT_DISABLE, SY1XX_PAD_SLEW_LOW, SY1XX_PAD_PULLUP_DIS,
264+
SY1XX_PAD_PULLDOWN_DIS, SY1XX_PAD_DRIVE_2PF, SY1XX_PAD_PMOD_NORMAL,
265+
SY1XX_PAD_DIR_OUTPUT);
265266

266267
uint32_t pad_config_rx =
267-
PAD_CONFIG(8, PAD_SMT_DISABLE, PAD_SLEW_LOW, PAD_PULLUP_DIS, PAD_PULLDOWN_DIS,
268-
PAD_DRIVE_2PF, PAD_PMOD_NORMAL, PAD_DIR_INPUT);
268+
SY1XX_PAD_CONFIG(8, SY1XX_PAD_SMT_DISABLE, SY1XX_PAD_SLEW_LOW, SY1XX_PAD_PULLUP_DIS,
269+
SY1XX_PAD_PULLDOWN_DIS, SY1XX_PAD_DRIVE_2PF, SY1XX_PAD_PMOD_NORMAL,
270+
SY1XX_PAD_DIR_INPUT);
269271

270272
uint32_t pad_config_cts =
271-
PAD_CONFIG(16, PAD_SMT_DISABLE, PAD_SLEW_LOW, PAD_PULLUP_EN, PAD_PULLDOWN_DIS,
272-
PAD_DRIVE_2PF, PAD_PMOD_NORMAL, PAD_DIR_INPUT);
273+
SY1XX_PAD_CONFIG(16, SY1XX_PAD_SMT_DISABLE, SY1XX_PAD_SLEW_LOW, SY1XX_PAD_PULLUP_EN,
274+
SY1XX_PAD_PULLDOWN_DIS, SY1XX_PAD_DRIVE_2PF, SY1XX_PAD_PMOD_NORMAL,
275+
SY1XX_PAD_DIR_INPUT);
273276

274277
uint32_t pad_config_rts =
275-
PAD_CONFIG(24, PAD_SMT_DISABLE, PAD_SLEW_LOW, PAD_PULLUP_DIS, PAD_PULLDOWN_DIS,
276-
PAD_DRIVE_2PF, PAD_PMOD_NORMAL, PAD_DIR_OUTPUT);
278+
SY1XX_PAD_CONFIG(24, SY1XX_PAD_SMT_DISABLE, SY1XX_PAD_SLEW_LOW,
279+
SY1XX_PAD_PULLUP_DIS, SY1XX_PAD_PULLDOWN_DIS, SY1XX_PAD_DRIVE_2PF,
280+
SY1XX_PAD_PMOD_NORMAL, SY1XX_PAD_DIR_OUTPUT);
277281

278282
sys_write32((pad_config_tx | pad_config_rx | pad_config_cts | pad_config_rts),
279-
PAD_CONFIG_ADDR_UART + (config->inst * 4 + 0));
283+
SY1XX_PAD_CONFIG_ADDR_UART + (config->inst * 4 + 0));
280284

281-
uartConfig_t default_config = {
285+
sy1xx_uartConfig_t default_config = {
282286
.baudrate = 1000000,
283287
.parity = DRIVERS_UART_PAR_NONE,
284288
.stopbits = DRIVERS_UART_STOP_1,
285289
};
286290

287-
UDMA_CANCEL_RX(config->base);
288-
UDMA_CANCEL_TX(config->base);
291+
SY1XX_UDMA_CANCEL_RX(config->base);
292+
SY1XX_UDMA_CANCEL_TX(config->base);
289293

290-
drivers_uart_configure(dev, &default_config);
294+
sy1xx_uart_configure(dev, &default_config);
291295

292296
return 0;
293297
}
294298

295299
static const struct uart_driver_api sy1xx_uart_driver_api = {
296300

297-
.poll_in = sensry_uart_poll_in,
298-
.poll_out = sensry_uart_poll_out,
299-
.err_check = sensry_uart_err_check,
301+
.poll_in = sy1xx_uart_poll_in,
302+
.poll_out = sy1xx_uart_poll_out,
303+
.err_check = sy1xx_uart_err_check,
300304

301305
};
302306

0 commit comments

Comments
 (0)