1818#include  <driverlib/uart.h> 
1919
2020struct  uart_cc32xx_dev_data_t  {
21+ 	uint32_t  prcm ;
22+ 	uint32_t  baud_rate ;
2123#ifdef  CONFIG_UART_INTERRUPT_DRIVEN 
2224	uart_irq_callback_user_data_t  cb ; /**< Callback function pointer */ 
2325	void  * cb_data ; /**< Callback function arg */ 
@@ -36,17 +38,6 @@ struct uart_cc32xx_dev_data_t {
3638static  void  uart_cc32xx_isr (const  struct  device  * dev );
3739#endif 
3840
39- static  const  struct  uart_device_config  uart_cc32xx_dev_cfg_0  =  {
40- 	.base  =  (void  * )DT_INST_REG_ADDR (0 ),
41- 	.sys_clk_freq  =  DT_INST_PROP_BY_PHANDLE (0 , clocks , clock_frequency )
42- };
43- 
44- static  struct  uart_cc32xx_dev_data_t  uart_cc32xx_dev_data_0  =  {
45- #ifdef  CONFIG_UART_INTERRUPT_DRIVEN 
46- 	.cb  =  NULL ,
47- #endif 
48- };
49- 
5041/* 
5142 *  CC32XX UART has a configurable FIFO length, from 1 to 8 characters. 
5243 *  However, the Zephyr console driver, and the Zephyr uart sample test, assume 
@@ -57,13 +48,17 @@ static struct uart_cc32xx_dev_data_t uart_cc32xx_dev_data_0 = {
5748static  int  uart_cc32xx_init (const  struct  device  * dev )
5849{
5950	const  struct  uart_device_config  * config  =  DEV_CFG (dev );
51+ 	const  struct  uart_cc32xx_dev_data_t  * data  =  DEV_DATA (dev );
52+ 
53+ 	MAP_PRCMPeripheralClkEnable (data -> prcm ,
54+ 		    PRCM_RUN_MODE_CLK  | PRCM_SLP_MODE_CLK );
6055
61- 	MAP_PRCMPeripheralReset (PRCM_UARTA0 );
56+ 	MAP_PRCMPeripheralReset (data -> prcm );
6257
6358	/* This also calls MAP_UARTEnable() to enable the FIFOs: */ 
6459	MAP_UARTConfigSetExpClk ((unsigned long )config -> base ,
65- 				MAP_PRCMPeripheralClockGet (PRCM_UARTA0 ),
66- 				DT_INST_PROP ( 0 ,  current_speed ) ,
60+ 				MAP_PRCMPeripheralClockGet (data -> prcm ),
61+ 				data -> baud_rate ,
6762				(UART_CONFIG_WLEN_8  | UART_CONFIG_STOP_ONE 
6863				 | UART_CONFIG_PAR_NONE ));
6964	MAP_UARTFlowControlSet ((unsigned long )config -> base ,
@@ -75,11 +70,7 @@ static int uart_cc32xx_init(const struct device *dev)
7570	/* Clear any pending UART RX interrupts: */ 
7671	MAP_UARTIntClear ((unsigned long )config -> base , UART_INT_RX );
7772
78- 	IRQ_CONNECT (DT_INST_IRQN (0 ),
79- 		    DT_INST_IRQ (0 , priority ),
80- 		    uart_cc32xx_isr , DEVICE_DT_INST_GET (0 ),
81- 		    0 );
82- 	irq_enable (DT_INST_IRQN (0 ));
73+ 	config -> irq_config_func (dev );
8374
8475	/* Fill the tx fifo, so Zephyr console & shell subsystems get "primed" 
8576	 * with first tx fifo empty interrupt when they first call 
@@ -314,8 +305,33 @@ static const struct uart_driver_api uart_cc32xx_driver_api = {
314305#endif  /* CONFIG_UART_INTERRUPT_DRIVEN */ 
315306};
316307
317- DEVICE_DT_INST_DEFINE (0 , uart_cc32xx_init ,
318- 		    device_pm_control_nop , & uart_cc32xx_dev_data_0 ,
319- 		    & uart_cc32xx_dev_cfg_0 ,
320- 		    PRE_KERNEL_1 , CONFIG_KERNEL_INIT_PRIORITY_DEVICE ,
321- 		    (void  * )& uart_cc32xx_driver_api );
308+ #define  UART_32XX_DEVICE (idx ) \
309+ IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \
310+ 	(static void uart_cc32xx_cfg_func_##idx(const struct device *dev) \
311+ 	{ \
312+ 		IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, ( \
313+ 			IRQ_CONNECT(DT_INST_IRQN(idx), \
314+ 			    DT_INST_IRQ(idx, priority), \
315+ 			    uart_cc32xx_isr, DEVICE_DT_INST_GET(idx), \
316+ 			    0); \
317+ 			irq_enable(DT_INST_IRQN(idx))) \
318+ 		); \
319+ 	})); \
320+ static const struct uart_device_config uart_cc32xx_dev_cfg_##idx = { \
321+ 	.base = (void *)DT_INST_REG_ADDR(idx), \
322+ 	.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(idx, clocks, clock_frequency),\
323+ 	IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \
324+ 		    (.irq_config_func = uart_cc32xx_cfg_func_##idx,)) \
325+ }; \
326+ static struct uart_cc32xx_dev_data_t uart_cc32xx_dev_data_##idx = { \
327+ 	.prcm = PRCM_UARTA##idx, \
328+ 	.baud_rate = DT_INST_PROP(idx, current_speed), \
329+ 	IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, (.cb = NULL,)) \
330+ }; \
331+ DEVICE_DT_INST_DEFINE(idx, uart_cc32xx_init, \
332+ 	device_pm_control_nop, &uart_cc32xx_dev_data_##idx, \
333+ 	&uart_cc32xx_dev_cfg_##idx, \
334+ 	PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
335+ 	(void *)&uart_cc32xx_driver_api); \
336+ 
337+ DT_INST_FOREACH_STATUS_OKAY (UART_32XX_DEVICE );
0 commit comments