sam3 port: add serial module.
[bertos.git] / bertos / io / kblock.h
index 7775d7b87f14f9f28df7c014b89f6f3e15fb2bda..9ac358ce37e34e01122a924c55018fea8de2b2ca 100644 (file)
@@ -33,6 +33,8 @@
  * \author Francesco Sacchi <batt@develer.com>
  *
  * \brief KBlock interface
+ *
+ * $WIZ$ module_name = "kblock"
  */
 
 #ifndef IO_KBLOCK_H
@@ -66,7 +68,7 @@ typedef int    (* kblock_load_t)        (struct KBlock *b, block_idx_t index);
 typedef int    (* kblock_store_t)       (struct KBlock *b, block_idx_t index);
 
 typedef int    (* kblock_error_t)       (struct KBlock *b);
-typedef int    (* kblock_clearerr_t)    (struct KBlock *b);
+typedef void   (* kblock_clearerr_t)    (struct KBlock *b);
 typedef int    (* kblock_close_t)       (struct KBlock *b);
 /* \} */
 
@@ -90,9 +92,13 @@ typedef struct KBlockVTable
 } KBlockVTable;
 
 
-#define KB_BUFFERED    BV(0) ///< Internal flag: true if the KBlock has a buffer
-#define KB_CACHE_DIRTY BV(1) ///< Internal flag: true if the cache is dirty
-#define KB_PARTIAL_WRITE BV(2) ///< Internal flag: true if the device allows partial block write
+#define KB_BUFFERED        BV(0) ///< Internal flag: true if the KBlock has a buffer
+#define KB_CACHE_DIRTY     BV(1) ///< Internal flag: true if the cache is dirty
+#define KB_PARTIAL_WRITE   BV(2) ///< Internal flag: true if the device allows partial block write
+
+#define KB_WRITE_ONCE      BV(3) ///< Allow only the one write on select block.
+#define KB_OPEN_BUFF       BV(4) ///< Open flash memory using page caching, allowing the modification and partial write.
+#define KB_OPEN_UNBUFF     BV(5) ///< Open flash memory whitout memory caching.
 
 /**
  * KBlock private members.
@@ -202,16 +208,27 @@ INLINE int kblock_error(struct KBlock *b)
  *
  * \param b KBlock device.
  *
- * \return 0 on success, EOF on errors.
  *
  * \sa kblock_error()
  */
-INLINE int kblock_clearerr(struct KBlock *b)
+INLINE void kblock_clearerr(struct KBlock *b)
 {
        KB_ASSERT_METHOD(b, clearerr);
-       return b->priv.vt->clearerr(b);
+       b->priv.vt->clearerr(b);
 }
 
+
+/**
+ * Flush the cache (if any) to the device.
+ *
+ * This function will write any pending modifications to the device.
+ * If the device does not have a cache, this function will do nothing.
+ *
+ * \return 0 if all is OK, EOF on errors.
+ * \sa kblock_read(), kblock_write(), kblock_buffered().
+ */
+int kblock_flush(struct KBlock *b);
+
 /**
  * Close the device.
  *
@@ -222,7 +239,7 @@ INLINE int kblock_clearerr(struct KBlock *b)
 INLINE int kblock_close(struct KBlock *b)
 {
        KB_ASSERT_METHOD(b, close);
-       return b->priv.vt->close(b);
+       return kblock_flush(b) | b->priv.vt->close(b);
 }
 
 /**
@@ -331,19 +348,6 @@ size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset,
  */
 size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *buf, size_t offset, size_t size);
 
-
-/**
- * Flush the cache (if any) to the device.
- *
- * This function will write any pending modifications to the device.
- * If the device does not have a cache, this function will do nothing.
- *
- * \return 0 if all is OK, EOF on errors.
- * \sa kblock_read(), kblock_write(), kblock_buffered().
- */
-int kblock_flush(struct KBlock *b);
-
-
 /**
  * Copy one block to another.
  *
@@ -364,5 +368,6 @@ int kblock_swLoad(struct KBlock *b, block_idx_t index);
 int kblock_swStore(struct KBlock *b, block_idx_t index);
 size_t kblock_swReadBuf(struct KBlock *b, void *buf, size_t offset, size_t size);
 size_t kblock_swWriteBuf(struct KBlock *b, const void *buf, size_t offset, size_t size);
+int kblock_swClose(struct KBlock *b);
 
 #endif /* IO_KBLOCK_H */