Line data Source code
1 : /* 2 : driver for RAMTRON FRAM persistent memory devices 3 : */ 4 : #pragma once 5 : 6 : #include <AP_Common/AP_Common.h> 7 : #include <AP_HAL/AP_HAL.h> 8 : 9 : class AP_RAMTRON { 10 : public: 11 : // initialise the driver 12 : // this will retry RAMTRON_RETRIES times until successful 13 : bool init(void); 14 : 15 : // get size in bytes 16 96532 : uint32_t get_size(void) const { return (id == UINT8_MAX) ? 0 : ramtron_ids[id].size_kbyte * 1024UL; } 17 : 18 : // read from device 19 : // this will retry RAMTRON_RETRIES times until two successive reads return the same data 20 : bool read(uint32_t offset, uint8_t * const buf, uint32_t size); 21 : 22 : // write to device 23 : bool write(uint32_t offset, uint8_t const * const buf, uint32_t size); 24 : 25 : private: 26 : AP_HAL::SPIDevice *dev; 27 : 28 : enum class RDID_type :uint8_t { 29 : Cypress, 30 : Fujitsu, 31 : Petabytes 32 : }; 33 : 34 : struct ramtron_id { 35 : uint8_t id1; 36 : uint8_t id2; 37 : uint16_t size_kbyte; 38 : uint8_t addrlen; 39 : RDID_type rdid_type; 40 : }; 41 : static const struct ramtron_id ramtron_ids[]; 42 : uint8_t id = UINT8_MAX; 43 : 44 : // perform a single device initialisation 45 : bool _init(void); 46 : // perform a single device read 47 : bool _read(uint32_t offset, uint8_t * const buf, uint32_t size); 48 : 49 : void send_offset(uint8_t cmd, uint32_t offset) const; 50 : };