Line data Source code
1 : #pragma once 2 : 3 : #include "SIM_config.h" 4 : 5 : #if AP_SIM_JEDEC_ENABLED 6 : 7 : #include "SIM_SPIDevice.h" 8 : 9 : namespace SITL { 10 : 11 : class JEDEC : public SPIDevice 12 : { 13 : public: 14 : 15 : int rdwr(uint8_t count, SPI::spi_ioc_transfer *&data) override; 16 : 17 : protected: 18 : 19 : virtual void fill_rdid(uint8_t *buf, uint8_t len) = 0; 20 : virtual void fill_rdsr(uint8_t *buf, uint8_t len) = 0; 21 : virtual const char *filename() const = 0; 22 : virtual uint8_t get_num_blocks() const = 0; 23 : virtual uint16_t get_page_per_block() const = 0; 24 : virtual uint8_t get_page_per_sector() const = 0; 25 : virtual uint16_t get_page_size() const = 0; 26 230879 : uint32_t get_storage_size() const { return get_num_pages()*get_page_size(); } // in bytes 27 230879 : uint32_t get_num_pages() const { return get_num_blocks()*get_page_per_block(); } 28 : 29 : private: 30 : 31 : enum class State { 32 : WAITING, 33 : READING_RDID, 34 : READING, 35 : WRITING, 36 : READING_RDSR 37 : } state = State::WAITING; 38 : 39 : bool write_enabled; 40 : uint32_t xfr_addr; 41 : 42 : void sector4k_erase(uint32_t addr); 43 : void block64k_erase(uint32_t addr); 44 : void page_erase(uint32_t addr); 45 : void bulk_erase(); 46 : uint32_t parse_addr(uint8_t *buffer, uint32_t len); 47 : void assert_writes_enabled(); 48 : void open_storage_fd(); 49 : int storage_fd = -1; 50 : }; 51 : 52 : } 53 : 54 : #endif // AP_SIM_JEDEC_ENABLED