Changeset f658458 in mainline for uspace/app/test_serial/test_serial.c
- Timestamp:
- 2010-05-02T20:49:09Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bb864a0
- Parents:
- 25a7e11d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/test_serial/test_serial.c
r25a7e11d rf658458 56 56 57 57 #define NAME "test serial" 58 #define MYROOM 2 59 #define UpSection1 25 60 #define DwnSection1 26 61 #define UpSection2 27 62 #define DwnSection2 28 63 58 59 /* 64 60 static int device_get_handle(const char *name, dev_handle_t *handle); 65 61 static void print_usage(); … … 105 101 106 102 107 /* 108 * The name of a serial device must be between 'com0' and 'com9'. 109 */ 103 // The name of a serial device must be between 'com0' and 'com9'. 110 104 static bool is_com_dev(const char *dev_name) 111 105 { … … 168 162 169 163 return 0; 170 } 164 }*/ 165 166 167 #include <ipc/devman.h> 168 #include <devman.h> 169 #include <device/char.h> 170 171 172 static void print_usage() 173 { 174 printf("Usage: \n test_serial count \n where count is a number of characters to be read\n"); 175 } 176 177 178 int main(int argc, char *argv[]) 179 { 180 if (argc != 2) { 181 printf(NAME ": incorrect number of arguments.\n"); 182 print_usage(); 183 return 0; 184 } 185 186 long int cnt = strtol(argv[1], NULL, 10); 187 188 int res; 189 res = devman_get_phone(DEVMAN_CLIENT, IPC_FLAG_BLOCKING); 190 device_handle_t handle; 191 192 if (EOK != (res = devman_device_get_handle("/hw/pci0/00:01.0/com1", &handle, IPC_FLAG_BLOCKING))) { 193 printf(NAME ": could not get the device handle, errno = %d.\n", -res); 194 return 1; 195 } 196 197 printf(NAME ": device handle is %d.\n", handle); 198 199 int phone; 200 if (0 >= (phone = devman_device_connect(handle, IPC_FLAG_BLOCKING))) { 201 printf(NAME ": could not connect to the device, errno = %d.\n", -res); 202 devman_hangup_phone(DEVMAN_CLIENT); 203 return 2; 204 } 205 206 char *buf = (char *)malloc(cnt+1); 207 if (NULL == buf) { 208 printf(NAME ": failed to allocate the input buffer\n"); 209 ipc_hangup(phone); 210 devman_hangup_phone(DEVMAN_CLIENT); 211 return 3; 212 } 213 214 int read = read_dev(phone, buf, cnt); 215 if (0 > read) { 216 printf(NAME ": failed read from device, errno = %d.\n", -read); 217 ipc_hangup(phone); 218 devman_hangup_phone(DEVMAN_CLIENT); 219 return 4; 220 } 221 222 buf[cnt+1] = 0; 223 printf(NAME ": read data: '%s'.", buf); 224 225 devman_hangup_phone(DEVMAN_CLIENT); 226 ipc_hangup(phone); 227 228 return 0; 229 } 230 171 231 172 232 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.