root / proj / src / test7.c @ 258
History | View | Annotate | Download (2.16 KB)
1 | 235 | up20180642 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | #include "errors.h" |
||
4 | #include "uart.h" |
||
5 | |||
6 | int ser_test_conf(unsigned short base_addr) { |
||
7 | int ret = SUCCESS;
|
||
8 | uart_config conf; |
||
9 | if((ret = uart_get_config(base_addr, &conf))) return ret; |
||
10 | uart_print_config(conf); |
||
11 | return SUCCESS;
|
||
12 | } |
||
13 | |||
14 | int ser_test_set(unsigned short base_addr, unsigned long bits, unsigned long stop, |
||
15 | long parity, unsigned long rate) { |
||
16 | int par;
|
||
17 | switch(parity){
|
||
18 | case -1: par = uart_parity_none; break; |
||
19 | case 0: par = uart_parity_even; break; |
||
20 | case +1: par = uart_parity_odd ; break; |
||
21 | default: return INVALID_ARG; |
||
22 | } |
||
23 | int ret = SUCCESS;
|
||
24 | 241 | up20180642 | if((ret = uart_set_bits_per_character(base_addr, bits))) return ret; tickdelay(micros_to_ticks(100000)); |
25 | if((ret = uart_set_stop_bits (base_addr, stop))) return ret; tickdelay(micros_to_ticks(100000)); |
||
26 | if((ret = uart_set_parity (base_addr, par ))) return ret; tickdelay(micros_to_ticks(100000)); |
||
27 | 235 | up20180642 | if((ret = uart_set_bit_rate (base_addr, rate))) return ret; tickdelay(micros_to_ticks(100000)); |
28 | |||
29 | return SUCCESS;
|
||
30 | } |
||
31 | |||
32 | int ser_test_poll(unsigned short base_addr, unsigned char tx, unsigned long bits, |
||
33 | unsigned long stop, long parity, unsigned long rate, |
||
34 | int stringc, char *strings[]) { |
||
35 | 244 | up20180642 | int ret = SUCCESS;
|
36 | if((ret = ser_test_set(base_addr, bits, stop, parity, rate))) return ret; |
||
37 | 252 | up20180642 | if((ret = uart_disable_int_rx(base_addr))) return ret; |
38 | if((ret = uart_disable_int_tx(base_addr))) return ret; |
||
39 | 244 | up20180642 | if(tx == 0){ |
40 | 249 | up20180642 | uint8_t c; |
41 | if((ret = uart_get_char_poll(base_addr, &c))) return ret; |
||
42 | while((char)c != '.'){ |
||
43 | printf("%c", (char)c); |
||
44 | if((ret = uart_get_char_poll(base_addr, &c))) return ret; |
||
45 | 244 | up20180642 | } |
46 | 249 | up20180642 | printf("%c\n", (char)c); |
47 | 244 | up20180642 | }else{
|
48 | for(int i = 0; i < stringc; ++i){ |
||
49 | 252 | up20180642 | for(int j = 0; strings[i][j] != 0; ++j) |
50 | if((ret = uart_send_char_poll(base_addr, strings[i][j])))
|
||
51 | return ret;
|
||
52 | if(i+1 != stringc) |
||
53 | if((ret = uart_send_char_poll(base_addr, ' '))) return ret; |
||
54 | 244 | up20180642 | } |
55 | 252 | up20180642 | if((ret = uart_send_char_poll(base_addr, '.'))) return ret; |
56 | 244 | up20180642 | } |
57 | return SUCCESS;
|
||
58 | 235 | up20180642 | } |
59 | |||
60 | int ser_test_int(/* details to be provided */) { |
||
61 | /* To be completed */
|
||
62 | return 1; |
||
63 | } |
||
64 | |||
65 | int ser_test_fifo(/* details to be provided */) { |
||
66 | /* To be completed */
|
||
67 | return 1; |
||
68 | } |