Project

General

Profile

Statistics
| Revision:

root / proj / src / test7.c @ 244

History | View | Annotate | Download (2 KB)

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