X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=drv%2Fdflash.c;h=7dda5db06584bea0b74507fb3ebf32923e56baef;hb=86729451cd20c1805955d9e50f03d98b3f4e20ef;hp=8aad1f5465ebba249855a7c465bc8e4142d149a2;hpb=8b2138872120fa65294769202059dd8198da8504;p=bertos.git diff --git a/drv/dflash.c b/drv/dflash.c index 8aad1f54..7dda5db0 100644 --- a/drv/dflash.c +++ b/drv/dflash.c @@ -61,11 +61,14 @@ static void send_cmd(dflashAddr_t page_addr, dflashAddr_t byte_addr, DFlashOpcod /* * Make sure to toggle CS signal in order, * and reset dflash command decoder. - * \{ + * + * Note: + * #define CS_TOGGLE() \ + * CS_DISABLE(); \ + * CS_ENABLE(); \ */ - CS_DISABLE(); - CS_ENABLE(); - /* \} */ + CS_TOGGLE(); + /* * To send one command to data flash memory, we send 4 byte. @@ -104,25 +107,6 @@ static void send_cmd(dflashAddr_t page_addr, dflashAddr_t byte_addr, DFlashOpcod } - -//TODO: deve ritornare un bool? -/** - * Init data flash memory interface. - */ -void dflash_init(struct _KFile *fd) -{ - // Set up data flash programming functions. - fd->open = dflash_open; - fd->close = dflash_close; - fd->read = dflash_read; - fd->write = dflash_write; - fd->seek = dflash_seek; - - // Init data flash memory and micro pin. - dflash_pin_init(); -} - - /** * Reset dataflash memory function. * @@ -130,7 +114,7 @@ void dflash_init(struct _KFile *fd) * with one pulse reset long about 10usec. * */ -void dflash_reset(void) +static void dflash_reset(void) { CS_ENABLE(); RESET_ENABLE(); @@ -193,9 +177,7 @@ static uint8_t dflash_stat(void) * and reset dflash command decoder. * \{ */ - CS_DISABLE(); - CS_ENABLE(); - /* \} */ + CS_TOGGLE(); stat = spi_sendRecv(DFO_READ_STATUS); stat = spi_sendRecv(0x00); @@ -260,8 +242,8 @@ static uint8_t dflash_read_byte(dflashAddr_t page_addr, dflashAddr_t byte_addr, } /** - * Read \param len bytes from main data flash memory or buffer data - * flash memory, and put it in \param *block. + * Read \a len bytes from main data flash memory or buffer data + * flash memory, and put it in \a *block. */ static void dflash_read_block(dflashAddr_t page_addr, dflashAddr_t byte_addr, DFlashOpcode opcode, uint8_t *block, dflashSize_t len) { @@ -288,37 +270,71 @@ static void dflash_read_block(dflashAddr_t page_addr, dflashAddr_t byte_addr, DF } + /** - * Write one byte in buffer buffer data flash memory. + * Write \a len bytes in buffer buffer data flash memory. * - * \note Isn't possible to write byte directly in main memory data + * \note Isn't possible to write bytes directly in main memory data * flash. To perform write in main memory you must before write in buffer * data flash memory, an then send command to write page in main memory. */ -static void dflash_write_byte(dflashAddr_t byte_addr, DFlashOpcode opcode, uint8_t data) +static void dflash_write_block(dflashAddr_t byte_addr, DFlashOpcode opcode, uint8_t *block, dflashSize_t len) { + send_cmd(0x00, byte_addr, opcode); - spi_sendRecv(data); //Write data byte. + spi_write(block, len); //Write len bytes. CS_DISABLE(); + } +/* Kfile interface section */ + /** - * Write \param len bytes in buffer buffer data flash memory. - * - * \note Isn't possible to write bytes directly in main memory data - * flash. To perform write in main memory you must before write in buffer - * data flash memory, an then send command to write page in main memory. + * Open data flash file \a fd + * \a name and \a mode are unused, cause flash memory is + * threated like one file. */ -static void dflash_write_block(dflashAddr_t byte_addr, DFlashOpcode opcode, uint8_t *block, dflashSize_t len) +static bool dflash_open(struct _KFile *fd, UNUSED_ARG(const char *, name), UNUSED_ARG(int, mode)) { +} +/** + * Close file \a fd + */ +static bool dflash_close(UNUSED_ARG(struct _KFile *,fd)) +{ +} - send_cmd(0x00, byte_addr, opcode); +/** + * Move \a fd file seek position of \a offset bytes + * from current position. + */ +static int32_t dflash_seek(struct _KFile *fd, int32_t offset, KSeekMode whence) +{ +} - spi_write(block, len); //Write len bytes. +/** + * Read from file \a fd \a size bytes and put it in buffer \a buf + * \return the number of bytes read. + */ +static size_t dflash_read(struct _KFile *fd, void *buf, size_t size) +{ +} - CS_DISABLE(); +/** + * Init data flash memory interface. + */ +void dflash_init(struct _KFile *fd) +{ + // Set up data flash programming functions. + fd->open = dflash_open; + fd->close = dflash_close; + fd->read = dflash_read; + fd->write = dflash_write; + fd->seek = dflash_seek; -} + // Init data flash memory and micro pin. + ASSERT(dflash_pin_init()); +} \ No newline at end of file