2727 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828 *
2929--------------------------------------------- */
30- #include <stdio.h>
30+ #include "dw_uart.h"
31+ #include "nsim_uart_obj.h"
3132#include "arc.h"
3233#include "arc_builtin.h"
3334#include "embARC_toolchain.h"
3940 * NSIM UART 0 Object Instantiation
4041 */
4142#if (USE_NSIM_UART_0 )
42-
43- DEV_UART nsim_uart_0 ; /*!< nsim uart object */
44-
45-
46- /** nsim uart 0 open */
47- static int32_t nsim_uart_0_open (uint32_t baud )
43+ static void dw_uart_0_isr (void * ptr );
44+ #define DW_UART_0_BASE (0xf0000000) /*!< designware uart 0 relative baseaddr */
45+ #define DW_UART_0_INTNO (24) /*!< designware uart 0 interrupt number */
46+
47+ static DEV_UART dw_uart_0 ; /*!< designware uart object */
48+ static DW_UART_CTRL dw_uart_0_ctrl = { /*!< designware uart 0 ctrl */
49+ 0 , 1000000 , DW_UART_0_INTNO , (INT_HANDLER )dw_uart_0_isr ,
50+ 1 , 1 , 0
51+ };
52+
53+ /** designware uart 0 open */
54+ static int32_t dw_uart_0_open (uint32_t baud )
4855{
49- /* no need to open, stdio is used */
50- return 0 ;
56+ return dw_uart_open (& dw_uart_0 , baud );
5157}
52- /** nsim uart 0 close */
53- static int32_t nsim_uart_0_close (void )
58+ /** designware uart 0 close */
59+ static int32_t dw_uart_0_close (void )
5460{
55- return 0 ;
61+ return dw_uart_close ( & dw_uart_0 ) ;
5662}
57- /** nsim uart 0 control */
58- static int32_t nsim_uart_0_control (uint32_t ctrl_cmd , void * param )
63+ /** designware uart 0 control */
64+ static int32_t dw_uart_0_control (uint32_t ctrl_cmd , void * param )
5965{
60- return 0 ;
66+ return dw_uart_control ( & dw_uart_0 , ctrl_cmd , param ) ;
6167}
62- /** nsim uart 0 write */
63- static int32_t nsim_uart_0_write (const void * data , uint32_t len )
68+ /** designware uart 0 write */
69+ static int32_t dw_uart_0_write (const void * data , uint32_t len )
6470{
65- return fwrite ( data , len , sizeof ( unsigned char ), stdout );
71+ return dw_uart_write ( & dw_uart_0 , data , len );
6672}
67- /** nsim uart 0 close */
68- static int32_t nsim_uart_0_read (void * data , uint32_t len )
73+ /** designware uart 0 close */
74+ static int32_t dw_uart_0_read (void * data , uint32_t len )
6975{
70- unsigned int i ;
71- int c ;
72-
73- for (i = 0 ; i < len ; i ++ ) {
74- c = getchar ();
75- if (c < 0 ) {
76- break ;
77- }
78- if (c == 10 ) {
79- c = 13 ;
80- }
81- * ((unsigned char * )data ) = (unsigned char )c ;
82- data ++ ;
83- }
84-
85- return i ;
76+ return dw_uart_read (& dw_uart_0 , data , len );
8677}
87-
88- /** install nsim uart 0 to system */
89- static void nsim_uart_0_install (void )
78+ /** designware uart 0 interrupt rountine */
79+ static void dw_uart_0_isr (void * ptr )
80+ {
81+ dw_uart_isr (& dw_uart_0 , ptr );
82+ }
83+ /** install designware uart 0 to system */
84+ static void dw_uart_0_install (void )
9085{
91- DEV_UART * nsim_uart_ptr = & nsim_uart_0 ;
86+ uint32_t uart_abs_base = 0 ;
87+ DEV_UART * dw_uart_ptr = & dw_uart_0 ;
88+ DEV_UART_INFO * dw_uart_info_ptr = & (dw_uart_0 .uart_info );
89+ DW_UART_CTRL * dw_uart_ctrl_ptr = & dw_uart_0_ctrl ;
90+
91+ /**
92+ * get absolute designware base address
93+ */
94+ uart_abs_base = (uint32_t )DW_UART_0_BASE ;
95+ dw_uart_ctrl_ptr -> dw_uart_regbase = uart_abs_base ;
96+
97+ /** uart info init */
98+ dw_uart_info_ptr -> uart_ctrl = (void * )dw_uart_ctrl_ptr ;
99+ dw_uart_info_ptr -> opn_cnt = 0 ;
100+ dw_uart_info_ptr -> status = 0 ;
101+ dw_uart_info_ptr -> baudrate = UART_BAUDRATE_115200 ; /* default 115200bps */
92102
93103 /** uart dev init */
94- nsim_uart_ptr -> uart_open = nsim_uart_0_open ;
95- nsim_uart_ptr -> uart_close = nsim_uart_0_close ;
96- nsim_uart_ptr -> uart_control = nsim_uart_0_control ;
97- nsim_uart_ptr -> uart_write = nsim_uart_0_write ;
98- nsim_uart_ptr -> uart_read = nsim_uart_0_read ;
104+ dw_uart_ptr -> uart_open = dw_uart_0_open ;
105+ dw_uart_ptr -> uart_close = dw_uart_0_close ;
106+ dw_uart_ptr -> uart_control = dw_uart_0_control ;
107+ dw_uart_ptr -> uart_write = dw_uart_0_write ;
108+ dw_uart_ptr -> uart_read = dw_uart_0_read ;
99109
100110}
101111#endif /* USE_DW_UART_0 */
@@ -114,7 +124,7 @@ DEV_UART_PTR uart_get_dev(int32_t uart_id)
114124 switch (uart_id ) {
115125#if (USE_NSIM_UART_0 )
116126 case NSIM_UART_0_ID :
117- return & nsim_uart_0 ;
127+ return & dw_uart_0 ;
118128 break ;
119129#endif
120130 default :
@@ -130,6 +140,6 @@ DEV_UART_PTR uart_get_dev(int32_t uart_id)
130140void nsim_uart_all_install (void )
131141{
132142#if (USE_NSIM_UART_0 )
133- nsim_uart_0_install ();
143+ dw_uart_0_install ();
134144#endif
135145}
0 commit comments