Ignore:
File:
1 edited

Legend:

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

    ra35b458 r5a6cc679  
    5959        size_t nread;
    6060        size_t nwritten;
    61 
     61       
    6262        if (test_argc < 1)
    6363                cnt = DEFAULT_COUNT;
     
    7373                        return "Unexpected argument error";
    7474                }
    75 
     75       
    7676        service_id_t svc_id;
    7777        errno_t res = loc_service_get_id("devices/\\hw\\pci0\\00:01.0\\com1\\a",
     
    7979        if (res != EOK)
    8080                return "Failed getting serial port service ID";
    81 
     81       
    8282        async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF,
    8383            IPC_FLAG_BLOCKING);
    8484        if (sess == NULL)
    8585                return "Failed connecting to serial device";
    86 
     86       
    8787        res = chardev_open(sess, &chardev);
    8888        if (res != EOK) {
     
    9090                return "Failed opening serial port";
    9191        }
    92 
     92       
    9393        res = serial_open(sess, &serial);
    9494        if (res != EOK) {
     
    9797                return "Failed opening serial port";
    9898        }
    99 
     99       
    100100        char *buf = (char *) malloc(cnt + 1);
    101101        if (buf == NULL) {
     
    105105                return "Failed allocating input buffer";
    106106        }
    107 
     107       
    108108        unsigned old_baud;
    109109        serial_parity_t old_par;
    110110        unsigned old_stop;
    111111        unsigned old_word_size;
    112 
     112       
    113113        res = serial_get_comm_props(serial, &old_baud, &old_par,
    114114            &old_word_size, &old_stop);
     
    120120                return "Failed to get old serial communication parameters";
    121121        }
    122 
     122       
    123123        res = serial_set_comm_props(serial, 1200, SERIAL_NO_PARITY, 8, 1);
    124124        if (EOK != res) {
     
    129129                return "Failed setting serial communication parameters";
    130130        }
    131 
     131       
    132132        TPRINTF("Trying reading %zu characters from serial device "
    133133            "(svc_id=%" PRIun ")\n", cnt, svc_id);
    134 
     134       
    135135        size_t total = 0;
    136136        while (total < cnt) {
    137 
     137               
    138138                rc = chardev_read(chardev, buf, cnt - total, &nread);
    139139                if (rc != EOK) {
    140140                        (void) serial_set_comm_props(serial, old_baud,
    141141                            old_par, old_word_size, old_stop);
    142 
     142                       
    143143                        free(buf);
    144144                        chardev_close(chardev);
     
    147147                        return "Failed reading from serial device";
    148148                }
    149 
     149               
    150150                if (nread > cnt - total) {
    151151                        (void) serial_set_comm_props(serial, old_baud,
    152152                            old_par, old_word_size, old_stop);
    153 
     153                       
    154154                        free(buf);
    155155                        chardev_close(chardev);
     
    158158                        return "Read more data than expected";
    159159                }
    160 
     160               
    161161                TPRINTF("Read %zd bytes\n", nread);
    162 
     162               
    163163                buf[nread] = 0;
    164 
     164               
    165165                /*
    166166                 * Write data back to the device to test the opposite
     
    171171                        (void) serial_set_comm_props(serial, old_baud,
    172172                            old_par, old_word_size, old_stop);
    173 
     173                       
    174174                        free(buf);
    175175                        chardev_close(chardev);
     
    178178                        return "Failed writing to serial device";
    179179                }
    180 
     180               
    181181                if (nwritten != nread) {
    182182                        (void) serial_set_comm_props(serial, old_baud,
    183183                            old_par, old_word_size, old_stop);
    184 
     184                       
    185185                        free(buf);
    186186                        chardev_close(chardev);
     
    189189                        return "Written less data than read from serial device";
    190190                }
    191 
     191               
    192192                TPRINTF("Written %zd bytes\n", nwritten);
    193 
     193               
    194194                total += nread;
    195195        }
    196 
     196       
    197197        TPRINTF("Trying to write EOT banner to the serial device\n");
    198 
     198       
    199199        size_t eot_size = str_size(EOT);
    200200        rc = chardev_write(chardev, (void *) EOT, eot_size, &nwritten);
    201 
     201       
    202202        (void) serial_set_comm_props(serial, old_baud, old_par, old_word_size,
    203203            old_stop);
    204 
     204       
    205205        free(buf);
    206206        chardev_close(chardev);
    207207        serial_close(serial);
    208208        async_hangup(sess);
    209 
     209       
    210210        if (rc != EOK)
    211211                return "Failed to write EOT banner to serial device";
    212 
     212       
    213213        if (nwritten != eot_size)
    214214                return "Written less data than the size of the EOT banner "
    215215                    "to serial device";
    216 
     216       
    217217        return NULL;
    218218}
Note: See TracChangeset for help on using the changeset viewer.