Ignore:
File:
1 edited

Legend:

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

    rf300523 r8d2dd7f2  
    3535 */
    3636
    37 #include <async.h>
     37#include <inttypes.h>
    3838#include <errno.h>
    39 #include <io/chardev.h>
    40 #include <io/serial.h>
    41 #include <ipc/services.h>
    42 #include <loc.h>
    4339#include <stdlib.h>
    4440#include <stdio.h>
    4541#include <stddef.h>
     42#include <async.h>
     43#include <thread.h>
     44#include <ipc/services.h>
     45#include <loc.h>
     46#include <char_dev_iface.h>
    4647#include <str.h>
     48#include <ipc/serial_ctl.h>
    4749#include "../../tester.h"
    4850
     
    5456{
    5557        size_t cnt;
    56         serial_t *serial;
    57         chardev_t *chardev;
    58         int rc;
    59         size_t nread;
    60         size_t nwritten;
    6158       
    6259        if (test_argc < 1)
     
    8279        async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF,
    8380            IPC_FLAG_BLOCKING);
    84         if (sess == NULL)
     81        if (!sess)
    8582                return "Failed connecting to serial device";
    86        
    87         res = chardev_open(sess, &chardev);
    88         if (res != EOK) {
    89                 async_hangup(sess);
    90                 return "Failed opening serial port";
    91         }
    92        
    93         res = serial_open(sess, &serial);
    94         if (res != EOK) {
    95                 chardev_close(chardev);
    96                 async_hangup(sess);
    97                 return "Failed opening serial port";
    98         }
    9983       
    10084        char *buf = (char *) malloc(cnt + 1);
    10185        if (buf == NULL) {
    102                 chardev_close(chardev);
    103                 serial_close(serial);
    10486                async_hangup(sess);
    10587                return "Failed allocating input buffer";
    10688        }
    10789       
    108         unsigned old_baud;
    109         serial_parity_t old_par;
    110         unsigned old_stop;
    111         unsigned old_word_size;
    112        
    113         res = serial_get_comm_props(serial, &old_baud, &old_par,
    114             &old_word_size, &old_stop);
     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       
    115100        if (res != EOK) {
    116101                free(buf);
    117                 chardev_close(chardev);
    118                 serial_close(serial);
    119102                async_hangup(sess);
    120103                return "Failed to get old serial communication parameters";
    121104        }
    122105       
    123         res = serial_set_comm_props(serial, 1200, SERIAL_NO_PARITY, 8, 1);
     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       
    124111        if (EOK != res) {
    125112                free(buf);
    126                 chardev_close(chardev);
    127                 serial_close(serial);
    128113                async_hangup(sess);
    129114                return "Failed setting serial communication parameters";
     
    135120        size_t total = 0;
    136121        while (total < cnt) {
    137                
    138                 rc = chardev_read(chardev, buf, cnt - total, &nread);
    139                 if (rc != EOK) {
    140                         (void) serial_set_comm_props(serial, old_baud,
     122                ssize_t read = char_dev_read(sess, buf, cnt - total);
     123               
     124                if (read < 0) {
     125                        exch = async_exchange_begin(sess);
     126                        async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    141127                            old_par, old_word_size, old_stop);
     128                        async_exchange_end(exch);
    142129                       
    143130                        free(buf);
    144                         chardev_close(chardev);
    145                         serial_close(serial);
    146131                        async_hangup(sess);
    147132                        return "Failed reading from serial device";
    148133                }
    149134               
    150                 if (nread > cnt - total) {
    151                         (void) serial_set_comm_props(serial, old_baud,
     135                if ((size_t) read > cnt - total) {
     136                        exch = async_exchange_begin(sess);
     137                        async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    152138                            old_par, old_word_size, old_stop);
     139                        async_exchange_end(exch);
    153140                       
    154141                        free(buf);
    155                         chardev_close(chardev);
    156                         serial_close(serial);
    157142                        async_hangup(sess);
    158143                        return "Read more data than expected";
    159144                }
    160145               
    161                 TPRINTF("Read %zd bytes\n", nread);
    162                
    163                 buf[nread] = 0;
    164                
    165                 /*
    166                  * Write data back to the device to test the opposite
    167                  * direction of data transfer.
    168                  */
    169                 rc = chardev_write(chardev, buf, nread, &nwritten);
    170                 if (rc != EOK) {
    171                         (void) serial_set_comm_props(serial, old_baud,
    172                             old_par, old_word_size, old_stop);
    173                        
    174                         free(buf);
    175                         chardev_close(chardev);
    176                         serial_close(serial);
    177                         async_hangup(sess);
    178                         return "Failed writing to serial device";
    179                 }
    180                
    181                 if (nwritten != nread) {
    182                         (void) serial_set_comm_props(serial, old_baud,
    183                             old_par, old_word_size, old_stop);
    184                        
    185                         free(buf);
    186                         chardev_close(chardev);
    187                         serial_close(serial);
    188                         async_hangup(sess);
    189                         return "Written less data than read from serial device";
    190                 }
    191                
    192                 TPRINTF("Written %zd bytes\n", nwritten);
    193                
    194                 total += nread;
     146                TPRINTF("Read %zd bytes\n", read);
     147               
     148                if (read == 0)
     149                        thread_usleep(DEFAULT_SLEEP);
     150                else {
     151                        buf[read] = 0;
     152                       
     153                        /*
     154                         * Write data back to the device to test the opposite
     155                         * direction of data transfer.
     156                         */
     157                        ssize_t written = char_dev_write(sess, buf, read);
     158                       
     159                        if (written < 0) {
     160                                exch = async_exchange_begin(sess);
     161                                async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
     162                                    old_par, old_word_size, old_stop);
     163                                async_exchange_end(exch);
     164                               
     165                                free(buf);
     166                                async_hangup(sess);
     167                                return "Failed writing to serial device";
     168                        }
     169                       
     170                        if (written != read) {
     171                                exch = async_exchange_begin(sess);
     172                                async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
     173                                    old_par, old_word_size, old_stop);
     174                                async_exchange_end(exch);
     175                               
     176                                free(buf);
     177                                async_hangup(sess);
     178                                return "Written less data than read from serial device";
     179                        }
     180                       
     181                        TPRINTF("Written %zd bytes\n", written);
     182                }
     183               
     184                total += read;
    195185        }
    196186       
     
    198188       
    199189        size_t eot_size = str_size(EOT);
    200         rc = chardev_write(chardev, (void *) EOT, eot_size, &nwritten);
    201        
    202         (void) serial_set_comm_props(serial, old_baud, old_par, old_word_size,
    203             old_stop);
     190        ssize_t written = char_dev_write(sess, (void *) EOT, eot_size);
     191       
     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);
    204196       
    205197        free(buf);
    206         chardev_close(chardev);
    207         serial_close(serial);
    208198        async_hangup(sess);
    209199       
    210         if (rc != EOK)
     200        if (written < 0)
    211201                return "Failed to write EOT banner to serial device";
    212202       
    213         if (nwritten != eot_size)
     203        if ((size_t) written != eot_size)
    214204                return "Written less data than the size of the EOT banner "
    215205                    "to serial device";
Note: See TracChangeset for help on using the changeset viewer.