Graphics framework for GR-PEACH. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Dependents:   ImageZoomInout_Sample ImageRotaion_Sample ImageScroll_Sample GR-PEACH_LCD_4_3inch_Save_to_USB ... more

License

When you use this library, we judge you have agreed to the following contents.

https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Note

If you import the GraphicsFramework library, please import GR-PEACH_video library and R_BSP library together.



JPEG Converter

The JPEG Converter driver implements encode and decode functionality which uses the JCU of the RZ/A Series.

Hello World!

Import programJCU_HelloWorld

Hello World for JCU(JPEG Codec Unit). JCU is JPEG codec unit of RZ/A1. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

API

Import library

Data Structures

struct bitmap_buff_info_t
Bitmap data setting struct. More...
struct encode_options_t
Encode option setting. More...

Public Types

enum jpeg_conv_error_t {
JPEG_CONV_OK = 0, JPEG_CONV_JCU_ERR = -1, JPEG_CONV_FORMA_ERR = -2, JPEG_CONV_PARAM_ERR = -3,
JPEG_CONV_BUSY = -4, JPEG_CONV_PARAM_RANGE_ERR = -7
}

Error codes.

More...
enum wr_rd_swa_t {
WR_RD_WRSWA_NON = 0, WR_RD_WRSWA_8BIT = 1, WR_RD_WRSWA_16BIT = 2, WR_RD_WRSWA_16_8BIT = 3,
WR_RD_WRSWA_32BIT = 4, WR_RD_WRSWA_32_8BIT = 5, WR_RD_WRSWA_32_16BIT = 6, WR_RD_WRSWA_32_16_8BIT = 7
}

Write/Read image pixcel frame buffer swap setting.

More...
enum wr_rd_format_t { WR_RD_YCbCr422 = 0x00, WR_RD_ARGB8888 = 0x01, WR_RD_RGB565 = 0x02 }

Write/Read image pixcel format selects.

More...
enum sub_sampling_t { SUB_SAMPLING_1_1 = 0x00, SUB_SAMPLING_1_2 = 0x01, SUB_SAMPLING_1_4 = 0x02, SUB_SAMPLING_1_8 = 0x03 }

Thinning output image selects.

More...
enum cbcr_offset_t { CBCR_OFFSET_0 = 0x00, CBCR_OFFSET_128 = 0x01 }

Cb/Cr range selects for decode.

More...

Public Member Functions

JPEG_Converter ()
Constructor method of JPEG converter(encode/decode)
virtual ~JPEG_Converter ()
Destructor method of JPEG converter(encode/decode)
JPEG_Converter::jpeg_conv_error_t decode (void *pJpegBuff, bitmap_buff_info_t *psOutputBuff)
Decode JPEG to rinear data.
JPEG_Converter::jpeg_conv_error_t decode (void *pJpegBuff, bitmap_buff_info_t *psOutputBuff, decode_options_t *pOptions)
JPEG data decode to bitmap.
JPEG_Converter::jpeg_conv_error_t encode ( bitmap_buff_info_t *psInputBuff, void *pJpegBuff, size_t *pEncodeSize)
Encode rinear data to JPEG.
JPEG_Converter::jpeg_conv_error_t encode ( bitmap_buff_info_t *psInputBuff, void *pJpegBuff, size_t *pEncodeSize, encode_options_t *pOptions)
Bitmap data encode to JPEG.
JPEG_Converter::jpeg_conv_error_t SetQuality (const uint8_t qual)
Set encode quality.

Correspondence file

A correspondence file of JPEG Converter is as the following table.

JPEGCorrespondence
Width>0(greater than 0)
Height>0(greater than 0)
Color formatYCbCr444, YCbCr422, YCbCr420, YCbCr411
BitmapCorrespondence
Width>0(greater than 0)
Height>0(greater than 0)
Color formatYCbCr422

Notice

You run JPEG converter once destruction each time.

You set whether these JPEG files aren't input, or it check error setting decode(set in "flag" = true). The JPEG file which becomes correspondence outside will be the following condition.

  • File besides the above-mentioned correspondence file.
  • As information in the JPEG file, WIDTH or HEIGHT is larger than output buffer setting.

Buffer area is used encode/decode, set 8 bytes align and non-cash memory area. The output buffer when decoding, is made beyond the size decided in the size of the JPEG file, the format, setting of thinning out. You make output buffer for decode/encode to enough big size in order to stock this result. JPEG Converter, if you do not particularly perform specified, does not check size against the output data at the time of encoding and decoding. You set the output buffer so that there is no effect of corruption by the output data.

Color format

Color format in case to be converted from Bitmap to JPEG is either ARGB8888 or RGB555, YCbCr422. Color format of the If you want to convert from JPEG file to Bitmap file is YCbCr422. You correct "alpha(member of decode_options_t)" of setting and "output_cb_cr_offset(member of decode_options_t)" according to color format when decoding.

  • example
    decode to ARGB8888(WR_RD_ARGB8888 set in format member of bitmap_buff_info_t)
    alpha = 0x01-0xFF
    output_cb_cr_offset = CBCR_OFFSET_0

    decode to YCbCr422(WR_RD_YCbCr422 set in format member of bitmap_buff_info_t)
    alpha = 0
    output_cb_cr_offset = CBCR_OFFSET_0 or CBCR_OFFSET_128

    decode to RGB565(WR_RD_RGB565 set in format member of bitmap_buff_info_t)
    alpha = 0
    output_cb_cr_offset = CBCR_OFFSET_0

Decode/encode settings are optional

If omitted encode/decode settings, it will work with the following settings.
[Decode option setting (member of decode_options_t)]

  • Vertical sub sampling is thinning output image to 1/1.
  • Horizontal sub sampling is thinning output image to 1/1.
  • Output data of Cb/Cr range is -128 to 127.
  • Output data of swap in 8-bit units: 2-1-4-3-6-5-8-7.
  • Alpha value of 0.
  • JPEG format correspondence outside error check.
  • It decode in a synchronous function.

[Encode option setting (member of encode_options_t)]

  • DRI value is 0.
  • Encoding JPEG file start width offset is 0.
  • Encoding JPEG file start height offset is 0.
  • Input data of Cb/Cr range of input data is -128 to 127.
  • Input data swap in 8-bit units: 2-1-4-3-6-5-8-7.
  • It don't check encode size.
  • Quantization Y use default table(Quality75).
  • Quantization C use default table(Quality75).
  • Huffman Y DC use default table.
  • Huffman C DC use default table.
  • Huffman Y AC use default table.
  • Huffman C AC use default table.
  • It encode in a synchronous function.

Synchronous/asynchronous switching

Decoding and encoding setting to operate asynchronously by setting a callback function(decode_options_t and encode_options_t).

Quality

Quality changes are possible. If you want to change the Quality, please specify the table made of Quality you want to change the address of the setting. If you do not want to change the Quality, it will operate at Quality75.

RGA

The RGA library implements fast drawing functionality which uses the RGA of the RZ/A Series.
Supporting compiler is ARMCC, GCC ARM and IAR.

Hello World!

Import programRGA_HelloWorld

