software_APIs  1.0.0
uart_api.h
Go to the documentation of this file.
1 
4 #ifndef UART_API_C_HEADER_FILE
5 #define UART_API_C_HEADER_FILE
6 
7 #ifndef DOXYGEN_SHOULD_SKIP_THIS
8 void arm_mgmt_uart_enable(){reg_wb_enable = reg_wb_enable | 0x40;}
9 void arm_mgmt_uart_disable(){reg_wb_enable = reg_wb_enable & 0xFFBF;}
10 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
11 // UART
22 void UART_enableTX(bool is_enable){
23  if (is_enable){
24  #ifdef ARM
25  // 0x08 RW CTRL[3:0] TxIntEn, RxIntEn, TxEn, RxEn
26  // [6] High speed test mode Enable
27  // [5] RX overrun interrupt enable
28  // [4] TX overrun interrupt enable
29  // [3] RX Interrupt Enable
30  // [2] TX Interrupt Enable
31  // [1] RX Enable
32  // [0] TX Enable
33  arm_mgmt_uart_enable();
34  reg_uart_ctrl = reg_uart_ctrl | 0x1;
35  reg_uart_clkdiv=0x3C0; // set default to 9600
36  #else
37  reg_uart_enable = 1;
38  #endif
39  }else{
40  #ifdef ARM
41  arm_mgmt_uart_disable();
42  reg_uart_ctrl = reg_uart_ctrl & 0xFFFFE;
43  reg_uart_clkdiv=0x3C0; // set default to 9600
44  #else
45  reg_uart_enable = 0;
46  #endif
47  }
48 
49 }
50 // UART
61 void UART_enableRX(bool is_enable){
62  if (is_enable){
63  #ifdef ARM
64  arm_mgmt_uart_enable();
65  reg_uart_ctrl = reg_uart_ctrl | 0x2;
66  reg_uart_clkdiv=0x3C0; // set default to 9600
67  #else
68  reg_uart_enable = 1;
69  #endif
70  }else{
71  #ifdef ARM
72  arm_mgmt_uart_disable();
73  reg_uart_ctrl = reg_uart_ctrl & 0xFFFFD;
74  reg_uart_clkdiv=0x3C0; // set default to 9600
75  #else
76  reg_uart_enable = 0;
77  #endif
78 
79  }
80 }
90  #ifdef ARM
91  while ((reg_uart_stat &2) == 0); // RX is empty
92  #else
93  while (uart_rxempty_read() == 1);
94  #endif
95  return reg_uart_data;
96 }
103  #ifndef ARM
104  uart_ev_pending_write(UART_EV_RX);
105  #endif
106  return;
107 }
108 
114  char* received_array =0;
115  char received_char;
116  int count = 0;
117  while ((received_char = UART_readChar()) != '\n'){
118  received_array[count++] = received_char;
119  UART_popChar();
120  }
121  received_array[count++] = received_char;
122  UART_popChar();
123  return received_array;
124 }
125 
126 
127 #ifdef DOXYGEN_DOCS_ONLY
128 
133 void print(const char *p){}
134 // real function defined at caravel repo
135 #endif // DOXYGEN_DOCS_ONLY
136 
142 void UART_sendChar(char c){
143  while (reg_uart_txfull == 1);
144  reg_uart_data = c;
145 }
146 
154 void UART_sendInt(int data){
155  for (int i = 0; i < 8; i++) {
156  // Extract the current 4-bit chunk
157  int chunk = (data >> (i * 4));
158  if (chunk == 0) {
159  break;
160  }
161  chunk = chunk & 0x0F;
162  char ch;
163  if (chunk >= 0 && chunk <= 9) {
164  ch = '0' + chunk; // Convert to corresponding decimal digit character
165  } else {
166  ch = 'A' + (chunk - 10); // Convert to corresponding hex character A-F
167  }
168  UART_sendChar(ch);
169  }
170  UART_sendChar('\n');
171 }
172 #endif // UART_API_C_HEADER_FILE
void UART_sendInt(int data)
Definition: uart_api.h:154
char * UART_readLine()
Definition: uart_api.h:113
char UART_readChar()
Definition: uart_api.h:89
void UART_sendChar(char c)
Definition: uart_api.h:142
void UART_popChar()
Definition: uart_api.h:102
void print(const char *p)
Definition: uart_api.h:133
void UART_enableRX(bool is_enable)
Definition: uart_api.h:61
void UART_enableTX(bool is_enable)
Definition: uart_api.h:22