Changes in uspace/app/tester/hw/serial/serial1.c [f300523:8d2dd7f2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/hw/serial/serial1.c
rf300523 r8d2dd7f2 35 35 */ 36 36 37 #include < async.h>37 #include <inttypes.h> 38 38 #include <errno.h> 39 #include <io/chardev.h>40 #include <io/serial.h>41 #include <ipc/services.h>42 #include <loc.h>43 39 #include <stdlib.h> 44 40 #include <stdio.h> 45 41 #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> 46 47 #include <str.h> 48 #include <ipc/serial_ctl.h> 47 49 #include "../../tester.h" 48 50 … … 54 56 { 55 57 size_t cnt; 56 serial_t *serial;57 chardev_t *chardev;58 int rc;59 size_t nread;60 size_t nwritten;61 58 62 59 if (test_argc < 1) … … 82 79 async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF, 83 80 IPC_FLAG_BLOCKING); 84 if ( sess == NULL)81 if (!sess) 85 82 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 }99 83 100 84 char *buf = (char *) malloc(cnt + 1); 101 85 if (buf == NULL) { 102 chardev_close(chardev);103 serial_close(serial);104 86 async_hangup(sess); 105 87 return "Failed allocating input buffer"; 106 88 } 107 89 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 115 100 if (res != EOK) { 116 101 free(buf); 117 chardev_close(chardev);118 serial_close(serial);119 102 async_hangup(sess); 120 103 return "Failed to get old serial communication parameters"; 121 104 } 122 105 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 124 111 if (EOK != res) { 125 112 free(buf); 126 chardev_close(chardev);127 serial_close(serial);128 113 async_hangup(sess); 129 114 return "Failed setting serial communication parameters"; … … 135 120 size_t total = 0; 136 121 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, 141 127 old_par, old_word_size, old_stop); 128 async_exchange_end(exch); 142 129 143 130 free(buf); 144 chardev_close(chardev);145 serial_close(serial);146 131 async_hangup(sess); 147 132 return "Failed reading from serial device"; 148 133 } 149 134 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, 152 138 old_par, old_word_size, old_stop); 139 async_exchange_end(exch); 153 140 154 141 free(buf); 155 chardev_close(chardev);156 serial_close(serial);157 142 async_hangup(sess); 158 143 return "Read more data than expected"; 159 144 } 160 145 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; 195 185 } 196 186 … … 198 188 199 189 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); 204 196 205 197 free(buf); 206 chardev_close(chardev);207 serial_close(serial);208 198 async_hangup(sess); 209 199 210 if ( rc != EOK)200 if (written < 0) 211 201 return "Failed to write EOT banner to serial device"; 212 202 213 if ( nwritten != eot_size)203 if ((size_t) written != eot_size) 214 204 return "Written less data than the size of the EOT banner " 215 205 "to serial device";
Note:
See TracChangeset
for help on using the changeset viewer.