Changes in uspace/app/tester/hw/serial/serial1.c [a35b458:5a6cc679] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/hw/serial/serial1.c
ra35b458 r5a6cc679 59 59 size_t nread; 60 60 size_t nwritten; 61 61 62 62 if (test_argc < 1) 63 63 cnt = DEFAULT_COUNT; … … 73 73 return "Unexpected argument error"; 74 74 } 75 75 76 76 service_id_t svc_id; 77 77 errno_t res = loc_service_get_id("devices/\\hw\\pci0\\00:01.0\\com1\\a", … … 79 79 if (res != EOK) 80 80 return "Failed getting serial port service ID"; 81 81 82 82 async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF, 83 83 IPC_FLAG_BLOCKING); 84 84 if (sess == NULL) 85 85 return "Failed connecting to serial device"; 86 86 87 87 res = chardev_open(sess, &chardev); 88 88 if (res != EOK) { … … 90 90 return "Failed opening serial port"; 91 91 } 92 92 93 93 res = serial_open(sess, &serial); 94 94 if (res != EOK) { … … 97 97 return "Failed opening serial port"; 98 98 } 99 99 100 100 char *buf = (char *) malloc(cnt + 1); 101 101 if (buf == NULL) { … … 105 105 return "Failed allocating input buffer"; 106 106 } 107 107 108 108 unsigned old_baud; 109 109 serial_parity_t old_par; 110 110 unsigned old_stop; 111 111 unsigned old_word_size; 112 112 113 113 res = serial_get_comm_props(serial, &old_baud, &old_par, 114 114 &old_word_size, &old_stop); … … 120 120 return "Failed to get old serial communication parameters"; 121 121 } 122 122 123 123 res = serial_set_comm_props(serial, 1200, SERIAL_NO_PARITY, 8, 1); 124 124 if (EOK != res) { … … 129 129 return "Failed setting serial communication parameters"; 130 130 } 131 131 132 132 TPRINTF("Trying reading %zu characters from serial device " 133 133 "(svc_id=%" PRIun ")\n", cnt, svc_id); 134 134 135 135 size_t total = 0; 136 136 while (total < cnt) { 137 137 138 138 rc = chardev_read(chardev, buf, cnt - total, &nread); 139 139 if (rc != EOK) { 140 140 (void) serial_set_comm_props(serial, old_baud, 141 141 old_par, old_word_size, old_stop); 142 142 143 143 free(buf); 144 144 chardev_close(chardev); … … 147 147 return "Failed reading from serial device"; 148 148 } 149 149 150 150 if (nread > cnt - total) { 151 151 (void) serial_set_comm_props(serial, old_baud, 152 152 old_par, old_word_size, old_stop); 153 153 154 154 free(buf); 155 155 chardev_close(chardev); … … 158 158 return "Read more data than expected"; 159 159 } 160 160 161 161 TPRINTF("Read %zd bytes\n", nread); 162 162 163 163 buf[nread] = 0; 164 164 165 165 /* 166 166 * Write data back to the device to test the opposite … … 171 171 (void) serial_set_comm_props(serial, old_baud, 172 172 old_par, old_word_size, old_stop); 173 173 174 174 free(buf); 175 175 chardev_close(chardev); … … 178 178 return "Failed writing to serial device"; 179 179 } 180 180 181 181 if (nwritten != nread) { 182 182 (void) serial_set_comm_props(serial, old_baud, 183 183 old_par, old_word_size, old_stop); 184 184 185 185 free(buf); 186 186 chardev_close(chardev); … … 189 189 return "Written less data than read from serial device"; 190 190 } 191 191 192 192 TPRINTF("Written %zd bytes\n", nwritten); 193 193 194 194 total += nread; 195 195 } 196 196 197 197 TPRINTF("Trying to write EOT banner to the serial device\n"); 198 198 199 199 size_t eot_size = str_size(EOT); 200 200 rc = chardev_write(chardev, (void *) EOT, eot_size, &nwritten); 201 201 202 202 (void) serial_set_comm_props(serial, old_baud, old_par, old_word_size, 203 203 old_stop); 204 204 205 205 free(buf); 206 206 chardev_close(chardev); 207 207 serial_close(serial); 208 208 async_hangup(sess); 209 209 210 210 if (rc != EOK) 211 211 return "Failed to write EOT banner to serial device"; 212 212 213 213 if (nwritten != eot_size) 214 214 return "Written less data than the size of the EOT banner " 215 215 "to serial device"; 216 216 217 217 return NULL; 218 218 }
Note:
See TracChangeset
for help on using the changeset viewer.