Changeset 64d138b in mainline
- Timestamp:
- 2017-12-15T17:21:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 73b0773
- Parents:
- a8723748
- Location:
- uspace
- Files:
-
- 1 added
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tmon/Makefile
ra8723748 r64d138b 30 30 BINARY = tmon 31 31 32 LIBS = usbdiag32 LIBS = drv usbdiag 33 33 34 34 SOURCES = \ -
uspace/app/tmon/main.c
ra8723748 r64d138b 36 36 37 37 #include <stdio.h> 38 #include <loc.h> 38 39 #include <usb/diag/diag.h> 40 #include <usb/diag/iface.h> 41 #include <devman.h> 42 #include <errno.h> 39 43 40 44 #define NAME "tmon" … … 43 47 { 44 48 printf(NAME ": hello USB transfers!\n\n"); 49 } 50 51 static void print_list_item(service_id_t svc) 52 { 53 int rc; 54 devman_handle_t diag_handle = 0; 55 56 if ((rc = devman_fun_sid_to_handle(svc, &diag_handle))) { 57 printf(NAME ": Error resolving handle of device with SID %ld, skipping.\n", svc); 58 return; 59 } 60 } 61 62 static int print_list() 63 { 64 category_id_t diag_cat; 65 service_id_t *svcs; 66 size_t count; 67 int rc; 68 69 if ((rc = loc_category_get_id(USB_DIAG_CATEGORY, &diag_cat, 0))) { 70 printf(NAME ": Error resolving category '%s'", USB_DIAG_CATEGORY); 71 return 1; 72 } 73 74 if ((rc = loc_category_get_svcs(diag_cat, &svcs, &count))) { 75 printf(NAME ": Error getting list of host controllers.\n"); 76 return 1; 77 } 78 79 for (unsigned i = 0; i < count; ++i) { 80 print_list_item(svcs[i]); 81 } 82 83 free(svcs); 84 return 0; 45 85 } 46 86 … … 52 92 } 53 93 54 int out; 55 const int rc = usb_diag_test(0, &out); 56 if (rc) { 57 printf("Error: %d\n", rc); 58 } else { 59 printf("The number is %d.\n", out); 60 } 61 62 return 0; 94 return print_list(); 63 95 } 64 96 -
uspace/drv/bus/usb/usbdiag/device.c
ra8723748 r64d138b 36 36 #include <errno.h> 37 37 #include <usb/debug.h> 38 #include <usb/diag/iface.h> 38 39 39 40 #include "device.h" … … 41 42 #define NAME "usbdiag" 42 43 44 static void connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 45 { 46 // usb_diag_fun_t *fun = (usb_diag_fun_t *) ddf_fun_data_get((ddf_fun_t *) arg); 47 48 // FIXME: handle connection 49 } 50 51 static int some_test(ddf_fun_t *fun, int x, int *y) 52 { 53 *y = x + 42; 54 return EOK; 55 } 56 57 static usb_diag_iface_t diag_interface = { 58 .test = some_test, 59 }; 60 61 static ddf_dev_ops_t diag_ops = { 62 .interfaces[USBDIAG_DEV_IFACE] = &diag_interface 63 }; 64 43 65 static int device_init(usb_diag_dev_t *dev) 44 66 { 45 // TODO: allocate data structures, set up stuffs 67 ddf_fun_t *fun = usb_device_ddf_fun_create(dev->usb_dev, fun_exposed, "tmon"); 68 if (!fun) 69 return ENOMEM; 46 70 71 ddf_fun_set_conn_handler(fun, connection); 72 ddf_fun_set_ops(fun, &diag_ops); 73 74 dev->fun = fun; 47 75 return EOK; 48 76 } … … 50 78 static void device_fini(usb_diag_dev_t *dev) 51 79 { 52 // TODO: tear down data structures80 ddf_fun_destroy(dev->fun); 53 81 } 54 82 -
uspace/drv/bus/usb/usbdiag/device.h
ra8723748 r64d138b 40 40 41 41 /** 42 * USB d ebugdevice.42 * USB diagnostic device. 43 43 */ 44 44 typedef struct usb_diag_dev { 45 45 usb_device_t *usb_dev; 46 ddf_fun_t *fun; 46 47 } usb_diag_dev_t; 47 48 -
uspace/drv/bus/usb/usbdiag/main.c
ra8723748 r64d138b 38 38 #include <usb/dev/driver.h> 39 39 #include <usb/diag/diag.h> 40 #include <str_error.h> 40 41 41 42 #include "usbdiag.h" … … 44 45 #define NAME "usbdiag" 45 46 46 static void usb_diag_test_impl(ipc_callid_t rid, ipc_call_t *request)47 {48 int x = IPC_GET_ARG1(*request);49 int ret = 4200 + x;50 async_answer_0(rid, ret);51 }52 53 47 static int device_add(usb_device_t *dev) 54 48 { 49 int rc; 55 50 usb_log_info("Adding device '%s'", usb_device_get_name(dev)); 56 51 57 int err; 52 usb_diag_dev_t *diag_dev; 53 if ((rc = usb_diag_dev_create(dev, &diag_dev))) { 54 usb_log_error("Failed create device: %s.\n", str_error(rc)); 55 goto err; 56 } 58 57 59 usb_diag_dev_t *diag_dev; 60 if ((err = usb_diag_dev_create(dev, &diag_dev))) 61 return err; 58 if ((rc = ddf_fun_bind(diag_dev->fun))) { 59 usb_log_error("Failed to bind DDF function: %s.\n", str_error(rc)); 60 goto err_create; 61 } 62 62 63 /* TODO: Register device in some list. */ 64 /* TODO: Register device DDF function. */ 63 if ((rc = ddf_fun_add_to_category(diag_dev->fun, USB_DIAG_CATEGORY))) { 64 usb_log_error("Failed add DDF to category '" 65 USB_DIAG_CATEGORY "': %s.\n", str_error(rc)); 66 goto err_bind; 67 } 65 68 66 69 return EOK; 70 71 err_bind: 72 ddf_fun_unbind(diag_dev->fun); 73 err_create: 74 usb_diag_dev_destroy(diag_dev); 75 err: 76 return rc; 67 77 } 68 78 69 79 static int device_remove(usb_device_t *dev) 70 80 { 81 int rc; 71 82 usb_log_info("Removing device '%s'", usb_device_get_name(dev)); 72 83 … … 74 85 75 86 /* TODO: Make sure nothing is going on with the device. */ 76 /* TODO: Unregister device DDF function. */ 77 /* TODO: Remove device from list */ 87 88 if ((rc = ddf_fun_unbind(diag_dev->fun))) { 89 usb_log_error("Failed to unbind DDF function: %s\n", str_error(rc)); 90 goto err; 91 } 78 92 79 93 usb_diag_dev_destroy(diag_dev); 80 94 81 95 return EOK; 96 97 err: 98 return rc; 82 99 } 83 100 … … 107 124 } 108 125 109 static void connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)110 {111 bool cont = true;112 113 async_answer_0(iid, EOK);114 115 while (cont) {116 ipc_call_t call;117 ipc_callid_t callid = async_get_call(&call);118 119 if (!IPC_GET_IMETHOD(call))120 break;121 122 switch (IPC_GET_IMETHOD(call)) {123 case USB_DIAG_IN_TEST:124 usb_diag_test_impl(callid, &call);125 break;126 default:127 async_answer_0(callid, ENOTSUP);128 break;129 }130 }131 }132 133 static int server_fibril(void *arg)134 {135 // async_set_client_data_constructor(NULL);136 // async_set_client_data_destructor(NULL);137 async_set_fallback_port_handler(connection, NULL);138 // async_event_task_subscribe();139 // service_register();140 async_manager();141 142 /* Never reached. */143 return EOK;144 }145 146 126 /** USB diagnostic driver ops. */ 147 127 static const usb_driver_ops_t diag_driver_ops = { … … 166 146 log_init(NAME); 167 147 168 /* Start usbdiag service. */169 fid_t srv = fibril_create(server_fibril, NULL);170 if (!srv)171 return ENOMEM;172 fibril_add_ready(srv);173 174 148 return usb_driver_main(&diag_driver); 175 149 } -
uspace/lib/c/include/ipc/dev_iface.h
ra8723748 r64d138b 44 44 /** Audio device pcm buffer interface */ 45 45 AUDIO_PCM_BUFFER_IFACE, 46 46 47 47 /** Network interface controller interface */ 48 48 NIC_DEV_IFACE, 49 49 50 50 /** IEEE 802.11 interface controller interface */ 51 51 IEEE80211_DEV_IFACE, 52 52 53 53 /** Interface provided by any PCI device. */ 54 54 PCI_DEV_IFACE, … … 56 56 /** Interface provided by any USB device. */ 57 57 USB_DEV_IFACE, 58 /** Interface provided by USB diagnostic devices. */ 59 USBDIAG_DEV_IFACE, 58 60 /** Interface provided by USB host controller to USB device. */ 59 61 USBHC_DEV_IFACE, -
uspace/lib/usbdiag/Makefile
ra8723748 r64d138b 32 32 33 33 SOURCES = \ 34 src/ test.c34 src/remote_usbdiag.c 35 35 36 36 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/usbdiag/include/usb/diag/diag.h
ra8723748 r64d138b 36 36 #define LIBUSBDIAG_DIAG_H_ 37 37 38 #include <ipc/common.h> 39 40 typedef enum { 41 USB_DIAG_IN_TEST = IPC_FIRST_USER_METHOD, 42 } usb_diag_in_request_t; 43 44 /** Just a dummy symbol to make compiler happy. TODO: remove it */ 45 int usb_diag_test(int, int*); 38 #define USB_DIAG_CATEGORY "usbdiag" 46 39 47 40 #endif -
uspace/lib/usbdiag/include/usb/diag/iface.h
ra8723748 r64d138b 31 31 */ 32 32 /** @file 33 * Testing stuff33 * @brief USB diagnostic device communication interface. 34 34 */ 35 #ifndef LIBUSBDIAG_IFACE_H_ 36 #define LIBUSBDIAG_IFACE_H_ 35 37 36 38 #include <async.h> 37 #include < usb/diag/diag.h>39 #include <ddf/driver.h> 38 40 39 int usb_diag_test(int x, int *out) 40 { 41 sysarg_t _out; 42 async_sess_t *session = NULL; 43 async_exch_t *exch = async_exchange_begin(session); 44 const int rc = async_req_1_1(exch, USB_DIAG_IN_TEST, x, &_out); 45 async_exchange_end(exch); 41 async_sess_t *usb_diag_connect(devman_handle_t); 42 void usb_diag_disconnect(async_sess_t*); 43 int usb_diag_test(async_exch_t*, int, int*); 46 44 47 if (out) 48 *out = (int) _out; 45 /** USB diagnostic device communication interface. */ 46 typedef struct { 47 int (*test)(ddf_fun_t*, int, int*); 48 } usb_diag_iface_t; 49 49 50 return rc; 51 } 52 50 #endif 53 51 /** 54 52 * @} -
uspace/srv/locsrv/locsrv.c
ra8723748 r64d138b 1353 1353 categ_dir_add_cat(&cdir, cat); 1354 1354 1355 cat = category_new("usbdiag"); 1356 categ_dir_add_cat(&cdir, cat); 1357 1355 1358 cat = category_new("usbhc"); 1356 1359 categ_dir_add_cat(&cdir, cat);
Note:
See TracChangeset
for help on using the changeset viewer.