Project

General

Profile

Statistics
| Revision:

root / proj / src / test7.c @ 269

History | View | Annotate | Download (2.13 KB)

1 235 up20180642
#include <lcom/lcf.h>
2
3
#include "errors.h"
4 261 up20180642
#include "nctp.h"
5 235 up20180642
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 261 up20180642
                uint8_t c = ' ';
41
                int r;
42
                while(c != '.'){
43
                        r = nctp_get_char_poll(base_addr, &c);
44
                        if(r == TIMEOUT_ERROR) continue;
45
                        else if(r != SUCCESS ) return r;
46
                        printf("%c", c);
47 244 up20180642
                }
48
        }else{
49
                for(int i = 0; i < stringc; ++i){
50 252 up20180642
                        for(int j = 0; strings[i][j] != 0; ++j)
51 261 up20180642
                                if((ret = nctp_send_char_poll(base_addr, strings[i][j])))
52 252 up20180642
                                        return ret;
53
                        if(i+1 != stringc)
54 261 up20180642
                                if((ret = nctp_send_char_poll(base_addr, ' '))) return ret;
55 244 up20180642
                }
56 261 up20180642
                if((ret = nctp_send_char_poll(base_addr, '.'))) return ret;
57 244 up20180642
        }
58
        return SUCCESS;
59 235 up20180642
}
60
61
int ser_test_int(/* details to be provided */) {
62
    /* To be completed */
63
        return 1;
64
}
65
66
int ser_test_fifo(/* details to be provided */) {
67
    /* To be completed */
68
        return 1;
69
}