flash.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2018 Ayke van Laethem
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef __MICROPY_INCLUDED_LIB_FLASH_H__
  27. #define __MICROPY_INCLUDED_LIB_FLASH_H__
  28. #include "nrf_nvmc.h"
  29. #if defined(NRF51)
  30. #define FLASH_PAGESIZE (1024)
  31. #elif defined(NRF52_SERIES)
  32. #define FLASH_PAGESIZE (4096)
  33. #else
  34. #error Unknown chip
  35. #endif
  36. #define FLASH_IS_PAGE_ALIGNED(addr) (((uint32_t)(addr) & (FLASH_PAGESIZE - 1)) == 0)
  37. #if BLUETOOTH_SD
  38. typedef enum {
  39. FLASH_STATE_BUSY,
  40. FLASH_STATE_SUCCESS,
  41. FLASH_STATE_ERROR,
  42. } flash_state_t;
  43. void flash_page_erase(uint32_t address);
  44. void flash_write_byte(uint32_t address, uint8_t value);
  45. void flash_write_bytes(uint32_t address, const uint8_t *src, uint32_t num_bytes);
  46. void flash_operation_finished(flash_state_t result);
  47. #else
  48. #define flash_page_erase nrf_nvmc_page_erase
  49. #define flash_write_byte nrf_nvmc_write_byte
  50. #define flash_write_bytes nrf_nvmc_write_bytes
  51. #endif
  52. #endif // __MICROPY_INCLUDED_LIB_FLASH_H__