luat_sfd_onchip.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "luat_base.h"
  2. #include "luat_sfd.h"
  3. #include "luat_mem.h"
  4. const sdf_opts_t sfd_onchip_opts = {
  5. .initialize = sfd_onchip_init,
  6. .status = sfd_onchip_status,
  7. .read = sfd_onchip_read,
  8. .write = sfd_onchip_write,
  9. .erase = sfd_onchip_erase,
  10. .ioctl = sfd_onchip_ioctl,
  11. };
  12. sfd_drv_t* sfd_onchip;
  13. int luat_sfd_onchip_init(void) {
  14. if (sfd_onchip != NULL) {
  15. return 0;
  16. }
  17. sfd_onchip = luat_heap_malloc(sizeof(sfd_drv_t));
  18. if (sfd_onchip == NULL) {
  19. return -1;
  20. }
  21. sfd_onchip_t * onchip = luat_heap_malloc(sizeof(sfd_onchip_t));
  22. if (onchip == NULL) {
  23. luat_heap_free(sfd_onchip);
  24. sfd_onchip = NULL;
  25. return -2;
  26. }
  27. memset(sfd_onchip, 0, sizeof(sfd_drv_t));
  28. sfd_onchip->opts = &sfd_onchip_opts;
  29. sfd_onchip->type = 2;
  30. sfd_onchip->userdata = onchip;
  31. int ret = sfd_onchip_init(onchip);
  32. if (ret != 0) {
  33. luat_heap_free(onchip);
  34. luat_heap_free(sfd_onchip);
  35. sfd_onchip = NULL;
  36. return -3;
  37. }
  38. return ret;
  39. }