Changeset f658458 in mainline
- 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
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
r25a7e11d rf658458 70 70 $(USPACEDIR)/app/tester/tester \ 71 71 $(USPACEDIR)/app/tetris/tetris \ 72 $(USPACEDIR)/app/trace/trace 72 $(USPACEDIR)/app/trace/trace \ 73 $(USPACEDIR)/app/test_serial/test_serial 73 74 74 75 COMPONENTS = \ -
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 /** @} -
uspace/lib/libc/generic/device/char.c
r25a7e11d rf658458 38 38 #include <async.h> 39 39 #include <malloc.h> 40 #include <stdio.h> 40 41 41 42 … … 46 47 async_serialize_start(); 47 48 49 printf("calling interface %d\n", DEV_IFACE_ID(CHAR_DEV_IFACE)); 48 50 aid_t req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer); 49 51 -
uspace/lib/libc/generic/devman.c
r25a7e11d rf658458 230 230 } 231 231 232 int devman_device_get_handle(const char *pathname, device_handle_t *handle, unsigned int flags) 233 { 234 int phone = devman_get_phone(DEVMAN_CLIENT, flags); 235 236 if (phone < 0) 237 return phone; 238 239 async_serialize_start(); 240 241 ipc_call_t answer; 242 aid_t req = async_send_2(phone, DEVMAN_DEVICE_GET_HANDLE, flags, 0, 243 &answer); 244 245 ipcarg_t retval = async_data_write_start(phone, pathname, str_size(pathname)); 246 if (retval != EOK) { 247 async_wait_for(req, NULL); 248 async_serialize_end(); 249 return retval; 250 } 251 252 async_wait_for(req, &retval); 253 254 async_serialize_end(); 255 256 if (retval != EOK) { 257 if (handle != NULL) 258 *handle = (device_handle_t) -1; 259 return retval; 260 } 261 262 if (handle != NULL) 263 *handle = (device_handle_t) IPC_GET_ARG1(answer); 264 265 return retval; 266 } 267 268 232 269 /** @} 233 270 */ -
uspace/lib/libc/include/devman.h
r25a7e11d rf658458 51 51 int devman_parent_device_connect(device_handle_t handle, unsigned int flags); 52 52 53 int devman_device_get_handle(const char *pathname, device_handle_t *handle, unsigned int flags); 54 53 55 54 56 #endif -
uspace/lib/libc/include/ipc/devman.h
r25a7e11d rf658458 138 138 } devman_to_driver_t; 139 139 140 typedef enum { 141 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD 142 } client_to_devman_t; 143 140 144 #endif 141 145 -
uspace/lib/libdrv/generic/driver.c
r25a7e11d rf658458 254 254 if (!is_valid_iface_idx(iface_idx)) { 255 255 // this is not device's interface 256 printf("%s: driver_connection_gen error - invalid interface id % x.", driver->name, method);256 printf("%s: driver_connection_gen error - invalid interface id %d.", driver->name, iface_idx); 257 257 ipc_answer_0(callid, ENOTSUP); 258 258 break; … … 265 265 if (NULL == iface) { 266 266 printf("%s: driver_connection_gen error - ", driver->name); 267 printf("device with handle % x has no interface with id %x.\n", handle, method);267 printf("device with handle %d has no interface with id %d.\n", handle, iface_idx); 268 268 ipc_answer_0(callid, ENOTSUP); 269 269 break; -
uspace/lib/libdrv/generic/remote_char.c
r25a7e11d rf658458 56 56 57 57 static void remote_char_read(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call) 58 { 58 { 59 59 char_iface_t *char_iface = (char_iface_t *)iface; 60 if (!char_iface->read) {61 ipc_answer_0(callid, ENOTSUP);62 return;63 }64 60 65 61 size_t len; 66 62 if (!async_data_read_receive(&callid, &len)) { 67 63 // TODO handle protocol error 64 ipc_answer_0(callid, EINVAL); 65 return; 66 } 67 68 if (!char_iface->read) { 69 async_data_read_finalize(callid, NULL, 0); 70 ipc_answer_0(callid, ENOTSUP); 68 71 return; 69 72 } -
uspace/lib/libdrv/include/driver.h
r25a7e11d rf658458 163 163 { 164 164 assert(is_valid_iface_idx(idx)); 165 165 if (NULL == dev->class) { 166 return NULL; 167 } 166 168 return dev->class->interfaces[idx]; 167 169 } -
uspace/srv/devman/devman.c
r25a7e11d rf658458 679 679 { 680 680 node_t *dev = tree->root_node; 681 // relative path to the device from its parent (but with '/' at the beginning) 681 682 char *rel_path = path; 682 683 char *next_path_elem = NULL; … … 685 686 686 687 while (cont && NULL != dev) { 687 next_path_elem = get_path_elem_end(rel_path +1);688 next_path_elem = get_path_elem_end(rel_path + 1); 688 689 if ('/' == next_path_elem[0]) { 689 690 cont = true; … … 693 694 } 694 695 695 dev = find_node_child(dev, rel_path );696 dev = find_node_child(dev, rel_path + 1); 696 697 697 698 if (cont) { 699 // restore the original path 698 700 next_path_elem[0] = '/'; 699 701 } -
uspace/srv/devman/main.c
r25a7e11d rf658458 291 291 } 292 292 293 /** Find handle for the device instance identified by the device's path in the device tree. 294 */ 295 static void devman_device_get_handle(ipc_callid_t iid, ipc_call_t *icall) 296 { 297 char *pathname; 298 299 /* Get fqdn */ 300 int rc = async_string_receive(&pathname, 0, NULL); 301 if (rc != EOK) { 302 ipc_answer_0(iid, rc); 303 return; 304 } 305 306 node_t * dev = find_dev_node_by_path(&device_tree, pathname); 307 308 free(pathname); 309 310 if (NULL == dev) { 311 ipc_answer_0(iid, ENOENT); 312 return; 313 } 314 315 ipc_answer_1(iid, EOK, dev->handle); 316 } 317 318 319 /** Function for handling connections from a client to the device manager. 320 */ 321 static void devman_connection_client(ipc_callid_t iid, ipc_call_t *icall) 322 { 323 /* Accept connection */ 324 ipc_answer_0(iid, EOK); 325 326 bool cont = true; 327 while (cont) { 328 ipc_call_t call; 329 ipc_callid_t callid = async_get_call(&call); 330 331 switch (IPC_GET_METHOD(call)) { 332 case IPC_M_PHONE_HUNGUP: 333 cont = false; 334 continue; 335 case DEVMAN_DEVICE_GET_HANDLE: 336 devman_device_get_handle(callid, &call); 337 break; 338 default: 339 if (!(callid & IPC_CALLID_NOTIFICATION)) 340 ipc_answer_0(callid, ENOENT); 341 } 342 } 343 } 344 293 345 static void devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent) { 294 346 … … 346 398 devman_connection_driver(iid, icall); 347 399 break; 348 /*case DEVMAN_CLIENT:349 devma p_connection_client(iid, icall);350 break; */400 case DEVMAN_CLIENT: 401 devman_connection_client(iid, icall); 402 break; 351 403 case DEVMAN_CONNECT_TO_DEVICE: 352 404 // Connect client to selected device -
uspace/srv/drivers/serial/serial.c
r25a7e11d rf658458 53 53 54 54 #include <driver.h> 55 #include <char.h> 55 56 #include <resource.h> 56 57 … … 91 92 } 92 93 94 static int serial_read(device_t *dev, char *buf, size_t count) 95 { 96 printf(NAME ": serial_read %s\n", dev->name); 97 // TODO 98 return 0; 99 } 100 101 static int serial_write(device_t *dev, char *buf, size_t count) 102 { 103 // TODO 104 return 0; 105 } 106 93 107 static device_class_t serial_dev_class; 108 109 static char_iface_t serial_char_iface = { 110 .read = &serial_read, 111 .write = &serial_write 112 }; 94 113 95 114 static int serial_add_device(device_t *dev); … … 377 396 serial_unregister_interrupt_handler(dev); 378 397 return res; 379 } 398 } 399 400 dev->class = &serial_dev_class; 380 401 381 402 printf(NAME ": the %s device has been successfully initialized.\n", dev->name); … … 440 461 serial_dev_class.open = &serial_open; 441 462 serial_dev_class.close = &serial_close; 463 464 serial_dev_class.interfaces[CHAR_DEV_IFACE] = &serial_char_iface; 442 465 } 443 466
Note:
See TracChangeset
for help on using the changeset viewer.