]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - embedded/libs4c/keyval/keyvalpb.h
Embedded code-base updated to actual version from uLan repository.
[lincan.git] / embedded / libs4c / keyval / keyvalpb.h
index dbb77740c170580f756ff6d772ed13a8f301d1e1..210a02b3c2ef20786cfe9b1a77f96d7534381682 100644 (file)
@@ -17,7 +17,7 @@
   some of the licenses, he/she can delete appropriate line.
   Warning, if you delete all lines, you are not allowed to
   distribute source code and/or binaries utilizing code.
   some of the licenses, he/she can delete appropriate line.
   Warning, if you delete all lines, you are not allowed to
   distribute source code and/or binaries utilizing code.
-  
+
   See files COPYING and README for details.
 
  *******************************************************************/
   See files COPYING and README for details.
 
  *******************************************************************/
@@ -63,7 +63,7 @@
 #define KVPB_DESC_RO      0x08
 #define KVPB_DESC_CHUNKWO 0x10
 #define KVPB_DESC_ALIGN4  0x40
 #define KVPB_DESC_RO      0x08
 #define KVPB_DESC_CHUNKWO 0x10
 #define KVPB_DESC_ALIGN4  0x40
-#define KVPB_DESC_FLASH   0x80  
+#define KVPB_DESC_FLASH   0x80
 
 #ifdef  KVPB_MINIMALIZED
 typedef uint16_t kvpb_sum_t;
 
 #ifdef  KVPB_MINIMALIZED
 typedef uint16_t kvpb_sum_t;
@@ -84,7 +84,7 @@ typedef uint32_t kvpb_keyid_t;
  *     %KVPB_DESC_USE2ND - data will be read from the second copy because first one is damaged;
  *     %KVPB_DESC_VALID - at least one region is valid;
  *     %KVPB_DESC_RO - because of some problems, only read access is allowed
  *     %KVPB_DESC_USE2ND - data will be read from the second copy because first one is damaged;
  *     %KVPB_DESC_VALID - at least one region is valid;
  *     %KVPB_DESC_RO - because of some problems, only read access is allowed
- *      %KVPB_DESC_CHUNKWO - chunk can be written only once between erase operations 
+ *      %KVPB_DESC_CHUNKWO - chunk can be written only once between erase operations
  *     %KVPB_DESC_ALIGN4 - data has to be aligned to four bytes
  *     %KVPB_DESC_FLASH - flash memory is used for data storage
  * @psum1: Pointer to the control checksum of the first data region
  *     %KVPB_DESC_ALIGN4 - data has to be aligned to four bytes
  *     %KVPB_DESC_FLASH - flash memory is used for data storage
  * @psum1: Pointer to the control checksum of the first data region
@@ -111,14 +111,15 @@ typedef struct kvpb_block {
 } kvpb_block_t;
 
 
 } kvpb_block_t;
 
 
-#define kvpb_region_base(block,regidx) (((block)->base+(regidx*(block)->size)))
+#define kvpb_region_base(block,regidx) \
+       ((((KVPB_DPTRTYPE uint8_t *)(block)->base)+(regidx*(block)->size)))
 
 #ifndef  KVPB_MINIMALIZED
  #ifndef kvpb_chunk_size
    #define kvpb_chunk_size(store) ((store)->chunk_size<4?4:(store)->chunk_size)
  #endif /*kvpb_chunk_size*/
  #define kvpb_chunk_size_mask(store) (kvpb_chunk_size(store)-1)
 
 #ifndef  KVPB_MINIMALIZED
  #ifndef kvpb_chunk_size
    #define kvpb_chunk_size(store) ((store)->chunk_size<4?4:(store)->chunk_size)
  #endif /*kvpb_chunk_size*/
  #define kvpb_chunk_size_mask(store) (kvpb_chunk_size(store)-1)
