Skip to content

Commit 0f2df12

Browse files
committed
os/arch,board: consolidate PINs definitions
This patch consolidates all definitions related to PINs being used for rtl8730e board. This version changes - creates one board specific file board_pins.c and modified one board specific file board_pins.h - board_pins.c Have all the board pins which are accessed according to enabled and disabled perpheral. - Disabled peripheral pins are mentioned as unused pins - Enabled peripheral pins are used in the pin_table start - board_pins.h used for accesing pin_table using Macro based indexing, It is called from the peripherals. - Pins are assigned during runtime.
1 parent 0899f30 commit 0f2df12

23 files changed

+1820
-396
lines changed

os/arch/arm/src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ else
104104
CFLAGS += -I$(ARCH_SRCDIR)/common
105105
CFLAGS += -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR)
106106
CFLAGS += -I$(TOPDIR)/kernel
107+
CFLAGS += -I$(TOPDIR)/board/common
107108
endif
108109
endif
109110

os/arch/arm/src/amebasmart/amebasmart_i2c.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include <arch/board/board.h>
4242

4343
#include "PinNames.h"
44-
#include "board_pins.h"
44+
#include <board_pins.h>
4545

4646
#include "up_arch.h"
4747
#include "ameba_i2c.h"
@@ -172,7 +172,7 @@ typedef struct i2c_m i2c_t;
172172

