Ignore:
Timestamp:
2017-11-21T18:40:27Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
74017ce, d51a0d6, ee44809
Parents:
afec1be
Message:

Add C API for serial port control.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/hw/serial/serial1.c

    rafec1be rc4c6025  
    4646#include <char_dev_iface.h>
    4747#include <str.h>
    48 #include <ipc/serial_ctl.h>
     48#include <io/serial.h>
    4949#include "../../tester.h"
    5050
     
    5656{
    5757        size_t cnt;
     58        serial_t *serial;
    5859       
    5960        if (test_argc < 1)
     
    7980        async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF,
    8081            IPC_FLAG_BLOCKING);
    81         if (!sess)
     82        if (sess == NULL)
    8283                return "Failed connecting to serial device";
     84       
     85        res = serial_open(sess, &serial);
     86        if (res != EOK)
     87                return "Failed opening serial port";
    8388       
    8489        char *buf = (char *) malloc(cnt + 1);
    8590        if (buf == NULL) {
     91                serial_close(serial);
    8692                async_hangup(sess);
    8793                return "Failed allocating input buffer";
    8894        }
    8995       
    90         sysarg_t old_baud;
    91         sysarg_t old_par;
    92         sysarg_t old_stop;
    93         sysarg_t old_word_size;
    94        
    95         async_exch_t *exch = async_exchange_begin(sess);
    96         res = async_req_0_4(exch, SERIAL_GET_COM_PROPS, &old_baud,
    97             &old_par, &old_word_size, &old_stop);
    98         async_exchange_end(exch);
    99        
     96        unsigned old_baud;
     97        serial_parity_t old_par;
     98        unsigned old_stop;
     99        unsigned old_word_size;
     100       
     101        res = serial_get_comm_props(serial, &old_baud, &old_par,
     102            &old_word_size, &old_stop);
    100103        if (res != EOK) {
    101104                free(buf);
     105                serial_close(serial);
    102106                async_hangup(sess);
    103107                return "Failed to get old serial communication parameters";
    104108        }
    105109       
    106         exch = async_exchange_begin(sess);
    107         res = async_req_4_0(exch, SERIAL_SET_COM_PROPS, 1200,
    108             SERIAL_NO_PARITY, 8, 1);
    109         async_exchange_end(exch);
    110        
     110        res = serial_set_comm_props(serial, 1200, SERIAL_NO_PARITY, 8, 1);
    111111        if (EOK != res) {
    112112                free(buf);
     113                serial_close(serial);
    113114                async_hangup(sess);
    114115                return "Failed setting serial communication parameters";
     
    123124               
    124125                if (read < 0) {
    125                         exch = async_exchange_begin(sess);
    126                         async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
     126                        (void) serial_set_comm_props(serial, old_baud,
    127127                            old_par, old_word_size, old_stop);
    128                         async_exchange_end(exch);
    129128                       
    130129                        free(buf);
     130                        serial_close(serial);
    131131                        async_hangup(sess);
    132132                        return "Failed reading from serial device";
     
    134134               
    135135                if ((size_t) read > cnt - total) {
    136                         exch = async_exchange_begin(sess);
    137                         async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
     136                        (void) serial_set_comm_props(serial, old_baud,
    138137                            old_par, old_word_size, old_stop);
    139                         async_exchange_end(exch);
    140138                       
    141139                        free(buf);
     140                        serial_close(serial);
    142141                        async_hangup(sess);
    143142                        return "Read more data than expected";
     
    158157                       
    159158                        if (written < 0) {
    160                                 exch = async_exchange_begin(sess);
    161                                 async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
     159                                (void) serial_set_comm_props(serial, old_baud,
    162160                                    old_par, old_word_size, old_stop);
    163                                 async_exchange_end(exch);
    164161                               
    165162                                free(buf);
     163                                serial_close(serial);
    166164                                async_hangup(sess);
    167165                                return "Failed writing to serial device";
     
    169167                       
    170168                        if (written != read) {
    171                                 exch = async_exchange_begin(sess);
    172                                 async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
     169                                (void) serial_set_comm_props(serial, old_baud,
    173170                                    old_par, old_word_size, old_stop);
    174                                 async_exchange_end(exch);
    175171                               
    176172                                free(buf);
     173                                serial_close(serial);
    177174                                async_hangup(sess);
    178175                                return "Written less data than read from serial device";
     
    190187        ssize_t written = char_dev_write(sess, (void *) EOT, eot_size);
    191188       
    192         exch = async_exchange_begin(sess);
    193         async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    194             old_par, old_word_size, old_stop);
    195         async_exchange_end(exch);
     189        (void) serial_set_comm_props(serial, old_baud, old_par, old_word_size,
     190            old_stop);
    196191       
    197192        free(buf);
     193        serial_close(serial);
    198194        async_hangup(sess);
    199195       
Note: See TracChangeset for help on using the changeset viewer.