root / proj / src / test7.c @ 250
History | View | Annotate | Download (2.04 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 | if(tx == 0){ |
||
38 | 249 | up20180642 | uint8_t c; |
39 | if((ret = uart_get_char_poll(base_addr, &c))) return ret; |
||
40 | while((char)c != '.'){ |
||
41 | printf("%c", (char)c); |
||
42 | if((ret = uart_get_char_poll(base_addr, &c))) return ret; |
||
43 | 244 | up20180642 | } |
44 | 249 | up20180642 | printf("%c\n", (char)c); |
45 | 244 | up20180642 | }else{
|
46 | for(int i = 0; i < stringc; ++i){ |
||
47 | 249 | up20180642 | size_t sz = strlen(strings[i]); |
48 | if((ret = uart_send_memory_poll(base_addr, strings[i], sz))) return ret; |
||
49 | if(i+1 != stringc) if((ret = uart_send_memory_poll(base_addr, " ", 1))) return ret; |
||
50 | 244 | up20180642 | } |
51 | 249 | up20180642 | if((ret = uart_send_memory_poll(base_addr, ".", 1))) return ret; |
52 | 244 | up20180642 | } |
53 | return SUCCESS;
|
||
54 | 235 | up20180642 | } |
55 | |||
56 | int ser_test_int(/* details to be provided */) { |
||
57 | /* To be completed */
|
||
58 | return 1; |
||
59 | } |
||
60 | |||
61 | int ser_test_fifo(/* details to be provided */) { |
||
62 | /* To be completed */
|
||
63 | return 1; |
||
64 | } |