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
1050186 3:9f857750e4e9 1 /*******************************************************************************
1050186 3:9f857750e4e9 2 * DISCLAIMER
1050186 3:9f857750e4e9 3 * This software is supplied by Renesas Electronics Corporation and is only
1050186 3:9f857750e4e9 4 * intended for use with Renesas products. No other uses are authorized. This
1050186 3:9f857750e4e9 5 * software is owned by Renesas Electronics Corporation and is protected under
1050186 3:9f857750e4e9 6 * all applicable laws, including copyright laws.
1050186 3:9f857750e4e9 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
1050186 3:9f857750e4e9 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
1050186 3:9f857750e4e9 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
1050186 3:9f857750e4e9 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
1050186 3:9f857750e4e9 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
1050186 3:9f857750e4e9 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
1050186 3:9f857750e4e9 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
1050186 3:9f857750e4e9 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
1050186 3:9f857750e4e9 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
1050186 3:9f857750e4e9 16 * Renesas reserves the right, without notice, to make changes to this software
1050186 3:9f857750e4e9 17 * and to discontinue the availability of this software. By using this software,
1050186 3:9f857750e4e9 18 * you agree to the additional terms and conditions found by accessing the
1050186 3:9f857750e4e9 19 * following link:
1050186 3:9f857750e4e9 20 * http://www.renesas.com/disclaimer
1050186 3:9f857750e4e9 21 * Copyright (C) 2013 - 2014 Renesas Electronics Corporation. All rights reserved.
1050186 3:9f857750e4e9 22 *******************************************************************************/
1050186 3:9f857750e4e9 23 /**
1050186 3:9f857750e4e9 24 * @file vsync.c
1050186 3:9f857750e4e9 25 * @brief $Module: CLibCommon $ $PublicVersion: 1.00 $ (=CLIB_VERSION)
1050186 3:9f857750e4e9 26 * $Rev: $
1050186 3:9f857750e4e9 27 * $Date:: $
1050186 3:9f857750e4e9 28 */
1050186 3:9f857750e4e9 29
1050186 3:9f857750e4e9 30
1050186 3:9f857750e4e9 31 /******************************************************************************
1050186 3:9f857750e4e9 32 Includes <System Includes> , "Project Includes"
1050186 3:9f857750e4e9 33 ******************************************************************************/
1050186 3:9f857750e4e9 34 #include "vsync.h"
1050186 3:9f857750e4e9 35 #include "vsync_pl.h"
1050186 3:9f857750e4e9 36 #include "r_ospl.h"
1050186 3:9f857750e4e9 37
1050186 3:9f857750e4e9 38
1050186 3:9f857750e4e9 39 /******************************************************************************
1050186 3:9f857750e4e9 40 Typedef definitions
1050186 3:9f857750e4e9 41 ******************************************************************************/
1050186 3:9f857750e4e9 42
1050186 3:9f857750e4e9 43 /**
1050186 3:9f857750e4e9 44 * @struct r_v_sync_i_lock_t
1050186 3:9f857750e4e9 45 * @brief I-Lock
1050186 3:9f857750e4e9 46 */
1050186 3:9f857750e4e9 47 typedef struct st_r_v_sync_i_lock_t r_v_sync_i_lock_t;
1050186 3:9f857750e4e9 48 struct st_r_v_sync_i_lock_t {
1050186 3:9f857750e4e9 49 /** is_lock */
1050186 3:9f857750e4e9 50 bool_t is_lock;
1050186 3:9f857750e4e9 51
1050186 3:9f857750e4e9 52 /** channel_num */
1050186 3:9f857750e4e9 53 int_fast32_t channel_num;
1050186 3:9f857750e4e9 54 };
1050186 3:9f857750e4e9 55
1050186 3:9f857750e4e9 56
1050186 3:9f857750e4e9 57 /**
1050186 3:9f857750e4e9 58 * @struct r_v_sync_channel_t
1050186 3:9f857750e4e9 59 * @brief V-Sync context
1050186 3:9f857750e4e9 60 */
1050186 3:9f857750e4e9 61 typedef struct st_r_v_sync_channel_t r_v_sync_channel_t;
1050186 3:9f857750e4e9 62 struct st_r_v_sync_channel_t {
1050186 3:9f857750e4e9 63 /*-----------------------------------------------------------*/
1050186 3:9f857750e4e9 64 /* Group: Count */
1050186 3:9f857750e4e9 65
1050186 3:9f857750e4e9 66 /** VSync_FrameCount */
1050186 3:9f857750e4e9 67 volatile int_fast32_t VSync_FrameCount;
1050186 3:9f857750e4e9 68
1050186 3:9f857750e4e9 69 /** VSync_PreviousFrameCount */
1050186 3:9f857750e4e9 70 volatile int_fast32_t VSync_PreviousFrameCount;
1050186 3:9f857750e4e9 71
1050186 3:9f857750e4e9 72 /** VSync_TargetCount */
1050186 3:9f857750e4e9 73 volatile int_fast32_t VSync_TargetCount;
1050186 3:9f857750e4e9 74
1050186 3:9f857750e4e9 75
1050186 3:9f857750e4e9 76 /*-----------------------------------------------------------*/
1050186 3:9f857750e4e9 77 /* Group: Interrupt */
1050186 3:9f857750e4e9 78
1050186 3:9f857750e4e9 79 /** AsyncStatus */
1050186 3:9f857750e4e9 80 r_v_sync_async_status_t AsyncStatus;
1050186 3:9f857750e4e9 81
1050186 3:9f857750e4e9 82 /** InterruptCallbackCaller */
1050186 3:9f857750e4e9 83 r_ospl_caller_t InterruptCallbackCaller;
1050186 3:9f857750e4e9 84
1050186 3:9f857750e4e9 85 /** InterruptFlag */
1050186 3:9f857750e4e9 86 r_ospl_flag32_t InterruptFlag;
1050186 3:9f857750e4e9 87
1050186 3:9f857750e4e9 88 /** IsEnabledInterrupt */
1050186 3:9f857750e4e9 89 bool_t IsEnabledInterrupt;
1050186 3:9f857750e4e9 90
1050186 3:9f857750e4e9 91 /** InterruptEnables */
1050186 3:9f857750e4e9 92 r_ospl_flag32_t InterruptEnables;
1050186 3:9f857750e4e9 93
1050186 3:9f857750e4e9 94 /** I_Lock */
1050186 3:9f857750e4e9 95 r_v_sync_i_lock_t I_Lock;
1050186 3:9f857750e4e9 96 };
1050186 3:9f857750e4e9 97
1050186 3:9f857750e4e9 98
1050186 3:9f857750e4e9 99 /* Section: Global */
1050186 3:9f857750e4e9 100 /** V-Sync context */
1050186 3:9f857750e4e9 101 static r_v_sync_channel_t gs_v_sync_channel[ R_V_SYNC_CHANNEL_COUNT ];
1050186 3:9f857750e4e9 102
1050186 3:9f857750e4e9 103
1050186 3:9f857750e4e9 104 /******************************************************************************
1050186 3:9f857750e4e9 105 Macro definitions
1050186 3:9f857750e4e9 106 ******************************************************************************/
1050186 3:9f857750e4e9 107
1050186 3:9f857750e4e9 108 /******************************************************************************
1050186 3:9f857750e4e9 109 Imported global variables and functions (from other files)
1050186 3:9f857750e4e9 110 ******************************************************************************/
1050186 3:9f857750e4e9 111
1050186 3:9f857750e4e9 112 /******************************************************************************
1050186 3:9f857750e4e9 113 Exported global variables and functions (to be accessed by other files)
1050186 3:9f857750e4e9 114 ******************************************************************************/
1050186 3:9f857750e4e9 115
1050186 3:9f857750e4e9 116 /******************************************************************************
1050186 3:9f857750e4e9 117 Private global variables and functions
1050186 3:9f857750e4e9 118 ******************************************************************************/
1050186 3:9f857750e4e9 119
1050186 3:9f857750e4e9 120 static void R_V_SYNC_I_LOCK_Reset( r_v_sync_i_lock_t *const self );
1050186 3:9f857750e4e9 121 static bool_t R_V_SYNC_I_LOCK_Lock( r_v_sync_i_lock_t *const self );
1050186 3:9f857750e4e9 122 static void R_V_SYNC_I_LOCK_Unlock( r_v_sync_i_lock_t *const self );
1050186 3:9f857750e4e9 123
1050186 3:9f857750e4e9 124
1050186 3:9f857750e4e9 125 /***********************************************************************
1050186 3:9f857750e4e9 126 * Implement: R_V_SYNC_Initialize
1050186 3:9f857750e4e9 127 ************************************************************************/
1050186 3:9f857750e4e9 128 errnum_t R_V_SYNC_Initialize( int_fast32_t const ChannelNum )
1050186 3:9f857750e4e9 129 {
1050186 3:9f857750e4e9 130 errnum_t e;
1050186 3:9f857750e4e9 131 r_v_sync_channel_t *const self = &gs_v_sync_channel[ ChannelNum ];
1050186 3:9f857750e4e9 132
1050186 3:9f857750e4e9 133 IF ( (ChannelNum < 0) || (ChannelNum >= R_V_SYNC_CHANNEL_COUNT) ) {
1050186 3:9f857750e4e9 134 e=E_OTHERS;
1050186 3:9f857750e4e9 135 goto fin;
1050186 3:9f857750e4e9 136 }
1050186 3:9f857750e4e9 137
1050186 3:9f857750e4e9 138 self->I_Lock.channel_num = ChannelNum;
1050186 3:9f857750e4e9 139 R_V_SYNC_I_LOCK_Reset( &self->I_Lock );
1050186 3:9f857750e4e9 140
1050186 3:9f857750e4e9 141 ASSERT_R( self->AsyncStatus.State == R_OSPL_UNINITIALIZED, e=E_STATE; goto fin );
1050186 3:9f857750e4e9 142 R_OSPL_FLAG32_InitConst( &self->AsyncStatus.InterruptFlags );
1050186 3:9f857750e4e9 143 R_OSPL_FLAG32_InitConst( &self->AsyncStatus.CancelFlags );
1050186 3:9f857750e4e9 144
1050186 3:9f857750e4e9 145 e= R_V_SYNC_OnInitialize( ChannelNum );
1050186 3:9f857750e4e9 146 IF(e!=0) {
1050186 3:9f857750e4e9 147 goto fin;
1050186 3:9f857750e4e9 148 }
1050186 3:9f857750e4e9 149
1050186 3:9f857750e4e9 150 self->IsEnabledInterrupt = true;
1050186 3:9f857750e4e9 151 R_OSPL_FLAG32_InitConst( &self->InterruptEnables );
1050186 3:9f857750e4e9 152 self->AsyncStatus.State = R_OSPL_RUNNABLE;
1050186 3:9f857750e4e9 153
1050186 3:9f857750e4e9 154 R_OSPL_FLAG32_Set( &self->InterruptEnables, R_V_SYNC_INTERRUPT_LINE_V_LINE );
1050186 3:9f857750e4e9 155 /* V-Sync interrupt always be enabled. Because clear interrupt status */
1050186 3:9f857750e4e9 156
1050186 3:9f857750e4e9 157 e=0;
1050186 3:9f857750e4e9 158 fin:
1050186 3:9f857750e4e9 159 if ( e != 0 ) {
1050186 3:9f857750e4e9 160 e= R_V_SYNC_Finalize( ChannelNum, e );
1050186 3:9f857750e4e9 161 R_UNREFERENCED_VARIABLE( e );
1050186 3:9f857750e4e9 162 }
1050186 3:9f857750e4e9 163 return e;
1050186 3:9f857750e4e9 164 }
1050186 3:9f857750e4e9 165
1050186 3:9f857750e4e9 166
1050186 3:9f857750e4e9 167 /***********************************************************************
1050186 3:9f857750e4e9 168 * Implement: R_V_SYNC_Finalize
1050186 3:9f857750e4e9 169 ************************************************************************/
1050186 3:9f857750e4e9 170 errnum_t R_V_SYNC_Finalize( int_fast32_t const ChannelNum, errnum_t e )
1050186 3:9f857750e4e9 171 {
1050186 3:9f857750e4e9 172 bool_t was_enabled; /* = false; */ /* QAC 3197 */
1050186 3:9f857750e4e9 173 r_v_sync_channel_t *const self = &gs_v_sync_channel[ ChannelNum ];
1050186 3:9f857750e4e9 174
1050186 3:9f857750e4e9 175 was_enabled = R_V_SYNC_I_LOCK_Lock( &self->I_Lock );
1050186 3:9f857750e4e9 176
1050186 3:9f857750e4e9 177 if ( ! ( (ChannelNum < 0) || (ChannelNum >= R_V_SYNC_CHANNEL_COUNT) ) ) {
1050186 3:9f857750e4e9 178 if ( self->AsyncStatus.State != R_OSPL_UNINITIALIZED ) {
1050186 3:9f857750e4e9 179 R_OSPL_FLAG32_Clear( &self->InterruptEnables, R_V_SYNC_INTERRUPT_LINE_V_LINE );
1050186 3:9f857750e4e9 180
1050186 3:9f857750e4e9 181 R_OSPL_FLAG32_Set( &self->AsyncStatus.CancelFlags,
1050186 3:9f857750e4e9 182 R_OSPL_CANNEL_REQUEST | R_OSPL_CANNELING | R_OSPL_CANNELED |
1050186 3:9f857750e4e9 183 R_OSPL_FINALIZE_REQUEST | R_OSPL_FINALIZING );
1050186 3:9f857750e4e9 184
1050186 3:9f857750e4e9 185 e= R_V_SYNC_OnFinalize( ChannelNum, e );
1050186 3:9f857750e4e9 186
1050186 3:9f857750e4e9 187 R_OSPL_FLAG32_Set( &self->AsyncStatus.CancelFlags, R_OSPL_FINALIZED );
1050186 3:9f857750e4e9 188 R_OSPL_FLAG32_Clear( &self->AsyncStatus.CancelFlags, R_OSPL_FLAG32_ALL_BITS );
1050186 3:9f857750e4e9 189 self->AsyncStatus.State = R_OSPL_UNINITIALIZED;
1050186 3:9f857750e4e9 190 }
1050186 3:9f857750e4e9 191 }
1050186 3:9f857750e4e9 192
1050186 3:9f857750e4e9 193 if ( IS( was_enabled ) ) {
1050186 3:9f857750e4e9 194 R_V_SYNC_I_LOCK_Unlock( &self->I_Lock );
1050186 3:9f857750e4e9 195 }
1050186 3:9f857750e4e9 196 R_V_SYNC_I_LOCK_Reset( &self->I_Lock );
1050186 3:9f857750e4e9 197
1050186 3:9f857750e4e9 198 return e;
1050186 3:9f857750e4e9 199 }
1050186 3:9f857750e4e9 200
1050186 3:9f857750e4e9 201
1050186 3:9f857750e4e9 202 /***********************************************************************
1050186 3:9f857750e4e9 203 * Implement: R_V_SYNC_Wait
1050186 3:9f857750e4e9 204 ************************************************************************/
1050186 3:9f857750e4e9 205 errnum_t R_V_SYNC_Wait( int_fast32_t const ChannelNum,
1050186 3:9f857750e4e9 206 int_fast32_t const SwapInterval, bool_t const Is1VSyncAtMinimum )
1050186 3:9f857750e4e9 207 {
1050186 3:9f857750e4e9 208 errnum_t e;
1050186 3:9f857750e4e9 209 r_ospl_async_t async;
1050186 3:9f857750e4e9 210 bit_flags32_t got_flags;
1050186 3:9f857750e4e9 211
1050186 3:9f857750e4e9 212 async.Flags = R_F_OSPL_A_Thread;
1050186 3:9f857750e4e9 213 async.A_Thread = R_OSPL_THREAD_GetCurrentId();
1050186 3:9f857750e4e9 214
1050186 3:9f857750e4e9 215 e= R_V_SYNC_WaitStart( ChannelNum, SwapInterval, Is1VSyncAtMinimum, &async );
1050186 3:9f857750e4e9 216 IF(e!=0) {
1050186 3:9f857750e4e9 217 goto fin;
1050186 3:9f857750e4e9 218 }
1050186 3:9f857750e4e9 219
1050186 3:9f857750e4e9 220 e= R_OSPL_EVENT_Wait( async.A_EventValue, &got_flags, R_OSPL_INFINITE );
1050186 3:9f857750e4e9 221 IF(e!=0) {
1050186 3:9f857750e4e9 222 goto fin;
1050186 3:9f857750e4e9 223 }
1050186 3:9f857750e4e9 224
1050186 3:9f857750e4e9 225 e= async.ReturnValue;
1050186 3:9f857750e4e9 226 IF(e!=0) {
1050186 3:9f857750e4e9 227 goto fin;
1050186 3:9f857750e4e9 228 }
1050186 3:9f857750e4e9 229
1050186 3:9f857750e4e9 230 e=0;
1050186 3:9f857750e4e9 231 fin:
1050186 3:9f857750e4e9 232 return e;
1050186 3:9f857750e4e9 233 }
1050186 3:9f857750e4e9 234
1050186 3:9f857750e4e9 235
1050186 3:9f857750e4e9 236 /***********************************************************************
1050186 3:9f857750e4e9 237 * Implement: R_V_SYNC_WaitStart
1050186 3:9f857750e4e9 238 ************************************************************************/
1050186 3:9f857750e4e9 239 errnum_t R_V_SYNC_WaitStart( int_fast32_t const ChannelNum,
1050186 3:9f857750e4e9 240 int_fast32_t const SwapInterval, bool_t const Is1VSyncAtMinimum,
1050186 3:9f857750e4e9 241 r_ospl_async_t *const Async )
1050186 3:9f857750e4e9 242 {
1050186 3:9f857750e4e9 243 errnum_t e;
1050186 3:9f857750e4e9 244 bool_t was_enabled = false;
1050186 3:9f857750e4e9 245 int_fast32_t target_count;
1050186 3:9f857750e4e9 246 int_fast32_t operand1;
1050186 3:9f857750e4e9 247 int_fast32_t operand2;
1050186 3:9f857750e4e9 248 r_v_sync_channel_t *const self = &gs_v_sync_channel[ ChannelNum ];
1050186 3:9f857750e4e9 249
1050186 3:9f857750e4e9 250 IF ( (ChannelNum < 0) || (ChannelNum >= R_V_SYNC_CHANNEL_COUNT) ) {
1050186 3:9f857750e4e9 251 e=E_OTHERS;
1050186 3:9f857750e4e9 252 goto fin;
1050186 3:9f857750e4e9 253 }
1050186 3:9f857750e4e9 254 IF ( Async == NULL ) {
1050186 3:9f857750e4e9 255 e=E_OTHERS;
1050186 3:9f857750e4e9 256 goto fin;
1050186 3:9f857750e4e9 257 }
1050186 3:9f857750e4e9 258
1050186 3:9f857750e4e9 259 R_V_SYNC_SetDefaultAsync( Async, R_OSPL_ASYNC_TYPE_NORMAL );
1050186 3:9f857750e4e9 260 Async->ReturnValue = 0;
1050186 3:9f857750e4e9 261 ASSERT_R( Async->I_Thread == NULL, e=E_OTHERS; goto fin );
1050186 3:9f857750e4e9 262
1050186 3:9f857750e4e9 263 was_enabled = R_V_SYNC_I_LOCK_Lock( &self->I_Lock );
1050186 3:9f857750e4e9 264
1050186 3:9f857750e4e9 265 ASSERT_R( self->AsyncStatus.State == R_OSPL_RUNNABLE, e=E_STATE; goto fin );
1050186 3:9f857750e4e9 266
1050186 3:9f857750e4e9 267
1050186 3:9f857750e4e9 268 /* Set "self->VSync_TargetCount" */
1050186 3:9f857750e4e9 269 target_count = self->VSync_PreviousFrameCount + SwapInterval;
1050186 3:9f857750e4e9 270 if ( (Is1VSyncAtMinimum) && (target_count < (self->VSync_FrameCount + 1)) ) {
1050186 3:9f857750e4e9 271 target_count = self->VSync_FrameCount + 1;
1050186 3:9f857750e4e9 272 }
1050186 3:9f857750e4e9 273 self->VSync_TargetCount = target_count;
1050186 3:9f857750e4e9 274
1050186 3:9f857750e4e9 275
1050186 3:9f857750e4e9 276 /* If already target count */
1050186 3:9f857750e4e9 277 operand1 = self->VSync_TargetCount; /* SEC R3.6.2 */
1050186 3:9f857750e4e9 278 operand2 = self->VSync_FrameCount; /* SEC R3.6.2 */
1050186 3:9f857750e4e9 279 if ( (operand1 - operand2) <= 0 ) {
1050186 3:9f857750e4e9 280 operand1 = self->VSync_FrameCount; /* SEC R3.6.2 */
1050186 3:9f857750e4e9 281 self->VSync_PreviousFrameCount = operand1;
1050186 3:9f857750e4e9 282
1050186 3:9f857750e4e9 283 /* Set application event */
1050186 3:9f857750e4e9 284 R_OSPL_EVENT_Set( Async->A_Thread, Async->A_EventValue );
1050186 3:9f857750e4e9 285 } else {
1050186 3:9f857750e4e9 286 /* Change state to waiting */
1050186 3:9f857750e4e9 287 self->AsyncStatus.State = R_OSPL_RUNNING;
1050186 3:9f857750e4e9 288
1050186 3:9f857750e4e9 289 /* Clear application event */
1050186 3:9f857750e4e9 290 R_OSPL_EVENT_Clear( Async->A_Thread, Async->A_EventValue );
1050186 3:9f857750e4e9 291
1050186 3:9f857750e4e9 292 /* Attach "Async" to interrupt */
1050186 3:9f857750e4e9 293 /* ->MISRA 11.4 : Not too big "enum" is same bit count as "int" */ /* ->SEC R2.7.1 */
1050186 3:9f857750e4e9 294 R_OSPL_CALLER_Initialize( &self->InterruptCallbackCaller,
1050186 3:9f857750e4e9 295 Async, (volatile int_t *) &self->AsyncStatus.State, R_OSPL_INTERRUPTING, NULL, NULL );
1050186 3:9f857750e4e9 296 /* <-MISRA 11.4 */ /* <-SEC R2.7.1 */
1050186 3:9f857750e4e9 297 e= R_V_SYNC_SetInterruptCallbackCaller( ChannelNum,
1050186 3:9f857750e4e9 298 &self->InterruptCallbackCaller );
1050186 3:9f857750e4e9 299 IF(e!=0) {
1050186 3:9f857750e4e9 300 goto fin;
1050186 3:9f857750e4e9 301 }
1050186 3:9f857750e4e9 302 }
1050186 3:9f857750e4e9 303
1050186 3:9f857750e4e9 304 e=0;
1050186 3:9f857750e4e9 305 fin:
1050186 3:9f857750e4e9 306 if ( IS( was_enabled ) ) {
1050186 3:9f857750e4e9 307 R_V_SYNC_I_LOCK_Unlock( &self->I_Lock );
1050186 3:9f857750e4e9 308 }
1050186 3:9f857750e4e9 309 return e;
1050186 3:9f857750e4e9 310 }
1050186 3:9f857750e4e9 311
1050186 3:9f857750e4e9 312
1050186 3:9f857750e4e9 313 /***********************************************************************
1050186 3:9f857750e4e9 314 * Implement: R_V_SYNC_OnInterrupting
1050186 3:9f857750e4e9 315 ************************************************************************/
1050186 3:9f857750e4e9 316 errnum_t R_V_SYNC_OnInterrupting( const r_ospl_interrupt_t *const InterruptSource )
1050186 3:9f857750e4e9 317 {
1050186 3:9f857750e4e9 318 errnum_t e;
1050186 3:9f857750e4e9 319 bool_t was_enabled = false;
1050186 3:9f857750e4e9 320 int_fast32_t operand1;
1050186 3:9f857750e4e9 321 int_fast32_t operand2;
1050186 3:9f857750e4e9 322 int_fast32_t channel_num_;
1050186 3:9f857750e4e9 323 r_v_sync_channel_t *self;
1050186 3:9f857750e4e9 324 r_ospl_async_t *notify_async = NULL;
1050186 3:9f857750e4e9 325
1050186 3:9f857750e4e9 326 IF_DQ( InterruptSource == NULL ) {
1050186 3:9f857750e4e9 327 e=E_OTHERS;
1050186 3:9f857750e4e9 328 goto fin;
1050186 3:9f857750e4e9 329 }
1050186 3:9f857750e4e9 330
1050186 3:9f857750e4e9 331 channel_num_ = InterruptSource->ChannelNum;
1050186 3:9f857750e4e9 332 self = &gs_v_sync_channel[ channel_num_ ];
1050186 3:9f857750e4e9 333
1050186 3:9f857750e4e9 334 if ( self->AsyncStatus.State != R_OSPL_INTERRUPTING ) {
1050186 3:9f857750e4e9 335 e=0;
1050186 3:9f857750e4e9 336 goto fin;
1050186 3:9f857750e4e9 337 }
1050186 3:9f857750e4e9 338
1050186 3:9f857750e4e9 339 self->AsyncStatus.State = R_OSPL_INTERRUPTED;
1050186 3:9f857750e4e9 340
1050186 3:9f857750e4e9 341
1050186 3:9f857750e4e9 342 /* Operate like R_V_SYNC_OnInterrupted() */
1050186 3:9f857750e4e9 343 was_enabled = R_V_SYNC_I_LOCK_Lock( &self->I_Lock );
1050186 3:9f857750e4e9 344
1050186 3:9f857750e4e9 345 self->VSync_FrameCount += 1;
1050186 3:9f857750e4e9 346
1050186 3:9f857750e4e9 347
1050186 3:9f857750e4e9 348 operand1 = self->VSync_TargetCount; /* SEC R3.6.2 */
1050186 3:9f857750e4e9 349 operand2 = self->VSync_FrameCount; /* SEC R3.6.2 */
1050186 3:9f857750e4e9 350 if ( (operand1 - operand2) <= 0 ) {
1050186 3:9f857750e4e9 351 operand1 = self->VSync_FrameCount; /* SEC R3.6.2 */
1050186 3:9f857750e4e9 352 self->VSync_PreviousFrameCount = operand1;
1050186 3:9f857750e4e9 353
1050186 3:9f857750e4e9 354 e= R_V_SYNC_SetInterruptCallbackCaller( channel_num_, NULL );
1050186 3:9f857750e4e9 355
1050186 3:9f857750e4e9 356 self->AsyncStatus.State = R_OSPL_RUNNABLE;
1050186 3:9f857750e4e9 357 notify_async = self->InterruptCallbackCaller.Async;
1050186 3:9f857750e4e9 358 } else {
1050186 3:9f857750e4e9 359 self->AsyncStatus.State = R_OSPL_RUNNING;
1050186 3:9f857750e4e9 360 }
1050186 3:9f857750e4e9 361
1050186 3:9f857750e4e9 362
1050186 3:9f857750e4e9 363 e=0;
1050186 3:9f857750e4e9 364 fin:
1050186 3:9f857750e4e9 365 if ( IS( was_enabled ) ) {
1050186 3:9f857750e4e9 366 /* ->QAC 3353 : "self" is always assigned, if "was_enabled" is true */
1050186 3:9f857750e4e9 367 IF_DQ( self == NULL ) {} /* QAC 3353 raises SEC R3.2.2 */
1050186 3:9f857750e4e9 368 else {
1050186 3:9f857750e4e9 369 R_V_SYNC_I_LOCK_Unlock( &self->I_Lock );
1050186 3:9f857750e4e9 370 }
1050186 3:9f857750e4e9 371 /* <-QAC 3353 */
1050186 3:9f857750e4e9 372 /* This is for disabling interrupt by R_V_SYNC_I_LOCK_Disable() */
1050186 3:9f857750e4e9 373 }
1050186 3:9f857750e4e9 374
1050186 3:9f857750e4e9 375 if ( notify_async != NULL ) {
1050186 3:9f857750e4e9 376 R_OSPL_EVENT_Set( notify_async->A_Thread, notify_async->A_EventValue );
1050186 3:9f857750e4e9 377 }
1050186 3:9f857750e4e9 378 return e;
1050186 3:9f857750e4e9 379 }
1050186 3:9f857750e4e9 380
1050186 3:9f857750e4e9 381
1050186 3:9f857750e4e9 382 /***********************************************************************
1050186 3:9f857750e4e9 383 * Implement: R_V_SYNC_GetAsyncStatus
1050186 3:9f857750e4e9 384 ************************************************************************/
1050186 3:9f857750e4e9 385 errnum_t R_V_SYNC_GetAsyncStatus( int_fast32_t const ChannelNum,
1050186 3:9f857750e4e9 386 const r_v_sync_async_status_t **const out_Status )
1050186 3:9f857750e4e9 387 {
1050186 3:9f857750e4e9 388 errnum_t e;
1050186 3:9f857750e4e9 389 r_v_sync_channel_t *const self = &gs_v_sync_channel[ ChannelNum ];
1050186 3:9f857750e4e9 390
1050186 3:9f857750e4e9 391 IF_DQ( out_Status == NULL ) {
1050186 3:9f857750e4e9 392 e=E_OTHERS;
1050186 3:9f857750e4e9 393 goto fin;
1050186 3:9f857750e4e9 394 }
1050186 3:9f857750e4e9 395 IF ( (ChannelNum < 0) || (ChannelNum >= R_V_SYNC_CHANNEL_COUNT) ) {
1050186 3:9f857750e4e9 396 e=E_OTHERS;
1050186 3:9f857750e4e9 397 goto fin;
1050186 3:9f857750e4e9 398 }
1050186 3:9f857750e4e9 399
1050186 3:9f857750e4e9 400 *out_Status = &self->AsyncStatus;
1050186 3:9f857750e4e9 401
1050186 3:9f857750e4e9 402 e=0;
1050186 3:9f857750e4e9 403 fin:
1050186 3:9f857750e4e9 404 return e;
1050186 3:9f857750e4e9 405 }
1050186 3:9f857750e4e9 406
1050186 3:9f857750e4e9 407
1050186 3:9f857750e4e9 408 /**
1050186 3:9f857750e4e9 409 * @brief Enable interrupt API
1050186 3:9f857750e4e9 410 *
1050186 3:9f857750e4e9 411 * @param ChannelNum ChannelNum
1050186 3:9f857750e4e9 412 * @return None
1050186 3:9f857750e4e9 413 */
1050186 3:9f857750e4e9 414 void R_V_SYNC_EnableInterrupt( int_fast32_t const ChannelNum )
1050186 3:9f857750e4e9 415 {
1050186 3:9f857750e4e9 416 errnum_t e;
1050186 3:9f857750e4e9 417 r_v_sync_channel_t *const self = &gs_v_sync_channel[ ChannelNum ];
1050186 3:9f857750e4e9 418
1050186 3:9f857750e4e9 419 IF ( (ChannelNum < 0) || (ChannelNum >= R_V_SYNC_CHANNEL_COUNT) ) {
1050186 3:9f857750e4e9 420 e=E_OTHERS;
1050186 3:9f857750e4e9 421 goto fin;
1050186 3:9f857750e4e9 422 }
1050186 3:9f857750e4e9 423
1050186 3:9f857750e4e9 424 R_V_SYNC_OnEnableInterrupt( ChannelNum, self->InterruptEnables.Flags );
1050186 3:9f857750e4e9 425 self->IsEnabledInterrupt = true;
1050186 3:9f857750e4e9 426
1050186 3:9f857750e4e9 427 e=0;
1050186 3:9f857750e4e9 428 fin:
1050186 3:9f857750e4e9 429 R_UNREFERENCED_VARIABLE( e );
1050186 3:9f857750e4e9 430 }
1050186 3:9f857750e4e9 431
1050186 3:9f857750e4e9 432
1050186 3:9f857750e4e9 433 /**
1050186 3:9f857750e4e9 434 * @brief Disable interrupt API
1050186 3:9f857750e4e9 435 *
1050186 3:9f857750e4e9 436 * @param ChannelNum ChannelNum
1050186 3:9f857750e4e9 437 * @return None
1050186 3:9f857750e4e9 438 */
1050186 3:9f857750e4e9 439 bool_t R_V_SYNC_DisableInterrupt( int_fast32_t const ChannelNum )
1050186 3:9f857750e4e9 440 {
1050186 3:9f857750e4e9 441 errnum_t e;
1050186 3:9f857750e4e9 442 bool_t was_interrupted = false;
1050186 3:9f857750e4e9 443 r_v_sync_channel_t *const self = &gs_v_sync_channel[ ChannelNum ];
1050186 3:9f857750e4e9 444
1050186 3:9f857750e4e9 445 IF ( (ChannelNum < 0) || (ChannelNum >= R_V_SYNC_CHANNEL_COUNT) ) {
1050186 3:9f857750e4e9 446 e=E_OTHERS;
1050186 3:9f857750e4e9 447 goto fin;
1050186 3:9f857750e4e9 448 }
1050186 3:9f857750e4e9 449
1050186 3:9f857750e4e9 450 was_interrupted = self->IsEnabledInterrupt;
1050186 3:9f857750e4e9 451 self->IsEnabledInterrupt = false;
1050186 3:9f857750e4e9 452
1050186 3:9f857750e4e9 453 R_V_SYNC_OnDisableInterrupt( ChannelNum, self->InterruptEnables.Flags );
1050186 3:9f857750e4e9 454
1050186 3:9f857750e4e9 455 e=0;
1050186 3:9f857750e4e9 456 fin:
1050186 3:9f857750e4e9 457 R_UNREFERENCED_VARIABLE( e );
1050186 3:9f857750e4e9 458 return was_interrupted;
1050186 3:9f857750e4e9 459 }
1050186 3:9f857750e4e9 460
1050186 3:9f857750e4e9 461
1050186 3:9f857750e4e9 462 /**
1050186 3:9f857750e4e9 463 * @brief Reset I-Lock (Interrupt Lock)
1050186 3:9f857750e4e9 464 *
1050186 3:9f857750e4e9 465 * @param self r_v_sync_i_lock_t
1050186 3:9f857750e4e9 466 * @return None
1050186 3:9f857750e4e9 467 */
1050186 3:9f857750e4e9 468 static void R_V_SYNC_I_LOCK_Reset( r_v_sync_i_lock_t *const self )
1050186 3:9f857750e4e9 469 {
1050186 3:9f857750e4e9 470 IF_DQ( self == NULL ) {
1050186 3:9f857750e4e9 471 goto fin;
1050186 3:9f857750e4e9 472 }
1050186 3:9f857750e4e9 473
1050186 3:9f857750e4e9 474 self->is_lock = false;
1050186 3:9f857750e4e9 475 R_V_SYNC_OnDisableInterrupt( self->channel_num, R_V_SYNC_INTERRUPT_LINE_ALL );
1050186 3:9f857750e4e9 476
1050186 3:9f857750e4e9 477 fin:
1050186 3:9f857750e4e9 478 return;
1050186 3:9f857750e4e9 479 }
1050186 3:9f857750e4e9 480
1050186 3:9f857750e4e9 481
1050186 3:9f857750e4e9 482 /**
1050186 3:9f857750e4e9 483 * @brief Lock
1050186 3:9f857750e4e9 484 *
1050186 3:9f857750e4e9 485 * @param self r_v_sync_i_lock_t
1050186 3:9f857750e4e9 486 * @return Was interrupt enabled
1050186 3:9f857750e4e9 487 */
1050186 3:9f857750e4e9 488 static bool_t R_V_SYNC_I_LOCK_Lock( r_v_sync_i_lock_t *const self )
1050186 3:9f857750e4e9 489 {
1050186 3:9f857750e4e9 490 bool_t is_locked;
1050186 3:9f857750e4e9 491 bool_t was_all_enabled; /* = false; */ /* QAC 3197 */
1050186 3:9f857750e4e9 492 bool_t b;
1050186 3:9f857750e4e9 493
1050186 3:9f857750e4e9 494 IF_DQ( self == NULL ) {
1050186 3:9f857750e4e9 495 is_locked = true;
1050186 3:9f857750e4e9 496 goto fin;
1050186 3:9f857750e4e9 497 }
1050186 3:9f857750e4e9 498
1050186 3:9f857750e4e9 499 was_all_enabled = R_OSPL_DisableAllInterrupt();
1050186 3:9f857750e4e9 500
1050186 3:9f857750e4e9 501 is_locked = self->is_lock;
1050186 3:9f857750e4e9 502 if ( ! is_locked ) {
1050186 3:9f857750e4e9 503 b= R_V_SYNC_DisableInterrupt( self->channel_num );
1050186 3:9f857750e4e9 504 R_UNREFERENCED_VARIABLE( b ); /* QAC 3200 : This is not error information */
1050186 3:9f857750e4e9 505 self->is_lock = true;
1050186 3:9f857750e4e9 506 }
1050186 3:9f857750e4e9 507
1050186 3:9f857750e4e9 508 if ( IS( was_all_enabled ) ) {
1050186 3:9f857750e4e9 509 R_OSPL_EnableAllInterrupt();
1050186 3:9f857750e4e9 510 }
1050186 3:9f857750e4e9 511
1050186 3:9f857750e4e9 512 fin:
1050186 3:9f857750e4e9 513 return ! is_locked;
1050186 3:9f857750e4e9 514 }
1050186 3:9f857750e4e9 515
1050186 3:9f857750e4e9 516
1050186 3:9f857750e4e9 517 /**
1050186 3:9f857750e4e9 518 * @brief Unlock
1050186 3:9f857750e4e9 519 *
1050186 3:9f857750e4e9 520 * @param self r_v_sync_i_lock_t
1050186 3:9f857750e4e9 521 * @return None
1050186 3:9f857750e4e9 522 */
1050186 3:9f857750e4e9 523 static void R_V_SYNC_I_LOCK_Unlock( r_v_sync_i_lock_t *const self )
1050186 3:9f857750e4e9 524 {
1050186 3:9f857750e4e9 525 bool_t was_all_enabled; /* = false; */ /* QAC 3197 */
1050186 3:9f857750e4e9 526
1050186 3:9f857750e4e9 527 IF_DQ( self == NULL ) {
1050186 3:9f857750e4e9 528 goto fin;
1050186 3:9f857750e4e9 529 }
1050186 3:9f857750e4e9 530
1050186 3:9f857750e4e9 531 was_all_enabled = R_OSPL_DisableAllInterrupt();
1050186 3:9f857750e4e9 532
1050186 3:9f857750e4e9 533 R_V_SYNC_EnableInterrupt( self->channel_num );
1050186 3:9f857750e4e9 534 self->is_lock = false;
1050186 3:9f857750e4e9 535
1050186 3:9f857750e4e9 536 if ( IS( was_all_enabled ) ) {
1050186 3:9f857750e4e9 537 R_OSPL_EnableAllInterrupt();
1050186 3:9f857750e4e9 538 }
1050186 3:9f857750e4e9 539 fin:
1050186 3:9f857750e4e9 540 return;
1050186 3:9f857750e4e9 541 }
1050186 3:9f857750e4e9 542
1050186 3:9f857750e4e9 543