luat_sfd_onchip_air105.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #include "luat_base.h"
  22. #include "luat_sfd.h"
  23. // #ifdef LUAT_SFD_ONCHIP
  24. #define LUAT_LOG_TAG "onchip"
  25. #include "luat_log.h"
  26. #include "app_interface.h"
  27. extern const size_t script_luadb_start_addr;
  28. int sfd_onchip_init (void* userdata) {
  29. sfd_onchip_t* onchip = (sfd_onchip_t*)userdata;
  30. if (onchip == NULL)
  31. return -1;
  32. onchip->addr = script_luadb_start_addr - 64*1024;
  33. return 0;
  34. }
  35. int sfd_onchip_status (void* userdata) {
  36. return 0;
  37. }
  38. int sfd_onchip_read (void* userdata, char* buff, size_t offset, size_t len) {
  39. int ret;
  40. sfd_onchip_t* onchip = (sfd_onchip_t*)userdata;
  41. if (onchip == NULL)
  42. return -1;
  43. mempcpy(buff, (char*)(offset + onchip->addr), len);
  44. return 0;
  45. }
  46. int sfd_onchip_write (void* userdata, const char* buff, size_t offset, size_t len) {
  47. int ret;
  48. sfd_onchip_t* onchip = (sfd_onchip_t*)userdata;
  49. if (onchip == NULL)
  50. return -1;
  51. ret = Flash_ProgramData(offset + onchip->addr, (uint32_t *)buff, len, 0);
  52. if (ret != 0)
  53. {
  54. return -1;
  55. }
  56. return 0;
  57. }
  58. int sfd_onchip_erase (void* userdata, size_t offset, size_t len) {
  59. int ret;
  60. sfd_onchip_t* onchip = (sfd_onchip_t*)userdata;
  61. if (onchip == NULL)
  62. return -1;
  63. ret = Flash_EraseSector(offset + onchip->addr, 0);
  64. if (ret != 0)
  65. {
  66. return -1;
  67. }
  68. return 0;
  69. }
  70. int sfd_onchip_ioctl (void* userdata, size_t cmd, void* buff) {
  71. return 0;
  72. }
  73. // #endif