Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:12

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief RTEMS File System Data
0007  *
0008  * @ingroup rtems_rfs
0009  *
0010  * RTEMS File System Data.
0011  *
0012  * Access data in the correct byte order for the specific target we are running
0013  * on.
0014  *
0015  * @todo Make direct access on matching byte ordered targets.
0016  */
0017 
0018 /*
0019  *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
0020  *
0021  * Redistribution and use in source and binary forms, with or without
0022  * modification, are permitted provided that the following conditions
0023  * are met:
0024  * 1. Redistributions of source code must retain the above copyright
0025  *    notice, this list of conditions and the following disclaimer.
0026  * 2. Redistributions in binary form must reproduce the above copyright
0027  *    notice, this list of conditions and the following disclaimer in the
0028  *    documentation and/or other materials provided with the distribution.
0029  *
0030  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0031  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0032  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0033  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0034  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0035  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0036  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0037  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0038  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0039  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0040  * POSSIBILITY OF SUCH DAMAGE.
0041  */
0042 
0043 
0044 #if !defined (_RTEMS_RFS_DATA_H_)
0045 #define _RTEMS_RFS_DATA_H_
0046 
0047 #include <stdint.h>
0048 
0049 /**
0050  * Helper function to make sure we have a byte pointer.
0051  */
0052 #define rtems_rfs_data_ptr(_d) ((uint8_t*)(_d))
0053 
0054 /**
0055  * Helper function to get the data shifted in the correctly sized type.
0056  */
0057 #define rtems_rfs_data_get(_d, _t, _o, _s) \
0058   (((_t)(rtems_rfs_data_ptr (_d)[_o])) << (_s))
0059 
0060 /**
0061  * RFS Read Unsigned 8bit Integer
0062  */
0063 #define rtems_rfs_read_u8(_d) \
0064   (*rtems_rfs_data_ptr (_d))
0065 
0066 /**
0067  * RFS Read Unsigned 16bit Integer
0068  */
0069 #define rtems_rfs_read_u16(_d) \
0070   (rtems_rfs_data_get (_d, uint16_t, 0, 8) | \
0071    rtems_rfs_data_get (_d, uint16_t, 1, 0))
0072 
0073 /**
0074  * RFS Read Unsigned 32bit Integer
0075  */
0076 #define rtems_rfs_read_u32(_d) \
0077   (rtems_rfs_data_get (_d, uint32_t, 0, 24) | \
0078    rtems_rfs_data_get (_d, uint32_t, 1, 16) | \
0079    rtems_rfs_data_get (_d, uint32_t, 2, 8) | \
0080    rtems_rfs_data_get (_d, uint32_t, 3, 0))
0081 
0082 /**
0083  * RFS Write Unsigned 8bit Integer
0084  */
0085 #define rtems_rfs_write_u8(_d, _v) \
0086   (*rtems_rfs_data_ptr (_d) = (uint8_t)(_v))
0087 
0088 /**
0089  * RFS Write Unsigned 16bit Integer
0090  */
0091 #define rtems_rfs_write_u16(_d, _v) \
0092   do { \
0093     rtems_rfs_data_ptr (_d)[0] = (uint8_t)(((uint16_t)(_v)) >> 8); \
0094     rtems_rfs_data_ptr (_d)[1] = (uint8_t)((_v)); \
0095   } while (0)
0096 
0097 /**
0098  * RFS Write Unsigned 32bit Integer
0099  */
0100 #define rtems_rfs_write_u32(_d, _v) \
0101   do { \
0102     rtems_rfs_data_ptr (_d)[0] = (uint8_t)(((uint32_t)(_v)) >> 24); \
0103     rtems_rfs_data_ptr (_d)[1] = (uint8_t)(((uint32_t)(_v)) >> 16); \
0104     rtems_rfs_data_ptr (_d)[2] = (uint8_t)(((uint32_t)(_v)) >> 8);  \
0105     rtems_rfs_data_ptr (_d)[3] = (uint8_t)((uint32_t)(_v)); \
0106   } while (0)
0107 
0108 #endif