summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/modules/flash/flash.c
diff options
context:
space:
mode:
Diffstat (limited to 'digital/avr/modules/flash/flash.c')
-rw-r--r--digital/avr/modules/flash/flash.c172
1 files changed, 172 insertions, 0 deletions
diff --git a/digital/avr/modules/flash/flash.c b/digital/avr/modules/flash/flash.c
index e75df80c..bd84b4e4 100644
--- a/digital/avr/modules/flash/flash.c
+++ b/digital/avr/modules/flash/flash.c
@@ -23,8 +23,153 @@
*
* }}} */
#include "flash.h"
+#include "flash_sst.h"
+#include "flash_at.h"
#include "modules/proto/proto.h"
+/** Erase the memory.
+ * \param erase_type the erase type..
+ * \param start_addr the start address.
+ */
+typedef void
+(*flash_erase_t) (flash_erase_cmd_t cmd, uint32_t start_addr);
+
+/* Send a flash command to the flash memory (only a command).
+ * \param cmd the command to send.
+ */
+typedef void
+(*flash_send_command_t) (flash_cmd_t cmd);
+
+/** Read the busy bit in the Software Status Register of the flash memory.
+ * \return the status register.
+ */
+typedef uint8_t
+(*flash_read_status_t) (void);
+
+/** Read the busy bit in the Software Status Register of the flash memory.
+ * \return the busy bit state.
+ */
+typedef uint8_t
+(*flash_is_busy_t) (void);
+
+/** Write in the flash byte provided in parameter.
+ * \param data the buffer to store the data.
+ */
+typedef void
+(*flash_write_t) (uint32_t addr, uint8_t data);
+
+/** Read the data at the address provided.
+ * \param addr the address of the data to read.
+ * \return the data read.
+ */
+typedef uint8_t
+(*flash_read_t) (uint32_t addr);
+
+/** Read a data from the flash memory from the address provided and for a
+ * length of the number of bytes provided.
+ * \param address at which the data should be read.
+ * \param buffer the buffer to fill with the read data.
+ * \param length the length of the data to read.
+ */
+typedef void
+(*flash_read_array_t) (uint32_t addr, uint8_t *buffer, uint32_t length);
+
+/** Write in the flash byte provided in parameter.
+ * \param addr the address to store the data.
+ * \param data the array to store.
+ * \param length the array length
+ */
+typedef void
+(*flash_write_array_t) (uint32_t addr, uint8_t *data, uint32_t length);
+
+/** Get the flash size.
+ * \return the flash size.
+ */
+typedef uint32_t
+(*flash_size_t) (void);
+
+/** Get the flash block size.
+ * \return the flash block size.
+ */
+typedef uint32_t
+(*flash_block_size_t) (void);
+
+struct flash_t
+{
+ /** Erase function. */
+ flash_erase_t erase_func;
+ /** Send command function. */
+ flash_send_command_t send_cmd_func;
+ /** Read status function. */
+ flash_read_status_t read_status_func;
+ /** Is busy function. */
+ flash_is_busy_t is_busy_func;
+ /** Write function. */
+ flash_write_t write_func;
+ /** Read function. */
+ flash_read_t read_func;
+ /** Read array function. */
+ flash_read_array_t read_array_func;
+ /** Write array function. */
+ flash_write_array_t write_array_func;
+ /** Flash size function. */
+ flash_size_t flash_size_func;
+ /** Flash block size function. */
+ flash_block_size_t flash_block_size_func;
+};
+typedef struct flash_t flash_t;
+
+/** Static variable. */
+static flash_t flash;
+
+void
+flash_erase (flash_erase_cmd_t cmd, uint32_t start_addr)
+{
+ flash.erase_func (cmd, start_addr);
+}
+
+void
+flash_send_command (flash_cmd_t cmd)
+{
+ flash.send_cmd_func (cmd);
+}
+
+uint8_t
+flash_read_status (void)
+{
+ return flash.read_status_func ();
+}
+
+uint8_t
+flash_is_busy (void)
+{
+ return flash.is_busy_func ();
+}
+
+void
+flash_write (uint32_t addr, uint8_t data)
+{
+ flash.write_func (addr, data);
+}
+
+uint8_t
+flash_read (uint32_t addr)
+{
+ return flash.read_func (addr);
+}
+
+void
+flash_read_array (uint32_t addr, uint8_t *buffer, uint32_t length)
+{
+ flash.read_array_func (addr, buffer, length);
+}
+
+void
+flash_write_array (uint32_t addr, uint8_t *data, uint32_t length)
+{
+ flash.write_array_func (addr, data, length);
+}
+
int8_t
flash_log (uint8_t size, uint8_t *args)
{
@@ -75,3 +220,30 @@ flash_log (uint8_t size, uint8_t *args)
return error;
}
+
+uint32_t
+flash_size (void)
+{
+ return flash.flash_size_func ();
+}
+
+uint32_t
+flash_block_size (void)
+{
+ return flash.flash_block_size_func ();
+}
+
+void
+flash_init_sst (void)
+{
+ flash.erase_func = flash_sst_erase;
+ flash.send_cmd_func = flash_sst_send_command;
+ flash.read_status_func = flash_sst_read_status;
+ flash.is_busy_func = flash_sst_is_busy;
+ flash.write_func = flash_sst_write;
+ flash.read_func = flash_sst_read;
+ flash.read_array_func = flash_sst_read_array;
+ flash.write_array_func = flash_sst_write_array;
+ flash.flash_size_func = flash_sst_size;
+ flash.flash_block_size_func = flash_sst_block_size;
+}