diff options
-rw-r--r-- | os/ex/Micron/n25q128.c | 84 | ||||
-rw-r--r-- | os/ex/Micron/n25q128.h | 50 | ||||
-rw-r--r-- | os/hal/lib/peripherals/flash/hal_flash.h | 113 |
3 files changed, 182 insertions, 65 deletions
diff --git a/os/ex/Micron/n25q128.c b/os/ex/Micron/n25q128.c index 5643336ad..53e54aecd 100644 --- a/os/ex/Micron/n25q128.c +++ b/os/ex/Micron/n25q128.c @@ -33,6 +33,27 @@ /* Driver local definitions. */ /*===========================================================================*/ +static const flash_descriptor_t *get_attributes(void *instance); +static flash_error_t erase_all(void *instance); +static flash_error_t erase_sectors(void *instance, + flash_sector_t sector, + flash_sector_t n); +static flash_error_t are_sectors_erased(void *instance, + flash_sector_t sector, + flash_sector_t n); +static flash_error_t program(void *instance, flash_address_t addr, + const uint8_t *pp, size_t n); +static flash_error_t read(void *instance, flash_address_t addr, + uint8_t *rp, size_t n); + +/** + * @brief Virtual methods table. + */ +static const struct N25Q128DriverVMT n25q128_vmt = { + get_attributes, erase_all, erase_sectors, are_sectors_erased, + program, read +}; + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ @@ -45,6 +66,64 @@ /* Driver local functions. */ /*===========================================================================*/ +static const flash_descriptor_t *get_attributes(void *instance) { + + (void)instance; + + return FLASH_NO_ERROR; +} + +static flash_error_t erase_all(void *instance) { + + (void)instance; + + return FLASH_NO_ERROR; +} + +static flash_error_t erase_sectors(void *instance, + flash_sector_t sector, + flash_sector_t n) { + + (void)instance; + (void)sector; + (void)n; + + return FLASH_NO_ERROR; +} + +static flash_error_t are_sectors_erased(void *instance, + flash_sector_t sector, + flash_sector_t n) { + + (void)instance; + (void)sector; + (void)n; + + return FLASH_NO_ERROR; +} + +static flash_error_t program(void *instance, flash_address_t addr, + const uint8_t *pp, size_t n) { + + (void)instance; + (void)addr; + (void)pp; + (void)n; + + return FLASH_NO_ERROR; +} + +static flash_error_t read(void *instance, flash_address_t addr, + uint8_t *rp, size_t n) { + + (void)instance; + (void)addr; + (void)rp; + (void)n; + + return FLASH_NO_ERROR; +} + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ @@ -58,6 +137,8 @@ */ void n15q128ObjectInit(N25Q128Driver *devp) { + devp->vmt_baseflash = &n25q128_vmt; + devp->config = NULL; } /** @@ -70,6 +151,8 @@ void n15q128ObjectInit(N25Q128Driver *devp) { */ void n15q128Start(N25Q128Driver *devp, const N25Q128Config *config) { + (void)devp; + (void)config; } /** @@ -81,6 +164,7 @@ void n15q128Start(N25Q128Driver *devp, const N25Q128Config *config) { */ void n15q128Stop(N25Q128Driver *devp) { + (void)devp; } /** @} */ diff --git a/os/ex/Micron/n25q128.h b/os/ex/Micron/n25q128.h index 13e9ec3bf..e0f301a30 100644 --- a/os/ex/Micron/n25q128.h +++ b/os/ex/Micron/n25q128.h @@ -33,6 +33,40 @@ /* Driver constants. */ /*===========================================================================*/ +/** + * @name Command codes + * @{ + */ +#define N25Q128_CMD_RESET_ENABLE 0x66 +#define N25Q128_CMD_RESET_MEMORY 0x99 +#define N25Q128_CMD_READ_ID 0x9E +#define N25Q128_CMD_READ_DISCOVERY_PARAMETER 0x5A +#define N25Q128_CMD_READ 0x03 +#define N25Q128_CMD_FAST_READ 0x08 +#define N25Q128_CMD_WRITE_ENABLE 0x06 +#define N25Q128_CMD_WRITE_DISABLE 0x04 +#define N25Q128_CMD_READ_STATUS_REGISTER 0x05 +#define N25Q128_CMD_WRITE_STATUS_REGISTER 0x01 +#define N25Q128_CMD_READ_LOCK_REGISTER 0xE8 +#define N25Q128_CMD_WRITE_LOCK_REGISTER 0xE5 +#define N25Q128_CMD_READ_FLAG_STATUS_REGISTER 0x70 +#define N25Q128_CMD_CLEAR_FLAG_STATUS_REGISTER 0x50 +#define N25Q128_CMD_READ_NV_CONFIGURATION_REGISTER 0xB5 +#define N25Q128_CMD_WRITE_NV_CONFIGURATION_REGISTER 0xB1 +#define N25Q128_CMD_READ_V_CONF_REGISTER 0x85 +#define N25Q128_CMD_WRITE_V_CONF_REGISTER 0x81 +#define N25Q128_CMD_READ_ENHANCED_V_CONF_REGISTER 0x65 +#define N25Q128_CMD_WRITE_ENHANCED_V_CONF_REGISTER 0x61 +#define N25Q128_CMD_PAGE_PROGRAM 0x02 +#define N25Q128_CMD_SUBSECTOR_ERASE 0x20 +#define N25Q128_CMD_SECTOR_ERASE 0xD8 +#define N25Q128_CMD_BULK_ERASE 0xC7 +#define N25Q128_CMD_PROGRAM_ERASE_RESUME 0x7A +#define N25Q128_CMD_PROGRAM_ERASE_SUSPEND 0x75 +#define N25Q128_CMD_READ_OTP_ARRAY 0x4B +#define N25Q128_CMD_PROGRAM_OTP_ARRAY 0x42 +/** @} */ + /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ @@ -96,12 +130,6 @@ typedef struct { struct N25Q128DriverVMT { _n25q128_methods }; - -/** - * @brief @p N25Q128Driver specific data. - */ -#define _n25q128_data \ - _base_flash_data /** * @extends BaseFlash @@ -109,9 +137,15 @@ struct N25Q128DriverVMT { * @brief Type of N25Q128 flash class. */ typedef struct { - /** @brief BaseSensor Virtual Methods Table. */ + /** + * @brief BaseFlash Virtual Methods Table. + */ const struct N25Q128DriverVMT *vmt_baseflash; - _n25q128_data + _base_flash_data + /** + * @brief Current configuration data. + */ + const N25Q128Config *config; } N25Q128Driver; /*===========================================================================*/ diff --git a/os/hal/lib/peripherals/flash/hal_flash.h b/os/hal/lib/peripherals/flash/hal_flash.h index 2d3ea1ba9..9905abb2a 100644 --- a/os/hal/lib/peripherals/flash/hal_flash.h +++ b/os/hal/lib/peripherals/flash/hal_flash.h @@ -51,60 +51,6 @@ /*===========================================================================*/
/**
- * @brief @p BaseFlash specific methods.
- * @note No methods so far, just a common ancestor interface.
- */
-#define _base_flash_methods_alone \
- /* Get flash device attributes.*/ \
- const flash_descriptor_t * (*get_attributes)(void *instance); \
- /* Erase whole flash device.*/ \
- flash_error_t erase_all(void *instance); \
- /* Erase single sector.*/ \
- flash_error_t erase_sectors(void *instance, \
- flash_sector_t sector, \
- flash_sector_t n); \
- /* Erase single sector.*/ \
- flash_error_t are_sectors_erased(void *instance, \
- flash_sector_t sector, \
- flash_sector_t n); \
- /* Write operation.*/ \
- flash_error_t write(void *instance, flash_address_t addr, \
- const uint8_t *wp, size_t n); \
- /* Read operation.*/ \
- flash_error_t read(void *instance, flash_address_t addr, \
- uint8_t *rp, size_t n);
-
-
-/**
- * @brief @p BaseFlash specific methods with inherited ones.
- */
-#define _base_flash_methods \
- _base_flash_methods_alone
-
-/**
- * @brief @p BaseFlash virtual methods table.
- */
-struct BaseFlashVMT {
- _base_flash_methods
-};
-
-/**
- * @brief @p BaseFlash specific data.
- * @note It is empty because @p BaseFlash is only an interface
- * without implementation.
- */
-#define _base_flash_data
-
-/**
- * @brief Base flash class.
- */
-typedef struct {
- /** @brief Virtual Methods Table.*/
- const struct BaseFlashVMT *vmt_baseflash;
- _base_flash_data
-} BaseFlash;
-
-/**
* @brief Type of a flash error code.
*/
typedef enum {
@@ -174,6 +120,59 @@ typedef struct { flash_address_t address;
} flash_descriptor_t;
+/**
+ * @brief @p BaseFlash specific methods.
+ * @note No methods so far, just a common ancestor interface.
+ */
+#define _base_flash_methods_alone \
+ /* Get flash device attributes.*/ \
+ const flash_descriptor_t * (*get_attributes)(void *instance); \
+ /* Erase whole flash device.*/ \
+ flash_error_t (*erase_all)(void *instance); \
+ /* Erase single sector.*/ \
+ flash_error_t (*erase_sectors)(void *instance, \
+ flash_sector_t sector, \
+ flash_sector_t n); \
+ /* Erase single sector.*/ \
+ flash_error_t (*are_sectors_erased)(void *instance, \
+ flash_sector_t sector, \
+ flash_sector_t n); \
+ /* Write operation.*/ \
+ flash_error_t (*program)(void *instance, flash_address_t addr, \
+ const uint8_t *pp, size_t n); \
+ /* Read operation.*/ \
+ flash_error_t (*read)(void *instance, flash_address_t addr, \
+ uint8_t *rp, size_t n);
+
+/**
+ * @brief @p BaseFlash specific methods with inherited ones.
+ */
+#define _base_flash_methods \
+ _base_flash_methods_alone
+
+/**
+ * @brief @p BaseFlash virtual methods table.
+ */
+struct BaseFlashVMT {
+ _base_flash_methods
+};
+
+/**
+ * @brief @p BaseFlash specific data.
+ * @note It is empty because @p BaseFlash is only an interface
+ * without implementation.
+ */
+#define _base_flash_data
+
+/**
+ * @brief Base flash class.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BaseFlashVMT *vmt_baseflash;
+ _base_flash_data
+} BaseFlash;
+
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
@@ -236,13 +235,13 @@ typedef struct { * @param[in] ip pointer to a @p BaseFlash or derived class
* @param[in] addr flash address
* @param[in] wp pointer to the data buffer
- * @param[in] n number of bytes to be written
+ * @param[in] n number of bytes to be programmed
* @return An error code.
*
* @api
*/
-#define flashWrite(ip) \
- (ip)->vmt_baseflash->write(ip, addr, wp, n)
+#define flashProgram(ip) \
+ (ip)->vmt_baseflash->program(ip, addr, pp, n)
/**
* @brief Read operation.
|