+
 /**
  * kvpb_chunk_align - Round up KVPB size to minimal store chunk size multiple
  * @store: Pointer to the KVPB access information/state structure
 /**
  * kvpb_chunk_align - Round up KVPB size to minimal store chunk size multiple
  * @store: Pointer to the KVPB access information/state structure
@@ -135,7 +136,7 @@ typedef struct kvpb_block {
 /**
  * kvpb_psum_align - Round up KVPB size to minimal store chunk size multiple
  * @store: Pointer to the KVPB access information/state structure
 /**
  * kvpb_psum_align - Round up KVPB size to minimal store chunk size multiple
  * @store: Pointer to the KVPB access information/state structure
- * @psum: Pointer to proposed location of next check sum location 
+ * @psum: Pointer to proposed location of next check sum location
  *
  * Return Value: Pointer to next check sum location rounded down to next slot.
  * File: keyvalpb.h
  *
  * Return Value: Pointer to next check sum location rounded down to next slot.
  * File: keyvalpb.h
@@ -180,7 +181,7 @@ typedef struct kvpb_block {
  */
  static inline int kvpb_block_erase(struct kvpb_block *store, void *base,int size)
  {
  */
  static inline int kvpb_block_erase(struct kvpb_block *store, void *base,int size)
  {
-   return store->erase(store, base,size) ; 
+   return store->erase(store, base,size) ;
  }
 
 /**
  }
 
 /**
@@ -222,15 +223,18 @@ typedef struct kvpb_block {
                 ((KVPB_DPTRTYPE kvpb_sum_t*)((unsigned)(x)&~kvpb_chunk_size_mask(store)))
  #define kvpb_psum_valid_loc(store,x) \
                ((kvpb_sum_t*)((char*)(x)+0*kvpb_chunk_size(store)))
                 ((KVPB_DPTRTYPE kvpb_sum_t*)((unsigned)(x)&~kvpb_chunk_size_mask(store)))
  #define kvpb_psum_valid_loc(store,x) \
                ((kvpb_sum_t*)((char*)(x)+0*kvpb_chunk_size(store)))
+#ifndef kvpb_block_copy
  #define kvpb_block_erase(store, base, size) flash_erase(base, size)
  #define kvpb_block_erase(store, base, size) flash_erase(base, size)
- #define kvpb_block_copy(store, des, src, len) flash_copy(des, src, len) 
- #define kvpb_block_flush(store) flash_flush() 
+ #define kvpb_block_copy(store, des, src, len) flash_copy(des, src, len)
+ #define kvpb_block_flush(store) flash_flush()
+
  /* forward declarations for external procedures */
  int flash_erase(void *base,int size);
  int flash_copy(void *des,const void *src,int len);
 #ifndef flash_flush
  int flash_flush(void);
 #endif /* flash_flush */
  /* forward declarations for external procedures */
  int flash_erase(void *base,int size);
  int flash_copy(void *des,const void *src,int len);
 #ifndef flash_flush
  int flash_flush(void);
 #endif /* flash_flush */
+#endif /* kvpb_block_copy */
 #endif /* KVPB_MINIMALIZED */
 
 /**
 #endif /* KVPB_MINIMALIZED */
 
 /**
@@ -284,7 +288,7 @@ int __kvpb_check(uint8_t mode);
 #define kvpb_find(block, keyid, mode, key) __kvpb_find(keyid, mode, key)
 #define kvpb_get_key(block, keyid, size, buf) __kvpb_get_key(keyid, size, buf)
 #define kvpb_set_key(block, keyid, size, buf) __kvpb_set_key(keyid, size, buf)
 #define kvpb_find(block, keyid, mode, key) __kvpb_find(keyid, mode, key)
 #define kvpb_get_key(block, keyid, size, buf) __kvpb_get_key(keyid, size, buf)
 #define kvpb_set_key(block, keyid, size, buf) __kvpb_set_key(keyid, size, buf)
-#define kvpb_err_keys(block,keyid) kvpb_set_key(block,keyid,0,NULL) 
+#define kvpb_err_keys(block,keyid) kvpb_set_key(block,keyid,0,NULL)
 #define kvpb_check(block, mode) __kvpb_check(mode)
 #define kvpb_compact_region(block, mode, keyid) __kvpb_compact_region(mode, keyid)
 #define kvpb_get_cfk(block,mode,size) __kvpb_get_cfk(mode,size)
 #define kvpb_check(block, mode) __kvpb_check(mode)
 #define kvpb_compact_region(block, mode, keyid) __kvpb_compact_region(mode, keyid)
 #define kvpb_get_cfk(block,mode,size) __kvpb_get_cfk(mode,size)
@@ -301,7 +305,7 @@ int __kvpb_check(uint8_t mode);
  */
 #define kvpb_for_each(root, key,mode) \
         for(key=kvpb_first(root,mode);key;\
  */
 #define kvpb_for_each(root, key,mode) \
         for(key=kvpb_first(root,mode);key;\
-            key=kvpb_next(key))
+            key=kvpb_next(root, key))
 
 /**
  * kvpb_for_each - Iterate over all key value pairs matching given key ID
 
 /**
  * kvpb_for_each - Iterate over all key value pairs matching given key ID