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
util/buf_io.h@1:acdf490d94a7, 2014-04-08 (annotated)
- Committer:
- marcelobarrosalmeida
- Date:
- Tue Apr 08 16:34:20 2014 +0000
- Revision:
- 1:acdf490d94a7
Adding accel to sensor list
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcelobarrosalmeida | 1:acdf490d94a7 | 1 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 2 | @file buf_io.c |
marcelobarrosalmeida | 1:acdf490d94a7 | 3 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 4 | Several functions for handling data in buffers. |
marcelobarrosalmeida | 1:acdf490d94a7 | 5 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 6 | Basic functions: |
marcelobarrosalmeida | 1:acdf490d94a7 | 7 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 8 | buf_io_[get|put][8|16|32|64|f|d]_[f|t][b|l]_ap[r] |
marcelobarrosalmeida | 1:acdf490d94a7 | 9 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 10 | Notation: |
marcelobarrosalmeida | 1:acdf490d94a7 | 11 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 12 | 8|16|32|64|f|d = data size (f for float, d for double) |
marcelobarrosalmeida | 1:acdf490d94a7 | 13 | [f|t][b|l] = from/to big/little |
marcelobarrosalmeida | 1:acdf490d94a7 | 14 | ap[r] = add pointer [reference] at the end |
marcelobarrosalmeida | 1:acdf490d94a7 | 15 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 16 | Check buf_io.c for a proper implementation of these functions for your platform. |
marcelobarrosalmeida | 1:acdf490d94a7 | 17 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 18 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 19 | #ifndef __BUF_IO__ |
marcelobarrosalmeida | 1:acdf490d94a7 | 20 | #define __BUF_IO__ |
marcelobarrosalmeida | 1:acdf490d94a7 | 21 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 22 | #ifdef __cplusplus |
marcelobarrosalmeida | 1:acdf490d94a7 | 23 | extern "C" { |
marcelobarrosalmeida | 1:acdf490d94a7 | 24 | #endif |
marcelobarrosalmeida | 1:acdf490d94a7 | 25 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 26 | /** Pointer size */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 27 | #define POINTER_SIZE (sizeof(void *)) |
marcelobarrosalmeida | 1:acdf490d94a7 | 28 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 29 | /** Number of elements in a array */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 30 | #define NUM_OF_ELEMENTS_IN_ARRAY(a) (sizeof(a)/sizeof(a[0])) |
marcelobarrosalmeida | 1:acdf490d94a7 | 31 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 32 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 33 | @name next/prev macro functions |
marcelobarrosalmeida | 1:acdf490d94a7 | 34 | Next/previous aligned address, avoiding data aborts in buffer operations. |
marcelobarrosalmeida | 1:acdf490d94a7 | 35 | @{ |
marcelobarrosalmeida | 1:acdf490d94a7 | 36 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 37 | #define __next_aligned_addr32(x) (((x) + 0x03) & 0xFFFFFFFC) |
marcelobarrosalmeida | 1:acdf490d94a7 | 38 | #define __next_aligned_addr16(x) (((x) + 0x01) & 0xFFFFFFFE) |
marcelobarrosalmeida | 1:acdf490d94a7 | 39 | #define __prev_aligned_addr32(x) ((x) & 0xFFFFFFFC) |
marcelobarrosalmeida | 1:acdf490d94a7 | 40 | #define __prev_aligned_addr16(x) ((x) & 0xFFFFFFFE) |
marcelobarrosalmeida | 1:acdf490d94a7 | 41 | /** @} */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 42 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 43 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 44 | @name swap functions |
marcelobarrosalmeida | 1:acdf490d94a7 | 45 | Swap operations. |
marcelobarrosalmeida | 1:acdf490d94a7 | 46 | @{ |
marcelobarrosalmeida | 1:acdf490d94a7 | 47 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 48 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 49 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 50 | Swaps a 16 bits unsigned integer. |
marcelobarrosalmeida | 1:acdf490d94a7 | 51 | @param ucShort 16 bits unsigned integer to be swapped |
marcelobarrosalmeida | 1:acdf490d94a7 | 52 | @return 16 bits unsigned integer swapped |
marcelobarrosalmeida | 1:acdf490d94a7 | 53 | @{ |
marcelobarrosalmeida | 1:acdf490d94a7 | 54 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 55 | uint16_t buf_io_swap16 (uint16_t usShort); |
marcelobarrosalmeida | 1:acdf490d94a7 | 56 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 57 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 58 | Swaps a 32 bits unsigned integer. |
marcelobarrosalmeida | 1:acdf490d94a7 | 59 | @param ulLong 32 bits unsigned integer to be swapped |
marcelobarrosalmeida | 1:acdf490d94a7 | 60 | @return 32 bits unsigned integer swapped |
marcelobarrosalmeida | 1:acdf490d94a7 | 61 | @{ |
marcelobarrosalmeida | 1:acdf490d94a7 | 62 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 63 | uint32_t buf_io_swap32 (uint32_t ulLong); |
marcelobarrosalmeida | 1:acdf490d94a7 | 64 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 65 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 66 | Swaps a 16 bits unsigned integer inside a buffer. |
marcelobarrosalmeida | 1:acdf490d94a7 | 67 | @param pucPtr Pointer where 16 bits unsigned integer is stored. |
marcelobarrosalmeida | 1:acdf490d94a7 | 68 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 69 | void buf_io_swap16p(uint8_t *pucPtr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 70 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 71 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 72 | Swaps a 32 bits unsigned integer inside a buffer. |
marcelobarrosalmeida | 1:acdf490d94a7 | 73 | @param pucPtr Pointer where 32 bits unsigned integer is stored. |
marcelobarrosalmeida | 1:acdf490d94a7 | 74 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 75 | void buf_io_swap32p(uint8_t *pucPtr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 76 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 77 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 78 | Swaps 8 bits unsigned integer in a byte. |
marcelobarrosalmeida | 1:acdf490d94a7 | 79 | @param ucChar 8 bits unsigned integer to be bit swapped |
marcelobarrosalmeida | 1:acdf490d94a7 | 80 | @return 8 bits unsigned integer swapped |
marcelobarrosalmeida | 1:acdf490d94a7 | 81 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 82 | uint8_t buf_io_swap8b (uint8_t ucChar); |
marcelobarrosalmeida | 1:acdf490d94a7 | 83 | /** @} */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 84 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 85 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 86 | @name endianess dependent functions (GET) |
marcelobarrosalmeida | 1:acdf490d94a7 | 87 | @{ |
marcelobarrosalmeida | 1:acdf490d94a7 | 88 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 89 | uint8_t buf_io_get8_fl (uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 90 | uint8_t buf_io_get8_fb (uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 91 | uint8_t buf_io_get8_fl_apr (uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 92 | uint8_t buf_io_get8_fb_apr (uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 93 | #define buf_io_get8_fl_ap(x) buf_io_get8_fl_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 94 | #define buf_io_get8_fb_ap(x) buf_io_get8_fb_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 95 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 96 | uint16_t buf_io_get16_fl (uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 97 | uint16_t buf_io_get16_fb (uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 98 | uint16_t buf_io_get16_fl_apr (uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 99 | uint16_t buf_io_get16_fb_apr (uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 100 | #define buf_io_get16_fl_ap(x) buf_io_get16_fl_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 101 | #define buf_io_get16_fb_ap(x) buf_io_get16_fb_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 102 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 103 | uint32_t buf_io_get32_fl (uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 104 | uint32_t buf_io_get32_fb (uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 105 | uint32_t buf_io_get32_fl_apr (uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 106 | uint32_t buf_io_get32_fb_apr (uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 107 | #define buf_io_get32_fl_ap(x) buf_io_get32_fl_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 108 | #define buf_io_get32_fb_ap(x) buf_io_get32_fb_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 109 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 110 | uint64_t buf_io_get64_fl (uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 111 | uint64_t buf_io_get64_fb (uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 112 | uint64_t buf_io_get64_fl_apr (uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 113 | uint64_t buf_io_get64_fb_apr (uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 114 | #define buf_io_get64_fl_ap(x) buf_io_get64_fl_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 115 | #define buf_io_get64_fb_ap(x) buf_io_get64_fb_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 116 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 117 | float buf_io_getf_fl (uint8_t *src_ptr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 118 | float buf_io_getf_fb (uint8_t *src_ptr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 119 | float buf_io_getf_fl_apr (uint8_t **src_ptr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 120 | float buf_io_getf_fb_apr (uint8_t **src_ptr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 121 | #define buf_io_getf_fl_ap(x) buf_io_getf_fl_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 122 | #define buf_io_getf_fb_ap(x) buf_io_getf_fb_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 123 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 124 | double buf_io_getd_fl (uint8_t *src_ptr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 125 | double buf_io_getd_fb (uint8_t *src_ptr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 126 | double buf_io_getd_fl_apr (uint8_t **src_ptr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 127 | double buf_io_getd_fb_apr (uint8_t **src_ptr); |
marcelobarrosalmeida | 1:acdf490d94a7 | 128 | #define buf_io_getd_fl_ap(x) buf_io_getd_fl_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 129 | #define buf_io_getd_fb_ap(x) buf_io_getd_fb_apr(&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 130 | /** @} */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 131 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 132 | /** |
marcelobarrosalmeida | 1:acdf490d94a7 | 133 | @name endianess dependent functions (PUT) |
marcelobarrosalmeida | 1:acdf490d94a7 | 134 | @{ |
marcelobarrosalmeida | 1:acdf490d94a7 | 135 | */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 136 | void buf_io_put8_tl (uint8_t value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 137 | void buf_io_put8_tb (uint8_t value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 138 | void buf_io_put8_tl_apr (uint8_t value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 139 | void buf_io_put8_tb_apr (uint8_t value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 140 | #define buf_io_put8_tl_ap(v,x) buf_io_put8_tl_apr(v,&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 141 | #define buf_io_put8_tb_ap(v,x) buf_io_put8_tb_apr(v,&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 142 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 143 | void buf_io_put16_tl (uint16_t value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 144 | void buf_io_put16_tb (uint16_t value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 145 | void buf_io_put16_tl_apr (uint16_t value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 146 | void buf_io_put16_tb_apr (uint16_t value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 147 | #define buf_io_put16_tl_ap(v,x) buf_io_put16_tl_apr(v,&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 148 | #define buf_io_put16_tb_ap(v,x) buf_io_put16_tb_apr(v,&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 149 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 150 | void buf_io_put32_tl (uint32_t value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 151 | void buf_io_put32_tb (uint32_t value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 152 | void buf_io_put32_tl_apr (uint32_t value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 153 | void buf_io_put32_tb_apr (uint32_t value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 154 | #define buf_io_put32_tl_ap(v,x) buf_io_put32_tl_apr(v,&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 155 | #define buf_io_put32_tb_ap(v,x) buf_io_put32_tb_apr(v,&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 156 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 157 | void buf_io_put64_tl (uint64_t value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 158 | void buf_io_put64_tb (uint64_t value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 159 | void buf_io_put64_tl_apr (uint64_t value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 160 | void buf_io_put64_tb_apr (uint64_t value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 161 | #define buf_io_put64_tl_ap(v,x) buf_io_put64_tl_apr(v,&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 162 | #define buf_io_put64_tb_ap(v,x) buf_io_put64_tb_apr(v,&x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 163 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 164 | void buf_io_putf_tl (float value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 165 | void buf_io_putf_tb (float value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 166 | void buf_io_putf_tl_apr (float value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 167 | void buf_io_putf_tb_apr (float value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 168 | #define buf_io_putf_tl_ap(v, x) buf_io_putf_tl_apr(v, &x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 169 | #define buf_io_putf_tb_ap(v, x) buf_io_putf_tb_apr(v, &x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 170 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 171 | void buf_io_putd_tl (double value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 172 | void buf_io_putd_tb (double value, uint8_t *buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 173 | void buf_io_putd_tl_apr (double value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 174 | void buf_io_putd_tb_apr (double value, uint8_t **buf); |
marcelobarrosalmeida | 1:acdf490d94a7 | 175 | #define buf_io_putd_tl_ap(v, x) buf_io_putd_tl_apr(v, &x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 176 | #define buf_io_putd_tb_ap(v, x) buf_io_putd_tb_apr(v, &x) |
marcelobarrosalmeida | 1:acdf490d94a7 | 177 | /** @} */ |
marcelobarrosalmeida | 1:acdf490d94a7 | 178 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 179 | #ifdef __cplusplus |
marcelobarrosalmeida | 1:acdf490d94a7 | 180 | } |
marcelobarrosalmeida | 1:acdf490d94a7 | 181 | #endif |
marcelobarrosalmeida | 1:acdf490d94a7 | 182 | |
marcelobarrosalmeida | 1:acdf490d94a7 | 183 | #endif /* __BUF_IO__ */ |