| 1147 | ****************************************************************************/ |
| 1148 | |
| 1149 | int rpmsgdev_register(FAR const char *remotecpu, FAR const char *remotepath, |
| 1150 | FAR const char *localpath, uint32_t flags) |
| 1151 | { |
| 1152 | FAR struct rpmsgdev_s *dev; |
| 1153 | int ret; |
| 1154 | |
| 1155 | /* Arguments check */ |
| 1156 | |
| 1157 | if (remotecpu == NULL || remotepath == NULL) |
| 1158 | { |
| 1159 | return -EINVAL; |
| 1160 | } |
| 1161 | |
| 1162 | DEBUGASSERT(strlen(remotepath) + RPMSGDEV_NAME_PREFIX_LEN <= |
| 1163 | RPMSG_NAME_SIZE); |
| 1164 | |
| 1165 | dev = kmm_zalloc(sizeof(*dev)); |
| 1166 | if (dev == NULL) |
| 1167 | { |
| 1168 | return -ENOMEM; |
| 1169 | } |
| 1170 | |
| 1171 | /* Initialize the rpmsg device */ |
| 1172 | |
| 1173 | dev->remotecpu = remotecpu; |
| 1174 | dev->remotepath = remotepath; |
| 1175 | dev->flags = flags; |
| 1176 | |
| 1177 | nxsem_init(&dev->wait, 0, 0); |
| 1178 | |
| 1179 | /* Register the rpmsg callback */ |
| 1180 | |
| 1181 | ret = rpmsg_register_callback(dev, |
| 1182 | rpmsgdev_device_created, |
| 1183 | rpmsgdev_device_destroy, |
| 1184 | NULL, |
| 1185 | NULL); |
| 1186 | if (ret < 0) |
| 1187 | { |
| 1188 | rpmsgdeverr("register callback failed, ret=%d\n", ret); |
| 1189 | goto fail; |
| 1190 | } |
| 1191 | |
| 1192 | /* Register driver, using the remotepath if localpath is NULL */ |
| 1193 | |
| 1194 | if (localpath == NULL) |
| 1195 | { |
| 1196 | localpath = remotepath; |
| 1197 | } |
| 1198 | |
| 1199 | ret = register_driver(localpath, &g_rpmsgdev_ops, 0666, dev); |
| 1200 | if (ret < 0) |
| 1201 | { |
| 1202 | rpmsgdeverr("register driver failed, ret=%d\n", ret); |
| 1203 | goto fail_with_rpmsg; |
| 1204 | } |
| 1205 | |
| 1206 | return OK; |
no test coverage detected