Anh Tran / Mbed OS GR-Boards_WebCamera

Dependencies:   HttpServer_snapshot_mbed-os

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers jcu_para.c Source File

jcu_para.c

00001 /*******************************************************************************
00002 * DISCLAIMER
00003 * This software is supplied by Renesas Electronics Corporation and is only
00004 * intended for use with Renesas products. No other uses are authorized. This
00005 * software is owned by Renesas Electronics Corporation and is protected under
00006 * all applicable laws, including copyright laws.
00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00016 * Renesas reserves the right, without notice, to make changes to this software
00017 * and to discontinue the availability of this software. By using this software,
00018 * you agree to the additional terms and conditions found by accessing the
00019 * following link:
00020 * http://www.renesas.com/disclaimer
00021 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
00022 *******************************************************************************/
00023 /*******************************************************************************
00024 * $FileName: jcu_para.c $
00025 * $Module: JCU $ $PublicVersion: 1.00 $ (=JCU_VERSION)
00026 * $Rev: 38 $
00027 * $Date:: 2014-03-18 16:14:45 +0900#$
00028 * Description : JCU driver checking parameter
00029 ******************************************************************************/
00030 
00031 /******************************************************************************
00032 Includes   <System Includes> , "Project Includes"
00033 ******************************************************************************/
00034 #include    <string.h>
00035 #include    "r_typedefs.h"
00036 #include    "r_ospl.h"
00037 #include    "r_jcu_api.h"
00038 #include    "r_jcu_local.h"
00039 #include    "r_jcu_user.h"
00040 #include    "iodefine.h"
00041 
00042 #ifdef      JCU_PARAMETER_CHECK
00043 
00044 /******************************************************************************
00045 Typedef definitions
00046 ******************************************************************************/
00047 
00048 /******************************************************************************
00049 Macro definitions
00050 ******************************************************************************/
00051 #define MASK_LOW_3BIT   (0x7u)
00052 #define MOD_8           (0x8u)
00053 #define MOD_16          (0x10u)
00054 
00055 /******************************************************************************
00056 Imported global variables and functions (from other files)
00057 ******************************************************************************/
00058 
00059 /******************************************************************************
00060 Exported global variables and functions (to be accessed by other files)
00061 ******************************************************************************/
00062 
00063 /******************************************************************************
00064 Private global variables and functions
00065 ******************************************************************************/
00066 
00067 /**************************************************************************//**
00068  * Function Name : [JCU_ParaCheckSelectCodec]
00069  * @brief       SelectCodec api's parameter checking
00070  * @param       [in] codec  codec type
00071  * @retval      jcu_errorcode_t
00072  *****************************************************************************/
00073 jcu_errorcode_t JCU_ParaCheckSelectCodec(
00074     const jcu_codec_t   codec)
00075 {
00076     jcu_errorcode_t  returnValue;
00077 
00078     IF_DS ((codec != JCU_ENCODE)
00079            && (codec != JCU_DECODE)) {
00080         returnValue = JCU_ERROR_PARAM;
00081     }
00082     else {
00083         returnValue = JCU_ERROR_OK;
00084     } /* end if */
00085 
00086     return (returnValue);
00087 }
00088 
00089 /**************************************************************************//**
00090  * Function Name : [JCU_ParaCheckStart]
00091  * @brief       Start api's parameter checking
00092  * @param       [in] codec  codec type
00093  * @retval      jcu_errorcode_t
00094  *****************************************************************************/
00095 jcu_errorcode_t JCU_ParaCheckStart(
00096     void)
00097 {
00098     jcu_errorcode_t   returnValue;
00099 
00100     /* If jcu already start, it cannot update this bit (this is limitation of hardware) */
00101 #if defined(TARGET_RZ_A1XX)
00102     IF ( (uint32_t)R_GET_REG_BIT_FIELD( JCU.JCCMD, JSRT ) == REG_F_SET ) {
00103 #elif defined(TARGET_RZ_A2XX)
00104     IF ( (uint32_t)R_GET_REG_BIT_FIELD( JCU.JCCMD.BYTE, JSRT ) == REG_F_SET ) {
00105 #endif
00106         returnValue = JCU_ERROR_STATUS;
00107     }
00108     else {
00109         returnValue = JCU_ERROR_OK;
00110     } /* end if */
00111 
00112     return (returnValue);
00113 }
00114 
00115 /**************************************************************************//**
00116  * Function Name : [JCU_ParaCheckSetCountMode]
00117  * @brief       parameter check for the SetCountMode
00118  * @param       [in] buffer the parameter for the Count Mode
00119  * @retval      jcu_errorcode_t
00120  *****************************************************************************/
00121 jcu_errorcode_t JCU_ParaCheckSetCountMode(
00122     const jcu_count_mode_param_t  *const buffer)
00123 {
00124     jcu_errorcode_t  returnValue = JCU_ERROR_OK;
00125 
00126     IF (buffer == NULL) {
00127         returnValue = JCU_ERROR_PARAM;
00128         goto fin;
00129     } /* end if */
00130 
00131     IF ((buffer->inputBuffer.isEnable != false) && (buffer->outputBuffer.isEnable != false)) {
00132         returnValue = JCU_ERROR_PARAM;
00133         goto fin;
00134     }
00135 
00136     if (buffer->inputBuffer.isEnable != false) {
00137         /* When initAddress is true, restartAddress has to set the address */
00138         if (buffer->inputBuffer.isInitAddress != false) {
00139             IF (buffer->inputBuffer.restartAddress == NULL) {
00140                 returnValue = JCU_ERROR_PARAM;
00141                 goto fin;
00142             } /* end if */
00143         } /* end if */
00144 
00145         /* Datasize(JDATAS/LINES bit) have to 8byte alignment */
00146         IF ((buffer->inputBuffer.dataCount & MASK_LOW_3BIT) != 0u) {
00147             returnValue = JCU_ERROR_PARAM;
00148             goto fin;
00149         } /* end if */
00150 
00151         /* Datasize have to bigger than 0 */
00152         IF (buffer->inputBuffer.dataCount == 0u) {
00153             returnValue = JCU_ERROR_PARAM;
00154             goto fin;
00155         } /* end if */
00156 
00157     } /* end if */
00158 
00159     if (buffer->outputBuffer.isEnable != false) {
00160         /* When initAddress is true, restartAddress has to set the address */
00161         if (buffer->outputBuffer.isInitAddress != false) {
00162             IF (buffer->outputBuffer.restartAddress == NULL) {
00163                 returnValue = JCU_ERROR_PARAM;
00164                 goto fin;
00165             } /* end if */
00166         } /* end if */
00167 
00168         /* Datasize(JDATAS/LINES bit) have to 8byte alignment */
00169         IF ((buffer->outputBuffer.dataCount & MASK_LOW_3BIT) != 0u) {
00170             returnValue = JCU_ERROR_PARAM;
00171             goto fin;
00172         } /* end if */
00173 
00174         /* Datasize have to bigger than 0 */
00175         IF (buffer->outputBuffer.dataCount == 0u) {
00176             returnValue = JCU_ERROR_PARAM;
00177             goto fin;
00178         } /* end if */
00179 
00180     } /* end if */
00181 fin:
00182     return (returnValue);
00183 }
00184 
00185 /**************************************************************************//**
00186  * Function Name : [JCU_ParaCheckSetDecodeParam]
00187  * @brief       SetDecodeParam api's parameter checking
00188  * @param       [in] buffer         input and output buffer settings
00189  * @param       [in] interruptKind  tye type of interrupt that use in this system
00190  * @retval      jcu_errorcode_t
00191  *****************************************************************************/
00192 jcu_errorcode_t JCU_ParaCheckSetDecodeParam(
00193     const jcu_decode_param_t   *const decode,
00194     const jcu_buffer_param_t   *const buffer)
00195 {
00196     jcu_errorcode_t  returnValue = JCU_ERROR_OK;
00197 
00198     IF ((decode == NULL) || (buffer == NULL)) {
00199         returnValue = JCU_ERROR_PARAM;
00200         goto fin;
00201     } /* end if */
00202 
00203     /* NULL check for the address data */
00204     IF ((buffer->source.address == NULL)
00205         || (buffer->destination.address == NULL)) {
00206         returnValue = JCU_ERROR_PARAM;
00207         goto fin;
00208     }  /* end if */
00209 
00210     /* Check for the address alignment */
00211     /* ->MISRA 11.3 */ /* ->SEC R2.7.1 */
00212     IF ((((uint32_t) (buffer->source.address) % MOD_8) != 0u) ||
00213         (((uint32_t) (buffer->destination.address) % MOD_8) != 0u))
00214     /* <-MISRA 11.3 */ { /* <-SEC R2.7.1 */
00215         returnValue = JCU_ERROR_PARAM;
00216         goto fin;
00217     }  /* end if */
00218 
00219     /*Check for Cb/Cr offset */
00220     if(decode->decodeFormat == JCU_OUTPUT_YCbCr422) {
00221         IF (((decode->outputCbCrOffset) != JCU_CBCR_OFFSET_0) && ((decode->outputCbCrOffset) != JCU_CBCR_OFFSET_128)) {
00222             returnValue = JCU_ERROR_PARAM;
00223         }  /* end if */
00224     } else {
00225         IF ((decode->outputCbCrOffset) != JCU_CBCR_OFFSET_0) {
00226             returnValue = JCU_ERROR_PARAM;
00227         }  /* end if */
00228     } /* end if */
00229 fin:
00230     return (returnValue);
00231 }
00232 
00233 /**************************************************************************//**
00234  * Function Name : [JCU_ParaCheckGetImageInfo]
00235  * @brief       GetImageInfo api's parameter checking
00236  * @param       [in] buffer         buffer address that set the image information
00237  * @retval      jcu_errorcode_t
00238  *****************************************************************************/
00239 jcu_errorcode_t JCU_ParaCheckGetImageInfo(
00240     const jcu_image_info_t   *const buffer)
00241 {
00242     jcu_errorcode_t  returnValue = JCU_ERROR_OK;
00243 
00244     IF (buffer == NULL) {
00245         returnValue = JCU_ERROR_PARAM;
00246     } /* end if */
00247 
00248     return (returnValue);
00249 }
00250 
00251 /**************************************************************************//**
00252  * Function Name : [JCU_ParaCheckSetQuantizationTbl]
00253  * @brief       SetQuantizationTable api's parameter checking
00254  * @param       [in] tableNo        the table number that set the parameter
00255  * @retval      jcu_errorcode_t
00256  *****************************************************************************/
00257 jcu_errorcode_t JCU_ParaCheckSetQuantizationTbl(
00258     const jcu_table_no_t   tableNo)
00259 {
00260     jcu_errorcode_t  returnValue = JCU_ERROR_OK;
00261 
00262     /* ->MISRA 13.7 : For fail safe. */
00263     IF_DS (tableNo > JCU_TABLE_NO_3)
00264     /* <-MISRA 13.7 */
00265     /* ->MISRA 14.1 ->QAC 3201 : For fail safe. */
00266     {
00267         returnValue = JCU_ERROR_PARAM;
00268     } /* end if */
00269     /* <-MISRA 14.1 <-QAC 3201 */
00270 
00271     return (returnValue);
00272 }
00273 
00274 /**************************************************************************//**
00275  * Function Name : [JCU_ParaCheckSetHuffmanTable]
00276  * @brief       SetHuffmanTable api's parameter checking
00277  * @param       [in] tableNo        the table number that set the parameter
00278  * @param       [in] type        the type which table is set(AC or DC)
00279  * @retval      jcu_errorcode_t
00280  *****************************************************************************/
00281 jcu_errorcode_t JCU_ParaCheckSetHuffmanTable(
00282     const jcu_table_no_t   tableNo,
00283     const jcu_huff_t       type)
00284 {
00285     jcu_errorcode_t  returnValue = JCU_ERROR_OK;
00286 
00287     /* ->MISRA 13.7 : For fail safe. */
00288     IF (tableNo > JCU_TABLE_NO_1)
00289     /* <-MISRA 13.7 */
00290     {
00291         returnValue = JCU_ERROR_PARAM;
00292         goto fin;
00293     } /* end if */
00294 
00295     /* ->MISRA 13.7 : For fail safe. */
00296     IF_DS ((type != JCU_HUFFMAN_AC)
00297            && (type != JCU_HUFFMAN_DC))
00298     /* <-MISRA 13.7 */
00299     /* ->MISRA 14.1 ->QAC 3201 : For fail safe. */
00300     {
00301         returnValue = JCU_ERROR_PARAM;
00302     } /* end if */
00303     /* <-MISRA 14.1 <-QAC 3201 */
00304 fin:
00305     return (returnValue);
00306 }
00307 
00308 /**************************************************************************//**
00309  * Function Name : [JCU_ParaCheckEncodeParam]
00310  * @brief        api's parameter checking
00311  * @param       [in]
00312  * @retval      jcu_errorcode_t
00313  *****************************************************************************/
00314 jcu_errorcode_t JCU_ParaCheckEncodeParam(
00315     const jcu_encode_param_t   *const encode,
00316     const jcu_buffer_param_t   *const buffer)
00317 {
00318     jcu_errorcode_t  returnValue = JCU_ERROR_OK;
00319 
00320     IF ((encode == NULL) || (buffer == NULL)) {
00321         returnValue = JCU_ERROR_PARAM;
00322         goto fin;
00323     } /* end if */
00324 
00325     /* NULL check for the address data */
00326     IF ((buffer->source.address == NULL)
00327         || (buffer->destination.address == NULL)) {
00328         returnValue = JCU_ERROR_PARAM;
00329         goto fin;
00330     }  /* end if */
00331 
00332 
00333     if (encode->encodeFormat == JCU_JPEG_YCbCr422) {
00334         /* Check the width of the image data */
00335         IF ((encode->width % MOD_16) != 0u) {
00336             returnValue = JCU_ERROR_PARAM;
00337             goto fin;
00338         } /* end if */
00339 
00340         /* Check the height of the image data */
00341         IF ((encode->height % MOD_8) != 0u) {
00342             returnValue = JCU_ERROR_PARAM;
00343             goto fin;
00344         } /* end if */
00345     } else {
00346         returnValue = JCU_ERROR_PARAM;
00347         ASSERT_D( false, R_NOOP() );
00348         goto fin;
00349     } /* end if */
00350 
00351     /*Check for Cb/Cr offset */
00352     IF (((encode->inputCbCrOffset) != JCU_CBCR_OFFSET_0) && ((encode->inputCbCrOffset) != JCU_CBCR_OFFSET_128)) {
00353         returnValue = JCU_ERROR_PARAM;
00354     }  /* end if */
00355 
00356 fin:
00357     return (returnValue);
00358 }
00359 
00360 #endif