Changeset 76b5a95c in mainline for uspace/drv/test2/test2.c
- Timestamp:
- 2011-03-23T20:53:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 71af5a4
- Parents:
- 5716e9a (diff), ab10b842 (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
r5716e9a r76b5a95c 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 <d river.h>37 #include <ddf/driver.h> 37 38 38 39 #define NAME "test2" 39 40 40 static int add_device(device_t *dev);41 static int test2_add_device(ddf_dev_t *dev); 41 42 42 43 static driver_ops_t driver_ops = { 43 .add_device = & add_device44 .add_device = &test2_add_device 44 45 }; 45 46 46 static driver_t t he_driver = {47 static driver_t test2_driver = { 47 48 .name = NAME, 48 49 .driver_ops = &driver_ops … … 57 58 * @param score Device match score. 58 59 */ 59 static void register_child_verbose(device_t *parent, const char *message,60 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 60 61 const char *name, const char *match_id, int match_score) 61 62 { 62 printf(NAME ": registering child device `%s': %s.\n",63 name, message);63 ddf_fun_t *fun; 64 int rc; 64 65 65 int rc = child_device_register_wrapper(parent, name, 66 match_id, match_score); 66 printf(NAME ": registering function `%s': %s.\n", name, message); 67 67 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)); 68 fun = ddf_fun_create(parent, fun_inner, name); 69 if (fun == NULL) { 70 printf(NAME ": error creating function %s\n", name); 71 return ENOMEM; 73 72 } 73 74 rc = ddf_fun_add_match_id(fun, match_id, match_score); 75 if (rc != EOK) { 76 printf(NAME ": error adding match IDs to function %s\n", name); 77 ddf_fun_destroy(fun); 78 return rc; 79 } 80 81 rc = ddf_fun_bind(fun); 82 if (rc != EOK) { 83 printf(NAME ": error binding function %s: %s\n", name, 84 str_error(rc)); 85 ddf_fun_destroy(fun); 86 return rc; 87 } 88 89 printf(NAME ": registered child device `%s'\n", name); 90 return EOK; 74 91 } 75 92 76 93 /** Add child devices after some sleep. 77 94 * 78 * @param arg Parent device structure (d evice_t *).95 * @param arg Parent device structure (ddf_dev_t *). 79 96 * @return Always EOK. 80 97 */ 81 98 static int postponed_birth(void *arg) 82 99 { 83 device_t *dev = (device_t *) arg; 100 ddf_dev_t *dev = (ddf_dev_t *) arg; 101 ddf_fun_t *fun_a; 102 int rc; 84 103 85 104 async_usleep(1000); 86 105 87 register_child_verbose(dev, "child driven by the same task",106 (void) register_fun_verbose(dev, "child driven by the same task", 88 107 "child", "virtual&test2", 10); 89 register_child_verbose(dev, "child driven by test1",108 (void) register_fun_verbose(dev, "child driven by test1", 90 109 "test1", "virtual&test1", 10); 91 110 92 add_device_to_class(dev, "virtual"); 111 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 112 if (fun_a == NULL) { 113 printf(NAME ": error creating function 'a'.\n"); 114 return ENOMEM; 115 } 116 117 rc = ddf_fun_bind(fun_a); 118 if (rc != EOK) { 119 printf(NAME ": error binding function 'a'.\n"); 120 return rc; 121 } 122 123 ddf_fun_add_to_class(fun_a, "virtual"); 93 124 94 125 return EOK; 95 126 } 96 127 97 98 static int add_device(device_t *dev) 128 static int test2_add_device(ddf_dev_t *dev) 99 129 { 100 printf(NAME ": add_device(name=\"%s\", handle=%d)\n",130 printf(NAME ": test2_add_device(name=\"%s\", handle=%d)\n", 101 131 dev->name, (int) dev->handle); 102 132 103 if ( dev->parent == NULL) {133 if (str_cmp(dev->name, "child") != 0) { 104 134 fid_t postpone = fibril_create(postponed_birth, dev); 135 if (postpone == 0) { 136 printf(NAME ": fibril_create() error\n"); 137 return ENOMEM; 138 } 105 139 fibril_add_ready(postpone); 106 140 } else { 107 register_child_verbose(dev, "child without available driver",141 (void) register_fun_verbose(dev, "child without available driver", 108 142 "ERROR", "non-existent.match.id", 10); 109 143 } … … 115 149 { 116 150 printf(NAME ": HelenOS test2 virtual device driver\n"); 117 return d river_main(&the_driver);151 return ddf_driver_main(&test2_driver); 118 152 } 119 153
Note:
See TracChangeset
for help on using the changeset viewer.