[a9fa9b7] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org> |
---|
| 3 | * |
---|
| 4 | * The license and distribution terms for this file may be |
---|
| 5 | * found in the file LICENSE in this distribution or at |
---|
| 6 | * http://www.rtems.com/license/LICENSE. |
---|
| 7 | * |
---|
| 8 | * $Id$ |
---|
| 9 | */ |
---|
| 10 | /** |
---|
| 11 | * @file |
---|
| 12 | * |
---|
| 13 | * @ingroup rtems-rfs |
---|
| 14 | * |
---|
| 15 | * RTEMS File System Data. |
---|
| 16 | * |
---|
| 17 | * Access data in the correct byte order for the specific target we are running |
---|
| 18 | * on. |
---|
| 19 | * |
---|
| 20 | * @todo Make direct access on matching byte ordered targets. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #if !defined (_RTEMS_RFS_DATA_H_) |
---|
| 24 | #define _RTEMS_RFS_DATA_H_ |
---|
| 25 | |
---|
| 26 | #include <stdint.h> |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * Helper function to make sure we have a byte pointer. |
---|
| 30 | */ |
---|
| 31 | #define rtems_rfs_data_ptr(_d) ((uint8_t*)(_d)) |
---|
| 32 | |
---|
[1d539c0] | 33 | /** |
---|
| 34 | * Helper function to get the data shifted in the correctly sized type. |
---|
| 35 | */ |
---|
| 36 | #define rtems_rfs_data_get(_d, _t, _o, _s) \ |
---|
| 37 | (((_t)(rtems_rfs_data_ptr (_d)[_o])) << (_s)) |
---|
| 38 | |
---|
[a9fa9b7] | 39 | /** |
---|
| 40 | * RFS Read Unsigned 8bit Integer |
---|
| 41 | */ |
---|
| 42 | #define rtems_rfs_read_u8(_d) \ |
---|
| 43 | (*rtems_rfs_data_ptr (_d)) |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * RFS Read Unsigned 16bit Integer |
---|
| 47 | */ |
---|
| 48 | #define rtems_rfs_read_u16(_d) \ |
---|
[1d539c0] | 49 | (rtems_rfs_data_get (_d, uint16_t, 0, 8) | \ |
---|
| 50 | rtems_rfs_data_get (_d, uint16_t, 1, 0)) |
---|
[a9fa9b7] | 51 | |
---|
| 52 | /** |
---|
| 53 | * RFS Read Unsigned 32bit Integer |
---|
| 54 | */ |
---|
| 55 | #define rtems_rfs_read_u32(_d) \ |
---|
[1d539c0] | 56 | (rtems_rfs_data_get (_d, uint32_t, 0, 24) | \ |
---|
| 57 | rtems_rfs_data_get (_d, uint32_t, 1, 16) | \ |
---|
| 58 | rtems_rfs_data_get (_d, uint32_t, 2, 8) | \ |
---|
| 59 | rtems_rfs_data_get (_d, uint32_t, 3, 0)) |
---|
[a9fa9b7] | 60 | |
---|
| 61 | /** |
---|
| 62 | * RFS Write Unsigned 8bit Integer |
---|
| 63 | */ |
---|
| 64 | #define rtems_rfs_write_u8(_d, _v) \ |
---|
| 65 | (*rtems_rfs_data_ptr (_d) = (uint8_t)(_v)) |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * RFS Write Unsigned 16bit Integer |
---|
| 69 | */ |
---|
| 70 | #define rtems_rfs_write_u16(_d, _v) \ |
---|
| 71 | do { \ |
---|
[1d539c0] | 72 | rtems_rfs_data_ptr (_d)[0] = (uint8_t)(((uint16_t)(_v)) >> 8); \ |
---|
[a9fa9b7] | 73 | rtems_rfs_data_ptr (_d)[1] = (uint8_t)((_v)); \ |
---|
| 74 | } while (0) |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | * RFS Write Unsigned 32bit Integer |
---|
| 78 | */ |
---|
| 79 | #define rtems_rfs_write_u32(_d, _v) \ |
---|
| 80 | do { \ |
---|
[1d539c0] | 81 | rtems_rfs_data_ptr (_d)[0] = (uint8_t)(((uint32_t)(_v)) >> 24); \ |
---|
| 82 | rtems_rfs_data_ptr (_d)[1] = (uint8_t)(((uint32_t)(_v)) >> 16); \ |
---|
| 83 | rtems_rfs_data_ptr (_d)[2] = (uint8_t)(((uint32_t)(_v)) >> 8); \ |
---|
| 84 | rtems_rfs_data_ptr (_d)[3] = (uint8_t)((uint32_t)(_v)); \ |
---|
[a9fa9b7] | 85 | } while (0) |
---|
| 86 | |
---|
| 87 | #endif |
---|