update: 重构libgnss,解决air530z-bd及air780epvg出现的问题
[LuatOS.git] / components / sfd / luat_sfd_onchip.c
blob22cb8365aa02689852762a53f34ad4105ac7bded
2 #include "luat_base.h"
4 #include "luat_sfd.h"
5 #include "luat_mem.h"
7 const sdf_opts_t sfd_onchip_opts = {
8 .initialize = sfd_onchip_init,
9 .status = sfd_onchip_status,
10 .read = sfd_onchip_read,
11 .write = sfd_onchip_write,
12 .erase = sfd_onchip_erase,
13 .ioctl = sfd_onchip_ioctl,
16 sfd_drv_t* sfd_onchip;
18 int luat_sfd_onchip_init(void) {
19 if (sfd_onchip != NULL) {
20 return 0;
22 sfd_onchip = luat_heap_malloc(sizeof(sfd_drv_t));
23 if (sfd_onchip == NULL) {
24 return -1;
26 sfd_onchip_t * onchip = luat_heap_malloc(sizeof(sfd_onchip_t));
27 if (onchip == NULL) {
28 luat_heap_free(sfd_onchip);
29 sfd_onchip = NULL;
30 return -2;
32 memset(sfd_onchip, 0, sizeof(sfd_drv_t));
33 sfd_onchip->opts = &sfd_onchip_opts;
34 sfd_onchip->type = 2;
35 sfd_onchip->userdata = onchip;
36 int ret = sfd_onchip_init(onchip);
37 if (ret != 0) {
38 luat_heap_free(onchip);
39 luat_heap_free(sfd_onchip);
40 sfd_onchip = NULL;
41 return -3;
43 return ret;