Generic communication interface between the wireless board (mote) and the sensor board. Any kind of sensor board can be connected to the mote using this specification given it provides a SPI peripheral, one input pin with interrupt capability and one digital output. The sensor board must implement a special register set from which all required information can be retrieved. Protocol: http://is.gd/wuQorh Github: http://is.gd/ySj1L9

Dependencies:   mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers buf_io.h Source File

buf_io.h

00001 /**
00002 @file buf_io.c
00003 
00004 Several functions for handling data in buffers. 
00005 
00006 Basic functions:
00007 
00008 buf_io_[get|put][8|16|32|64|f|d]_[f|t][b|l]_ap[r]
00009 
00010 Notation:
00011 
00012 8|16|32|64|f|d = data size (f for float, d for double)
00013 [f|t][b|l] = from/to big/little
00014 ap[r] = add pointer [reference] at the end
00015 
00016 Check buf_io.c for a proper implementation of these functions for your platform.
00017 */
00018 
00019 #ifndef __BUF_IO__
00020 #define __BUF_IO__
00021 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026 /** Pointer size */
00027 #define POINTER_SIZE (sizeof(void *)) 
00028 
00029 /** Number of elements in a array */
00030 #define NUM_OF_ELEMENTS_IN_ARRAY(a) (sizeof(a)/sizeof(a[0]))
00031 
00032 /** 
00033   @name next/prev macro functions
00034   Next/previous aligned address, avoiding data aborts in buffer operations.
00035   @{
00036 */
00037 #define __next_aligned_addr32(x)  (((x) + 0x03) & 0xFFFFFFFC)
00038 #define __next_aligned_addr16(x)  (((x) + 0x01) & 0xFFFFFFFE)
00039 #define __prev_aligned_addr32(x)  ((x) & 0xFFFFFFFC)
00040 #define __prev_aligned_addr16(x)  ((x) & 0xFFFFFFFE)
00041 /** @} */
00042 
00043 /** 
00044   @name swap functions
00045   Swap operations.
00046   @{
00047 */
00048 
00049 /** 
00050   Swaps a 16 bits unsigned integer.
00051   @param ucShort 16 bits unsigned integer to be swapped
00052   @return 16 bits unsigned integer swapped
00053   @{
00054  */
00055 uint16_t buf_io_swap16 (uint16_t usShort);
00056 
00057 /** 
00058   Swaps a 32 bits unsigned integer.
00059   @param ulLong 32 bits unsigned integer to be swapped
00060   @return 32 bits unsigned integer swapped
00061   @{
00062  */
00063 uint32_t buf_io_swap32 (uint32_t ulLong);
00064 
00065 /**
00066   Swaps a 16 bits unsigned integer inside a buffer.
00067   @param pucPtr Pointer where 16 bits unsigned integer is stored.
00068 */
00069 void buf_io_swap16p(uint8_t *pucPtr);
00070 
00071 /**
00072   Swaps a 32 bits unsigned integer inside a buffer.
00073   @param pucPtr Pointer where 32 bits unsigned integer is stored.
00074 */
00075 void buf_io_swap32p(uint8_t *pucPtr);
00076 
00077 /**
00078   Swaps 8 bits unsigned integer in a byte.
00079   @param ucChar 8 bits unsigned integer  to be bit swapped
00080   @return 8 bits unsigned integer  swapped
00081 */
00082 uint8_t  buf_io_swap8b (uint8_t ucChar);
00083 /** @} */
00084 
00085 /** 
00086   @name endianess dependent functions (GET)
00087   @{
00088 */
00089 uint8_t buf_io_get8_fl       (uint8_t  *buf);
00090 uint8_t buf_io_get8_fb       (uint8_t  *buf);
00091 uint8_t buf_io_get8_fl_apr   (uint8_t **buf);
00092 uint8_t buf_io_get8_fb_apr   (uint8_t **buf);
00093 #define  buf_io_get8_fl_ap(x) buf_io_get8_fl_apr(&x)
00094 #define  buf_io_get8_fb_ap(x) buf_io_get8_fb_apr(&x)
00095 
00096 uint16_t buf_io_get16_fl       (uint8_t  *buf);
00097 uint16_t buf_io_get16_fb       (uint8_t  *buf);
00098 uint16_t buf_io_get16_fl_apr   (uint8_t **buf);
00099 uint16_t buf_io_get16_fb_apr   (uint8_t **buf);
00100 #define  buf_io_get16_fl_ap(x) buf_io_get16_fl_apr(&x)
00101 #define  buf_io_get16_fb_ap(x) buf_io_get16_fb_apr(&x)
00102 
00103 uint32_t  buf_io_get32_fl       (uint8_t  *buf);
00104 uint32_t  buf_io_get32_fb       (uint8_t  *buf);
00105 uint32_t  buf_io_get32_fl_apr   (uint8_t **buf);
00106 uint32_t  buf_io_get32_fb_apr   (uint8_t **buf);
00107 #define   buf_io_get32_fl_ap(x) buf_io_get32_fl_apr(&x)
00108 #define   buf_io_get32_fb_ap(x) buf_io_get32_fb_apr(&x)
00109 
00110 uint64_t buf_io_get64_fl       (uint8_t  *buf);
00111 uint64_t buf_io_get64_fb       (uint8_t  *buf);
00112 uint64_t buf_io_get64_fl_apr   (uint8_t **buf);
00113 uint64_t buf_io_get64_fb_apr   (uint8_t **buf);
00114 #define  buf_io_get64_fl_ap(x) buf_io_get64_fl_apr(&x)
00115 #define  buf_io_get64_fb_ap(x) buf_io_get64_fb_apr(&x)
00116 
00117 float   buf_io_getf_fl       (uint8_t *src_ptr);
00118 float   buf_io_getf_fb       (uint8_t *src_ptr);
00119 float   buf_io_getf_fl_apr   (uint8_t **src_ptr);
00120 float   buf_io_getf_fb_apr   (uint8_t **src_ptr);
00121 #define buf_io_getf_fl_ap(x) buf_io_getf_fl_apr(&x)
00122 #define buf_io_getf_fb_ap(x) buf_io_getf_fb_apr(&x)
00123 
00124 double  buf_io_getd_fl       (uint8_t *src_ptr);
00125 double  buf_io_getd_fb       (uint8_t *src_ptr);
00126 double  buf_io_getd_fl_apr   (uint8_t **src_ptr);
00127 double  buf_io_getd_fb_apr   (uint8_t **src_ptr);
00128 #define buf_io_getd_fl_ap(x) buf_io_getd_fl_apr(&x)
00129 #define buf_io_getd_fb_ap(x) buf_io_getd_fb_apr(&x)
00130 /** @} */
00131 
00132 /** 
00133   @name endianess dependent functions (PUT)
00134   @{
00135 */
00136 void    buf_io_put8_tl         (uint8_t value, uint8_t  *buf);
00137 void    buf_io_put8_tb         (uint8_t value, uint8_t  *buf);
00138 void    buf_io_put8_tl_apr     (uint8_t value, uint8_t **buf);
00139 void    buf_io_put8_tb_apr     (uint8_t value, uint8_t **buf);
00140 #define buf_io_put8_tl_ap(v,x) buf_io_put8_tl_apr(v,&x) 
00141 #define buf_io_put8_tb_ap(v,x) buf_io_put8_tb_apr(v,&x) 
00142 
00143 void    buf_io_put16_tl         (uint16_t value, uint8_t  *buf);
00144 void    buf_io_put16_tb         (uint16_t value, uint8_t  *buf);
00145 void    buf_io_put16_tl_apr     (uint16_t value, uint8_t **buf);
00146 void    buf_io_put16_tb_apr     (uint16_t value, uint8_t **buf);
00147 #define buf_io_put16_tl_ap(v,x) buf_io_put16_tl_apr(v,&x) 
00148 #define buf_io_put16_tb_ap(v,x) buf_io_put16_tb_apr(v,&x) 
00149 
00150 void    buf_io_put32_tl         (uint32_t value, uint8_t  *buf);
00151 void    buf_io_put32_tb         (uint32_t value, uint8_t  *buf);
00152 void    buf_io_put32_tl_apr     (uint32_t value, uint8_t **buf);
00153 void    buf_io_put32_tb_apr     (uint32_t value, uint8_t **buf);
00154 #define buf_io_put32_tl_ap(v,x) buf_io_put32_tl_apr(v,&x) 
00155 #define buf_io_put32_tb_ap(v,x) buf_io_put32_tb_apr(v,&x) 
00156 
00157 void    buf_io_put64_tl         (uint64_t value, uint8_t  *buf);
00158 void    buf_io_put64_tb         (uint64_t value, uint8_t  *buf);
00159 void    buf_io_put64_tl_apr     (uint64_t value, uint8_t **buf);
00160 void    buf_io_put64_tb_apr     (uint64_t value, uint8_t **buf);
00161 #define buf_io_put64_tl_ap(v,x) buf_io_put64_tl_apr(v,&x) 
00162 #define buf_io_put64_tb_ap(v,x) buf_io_put64_tb_apr(v,&x) 
00163 
00164 void    buf_io_putf_tl          (float value, uint8_t *buf); 
00165 void    buf_io_putf_tb          (float value, uint8_t *buf); 
00166 void    buf_io_putf_tl_apr      (float value, uint8_t **buf); 
00167 void    buf_io_putf_tb_apr      (float value, uint8_t **buf); 
00168 #define buf_io_putf_tl_ap(v, x) buf_io_putf_tl_apr(v, &x) 
00169 #define buf_io_putf_tb_ap(v, x) buf_io_putf_tb_apr(v, &x) 
00170 
00171 void    buf_io_putd_tl          (double value, uint8_t *buf); 
00172 void    buf_io_putd_tb          (double value, uint8_t *buf); 
00173 void    buf_io_putd_tl_apr      (double value, uint8_t **buf); 
00174 void    buf_io_putd_tb_apr      (double value, uint8_t **buf); 
00175 #define buf_io_putd_tl_ap(v, x) buf_io_putd_tl_apr(v, &x) 
00176 #define buf_io_putd_tb_ap(v, x) buf_io_putd_tb_apr(v, &x) 
00177 /** @} */
00178 
00179 #ifdef __cplusplus
00180 }
00181 #endif
00182 
00183 #endif /* __BUF_IO__ */