2020#include " drivers/QSPI.h"
2121#include " blockdevice/BlockDevice.h"
2222#include " platform/Callback.h"
23+ #include " bch.h"
2324
2425#ifndef MBED_CONF_SPINAND_QSPI_IO0
2526#define MBED_CONF_SPINAND_QSPI_IO0 NC
@@ -237,6 +238,10 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
237238 */
238239 virtual const char *get_type () const ;
239240
241+ virtual bool is_bad_block (uint16_t blk_idx);
242+
243+ virtual int mark_bad_block (uint16_t blk_idx);
244+
240245private:
241246 /* *******************************/
242247 /* Different Device Csel Mgmt */
@@ -258,6 +263,9 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
258263 // Send Read command to Driver
259264 qspi_status_t _qspi_send_read_command (mbed::qspi_inst_t read_instruction, void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
260265
266+ // Send Continuous Read command to Driver
267+ qspi_status_t _qspi_send_continuous_read_command (mbed::qspi_inst_t read_instruction, void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
268+
261269 // Send Erase Instruction using command_transfer command to Driver
262270 qspi_status_t _qspi_send_erase_command (mbed::qspi_inst_t erase_instruction, mbed::bd_addr_t addr, mbed::bd_size_t size);
263271
@@ -272,6 +280,13 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
272280 /* Flash Configuration Functions */
273281 /* ********************************/
274282
283+ // Read OTP ONFI parameters
284+ bool _read_otp_onfi ();
285+
286+ int _read_oob (void *buffer, bd_addr_t addr, bd_size_t size);
287+
288+ int _program_oob (const void *buffer, bd_addr_t addr, bd_size_t size);
289+
275290 // Quad Enable in Security Register
276291 int _set_quad_enable ();
277292
@@ -281,9 +296,19 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
281296 // Configure Write Enable in Status Register
282297 int _set_write_enable ();
283298
299+ int _set_conti_read_enable ();
300+
301+ int _set_conti_read_disable ();
302+
303+ int _conti_read_exit ();
304+
284305 // Wait on status register until write not-in-progress
285306 bool _is_mem_ready ();
286307
308+ void _bch_init (uint8_t ecc_bits);
309+ void _bch_free ();
310+ int _bch_calculate_ecc (unsigned char *buf, unsigned char *code);
311+ int _bch_correct_data (unsigned char *buf, unsigned char *read_ecc, unsigned char *calc_ecc);
287312private:
288313
289314 // QSPI Driver Object
@@ -320,6 +345,23 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
320345
321346 uint32_t _init_ref_count;
322347 bool _is_initialized;
348+ char _name[32 ];
349+ uint32_t _page_size, _block_size, _flash_size;
350+ uint8_t _page_shift, _block_shift;
351+ uint16_t _block_num, _page_num, _oob_size;
352+ uint8_t _ecc_bits, _ecc_bytes, _ecc_steps, _ecc_layout_pos;
353+ uint32_t _ecc_size;
354+ uint8_t *_ecc_calc;
355+ uint8_t *_ecc_code;
356+ uint8_t *_page_buf;
357+ uint8_t _continuous_read;
358+
359+ struct nand_bch_control {
360+ struct bch_code *bch;
361+ unsigned int *errloc;
362+ unsigned char *eccmask;
363+ };
364+ struct nand_bch_control _nbc;
323365};
324366
325367#endif
0 commit comments