MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / fal_char_device_create

Function fal_char_device_create

components/fal/src/fal_rtt.c:500–553  ·  view source on GitHub ↗

* create RT-Thread char device by specified partition * * @param parition_name partition name * * @return != NULL: created char device * NULL: created failed */

Source from the content-addressed store, hash-verified

498 * NULL: created failed
499 */
500struct rt_device *fal_char_device_create(const char *parition_name)
501{
502 struct fal_char_device *char_dev;
503 const struct fal_partition *fal_part = fal_partition_find(parition_name);
504
505 if (!fal_part)
506 {
507 LOG_E("Error: the partition name (%s) is not found.", parition_name);
508 return NULL;
509 }
510
511 if ((fal_flash_device_find(fal_part->flash_name)) == NULL)
512 {
513 LOG_E("Error: the flash device name (%s) is not found.", fal_part->flash_name);
514 return NULL;
515 }
516
517 char_dev = (struct fal_char_device *) rt_malloc(sizeof(struct fal_char_device));
518 if (char_dev)
519 {
520 char_dev->fal_part = fal_part;
521
522 /* register device */
523 char_dev->parent.type = RT_Device_Class_Char;
524
525#ifdef RT_USING_DEVICE_OPS
526 char_dev->parent.ops = &char_dev_ops;
527#else
528 char_dev->parent.init = NULL;
529 char_dev->parent.open = NULL;
530 char_dev->parent.close = NULL;
531 char_dev->parent.read = char_dev_read;
532 char_dev->parent.write = char_dev_write;
533 char_dev->parent.control = NULL;
534 /* no private */
535 char_dev->parent.user_data = NULL;
536#endif
537
538 rt_device_register(RT_DEVICE(char_dev), fal_part->name, RT_DEVICE_FLAG_RDWR);
539 LOG_I("The FAL char device (%s) created successfully", fal_part->name);
540
541#ifdef RT_USING_POSIX_DEVIO
542 /* set fops */
543 char_dev->parent.fops = &char_dev_fops;
544#endif
545
546 }
547 else
548 {
549 LOG_E("Error: no memory for create FAL char device");
550 }
551
552 return RT_DEVICE(char_dev);
553}
554
555#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
556

Callers

nothing calls this directly

Calls 4

fal_partition_findFunction · 0.85
fal_flash_device_findFunction · 0.85
rt_mallocFunction · 0.85
rt_device_registerFunction · 0.85

Tested by

no test coverage detected