Changeset 8b655705 in mainline for uspace/drv/test2/test2.c
- Timestamp:
- 2011-04-15T19:38:07Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9dd730d1
- Parents:
- 6b9e85b (diff), b2fb47f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/test2/test2.c
r6b9e85b r8b655705 31 31 32 32 #include <assert.h> 33 #include <async.h> 33 34 #include <stdio.h> 34 35 #include <errno.h> 35 36 #include <str_error.h> 36 #include <driver.h> 37 #include <ddf/driver.h> 38 #include <ddf/log.h> 37 39 38 40 #define NAME "test2" 39 41 40 static int add_device(device_t *dev);42 static int test2_add_device(ddf_dev_t *dev); 41 43 42 44 static driver_ops_t driver_ops = { 43 .add_device = & add_device45 .add_device = &test2_add_device 44 46 }; 45 47 46 static driver_t t he_driver = {48 static driver_t test2_driver = { 47 49 .name = NAME, 48 50 .driver_ops = &driver_ops … … 57 59 * @param score Device match score. 58 60 */ 59 static void register_child_verbose(device_t *parent, const char *message,61 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 60 62 const char *name, const char *match_id, int match_score) 61 63 { 62 printf(NAME ": registering child device `%s': %s.\n",63 name, message);64 ddf_fun_t *fun; 65 int rc; 64 66 65 int rc = child_device_register_wrapper(parent, name, 66 match_id, match_score); 67 ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message); 67 68 68 if (rc == EOK) { 69 printf(NAME ": registered child device `%s'.\n", name); 70 } else { 71 printf(NAME ": failed to register child `%s' (%s).\n", 72 name, str_error(rc)); 69 fun = ddf_fun_create(parent, fun_inner, name); 70 if (fun == NULL) { 71 ddf_msg(LVL_ERROR, "Failed creating function %s", name); 72 return ENOMEM; 73 73 } 74 75 rc = ddf_fun_add_match_id(fun, match_id, match_score); 76 if (rc != EOK) { 77 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 78 name); 79 ddf_fun_destroy(fun); 80 return rc; 81 } 82 83 rc = ddf_fun_bind(fun); 84 if (rc != EOK) { 85 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name, 86 str_error(rc)); 87 ddf_fun_destroy(fun); 88 return rc; 89 } 90 91 ddf_msg(LVL_NOTE, "Registered child device `%s'", name); 92 return EOK; 74 93 } 75 94 76 95 /** Add child devices after some sleep. 77 96 * 78 * @param arg Parent device structure (d evice_t *).97 * @param arg Parent device structure (ddf_dev_t *). 79 98 * @return Always EOK. 80 99 */ 81 100 static int postponed_birth(void *arg) 82 101 { 83 device_t *dev = (device_t *) arg; 102 ddf_dev_t *dev = (ddf_dev_t *) arg; 103 ddf_fun_t *fun_a; 104 int rc; 84 105 85 106 async_usleep(1000); 86 107 87 register_child_verbose(dev, "child driven by the same task",108 (void) register_fun_verbose(dev, "child driven by the same task", 88 109 "child", "virtual&test2", 10); 89 register_child_verbose(dev, "child driven by test1",110 (void) register_fun_verbose(dev, "child driven by test1", 90 111 "test1", "virtual&test1", 10); 91 112 92 add_device_to_class(dev, "virtual"); 113 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 114 if (fun_a == NULL) { 115 ddf_msg(LVL_ERROR, "Failed creating function 'a'."); 116 return ENOMEM; 117 } 118 119 rc = ddf_fun_bind(fun_a); 120 if (rc != EOK) { 121 ddf_msg(LVL_ERROR, "Failed binding function 'a'."); 122 return rc; 123 } 124 125 ddf_fun_add_to_class(fun_a, "virtual"); 93 126 94 127 return EOK; 95 128 } 96 129 97 98 static int add_device(device_t *dev) 130 static int test2_add_device(ddf_dev_t *dev) 99 131 { 100 printf(NAME ": add_device(name=\"%s\", handle=%d)\n",132 ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)", 101 133 dev->name, (int) dev->handle); 102 134 103 if ( dev->parent == NULL) {135 if (str_cmp(dev->name, "child") != 0) { 104 136 fid_t postpone = fibril_create(postponed_birth, dev); 137 if (postpone == 0) { 138 ddf_msg(LVL_ERROR, "fibril_create() failed."); 139 return ENOMEM; 140 } 105 141 fibril_add_ready(postpone); 106 142 } else { 107 register_child_verbose(dev, "child without available driver",143 (void) register_fun_verbose(dev, "child without available driver", 108 144 "ERROR", "non-existent.match.id", 10); 109 145 } … … 115 151 { 116 152 printf(NAME ": HelenOS test2 virtual device driver\n"); 117 return driver_main(&the_driver); 153 ddf_log_init(NAME, LVL_ERROR); 154 return ddf_driver_main(&test2_driver); 118 155 } 119 156
Note:
See TracChangeset
for help on using the changeset viewer.