Changeset 848e3d15 in mainline
- Timestamp:
- 2010-10-21T20:22:56Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 032e0bb
- Parents:
- 7a252ec8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/test_serial/test_serial.c
r7a252ec8 r848e3d15 30 30 * @brief test the serial port driver - read from the serial port 31 31 * @{ 32 */ 32 */ 33 33 /** 34 34 * @file … … 51 51 52 52 53 static void print_usage( )53 static void print_usage(void) 54 54 { 55 printf("Usage: \n test_serial count \n where count is the number of characters to be read\n"); 55 printf("Usage: \n test_serial count \n where count is the number of " 56 "characters to be read\n"); 56 57 } 57 58 … … 61 62 printf(NAME ": incorrect number of arguments.\n"); 62 63 print_usage(); 63 return 0; 64 return 0; 64 65 } 65 66 … … 70 71 device_handle_t handle; 71 72 72 if (EOK != (res = devman_device_get_handle("/hw/pci0/00:01.0/com1", &handle, IPC_FLAG_BLOCKING))) { 73 printf(NAME ": could not get the device handle, errno = %d.\n", -res); 73 res = devman_device_get_handle("/hw/pci0/00:01.0/com1", &handle, 74 IPC_FLAG_BLOCKING); 75 if (EOK != res) { 76 printf(NAME ": could not get the device handle, errno = %d.\n", 77 -res); 74 78 return 1; 75 79 } 76 80 77 printf(NAME ": trying to read %d characters from device with handle %d.\n", cnt, handle); 81 printf(NAME ": trying to read %d characters from device with handle " 82 "%d.\n", cnt, handle); 78 83 79 int phone; 80 if (0 >= (phone = devman_device_connect(handle, IPC_FLAG_BLOCKING))) { 81 printf(NAME ": could not connect to the device, errno = %d.\n", -res); 82 devman_hangup_phone(DEVMAN_CLIENT); 84 int phone = devman_device_connect(handle, IPC_FLAG_BLOCKING); 85 if (0 > phone) { 86 printf(NAME ": could not connect to the device, errno = %d.\n", 87 -res); 88 devman_hangup_phone(DEVMAN_CLIENT); 83 89 return 2; 84 90 } 85 91 86 char *buf = (char *) malloc(cnt+1);92 char *buf = (char *) malloc(cnt + 1); 87 93 if (NULL == buf) { 88 94 printf(NAME ": failed to allocate the input buffer\n"); … … 94 100 ipcarg_t old_baud, old_par, old_stop, old_word_size; 95 101 96 res = ipc_call_sync_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud, &old_par, &old_word_size, &old_stop); 102 res = ipc_call_sync_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud, 103 &old_par, &old_word_size, &old_stop); 97 104 if (EOK != res) { 98 printf(NAME ": failed to get old communication parameters, errno = %d.\n", -res); 105 printf(NAME ": failed to get old communication parameters, " 106 "errno = %d.\n", -res); 99 107 devman_hangup_phone(DEVMAN_CLIENT); 100 108 ipc_hangup(phone); … … 103 111 } 104 112 105 res = ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, 1200, SERIAL_NO_PARITY, 8, 1); 113 res = ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, 1200, 114 SERIAL_NO_PARITY, 8, 1); 106 115 if (EOK != res) { 107 printf(NAME ": failed to set communication parameters, errno = %d.\n", -res); 116 printf(NAME ": failed to set communication parameters, errno = " 117 "%d.\n", -res); 108 118 devman_hangup_phone(DEVMAN_CLIENT); 109 119 ipc_hangup(phone); … … 112 122 } 113 123 114 115 124 int total = 0; 116 125 int read = 0; 117 while (total < cnt) { 126 while (total < cnt) { 118 127 read = read_dev(phone, buf, cnt - total); 119 128 if (0 > read) { 120 printf(NAME ": failed read from device, errno = %d.\n", -read); 121 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, old_par, old_word_size, old_stop); 129 printf(NAME ": failed read from device, errno = %d.\n", 130 -read); 131 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 132 old_par, old_word_size, old_stop); 122 133 ipc_hangup(phone); 123 134 devman_hangup_phone(DEVMAN_CLIENT); 124 135 free(buf); 125 136 return 5; 126 } 137 } 127 138 total += read; 128 if (read > 0) { 139 if (read > 0) { 129 140 buf[read] = 0; 130 printf(buf); 131 // write data back to the device to test the opposite direction of data transfer 141 printf(buf); 142 /* 143 * Write data back to the device to test the opposite 144 * direction of data transfer. 145 */ 132 146 write_dev(phone, buf, read); 133 } else { 134 usleep(100000); 147 } else { 148 usleep(100000); 135 149 } 136 150 } … … 139 153 write_dev(phone, (void *)the_end, str_size(the_end)); 140 154 141 // restore original communication settings 142 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, old_par, old_word_size, old_stop); 155 /* restore original communication settings */ 156 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, old_par, 157 old_word_size, old_stop); 143 158 devman_hangup_phone(DEVMAN_CLIENT); 144 159 ipc_hangup(phone); … … 148 163 } 149 164 150 151 165 /** @} 152 166 */
Note:
See TracChangeset
for help on using the changeset viewer.