luat_otp_air105.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_otp.h"
  23. #include "app_interface.h"
  24. int luat_otp_read(int zone, char* buff, size_t offset, size_t len) {
  25. if (zone < 0 || zone > 2)
  26. return -1;
  27. int addr = zone * 1024 + offset;
  28. OTP_Read((uint32_t)addr, (const uint32_t *)buff, len / 4);
  29. return len;
  30. }
  31. int luat_otp_write(int zone, char* buff, size_t offset, size_t len) {
  32. if (zone < 0 || zone > 2)
  33. return -1;
  34. int addr = zone * 1024 + offset;
  35. OTP_Write(addr, (const uint32_t *)buff, len / 4);
  36. return 0;
  37. }
  38. int luat_otp_erase(int zone, size_t offset, size_t len) {
  39. return 0; // 无需主动擦除
  40. }
  41. int luat_otp_lock(int zone) {
  42. OTP_Lock();
  43. return 0;
  44. }