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

Function _function_enable

components/legacy/usb/usbdevice/class/mstorage.c:982–1034  ·  view source on GitHub ↗

* This function will run mass storage function, it will be called on handle set configuration request. * * @param func the usb function object. * * @return RT_EOK on successful. */

Source from the content-addressed store, hash-verified

980 * @return RT_EOK on successful.
981 */
982static rt_err_t _function_enable(ufunction_t func)
983{
984 struct mstorage *data;
985 RT_ASSERT(func != RT_NULL);
986 LOG_D("Mass storage function enabled");
987 data = (struct mstorage*)func->user_data;
988
989 data->disk = rt_device_find(RT_USB_MSTORAGE_DISK_NAME);
990 if(data->disk == RT_NULL)
991 {
992 rt_kprintf("no data->disk named %s\n", RT_USB_MSTORAGE_DISK_NAME);
993 return -RT_ERROR;
994 }
995
996#ifdef RT_USING_DFS_MNTTABLE
997 dfs_unmount_device(data->disk);
998#endif
999
1000 if(rt_device_open(data->disk, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
1001 {
1002 rt_kprintf("disk open error\n");
1003 return -RT_ERROR;
1004 }
1005
1006 if(rt_device_control(data->disk, RT_DEVICE_CTRL_BLK_GETGEOME,
1007 (void*)&data->geometry) != RT_EOK)
1008 {
1009 rt_kprintf("get disk info error\n");
1010 return -RT_ERROR;
1011 }
1012
1013 data->ep_in->buffer = (rt_uint8_t*)rt_malloc(data->geometry.bytes_per_sector);
1014 if(data->ep_in->buffer == RT_NULL)
1015 {
1016 rt_kprintf("no memory\n");
1017 return -RT_ENOMEM;
1018 }
1019 data->ep_out->buffer = (rt_uint8_t*)rt_malloc(data->geometry.bytes_per_sector);
1020 if(data->ep_out->buffer == RT_NULL)
1021 {
1022 rt_free(data->ep_in->buffer);
1023 rt_kprintf("no memory\n");
1024 return -RT_ENOMEM;
1025 }
1026
1027 /* prepare to read CBW request */
1028 data->ep_out->request.buffer = data->ep_out->buffer;
1029 data->ep_out->request.size = SIZEOF_CBW;
1030 data->ep_out->request.req_type = UIO_REQUEST_READ_FULL;
1031 rt_usbd_io_request(func->device, data->ep_out, &data->ep_out->request);
1032
1033 return RT_EOK;
1034}
1035
1036/**
1037 * This function will stop mass storage function, it will be called on handle set configuration request.

Callers

nothing calls this directly

Calls 8

rt_device_findFunction · 0.85
rt_kprintfFunction · 0.85
dfs_unmount_deviceFunction · 0.85
rt_device_openFunction · 0.85
rt_device_controlFunction · 0.85
rt_mallocFunction · 0.85
rt_freeFunction · 0.85
rt_usbd_io_requestFunction · 0.85

Tested by

no test coverage detected