luat_sfd_onchip_air101.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "luat_base.h"
  2. #include "luat_sfd.h"
  3. // #ifdef LUAT_SFD_ONCHIP
  4. #define LUAT_LOG_TAG "onchip"
  5. #include "luat_log.h"
  6. #include "wm_include.h"
  7. #include "wm_flash_map.h"
  8. #include "wm_internal_flash.h"
  9. extern uint32_t kv_addr;
  10. extern uint32_t kv_size_kb;
  11. int sfd_onchip_init (void* userdata) {
  12. sfd_onchip_t* onchip = (sfd_onchip_t*)userdata;
  13. if (onchip == NULL)
  14. return -1;
  15. //LLOGD("kv addr 0x%08X", kv_addr);
  16. //LLOGD("kv addr2 0x%08X", (0x1FC000 - 112 * 1024 - 64 * 1024));
  17. onchip->addr = kv_addr;
  18. return 0;
  19. }
  20. int sfd_onchip_status (void* userdata) {
  21. return 0;
  22. }
  23. int sfd_onchip_read (void* userdata, char* buff, size_t offset, size_t len) {
  24. int ret;
  25. sfd_onchip_t* onchip = (sfd_onchip_t*)userdata;
  26. if (onchip == NULL)
  27. return -1;
  28. ret = tls_fls_read(offset + onchip->addr, (u8 *)buff, len);
  29. if (ret != TLS_FLS_STATUS_OK)
  30. {
  31. return -1;
  32. }
  33. return 0;
  34. }
  35. int sfd_onchip_write (void* userdata, const char* buff, size_t offset, size_t len) {
  36. int ret;
  37. sfd_onchip_t* onchip = (sfd_onchip_t*)userdata;
  38. if (onchip == NULL)
  39. return -1;
  40. ret = tls_fls_write_without_erase(offset + onchip->addr, (u8 *)buff, len);
  41. if (ret != TLS_FLS_STATUS_OK)
  42. {
  43. return -1;
  44. }
  45. return 0;
  46. }
  47. int sfd_onchip_erase (void* userdata, size_t offset, size_t len) {
  48. int ret;
  49. sfd_onchip_t* onchip = (sfd_onchip_t*)userdata;
  50. if (onchip == NULL)
  51. return -1;
  52. ret = tls_fls_erase((offset + onchip->addr) / INSIDE_FLS_SECTOR_SIZE);
  53. if (ret != TLS_FLS_STATUS_OK)
  54. {
  55. return -1;
  56. }
  57. return 0;
  58. }
  59. int sfd_onchip_ioctl (void* userdata, size_t cmd, void* buff) {
  60. return 0;
  61. }
  62. // #endif