173173
struct amebasmart_i2c_priv_s {
174174
const struct i2c_ops_s *ops; /* Standard I2C operations */
175-
const struct amebasmart_i2c_config_s *config; /* Port configuration */
175+
struct amebasmart_i2c_config_s *config; /* Port configuration */
176176
int refs; /* Referernce count */
177177
sem_t sem_excl; /* Mutual exclusion semaphore */
178178
#ifndef CONFIG_I2C_POLLED
@@ -302,8 +302,6 @@ static const struct amebasmart_i2c_config_s amebasmart_i2c0_config = {
302302
//.busy_idle = CONFIG_I2C0_BUSYIDLE,
303303
//.filtscl = CONFIG_I2C0_FILTSCL,
304304
//.filtsda = CONFIG_I2C0_FILTSDA,
305-
.scl_pin = I2C0_SCL,
306-
.sda_pin = I2C0_SDA,
307305
#ifndef CONFIG_I2C_SLAVE
308306
.mode = AMEBASMART_I2C_MASTER,
309307
#else
@@ -334,8 +332,6 @@ static const struct amebasmart_i2c_config_s amebasmart_i2c1_config = {
334332
//.busy_idle = CONFIG_I2C1_BUSYIDLE,
335333
//.filtscl = CONFIG_I2C1_FILTSCL,
336334
//.filtsda = CONFIG_I2C1_FILTSDA,
337-
.scl_pin = I2C1_SCL,
338-
.sda_pin = I2C1_SDA,
339335
#ifndef CONFIG_I2C_SLAVE
340336
.mode = AMEBASMART_I2C_MASTER,
341337
#else
@@ -366,8 +362,6 @@ static const struct amebasmart_i2c_config_s amebasmart_i2c2_config = {
366362
//.busy_idle = CONFIG_I2C2_BUSYIDLE,
367363
//.filtscl = CONFIG_I2C2_FILTSCL,
368364
//.filtsda = CONFIG_I2C2_FILTSDA,
369-
.scl_pin = I2C2_SCL,
370-
.sda_pin = I2C2_SDA,
371365
#ifndef CONFIG_I2C_SLAVE
372366
.mode = AMEBASMART_I2C_MASTER,
373367
#else
@@ -1150,6 +1144,9 @@ static int amebasmart_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg
11501144
*
11511145
************************************************************************************/
11521146

1147+
/* Global I2C initialization completion flags */
1148+
static volatile bool g_i2c_board_init_complete = false; /* Board I2C initialization complete */
1149+
11531150
FAR struct i2c_dev_s *up_i2cinitialize(int port)
11541151
{
11551152
struct amebasmart_i2c_priv_s *priv = NULL;
@@ -1159,16 +1156,25 @@ FAR struct i2c_dev_s *up_i2cinitialize(int port)
11591156
#ifdef CONFIG_AMEBASMART_I2C0
11601157
if (port == 0) {
11611158
priv = (struct amebasmart_i2c_priv_s *)&amebasmart_i2c0_priv;
1159+
lldbg("\n");
1160+
priv->config->scl_pin = I2C_PIN(I2C0, I2C_SCL);
1161+
priv->config->sda_pin = I2C_PIN(I2C0, I2C_SDA);
11621162
} else
11631163
#endif
11641164
#ifdef CONFIG_AMEBASMART_I2C1
11651165
if (port == 1) {
11661166
priv = (struct amebasmart_i2c_priv_s *)&amebasmart_i2c1_priv;
1167+
1168+
priv->config->scl_pin = I2C_PIN(I2C1, I2C_SCL);
1169+
priv->config->sda_pin = I2C_PIN(I2C1, I2C_SDA);
11671170
} else
11681171
#endif
11691172
#ifdef CONFIG_AMEBASMART_I2C2
11701173
if (port == 2) {
11711174
priv = (struct amebasmart_i2c_priv_s *)&amebasmart_i2c2_priv;
1175+
1176+
priv->config->scl_pin = I2C_PIN(I2C2, I2C_SCL);
1177+
priv->config->sda_pin = I2C_PIN(I2C2, I2C_SDA);
11721178
} else
11731179
#endif
11741180
{
@@ -1180,9 +1186,10 @@ FAR struct i2c_dev_s *up_i2cinitialize(int port)
11801186
if (priv->i2c_object != NULL) {
11811187
return (struct i2c_dev_s *)priv;
11821188
}
1183-
/* Initialize private data for the first time, increment reference count,
1184-
* power-up hardware and configure GPIOs.
1185-
*/
1189+
1190+
/* Initialize private data for the first time, increment reference count,
1191+
* power-up hardware and configure GPIOs.
1192+
*/
11861193
flags = enter_critical_section();
11871194

11881195
if ((volatile int)priv->refs++ == 0) {

os/arch/arm/src/amebasmart/amebasmart_i2s.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
#include "PinNames.h"
5454
#include "i2s_api.h"
55-
#include "board_pins.h"
55+
#include <board_pins.h>
5656
/****************************************************************************
5757
* Pre-processor Definitions
5858
****************************************************************************/
@@ -216,12 +216,7 @@ struct amebasmart_i2s_s {
216216
};
217217
#ifdef CONFIG_AMEBASMART_I2S2
218218
/* I2S device structures */
219-
static const struct amebasmart_i2s_config_s amebasmart_i2s2_config = {
220-
.i2s_mclk_pin = I2S2_MCLK,
221-
.i2s_sclk_pin = I2S2_SCLK,
222-
.i2s_ws_pin = I2S2_WS,
223-
.i2s_sd_tx_pin = I2S2_SD_TX,
224-
.i2s_sd_rx_pin = I2S2_SD_RX,
219+
static struct amebasmart_i2s_config_s amebasmart_i2s2_config = {
225220

226221
.i2s_idx = I2S_NUM_2,
227222
.rxenab = 0,
@@ -230,12 +225,7 @@ static const struct amebasmart_i2s_config_s amebasmart_i2s2_config = {
230225
#endif
231226

232227
#ifdef CONFIG_AMEBASMART_I2S3
233-
static const struct amebasmart_i2s_config_s amebasmart_i2s3_config = {
234-
.i2s_mclk_pin = I2S3_MCLK,
235-
.i2s_sclk_pin = I2S3_SCLK,
236-
.i2s_ws_pin = I2S3_WS,
237-
.i2s_sd_tx_pin = I2S3_SD_TX,
238-
.i2s_sd_rx_pin = I2S3_SD_RX,
228+
static struct amebasmart_i2s_config_s amebasmart_i2s3_config = {
239229

240230
.i2s_idx = I2S_NUM_3,
241231
.rxenab = 1,
@@ -1811,11 +1801,23 @@ struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port)
18111801
#ifdef CONFIG_AMEBASMART_I2S2
18121802
if (port == I2S_NUM_2) {
18131803
hw_config_s = (struct amebasmart_i2s_config_s *)&amebasmart_i2s2_config;
1804+
1805+
hw_config_s->i2s_mclk_pin = I2S_PIN(I2S2, I2S_MCLK);
1806+
hw_config_s->i2s_sclk_pin = I2S_PIN(I2S2, I2S_SCLK);
1807+
hw_config_s->i2s_ws_pin = I2S_PIN(I2S2, I2S_WS);
1808+
hw_config_s->i2s_sd_tx_pin = I2S_PIN(I2S2, I2S_SD_TX);
1809+
hw_config_s->i2s_sd_rx_pin = I2S_PIN(I2S2, I2S_SD_RX);
18141810
} else
18151811
#endif
18161812
#ifdef CONFIG_AMEBASMART_I2S3
18171813
if (port == I2S_NUM_3) {
18181814
hw_config_s = (struct amebasmart_i2s_config_s *)&amebasmart_i2s3_config;
1815+
1816+
hw_config_s->i2s_mclk_pin = I2S_PIN(I2S3, I2S_MCLK);
1817+
hw_config_s->i2s_sclk_pin = I2S_PIN(I2S3, I2S_SCLK);
1818+
hw_config_s->i2s_ws_pin = I2S_PIN(I2S3, I2S_WS);
1819+
hw_config_s->i2s_sd_tx_pin = I2S_PIN(I2S3, I2S_SD_TX);
1820+
hw_config_s->i2s_sd_rx_pin = I2S_PIN(I2S3, I2S_SD_RX);
18191821
} else
18201822
#endif
18211823
{

os/arch/arm/src/amebasmart/amebasmart_serial.c

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
#include "serial_api.h"
8686
#include "PinNames.h"
87-
#include "board_pins.h"
87+
#include <board_pins.h>
8888
#include "objects.h"
8989
#include "ameba_uart.h"
9090
#include "tinyara/kmalloc.h"
@@ -234,6 +234,8 @@ struct rtl8730e_up_dev_s {
234234
#ifdef CONFIG_SERIAL_OFLOWCONTROL
235235
uint8_t oflow:1; /* output flow control (CTS) enabled */
236236
#endif
237+
uint8_t uart_type:3; /* identifies the uart type */
238+
237239
uint8_t tx_level;
238240
};
239241

@@ -348,11 +350,10 @@ static struct rtl8730e_up_dev_s g_uart0priv = {
348350
#endif
349351
.baud = CONFIG_UART0_BAUD,
350352
.irq = RTL8730E_UART0_IRQ,
351-
.tx = UART0_TX,
352-
.rx = UART0_RX,
353353
.FlowControl = FlowControlNone,
354354
.txint_enable = false,
355355
.rxint_enable = false,
356+
.uart_type = 0,
356357
};
357358

358359
static uart_dev_t g_uart0port = {
@@ -382,11 +383,10 @@ static struct rtl8730e_up_dev_s g_uart1priv = {
382383
#endif
383384
.baud = CONFIG_UART1_BAUD,
384385
.irq = RTL8730E_UART1_IRQ,
385-
.tx = UART1_TX,
386-
.rx = UART1_RX,
387386
.FlowControl = FlowControlNone,
388387
.txint_enable = false,
389388
.rxint_enable = false,
389+
.uart_type = 1,
390390
};
391391

392392
static uart_dev_t g_uart1port = {
@@ -416,13 +416,10 @@ static struct rtl8730e_up_dev_s g_uart2priv = {
416416
#endif
417417
.baud = CONFIG_UART2_BAUD,
418418
.irq = RTL8730E_UART2_IRQ,
419-
.tx = UART2_TX,
420-
.rx = UART2_RX,
421-
.rts = UART2_RTS,
422-
.cts = UART2_CTS,
423419
.FlowControl = FlowControlNone,
424420
.txint_enable = false,
425421
.rxint_enable = false,
422+
.uart_type = 2,
426423
};
427424

428425
static uart_dev_t g_uart2port = {
@@ -484,11 +481,10 @@ static struct rtl8730e_up_dev_s g_uart4priv = {
484481
#endif
485482
.baud = CONFIG_UART4_BAUD,
486483
.irq = RTL8730E_UART_LOG_IRQ,
487-
.tx = UART4_TX,
488-
.rx = UART4_RX,
489484
.FlowControl = FlowControlNone,
490485
.txint_enable = false,
491486
.rxint_enable = false,
487+
.uart_type = 4,
492488
};
493489

494490
static uart_dev_t g_uart4port = {
@@ -830,6 +826,15 @@ static int rtl8730e_up_setup(struct uart_dev_s *dev)
830826
{
831827
struct rtl8730e_up_dev_s *priv = (struct rtl8730e_up_dev_s *)dev->priv;
832828
DEBUGASSERT(priv);
829+
830+
#ifdef CONFIG_RTL8730E_UART4
831+
if (priv->uart_type == 4) {
832+
priv->tx = UART_PIN(UART4, UART_TX);
833+
priv->rx = UART_PIN(UART4, UART_RX);
834+
}
835+
#endif
836+
837+
833838
DEBUGASSERT(!sdrv[uart_index_get(priv->tx)]);
834839
sdrv[uart_index_get(priv->tx)] = (serial_t *)kmm_malloc(sizeof(serial_t));
835840
DEBUGASSERT(sdrv[uart_index_get(priv->tx)]);
@@ -868,8 +873,32 @@ static int rtl8730e_up_setup_pin(struct uart_dev_s *dev)
868873
struct rtl8730e_up_dev_s *priv = (struct rtl8730e_up_dev_s *)dev->priv;
869874
DEBUGASSERT(priv);
870875

871-
serial_pin_init(priv->tx, priv->rx);
872-
return OK;
876+
#ifdef CONFIG_RTL8730E_UART0
877+
if (priv->uart_type == 0) {
878+
priv->tx = UART_PIN(UART0, UART_TX);
879+
priv->rx = UART_PIN(UART0, UART_RX);
880+
}
881+
#endif
882+
883+
#ifdef CONFIG_RTL8730E_UART1
884+
if (priv->uart_type == 1) {
885+
#if defined(CONFIG_RTL8730E_BOARD_AIL) || defined(CONFIG_RTL8730E_BOARD_AILP) || defined(CONFIG_RTL8730E_BOARD_AILPW) || defined(CONFIG_RTL8730E_BOARD_AID)
886+
priv->tx = UART_PIN(UART1, UART_TX);
887+
priv->rx = UART_PIN(UART1, UART_RX);
888+
#endif
889+
}
890+
#endif
891+
892+
#ifdef CONFIG_RTL8730E_UART2
893+
if (priv->uart_type == 2) {
894+
priv->tx = UART_PIN(UART2, UART_TX);
895+
priv->rx = UART_PIN(UART2, UART_RX);
896+
priv->cts = UART_PIN(UART2, UART_CTS);
897+
priv->rts = UART_PIN(UART2, UART_RTS);
898+
}
899+
#endif
900+
serial_pin_init(priv->tx, priv->rx);
901+
return OK;
873902
}
874903

875904
/****************************************************************************
@@ -1244,7 +1273,6 @@ void up_serialinit(void)
12441273
/* Register the console */
12451274
uart_register("/dev/console", &CONSOLE_DEV);
12461275
#endif
1247-
12481276
/* Register all UARTs */
12491277
#ifdef TTYS0_DEV
12501278
/* Default LOGUART(UART4) is already running and could not be reinit or stopped */
@@ -1268,6 +1296,7 @@ void up_serialinit(void)
12681296
pmu_register_sleep_callback(PMU_LOGUART_DEVICE, (PSM_HOOK_FUN)rtk_loguart_suspend, NULL, (PSM_HOOK_FUN)rtk_loguart_resume, NULL);
12691297
pmu_register_sleep_callback(PMU_UART1_DEVICE, (PSM_HOOK_FUN)rtk_uart_suspend, NULL, (PSM_HOOK_FUN)rtk_uart_resume, NULL);
12701298
#endif
1299+
12711300
}
12721301

12731302
/****************************************************************************
@@ -1426,5 +1455,3 @@ int up_getc(void)
14261455
return ch;
14271456
}
14281457
#endif /* USE_SERIALDRIVER */
1429-
1430-

os/arch/arm/src/amebasmart/amebasmart_spi.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
#include "chip.h"
4343

44-
#include "board_pins.h"
44+
#include <board_pins.h>
4545
#include "amebasmart_spi.h"
4646
#include "PinNames.h"
4747
#include "spi_api.h"
@@ -235,13 +235,6 @@ static struct amebasmart_spidev_s g_spi0dev = {
235235
.spi_object = {0},
236236
.refs = 0,
237237
.spi_idx = MBED_SPI0,
238-
.spi_mosi = SPI0_MOSI,
239-
.spi_miso = SPI0_MISO,
240-
.spi_sclk = SPI0_SCLK,
241-
.spi_cs0 = SPI0_CS0,
242-
#if defined(CONFIG_SPI_CS) && defined(CONFIG_AMEBASMART_SPI0_CS)
243-
.spi_cs1 = SPI0_CS1,
244-
#endif
245238
.nbits = 8,
246239
.mode = SPIDEV_MODE0,
247240
.role = AMEBASMART_SPI_MASTER,
@@ -294,13 +287,6 @@ static struct amebasmart_spidev_s g_spi1dev = {
294287
.spi_object = {0},
295288
.refs = 0,
296289
.spi_idx = MBED_SPI1,
297-
.spi_mosi = SPI1_MOSI,
298-
.spi_miso = SPI1_MISO,
299-
.spi_sclk = SPI1_SCLK,
300-
.spi_cs0 = SPI1_CS0,
301-
#if defined(CONFIG_SPI_CS) && defined(CONFIG_AMEBASMART_SPI1_CS)
302-
.spi_cs1 = SPI1_CS1,
303-
#endif
304290
.nbits = 8,
305291
.mode = SPIDEV_MODE0,
306292
.role = AMEBASMART_SPI_MASTER
@@ -1558,6 +1544,13 @@ FAR struct spi_dev_s *up_spiinitialize(int port)
15581544

15591545
priv = &g_spi0dev;
15601546

1547+
priv->spi_mosi = SPI_PIN(SPI0, SPI_MOSI);
1548+
priv->spi_miso = SPI_PIN(SPI0, SPI_MISO);
1549+
priv->spi_sclk = SPI_PIN(SPI0, SPI_SCLK);
1550+
priv->spi_cs0 = SPI_PIN(SPI0, SPI_CS0);
1551+
#if defined(CONFIG_SPI_CS) && defined(CONFIG_AMEBASMART_SPI0_CS)
1552+
priv->spi_cs1 = SPI_PIN(SPI0, SPI_CS1);
1553+
#endif
15611554
if (priv->refs > 0) {
15621555
dbg("SPI port%d has been initialized before!\n", port);
15631556
leave_critical_section(flags);
@@ -1579,6 +1572,14 @@ FAR struct spi_dev_s *up_spiinitialize(int port)
15791572

15801573
priv = &g_spi1dev;
15811574

1575+
priv->spi_mosi = SPI_PIN(SPI1, SPI_MOSI);
1576+
priv->spi_miso = SPI_PIN(SPI1, SPI_MISO);
1577+
priv->spi_sclk = SPI_PIN(SPI1, SPI_SCLK);
1578+
priv->spi_cs0 = SPI_PIN(SPI1, SPI_CS0);
1579+
#if defined(CONFIG_SPI_CS) && defined(CONFIG_AMEBASMART_SPI1_CS)
1580+
priv->spi_cs1 = SPI_PIN(SPI1, SPI_CS1);
1581+
#endif
1582+
15821583
if (priv->refs > 0) {
15831584
dbg("SPI port%d has been initialized before!\n", port);
15841585
leave_critical_section(flags);

0 commit comments

Comments
 (0)