Hello World for RGA(Renesas Graphics Architecture). RGA is the Graphics Library of RZ/A1. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Committer:
dkato
Date:
Mon Apr 24 08:16:23 2017 +0000
Revision:
13:1ee2176ef13f
Parent:
3:9f857750e4e9
Add "SetQuality()" to JCU.
; Bug fixes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:37e1e6a45ced 1 /*******************************************************************************
dkato 0:37e1e6a45ced 2 * DISCLAIMER
dkato 0:37e1e6a45ced 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:37e1e6a45ced 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:37e1e6a45ced 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:37e1e6a45ced 6 * all applicable laws, including copyright laws.
dkato 0:37e1e6a45ced 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:37e1e6a45ced 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:37e1e6a45ced 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:37e1e6a45ced 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:37e1e6a45ced 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:37e1e6a45ced 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:37e1e6a45ced 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:37e1e6a45ced 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:37e1e6a45ced 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:37e1e6a45ced 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:37e1e6a45ced 17 * and to discontinue the availability of this software. By using this software,
dkato 0:37e1e6a45ced 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:37e1e6a45ced 19 * following link:
dkato 0:37e1e6a45ced 20 * http://www.renesas.com/disclaimer
dkato 0:37e1e6a45ced 21 * Copyright (C) 2012 - 2015 Renesas Electronics Corporation. All rights reserved.
dkato 0:37e1e6a45ced 22 *******************************************************************************/
dkato 0:37e1e6a45ced 23 /**
dkato 0:37e1e6a45ced 24 * @file r_ospl.h
dkato 0:37e1e6a45ced 25 * @brief OS Porting Layer. Main Header. Functions.
dkato 0:37e1e6a45ced 26 *
dkato 0:37e1e6a45ced 27 * $Module: OSPL $ $PublicVersion: 0.90 $ (=R_OSPL_VERSION)
dkato 0:37e1e6a45ced 28 * $Rev: 35 $
dkato 0:37e1e6a45ced 29 * $Date:: 2014-04-15 21:38:18 +0900#$
dkato 0:37e1e6a45ced 30 */
dkato 0:37e1e6a45ced 31
dkato 0:37e1e6a45ced 32 #ifndef R_OSPL_H
dkato 0:37e1e6a45ced 33 #define R_OSPL_H
dkato 0:37e1e6a45ced 34
dkato 0:37e1e6a45ced 35
dkato 0:37e1e6a45ced 36 /******************************************************************************
dkato 0:37e1e6a45ced 37 Includes <System Includes> , "Project Includes"
dkato 0:37e1e6a45ced 38 ******************************************************************************/
dkato 0:37e1e6a45ced 39 #include "Project_Config.h"
dkato 0:37e1e6a45ced 40 #include "platform.h"
dkato 0:37e1e6a45ced 41 #include "r_ospl_typedef.h"
dkato 0:37e1e6a45ced 42 #include "r_multi_compiler_typedef.h"
dkato 0:37e1e6a45ced 43 #include "locking.h"
dkato 0:37e1e6a45ced 44 #include "r_static_an_tag.h"
dkato 0:37e1e6a45ced 45 #include "r_ospl_debug.h"
dkato 0:37e1e6a45ced 46 #if ! R_OSPL_IS_PREEMPTION
dkato 0:37e1e6a45ced 47 #include "r_ospl_os_less.h"
dkato 0:37e1e6a45ced 48 #endif
dkato 0:37e1e6a45ced 49
dkato 0:37e1e6a45ced 50 #ifdef __cplusplus
dkato 0:37e1e6a45ced 51 extern "C" {
dkato 0:37e1e6a45ced 52 #endif /* __cplusplus */
dkato 0:37e1e6a45ced 53
dkato 0:37e1e6a45ced 54
dkato 0:37e1e6a45ced 55 /******************************************************************************
dkato 0:37e1e6a45ced 56 Typedef definitions
dkato 0:37e1e6a45ced 57 ******************************************************************************/
dkato 0:37e1e6a45ced 58 /* In "r_ospl_typedef.h" */
dkato 0:37e1e6a45ced 59
dkato 0:37e1e6a45ced 60 /******************************************************************************
dkato 0:37e1e6a45ced 61 Macro definitions
dkato 0:37e1e6a45ced 62 ******************************************************************************/
dkato 0:37e1e6a45ced 63 /* In "r_ospl_typedef.h" */
dkato 0:37e1e6a45ced 64
dkato 0:37e1e6a45ced 65 /******************************************************************************
dkato 0:37e1e6a45ced 66 Variable Externs
dkato 0:37e1e6a45ced 67 ******************************************************************************/
dkato 0:37e1e6a45ced 68 /* In "r_ospl_typedef.h" */
dkato 0:37e1e6a45ced 69
dkato 0:37e1e6a45ced 70 /******************************************************************************
dkato 0:37e1e6a45ced 71 Functions Prototypes
dkato 0:37e1e6a45ced 72 ******************************************************************************/
dkato 0:37e1e6a45ced 73
dkato 0:37e1e6a45ced 74
dkato 0:37e1e6a45ced 75 /* Section: Version and initialize */
dkato 0:37e1e6a45ced 76 /**
dkato 0:37e1e6a45ced 77 * @brief Returns version number of OSPL
dkato 0:37e1e6a45ced 78 *
dkato 0:37e1e6a45ced 79 * @par Parameters
dkato 0:37e1e6a45ced 80 * None
dkato 0:37e1e6a45ced 81 * @return Version number of OSPL
dkato 0:37e1e6a45ced 82 *
dkato 0:37e1e6a45ced 83 * @par Description
dkato 0:37e1e6a45ced 84 * Return value is same as "R_OSPL_VERSION" macro.
dkato 0:37e1e6a45ced 85 */
dkato 0:37e1e6a45ced 86 int32_t R_OSPL_GetVersion(void);
dkato 0:37e1e6a45ced 87
dkato 0:37e1e6a45ced 88
dkato 0:37e1e6a45ced 89 /**
dkato 0:37e1e6a45ced 90 * @brief Returns whether the environment is supported preemption
dkato 0:37e1e6a45ced 91 *
dkato 0:37e1e6a45ced 92 * @par Parameters
dkato 0:37e1e6a45ced 93 * None
dkato 0:37e1e6a45ced 94 * @return Whether the environment is RTOS supported preemption
dkato 0:37e1e6a45ced 95 *
dkato 0:37e1e6a45ced 96 * @par Description
dkato 0:37e1e6a45ced 97 * Return value is same as "R_OSPL_IS_PREEMPTION" macro.
dkato 0:37e1e6a45ced 98 */
dkato 0:37e1e6a45ced 99 bool_t R_OSPL_IsPreemption(void);
dkato 0:37e1e6a45ced 100
dkato 0:37e1e6a45ced 101
dkato 0:37e1e6a45ced 102 /**
dkato 0:37e1e6a45ced 103 * @brief Initializes the internal of OSPL
dkato 0:37e1e6a45ced 104 *
dkato 0:37e1e6a45ced 105 * @param NullConfig Specify NULL
dkato 0:37e1e6a45ced 106 * @return None
dkato 0:37e1e6a45ced 107 *
dkato 0:37e1e6a45ced 108 * @par Description
dkato 0:37e1e6a45ced 109 * Initializes internal mutual exclusion objects.
dkato 0:37e1e6a45ced 110 * However, "R_OSPL_Initialize" function does not have to be called for
dkato 0:37e1e6a45ced 111 * OSPL of "R_OSPL_IS_PREEMPTION = 0".
dkato 0:37e1e6a45ced 112 * "E_ACCESS_DENIED" error is raised, when the OSPL API that it is
dkato 0:37e1e6a45ced 113 * necessary to call "R_OSPL_Initialize" before calling the API was called.
dkato 0:37e1e6a45ced 114 */
dkato 0:37e1e6a45ced 115 errnum_t R_OSPL_Initialize( const void *const NullConfig );
dkato 0:37e1e6a45ced 116
dkato 0:37e1e6a45ced 117
dkato 0:37e1e6a45ced 118 /* Section: Standard functions */
dkato 0:37e1e6a45ced 119 /**
dkato 0:37e1e6a45ced 120 * @brief No operation from C++ specification
dkato 0:37e1e6a45ced 121 *
dkato 0:37e1e6a45ced 122 * @par Parameters
dkato 0:37e1e6a45ced 123 * None
dkato 0:37e1e6a45ced 124 * @return None
dkato 0:37e1e6a45ced 125 *
dkato 0:37e1e6a45ced 126 * @par Description
dkato 0:37e1e6a45ced 127 * Compatible with __noop (MS C++). But our naming rule is not match.
dkato 0:37e1e6a45ced 128 */
dkato 0:37e1e6a45ced 129 INLINE void R_NOOP(void) {}
dkato 0:37e1e6a45ced 130
dkato 0:37e1e6a45ced 131
dkato 0:37e1e6a45ced 132 /**
dkato 0:37e1e6a45ced 133 * @brief Returns element count of the array
dkato 0:37e1e6a45ced 134 *
dkato 0:37e1e6a45ced 135 * @param Array An array
dkato 0:37e1e6a45ced 136 * @return Count of specified array's element
dkato 0:37e1e6a45ced 137 *
dkato 0:37e1e6a45ced 138 * @par Description
dkato 0:37e1e6a45ced 139 * Compatible with _countof (MS C++) and ARRAY_SIZE (Linux).
dkato 0:37e1e6a45ced 140 * But our naming rule is not match.
dkato 0:37e1e6a45ced 141 *
dkato 0:37e1e6a45ced 142 * @par Example
dkato 0:37e1e6a45ced 143 * @code
dkato 0:37e1e6a45ced 144 * uint32_t array[10];
dkato 0:37e1e6a45ced 145 * R_COUNT_OF( array ) // = 10
dkato 0:37e1e6a45ced 146 * @endcode
dkato 0:37e1e6a45ced 147 *
dkato 0:37e1e6a45ced 148 * @par Example
dkato 0:37e1e6a45ced 149 * Array argument must not be specified the pointer using like array.
dkato 0:37e1e6a45ced 150 * @code
dkato 0:37e1e6a45ced 151 * uint32_t array[10];
dkato 0:37e1e6a45ced 152 * func( array );
dkato 0:37e1e6a45ced 153 *
dkato 0:37e1e6a45ced 154 * void func( uint32_t array[] ) // "array" is a pointer
dkato 0:37e1e6a45ced 155 * {
dkato 0:37e1e6a45ced 156 * R_COUNT_OF( array ) // NG
dkato 0:37e1e6a45ced 157 * }
dkato 0:37e1e6a45ced 158 * @endcode
dkato 0:37e1e6a45ced 159 */
dkato 0:37e1e6a45ced 160 /* ->MISRA 19.7 : Cannot function */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 161 #define R_COUNT_OF( Array ) ( sizeof( Array ) / sizeof( *(Array) ) )
dkato 0:37e1e6a45ced 162 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 163
dkato 0:37e1e6a45ced 164
dkato 0:37e1e6a45ced 165 /* Section: Error handling and debugging (1) */
dkato 0:37e1e6a45ced 166
dkato 0:37e1e6a45ced 167
dkato 0:37e1e6a45ced 168 /**
dkato 0:37e1e6a45ced 169 * @def IF
dkato 0:37e1e6a45ced 170 * @brief Breaks and transits to error state, if condition expression is not 0
dkato 0:37e1e6a45ced 171 * @param Condition Condition expression
dkato 0:37e1e6a45ced 172 * @return None
dkato 0:37e1e6a45ced 173 *
dkato 0:37e1e6a45ced 174 * @par Example
dkato 0:37e1e6a45ced 175 * @code
dkato 0:37e1e6a45ced 176 * e= TestFunction(); IF(e){goto fin;}
dkato 0:37e1e6a45ced 177 * @endcode
dkato 0:37e1e6a45ced 178 *
dkato 0:37e1e6a45ced 179 * @par Description
dkato 0:37e1e6a45ced 180 * "IF" is as same as general "if", if "R_OSPL_ERROR_BREAK" macro was
dkato 0:37e1e6a45ced 181 * defined to be 0. The following descriptions are available,
dkato 0:37e1e6a45ced 182 * if "R_OSPL_ERROR_BREAK" macro was defined to be 1.
dkato 0:37e1e6a45ced 183 *
dkato 0:37e1e6a45ced 184 * "IF" macro supports to find the code raising an error.
dkato 0:37e1e6a45ced 185 *
dkato 0:37e1e6a45ced 186 * If the "if statement" that is frequently seen in guard condition and
dkato 0:37e1e6a45ced 187 * after calling functions was changed to "IF" macro, the CPU breaks
dkato 0:37e1e6a45ced 188 * at raising an error. Then the status (values of variables) can be
dkato 0:37e1e6a45ced 189 * looked immediately and the code (call stack) can be looked. Thus,
dkato 0:37e1e6a45ced 190 * debug work grows in efficiency.
dkato 0:37e1e6a45ced 191 *
dkato 0:37e1e6a45ced 192 * "IF" macro promotes recognizing normal code and exceptional code.
dkato 0:37e1e6a45ced 193 * Reading speed will grow up by skipping exceptional code.
dkato 0:37e1e6a45ced 194 *
dkato 0:37e1e6a45ced 195 * Call "R_OSPL_SET_BREAK_ERROR_ID" function, if set to break at the code
dkato 0:37e1e6a45ced 196 * raising an error.
dkato 0:37e1e6a45ced 197 *
dkato 0:37e1e6a45ced 198 * Whether the state was error state or the error raised count is stored
dkato 0:37e1e6a45ced 199 * in the thread local storage. In Release configuration, the variable
dkato 0:37e1e6a45ced 200 * of error state and the error raised count is deleted. Manage the error
dkato 0:37e1e6a45ced 201 * code using auto variable and so on at out of OSPL.
dkato 0:37e1e6a45ced 202 *
dkato 0:37e1e6a45ced 203 * The error state is resolved by calling "R_OSPL_CLEAR_ERROR" function.
dkato 0:37e1e6a45ced 204 * If "R_DEBUG_BREAK_IF_ERROR" macro was called with any error state,
dkato 0:37e1e6a45ced 205 * the process breaks at the macro.
dkato 0:37e1e6a45ced 206 */
dkato 0:37e1e6a45ced 207 #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 208
dkato 0:37e1e6a45ced 209 /* ->MISRA 19.4 : Abnormal termination. Compliant with C language syntax. */ /* ->SEC M1.8.2 */
dkato 0:37e1e6a45ced 210 #define IF( Condition ) \
dkato 0:37e1e6a45ced 211 if ( IS( R_OSPL_OnRaisingErrorForMISRA( \
dkato 0:37e1e6a45ced 212 IS( (int_fast32_t)( Condition ) ), __FILE__, __LINE__ ) ) )
dkato 0:37e1e6a45ced 213 /* (int_fast32_t) cast is for QAC warning of implicit cast unsigned to signed */
dkato 0:37e1e6a45ced 214 /* != 0 is for QAC warning of MISRA 13.2 Advice */
dkato 0:37e1e6a45ced 215 /* <-MISRA 19.4 */ /* <-SEC M1.8.2 */
dkato 0:37e1e6a45ced 216
dkato 0:37e1e6a45ced 217 #else /* ! R_OSPL_ERROR_BREAK */
dkato 0:37e1e6a45ced 218
dkato 0:37e1e6a45ced 219 /* ->MISRA 19.4 : Abnormal termination. Compliant with C language syntax. */ /* ->SEC M1.8.2 */
dkato 0:37e1e6a45ced 220 #define IF if
dkato 0:37e1e6a45ced 221 /* <-MISRA 19.4 */ /* <-SEC M1.8.2 */
dkato 0:37e1e6a45ced 222 #endif
dkato 0:37e1e6a45ced 223
dkato 0:37e1e6a45ced 224
dkato 0:37e1e6a45ced 225 /**
dkato 0:37e1e6a45ced 226 * @def IF_D
dkato 0:37e1e6a45ced 227 * @brief It is same as "IF" (for Debug configuration only)
dkato 0:37e1e6a45ced 228 * @param Condition Condition expression
dkato 0:37e1e6a45ced 229 * @return None
dkato 0:37e1e6a45ced 230 *
dkato 0:37e1e6a45ced 231 * @par Description
dkato 0:37e1e6a45ced 232 * In Release configuration, the result of condition expression is always "false".
dkato 0:37e1e6a45ced 233 * The release configuration is the configuration defined "R_OSPL_NDEBUG".
dkato 0:37e1e6a45ced 234 */
dkato 0:37e1e6a45ced 235 /* ->MISRA 19.4 : Compliant with C language syntax. */ /* ->SEC M1.8.2 */
dkato 0:37e1e6a45ced 236 /* ->MISRA 19.7 : Cannot function */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 237 #ifndef R_OSPL_NDEBUG
dkato 0:37e1e6a45ced 238 #define IF_D( Condition ) IF ( Condition )
dkato 0:37e1e6a45ced 239 #else
dkato 0:37e1e6a45ced 240 #define IF_D( Condition ) if ( false )
dkato 0:37e1e6a45ced 241 #endif
dkato 0:37e1e6a45ced 242 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 243 /* <-MISRA 19.4 */ /* <-SEC M1.8.2 */
dkato 0:37e1e6a45ced 244
dkato 0:37e1e6a45ced 245
dkato 0:37e1e6a45ced 246 /**
dkato 0:37e1e6a45ced 247 * @def ASSERT_R
dkato 0:37e1e6a45ced 248 * @brief Assertion (Programming By Contract)
dkato 0:37e1e6a45ced 249 * @param Condition The condition expression expected true
dkato 0:37e1e6a45ced 250 * @param goto_fin_Statement The operation doing at condition is false
dkato 0:37e1e6a45ced 251 * @return None
dkato 0:37e1e6a45ced 252 *
dkato 0:37e1e6a45ced 253 * @par Description
dkato 0:37e1e6a45ced 254 * It is possible to write complex sentence divided by ";" in
dkato 0:37e1e6a45ced 255 * "goto_fin_Statement" argument.
dkato 0:37e1e6a45ced 256 *
dkato 0:37e1e6a45ced 257 * @par - Case of defined "R_OSPL_ERROR_BREAK" to be 0
dkato 0:37e1e6a45ced 258 * If the result of condition expression is 0(false), do "StatementsForError".
dkato 0:37e1e6a45ced 259 * If operations did nothing, write "R_NOOP()" at "StatementsForError" argument.
dkato 0:37e1e6a45ced 260 *
dkato 0:37e1e6a45ced 261 * @par - Case of defined "R_OSPL_ERROR_BREAK" to be 1
dkato 0:37e1e6a45ced 262 * If the result of condition expression is 0(false), the error state
dkato 0:37e1e6a45ced 263 * will become active and the operation of "StatementForError" argument
dkato 0:37e1e6a45ced 264 * will be done.
dkato 0:37e1e6a45ced 265 */
dkato 0:37e1e6a45ced 266 #ifndef __cplusplus
dkato 0:37e1e6a45ced 267 #define ASSERT_R( Condition, goto_fin_Statement ) \
dkato 0:37e1e6a45ced 268 do{ IF(!(Condition)) { goto_fin_Statement; } } while(0) /* do-while is CERT standard PRE10-C */
dkato 0:37e1e6a45ced 269 #else
dkato 0:37e1e6a45ced 270 #define ASSERT_R( Condition, goto_fin_Statement ) \
dkato 0:37e1e6a45ced 271 { IF(!(Condition)) { goto_fin_Statement; } } /* no C5236(I) */
dkato 0:37e1e6a45ced 272 #endif
dkato 0:37e1e6a45ced 273
dkato 0:37e1e6a45ced 274
dkato 0:37e1e6a45ced 275 /**
dkato 0:37e1e6a45ced 276 * @def ASSERT_D
dkato 0:37e1e6a45ced 277 * @brief Assertion (Programming By Contract) (for Debug configuration only)
dkato 0:37e1e6a45ced 278 * @param Condition The condition expression expected true
dkato 0:37e1e6a45ced 279 * @param goto_fin_Statement The operation doing at condition is false
dkato 0:37e1e6a45ced 280 * @return None
dkato 0:37e1e6a45ced 281 *
dkato 0:37e1e6a45ced 282 * @par Description
dkato 0:37e1e6a45ced 283 * This does nothing in Release configuration.
dkato 0:37e1e6a45ced 284 * Release configuration is the configuration defined "R_OSPL_NDEBUG"
dkato 0:37e1e6a45ced 285 * as same as standard library.
dkato 0:37e1e6a45ced 286 */
dkato 0:37e1e6a45ced 287 #ifndef R_OSPL_NDEBUG
dkato 0:37e1e6a45ced 288 #define ASSERT_D ASSERT_R
dkato 0:37e1e6a45ced 289 #else
dkato 0:37e1e6a45ced 290 /* ->MISRA 19.7 : Function's argument can not get "goto_fin_Statement" */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 291 #define ASSERT_D( Condition, goto_fin_Statement ) R_NOOP()
dkato 0:37e1e6a45ced 292 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 293 #endif
dkato 0:37e1e6a45ced 294
dkato 0:37e1e6a45ced 295
dkato 0:37e1e6a45ced 296 /**
dkato 0:37e1e6a45ced 297 * @brief Sub routine of IF macro
dkato 0:37e1e6a45ced 298 *
dkato 0:37e1e6a45ced 299 * @param Condition Condition in IF macro
dkato 0:37e1e6a45ced 300 * @param File File name
dkato 0:37e1e6a45ced 301 * @param Line Line number
dkato 0:37e1e6a45ced 302 * @return "Condition" argument
dkato 0:37e1e6a45ced 303 *
dkato 0:37e1e6a45ced 304 * @par Description
dkato 0:37e1e6a45ced 305 * - This part is for compliant to MISRA 2004 - 19.7.
dkato 0:37e1e6a45ced 306 */
dkato 0:37e1e6a45ced 307 bool_t R_OSPL_OnRaisingErrorForMISRA( bool_t const Condition, const char_t *const File,
dkato 0:37e1e6a45ced 308 int_t const Line );
dkato 0:37e1e6a45ced 309
dkato 0:37e1e6a45ced 310
dkato 0:37e1e6a45ced 311 /***********************************************************************
dkato 0:37e1e6a45ced 312 * Class: r_ospl_thread_id_t
dkato 0:37e1e6a45ced 313 ************************************************************************/
dkato 0:37e1e6a45ced 314
dkato 0:37e1e6a45ced 315 /**
dkato 0:37e1e6a45ced 316 * @brief Get running thread ID (for OS less and OS-using environment)
dkato 0:37e1e6a45ced 317 *
dkato 0:37e1e6a45ced 318 * @par Parameters
dkato 0:37e1e6a45ced 319 * None
dkato 0:37e1e6a45ced 320 * @return The current running thread ID
dkato 0:37e1e6a45ced 321 *
dkato 0:37e1e6a45ced 322 * @par Description
dkato 0:37e1e6a45ced 323 * - It is possible to use this function for both OS less and OS - using environment.
dkato 0:37e1e6a45ced 324 * For OS less, returns thread ID passed to "R_OSPL_THREAD_SetCurrentId" function.
dkato 0:37e1e6a45ced 325 * "NULL" is returned, if in interrupt context.
dkato 0:37e1e6a45ced 326 */
dkato 0:37e1e6a45ced 327 r_ospl_thread_id_t R_OSPL_THREAD_GetCurrentId(void);
dkato 0:37e1e6a45ced 328
dkato 0:37e1e6a45ced 329
dkato 0:37e1e6a45ced 330 /**
dkato 0:37e1e6a45ced 331 * @brief Set one or some bits to 1
dkato 0:37e1e6a45ced 332 *
dkato 0:37e1e6a45ced 333 * @param ThreadId The thread ID attached the target event
dkato 0:37e1e6a45ced 334 * @param SetFlags The value of bit flags that target bit is 1
dkato 0:37e1e6a45ced 335 * @return None
dkato 0:37e1e6a45ced 336 *
dkato 0:37e1e6a45ced 337 * @par Description
dkato 0:37e1e6a45ced 338 * For OS less, there is the area disabled all interrupts.
dkato 0:37e1e6a45ced 339 *
dkato 0:37e1e6a45ced 340 * - For OS - using environment, the thread waiting in "R_OSPL_EVENT_Wait"
dkato 0:37e1e6a45ced 341 * function might wake up soon.
dkato 0:37e1e6a45ced 342 *
dkato 0:37e1e6a45ced 343 * Do nothing, when "ThreadId" = "NULL"
dkato 0:37e1e6a45ced 344 */
dkato 0:37e1e6a45ced 345 void R_OSPL_EVENT_Set( r_ospl_thread_id_t const ThreadId, bit_flags32_t const SetFlags );
dkato 0:37e1e6a45ced 346
dkato 0:37e1e6a45ced 347
dkato 0:37e1e6a45ced 348 /**
dkato 0:37e1e6a45ced 349 * @brief Set one or some bits to 0
dkato 0:37e1e6a45ced 350 *
dkato 0:37e1e6a45ced 351 * @param ThreadId The thread ID attached the target event
dkato 0:37e1e6a45ced 352 * @param ClearFlags1 The value of bit flags that clearing bit is 1
dkato 0:37e1e6a45ced 353 * @return None
dkato 0:37e1e6a45ced 354 *
dkato 0:37e1e6a45ced 355 * @par Description
dkato 0:37e1e6a45ced 356 * It is not necessary to call this function after called "R_OSPL_EVENT_Wait"
dkato 0:37e1e6a45ced 357 * function.
dkato 0:37e1e6a45ced 358 *
dkato 0:37e1e6a45ced 359 * The way that all bit flags is cleared is setting "R_OSPL_EVENT_ALL_BITS"
dkato 0:37e1e6a45ced 360 * (=0x0000FFFF) at "ClearFlags1" argument.
dkato 0:37e1e6a45ced 361 *
dkato 0:37e1e6a45ced 362 * When other thread was nofied by calling "R_OSPL_EVENT_Set", "R_OSPL_EVENT_Clear"
dkato 0:37e1e6a45ced 363 * must not be called from caller (notifier) thread.
dkato 0:37e1e6a45ced 364 *
dkato 0:37e1e6a45ced 365 * For OS less, there is the area disabled all interrupts.
dkato 0:37e1e6a45ced 366 *
dkato 0:37e1e6a45ced 367 * Do nothing, when "ThreadId" = "NULL"
dkato 0:37e1e6a45ced 368 */
dkato 0:37e1e6a45ced 369 void R_OSPL_EVENT_Clear( r_ospl_thread_id_t const ThreadId, bit_flags32_t const ClearFlags1 );
dkato 0:37e1e6a45ced 370
dkato 0:37e1e6a45ced 371
dkato 0:37e1e6a45ced 372 /**
dkato 0:37e1e6a45ced 373 * @brief Get 16bit flags value
dkato 0:37e1e6a45ced 374 *
dkato 0:37e1e6a45ced 375 * @param ThreadId The thread ID attached the target event
dkato 0:37e1e6a45ced 376 * @return The value of 16bit flags
dkato 0:37e1e6a45ced 377 *
dkato 0:37e1e6a45ced 378 * @par Description
dkato 0:37e1e6a45ced 379 * This API cannot be used in newest specification.
dkato 0:37e1e6a45ced 380 *
dkato 0:37e1e6a45ced 381 * In receiving the event, call "R_OSPL_EVENT_Wait" function instead of
dkato 0:37e1e6a45ced 382 * "R_OSPL_EVENT_Get" function or call "R_OSPL_EVENT_Clear" function
dkato 0:37e1e6a45ced 383 * passed the NOT operated value of flags got by "R_OSPL_EVENT_Get" function.
dkato 0:37e1e6a45ced 384 */
dkato 0:37e1e6a45ced 385 #if ( ! defined( osCMSIS ) || osCMSIS <= 0x10001 ) && R_OSPL_VERSION < 85
dkato 0:37e1e6a45ced 386 bit_flags32_t R_OSPL_EVENT_Get( r_ospl_thread_id_t const ThreadId );
dkato 0:37e1e6a45ced 387 #endif
dkato 0:37e1e6a45ced 388
dkato 0:37e1e6a45ced 389
dkato 0:37e1e6a45ced 390 /**
dkato 0:37e1e6a45ced 391 * @brief Waits for setting the flags in 16bit and clear received flags
dkato 0:37e1e6a45ced 392 *
dkato 0:37e1e6a45ced 393 * @param WaigingFlags The bit flags set to 1 waiting or "R_OSPL_ANY_FLAG"
dkato 0:37e1e6a45ced 394 * @param out_GotFlags NULL is permitted. Output: 16 bit flags or "R_OSPL_TIMEOUT"
dkato 0:37e1e6a45ced 395 * @param Timeout_msec Time out (millisecond) or "R_OSPL_INFINITE"
dkato 0:37e1e6a45ced 396 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 397 *
dkato 0:37e1e6a45ced 398 * @par Description
dkato 0:37e1e6a45ced 399 * Waits in this function until the flags become passed flags pattern
dkato 0:37e1e6a45ced 400 * by "R_OSPL_EVENT_Set" function.
dkato 0:37e1e6a45ced 401 *
dkato 0:37e1e6a45ced 402 * Check "r_ospl_async_t::ReturnValue", when the asynchronous operation
dkato 0:37e1e6a45ced 403 * was ended.
dkato 0:37e1e6a45ced 404 */
dkato 0:37e1e6a45ced 405 errnum_t R_OSPL_EVENT_Wait( bit_flags32_t const WaigingFlags, bit_flags32_t *const out_GotFlags,
dkato 0:37e1e6a45ced 406 uint32_t const Timeout_msec );
dkato 0:37e1e6a45ced 407 /* Unsigned flag (bit_flags32_t) is for QAC 4130 */
dkato 0:37e1e6a45ced 408
dkato 0:37e1e6a45ced 409
dkato 0:37e1e6a45ced 410 /***********************************************************************
dkato 0:37e1e6a45ced 411 * Class: r_ospl_flag32_t
dkato 0:37e1e6a45ced 412 ************************************************************************/
dkato 0:37e1e6a45ced 413
dkato 0:37e1e6a45ced 414 /**
dkato 0:37e1e6a45ced 415 * @brief Clears all flags in 32bit to 0
dkato 0:37e1e6a45ced 416 *
dkato 0:37e1e6a45ced 417 * @param self The value of 32bit flags
dkato 0:37e1e6a45ced 418 * @return None
dkato 0:37e1e6a45ced 419 *
dkato 0:37e1e6a45ced 420 * @par Description
dkato 0:37e1e6a45ced 421 * Operates following operation.
dkato 0:37e1e6a45ced 422 * @code
dkato 0:37e1e6a45ced 423 * volatile bit_flags32_t self->flags;
dkato 0:37e1e6a45ced 424 * self->flags = 0;
dkato 0:37e1e6a45ced 425 * @endcode
dkato 0:37e1e6a45ced 426 */
dkato 0:37e1e6a45ced 427 void R_OSPL_FLAG32_InitConst( volatile r_ospl_flag32_t *const self );
dkato 0:37e1e6a45ced 428
dkato 0:37e1e6a45ced 429
dkato 0:37e1e6a45ced 430 /**
dkato 0:37e1e6a45ced 431 * @brief Set one or some bits to 1
dkato 0:37e1e6a45ced 432 *
dkato 0:37e1e6a45ced 433 * @param self The value of 32bit flags
dkato 0:37e1e6a45ced 434 * @param SetFlags The value of bit flags that target bit is 1
dkato 0:37e1e6a45ced 435 * @return None
dkato 0:37e1e6a45ced 436 *
dkato 0:37e1e6a45ced 437 * @par Description
dkato 0:37e1e6a45ced 438 * Operates following operation.
dkato 0:37e1e6a45ced 439 * @code
dkato 0:37e1e6a45ced 440 * volatile bit_flags32_t self->Flags;
dkato 0:37e1e6a45ced 441 * bit_flags32_t SetFlags;
dkato 0:37e1e6a45ced 442 * self->Flags |= SetFlags;
dkato 0:37e1e6a45ced 443 * @endcode
dkato 0:37e1e6a45ced 444 * This function is not atomic because "|=" operator is "Read Modify Write" operation.
dkato 0:37e1e6a45ced 445 */
dkato 0:37e1e6a45ced 446 void R_OSPL_FLAG32_Set( volatile r_ospl_flag32_t *const self, bit_flags32_t const SetFlags );
dkato 0:37e1e6a45ced 447
dkato 0:37e1e6a45ced 448
dkato 0:37e1e6a45ced 449 /**
dkato 0:37e1e6a45ced 450 * @brief Set one or some bits to 0
dkato 0:37e1e6a45ced 451 *
dkato 0:37e1e6a45ced 452 * @param self The value of 32bit flags
dkato 0:37e1e6a45ced 453 * @param ClearFlags1 The value of bit flags that clearing bit is 1
dkato 0:37e1e6a45ced 454 * @return None
dkato 0:37e1e6a45ced 455 *
dkato 0:37e1e6a45ced 456 * @par Description
dkato 0:37e1e6a45ced 457 * Operates following operation.
dkato 0:37e1e6a45ced 458 * @code
dkato 0:37e1e6a45ced 459 * volatile bit_flags32_t self->Flags;
dkato 0:37e1e6a45ced 460 * bit_flags32_t ClearFlags1;
dkato 0:37e1e6a45ced 461 *
dkato 0:37e1e6a45ced 462 * self->Flags &= ~ClearFlags1;
dkato 0:37e1e6a45ced 463 * @endcode
dkato 0:37e1e6a45ced 464 *
dkato 0:37e1e6a45ced 465 * Set "R_OSPL_FLAG32_ALL_BITS", if you wanted to clear all bits.
dkato 0:37e1e6a45ced 466 *
dkato 0:37e1e6a45ced 467 * This function is not atomic because "&=" operator is "Read Modify Write" operation.
dkato 0:37e1e6a45ced 468 */
dkato 0:37e1e6a45ced 469 void R_OSPL_FLAG32_Clear( volatile r_ospl_flag32_t *const self, bit_flags32_t const ClearFlags1 );
dkato 0:37e1e6a45ced 470
dkato 0:37e1e6a45ced 471
dkato 0:37e1e6a45ced 472 /**
dkato 0:37e1e6a45ced 473 * @brief Get 32bit flags value
dkato 0:37e1e6a45ced 474 *
dkato 0:37e1e6a45ced 475 * @param self The value of 32bit flags
dkato 0:37e1e6a45ced 476 * @return The value of 32bit flags
dkato 0:37e1e6a45ced 477 *
dkato 0:37e1e6a45ced 478 * @par Description
dkato 0:37e1e6a45ced 479 * In receiving the event, call "R_OSPL_FLAG32_GetAndClear" function
dkato 0:37e1e6a45ced 480 * instead of "R_OSPL_FLAG32_Get" function or call "R_OSPL_FLAG32_Clear"
dkato 0:37e1e6a45ced 481 * function passed the NOT operated value of flags got by "R_OSPL_FLAG32_Get"
dkato 0:37e1e6a45ced 482 * function.
dkato 0:37e1e6a45ced 483 *
dkato 0:37e1e6a45ced 484 * @code
dkato 0:37e1e6a45ced 485 * Operates following operation.
dkato 0:37e1e6a45ced 486 * volatile bit_flags32_t self->Flags;
dkato 0:37e1e6a45ced 487 * bit_flags32_t return_flags;
dkato 0:37e1e6a45ced 488 *
dkato 0:37e1e6a45ced 489 * return_flags = self->Flags;
dkato 0:37e1e6a45ced 490 *
dkato 0:37e1e6a45ced 491 * return return_flags;
dkato 0:37e1e6a45ced 492 * @endcode
dkato 0:37e1e6a45ced 493 */
dkato 0:37e1e6a45ced 494 bit_flags32_t R_OSPL_FLAG32_Get( volatile const r_ospl_flag32_t *const self );
dkato 0:37e1e6a45ced 495
dkato 0:37e1e6a45ced 496
dkato 0:37e1e6a45ced 497 /**
dkato 0:37e1e6a45ced 498 * @brief Get 32bit flags value
dkato 0:37e1e6a45ced 499 *
dkato 0:37e1e6a45ced 500 * @param self The value of 32bit flags
dkato 0:37e1e6a45ced 501 * @return The value of 32bit flags
dkato 0:37e1e6a45ced 502 *
dkato 0:37e1e6a45ced 503 * @par Description
dkato 0:37e1e6a45ced 504 * Operates following operation.
dkato 0:37e1e6a45ced 505 * @code
dkato 0:37e1e6a45ced 506 * volatile bit_flags32_t self->Flags;
dkato 0:37e1e6a45ced 507 * bit_flags32_t return_flags;
dkato 0:37e1e6a45ced 508 *
dkato 0:37e1e6a45ced 509 * return_flags = self->Flags;
dkato 0:37e1e6a45ced 510 * self->Flags = 0;
dkato 0:37e1e6a45ced 511 *
dkato 0:37e1e6a45ced 512 * return return_flags;
dkato 0:37e1e6a45ced 513 * @endcode
dkato 0:37e1e6a45ced 514 *
dkato 0:37e1e6a45ced 515 * This function is not atomic because the value might be set before clearing to 0.
dkato 0:37e1e6a45ced 516 */
dkato 0:37e1e6a45ced 517 bit_flags32_t R_OSPL_FLAG32_GetAndClear( volatile r_ospl_flag32_t *const self );
dkato 0:37e1e6a45ced 518
dkato 0:37e1e6a45ced 519
dkato 0:37e1e6a45ced 520 /***********************************************************************
dkato 0:37e1e6a45ced 521 * Class: r_ospl_queue_t
dkato 0:37e1e6a45ced 522 ************************************************************************/
dkato 0:37e1e6a45ced 523
dkato 0:37e1e6a45ced 524 /**
dkato 0:37e1e6a45ced 525 * @brief Initializes a queue
dkato 0:37e1e6a45ced 526 *
dkato 0:37e1e6a45ced 527 * @param out_self Output: Address of initialized queue object
dkato 0:37e1e6a45ced 528 * @param QueueDefine Initial attributes of queue and work area
dkato 0:37e1e6a45ced 529 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 530 *
dkato 0:37e1e6a45ced 531 * @par Description
dkato 0:37e1e6a45ced 532 * It is not possible to call this function from the library.
dkato 0:37e1e6a45ced 533 * This function is called from porting layer of the driver and send
dkato 0:37e1e6a45ced 534 * created queue to the driver.
dkato 0:37e1e6a45ced 535 *
dkato 0:37e1e6a45ced 536 * OSPL does not have finalizing function (portabled with CMSIS).
dkato 0:37e1e6a45ced 537 * An object specified "QueueDefine" argument can be specified to the
dkato 0:37e1e6a45ced 538 * create function 1 times only. Some OS does not have this limitation.
dkato 0:37e1e6a45ced 539 *
dkato 0:37e1e6a45ced 540 * The address of a variable as "r_ospl_queue_t*" type is set at
dkato 0:37e1e6a45ced 541 * "out_self" argument.
dkato 0:37e1e6a45ced 542 * Internal variables of the queue are stored in the variable specified
dkato 0:37e1e6a45ced 543 * with "QueueDefine" argument.
dkato 0:37e1e6a45ced 544 */
dkato 0:37e1e6a45ced 545 errnum_t R_OSPL_QUEUE_Create( r_ospl_queue_t **out_self, r_ospl_queue_def_t *QueueDefine );
dkato 0:37e1e6a45ced 546
dkato 0:37e1e6a45ced 547
dkato 0:37e1e6a45ced 548 /**
dkato 0:37e1e6a45ced 549 * @brief Gets status of the queue
dkato 0:37e1e6a45ced 550 *
dkato 0:37e1e6a45ced 551 * @param self A queue object
dkato 0:37e1e6a45ced 552 * @param out_Status Output: Pointer to the status structure
dkato 0:37e1e6a45ced 553 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 554 *
dkato 0:37e1e6a45ced 555 * @par Description
dkato 0:37e1e6a45ced 556 * Got status are the information at calling moment.
dkato 0:37e1e6a45ced 557 * If ohter threads were run, the status will be changed.
dkato 0:37e1e6a45ced 558 * See "R_DRIVER_GetAsyncStatus" function about pointer type of
dkato 0:37e1e6a45ced 559 * "out_Status" argument
dkato 0:37e1e6a45ced 560 */
dkato 0:37e1e6a45ced 561 errnum_t R_OSPL_QUEUE_GetStatus( r_ospl_queue_t *self, const r_ospl_queue_status_t **out_Status );
dkato 0:37e1e6a45ced 562
dkato 0:37e1e6a45ced 563
dkato 0:37e1e6a45ced 564 /**
dkato 0:37e1e6a45ced 565 * @brief Allocates an element from the queue object
dkato 0:37e1e6a45ced 566 *
dkato 0:37e1e6a45ced 567 * @param self A queue object
dkato 0:37e1e6a45ced 568 * @param out_Address Output: Address of allocated element
dkato 0:37e1e6a45ced 569 * @param Timeout_msec Timeout (msec) or R_OSPL_INFINITE
dkato 0:37e1e6a45ced 570 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 571 *
dkato 0:37e1e6a45ced 572 * @par Description
dkato 0:37e1e6a45ced 573 * An error will be raised, if "Timeout_msec != 0" in interrupt context.
dkato 0:37e1e6a45ced 574 * It becomes "*out_Address = NULL", when it was timeout and
dkato 0:37e1e6a45ced 575 * "Timeout_msec = 0".
dkato 0:37e1e6a45ced 576 * E_TIME_OUT error is raised, when it was timeout and "Timeout_msec != 0".
dkato 0:37e1e6a45ced 577 */
dkato 0:37e1e6a45ced 578 errnum_t R_OSPL_QUEUE_Allocate( r_ospl_queue_t *self, void *out_Address, uint32_t Timeout_msec );
dkato 0:37e1e6a45ced 579
dkato 0:37e1e6a45ced 580
dkato 0:37e1e6a45ced 581 /**
dkato 0:37e1e6a45ced 582 * @brief Sends the element to the queue
dkato 0:37e1e6a45ced 583 *
dkato 0:37e1e6a45ced 584 * @param self A queue object
dkato 0:37e1e6a45ced 585 * @param Address Address of element to put
dkato 0:37e1e6a45ced 586 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 587 *
dkato 0:37e1e6a45ced 588 * @par Description
dkato 0:37e1e6a45ced 589 * It is correct, even if other thread put to the queue or get from
dkato 0:37e1e6a45ced 590 * the queue from calling "R_OSPL_QUEUE_Allocate" to calling
dkato 0:37e1e6a45ced 591 * "R_OSPL_QUEUE_Put".
dkato 0:37e1e6a45ced 592 *
dkato 0:37e1e6a45ced 593 * The message put to the queue by this function receives the thread
dkato 0:37e1e6a45ced 594 * calling "R_OSPL_QUEUE_Get" function.
dkato 0:37e1e6a45ced 595 */
dkato 0:37e1e6a45ced 596 errnum_t R_OSPL_QUEUE_Put( r_ospl_queue_t *self, void *Address );
dkato 0:37e1e6a45ced 597
dkato 0:37e1e6a45ced 598
dkato 0:37e1e6a45ced 599 /**
dkato 0:37e1e6a45ced 600 * @brief Receives the element from the queue
dkato 0:37e1e6a45ced 601 *
dkato 0:37e1e6a45ced 602 * @param self A queue object
dkato 0:37e1e6a45ced 603 * @param out_Address Output: Address of received element
dkato 0:37e1e6a45ced 604 * @param Timeout_msec Timeout (msec) or R_OSPL_INFINITE
dkato 0:37e1e6a45ced 605 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 606 *
dkato 0:37e1e6a45ced 607 * @par Description
dkato 0:37e1e6a45ced 608 * Call "R_OSPL_QUEUE_Free" function after finishing to access to
dkato 0:37e1e6a45ced 609 * the element. Don't access the memory area of the element after
dkato 0:37e1e6a45ced 610 * calling "R_OSPL_QUEUE_Free".
dkato 0:37e1e6a45ced 611 *
dkato 0:37e1e6a45ced 612 * "E_NOT_THREAD" error is raised, if "Timeout_msec = 0" was specified
dkato 0:37e1e6a45ced 613 * from interrupt context. It is not possible to wait for put data to
dkato 0:37e1e6a45ced 614 * the queue in interrupt context.
dkato 0:37e1e6a45ced 615 *
dkato 0:37e1e6a45ced 616 * "*out_Address" is NULL and any errors are not raised, if it becomed
dkato 0:37e1e6a45ced 617 * to timeout and "Timeout_msec = 0". "E_TIME_OUT" is raised,
dkato 0:37e1e6a45ced 618 * if "Timeout_msec != 0".
dkato 0:37e1e6a45ced 619 *
dkato 0:37e1e6a45ced 620 * Specify "Timeout_msec = 0", call the following functions by the following
dkato 0:37e1e6a45ced 621 * order and use an event for preventing to block to receive other events
dkato 0:37e1e6a45ced 622 * by the thread having waited for the queue.
dkato 0:37e1e6a45ced 623 *
dkato 0:37e1e6a45ced 624 * Sending Side
dkato 0:37e1e6a45ced 625 * - R_OSPL_QUEUE_Allocate
dkato 0:37e1e6a45ced 626 * - R_OSPL_QUEUE_Put
dkato 0:37e1e6a45ced 627 * - R_OSPL_EVENT_Set
dkato 0:37e1e6a45ced 628 *
dkato 0:37e1e6a45ced 629 * Receiving Side
dkato 0:37e1e6a45ced 630 * - R_OSPL_EVENT_Wait
dkato 0:37e1e6a45ced 631 * - R_OSPL_QUEUE_Get
dkato 0:37e1e6a45ced 632 * - R_OSPL_QUEUE_Free
dkato 0:37e1e6a45ced 633 *
dkato 0:37e1e6a45ced 634 * In OS less environment, "R_OSPL_QUEUE_Get" supports pseudo multi
dkato 0:37e1e6a45ced 635 * threading. See "R_OSPL_THREAD_GetIsWaiting" function.
dkato 0:37e1e6a45ced 636 */
dkato 0:37e1e6a45ced 637 errnum_t R_OSPL_QUEUE_Get( r_ospl_queue_t *self, void *out_Address, uint32_t Timeout_msec );
dkato 0:37e1e6a45ced 638
dkato 0:37e1e6a45ced 639
dkato 0:37e1e6a45ced 640 /**
dkato 0:37e1e6a45ced 641 * @brief Releases the element to the queue object
dkato 0:37e1e6a45ced 642 *
dkato 0:37e1e6a45ced 643 * @param self A queue object
dkato 0:37e1e6a45ced 644 * @param Address Address of received element
dkato 0:37e1e6a45ced 645 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 646 *
dkato 0:37e1e6a45ced 647 * @par Description
dkato 0:37e1e6a45ced 648 * It is correct, even if other thread put to the queue or get from
dkato 0:37e1e6a45ced 649 * the queue from calling "R_OSPL_QUEUE_Get" to calling "R_OSPL_QUEUE_Free".
dkato 0:37e1e6a45ced 650 */
dkato 0:37e1e6a45ced 651 errnum_t R_OSPL_QUEUE_Free( r_ospl_queue_t *self, void *Address );
dkato 0:37e1e6a45ced 652
dkato 0:37e1e6a45ced 653
dkato 0:37e1e6a45ced 654 /**
dkato 0:37e1e6a45ced 655 * @brief Print status of the queue object
dkato 0:37e1e6a45ced 656 *
dkato 0:37e1e6a45ced 657 * @param self A queue object
dkato 0:37e1e6a45ced 658 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 659 */
dkato 0:37e1e6a45ced 660 #ifndef R_OSPL_NDEBUG
dkato 0:37e1e6a45ced 661 errnum_t R_OSPL_QUEUE_Print( r_ospl_queue_t *self );
dkato 0:37e1e6a45ced 662 #endif
dkato 0:37e1e6a45ced 663
dkato 0:37e1e6a45ced 664
dkato 0:37e1e6a45ced 665 /***********************************************************************
dkato 0:37e1e6a45ced 666 * Class: r_ospl_async_t
dkato 0:37e1e6a45ced 667 ************************************************************************/
dkato 0:37e1e6a45ced 668
dkato 0:37e1e6a45ced 669 /**
dkato 0:37e1e6a45ced 670 * @brief CopyExceptAThread
dkato 0:37e1e6a45ced 671 *
dkato 0:37e1e6a45ced 672 * @param Source Source
dkato 0:37e1e6a45ced 673 * @param Destination Destination
dkato 0:37e1e6a45ced 674 * @return None
dkato 0:37e1e6a45ced 675 */
dkato 0:37e1e6a45ced 676 void R_OSPL_ASYNC_CopyExceptAThread( const r_ospl_async_t *const Source,
dkato 0:37e1e6a45ced 677 r_ospl_async_t *const Destination );
dkato 0:37e1e6a45ced 678
dkato 0:37e1e6a45ced 679
dkato 0:37e1e6a45ced 680 /***********************************************************************
dkato 0:37e1e6a45ced 681 * Class: r_ospl_caller_t
dkato 0:37e1e6a45ced 682 ************************************************************************/
dkato 0:37e1e6a45ced 683
dkato 0:37e1e6a45ced 684 /**
dkato 0:37e1e6a45ced 685 * @brief Calls the interrupt callback function. It is called from OS porting layer in the driver
dkato 0:37e1e6a45ced 686 *
dkato 0:37e1e6a45ced 687 * @param self The internal parameters about interrupt operations
dkato 0:37e1e6a45ced 688 * @param InterruptSource The source of the interrupt
dkato 0:37e1e6a45ced 689 * @return None
dkato 0:37e1e6a45ced 690 */
dkato 0:37e1e6a45ced 691 void R_OSPL_CallInterruptCallback( const r_ospl_caller_t *const self,
dkato 0:37e1e6a45ced 692 const r_ospl_interrupt_t *const InterruptSource );
dkato 0:37e1e6a45ced 693
dkato 0:37e1e6a45ced 694
dkato 0:37e1e6a45ced 695 /**
dkato 0:37e1e6a45ced 696 * @brief Initialize <r_ospl_caller_t>.
dkato 0:37e1e6a45ced 697 *
dkato 0:37e1e6a45ced 698 * @param self The internal parameters about interrupt operations
dkato 0:37e1e6a45ced 699 * @param Async <r_ospl_async_t>
dkato 0:37e1e6a45ced 700 * @return None
dkato 0:37e1e6a45ced 701 */
dkato 0:37e1e6a45ced 702 void R_OSPL_CALLER_Initialize( r_ospl_caller_t *const self, r_ospl_async_t *const Async,
dkato 0:37e1e6a45ced 703 volatile void *const PointerToState, int_t const StateValueOfOnInterrupting,
dkato 0:37e1e6a45ced 704 void *const I_Lock, const r_ospl_i_lock_vtable_t *const I_LockVTable );
dkato 0:37e1e6a45ced 705
dkato 0:37e1e6a45ced 706
dkato 0:37e1e6a45ced 707 /**
dkato 0:37e1e6a45ced 708 * @brief GetRootChannelNum.
dkato 0:37e1e6a45ced 709 *
dkato 0:37e1e6a45ced 710 * @param self The internal parameters about interrupt operations
dkato 0:37e1e6a45ced 711 * @return RootChannelNum
dkato 0:37e1e6a45ced 712 */
dkato 0:37e1e6a45ced 713 INLINE int_fast32_t R_OSPL_CALLER_GetRootChannelNum( const r_ospl_caller_t *const self );
dkato 0:37e1e6a45ced 714
dkato 0:37e1e6a45ced 715
dkato 0:37e1e6a45ced 716 /* Section: Interrupt */
dkato 0:37e1e6a45ced 717 /**
dkato 0:37e1e6a45ced 718 * @brief Interrupt callback function for unregisterd interrupt.
dkato 0:37e1e6a45ced 719 *
dkato 0:37e1e6a45ced 720 * @param int_sense (See INTC driver)
dkato 0:37e1e6a45ced 721 * @return None
dkato 0:37e1e6a45ced 722 */
dkato 0:37e1e6a45ced 723 void R_OSPL_OnInterruptForUnregistered( uint32_t const int_sense );
dkato 0:37e1e6a45ced 724
dkato 0:37e1e6a45ced 725
dkato 0:37e1e6a45ced 726 /**
dkato 0:37e1e6a45ced 727 * @brief Releases all disabled interrupts
dkato 0:37e1e6a45ced 728 *
dkato 0:37e1e6a45ced 729 * @par Parameters
dkato 0:37e1e6a45ced 730 * None
dkato 0:37e1e6a45ced 731 * @return None
dkato 0:37e1e6a45ced 732 *
dkato 0:37e1e6a45ced 733 * @par Description
dkato 0:37e1e6a45ced 734 * Driver user should not call this function.
dkato 0:37e1e6a45ced 735 * Call this function at the end of area of all interrupts disabled.
dkato 0:37e1e6a45ced 736 * Do not release, if all interrupts was already disabled by caller function.
dkato 0:37e1e6a45ced 737 * This function does not release disabled NMI.
dkato 0:37e1e6a45ced 738 */
dkato 0:37e1e6a45ced 739 void R_OSPL_EnableAllInterrupt(void);
dkato 0:37e1e6a45ced 740
dkato 0:37e1e6a45ced 741
dkato 0:37e1e6a45ced 742 /**
dkato 0:37e1e6a45ced 743 * @brief Disables all interrupts
dkato 0:37e1e6a45ced 744 *
dkato 0:37e1e6a45ced 745 * @par Parameters
dkato 0:37e1e6a45ced 746 * None
dkato 0:37e1e6a45ced 747 * @return None
dkato 0:37e1e6a45ced 748 *
dkato 0:37e1e6a45ced 749 * @par Description
dkato 0:37e1e6a45ced 750 * Driver user should not call this function.
dkato 0:37e1e6a45ced 751 * Call this function at begin of area of all interrupts disabled.
dkato 0:37e1e6a45ced 752 * This function does not disable NMI.
dkato 0:37e1e6a45ced 753 *
dkato 0:37e1e6a45ced 754 * @par Example
dkato 0:37e1e6a45ced 755 * @code
dkato 0:37e1e6a45ced 756 * void Func()
dkato 0:37e1e6a45ced 757 * {
dkato 0:37e1e6a45ced 758 * bool_t was_all_enabled = false;
dkato 0:37e1e6a45ced 759 *
dkato 0:37e1e6a45ced 760 * was_all_enabled = R_OSPL_DisableAllInterrupt();
dkato 0:37e1e6a45ced 761 *
dkato 0:37e1e6a45ced 762 * // All interrupt disabled
dkato 0:37e1e6a45ced 763 *
dkato 0:37e1e6a45ced 764 * if ( was_all_enabled )
dkato 0:37e1e6a45ced 765 * { R_OSPL_EnableAllInterrupt(); }
dkato 0:37e1e6a45ced 766 * }
dkato 0:37e1e6a45ced 767 * @endcode
dkato 0:37e1e6a45ced 768 */
dkato 0:37e1e6a45ced 769 bool_t R_OSPL_DisableAllInterrupt(void);
dkato 0:37e1e6a45ced 770
dkato 0:37e1e6a45ced 771
dkato 0:37e1e6a45ced 772 /**
dkato 0:37e1e6a45ced 773 * @brief Sets the priority of the interrupt line.
dkato 0:37e1e6a45ced 774 *
dkato 0:37e1e6a45ced 775 * @param IRQ_Num Interrupt request number
dkato 0:37e1e6a45ced 776 * @param Priority Priority. The less the prior.
dkato 0:37e1e6a45ced 777 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 778 */
dkato 0:37e1e6a45ced 779 errnum_t R_OSPL_SetInterruptPriority( bsp_int_src_t const IRQ_Num, int_fast32_t const Priority );
dkato 0:37e1e6a45ced 780
dkato 0:37e1e6a45ced 781
dkato 0:37e1e6a45ced 782 /* Section: Locking channel */
dkato 0:37e1e6a45ced 783 /**
dkato 0:37e1e6a45ced 784 * @brief Locks by channel number.
dkato 0:37e1e6a45ced 785 *
dkato 0:37e1e6a45ced 786 * @param ChannelNum Locking channel number or "R_OSPL_UNLOCKED_CHANNEL"
dkato 0:37e1e6a45ced 787 * @param out_ChannelNum Output: Locked channel number, (in) NULL is permitted
dkato 0:37e1e6a45ced 788 * @param HardwareIndexMin Hardware index of channel number = 0
dkato 0:37e1e6a45ced 789 * @param HardwareIndexMax Hardware index of max channel number
dkato 0:37e1e6a45ced 790 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 791 *
dkato 0:37e1e6a45ced 792 * @par Description
dkato 0:37e1e6a45ced 793 * This function is called from the internal of "R_DRIVER_Initialize"
dkato 0:37e1e6a45ced 794 * function or "R_DRIVER_LockChannel" function.
dkato 0:37e1e6a45ced 795 * This function calls "R_BSP_HardwareLock".
dkato 0:37e1e6a45ced 796 */
dkato 0:37e1e6a45ced 797 errnum_t R_OSPL_LockChannel( int_fast32_t ChannelNum, int_fast32_t *out_ChannelNum,
dkato 0:37e1e6a45ced 798 mcu_lock_t HardwareIndexMin, mcu_lock_t HardwareIndexMax );
dkato 0:37e1e6a45ced 799
dkato 0:37e1e6a45ced 800
dkato 0:37e1e6a45ced 801 /**
dkato 0:37e1e6a45ced 802 * @brief Unlocks by channel number.
dkato 0:37e1e6a45ced 803 *
dkato 0:37e1e6a45ced 804 * @param ChannelNum Channel number
dkato 0:37e1e6a45ced 805 * @param e Raising error code, If there is no error, 0
dkato 0:37e1e6a45ced 806 * @param HardwareIndexMin Hardware index of channel number = 0
dkato 0:37e1e6a45ced 807 * @param HardwareIndexMax Hardware index of max channel number
dkato 0:37e1e6a45ced 808 * @return Error code. If there is no error, the return value is 0
dkato 0:37e1e6a45ced 809 *
dkato 0:37e1e6a45ced 810 * @par Description
dkato 0:37e1e6a45ced 811 * This function is called from the internal of "R_DRIVER_Finalize"
dkato 0:37e1e6a45ced 812 * function or "R_DRIVER_UnlockChannel" function.
dkato 0:37e1e6a45ced 813 * This function calls "R_BSP_HardwareUnlock".
dkato 0:37e1e6a45ced 814 */
dkato 0:37e1e6a45ced 815 errnum_t R_OSPL_UnlockChannel( int_fast32_t ChannelNum, errnum_t e,
dkato 0:37e1e6a45ced 816 mcu_lock_t HardwareIndexMin, mcu_lock_t HardwareIndexMax );
dkato 0:37e1e6a45ced 817
dkato 0:37e1e6a45ced 818
dkato 0:37e1e6a45ced 819 /***********************************************************************
dkato 0:37e1e6a45ced 820 * Class: r_ospl_c_lock_t
dkato 0:37e1e6a45ced 821 ************************************************************************/
dkato 0:37e1e6a45ced 822
dkato 0:37e1e6a45ced 823 /**
dkato 0:37e1e6a45ced 824 * @brief Initializes the C-lock object
dkato 0:37e1e6a45ced 825 *
dkato 0:37e1e6a45ced 826 * @param self C-lock object
dkato 0:37e1e6a45ced 827 * @return None
dkato 0:37e1e6a45ced 828 *
dkato 0:37e1e6a45ced 829 * @par Description
dkato 0:37e1e6a45ced 830 * If *self is global variable or static variable initialized 0,
dkato 0:37e1e6a45ced 831 * this function does not have to be called.
dkato 0:37e1e6a45ced 832 */
dkato 0:37e1e6a45ced 833 void R_OSPL_C_LOCK_InitConst( r_ospl_c_lock_t *const self );
dkato 0:37e1e6a45ced 834
dkato 0:37e1e6a45ced 835
dkato 0:37e1e6a45ced 836 /**
dkato 0:37e1e6a45ced 837 * @brief Locks the target, if lockable state.
dkato 0:37e1e6a45ced 838 *
dkato 0:37e1e6a45ced 839 * @param self C-lock object
dkato 0:37e1e6a45ced 840 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 841 *
dkato 0:37e1e6a45ced 842 * @par Description
dkato 0:37e1e6a45ced 843 * Even if lock owner called this function, if lock object was already
dkato 0:37e1e6a45ced 844 * locked, E_ACCESS_DENIED error is raised.
dkato 0:37e1e6a45ced 845 *
dkato 0:37e1e6a45ced 846 * "R_OSPL_C_LOCK_Lock" does not do exclusive control.
dkato 0:37e1e6a45ced 847 */
dkato 0:37e1e6a45ced 848 errnum_t R_OSPL_C_LOCK_Lock( r_ospl_c_lock_t *const self );
dkato 0:37e1e6a45ced 849
dkato 0:37e1e6a45ced 850
dkato 0:37e1e6a45ced 851 /**
dkato 0:37e1e6a45ced 852 * @brief Unlocks the target.
dkato 0:37e1e6a45ced 853 *
dkato 0:37e1e6a45ced 854 * @param self C-lock object
dkato 0:37e1e6a45ced 855 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 856 *
dkato 0:37e1e6a45ced 857 * @par Description
dkato 0:37e1e6a45ced 858 * If this function was called with unlocked object, this function
dkato 0:37e1e6a45ced 859 * does nothing and raises "E_ACCESS_DENIED" error.
dkato 0:37e1e6a45ced 860 *
dkato 0:37e1e6a45ced 861 * If self == NULL, this function does nothing and raises no error.
dkato 0:37e1e6a45ced 862 * E_NOT_THREAD error is raised, if this function was called from the
dkato 0:37e1e6a45ced 863 * interrupt context.
dkato 0:37e1e6a45ced 864 *
dkato 0:37e1e6a45ced 865 * - I - lock does not do in this function.
dkato 0:37e1e6a45ced 866 *
dkato 0:37e1e6a45ced 867 * "R_OSPL_C_LOCK_Unlock" does not do exclusive control.
dkato 0:37e1e6a45ced 868 */
dkato 0:37e1e6a45ced 869 errnum_t R_OSPL_C_LOCK_Unlock( r_ospl_c_lock_t *const self );
dkato 0:37e1e6a45ced 870
dkato 0:37e1e6a45ced 871
dkato 0:37e1e6a45ced 872 /***********************************************************************
dkato 0:37e1e6a45ced 873 * Class: r_ospl_i_lock_vtable_t
dkato 0:37e1e6a45ced 874 ************************************************************************/
dkato 0:37e1e6a45ced 875
dkato 0:37e1e6a45ced 876 /**
dkato 0:37e1e6a45ced 877 * @brief Do nothing. This is registered to r_ospl_i_lock_vtable_t::Lock.
dkato 0:37e1e6a45ced 878 *
dkato 0:37e1e6a45ced 879 * @param self_ I-lock object
dkato 0:37e1e6a45ced 880 * @return false
dkato 0:37e1e6a45ced 881 */
dkato 0:37e1e6a45ced 882 bool_t R_OSPL_I_LOCK_LockStub( void *const self_ );
dkato 0:37e1e6a45ced 883
dkato 0:37e1e6a45ced 884
dkato 0:37e1e6a45ced 885 /**
dkato 0:37e1e6a45ced 886 * @brief Do nothing. This is registered to r_ospl_i_lock_vtable_t::Unlock.
dkato 0:37e1e6a45ced 887 *
dkato 0:37e1e6a45ced 888 * @param self_ I-lock object
dkato 0:37e1e6a45ced 889 * @return None
dkato 0:37e1e6a45ced 890 */
dkato 0:37e1e6a45ced 891 void R_OSPL_I_LOCK_UnlockStub( void *const self_ );
dkato 0:37e1e6a45ced 892
dkato 0:37e1e6a45ced 893
dkato 0:37e1e6a45ced 894 /**
dkato 0:37e1e6a45ced 895 * @brief Do nothing. This is registered to r_ospl_i_lock_vtable_t::RequestFinalize.
dkato 0:37e1e6a45ced 896 *
dkato 0:37e1e6a45ced 897 * @param self_ I-lock object
dkato 0:37e1e6a45ced 898 * @return None
dkato 0:37e1e6a45ced 899 */
dkato 0:37e1e6a45ced 900 void R_OSPL_I_LOCK_RequestFinalizeStub( void *const self_ );
dkato 0:37e1e6a45ced 901
dkato 0:37e1e6a45ced 902
dkato 0:37e1e6a45ced 903 /**
dkato 0:37e1e6a45ced 904 * @brief Get root channel number
dkato 0:37e1e6a45ced 905 *
dkato 0:37e1e6a45ced 906 * @param self <r_ospl_caller_t> object
dkato 0:37e1e6a45ced 907 * @return Root channel number
dkato 0:37e1e6a45ced 908 */
dkato 0:37e1e6a45ced 909 INLINE int_fast32_t R_OSPL_CALLER_GetRootChannelNum( const r_ospl_caller_t *const self )
dkato 0:37e1e6a45ced 910 {
dkato 0:37e1e6a45ced 911 int_fast32_t root_channel_num;
dkato 0:37e1e6a45ced 912
dkato 0:37e1e6a45ced 913 IF_DQ( self == NULL ) {
dkato 0:37e1e6a45ced 914 root_channel_num = 0;
dkato 0:37e1e6a45ced 915 }
dkato 0:37e1e6a45ced 916 else {
dkato 0:37e1e6a45ced 917 root_channel_num = self->I_LockVTable->GetRootChannelNum( self->I_Lock );
dkato 0:37e1e6a45ced 918 }
dkato 0:37e1e6a45ced 919
dkato 0:37e1e6a45ced 920 return root_channel_num;
dkato 0:37e1e6a45ced 921 }
dkato 0:37e1e6a45ced 922
dkato 0:37e1e6a45ced 923
dkato 0:37e1e6a45ced 924 /* Section: Memory Operation */
dkato 0:37e1e6a45ced 925 /**
dkato 0:37e1e6a45ced 926 * @brief Flushes cache memory
dkato 0:37e1e6a45ced 927 *
dkato 0:37e1e6a45ced 928 * @param FlushType The operation of flush
dkato 0:37e1e6a45ced 929 * @return None
dkato 0:37e1e6a45ced 930 *
dkato 0:37e1e6a45ced 931 * @par Description
dkato 0:37e1e6a45ced 932 * Call the function of the driver after flushing input output buffer
dkato 0:37e1e6a45ced 933 * in the cache memory, If the data area accessing by the hardware is
dkato 0:37e1e6a45ced 934 * on cache and the driver did not manage the cache memory.
dkato 0:37e1e6a45ced 935 * Whether the driver manages the cache memory is depend on the driver
dkato 0:37e1e6a45ced 936 * specification.
dkato 0:37e1e6a45ced 937 */
dkato 0:37e1e6a45ced 938 void R_OSPL_MEMORY_Flush( r_ospl_flush_t const FlushType );
dkato 0:37e1e6a45ced 939
dkato 0:37e1e6a45ced 940
dkato 0:37e1e6a45ced 941 /**
dkato 0:37e1e6a45ced 942 * @brief Flushes cache memory with the range of virtual address.
dkato 0:37e1e6a45ced 943 *
dkato 0:37e1e6a45ced 944 * @param FlushType The operation of flush
dkato 0:37e1e6a45ced 945 * @return None
dkato 0:37e1e6a45ced 946 *
dkato 0:37e1e6a45ced 947 * @par Description
dkato 0:37e1e6a45ced 948 * Align "StartAddress" argument and "Length" argument to cache line size.
dkato 0:37e1e6a45ced 949 * If not aligned, E_OTHERS error is raised.
dkato 0:37e1e6a45ced 950 * Refer to : R_OSPL_MEMORY_GetSpecification
dkato 0:37e1e6a45ced 951 *
dkato 0:37e1e6a45ced 952 * If the data area written by the hardware and read from CPU was in cache
dkato 0:37e1e6a45ced 953 * rea, when the hardware started without invalidate
dkato 0:37e1e6a45ced 954 * ("R_OSPL_FLUSH_WRITEBACK_INVALIDATE" or "R_OSPL_FLUSH_INVALIDATE"),
dkato 0:37e1e6a45ced 955 * invalidate the data area and read it after finished to write by hardware.
dkato 0:37e1e6a45ced 956 * (If the driver does not manage the cache memory.)
dkato 0:37e1e6a45ced 957 */
dkato 0:37e1e6a45ced 958 errnum_t R_OSPL_MEMORY_RangeFlush( r_ospl_flush_t const FlushType,
dkato 0:37e1e6a45ced 959 const void *const StartAddress, size_t const Length );
dkato 0:37e1e6a45ced 960
dkato 0:37e1e6a45ced 961
dkato 0:37e1e6a45ced 962 /**
dkato 0:37e1e6a45ced 963 * @brief Gets the specification about memory and cache memory.
dkato 0:37e1e6a45ced 964 *
dkato 0:37e1e6a45ced 965 * @param out_MemorySpec The specification about memory and cache memory
dkato 0:37e1e6a45ced 966 * @return None
dkato 0:37e1e6a45ced 967 */
dkato 0:37e1e6a45ced 968 void R_OSPL_MEMORY_GetSpecification( r_ospl_memory_spec_t *const out_MemorySpec );
dkato 0:37e1e6a45ced 969
dkato 0:37e1e6a45ced 970
dkato 0:37e1e6a45ced 971 /**
dkato 0:37e1e6a45ced 972 * @brief Set a memory barrier.
dkato 0:37e1e6a45ced 973 *
dkato 0:37e1e6a45ced 974 * @par Parameters
dkato 0:37e1e6a45ced 975 * None
dkato 0:37e1e6a45ced 976 * @return None
dkato 0:37e1e6a45ced 977 *
dkato 0:37e1e6a45ced 978 * @par Description
dkato 0:37e1e6a45ced 979 * In ARM, This function calls DSB assembler operation.
dkato 0:37e1e6a45ced 980 * This effects to L1 cache only.
dkato 0:37e1e6a45ced 981 */
dkato 0:37e1e6a45ced 982 void R_OSPL_MEMORY_Barrier(void);
dkato 0:37e1e6a45ced 983
dkato 0:37e1e6a45ced 984
dkato 0:37e1e6a45ced 985 /**
dkato 0:37e1e6a45ced 986 * @brief Set a instruction barrier.
dkato 0:37e1e6a45ced 987 *
dkato 0:37e1e6a45ced 988 * @par Parameters
dkato 0:37e1e6a45ced 989 * None
dkato 0:37e1e6a45ced 990 * @return None
dkato 0:37e1e6a45ced 991 *
dkato 0:37e1e6a45ced 992 * @par Description
dkato 0:37e1e6a45ced 993 * In ARM, This function calls ISB assembler operation.
dkato 0:37e1e6a45ced 994 */
dkato 0:37e1e6a45ced 995 void R_OSPL_InstructionSyncBarrier(void);
dkato 0:37e1e6a45ced 996
dkato 0:37e1e6a45ced 997
dkato 0:37e1e6a45ced 998 /**
dkato 0:37e1e6a45ced 999 * @brief Changes to physical address
dkato 0:37e1e6a45ced 1000 *
dkato 0:37e1e6a45ced 1001 * @param Address Virtual address
dkato 0:37e1e6a45ced 1002 * @param out_PhysicalAddress Output: Physical address
dkato 0:37e1e6a45ced 1003 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1004 *
dkato 0:37e1e6a45ced 1005 * @par Description
dkato 0:37e1e6a45ced 1006 * This function must be modified by MMU setting.
dkato 0:37e1e6a45ced 1007 */
dkato 0:37e1e6a45ced 1008 errnum_t R_OSPL_ToPhysicalAddress( const volatile void *const Address, uintptr_t *const out_PhysicalAddress );
dkato 0:37e1e6a45ced 1009
dkato 0:37e1e6a45ced 1010
dkato 0:37e1e6a45ced 1011 /**
dkato 0:37e1e6a45ced 1012 * @brief Changes to the address in the L1 cache area
dkato 0:37e1e6a45ced 1013 *
dkato 0:37e1e6a45ced 1014 * @param Address Virtual address
dkato 0:37e1e6a45ced 1015 * @param out_CachedAddress Output: Virtual address for cached area
dkato 0:37e1e6a45ced 1016 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1017 *
dkato 0:37e1e6a45ced 1018 * @par Description
dkato 0:37e1e6a45ced 1019 * This function must be modified by MMU setting.
1050186 3:9f857750e4e9 1020 * If "E_ACCESS_DENIED" error was raised, you may know the variable by
1050186 3:9f857750e4e9 1021 * looking at value of "Address" argument and map file.
dkato 0:37e1e6a45ced 1022 */
dkato 0:37e1e6a45ced 1023 errnum_t R_OSPL_ToCachedAddress( const volatile void *const Address, void *const out_CachedAddress );
dkato 0:37e1e6a45ced 1024
dkato 0:37e1e6a45ced 1025
dkato 0:37e1e6a45ced 1026 /**
dkato 0:37e1e6a45ced 1027 * @brief Changes to the address in the L1 uncached area
dkato 0:37e1e6a45ced 1028 *
dkato 0:37e1e6a45ced 1029 * @param Address Virtual address
dkato 0:37e1e6a45ced 1030 * @param out_UncachedAddress Output: Virtual address for uncached area
dkato 0:37e1e6a45ced 1031 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1032 *
dkato 0:37e1e6a45ced 1033 * @par Description
dkato 0:37e1e6a45ced 1034 * This function must be modified by MMU setting.
1050186 3:9f857750e4e9 1035 * If "E_ACCESS_DENIED" error was raised, you may know the variable by
1050186 3:9f857750e4e9 1036 * looking at value of "Address" argument and map file.
dkato 0:37e1e6a45ced 1037 */
dkato 0:37e1e6a45ced 1038 errnum_t R_OSPL_ToUncachedAddress( const volatile void *const Address, void *const out_UncachedAddress );
dkato 0:37e1e6a45ced 1039
dkato 0:37e1e6a45ced 1040
dkato 0:37e1e6a45ced 1041 /**
dkato 0:37e1e6a45ced 1042 * @brief Gets the level of cache for flushing the memory indicated by the address.
dkato 0:37e1e6a45ced 1043 *
dkato 0:37e1e6a45ced 1044 * @param Address The address in flushing memory
dkato 0:37e1e6a45ced 1045 * @param out_Level Output: 0=Not need to flush, 1=L1 cache only, 2=both of L1 and L2 cache
dkato 0:37e1e6a45ced 1046 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1047 */
dkato 0:37e1e6a45ced 1048 errnum_t R_OSPL_MEMORY_GetLevelOfFlush( const void *Address, int_fast32_t *out_Level );
dkato 0:37e1e6a45ced 1049
dkato 0:37e1e6a45ced 1050
dkato 0:37e1e6a45ced 1051 /**
dkato 0:37e1e6a45ced 1052 * @brief Get 2nd cache attribute of AXI bus for peripheral (not CPU) from physical address.
dkato 0:37e1e6a45ced 1053 *
dkato 0:37e1e6a45ced 1054 * @param PhysicalAddress The physical address in the memory area
dkato 0:37e1e6a45ced 1055 * @param out_CacheAttribute Output: Cache_attribute, AWCACHE[3:0], ARCACHE[3:0]
dkato 0:37e1e6a45ced 1056 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1057 */
dkato 0:37e1e6a45ced 1058 errnum_t R_OSPL_AXI_Get2ndCacheAttribute( uintptr_t const PhysicalAddress,
dkato 0:37e1e6a45ced 1059 r_ospl_axi_cache_attribute_t *const out_CacheAttribute );
dkato 0:37e1e6a45ced 1060
dkato 0:37e1e6a45ced 1061
dkato 0:37e1e6a45ced 1062 /**
dkato 0:37e1e6a45ced 1063 * @brief Gets protection attribute of AXI bus from the address
dkato 0:37e1e6a45ced 1064 *
dkato 0:37e1e6a45ced 1065 * @param PhysicalAddress The physical address in the memory area
dkato 0:37e1e6a45ced 1066 * @param out_CacheAttribute Output: The protection attribute of AXI bus AWPROT[2:0], ARPROT[2:0]
dkato 0:37e1e6a45ced 1067 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1068 */
dkato 0:37e1e6a45ced 1069 errnum_t R_OSPL_AXI_GetProtection( uintptr_t const physical_address,
dkato 0:37e1e6a45ced 1070 r_ospl_axi_protection_t *const out_protection );
dkato 0:37e1e6a45ced 1071
dkato 0:37e1e6a45ced 1072
dkato 0:37e1e6a45ced 1073 /* Section: Timer */
dkato 0:37e1e6a45ced 1074 /**
dkato 0:37e1e6a45ced 1075 * @brief Waits for a while until passed time
dkato 0:37e1e6a45ced 1076 *
dkato 0:37e1e6a45ced 1077 * @param DelayTime_msec Time of waiting (millisecond)
dkato 0:37e1e6a45ced 1078 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1079 *
dkato 0:37e1e6a45ced 1080 * @par Description
dkato 0:37e1e6a45ced 1081 * Maximum value is "R_OSPL_MAX_TIME_OUT" (=65533).
dkato 0:37e1e6a45ced 1082 */
dkato 0:37e1e6a45ced 1083 errnum_t R_OSPL_Delay( uint32_t const DelayTime_msec );
dkato 0:37e1e6a45ced 1084
dkato 0:37e1e6a45ced 1085
dkato 0:37e1e6a45ced 1086 /**
dkato 0:37e1e6a45ced 1087 * @brief Set up the free running timer
dkato 0:37e1e6a45ced 1088 *
dkato 0:37e1e6a45ced 1089 * @param out_Specification NULL is permitted. Output: The precision of the free run timer
dkato 0:37e1e6a45ced 1090 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1091 *
dkato 0:37e1e6a45ced 1092 * @par Description
dkato 0:37e1e6a45ced 1093 * The free running timer does not stop.
dkato 0:37e1e6a45ced 1094 *
dkato 0:37e1e6a45ced 1095 * If the counter of the free running timer was overflow, the counter returns to 0.
dkato 0:37e1e6a45ced 1096 * Even in interrupt handler, the counter does count up.
dkato 0:37e1e6a45ced 1097 * OSPL free running timer does not use any interrupt.
dkato 0:37e1e6a45ced 1098 *
dkato 0:37e1e6a45ced 1099 * Using timer can be selected by "R_OSPL_FTIMER_IS" macro.
dkato 0:37e1e6a45ced 1100 *
dkato 0:37e1e6a45ced 1101 * If the free running timer was already set up, this function does not set up it,
dkato 0:37e1e6a45ced 1102 * outputs to "out_Specification" argument and does not raise any error.
dkato 0:37e1e6a45ced 1103 *
dkato 0:37e1e6a45ced 1104 * When OSPL API function with timeout or "R_OSPL_Delay" function was called,
dkato 0:37e1e6a45ced 1105 * "R_OSPL_FTIMER_InitializeIfNot" function is callbacked from these functions.
dkato 0:37e1e6a45ced 1106 *
dkato 0:37e1e6a45ced 1107 * There is all interrupt disabled area inside.
dkato 0:37e1e6a45ced 1108 */
dkato 0:37e1e6a45ced 1109 errnum_t R_OSPL_FTIMER_InitializeIfNot( r_ospl_ftimer_spec_t *const out_Specification );
dkato 0:37e1e6a45ced 1110
dkato 0:37e1e6a45ced 1111
dkato 0:37e1e6a45ced 1112 /**
dkato 0:37e1e6a45ced 1113 * @brief Gets the specification of free running timer.
dkato 0:37e1e6a45ced 1114 *
dkato 0:37e1e6a45ced 1115 * @param out_Specification Output: The precision of the free run timer
dkato 0:37e1e6a45ced 1116 * @return None
dkato 0:37e1e6a45ced 1117 */
dkato 0:37e1e6a45ced 1118 void R_OSPL_FTIMER_GetSpecification( r_ospl_ftimer_spec_t *const out_Specification );
dkato 0:37e1e6a45ced 1119
dkato 0:37e1e6a45ced 1120
dkato 0:37e1e6a45ced 1121 /**
dkato 0:37e1e6a45ced 1122 * @brief Get current time of free running timer.
dkato 0:37e1e6a45ced 1123 *
dkato 0:37e1e6a45ced 1124 * @par Parameters
dkato 0:37e1e6a45ced 1125 * None
dkato 0:37e1e6a45ced 1126 * @return The current clock count of free run timer
dkato 0:37e1e6a45ced 1127 *
dkato 0:37e1e6a45ced 1128 * @par Description
dkato 0:37e1e6a45ced 1129 * Call "R_OSPL_FTIMER_InitializeIfNot" function before calling this function.
dkato 0:37e1e6a45ced 1130 * Call "R_OSPL_FTIMER_IsPast" function, when it is determined whether time passed.
dkato 0:37e1e6a45ced 1131 *
dkato 0:37e1e6a45ced 1132 * @par Example
dkato 0:37e1e6a45ced 1133 * @code
dkato 0:37e1e6a45ced 1134 * errnum_t e;
dkato 0:37e1e6a45ced 1135 * r_ospl_ftimer_spec_t ts;
dkato 0:37e1e6a45ced 1136 * uint32_t start;
dkato 0:37e1e6a45ced 1137 * uint32_t end;
dkato 0:37e1e6a45ced 1138 *
dkato 0:37e1e6a45ced 1139 * e= R_OSPL_FTIMER_InitializeIfNot( &ts ); IF(e){goto fin;}
dkato 0:37e1e6a45ced 1140 * start = R_OSPL_FTIMER_Get();
dkato 0:37e1e6a45ced 1141 *
dkato 0:37e1e6a45ced 1142 * // The section of measuring
dkato 0:37e1e6a45ced 1143 *
dkato 0:37e1e6a45ced 1144 * end = R_OSPL_FTIMER_Get();
dkato 0:37e1e6a45ced 1145 * printf( "%d msec\n", R_OSPL_FTIMER_CountToTime(
dkato 0:37e1e6a45ced 1146 * &ts, end - start ) );
dkato 0:37e1e6a45ced 1147 * @endcode
dkato 0:37e1e6a45ced 1148 */
dkato 0:37e1e6a45ced 1149 uint32_t R_OSPL_FTIMER_Get(void);
dkato 0:37e1e6a45ced 1150
dkato 0:37e1e6a45ced 1151
dkato 0:37e1e6a45ced 1152 /**
dkato 0:37e1e6a45ced 1153 * @brief Returns whether specified time was passed
dkato 0:37e1e6a45ced 1154 *
dkato 0:37e1e6a45ced 1155 * @param ts Precision of the free running timer
dkato 0:37e1e6a45ced 1156 * @param Now Count of current time
dkato 0:37e1e6a45ced 1157 * @param TargetTime Count of target time
dkato 0:37e1e6a45ced 1158 * @param out_IsPast Output: Whether the target time was past or not
dkato 0:37e1e6a45ced 1159 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1160 */
dkato 0:37e1e6a45ced 1161 errnum_t R_OSPL_FTIMER_IsPast( const r_ospl_ftimer_spec_t *const ts,
dkato 0:37e1e6a45ced 1162 uint32_t const Now, uint32_t const TargetTime, bool_t *const out_IsPast );
dkato 0:37e1e6a45ced 1163
dkato 0:37e1e6a45ced 1164
dkato 0:37e1e6a45ced 1165 /**
dkato 0:37e1e6a45ced 1166 * @brief Change from mili-second unit to free running timer unit
dkato 0:37e1e6a45ced 1167 *
dkato 0:37e1e6a45ced 1168 * @param ts Precision of the free running timer
dkato 0:37e1e6a45ced 1169 * @param msec The value of mili-second unit
dkato 0:37e1e6a45ced 1170 * @return The value of free running timer unit
dkato 0:37e1e6a45ced 1171 *
dkato 0:37e1e6a45ced 1172 * @par Description
dkato 0:37e1e6a45ced 1173 * The fractional part is been round up. (For waiting time must be more
dkato 0:37e1e6a45ced 1174 * than specified time.)
dkato 0:37e1e6a45ced 1175 *
dkato 0:37e1e6a45ced 1176 * This function calculates like the following formula.
dkato 0:37e1e6a45ced 1177 * @code
dkato 0:37e1e6a45ced 1178 * ( msec * ts->msec_Denominator + ts->msec_Numerator - 1 ) / ts->msec_Numerator
dkato 0:37e1e6a45ced 1179 * @endcode
dkato 0:37e1e6a45ced 1180 *
dkato 0:37e1e6a45ced 1181 * - Attention: If "ts - >msec_Denominator" was more than "ts->msec_Numerator",
dkato 0:37e1e6a45ced 1182 * take care of overflow.
dkato 0:37e1e6a45ced 1183 */
dkato 0:37e1e6a45ced 1184 INLINE uint32_t R_OSPL_FTIMER_TimeToCount( const r_ospl_ftimer_spec_t *const ts,
dkato 0:37e1e6a45ced 1185 uint32_t const msec )
dkato 0:37e1e6a45ced 1186 {
dkato 0:37e1e6a45ced 1187 uint32_t count;
dkato 0:37e1e6a45ced 1188
dkato 0:37e1e6a45ced 1189 IF_DQ( ts == NULL ) {
dkato 0:37e1e6a45ced 1190 count = 0;
dkato 0:37e1e6a45ced 1191 }
dkato 0:37e1e6a45ced 1192 else {
dkato 0:37e1e6a45ced 1193 count = ( ((msec * ts->msec_Denominator) + ts->msec_Numerator) - 1u ) / ts->msec_Numerator;
dkato 0:37e1e6a45ced 1194 }
dkato 0:37e1e6a45ced 1195 return count;
dkato 0:37e1e6a45ced 1196 }
dkato 0:37e1e6a45ced 1197
dkato 0:37e1e6a45ced 1198
dkato 0:37e1e6a45ced 1199 /**
dkato 0:37e1e6a45ced 1200 * @brief Change from free running timer unit to mili-second unit
dkato 0:37e1e6a45ced 1201 *
dkato 0:37e1e6a45ced 1202 * @param ts Precision of the free running timer
dkato 0:37e1e6a45ced 1203 * @param Count The value of free running timer unit
dkato 0:37e1e6a45ced 1204 * @return The value of mili-second unit
dkato 0:37e1e6a45ced 1205 *
dkato 0:37e1e6a45ced 1206 * @par Description
dkato 0:37e1e6a45ced 1207 * The fractional part is been round down. (Because overflow does not
dkato 0:37e1e6a45ced 1208 * occur, when "Count = r_ospl_ftimer_spec_t::MaxCount" )
dkato 0:37e1e6a45ced 1209 *
dkato 0:37e1e6a45ced 1210 * This function calculates like the following formula.
dkato 0:37e1e6a45ced 1211 * @code
dkato 0:37e1e6a45ced 1212 * ( Count * ts->msec_Numerator ) / ts->msec_Denominator
dkato 0:37e1e6a45ced 1213 * @endcode
dkato 0:37e1e6a45ced 1214 */
dkato 0:37e1e6a45ced 1215 INLINE uint32_t R_OSPL_FTIMER_CountToTime( const r_ospl_ftimer_spec_t *const ts,
dkato 0:37e1e6a45ced 1216 uint32_t const Count )
dkato 0:37e1e6a45ced 1217 {
dkato 0:37e1e6a45ced 1218 uint32_t time;
dkato 0:37e1e6a45ced 1219
dkato 0:37e1e6a45ced 1220 IF_DQ( ts == NULL ) {
dkato 0:37e1e6a45ced 1221 time = 0;
dkato 0:37e1e6a45ced 1222 }
dkato 0:37e1e6a45ced 1223 else {
dkato 0:37e1e6a45ced 1224 time = ( Count * ts->msec_Numerator ) / ts->msec_Denominator;
dkato 0:37e1e6a45ced 1225 }
dkato 0:37e1e6a45ced 1226 return time;
dkato 0:37e1e6a45ced 1227 }
dkato 0:37e1e6a45ced 1228
dkato 0:37e1e6a45ced 1229
dkato 0:37e1e6a45ced 1230 /***********************************************************************
dkato 0:37e1e6a45ced 1231 * Class: r_ospl_table_t
dkato 0:37e1e6a45ced 1232 ************************************************************************/
dkato 0:37e1e6a45ced 1233
dkato 0:37e1e6a45ced 1234 /**
dkato 0:37e1e6a45ced 1235 * @brief Initializes an index table
dkato 0:37e1e6a45ced 1236 *
dkato 0:37e1e6a45ced 1237 * @param self Index table object
dkato 0:37e1e6a45ced 1238 * @param Area First address of the index table
dkato 0:37e1e6a45ced 1239 * @param AreaByteSize Size of the index table. See <R_OSPL_TABLE_SIZE>
dkato 0:37e1e6a45ced 1240 * @param Is_T_Lock Whether to call <R_OSPL_Start_T_Lock>
dkato 0:37e1e6a45ced 1241 * @return None
dkato 0:37e1e6a45ced 1242 */
dkato 0:37e1e6a45ced 1243 void R_OSPL_TABLE_InitConst( r_ospl_table_t *const self,
dkato 0:37e1e6a45ced 1244 void *const Area, size_t const AreaByteSize, bool_t const Is_T_Lock );
dkato 0:37e1e6a45ced 1245
dkato 0:37e1e6a45ced 1246
dkato 0:37e1e6a45ced 1247 /**
dkato 0:37e1e6a45ced 1248 * @brief Returns index from related key
dkato 0:37e1e6a45ced 1249 *
dkato 0:37e1e6a45ced 1250 * @param self Index table object
dkato 0:37e1e6a45ced 1251 * @param Key Key number
dkato 0:37e1e6a45ced 1252 * @param out_Index Output: Related index
dkato 0:37e1e6a45ced 1253 * @param TypeOfIfNot Behavior when key was not registerd. See <r_ospl_if_not_t>
dkato 0:37e1e6a45ced 1254 * @return Error code. If there is no error, the return value is 0.
dkato 0:37e1e6a45ced 1255 */
dkato 0:37e1e6a45ced 1256 errnum_t R_OSPL_TABLE_GetIndex( r_ospl_table_t *const self, const void *const Key,
dkato 0:37e1e6a45ced 1257 int_fast32_t *const out_Index, r_ospl_if_not_t const TypeOfIfNot );
dkato 0:37e1e6a45ced 1258
dkato 0:37e1e6a45ced 1259
dkato 0:37e1e6a45ced 1260 /**
dkato 0:37e1e6a45ced 1261 * @brief Separates relationship of specified key and related index
dkato 0:37e1e6a45ced 1262 *
dkato 0:37e1e6a45ced 1263 * @param self Index table object
dkato 0:37e1e6a45ced 1264 * @param Key Key number
dkato 0:37e1e6a45ced 1265 * @return None
dkato 0:37e1e6a45ced 1266 *
dkato 0:37e1e6a45ced 1267 * @par Description
dkato 0:37e1e6a45ced 1268 * Error is not raised, even if specified key was already separated.
dkato 0:37e1e6a45ced 1269 */
dkato 0:37e1e6a45ced 1270 void R_OSPL_TABLE_Free( r_ospl_table_t *const self, const void *const Key );
dkato 0:37e1e6a45ced 1271
dkato 0:37e1e6a45ced 1272
dkato 0:37e1e6a45ced 1273 /**
dkato 0:37e1e6a45ced 1274 * @brief Print status of specified index table object (for debug)
dkato 0:37e1e6a45ced 1275 *
dkato 0:37e1e6a45ced 1276 * @param self Index table object
dkato 0:37e1e6a45ced 1277 * @return None
dkato 0:37e1e6a45ced 1278 */
dkato 0:37e1e6a45ced 1279 #if R_OSPL_DEBUG_TOOL
dkato 0:37e1e6a45ced 1280 void R_OSPL_TABLE_Print( r_ospl_table_t *const self );
dkato 0:37e1e6a45ced 1281 #endif
dkato 0:37e1e6a45ced 1282
dkato 0:37e1e6a45ced 1283
dkato 0:37e1e6a45ced 1284 /* Section: Bit flags */
dkato 0:37e1e6a45ced 1285 /**
dkato 0:37e1e6a45ced 1286 * @brief Evaluate whether any passed bits are 1 or not
dkato 0:37e1e6a45ced 1287 *
dkato 0:37e1e6a45ced 1288 * @param Variable The value of target bit flags
dkato 0:37e1e6a45ced 1289 * @param ConstValue The value that investigating bits are 1
dkato 0:37e1e6a45ced 1290 * @return Whether the any passed bit are 1
dkato 0:37e1e6a45ced 1291 */
dkato 0:37e1e6a45ced 1292 /* ->MISRA 19.7 : For return _Bool type */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 1293 #define IS_BIT_SET( Variable, ConstValue ) \
dkato 0:37e1e6a45ced 1294 ( BIT_And_Sub( Variable, ConstValue ) != 0u )
dkato 0:37e1e6a45ced 1295 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 1296
dkato 0:37e1e6a45ced 1297
dkato 0:37e1e6a45ced 1298 /**
dkato 0:37e1e6a45ced 1299 * @brief Evaluate whether any passed bits are 1 or not
dkato 0:37e1e6a45ced 1300 *
dkato 0:37e1e6a45ced 1301 * @param Variable The value of target bit flags
dkato 0:37e1e6a45ced 1302 * @param OrConstValue The value that investigating bits are 1
dkato 0:37e1e6a45ced 1303 * @return Whether the any passed bit are 1
dkato 0:37e1e6a45ced 1304 */
dkato 0:37e1e6a45ced 1305 /* ->MISRA 19.7 : For return _Bool type */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 1306 #define IS_ANY_BITS_SET( Variable, OrConstValue ) \
dkato 0:37e1e6a45ced 1307 ( BIT_And_Sub( Variable, OrConstValue ) != 0u )
dkato 0:37e1e6a45ced 1308 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 1309
dkato 0:37e1e6a45ced 1310
dkato 0:37e1e6a45ced 1311 /**
dkato 0:37e1e6a45ced 1312 * @brief Evaluate whether all passed bits are 1 or not
dkato 0:37e1e6a45ced 1313 *
dkato 0:37e1e6a45ced 1314 * @param Variable The value of target bit flags
dkato 0:37e1e6a45ced 1315 * @param OrConstValue The value that investigating bits are 1
dkato 0:37e1e6a45ced 1316 * @return Whether the all passed bit are 1
dkato 0:37e1e6a45ced 1317 */
dkato 0:37e1e6a45ced 1318 /* ->MISRA 19.7 : For return _Bool type */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 1319 #define IS_ALL_BITS_SET( Variable, OrConstValue ) \
dkato 0:37e1e6a45ced 1320 ( BIT_And_Sub( Variable, OrConstValue ) == (OrConstValue) )
dkato 0:37e1e6a45ced 1321 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 1322
dkato 0:37e1e6a45ced 1323
dkato 0:37e1e6a45ced 1324 /**
dkato 0:37e1e6a45ced 1325 * @brief Evaluate whether the passed bit is 0 or not
dkato 0:37e1e6a45ced 1326 *
dkato 0:37e1e6a45ced 1327 * @param Variable The value of target bit flags
dkato 0:37e1e6a45ced 1328 * @param ConstValue The value that investigating bit is 1
dkato 0:37e1e6a45ced 1329 * @return Whether the passed bit is 0
dkato 0:37e1e6a45ced 1330 */
dkato 0:37e1e6a45ced 1331 /* ->MISRA 19.7 : For return _Bool type */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 1332 #define IS_BIT_NOT_SET( Variable, ConstValue ) \
dkato 0:37e1e6a45ced 1333 ( BIT_And_Sub( Variable, ConstValue ) == 0u )
dkato 0:37e1e6a45ced 1334 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 1335
dkato 0:37e1e6a45ced 1336
dkato 0:37e1e6a45ced 1337 /**
dkato 0:37e1e6a45ced 1338 * @brief Evaluate whether any passed bits are 0 or not
dkato 0:37e1e6a45ced 1339 *
dkato 0:37e1e6a45ced 1340 * @param Variable The value of target bit flags
dkato 0:37e1e6a45ced 1341 * @param OrConstValue The value that investigating bits are 1
dkato 0:37e1e6a45ced 1342 * @return Whether the any passed bit are 0
dkato 0:37e1e6a45ced 1343 */
dkato 0:37e1e6a45ced 1344 /* ->MISRA 19.7 : For return _Bool type */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 1345 #define IS_ANY_BITS_NOT_SET( Variable, OrConstValue ) \
dkato 0:37e1e6a45ced 1346 ( BIT_And_Sub( Variable, OrConstValue ) != (OrConstValue) )
dkato 0:37e1e6a45ced 1347 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 1348
dkato 0:37e1e6a45ced 1349
dkato 0:37e1e6a45ced 1350 /**
dkato 0:37e1e6a45ced 1351 * @brief Evaluate whether all passed bits are 0 or not
dkato 0:37e1e6a45ced 1352 *
dkato 0:37e1e6a45ced 1353 * @param Variable The value of target bit flags
dkato 0:37e1e6a45ced 1354 * @param OrConstValue The value that investigating bits are 1
dkato 0:37e1e6a45ced 1355 * @return Whether the all passed bit are 0
dkato 0:37e1e6a45ced 1356 */
dkato 0:37e1e6a45ced 1357 /* ->MISRA 19.7 : For return _Bool type */ /* ->SEC M5.1.3 */
dkato 0:37e1e6a45ced 1358 #define IS_ALL_BITS_NOT_SET( Variable, OrConstValue ) \
dkato 0:37e1e6a45ced 1359 ( BIT_And_Sub( Variable, OrConstValue ) == 0u )
dkato 0:37e1e6a45ced 1360 /* <-MISRA 19.7 */ /* <-SEC M5.1.3 */
dkato 0:37e1e6a45ced 1361
dkato 0:37e1e6a45ced 1362
dkato 0:37e1e6a45ced 1363 /**
dkato 0:37e1e6a45ced 1364 * @brief Sub routine of bitwise operation
dkato 0:37e1e6a45ced 1365 *
dkato 0:37e1e6a45ced 1366 * @param Variable The value of target bit flags
dkato 0:37e1e6a45ced 1367 * @param ConstValue The value that investigating bits are 1
dkato 0:37e1e6a45ced 1368 * @return Whether the all passed bit are 0
dkato 0:37e1e6a45ced 1369 *
dkato 0:37e1e6a45ced 1370 * @par Description
dkato 0:37e1e6a45ced 1371 * - This part is for compliant to MISRA 2004 - 19.7.
dkato 0:37e1e6a45ced 1372 */
dkato 0:37e1e6a45ced 1373 INLINE uint_fast32_t BIT_And_Sub( bit_flags_fast32_t const Variable,
dkato 0:37e1e6a45ced 1374 bit_flags_fast32_t const ConstValue )
dkato 0:37e1e6a45ced 1375 {
dkato 0:37e1e6a45ced 1376 return ((Variable) & (ConstValue));
dkato 0:37e1e6a45ced 1377 }
dkato 0:37e1e6a45ced 1378
dkato 0:37e1e6a45ced 1379
dkato 0:37e1e6a45ced 1380 /***********************************************************************
dkato 0:37e1e6a45ced 1381 * About: IS_BIT_SET__Warning
dkato 0:37e1e6a45ced 1382 *
dkato 0:37e1e6a45ced 1383 * - This is for QAC-3344 warning : MISRA 13.2 Advice : Tests of a value against
dkato 0:37e1e6a45ced 1384 * zero should be made explicit, unless the operand is effectively Boolean.
dkato 0:37e1e6a45ced 1385 * - This is for QAC-1253 warning : SEC M1.2.2 : A "U" suffix shall be applied
dkato 0:37e1e6a45ced 1386 * to all constants of unsigned type.
dkato 0:37e1e6a45ced 1387 ************************************************************************/
dkato 0:37e1e6a45ced 1388
dkato 0:37e1e6a45ced 1389
dkato 0:37e1e6a45ced 1390 /* Section: Error handling and debugging (2) */
dkato 0:37e1e6a45ced 1391 /**
dkato 0:37e1e6a45ced 1392 * @brief Breaks here
dkato 0:37e1e6a45ced 1393 *
dkato 0:37e1e6a45ced 1394 * @par Parameters
dkato 0:37e1e6a45ced 1395 * None
dkato 0:37e1e6a45ced 1396 * @return None
dkato 0:37e1e6a45ced 1397 *
dkato 0:37e1e6a45ced 1398 * @par Description
dkato 0:37e1e6a45ced 1399 * Does break by calling "R_DebugBreak" function.
dkato 0:37e1e6a45ced 1400 * This macro is not influenced the setting of "R_OSPL_ERROR_BREAK" macro.
dkato 0:37e1e6a45ced 1401 */
dkato 0:37e1e6a45ced 1402 #define R_DEBUG_BREAK() R_DebugBreak(__FILE__,__LINE__)
dkato 0:37e1e6a45ced 1403
dkato 0:37e1e6a45ced 1404
dkato 0:37e1e6a45ced 1405 /**
dkato 0:37e1e6a45ced 1406 * @brief The function callbacked from OSPL for breaking
dkato 0:37e1e6a45ced 1407 *
dkato 0:37e1e6a45ced 1408 * @param Variable The value of target bit flags
dkato 0:37e1e6a45ced 1409 * @param ConstValue The value that investigating bits are 1
dkato 0:37e1e6a45ced 1410 * @return Whether the all passed bit are 0
dkato 0:37e1e6a45ced 1411 *
dkato 0:37e1e6a45ced 1412 * @par Description
dkato 0:37e1e6a45ced 1413 * Set a break point at this function.
dkato 0:37e1e6a45ced 1414 * In Release configuration, "File = NULL, Line = 0".
dkato 0:37e1e6a45ced 1415 * If "File = NULL", "Line" argument is error code.
dkato 0:37e1e6a45ced 1416 * This function can be customized by application developer.
dkato 0:37e1e6a45ced 1417 */
dkato 0:37e1e6a45ced 1418 void R_DebugBreak( const char_t *const File, int_fast32_t const Line );
dkato 0:37e1e6a45ced 1419
dkato 0:37e1e6a45ced 1420
dkato 0:37e1e6a45ced 1421 /**
dkato 0:37e1e6a45ced 1422 * @brief Breaks here, if it is error state
dkato 0:37e1e6a45ced 1423 *
dkato 0:37e1e6a45ced 1424 * @par Parameters
dkato 0:37e1e6a45ced 1425 * None
dkato 0:37e1e6a45ced 1426 * @return None
dkato 0:37e1e6a45ced 1427 *
dkato 0:37e1e6a45ced 1428 * @par Description
dkato 0:37e1e6a45ced 1429 * This function does nothing, if "R_OSPL_ERROR_BREAK" macro was defined
dkato 0:37e1e6a45ced 1430 * to be 0. The following descriptions are available, if "R_OSPL_ERROR_BREAK"
dkato 0:37e1e6a45ced 1431 * macro was defined to be 1.
dkato 0:37e1e6a45ced 1432 *
dkato 0:37e1e6a45ced 1433 * Checks the error state of the current thread.
dkato 0:37e1e6a45ced 1434 * Call this macro from the last of each thread.
dkato 0:37e1e6a45ced 1435 * Does break by calling "R_DebugBreak" function.
dkato 0:37e1e6a45ced 1436 *
dkato 0:37e1e6a45ced 1437 * If an error was raised, this function calls "printf" with following message.
dkato 0:37e1e6a45ced 1438 * Set "error_ID" to "R_OSPL_SET_BREAK_ERROR_ID"
dkato 0:37e1e6a45ced 1439 * @code
dkato 0:37e1e6a45ced 1440 * <ERROR error_ID="0x1" file="../src/api.c(336)"/>
dkato 0:37e1e6a45ced 1441 * @endcode
dkato 0:37e1e6a45ced 1442 */
dkato 0:37e1e6a45ced 1443 #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 1444 #define R_DEBUG_BREAK_IF_ERROR() R_OSPL_DebugBreakIfError(__FILE__,__LINE__)
dkato 0:37e1e6a45ced 1445 void R_OSPL_DebugBreakIfError( const char_t *const File, int_fast32_t const Line );
dkato 0:37e1e6a45ced 1446 #else
dkato 0:37e1e6a45ced 1447 INLINE void R_DEBUG_BREAK_IF_ERROR(void) {}
dkato 0:37e1e6a45ced 1448 #endif
dkato 0:37e1e6a45ced 1449
dkato 0:37e1e6a45ced 1450
dkato 0:37e1e6a45ced 1451 /**
dkato 0:37e1e6a45ced 1452 * @brief Raises the error of system unrecoverable
dkato 0:37e1e6a45ced 1453 *
dkato 0:37e1e6a45ced 1454 * @param e Error code
dkato 0:37e1e6a45ced 1455 * @return None
dkato 0:37e1e6a45ced 1456 *
dkato 0:37e1e6a45ced 1457 * @par Description
dkato 0:37e1e6a45ced 1458 * The error of system unrecoverable is the error of impossible to
dkato 0:37e1e6a45ced 1459 * - self - recover by process or main system. Example, the heap area was
dkato 0:37e1e6a45ced 1460 * broken or there are not any responses from hardware. This error can
dkato 0:37e1e6a45ced 1461 * be recoverable by OS or the system controller(e.g. Software reset)
dkato 0:37e1e6a45ced 1462 *
dkato 0:37e1e6a45ced 1463 * Example, when an error of recovery process was raised,
dkato 0:37e1e6a45ced 1464 * "R_OSPL_RaiseUnrecoverable" function must be called.
dkato 0:37e1e6a45ced 1465 *
dkato 0:37e1e6a45ced 1466 * "R_OSPL_RaiseUnrecoverable" function can be customized by the
dkato 0:37e1e6a45ced 1467 * application. By default, it calls "R_DebugBreak" function and falls
dkato 0:37e1e6a45ced 1468 * into the infinite loop.
dkato 0:37e1e6a45ced 1469 */
dkato 0:37e1e6a45ced 1470 void R_OSPL_RaiseUnrecoverable( errnum_t const e );
dkato 0:37e1e6a45ced 1471
dkato 0:37e1e6a45ced 1472
dkato 0:37e1e6a45ced 1473 /**
dkato 0:37e1e6a45ced 1474 * @brief Merge the error code raised in the finalizing operation
dkato 0:37e1e6a45ced 1475 *
dkato 0:37e1e6a45ced 1476 * @param CurrentError Current error code
dkato 0:37e1e6a45ced 1477 * @param AppendError New append error code
dkato 0:37e1e6a45ced 1478 * @return Merged error code
dkato 0:37e1e6a45ced 1479 *
dkato 0:37e1e6a45ced 1480 * @par Description
dkato 0:37e1e6a45ced 1481 * When the state was error state, if other new error was raised,
dkato 0:37e1e6a45ced 1482 * new error code is ignored.
dkato 0:37e1e6a45ced 1483 * - If "CurrentError != 0", this function returns "CurrentError" argument.
dkato 0:37e1e6a45ced 1484 * - If "CurrentError == 0", this function returns "AppendError" argument.
dkato 0:37e1e6a45ced 1485 *
dkato 0:37e1e6a45ced 1486 * This function can be modify by user.
dkato 0:37e1e6a45ced 1487 *
dkato 0:37e1e6a45ced 1488 * @par Example
dkato 0:37e1e6a45ced 1489 * @code
dkato 0:37e1e6a45ced 1490 * ee= Sample();
dkato 0:37e1e6a45ced 1491 * e= R_OSPL_MergeErrNum( e, ee );
dkato 0:37e1e6a45ced 1492 * return e;
dkato 0:37e1e6a45ced 1493 * @endcode
dkato 0:37e1e6a45ced 1494 */
dkato 0:37e1e6a45ced 1495 INLINE errnum_t R_OSPL_MergeErrNum( errnum_t const CurrentError, errnum_t const AppendError )
dkato 0:37e1e6a45ced 1496 {
dkato 0:37e1e6a45ced 1497 errnum_t e;
dkato 0:37e1e6a45ced 1498
dkato 0:37e1e6a45ced 1499 if ( CurrentError != 0 ) {
dkato 0:37e1e6a45ced 1500 e = CurrentError;
dkato 0:37e1e6a45ced 1501 } else {
dkato 0:37e1e6a45ced 1502 e = AppendError;
dkato 0:37e1e6a45ced 1503 }
dkato 0:37e1e6a45ced 1504 return e;
dkato 0:37e1e6a45ced 1505 }
dkato 0:37e1e6a45ced 1506
dkato 0:37e1e6a45ced 1507
dkato 0:37e1e6a45ced 1508 /**
dkato 0:37e1e6a45ced 1509 * @brief Sets an error code to TLS (Thread Local Storage).
dkato 0:37e1e6a45ced 1510 *
dkato 0:37e1e6a45ced 1511 * @param e Raising error code
dkato 0:37e1e6a45ced 1512 * @return None
dkato 0:37e1e6a45ced 1513 *
dkato 0:37e1e6a45ced 1514 * @par Description
dkato 0:37e1e6a45ced 1515 * Usually error code is returned. If API function cannot return any
dkato 0:37e1e6a45ced 1516 * error code, API function can have the specification of setting error
dkato 0:37e1e6a45ced 1517 * code by "R_OSPL_SetErrNum".
dkato 0:37e1e6a45ced 1518 *
dkato 0:37e1e6a45ced 1519 * There is this function, if "R_OSPL_TLS_ERROR_CODE" macro was defined
dkato 0:37e1e6a45ced 1520 * to be 1.
dkato 0:37e1e6a45ced 1521 * This function does nothing, if any error code was stored already in TLS.
dkato 0:37e1e6a45ced 1522 * The state does not change to error state, if "R_OSPL_SetErrNum" function
dkato 0:37e1e6a45ced 1523 * was called only. See "R_OSPL_GET_ERROR_ID".
dkato 0:37e1e6a45ced 1524 */
dkato 0:37e1e6a45ced 1525 #if R_OSPL_TLS_ERROR_CODE
dkato 0:37e1e6a45ced 1526 void R_OSPL_SetErrNum( errnum_t const e );
dkato 0:37e1e6a45ced 1527 #endif
dkato 0:37e1e6a45ced 1528
dkato 0:37e1e6a45ced 1529
dkato 0:37e1e6a45ced 1530 /**
dkato 0:37e1e6a45ced 1531 * @brief Returns the error code from TLS (Thread Local Storage).
dkato 0:37e1e6a45ced 1532 *
dkato 0:37e1e6a45ced 1533 * @par Parameters
dkato 0:37e1e6a45ced 1534 * None
dkato 0:37e1e6a45ced 1535 * @return Error code
dkato 0:37e1e6a45ced 1536 *
dkato 0:37e1e6a45ced 1537 * @par Description
dkato 0:37e1e6a45ced 1538 * Usually error code is returned. If API function cannot return any
dkato 0:37e1e6a45ced 1539 * error code, API function may have the specification of getting error
dkato 0:37e1e6a45ced 1540 * code by "R_OSPL_GetErrNum".
dkato 0:37e1e6a45ced 1541 *
dkato 0:37e1e6a45ced 1542 * There is this function, if "R_OSPL_TLS_ERROR_CODE" macro was defined
dkato 0:37e1e6a45ced 1543 * to be 1. This function returns 0 after called "R_OSPL_CLEAR_ERROR"
dkato 0:37e1e6a45ced 1544 * function.
dkato 0:37e1e6a45ced 1545 */
dkato 0:37e1e6a45ced 1546 #if R_OSPL_TLS_ERROR_CODE
dkato 0:37e1e6a45ced 1547 errnum_t R_OSPL_GetErrNum(void);
dkato 0:37e1e6a45ced 1548 #endif
dkato 0:37e1e6a45ced 1549
dkato 0:37e1e6a45ced 1550
dkato 0:37e1e6a45ced 1551 /**
dkato 0:37e1e6a45ced 1552 * @brief Clears the error state
dkato 0:37e1e6a45ced 1553 *
dkato 0:37e1e6a45ced 1554 * @par Parameters
dkato 0:37e1e6a45ced 1555 * None
dkato 0:37e1e6a45ced 1556 * @return None
dkato 0:37e1e6a45ced 1557 *
dkato 0:37e1e6a45ced 1558 * @par Description
dkato 0:37e1e6a45ced 1559 * This function does nothing, if "R_OSPL_ERROR_BREAK" macro and
dkato 0:37e1e6a45ced 1560 * "R_OSPL_TLS_ERROR_CODE" macro were defined to be 0. The following
dkato 0:37e1e6a45ced 1561 * descriptions are available, if "R_OSPL_ERROR_BREAK" macro was
dkato 0:37e1e6a45ced 1562 * defined to be 1.
dkato 0:37e1e6a45ced 1563 *
dkato 0:37e1e6a45ced 1564 * Whether the state is the error state is stored in thread local
dkato 0:37e1e6a45ced 1565 * storage. "R_OSPL_GetErrNum" function returns 0 after called this
dkato 0:37e1e6a45ced 1566 * function.
dkato 0:37e1e6a45ced 1567 *
dkato 0:37e1e6a45ced 1568 * If the error state was not cleared, the following descriptions were caused.
dkato 0:37e1e6a45ced 1569 * - Breaks at "R_DEBUG_BREAK_IF_ERROR" macro
dkato 0:37e1e6a45ced 1570 * - "R_OSPL_SET_BREAK_ERROR_ID" function behaves not expected behavior
dkato 0:37e1e6a45ced 1571 * because the count of error is not counted up.
dkato 0:37e1e6a45ced 1572 */
dkato 0:37e1e6a45ced 1573 #if R_OSPL_ERROR_BREAK || R_OSPL_TLS_ERROR_CODE
dkato 0:37e1e6a45ced 1574 void R_OSPL_CLEAR_ERROR(void);
dkato 0:37e1e6a45ced 1575 #else
dkato 0:37e1e6a45ced 1576 INLINE void R_OSPL_CLEAR_ERROR(void) {} /* QAC 3138 */
dkato 0:37e1e6a45ced 1577 #endif
dkato 0:37e1e6a45ced 1578
dkato 0:37e1e6a45ced 1579
dkato 0:37e1e6a45ced 1580 /**
dkato 0:37e1e6a45ced 1581 * @brief Returns the number of current error
dkato 0:37e1e6a45ced 1582 *
dkato 0:37e1e6a45ced 1583 * @par Parameters
dkato 0:37e1e6a45ced 1584 * None
dkato 0:37e1e6a45ced 1585 * @return The number of current error
dkato 0:37e1e6a45ced 1586 *
dkato 0:37e1e6a45ced 1587 * @par Description
dkato 0:37e1e6a45ced 1588 * This function does nothing, if "R_OSPL_ERROR_BREAK" macro was defined
dkato 0:37e1e6a45ced 1589 * to be 0. The following descriptions are available, if "R_OSPL_ERROR_BREAK"
dkato 0:37e1e6a45ced 1590 * macro was defined to be 1.
dkato 0:37e1e6a45ced 1591 *
dkato 0:37e1e6a45ced 1592 * This function returns 0, if any errors were not raised.
dkato 0:37e1e6a45ced 1593 *
dkato 0:37e1e6a45ced 1594 * This function returns 1, if first error was raised.
dkato 0:37e1e6a45ced 1595 *
dkato 0:37e1e6a45ced 1596 * After that, this function returns 2, if second error was raised after
dkato 0:37e1e6a45ced 1597 * calling "R_OSPL_CLEAR_ERROR" function.
dkato 0:37e1e6a45ced 1598 * This function does not return 0 after that the error was cleared by
dkato 0:37e1e6a45ced 1599 * calling "R_OSPL_CLEAR_ERROR".
dkato 0:37e1e6a45ced 1600 * The number of current error is running number in the whole of system
dkato 0:37e1e6a45ced 1601 * (all threads).
dkato 0:37e1e6a45ced 1602 *
dkato 0:37e1e6a45ced 1603 * Error is raised by following macros.
dkato 0:37e1e6a45ced 1604 * @code
dkato 0:37e1e6a45ced 1605 * IF, IF_D, ASSERT_R, ASSERT_D
dkato 0:37e1e6a45ced 1606 * @endcode
dkato 0:37e1e6a45ced 1607 * The process breaks at a moment of error raised, if the number of current
dkato 0:37e1e6a45ced 1608 * error was set to "R_OSPL_SET_BREAK_ERROR_ID" macro.
dkato 0:37e1e6a45ced 1609 */
dkato 0:37e1e6a45ced 1610 #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 1611 int_fast32_t R_OSPL_GET_ERROR_ID(void);
dkato 0:37e1e6a45ced 1612 #else
dkato 0:37e1e6a45ced 1613 INLINE int_fast32_t R_OSPL_GET_ERROR_ID(void)
dkato 0:37e1e6a45ced 1614 {
dkato 0:37e1e6a45ced 1615 return -1;
dkato 0:37e1e6a45ced 1616 }
dkato 0:37e1e6a45ced 1617 #endif
dkato 0:37e1e6a45ced 1618
dkato 0:37e1e6a45ced 1619
dkato 0:37e1e6a45ced 1620 /**
dkato 0:37e1e6a45ced 1621 * @brief Register to break at raising error at the moment
dkato 0:37e1e6a45ced 1622 *
dkato 0:37e1e6a45ced 1623 * @param ID Breaking number of error
dkato 0:37e1e6a45ced 1624 * @return None
dkato 0:37e1e6a45ced 1625 *
dkato 0:37e1e6a45ced 1626 * @par Description
dkato 0:37e1e6a45ced 1627 * This function does nothing, if "R_OSPL_ERROR_BREAK" macro was defined
dkato 0:37e1e6a45ced 1628 * to be 0. The following descriptions are available, if "R_OSPL_ERROR_BREAK"
dkato 0:37e1e6a45ced 1629 * macro was defined to be 1.
dkato 0:37e1e6a45ced 1630 *
dkato 0:37e1e6a45ced 1631 * Set a break point at "R_DebugBreak" function, when the process breaks
dkato 0:37e1e6a45ced 1632 * at the error raised code.
dkato 0:37e1e6a45ced 1633 *
dkato 0:37e1e6a45ced 1634 * The number of "ErrorID" argument can be known by "R_DEBUG_BREAK_IF_ERROR"
dkato 0:37e1e6a45ced 1635 * macro or "R_OSPL_GET_ERROR_ID" macro.
dkato 0:37e1e6a45ced 1636 * - In multi - threading environment, the number of "ErrorID" argument is the
dkato 0:37e1e6a45ced 1637 * number of raised errors in all threads. But when "ErrorID" argument was
dkato 0:37e1e6a45ced 1638 * set to be over 2, call "R_OSPL_SET_DEBUG_WORK" function before calling
dkato 0:37e1e6a45ced 1639 * "R_OSPL_SET_BREAK_ERROR_ID" function.
dkato 0:37e1e6a45ced 1640 *
dkato 0:37e1e6a45ced 1641 * The following code breaks at first error.
dkato 0:37e1e6a45ced 1642 * @code
dkato 0:37e1e6a45ced 1643 * R_OSPL_SET_BREAK_ERROR_ID( 1 );
dkato 0:37e1e6a45ced 1644 * @endcode
dkato 0:37e1e6a45ced 1645 *
dkato 0:37e1e6a45ced 1646 * The following code breaks at next error after resuming from meny errors.
dkato 0:37e1e6a45ced 1647 * @code
dkato 0:37e1e6a45ced 1648 * R_OSPL_SET_BREAK_ERROR_ID( R_OSPL_GET_ERROR_ID() + 1 );
dkato 0:37e1e6a45ced 1649 * @endcode
dkato 0:37e1e6a45ced 1650 */
dkato 0:37e1e6a45ced 1651 #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 1652 void R_OSPL_SET_BREAK_ERROR_ID( int_fast32_t ID );
dkato 0:37e1e6a45ced 1653 #else
dkato 0:37e1e6a45ced 1654 INLINE void R_OSPL_SET_BREAK_ERROR_ID( int_fast32_t const ID )
dkato 0:37e1e6a45ced 1655 {
dkato 0:37e1e6a45ced 1656 R_UNREFERENCED_VARIABLE( ID );
dkato 0:37e1e6a45ced 1657 }
dkato 0:37e1e6a45ced 1658 #endif
dkato 0:37e1e6a45ced 1659
dkato 0:37e1e6a45ced 1660
dkato 0:37e1e6a45ced 1661 /**
dkato 0:37e1e6a45ced 1662 * @brief Set the debug work area
dkato 0:37e1e6a45ced 1663 *
dkato 0:37e1e6a45ced 1664 * @param WorkArea Start address of work area
dkato 0:37e1e6a45ced 1665 * @param WorkAreaSize Size of work area (byte). See. <R_OSPL_DEBUG_WORK_SIZE>
dkato 0:37e1e6a45ced 1666 * @return None
dkato 0:37e1e6a45ced 1667 *
dkato 0:37e1e6a45ced 1668 * @par Description
dkato 0:37e1e6a45ced 1669 * This function does nothing, if "R_OSPL_ERROR_BREAK" macro was defined
dkato 0:37e1e6a45ced 1670 * to be 0. The following descriptions are available, if "R_OSPL_ERROR_BREAK"
dkato 0:37e1e6a45ced 1671 * macro was defined to be 1.
dkato 0:37e1e6a45ced 1672 *
dkato 0:37e1e6a45ced 1673 * Set the debug work area, when "R_OSPL_SET_BREAK_ERROR_ID" function
dkato 0:37e1e6a45ced 1674 * supports multi thread. "E_NO_DEBUG_TLS" error is raised, if the debug
dkato 0:37e1e6a45ced 1675 * work area was not set, when errors was raised in 2 or more threads.
dkato 0:37e1e6a45ced 1676 * It is not necessary to call this function, if error handling did by one
dkato 0:37e1e6a45ced 1677 * thread only.
dkato 0:37e1e6a45ced 1678 *
dkato 0:37e1e6a45ced 1679 * @par Example
dkato 0:37e1e6a45ced 1680 * @code
dkato 0:37e1e6a45ced 1681 * #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 1682 * #define GS_MAX_THREAD 10
dkato 0:37e1e6a45ced 1683 * static uint8_t gs_DebugWorkArea[ R_OSPL_DEBUG_WORK_SIZE( GS_MAX_THREAD ) ];
dkato 0:37e1e6a45ced 1684 * #endif
dkato 0:37e1e6a45ced 1685 *
dkato 0:37e1e6a45ced 1686 * R_OSPL_SET_DEBUG_WORK( gs_DebugWorkArea, sizeof(gs_DebugWorkArea) );
dkato 0:37e1e6a45ced 1687 * @endcode
dkato 0:37e1e6a45ced 1688 */
dkato 0:37e1e6a45ced 1689 #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 1690 void R_OSPL_SET_DEBUG_WORK( void *WorkArea, uint32_t WorkAreaSize );
dkato 0:37e1e6a45ced 1691 #else
dkato 0:37e1e6a45ced 1692 INLINE void R_OSPL_SET_DEBUG_WORK( const void *const WorkArea, uint32_t const WorkAreaSize )
dkato 0:37e1e6a45ced 1693 {
dkato 0:37e1e6a45ced 1694 R_UNREFERENCED_VARIABLE_2( WorkArea, WorkAreaSize );
dkato 0:37e1e6a45ced 1695 }
dkato 0:37e1e6a45ced 1696 #endif
dkato 0:37e1e6a45ced 1697
dkato 0:37e1e6a45ced 1698
dkato 0:37e1e6a45ced 1699 /**
dkato 0:37e1e6a45ced 1700 * @brief Returns debbug information of current thread.
dkato 0:37e1e6a45ced 1701 *
dkato 0:37e1e6a45ced 1702 * @par Parameters
dkato 0:37e1e6a45ced 1703 * None
dkato 0:37e1e6a45ced 1704 * @return Debbug information of current thread.
dkato 0:37e1e6a45ced 1705 */
dkato 0:37e1e6a45ced 1706 #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 1707 r_ospl_error_t *R_OSPL_GetCurrentThreadError(void);
dkato 0:37e1e6a45ced 1708 #endif
dkato 0:37e1e6a45ced 1709
dkato 0:37e1e6a45ced 1710
dkato 0:37e1e6a45ced 1711 /**
dkato 0:37e1e6a45ced 1712 * @brief Modifies count of objects that current thread has locked.
dkato 0:37e1e6a45ced 1713 *
dkato 0:37e1e6a45ced 1714 * @param Plus The value of adding to the counter.
dkato 0:37e1e6a45ced 1715 * @return None
dkato 0:37e1e6a45ced 1716 *
dkato 0:37e1e6a45ced 1717 * @par Description
dkato 0:37e1e6a45ced 1718 * The counter is subtracted, if this argument was minus.
dkato 0:37e1e6a45ced 1719 *
dkato 0:37e1e6a45ced 1720 * Drivers calls this function.
dkato 0:37e1e6a45ced 1721 * This function is not called from OSPL.
dkato 0:37e1e6a45ced 1722 * This function does nothing, if "R_OSPL_ERROR_BREAK" macro is 0.
dkato 0:37e1e6a45ced 1723 */
dkato 0:37e1e6a45ced 1724 #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 1725 #if R_OSPL_IS_PREEMPTION
dkato 0:37e1e6a45ced 1726 void R_OSPL_MODIFY_THREAD_LOCKED_COUNT( int_fast32_t Plus );
dkato 0:37e1e6a45ced 1727 #else
dkato 0:37e1e6a45ced 1728 INLINE void R_OSPL_MODIFY_THREAD_LOCKED_COUNT( int_fast32_t Plus ) {}
dkato 0:37e1e6a45ced 1729 #endif
dkato 0:37e1e6a45ced 1730 #else
dkato 0:37e1e6a45ced 1731 INLINE void R_OSPL_MODIFY_THREAD_LOCKED_COUNT( int_fast32_t Plus ) {}
dkato 0:37e1e6a45ced 1732 #endif
dkato 0:37e1e6a45ced 1733
dkato 0:37e1e6a45ced 1734
dkato 0:37e1e6a45ced 1735 /**
dkato 0:37e1e6a45ced 1736 * @brief Returns count of objects that current thread has locked.
dkato 0:37e1e6a45ced 1737 *
dkato 0:37e1e6a45ced 1738 * @par Parameters
dkato 0:37e1e6a45ced 1739 * None
dkato 0:37e1e6a45ced 1740 * @return Count of objects that current thread has locked
dkato 0:37e1e6a45ced 1741 *
dkato 0:37e1e6a45ced 1742 * @par Description
dkato 0:37e1e6a45ced 1743 * This function returns 0, if "R_OSPL_ERROR_BREAK" macro is 0.
dkato 0:37e1e6a45ced 1744 */
dkato 0:37e1e6a45ced 1745 #if R_OSPL_ERROR_BREAK
dkato 0:37e1e6a45ced 1746 #if R_OSPL_IS_PREEMPTION
dkato 0:37e1e6a45ced 1747 int_fast32_t R_OSPL_GET_THREAD_LOCKED_COUNT(void);
dkato 0:37e1e6a45ced 1748 #else
dkato 0:37e1e6a45ced 1749 INLINE int_fast32_t R_OSPL_GET_THREAD_LOCKED_COUNT(void)
dkato 0:37e1e6a45ced 1750 {
dkato 0:37e1e6a45ced 1751 return 0;
dkato 0:37e1e6a45ced 1752 }
dkato 0:37e1e6a45ced 1753 #endif
dkato 0:37e1e6a45ced 1754 #else
dkato 0:37e1e6a45ced 1755 INLINE int_fast32_t R_OSPL_GET_THREAD_LOCKED_COUNT(void)
dkato 0:37e1e6a45ced 1756 {
dkato 0:37e1e6a45ced 1757 return 0;
dkato 0:37e1e6a45ced 1758 }
dkato 0:37e1e6a45ced 1759 #endif
dkato 0:37e1e6a45ced 1760
dkato 0:37e1e6a45ced 1761
dkato 0:37e1e6a45ced 1762 /* Section: Accessing to register bit field */
dkato 0:37e1e6a45ced 1763 /**
dkato 0:37e1e6a45ced 1764 * @brief Reads modifies writes for bit field of 32bit register.
dkato 0:37e1e6a45ced 1765 *
dkato 0:37e1e6a45ced 1766 * @param in_out_Register Address of accessing register
dkato 0:37e1e6a45ced 1767 * @param Mask Mask of accessing bit field
dkato 0:37e1e6a45ced 1768 * @param Shift Shift count. Lowest bit number
dkato 0:37e1e6a45ced 1769 * @param Value Writing value before shift to the bit field
dkato 0:37e1e6a45ced 1770 * @return None
dkato 0:37e1e6a45ced 1771 */
dkato 0:37e1e6a45ced 1772 #if R_OSPL_BIT_FIELD_ACCESS_MACRO
dkato 0:37e1e6a45ced 1773
dkato 0:37e1e6a45ced 1774 /* ->SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1775 /* Volatile access at left of "=" and right of "=". But this is not depend on compiler spcifications. */
dkato 0:37e1e6a45ced 1776 /* ->SEC M1.2.2(QAC-1259) */
dkato 0:37e1e6a45ced 1777 /* If "Value" is signed, this is depend on CPU bit width. This expects 32bit CPU. But driver code is no problem. */
dkato 0:37e1e6a45ced 1778
dkato 0:37e1e6a45ced 1779 #define R_OSPL_SET_TO_32_BIT_REGISTER( in_out_Register, Mask, Shift, Value ) \
dkato 0:37e1e6a45ced 1780 ( *(volatile uint32_t*)(in_out_Register) = (uint32_t)( \
dkato 0:37e1e6a45ced 1781 ( ((uint32_t) *(volatile uint32_t*)(in_out_Register)) & \
dkato 0:37e1e6a45ced 1782 ~(Mask) ) | ( (Mask) & ( ( (uint_fast32_t)(Value) << (Shift) ) & (Mask) ) ) ) )
dkato 0:37e1e6a45ced 1783 /* This code is optimized well. */
dkato 0:37e1e6a45ced 1784
dkato 0:37e1e6a45ced 1785 /* <-SEC M1.2.2(QAC-1259) */
dkato 0:37e1e6a45ced 1786 /* <-SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1787
dkato 0:37e1e6a45ced 1788 #else
dkato 0:37e1e6a45ced 1789
dkato 0:37e1e6a45ced 1790 INLINE void R_OSPL_SET_TO_32_BIT_REGISTER( volatile uint32_t *const Register,
dkato 0:37e1e6a45ced 1791 uint32_t const Mask, int_fast32_t const Shift, uint32_t const Value )
dkato 0:37e1e6a45ced 1792 {
dkato 0:37e1e6a45ced 1793 uint32_t reg_value;
dkato 0:37e1e6a45ced 1794
dkato 0:37e1e6a45ced 1795 IF_DQ ( Register == NULL ) {}
dkato 0:37e1e6a45ced 1796 else {
dkato 0:37e1e6a45ced 1797 reg_value = *Register;
dkato 0:37e1e6a45ced 1798 reg_value = ( reg_value & ~Mask ) | ( ( Value << Shift ) & Mask );
dkato 0:37e1e6a45ced 1799 *Register = reg_value;
dkato 0:37e1e6a45ced 1800 }
dkato 0:37e1e6a45ced 1801 }
dkato 0:37e1e6a45ced 1802
dkato 0:37e1e6a45ced 1803 #endif
dkato 0:37e1e6a45ced 1804
dkato 0:37e1e6a45ced 1805
dkato 0:37e1e6a45ced 1806 /**
dkato 0:37e1e6a45ced 1807 * @brief Reads modifies writes for bit field of 16bit register.
dkato 0:37e1e6a45ced 1808 *
dkato 0:37e1e6a45ced 1809 * @param in_out_Register Address of accessing register
dkato 0:37e1e6a45ced 1810 * @param Mask Mask of accessing bit field
dkato 0:37e1e6a45ced 1811 * @param Shift Shift count. Lowest bit number
dkato 0:37e1e6a45ced 1812 * @param Value Writing value before shift to the bit field
dkato 0:37e1e6a45ced 1813 * @return None
dkato 0:37e1e6a45ced 1814 */
dkato 0:37e1e6a45ced 1815 #if R_OSPL_BIT_FIELD_ACCESS_MACRO
dkato 0:37e1e6a45ced 1816
dkato 0:37e1e6a45ced 1817 /* ->SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1818 /* Volatile access at left of "=" and right of "=". But this is not depend on compiler spcifications. */
dkato 0:37e1e6a45ced 1819 /* ->SEC M1.2.2(QAC-1259) */
dkato 0:37e1e6a45ced 1820 /* If "Value" is signed, this is depend on CPU bit width. This expects 32bit CPU. But driver code is no problem. */
dkato 0:37e1e6a45ced 1821
dkato 0:37e1e6a45ced 1822 #define R_OSPL_SET_TO_16_BIT_REGISTER( in_out_Register, Mask, Shift, Value ) \
dkato 0:37e1e6a45ced 1823 ( *(volatile uint16_t*)(in_out_Register) = (uint16_t)( \
dkato 0:37e1e6a45ced 1824 ( ((uint16_t) *(volatile uint16_t*)(in_out_Register)) & \
dkato 0:37e1e6a45ced 1825 ~(Mask) ) | ( (Mask) & ( ( (uint_fast16_t)(Value) << (Shift) ) & (Mask) ) ) ) )
dkato 0:37e1e6a45ced 1826 /* This code is optimized well. */
dkato 0:37e1e6a45ced 1827
dkato 0:37e1e6a45ced 1828
dkato 0:37e1e6a45ced 1829 /* <-SEC M1.2.2(QAC-1259) */
dkato 0:37e1e6a45ced 1830 /* <-SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1831
dkato 0:37e1e6a45ced 1832 #else
dkato 0:37e1e6a45ced 1833
dkato 0:37e1e6a45ced 1834 INLINE void R_OSPL_SET_TO_16_BIT_REGISTER( volatile uint16_t *const Register,
dkato 0:37e1e6a45ced 1835 uint16_t const Mask, int_fast32_t const Shift, uint16_t const Value )
dkato 0:37e1e6a45ced 1836 {
dkato 0:37e1e6a45ced 1837 uint16_t reg_value;
dkato 0:37e1e6a45ced 1838
dkato 0:37e1e6a45ced 1839 IF_DQ ( Register == NULL ) {}
dkato 0:37e1e6a45ced 1840 else {
dkato 0:37e1e6a45ced 1841 reg_value = *Register;
dkato 0:37e1e6a45ced 1842 reg_value = (uint16_t)( ( (uint_fast32_t) reg_value & ~(uint_fast32_t) Mask ) |
dkato 0:37e1e6a45ced 1843 ( ( (uint_fast32_t) Value << Shift ) & (uint_fast32_t) Mask ) );
dkato 0:37e1e6a45ced 1844 /* Cast is for SEC R2.4.2 */
dkato 0:37e1e6a45ced 1845 *Register = reg_value;
dkato 0:37e1e6a45ced 1846 }
dkato 0:37e1e6a45ced 1847 }
dkato 0:37e1e6a45ced 1848
dkato 0:37e1e6a45ced 1849 #endif
dkato 0:37e1e6a45ced 1850
dkato 0:37e1e6a45ced 1851
dkato 0:37e1e6a45ced 1852 /**
dkato 0:37e1e6a45ced 1853 * @brief Reads modifies writes for bit field of 8bit register.
dkato 0:37e1e6a45ced 1854 *
dkato 0:37e1e6a45ced 1855 * @param in_out_Register Address of accessing register
dkato 0:37e1e6a45ced 1856 * @param Mask Mask of accessing bit field
dkato 0:37e1e6a45ced 1857 * @param Shift Shift count. Lowest bit number
dkato 0:37e1e6a45ced 1858 * @param Value Writing value before shift to the bit field
dkato 0:37e1e6a45ced 1859 * @return None
dkato 0:37e1e6a45ced 1860 */
dkato 0:37e1e6a45ced 1861 #if R_OSPL_BIT_FIELD_ACCESS_MACRO
dkato 0:37e1e6a45ced 1862
dkato 0:37e1e6a45ced 1863 /* ->SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1864 /* Volatile access at left of "=" and right of "=". But this is not depend on compiler spcifications. */
dkato 0:37e1e6a45ced 1865 /* ->SEC M1.2.2(QAC-1259) */
dkato 0:37e1e6a45ced 1866 /* If "Value" is signed, this is depend on CPU bit width. This expects 32bit CPU. But driver code is no problem. */
dkato 0:37e1e6a45ced 1867
dkato 0:37e1e6a45ced 1868
dkato 0:37e1e6a45ced 1869 #define R_OSPL_SET_TO_8_BIT_REGISTER( in_out_Register, Mask, Shift, Value ) \
dkato 0:37e1e6a45ced 1870 ( *(volatile uint8_t*)(in_out_Register) = (uint8_t)( \
dkato 0:37e1e6a45ced 1871 ( ((uint8_t) *(volatile uint8_t*)(in_out_Register)) & \
dkato 0:37e1e6a45ced 1872 ~(Mask) ) | ( (Mask) & ( ( (uint_fast8_t)(Value) << (Shift) ) & (Mask) ) ) ) )
dkato 0:37e1e6a45ced 1873 /* This code is optimized well. */
dkato 0:37e1e6a45ced 1874
dkato 0:37e1e6a45ced 1875 /* <-SEC M1.2.2(QAC-1259) */
dkato 0:37e1e6a45ced 1876 /* <-SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1877
dkato 0:37e1e6a45ced 1878 #else
dkato 0:37e1e6a45ced 1879
dkato 0:37e1e6a45ced 1880 INLINE void R_OSPL_SET_TO_8_BIT_REGISTER( volatile uint8_t *const Register,
dkato 0:37e1e6a45ced 1881 uint8_t const Mask, int_fast32_t const Shift, uint8_t const Value )
dkato 0:37e1e6a45ced 1882 {
dkato 0:37e1e6a45ced 1883 uint8_t reg_value;
dkato 0:37e1e6a45ced 1884
dkato 0:37e1e6a45ced 1885 IF_DQ ( Register == NULL ) {}
dkato 0:37e1e6a45ced 1886 else {
dkato 0:37e1e6a45ced 1887 reg_value = *Register;
dkato 0:37e1e6a45ced 1888 reg_value = (uint8_t)( ( (uint_fast32_t) reg_value & ~(uint_fast32_t) Mask ) |
dkato 0:37e1e6a45ced 1889 ( ( (uint_fast32_t) Value << Shift ) & (uint_fast32_t) Mask ) );
dkato 0:37e1e6a45ced 1890 /* Cast is for SEC R2.4.2 */
dkato 0:37e1e6a45ced 1891 *Register = reg_value;
dkato 0:37e1e6a45ced 1892 }
dkato 0:37e1e6a45ced 1893 }
dkato 0:37e1e6a45ced 1894
dkato 0:37e1e6a45ced 1895 #endif
dkato 0:37e1e6a45ced 1896
dkato 0:37e1e6a45ced 1897
dkato 0:37e1e6a45ced 1898 /**
dkato 0:37e1e6a45ced 1899 * @brief Reads for bit field of 32bit register.
dkato 0:37e1e6a45ced 1900 *
dkato 0:37e1e6a45ced 1901 * @param RegisterValueAddress Address of accessing register
dkato 0:37e1e6a45ced 1902 * @param Mask Mask of accessing bit field
dkato 0:37e1e6a45ced 1903 * @param Shift Shift count. Lowest bit number
dkato 0:37e1e6a45ced 1904 * @return Read value after shift
dkato 0:37e1e6a45ced 1905 */
dkato 0:37e1e6a45ced 1906 #if R_OSPL_BIT_FIELD_ACCESS_MACRO
dkato 0:37e1e6a45ced 1907
dkato 0:37e1e6a45ced 1908 /* ->SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1909 /* Volatile access at &(get address), cast and *(memory load). But this is not double volatile access. */
dkato 0:37e1e6a45ced 1910 /* RegisterValueAddress is for avoid QAC-0310,QAC-3345 by cast code at caller. */
dkato 0:37e1e6a45ced 1911
dkato 0:37e1e6a45ced 1912 #define R_OSPL_GET_FROM_32_BIT_REGISTER( RegisterValueAddress, Mask, Shift ) \
dkato 0:37e1e6a45ced 1913 ( (uint32_t)( ( (uint32_t)*(volatile const uint32_t*) (RegisterValueAddress) \
dkato 0:37e1e6a45ced 1914 & (uint_fast32_t)(Mask) ) >> (Shift) ) )
dkato 0:37e1e6a45ced 1915 /* This code is optimized well. */
dkato 0:37e1e6a45ced 1916
dkato 0:37e1e6a45ced 1917 /* <-SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1918
dkato 0:37e1e6a45ced 1919 #else /* __QAC_ARM_H__ */ /* This code must be tested defined "__QAC_ARM_H__" */
dkato 0:37e1e6a45ced 1920
dkato 0:37e1e6a45ced 1921
dkato 0:37e1e6a45ced 1922 /* This inline functions is not expanded on __CC_ARM 5.15 */
dkato 0:37e1e6a45ced 1923 INLINE uint32_t R_OSPL_GET_FROM_32_BIT_REGISTER( volatile const uint32_t *const RegisterAddress,
dkato 0:37e1e6a45ced 1924 uint32_t const Mask, int_fast32_t const Shift )
dkato 0:37e1e6a45ced 1925 {
dkato 0:37e1e6a45ced 1926 uint32_t reg_value;
dkato 0:37e1e6a45ced 1927
dkato 0:37e1e6a45ced 1928 IF_DQ ( RegisterAddress == NULL ) {
dkato 0:37e1e6a45ced 1929 enum { num = 0x0EDEDEDE }; /* SEC M1.10.1 */
dkato 0:37e1e6a45ced 1930 reg_value = num;
dkato 0:37e1e6a45ced 1931 }
dkato 0:37e1e6a45ced 1932 else {
dkato 0:37e1e6a45ced 1933 reg_value = *RegisterAddress;
dkato 0:37e1e6a45ced 1934 reg_value = ( reg_value & Mask ) >> Shift;
dkato 0:37e1e6a45ced 1935 }
dkato 0:37e1e6a45ced 1936 return reg_value;
dkato 0:37e1e6a45ced 1937 }
dkato 0:37e1e6a45ced 1938
dkato 0:37e1e6a45ced 1939 #endif
dkato 0:37e1e6a45ced 1940
dkato 0:37e1e6a45ced 1941
dkato 0:37e1e6a45ced 1942 /**
dkato 0:37e1e6a45ced 1943 * @brief Reads for bit field of 16bit register.
dkato 0:37e1e6a45ced 1944 *
dkato 0:37e1e6a45ced 1945 * @param RegisterValueAddress Address of accessing register
dkato 0:37e1e6a45ced 1946 * @param Mask Mask of accessing bit field
dkato 0:37e1e6a45ced 1947 * @param Shift Shift count. Lowest bit number
dkato 0:37e1e6a45ced 1948 * @return Read value after shift
dkato 0:37e1e6a45ced 1949 */
dkato 0:37e1e6a45ced 1950 #if R_OSPL_BIT_FIELD_ACCESS_MACRO
dkato 0:37e1e6a45ced 1951
dkato 0:37e1e6a45ced 1952 /* ->SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1953 /* Volatile access at &(get address), cast and *(memory load). But this is not double volatile access. */
dkato 0:37e1e6a45ced 1954 /* RegisterValueAddress is for avoid QAC-0310,QAC-3345 by cast code at caller. */
dkato 0:37e1e6a45ced 1955
dkato 0:37e1e6a45ced 1956 #define R_OSPL_GET_FROM_16_BIT_REGISTER( RegisterValueAddress, Mask, Shift ) \
dkato 0:37e1e6a45ced 1957 ( (uint16_t)( ( (uint_fast32_t)*(volatile const uint16_t*) (RegisterValueAddress) \
dkato 0:37e1e6a45ced 1958 & (uint_fast16_t)(Mask) ) >> (Shift) ) )
dkato 0:37e1e6a45ced 1959 /* This code is optimized well. */
dkato 0:37e1e6a45ced 1960
dkato 0:37e1e6a45ced 1961 /* <-SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1962
dkato 0:37e1e6a45ced 1963 #else /* __QAC_ARM_H__ */ /* This code must be tested defined "__QAC_ARM_H__" */
dkato 0:37e1e6a45ced 1964
dkato 0:37e1e6a45ced 1965 /* This inline functions is not expanded on __CC_ARM 5.15 */
dkato 0:37e1e6a45ced 1966 INLINE uint16_t R_OSPL_GET_FROM_16_BIT_REGISTER( volatile const uint16_t *const RegisterAddress,
dkato 0:37e1e6a45ced 1967 uint16_t const Mask, int_fast32_t const Shift )
dkato 0:37e1e6a45ced 1968 {
dkato 0:37e1e6a45ced 1969 uint16_t reg_value;
dkato 0:37e1e6a45ced 1970
dkato 0:37e1e6a45ced 1971 IF_DQ ( RegisterAddress == NULL ) {
dkato 0:37e1e6a45ced 1972 enum { num = 0xDEDE }; /* SEC M1.10.1 */
dkato 0:37e1e6a45ced 1973 reg_value = num;
dkato 0:37e1e6a45ced 1974 }
dkato 0:37e1e6a45ced 1975 else {
dkato 0:37e1e6a45ced 1976 reg_value = *RegisterAddress;
dkato 0:37e1e6a45ced 1977 reg_value = (uint16_t)( ( (uint_fast32_t) reg_value & (uint_fast32_t) Mask ) >> Shift );
dkato 0:37e1e6a45ced 1978 /* Cast is for SEC R2.4.2 */
dkato 0:37e1e6a45ced 1979 }
dkato 0:37e1e6a45ced 1980 return reg_value;
dkato 0:37e1e6a45ced 1981 }
dkato 0:37e1e6a45ced 1982
dkato 0:37e1e6a45ced 1983 #endif
dkato 0:37e1e6a45ced 1984
dkato 0:37e1e6a45ced 1985
dkato 0:37e1e6a45ced 1986 /**
dkato 0:37e1e6a45ced 1987 * @brief Reads for bit field of 8bit register.
dkato 0:37e1e6a45ced 1988 *
dkato 0:37e1e6a45ced 1989 * @param RegisterValueAddress Address of accessing register
dkato 0:37e1e6a45ced 1990 * @param Mask Mask of accessing bit field
dkato 0:37e1e6a45ced 1991 * @param Shift Shift count. Lowest bit number
dkato 0:37e1e6a45ced 1992 * @return Read value after shift
dkato 0:37e1e6a45ced 1993 */
dkato 0:37e1e6a45ced 1994 #if R_OSPL_BIT_FIELD_ACCESS_MACRO
dkato 0:37e1e6a45ced 1995
dkato 0:37e1e6a45ced 1996 /* ->SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 1997 /* Volatile access at &(get address), cast and *(memory load). But this is not double volatile access. */
dkato 0:37e1e6a45ced 1998 /* RegisterValueAddress is for avoid QAC-0310,QAC-3345 by cast code at caller. */
dkato 0:37e1e6a45ced 1999
dkato 0:37e1e6a45ced 2000 #define R_OSPL_GET_FROM_8_BIT_REGISTER( RegisterValueAddress, Mask, Shift ) \
dkato 0:37e1e6a45ced 2001 ( (uint8_t)( ( (uint_fast32_t)*(volatile const uint8_t*) (RegisterValueAddress) \
dkato 0:37e1e6a45ced 2002 & (uint_fast8_t)(Mask) ) >> (Shift) ) )
dkato 0:37e1e6a45ced 2003 /* This code is optimized well. */
dkato 0:37e1e6a45ced 2004
dkato 0:37e1e6a45ced 2005 /* <-SEC R3.6.2(QAC-3345) */
dkato 0:37e1e6a45ced 2006
dkato 0:37e1e6a45ced 2007 #else /* __QAC_ARM_H__ */ /* This code must be tested defined "__QAC_ARM_H__" */
dkato 0:37e1e6a45ced 2008
dkato 0:37e1e6a45ced 2009 /* This inline functions is not expanded on __CC_ARM 5.15 */
dkato 0:37e1e6a45ced 2010 INLINE uint8_t R_OSPL_GET_FROM_8_BIT_REGISTER( volatile const uint8_t *const RegisterAddress,
dkato 0:37e1e6a45ced 2011 uint8_t const Mask, int_fast32_t const Shift )
dkato 0:37e1e6a45ced 2012 {
dkato 0:37e1e6a45ced 2013 uint8_t reg_value;
dkato 0:37e1e6a45ced 2014
dkato 0:37e1e6a45ced 2015 IF_DQ ( RegisterAddress == NULL ) {
dkato 0:37e1e6a45ced 2016 enum { num = 0xDE }; /* SEC M1.10.1 */
dkato 0:37e1e6a45ced 2017 reg_value = num;
dkato 0:37e1e6a45ced 2018 }
dkato 0:37e1e6a45ced 2019 else {
dkato 0:37e1e6a45ced 2020 reg_value = *RegisterAddress;
dkato 0:37e1e6a45ced 2021 reg_value = (uint8_t)( ( (uint_fast32_t) reg_value & (uint_fast32_t) Mask ) >> Shift );
dkato 0:37e1e6a45ced 2022 /* Cast is for SEC R2.4.2 */
dkato 0:37e1e6a45ced 2023 }
dkato 0:37e1e6a45ced 2024 return reg_value;
dkato 0:37e1e6a45ced 2025 }
dkato 0:37e1e6a45ced 2026
dkato 0:37e1e6a45ced 2027 #endif
dkato 0:37e1e6a45ced 2028
dkato 0:37e1e6a45ced 2029
dkato 0:37e1e6a45ced 2030 /***********************************************************************
dkato 0:37e1e6a45ced 2031 * End of File:
dkato 0:37e1e6a45ced 2032 ************************************************************************/
dkato 0:37e1e6a45ced 2033
dkato 0:37e1e6a45ced 2034 #ifdef __cplusplus
dkato 0:37e1e6a45ced 2035 } /* extern "C" */
dkato 0:37e1e6a45ced 2036 #endif /* __cplusplus */
dkato 0:37e1e6a45ced 2037
dkato 0:37e1e6a45ced 2038 #endif /* R_OSPL_H */
dkato 0:37e1e6a45ced 2039