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 * Copyright(c) 2010-2012 Renesas Electronics Corporation. All rights reserved.
1050186 3:9f857750e4e9 3 *
1050186 3:9f857750e4e9 4 * brief : NCG State variable control functions.
1050186 3:9f857750e4e9 5 *
1050186 3:9f857750e4e9 6 * author : Renesas Electronics Corporation
1050186 3:9f857750e4e9 7 *
1050186 3:9f857750e4e9 8 * history: 2010.10.08
1050186 3:9f857750e4e9 9 * - Created the initial code.
1050186 3:9f857750e4e9 10 * 2013.05.20
1050186 3:9f857750e4e9 11 * - Applied to CMSIS-RTOS RTX.
1050186 3:9f857750e4e9 12 * 2014.12.10
1050186 3:9f857750e4e9 13 * - Applied to OSPL and RGA.
1050186 3:9f857750e4e9 14 *
1050186 3:9f857750e4e9 15 *******************************************************************************/
1050186 3:9f857750e4e9 16
1050186 3:9f857750e4e9 17 /*=============================================================================
1050186 3:9f857750e4e9 18 * Includes
1050186 3:9f857750e4e9 19 */
1050186 3:9f857750e4e9 20 #include "Project_Config.h"
1050186 3:9f857750e4e9 21 #include "r_ospl.h"
1050186 3:9f857750e4e9 22
1050186 3:9f857750e4e9 23 #include "ncg_defs.h"
1050186 3:9f857750e4e9 24 #include "ncg_debug.h"
1050186 3:9f857750e4e9 25 #include "ncg_state.h"
1050186 3:9f857750e4e9 26
1050186 3:9f857750e4e9 27 #ifdef RGAH_VERSION
1050186 3:9f857750e4e9 28
1050186 3:9f857750e4e9 29 /*=============================================================================
1050186 3:9f857750e4e9 30 * Internal definitions
1050186 3:9f857750e4e9 31 */
1050186 3:9f857750e4e9 32
1050186 3:9f857750e4e9 33 #define NCG_MAX_STATE_OBJECTS (1U)
1050186 3:9f857750e4e9 34 #define NCG_MAX_THREAD_ID (1U)
1050186 3:9f857750e4e9 35
1050186 3:9f857750e4e9 36 struct NCG_STATE_T {
1050186 3:9f857750e4e9 37 r_ospl_thread_id_t id[NCG_MAX_THREAD_ID];
1050186 3:9f857750e4e9 38 NCGboolean bInUse;
1050186 3:9f857750e4e9 39 int32_t flgbit;
1050186 3:9f857750e4e9 40 NCGuint32 ui32State;
1050186 3:9f857750e4e9 41 } ;
1050186 3:9f857750e4e9 42
1050186 3:9f857750e4e9 43
1050186 3:9f857750e4e9 44 /*=============================================================================
1050186 3:9f857750e4e9 45 * Prototyping of internal functions
1050186 3:9f857750e4e9 46 */
1050186 3:9f857750e4e9 47
1050186 3:9f857750e4e9 48 static NCGint32 ncg_init_states( void ) ;
1050186 3:9f857750e4e9 49 static NCGuint32 ncg_state_search( NCGvoid *pObj );
1050186 3:9f857750e4e9 50
1050186 3:9f857750e4e9 51
1050186 3:9f857750e4e9 52 /*=============================================================================
1050186 3:9f857750e4e9 53 * Private global variables and functions
1050186 3:9f857750e4e9 54 */
1050186 3:9f857750e4e9 55
1050186 3:9f857750e4e9 56 volatile static struct NCG_STATE_T tStates[NCG_MAX_STATE_OBJECTS];
1050186 3:9f857750e4e9 57
1050186 3:9f857750e4e9 58 static NCGboolean ncg_state_initialized = NCG_FALSE ;
1050186 3:9f857750e4e9 59 static struct NCG_STATE_T *ncg_last_created_state;
1050186 3:9f857750e4e9 60
1050186 3:9f857750e4e9 61
1050186 3:9f857750e4e9 62 /*=============================================================================
1050186 3:9f857750e4e9 63 * Global Function
1050186 3:9f857750e4e9 64 */
1050186 3:9f857750e4e9 65
1050186 3:9f857750e4e9 66 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 67 NAME : NCGSYS_CreateState
1050186 3:9f857750e4e9 68 FUNCTION : Create a state control object.
1050186 3:9f857750e4e9 69 PARAMETERS : ppObj : [OUT] The pointer to the created state control object.
1050186 3:9f857750e4e9 70 ui32StateID : [IN ] The identifier of the state variable.
1050186 3:9f857750e4e9 71 RETURN : Error code of the NCG.
1050186 3:9f857750e4e9 72 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 73 NCGint32
1050186 3:9f857750e4e9 74 NCGSYS_CreateState(
1050186 3:9f857750e4e9 75 NCGvoid **ppObj,
1050186 3:9f857750e4e9 76 NCGuint32 ui32StateID )
1050186 3:9f857750e4e9 77 {
1050186 3:9f857750e4e9 78 struct NCG_STATE_T *p_state;
1050186 3:9f857750e4e9 79 NCGuint32 state_idx;
1050186 3:9f857750e4e9 80 NCGuint32 thread_idx;
1050186 3:9f857750e4e9 81
1050186 3:9f857750e4e9 82 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_CreateState" );
1050186 3:9f857750e4e9 83
1050186 3:9f857750e4e9 84 NCG_UNREFERENCED_PARAMETER(ui32StateID);
1050186 3:9f857750e4e9 85
1050186 3:9f857750e4e9 86 if( ppObj == NCG_NULL ) {
1050186 3:9f857750e4e9 87 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_CreateState(1) invalid ppObj.%s" )
1050186 3:9f857750e4e9 88 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 89 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 90 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 91 return NCG_err_invalid_handle ;
1050186 3:9f857750e4e9 92 }
1050186 3:9f857750e4e9 93
1050186 3:9f857750e4e9 94 if( ncg_state_initialized == NCG_FALSE ) {
1050186 3:9f857750e4e9 95 ncg_init_states();
1050186 3:9f857750e4e9 96 }
1050186 3:9f857750e4e9 97
1050186 3:9f857750e4e9 98 p_state = NULL;
1050186 3:9f857750e4e9 99 for ( state_idx = 0 ; state_idx < NCG_MAX_STATE_OBJECTS ; state_idx++ ) {
1050186 3:9f857750e4e9 100 if ( tStates[state_idx].bInUse == NCG_FALSE ) {
1050186 3:9f857750e4e9 101 p_state = (struct NCG_STATE_T *)&tStates[state_idx];
1050186 3:9f857750e4e9 102 break ;
1050186 3:9f857750e4e9 103 }
1050186 3:9f857750e4e9 104 }
1050186 3:9f857750e4e9 105 if ( p_state == NULL ) {
1050186 3:9f857750e4e9 106 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_CreateState(2) Object over flow.%s" )
1050186 3:9f857750e4e9 107 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 108 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 109 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 110 return NCG_err_resource_exceeded ;
1050186 3:9f857750e4e9 111 }
1050186 3:9f857750e4e9 112
1050186 3:9f857750e4e9 113 /* set initial value */
1050186 3:9f857750e4e9 114 for ( thread_idx = 1U ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) {
1050186 3:9f857750e4e9 115 p_state->id[thread_idx] = NULL;
1050186 3:9f857750e4e9 116 }
1050186 3:9f857750e4e9 117 p_state->id[0] = R_OSPL_THREAD_GetCurrentId(); /* [0] is current thread id */
1050186 3:9f857750e4e9 118 p_state->bInUse = NCG_TRUE ;
1050186 3:9f857750e4e9 119 p_state->ui32State = 0U ;
1050186 3:9f857750e4e9 120
1050186 3:9f857750e4e9 121 *ppObj = ( NCGvoid *)p_state ;
1050186 3:9f857750e4e9 122 ncg_last_created_state = p_state;
1050186 3:9f857750e4e9 123
1050186 3:9f857750e4e9 124 return NCG_no_err ;
1050186 3:9f857750e4e9 125 }
1050186 3:9f857750e4e9 126
1050186 3:9f857750e4e9 127 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 128 NAME : NCGSYS_DestroyState
1050186 3:9f857750e4e9 129 FUNCTION : Destroy the given state control object.
1050186 3:9f857750e4e9 130 PARAMETERS : pObj : [IN ] The pointer to the state control object.
1050186 3:9f857750e4e9 131 RETURN : Error code of the NCG.
1050186 3:9f857750e4e9 132 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 133 NCGint32
1050186 3:9f857750e4e9 134 NCGSYS_DestroyState(
1050186 3:9f857750e4e9 135 NCGvoid *pObj )
1050186 3:9f857750e4e9 136 {
1050186 3:9f857750e4e9 137 volatile struct NCG_STATE_T *p_state;
1050186 3:9f857750e4e9 138 NCGuint32 state_idx;
1050186 3:9f857750e4e9 139 NCGuint32 thread_idx;
1050186 3:9f857750e4e9 140 NCGboolean bDestroyFlg ;
1050186 3:9f857750e4e9 141
1050186 3:9f857750e4e9 142 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_DestroyState" );
1050186 3:9f857750e4e9 143
1050186 3:9f857750e4e9 144 p_state = (struct NCG_STATE_T *)pObj;
1050186 3:9f857750e4e9 145 if( p_state == NCG_NULL ) {
1050186 3:9f857750e4e9 146 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_DestroyState(1) Failed: pObj is NULL.%s" )
1050186 3:9f857750e4e9 147 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 148 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 149 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 150 return NCG_err_invalid_handle ;
1050186 3:9f857750e4e9 151 }
1050186 3:9f857750e4e9 152
1050186 3:9f857750e4e9 153 state_idx = ncg_state_search( pObj );
1050186 3:9f857750e4e9 154 if ( state_idx >= NCG_MAX_STATE_OBJECTS ) {
1050186 3:9f857750e4e9 155 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_DestroyState(2) Failed: pObj is not found.%s" )
1050186 3:9f857750e4e9 156 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 157 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 158 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 159 return NCG_err_not_found ;
1050186 3:9f857750e4e9 160 }
1050186 3:9f857750e4e9 161
1050186 3:9f857750e4e9 162 if( p_state->bInUse == NCG_FALSE ) {
1050186 3:9f857750e4e9 163 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_DestroyState(3) Failed: pObj is not used.%s" )
1050186 3:9f857750e4e9 164 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 165 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 166 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 167 return NCG_err_bad_parameter ;
1050186 3:9f857750e4e9 168 }
1050186 3:9f857750e4e9 169
1050186 3:9f857750e4e9 170 /* clear status parameters */
1050186 3:9f857750e4e9 171 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) {
1050186 3:9f857750e4e9 172 p_state->id[thread_idx] = NULL;
1050186 3:9f857750e4e9 173 }
1050186 3:9f857750e4e9 174 p_state->bInUse = NCG_FALSE;
1050186 3:9f857750e4e9 175 p_state->ui32State = 0U;
1050186 3:9f857750e4e9 176
1050186 3:9f857750e4e9 177 bDestroyFlg = NCG_TRUE ;
1050186 3:9f857750e4e9 178 for ( state_idx = 0 ; state_idx < NCG_MAX_STATE_OBJECTS ; state_idx++ ) {
1050186 3:9f857750e4e9 179 if ( tStates[state_idx].bInUse != NCG_FALSE ) {
1050186 3:9f857750e4e9 180 bDestroyFlg = NCG_FALSE ;
1050186 3:9f857750e4e9 181 break ;
1050186 3:9f857750e4e9 182 }
1050186 3:9f857750e4e9 183 }
1050186 3:9f857750e4e9 184 if ( bDestroyFlg != NCG_FALSE ) {
1050186 3:9f857750e4e9 185 ncg_state_initialized = NCG_FALSE ;
1050186 3:9f857750e4e9 186 }
1050186 3:9f857750e4e9 187 return NCG_no_err ;
1050186 3:9f857750e4e9 188 }
1050186 3:9f857750e4e9 189
1050186 3:9f857750e4e9 190 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 191 NAME : NCGSYS_SetState
1050186 3:9f857750e4e9 192 FUNCTION : Set the state control object into the given state.
1050186 3:9f857750e4e9 193 PARAMETERS : pObj : [IN ] The pointer to the state control object.
1050186 3:9f857750e4e9 194 ui32State : [IN ] The state value to set.
1050186 3:9f857750e4e9 195 ui32Flags : [IN ] Flags.
1050186 3:9f857750e4e9 196 RETURN : Error code of the NCG.
1050186 3:9f857750e4e9 197 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 198 NCGint32
1050186 3:9f857750e4e9 199 NCGSYS_SetState(
1050186 3:9f857750e4e9 200 NCGvoid *pObj,
1050186 3:9f857750e4e9 201 NCGuint32 ui32State,
1050186 3:9f857750e4e9 202 NCGuint32 ui32Flags )
1050186 3:9f857750e4e9 203 {
1050186 3:9f857750e4e9 204 volatile struct NCG_STATE_T *p_state = (volatile struct NCG_STATE_T *)pObj ;
1050186 3:9f857750e4e9 205
1050186 3:9f857750e4e9 206 NCGuint32 uiSetMask;
1050186 3:9f857750e4e9 207 NCGuint32 thread_idx;
1050186 3:9f857750e4e9 208
1050186 3:9f857750e4e9 209 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_SetState" );
1050186 3:9f857750e4e9 210
1050186 3:9f857750e4e9 211 if( pObj == NCG_NULL ) {
1050186 3:9f857750e4e9 212 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_SetState(1) Failed:pObj is NULL.%s" )
1050186 3:9f857750e4e9 213 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 214 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 215 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 216 return NCG_err_unknown ;
1050186 3:9f857750e4e9 217 }
1050186 3:9f857750e4e9 218
1050186 3:9f857750e4e9 219 if ( ncg_state_search( pObj ) >= NCG_MAX_STATE_OBJECTS ) {
1050186 3:9f857750e4e9 220 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_SetState(2) Failed: pObj is not found.%s" )
1050186 3:9f857750e4e9 221 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 222 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 223 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 224 return NCG_err_not_found ;
1050186 3:9f857750e4e9 225 }
1050186 3:9f857750e4e9 226
1050186 3:9f857750e4e9 227 p_state = (volatile struct NCG_STATE_T *)pObj;
1050186 3:9f857750e4e9 228 if ( p_state->bInUse == NCG_FALSE ) {
1050186 3:9f857750e4e9 229 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_SetState(3) Failed: pObj is not used.%s" )
1050186 3:9f857750e4e9 230 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 231 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 232 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 233 return NCG_err_bad_parameter ;
1050186 3:9f857750e4e9 234 }
1050186 3:9f857750e4e9 235
1050186 3:9f857750e4e9 236 uiSetMask = ui32Flags & NCGSYS_STATE_SET_MASK;
1050186 3:9f857750e4e9 237 switch( uiSetMask ) {
1050186 3:9f857750e4e9 238 case NCGSYS_STATE_SET_AND :
1050186 3:9f857750e4e9 239 p_state->ui32State &= ui32State ;
1050186 3:9f857750e4e9 240 break ;
1050186 3:9f857750e4e9 241
1050186 3:9f857750e4e9 242 case NCGSYS_STATE_SET_OR :
1050186 3:9f857750e4e9 243 p_state->ui32State |= ui32State ;
1050186 3:9f857750e4e9 244 break ;
1050186 3:9f857750e4e9 245
1050186 3:9f857750e4e9 246 case NCGSYS_STATE_SET_SET :
1050186 3:9f857750e4e9 247 p_state->ui32State = ui32State ;
1050186 3:9f857750e4e9 248 break ;
1050186 3:9f857750e4e9 249
1050186 3:9f857750e4e9 250 default :
1050186 3:9f857750e4e9 251 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_SetState(5) Failed:ui32Flags (0x%08x).%s" )
1050186 3:9f857750e4e9 252 NCG_DEBUG_MAKE_MSG_PARAMETER( ui32Flags )
1050186 3:9f857750e4e9 253 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 254 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 255 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 256 return NCG_err_bad_parameter ;
1050186 3:9f857750e4e9 257 }
1050186 3:9f857750e4e9 258
1050186 3:9f857750e4e9 259 if ( uiSetMask == NCGSYS_STATE_SET_AND ) {
1050186 3:9f857750e4e9 260 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) {
1050186 3:9f857750e4e9 261 if ( p_state->id[thread_idx] != NULL ) {
1050186 3:9f857750e4e9 262 r_ospl_thread_id_t thread = p_state->id[thread_idx]; /* ICCARM Pa082 : volatile's order */
1050186 3:9f857750e4e9 263 R_OSPL_EVENT_Clear( thread, p_state->flgbit );
1050186 3:9f857750e4e9 264 }
1050186 3:9f857750e4e9 265 }
1050186 3:9f857750e4e9 266 } else {
1050186 3:9f857750e4e9 267 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) {
1050186 3:9f857750e4e9 268 if ( p_state->id[thread_idx] != NULL ) {
1050186 3:9f857750e4e9 269 r_ospl_thread_id_t thread = p_state->id[thread_idx]; /* ICCARM Pa082 : volatile's order */
1050186 3:9f857750e4e9 270 R_OSPL_EVENT_Set( thread, p_state->flgbit );
1050186 3:9f857750e4e9 271 }
1050186 3:9f857750e4e9 272 }
1050186 3:9f857750e4e9 273 }
1050186 3:9f857750e4e9 274
1050186 3:9f857750e4e9 275 return NCG_no_err ;
1050186 3:9f857750e4e9 276 }
1050186 3:9f857750e4e9 277
1050186 3:9f857750e4e9 278 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 279 NAME : NCGSYS_GetState
1050186 3:9f857750e4e9 280 FUNCTION : Get the current state value from the state control object.
1050186 3:9f857750e4e9 281 PARAMETERS : pObj : [IN ] The pointer to the state control object.
1050186 3:9f857750e4e9 282 ui32Flags : [IN ] Flags.
1050186 3:9f857750e4e9 283 RETURN : Error code of the NCG.
1050186 3:9f857750e4e9 284 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 285 NCGuint32
1050186 3:9f857750e4e9 286 NCGSYS_GetState(
1050186 3:9f857750e4e9 287 NCGvoid *pObj,
1050186 3:9f857750e4e9 288 NCGuint32 ui32Flags )
1050186 3:9f857750e4e9 289 {
1050186 3:9f857750e4e9 290 volatile struct NCG_STATE_T *p_state;
1050186 3:9f857750e4e9 291
1050186 3:9f857750e4e9 292 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_GetState" );
1050186 3:9f857750e4e9 293
1050186 3:9f857750e4e9 294 NCG_UNREFERENCED_PARAMETER(ui32Flags);
1050186 3:9f857750e4e9 295
1050186 3:9f857750e4e9 296 if ( pObj == NCG_NULL ) {
1050186 3:9f857750e4e9 297 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_GetState(1) Failed: pObj.%s" )
1050186 3:9f857750e4e9 298 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 299 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 300 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 301 return (NCGuint32)NCG_err_unknown ;
1050186 3:9f857750e4e9 302 }
1050186 3:9f857750e4e9 303
1050186 3:9f857750e4e9 304 if ( ncg_state_search( pObj ) >= NCG_MAX_STATE_OBJECTS ) {
1050186 3:9f857750e4e9 305 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_GetState(2) Failed: pObj is not found.%s" )
1050186 3:9f857750e4e9 306 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 307 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 308 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 309 return (NCGuint32)NCG_err_not_found ;
1050186 3:9f857750e4e9 310 }
1050186 3:9f857750e4e9 311
1050186 3:9f857750e4e9 312 p_state = (volatile struct NCG_STATE_T *)pObj;
1050186 3:9f857750e4e9 313 if( p_state->bInUse == NCG_FALSE ) {
1050186 3:9f857750e4e9 314 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_GetState(3) Failed: pObj is not used.%s" )
1050186 3:9f857750e4e9 315 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 316 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 317 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 318 return (NCGuint32)NCG_err_bad_parameter ;
1050186 3:9f857750e4e9 319 }
1050186 3:9f857750e4e9 320 return ( NCGuint32 )p_state->ui32State ;
1050186 3:9f857750e4e9 321 }
1050186 3:9f857750e4e9 322
1050186 3:9f857750e4e9 323 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 324 NAME : NCGSYS_WaitState
1050186 3:9f857750e4e9 325 FUNCTION : Wait for the state control object to be in the given state.
1050186 3:9f857750e4e9 326 PARAMETERS : pObj : [IN ] The pointer to the state control object.
1050186 3:9f857750e4e9 327 ui32State : [IN ] The state value to wait for.
1050186 3:9f857750e4e9 328 ui32Flags : [IN ] Flags.
1050186 3:9f857750e4e9 329 ui32Timeout : [IN ] Timeout value in milli seconds.
1050186 3:9f857750e4e9 330 RETURN : Error code of the NCG.
1050186 3:9f857750e4e9 331 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 332 NCGint32
1050186 3:9f857750e4e9 333 NCGSYS_WaitState(
1050186 3:9f857750e4e9 334 NCGvoid *pObj,
1050186 3:9f857750e4e9 335 NCGuint32 ui32State,
1050186 3:9f857750e4e9 336 NCGuint32 ui32Flags,
1050186 3:9f857750e4e9 337 NCGuint32 ui32Timeout )
1050186 3:9f857750e4e9 338 {
1050186 3:9f857750e4e9 339 volatile struct NCG_STATE_T *p_state;
1050186 3:9f857750e4e9 340 NCGuint32 wait_mode;
1050186 3:9f857750e4e9 341 NCGuint32 thread_idx;
1050186 3:9f857750e4e9 342 NCGint32 func_ret;
1050186 3:9f857750e4e9 343 uint32_t time_out;
1050186 3:9f857750e4e9 344 errnum_t e;
1050186 3:9f857750e4e9 345
1050186 3:9f857750e4e9 346
1050186 3:9f857750e4e9 347 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_WaitState" );
1050186 3:9f857750e4e9 348
1050186 3:9f857750e4e9 349 p_state = (volatile struct NCG_STATE_T *)pObj;
1050186 3:9f857750e4e9 350 wait_mode = (ui32Flags & NCGSYS_STATE_WAIT_MASK);
1050186 3:9f857750e4e9 351
1050186 3:9f857750e4e9 352 if ( p_state == NCG_NULL ) {
1050186 3:9f857750e4e9 353 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_WaitState(1) Failed: pObj is NULL.%s" )
1050186 3:9f857750e4e9 354 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 355 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 356 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 357 return NCG_err_unknown ;
1050186 3:9f857750e4e9 358 }
1050186 3:9f857750e4e9 359 if ( p_state->bInUse == NCG_FALSE ) {
1050186 3:9f857750e4e9 360 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_WaitState(2) Failed: pObj.%s" )
1050186 3:9f857750e4e9 361 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 362 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 363 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 364 return NCG_err_unknown ;
1050186 3:9f857750e4e9 365 }
1050186 3:9f857750e4e9 366 if (( ui32Timeout != NCG_TIMEOUT_INFINITE ) && ( ui32Timeout > 0x7fffffffU )) {
1050186 3:9f857750e4e9 367 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_WaitState(3) Failed: ui32Timeout.%s" )
1050186 3:9f857750e4e9 368 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF )
1050186 3:9f857750e4e9 369 NCG_DEBUG_MAKE_MSG_END();
1050186 3:9f857750e4e9 370 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF );
1050186 3:9f857750e4e9 371 return NCG_err_unknown ;
1050186 3:9f857750e4e9 372 }
1050186 3:9f857750e4e9 373
1050186 3:9f857750e4e9 374 if ( ui32Timeout == NCG_TIMEOUT_INFINITE ) {
1050186 3:9f857750e4e9 375 time_out = R_OSPL_INFINITE;
1050186 3:9f857750e4e9 376 } else {
1050186 3:9f857750e4e9 377 time_out = ui32Timeout;
1050186 3:9f857750e4e9 378 }
1050186 3:9f857750e4e9 379
1050186 3:9f857750e4e9 380 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) {
1050186 3:9f857750e4e9 381 if ( p_state->id[thread_idx] == R_OSPL_THREAD_GetCurrentId() ) {
1050186 3:9f857750e4e9 382 break;
1050186 3:9f857750e4e9 383 }
1050186 3:9f857750e4e9 384 if ( p_state->id[thread_idx] == NULL ) {
1050186 3:9f857750e4e9 385 /* add thread ID */
1050186 3:9f857750e4e9 386 p_state->id[thread_idx] = R_OSPL_THREAD_GetCurrentId();
1050186 3:9f857750e4e9 387 break;
1050186 3:9f857750e4e9 388 }
1050186 3:9f857750e4e9 389 }
1050186 3:9f857750e4e9 390
1050186 3:9f857750e4e9 391 while (1) {
1050186 3:9f857750e4e9 392 if ( wait_mode == NCGSYS_STATE_WAIT_OR ) {
1050186 3:9f857750e4e9 393 if ( (p_state->ui32State & ui32State) != 0 ) {
1050186 3:9f857750e4e9 394 func_ret = NCG_no_err;
1050186 3:9f857750e4e9 395 break;
1050186 3:9f857750e4e9 396 }
1050186 3:9f857750e4e9 397 } else {
1050186 3:9f857750e4e9 398 /* wait_mode == NCGSYS_STATE_WAIT_AND */
1050186 3:9f857750e4e9 399 if ( (p_state->ui32State & ui32State) == ui32State ) {
1050186 3:9f857750e4e9 400 func_ret = NCG_no_err;
1050186 3:9f857750e4e9 401 break;
1050186 3:9f857750e4e9 402 }
1050186 3:9f857750e4e9 403 }
1050186 3:9f857750e4e9 404 e = R_OSPL_EVENT_Wait( p_state->flgbit, NULL, time_out );
1050186 3:9f857750e4e9 405 IF ( e != 0 ) {
1050186 3:9f857750e4e9 406 func_ret = NCG_err_unknown;
1050186 3:9f857750e4e9 407 break;
1050186 3:9f857750e4e9 408 }
1050186 3:9f857750e4e9 409 }
1050186 3:9f857750e4e9 410
1050186 3:9f857750e4e9 411 for ( thread_idx = 1 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) {
1050186 3:9f857750e4e9 412 p_state->id[thread_idx] = NULL;
1050186 3:9f857750e4e9 413 }
1050186 3:9f857750e4e9 414
1050186 3:9f857750e4e9 415 return func_ret;
1050186 3:9f857750e4e9 416 }
1050186 3:9f857750e4e9 417
1050186 3:9f857750e4e9 418
1050186 3:9f857750e4e9 419 /*=============================================================================
1050186 3:9f857750e4e9 420 * Internal functions
1050186 3:9f857750e4e9 421 */
1050186 3:9f857750e4e9 422
1050186 3:9f857750e4e9 423 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 424 NAME : ncg_init_states
1050186 3:9f857750e4e9 425 FUNCTION : Initialize global variable in NCG state.
1050186 3:9f857750e4e9 426 PARAMETERS : None.
1050186 3:9f857750e4e9 427 RETURN : None.
1050186 3:9f857750e4e9 428 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 429 static NCGint32
1050186 3:9f857750e4e9 430 ncg_init_states( void )
1050186 3:9f857750e4e9 431 {
1050186 3:9f857750e4e9 432 NCGuint32 i ;
1050186 3:9f857750e4e9 433 NCGuint32 thread_idx;
1050186 3:9f857750e4e9 434
1050186 3:9f857750e4e9 435 for( i = 0 ; i < NCG_MAX_STATE_OBJECTS ; i++ ) {
1050186 3:9f857750e4e9 436 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) {
1050186 3:9f857750e4e9 437 tStates[i].id[thread_idx] = NULL;
1050186 3:9f857750e4e9 438 }
1050186 3:9f857750e4e9 439 tStates[i].bInUse = NCG_FALSE ;
1050186 3:9f857750e4e9 440 tStates[i].flgbit = (int32_t)(1 << i) ;
1050186 3:9f857750e4e9 441 tStates[ i ].ui32State = 0U ;
1050186 3:9f857750e4e9 442 }
1050186 3:9f857750e4e9 443 ncg_state_initialized = NCG_TRUE ;
1050186 3:9f857750e4e9 444
1050186 3:9f857750e4e9 445 return NCG_no_err;
1050186 3:9f857750e4e9 446 }
1050186 3:9f857750e4e9 447
1050186 3:9f857750e4e9 448 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 449 NAME : ncg_state_search
1050186 3:9f857750e4e9 450 FUNCTION : Search status object.
1050186 3:9f857750e4e9 451 PARAMETERS : pObj :[IN ] Handle to the status object.
1050186 3:9f857750e4e9 452 RETURN : Index of the status object.
1050186 3:9f857750e4e9 453 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 454 static NCGuint32 ncg_state_search(
1050186 3:9f857750e4e9 455 NCGvoid *pObj
1050186 3:9f857750e4e9 456 )
1050186 3:9f857750e4e9 457 {
1050186 3:9f857750e4e9 458 NCGuint32 state_idx;
1050186 3:9f857750e4e9 459
1050186 3:9f857750e4e9 460 for ( state_idx = 0U ; state_idx < NCG_MAX_STATE_OBJECTS ; state_idx++ ) {
1050186 3:9f857750e4e9 461 if ( pObj == &tStates[state_idx] ) {
1050186 3:9f857750e4e9 462 break;
1050186 3:9f857750e4e9 463 }
1050186 3:9f857750e4e9 464 }
1050186 3:9f857750e4e9 465
1050186 3:9f857750e4e9 466 return state_idx;
1050186 3:9f857750e4e9 467 }
1050186 3:9f857750e4e9 468
1050186 3:9f857750e4e9 469 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 470 NAME : NCGSYS_SetStateEventValue
1050186 3:9f857750e4e9 471 FUNCTION : Set the value of thread attached event.
1050186 3:9f857750e4e9 472 PARAMETERS : pObj : [IN ] The pointer to the state control object.
1050186 3:9f857750e4e9 473 ui32EventValue : [IN ] The value of thread attached event.
1050186 3:9f857750e4e9 474 RETURN : None.
1050186 3:9f857750e4e9 475 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 476 NCGvoid
1050186 3:9f857750e4e9 477 NCGSYS_SetStateEventValue(
1050186 3:9f857750e4e9 478 NCGvoid *pObj,
1050186 3:9f857750e4e9 479 NCGuint32 ui32EventValue )
1050186 3:9f857750e4e9 480 {
1050186 3:9f857750e4e9 481 volatile struct NCG_STATE_T *p_state = (volatile struct NCG_STATE_T *)pObj ;
1050186 3:9f857750e4e9 482
1050186 3:9f857750e4e9 483 p_state->flgbit = ui32EventValue;
1050186 3:9f857750e4e9 484 }
1050186 3:9f857750e4e9 485
1050186 3:9f857750e4e9 486 /*----------------------------------------------------------------------------
1050186 3:9f857750e4e9 487 NAME : NCGSYS_GetLastCreatedState
1050186 3:9f857750e4e9 488 FUNCTION : GetLastCreatedState.
1050186 3:9f857750e4e9 489 PARAMETERS : None.
1050186 3:9f857750e4e9 490 RETURN : LastCreatedState.
1050186 3:9f857750e4e9 491 ------------------------------------------------------------------------------*/
1050186 3:9f857750e4e9 492 NCGvoid *
1050186 3:9f857750e4e9 493 NCGSYS_GetLastCreatedState(void)
1050186 3:9f857750e4e9 494 {
1050186 3:9f857750e4e9 495 return (NCGvoid *) ncg_last_created_state;
1050186 3:9f857750e4e9 496 }
1050186 3:9f857750e4e9 497
1050186 3:9f857750e4e9 498 #endif
1050186 3:9f857750e4e9 499 /* -- end of file -- */