RZ/A1H CMSIS-RTOS RTX BSP for GR-PEACH.

Dependents:   R_BSP_SSIF_HelloWorld GR-PEACH_Azure_Speech ImageZoomInout_Sample ImageRotaion_Sample ... more

Fork of R_BSP by Daiki Kato

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers scux_if.c Source File

scux_if.c

Go to the documentation of this file.
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) 2013-2014 Renesas Electronics Corporation. All rights reserved.
00022 *******************************************************************************/
00023 
00024 /**************************************************************************//**
00025 * @file         scux_if.c
00026 * $Rev: 1674 $
00027 * $Date:: 2015-05-29 16:35:57 +0900#$
00028 * @brief        SCUX Driver interface functions
00029 
00030 *******************************************************************************/
00031 
00032 /*******************************************************************************
00033 Includes <System Includes>, "Project Includes"
00034 *******************************************************************************/
00035 
00036 #include "scux.h"
00037 #include "bsp_util.h"
00038 
00039 /******************************************************************************
00040 Macro definitions
00041 ******************************************************************************/
00042 
00043 #define SCUX_PATH_CH0 "\\0"    /**< channel 0 pathname */
00044 #define SCUX_PATH_CH1 "\\1"    /**< channel 1 pathname */
00045 #define SCUX_PATH_CH2 "\\2"    /**< channel 2 pathname */
00046 #define SCUX_PATH_CH3 "\\3"    /**< channel 3 pathname */
00047 #define MAX_PATH_SEARCH_LEN (32U)
00048 
00049 /******************************************************************************
00050 Private global tables
00051 ******************************************************************************/
00052 
00053 #if(1) /* mbed */
00054 #else  /* not mbed */
00055 static IOIF_DRV_API gb_ioif_scux_cb_table;
00056 #endif /* end mbed */
00057 
00058 static const char_t* const p_gb_device_name[SCUX_CH_NUM] =
00059 {
00060     SCUX_PATH_CH0,
00061     SCUX_PATH_CH1,
00062     SCUX_PATH_CH2,
00063     SCUX_PATH_CH3
00064 };
00065 
00066 /******************************************************************************
00067 Private global driver semaphore informationn
00068 ******************************************************************************/
00069 
00070 /******************************************************************************
00071  Function prototypes
00072  *****************************************************************************/
00073 #if(1) /* mbed */
00074 static void *R_SCUX_InitOne(const int_t channel, const void * const p_config_data, int32_t * const p_errno); 
00075 static int_t R_SCUX_UnInitOne(const int_t channel, const void* const p_driver_instance, int32_t * const p_errno);
00076 #else
00077 static void* R_SCUX_Init(void * p_config_data, int32_t * const p_errno);
00078 static int_t R_SCUX_UnInit(void *p_driver_instance, int32_t * const p_errno);
00079 #endif /* end mbed */
00080 static int_t R_SCUX_Open(void * const p_driver_instance, const char_t * p_path_name, const int_t flags, int_t mode, int32_t * const p_errno);
00081 static int_t R_SCUX_Close(void * const p_fd, int32_t * const p_errno);
00082 static int_t R_SCUX_Ioctl(void * const p_fd, const int_t request, void * const p_buf, int32_t * const p_errno);
00083 static int_t R_SCUX_WriteAsync(void * const p_fd, AIOCB * const p_aio, int32_t * const p_errno);
00084 static int_t R_SCUX_ReadAsync(void * const p_fd, AIOCB * const p_aio, int32_t * const p_errno);
00085 static int_t R_SCUX_Cancel(void * const p_fd, AIOCB * const p_aio, int32_t * const p_errno);
00086 static void  SCUX_SetErrCode(const int_t error_code, int32_t * const p_errno);
00087 
00088 /******************************************************************************
00089 Exported global functions (to be accessed by other files)
00090 ******************************************************************************/
00091 
00092 #if(1) /* mbed */
00093 /**************************************************************************//**
00094 * Function Name: R_SCUX_MakeCbTbl_mbed
00095 * @brief         Returns the SCUX driver callback function table.
00096 *
00097 *                Description:<br>
00098 *                
00099 * @param         none
00100 * @retval        pointer of sample driver callback table
00101 ******************************************************************************/
00102 /* ->IPA M1.1.1 If this function is the whole system, it will be called. */
00103 RBSP_MBED_FNS* R_SCUX_MakeCbTbl_mbed(void)
00104 /* <-IPA M1.1.1 */
00105 {
00106     static RBSP_MBED_FNS scux_apitbl_mbed;
00107 
00108     scux_apitbl_mbed.initialise_one   = &R_SCUX_InitOne;
00109     scux_apitbl_mbed.uninitialise_one = &R_SCUX_UnInitOne;
00110     scux_apitbl_mbed.open             = &R_SCUX_Open;
00111     scux_apitbl_mbed.close            = &R_SCUX_Close;
00112     scux_apitbl_mbed.ioctl            = &R_SCUX_Ioctl;
00113     scux_apitbl_mbed.write_a          = &R_SCUX_WriteAsync;
00114     scux_apitbl_mbed.read_a           = &R_SCUX_ReadAsync;
00115     scux_apitbl_mbed.cancel           = &R_SCUX_Cancel;
00116 
00117     return &scux_apitbl_mbed;
00118 }
00119 /******************************************************************************
00120 End of function R_SCUX_MakeCbTbl_mbed
00121 ******************************************************************************/
00122 #else
00123 
00124 /**************************************************************************//**
00125 * Function Name: R_SCUX_MakeCbTbl
00126 * @brief         Returns the SCUX driver callback function table.
00127 *
00128 *                Description:<br>
00129 *                
00130 * @param         none
00131 * @retval        pointer of sample driver callback table
00132 ******************************************************************************/
00133 /* ->IPA M1.1.1 If this function is the whole system, it will be called. */
00134 IOIF_DRV_API* R_SCUX_MakeCbTbl(void)
00135 /* <-IPA M1.1.1 */
00136 {
00137     static IOIF_DRV_API gb_ioif_scux_cb_table;
00138     IOIF_DRV_API* const p_api = &gb_ioif_scux_cb_table;
00139 
00140     /* ->MISRA 16.4, IPA M4.5.1 This description is based on the way to fill out OS defined. */
00141     p_api->family = IOIF_SERIAL_FAMILY;
00142     p_api->fns.serial.initialise   = &R_SCUX_Init;
00143     p_api->fns.serial.uninitialise = &R_SCUX_UnInit;
00144     p_api->fns.serial.open         = &R_SCUX_Open;
00145     p_api->fns.serial.close        = &R_SCUX_Close;
00146     p_api->fns.serial.ioctl        = &R_SCUX_Ioctl;
00147     p_api->fns.serial.write_a      = &R_SCUX_WriteAsync;
00148     p_api->fns.serial.read_a       = &R_SCUX_ReadAsync;
00149     p_api->fns.serial.cancel       = &R_SCUX_Cancel;
00150     /* <-MISRA 16.4, IPA M4.5.1 */
00151      
00152     return p_api;
00153 }
00154 
00155 /******************************************************************************
00156 End of function R_SCUX_MakeCbTbl
00157 ******************************************************************************/
00158 #endif /* end mbed */
00159 
00160 /**************************************************************************//**
00161 * Function Name: SCUX_SetErrCode
00162 * @brief         Set error code to error code pointer.
00163 *
00164 *                Description:<br>
00165 *                If error code pointer is NULL, nothing is done.
00166 * @param[in]     error_code :Error code.
00167 * @param[in,out] p_errno    :Pointer of set error code.
00168 * @retval        none
00169 ******************************************************************************/
00170 static void SCUX_SetErrCode(int_t error_code, int32_t * const p_errno)
00171 {
00172     if (NULL != p_errno)
00173     {
00174         *p_errno = error_code;
00175     }
00176     
00177     return;
00178 }
00179 
00180 /******************************************************************************
00181 End of function R_SCUX_SetErrCode
00182 ******************************************************************************/
00183 
00184 /******************************************************************************
00185 Private functions
00186 ******************************************************************************/
00187 
00188 #if(1) /* mbed */
00189 /**************************************************************************//**
00190 * Function Name: R_SCUX_InitOne
00191 * @brief         Init SCUX driver.
00192 *
00193 *                Description:<br>
00194 *                
00195 * @param[in]     channel    :Initialize channel number.
00196 * @param[in]     p_config_data :pointer of several parameters array per channels
00197 * @param[in,out] p_errno    :pointer of error code
00198 *                            error code -
00199 *                            ENOMEM : Making semaphore failed.
00200 *                            EBUSY  : SCUX driver has been initialized already.
00201 *                            EFAULT : p_config_data is NULL.
00202 *                            EFAULT : Internal error is occured.
00203 * @retval        other than (-1)
00204 *                  Operation successful.
00205 *                EERROR -
00206 *                  Error occured.
00207 ******************************************************************************/
00208 static void *R_SCUX_InitOne(const int_t channel, const void * const p_config_data, int32_t * const p_errno) 
00209 {
00210     int_t         ercd;
00211     void          *ret;
00212     scux_info_drv_t * const p_info_drv = SCUX_GetDrvInstance();
00213     scux_info_ch_t  * p_info_ch;
00214 
00215     if (NULL == p_info_drv)
00216     {
00217         ercd = EFAULT;
00218     }
00219     else if ((SCUX_CH_0 > channel) || ( SCUX_CH_NUM <= channel))
00220     {
00221         ercd = EFAULT;
00222     }
00223     else
00224     {
00225         p_info_ch = SCUX_GetDrvChInfo(channel);
00226 
00227         if (NULL == p_info_ch)
00228         {
00229             ercd = EFAULT;
00230         }
00231         else if (false != p_info_ch->enabled)
00232         {
00233             ercd = EBUSY;
00234         }
00235         else
00236         {
00237             if (NULL == p_config_data)
00238             {
00239                 /* set error return value */
00240                 ercd = EFAULT;
00241             }
00242             else
00243             {
00244                 /* init SCUX driver */
00245                 ercd = SCUX_InitializeOne(channel, (const scux_channel_cfg_t *)p_config_data);
00246             }
00247         }
00248     }
00249     
00250     if (ESUCCESS == ercd)
00251     {
00252         ret = (void *)p_info_drv;
00253     }
00254     else
00255     {
00256         ret = (void *)(EERROR);
00257     }
00258 
00259     SCUX_SetErrCode(ercd, p_errno);
00260     
00261     return ret;
00262 }
00263 /******************************************************************************
00264 End of function R_SCUX_InitOne
00265 ******************************************************************************/
00266 
00267 /**************************************************************************//**
00268 * Function Name: R_SCUX_UnInitOne
00269 * @brief         Uninit SCUX driver.
00270 *
00271 *                Description:<br>
00272 *                
00273 * @param[in]     channel    :Uninitialize channel number.
00274 * @param[in]     p_driver_instance :which was returned by R_SCUX_Init
00275 * @param[in,out] p_errno    :pointer of error code
00276 *                            error code -
00277 *                            EBADF : Driver status isn't SCUX_DRV_INIT.
00278 * @retval        ESUCCESS -
00279 *                  Operation successful.
00280 *                EERROR -
00281 *                  Error occured.
00282 ******************************************************************************/
00283 /* ->MISRA 16.7 'p_driver_instance' is based on the way to fill out OS defined. */
00284 /* ->IPA M1.11.1 */
00285 static int_t R_SCUX_UnInitOne(const int_t channel, const void* const p_driver_instance, int32_t * const p_errno)
00286 /* <-IPA M1.11.1 */
00287 /* <-MISRA 16.7 */
00288 {
00289     int_t            retval = ESUCCESS;
00290     int_t            ercd = ESUCCESS;
00291     scux_info_drv_t  * const p_info_drv = SCUX_GetDrvInstance();
00292     scux_info_ch_t   * p_info_ch;
00293 
00294     UNUSED_ARG(p_driver_instance);
00295     
00296     if (NULL == p_info_drv)
00297     {
00298         ercd = EFAULT;
00299     }
00300     else if ((SCUX_CH_0 > channel) || ( SCUX_CH_NUM <= channel))
00301     {
00302         ercd = EFAULT;
00303     }
00304     else
00305     {
00306         if (SCUX_DRV_INIT != p_info_drv->drv_stat)
00307         {
00308             ercd = EBADF;
00309         }
00310         else
00311         {
00312             p_info_ch = SCUX_GetDrvChInfo(channel);
00313 
00314             if (NULL == p_info_ch)
00315             {
00316                 ercd = EFAULT;
00317             }
00318             else if (false == p_info_ch->enabled)
00319             {
00320                 ercd = EBADF;
00321             }
00322             else
00323             {
00324                 SCUX_UnInitializeOne(channel);
00325             }
00326         }
00327     }
00328 
00329     if (ESUCCESS != ercd)
00330     {
00331         retval = EERROR;
00332     }
00333     SCUX_SetErrCode(ercd, p_errno);
00334 
00335     return retval;
00336 }
00337 
00338 /******************************************************************************
00339 End of function R_SCUX_UnInitOne
00340 ******************************************************************************/
00341 #else  /* not mbed */
00342 
00343 /**************************************************************************//**
00344 * Function Name: R_SCUX_Init
00345 * @brief         Init SCUX driver.
00346 *
00347 *                Description:<br>
00348 *                
00349 * @param[in]     p_config_data :pointer of several parameters array per channels
00350 * @param[in,out] p_errno    :pointer of error code
00351 *                            error code -
00352 *                            ENOMEM : Making semaphore failed.
00353 *                            EBUSY  : SCUX driver has been initialized already.
00354 *                            EFAULT : p_config_data is NULL.
00355 *                            EFAULT : Internal error is occured.
00356 * @retval        other than (-1)
00357 *                  Operation successful.
00358 *                EERROR -
00359 *                  Error occured.
00360 ******************************************************************************/
00361 /* ->MISRA 16.7 'p_config_data' is based on the way to fill out OS defined. */
00362 /* ->IPA M1.11.1 */
00363 static void *R_SCUX_Init(void * p_config_data, int32_t * const p_errno) 
00364 /* <-IPA M1.11.1 */
00365 /* <-MISRA 16.7 */
00366 {
00367     int_t         ercd;
00368     void          *ret;
00369     scux_info_drv_t * const p_info_drv = SCUX_GetDrvInstance();
00370 
00371     if (NULL == p_info_drv)
00372     {
00373         ercd = EFAULT;
00374     }
00375     else
00376     {
00377         if (SCUX_DRV_UNINIT != p_info_drv->drv_stat)
00378         {
00379             ercd = EBUSY;
00380         }
00381         else
00382         {
00383             if (NULL == p_config_data)
00384             {
00385                 /* set error return value */
00386                 ercd = EFAULT;
00387             }
00388             else
00389             {
00390                 /* init SCUX driver */
00391                 ercd = SCUX_Initialize((scux_channel_cfg_t *)p_config_data);
00392             }
00393         }
00394     }
00395     
00396     if (ESUCCESS == ercd)
00397     {
00398         ret = (void *)p_info_drv;
00399     }
00400     else
00401     {
00402         ret = (void *)(EERROR);
00403     }
00404 
00405     SCUX_SetErrCode(ercd, p_errno);
00406     
00407     return ret;
00408 }
00409 
00410 /******************************************************************************
00411 End of function R_SCUX_Init
00412 ******************************************************************************/
00413 
00414 /**************************************************************************//**
00415 * Function Name: R_SCUX_UnInit
00416 * @brief         Uninit SCUX driver.
00417 *
00418 *                Description:<br>
00419 *                
00420 * @param[in]     p_driver_instance :which was returned by R_SCUX_Init
00421 * @param[in,out] p_errno    :pointer of error code
00422 *                            error code -
00423 *                            EBADF : Driver status isn't SCUX_DRV_INIT.
00424 * @retval        ESUCCESS -
00425 *                  Operation successful.
00426 *                EERROR -
00427 *                  Error occured.
00428 ******************************************************************************/
00429 /* ->MISRA 16.7 'p_driver_instance' is based on the way to fill out OS defined. */
00430 /* ->IPA M1.11.1 */
00431 static int_t R_SCUX_UnInit(void* p_driver_instance, int32_t * const p_errno)
00432 /* <-IPA M1.11.1 */
00433 /* <-MISRA 16.7 */
00434 {
00435     int_t            retval = ESUCCESS;
00436     int_t            ercd = ESUCCESS;
00437     scux_info_drv_t  * const p_info_drv = SCUX_GetDrvInstance();
00438 
00439     UNUSED_ARG(p_driver_instance);
00440     
00441     if (NULL == p_info_drv)
00442     {
00443         ercd = EFAULT;
00444     }
00445     else
00446     {
00447         if (SCUX_DRV_INIT != p_info_drv->drv_stat)
00448         {
00449             ercd = EBADF;
00450         }
00451         else
00452         {
00453             SCUX_UnInitialize();
00454         }
00455     }
00456 
00457     if (ESUCCESS != ercd)
00458     {
00459         retval = EERROR;
00460     }
00461     SCUX_SetErrCode(ercd, p_errno);
00462     
00463     return retval;
00464 }
00465 #endif /* end mbed */
00466 
00467 /******************************************************************************
00468 End of function R_SCUX_UnInit
00469 ******************************************************************************/
00470 
00471 /**************************************************************************//**
00472 * Function Name: R_SCUX_Open
00473 * @brief         Open SCUX Channel.
00474 *
00475 *                Description:<br>
00476 *                
00477 * @param[in]     p_driver_instance:which was returned by R_SCUX_Init()
00478 * @param[in]     p_path_name   :device Name
00479 * @param[in]     flags         :specifies the access mode whether the channel is 
00480 *                               opened for a read or a write
00481 * @param[in]     mode          :specifies the permissions to use in case a new file
00482 *                               is created (not used for serial family driver)
00483 * @param[in,out] p_errno       :pointer of error code
00484 *                               error code -
00485 *                               ENOMEM : Craeaton of IOIF queue is failed.
00486 *                               ENOENT : Pathname is incorrect length.
00487 *                               ENOENT : Channel information is NULL.
00488 *                               EACCES : Setting to flag is other than O_WONLY or O_RDWR
00489 *                               EMFILE : Allocation of write DMA channel is failed.
00490 *                               ENOTSUP : Channel is not support.
00491 *                               EFAULT : Internal error is occured.
00492 *                               
00493 * @retval        Except ERROR -
00494 *                  Operation successful.
00495 *                EERROR -
00496 *                  Error occured.
00497 ******************************************************************************/
00498 /* ->IPA M1.11.1 This description is based on the way to fill out OS defined. */
00499 static int_t R_SCUX_Open(void * const p_driver_instance, const char_t * p_path_name, const int_t flags, int_t mode , int32_t * const p_errno)
00500 /* <-IPA M1.11.1 */
00501 {
00502     int_t ercd = ESUCCESS;
00503     osStatus sem_ercd;
00504     int32_t  sem_wait_ercd;
00505     void* p_channel_handle;
00506     scux_info_drv_t * const p_info_drv = (scux_info_drv_t *)p_driver_instance;
00507     scux_info_ch_t *p_info_ch = NULL;
00508     uint32_t open_channel;
00509     size_t pathname_len;
00510     size_t compare_len;
00511 
00512     UNUSED_ARG(mode);
00513 
00514     /* check driver instance */
00515     if (NULL == p_driver_instance)
00516     {
00517         ercd = EFAULT;
00518     }
00519     else
00520     {
00521         if (NULL == p_info_drv)
00522         {
00523             ercd = EFAULT;
00524         }
00525         else
00526         {
00527             if (SCUX_DRV_INIT != p_info_drv->drv_stat)
00528             {
00529                 ercd = EFAULT;
00530             }
00531         }
00532     }
00533     
00534     /* check path name */
00535     if (ESUCCESS == ercd)
00536     {
00537         if (NULL == p_info_drv)
00538         {
00539             ercd = EFAULT;
00540         }
00541         else
00542         {
00543             if (NULL == p_path_name)
00544             {
00545                 ercd = EFAULT;
00546             }
00547             else
00548             {
00549                 /* check length of path name */
00550                 pathname_len = SCUX_StrNLen(p_path_name, MAX_PATH_SEARCH_LEN);
00551                 if ( (0U == pathname_len) || (MAX_PATH_SEARCH_LEN == pathname_len) )
00552                 {
00553                     ercd = ENOENT;
00554                 }
00555                 else
00556                 {
00557                     for (open_channel = 0; ((open_channel < SCUX_CH_NUM) && (NULL == p_info_ch)); open_channel++)
00558                     {
00559                         /* Avoid reading beyond the end of the shortest of the two strings */
00560                         compare_len = SCUX_StrNLen(p_gb_device_name[open_channel], MAX_PATH_SEARCH_LEN);
00561                         if (pathname_len < compare_len)
00562                         {
00563                             compare_len = pathname_len;
00564                         }
00565         
00566                         if (0 == strncmp(p_path_name, p_gb_device_name[open_channel], compare_len))
00567                         {
00568                             if (NULL != p_info_drv->info_ch)
00569                             {
00570                                 p_info_ch = &p_info_drv->info_ch[open_channel]; /* found a match */
00571                             }
00572                         }           
00573                     }
00574                     
00575                     if (NULL == p_info_ch)
00576                     {
00577                         ercd = ENOENT; /* Pathname not recognised */
00578                     }
00579                 }
00580             }
00581         }
00582     }
00583     
00584     if (NULL != p_info_ch)
00585     {
00586         if (ESUCCESS == ercd)
00587         {
00588             if ((O_WRONLY != flags) && (O_RDWR != flags))
00589             {
00590                 ercd = EACCES;
00591             }
00592             
00593             /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
00594             /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/ 
00595             sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
00596             /* <-MISRA 10.6 */
00597             /* <-MISRA 1.2 */
00598             /* semaphore error check */
00599             if ((-1) == sem_wait_ercd)
00600             {
00601                 /* set error return value */
00602                 ercd = EFAULT;
00603             }
00604             else
00605             {
00606                 if (false == p_info_ch->enabled)
00607                 {
00608                     ercd = ENOTSUP;
00609                 }
00610                 
00611                 if (ESUCCESS == ercd)
00612                 {
00613                     if (SCUX_CH_INIT != p_info_ch->ch_stat)
00614                     {
00615                         ercd = EBUSY;
00616                     }
00617                 }
00618     
00619                 if (ESUCCESS == ercd)
00620                 {
00621                     ercd = SCUX_OpenChannel(p_info_ch->channel, flags);
00622                 }
00623             }
00624             sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
00625             /* semaphore error check */
00626             if (osOK != sem_ercd)
00627             {
00628                 /* set error return value */
00629                 ercd = EFAULT;
00630             }
00631         }
00632     }
00633 
00634     if (ESUCCESS == ercd)
00635     {
00636         p_channel_handle = (void*)p_info_ch;
00637     }
00638     else
00639     {
00640         p_channel_handle = (void*)EERROR;
00641     }
00642     SCUX_SetErrCode(ercd, p_errno);
00643     
00644     return (int_t)p_channel_handle;
00645 }
00646 
00647 /******************************************************************************
00648 End of function R_SCUX_Open
00649 ******************************************************************************/
00650 
00651 /**************************************************************************//**
00652 * Function Name: R_SCUX_Close
00653 * @brief         Close SCUX Channel.
00654 *
00655 *                Description:<br>
00656 *                
00657 * @param[in]     p_fd:which was returned by R_SCUX_Init()
00658 * @param[in,out] p_errno:pointer of error code
00659 *                        error code -
00660 *                           EFAULT : Internal error is occured.
00661 *                               
00662 * @retval        ESUCCESS -
00663 *                  Operation successful.
00664 *                EERROR -
00665 *                  Error occured.
00666 ******************************************************************************/
00667 static int_t R_SCUX_Close(void * const p_fd, int32_t * const p_errno)
00668 {
00669     int_t retval = ESUCCESS;
00670     int_t ercd = ESUCCESS;
00671     int32_t sem_wait_ercd;
00672     osStatus sem_ercd;
00673     scux_info_ch_t * const p_info_ch = p_fd;
00674     scux_info_drv_t * const p_info_drv = SCUX_GetDrvInstance();
00675     
00676     if ((NULL == p_info_ch) || (NULL == p_info_drv))
00677     {
00678         ercd = EFAULT;
00679     }
00680     else
00681     {
00682         if (SCUX_DRV_INIT != p_info_drv->drv_stat)
00683         {
00684             ercd = EFAULT;
00685         }
00686         
00687         if (ESUCCESS == ercd)
00688         {
00689             /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
00690             /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/ 
00691             sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
00692             /* <-MISRA 10.6 */
00693             /* <-MISRA 1.2 */
00694             /* semaphore error check */
00695             if ((-1) == sem_wait_ercd)
00696             {
00697                 /* set error return value */
00698                 ercd = EFAULT;
00699             }
00700             
00701             if (ESUCCESS == ercd)
00702             {
00703                 if (false == p_info_ch->enabled)
00704                 {
00705                     ercd = EFAULT;
00706                 }
00707                 
00708                 if (ESUCCESS == ercd)
00709                 {
00710                     if ((SCUX_CH_UNINIT == p_info_ch->ch_stat) ||
00711                         (SCUX_CH_INIT == p_info_ch->ch_stat))
00712                     {
00713                         ercd = EFAULT;
00714                     }
00715                 }
00716                 
00717                 if (ESUCCESS == ercd)
00718                 {
00719                     /* close channel */
00720                     ercd = SCUX_CloseChannel(p_info_ch->channel);               
00721                 }
00722             }
00723             sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
00724             /* semaphore error check */
00725             if (osOK != sem_ercd)
00726             {
00727                 /* set error return value */
00728                     ercd = EFAULT;
00729             }
00730             
00731         }
00732     }
00733 
00734     if (ESUCCESS != ercd)
00735     {
00736         retval = EERROR;
00737     }
00738     SCUX_SetErrCode(ercd, p_errno);
00739     
00740     return retval;
00741 }
00742 
00743 /******************************************************************************
00744 End of function R_SCUX_Close
00745 ******************************************************************************/
00746 
00747 /**************************************************************************//**
00748 * Function Name: R_SCUX_Ioctl
00749 * @brief         SCUX driver IOCTL function.
00750 *
00751 *                Description:<br>
00752 *                
00753 * @param[in]     p_fd: pointer of SCUX handler
00754 * @param[in]     request:IOCTL request code
00755 * @param[in]     p_buf  :Data buffer for IOCTL request code.
00756 * @param[in,out] p_errno:pointer of error code
00757 *                        error code -
00758 *                           EINVAL : IOCTL request code is unexpected value.
00759 *                           EFAULT : Internal error is occured.
00760 *                           other value : The value depending on IOCTL request code.
00761 *                                         Refer to the function of scux_ioctl.c for those meanings. 
00762 *                               
00763 * @retval        ESUCCESS -
00764 *                  Operation successful.
00765 *                EERROR -
00766 *                  Error occured.
00767 ******************************************************************************/
00768 static int_t R_SCUX_Ioctl(void * const p_fd, const int_t request, void * const p_buf, int32_t * const p_errno)
00769 {
00770     int_t retval = ESUCCESS;
00771     int_t ercd = ESUCCESS;
00772     int32_t sem_wait_ercd;
00773     int_t  was_masked;
00774     osStatus sem_ercd;
00775     scux_info_ch_t * const p_info_ch = p_fd;
00776     scux_info_drv_t * const p_info_drv = SCUX_GetDrvInstance();
00777     
00778     if ((NULL == p_info_ch) || (NULL == p_info_drv))
00779     {
00780         ercd = EFAULT;
00781     }
00782     else
00783     {
00784         if (SCUX_DRV_INIT != p_info_drv->drv_stat)
00785         {
00786             ercd = EFAULT;
00787         }
00788     
00789         if (ESUCCESS == ercd)
00790         {
00791             /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
00792             /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/ 
00793             if (0 == R_ExceptionalMode())
00794             {
00795                 sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
00796                 /* <-MISRA 10.6 */
00797                 /* <-MISRA 1.2 */
00798                 /* semaphore error check */
00799                 if ((-1) == sem_wait_ercd)
00800                 {
00801                     /* set error return value */
00802                     ercd = EFAULT;
00803                 }
00804             }
00805             
00806             if (ESUCCESS == ercd)
00807             {
00808                 if (false == p_info_ch->enabled)
00809                 {
00810                     ercd = EFAULT;
00811                 }
00812                 
00813                 if (ESUCCESS == ercd)
00814                 {
00815                     if ((SCUX_CH_UNINIT == p_info_ch->ch_stat) ||
00816                         (SCUX_CH_INIT == p_info_ch->ch_stat))
00817                     {
00818                         ercd = EFAULT;
00819                     }
00820                 }
00821                 
00822             }
00823             
00824             if (0 == R_ExceptionalMode())
00825             {
00826                 sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
00827                 /* semaphore error check */
00828                 if (osOK != sem_ercd)
00829                 {
00830                     /* set error return value */
00831                     ercd = EFAULT;
00832                 }
00833             }
00834             
00835             if (ESUCCESS == ercd)
00836             {
00837                 switch (request)
00838                 {
00839                     case SCUX_IOCTL_SET_START:
00840                     
00841                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
00842                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/ 
00843                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
00844                         /* <-MISRA 10.6 */
00845                         /* <-MISRA 1.2 */
00846                         /* semaphore error check */
00847                         if ((-1) == sem_wait_ercd)
00848                         {
00849                             /* set error return value */
00850                             ercd = EFAULT;
00851                         }
00852                         else
00853                         {
00854                             if (SCUX_CH_STOP != p_info_ch->ch_stat)
00855                             {
00856                                 ercd = EBUSY;
00857                             }
00858                             else
00859                             {
00860                                 ercd = SCUX_IoctlTransStart(p_info_ch->channel);
00861                             }
00862                         }
00863                         
00864                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
00865                         /* semaphore error check */
00866                         if (osOK != sem_ercd)
00867                         {
00868                             /* set error return value */
00869                             ercd = EFAULT;
00870                         }
00871                         
00872                     break;
00873             
00874                     case SCUX_IOCTL_SET_FLUSH_STOP:
00875                     
00876                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
00877                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/ 
00878                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
00879                         /* <-MISRA 10.6 */
00880                         /* <-MISRA 1.2 */
00881                         /* semaphore error check */
00882                         if ((-1) == sem_wait_ercd)
00883                         {
00884                             /* set error return value */
00885                             ercd = EFAULT;
00886                         }
00887                         else
00888                         {
00889                             /* check p_Buf */
00890                             if (NULL == p_buf)
00891                             {
00892                                 ercd = EFAULT;
00893                             }
00894                             else
00895                             {                    
00896 #if defined (__ICCARM__)
00897                                 was_masked = __disable_irq_iar();
00898 #else
00899                                 was_masked = __disable_irq();
00900 #endif    
00901                                 if (SCUX_CH_STOP == p_info_ch->ch_stat)
00902                                 {
00903                                     ercd = EBUSY;
00904                                 }
00905                                 
00906                                 /* The mesure to MISRA 1.1 , SEC P1.1.1 */
00907                                 if ((ESUCCESS != ercd) && (0 == was_masked))
00908                                 {
00909                                     /* enable all irq when ch_stat is SCUX_CH_STOP */
00910                                     __enable_irq();                                 
00911                                 }
00912                                 
00913                                 if (ESUCCESS == ercd)
00914                                 {
00915                                     /* ->MISRA 11.1 Since it is necessary to register a callback function, 
00916                                     the cast from a void pointer is performed intentionally. */
00917                                     ercd = SCUX_IoctlFlushStop(p_info_ch->channel, (void ( *)(int_t))p_buf, was_masked);
00918                                     /* <-MISRA 11.1 */
00919                                 }
00920                                 
00921                             }
00922                         }
00923                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
00924                         /* semaphore error check */
00925                         if (osOK != sem_ercd)
00926                         {
00927                             /* set error return value */
00928                             ercd = EFAULT;
00929                         }
00930                                                 
00931                     break;
00932             
00933                     case SCUX_IOCTL_SET_CLEAR_STOP:
00934     
00935                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
00936                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/                   
00937                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
00938                         /* <-MISRA 10.6 */
00939                         /* <-MISRA 1.2 */
00940                         /* semaphore error check */
00941 
00942                         if ((-1) == sem_wait_ercd)
00943                         {
00944                             /* set error return value */
00945                             ercd = EFAULT;
00946                         }
00947                         else
00948                         {
00949 #if defined (__ICCARM__)
00950                             was_masked = __disable_irq_iar();
00951 #else
00952                             was_masked = __disable_irq();
00953 #endif    
00954                             if (SCUX_CH_STOP == p_info_ch->ch_stat)
00955                             {
00956                                 ercd = EBUSY;
00957                                         
00958                                 if (0 == was_masked)
00959                                 {
00960                                     /* enable all irq */
00961                                     __enable_irq();
00962                                 }                                
00963                             }
00964                             else
00965                             {
00966                                 /* This exclusive access control ends in the SCUX_IoctlClearStop */
00967                                 ercd = SCUX_IoctlClearStop(p_info_ch->channel, was_masked);
00968                             }
00969                         }
00970                         
00971                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
00972                         /* semaphore error check */
00973                         if (osOK != sem_ercd)
00974                         {
00975                             /* set error return value */
00976                             ercd = EFAULT;
00977                         }
00978                             
00979                     break;
00980                         
00981                     case SCUX_IOCTL_SET_ROUTE:
00982     
00983                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
00984                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/                     
00985                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
00986                         /* <-MISRA 10.6 */
00987                         /* <-MISRA 1.2 */
00988                         /* semaphore error check */
00989                         if ((-1) == sem_wait_ercd)
00990                         {
00991                             /* set error return value */
00992                             ercd = EFAULT;
00993                         }
00994                         else
00995                         {
00996                             if (SCUX_CH_STOP != p_info_ch->ch_stat)
00997                             {
00998                                 ercd = EBUSY;
00999                             }
01000                             else
01001                             {
01002                                 if (NULL == p_buf)
01003                                 {
01004                                     ercd = EFAULT;
01005                                 }
01006                                 else
01007                                 {
01008                                     SCUX_IoctlSetRoute(p_info_ch->channel, *(scux_route_t *)p_buf);
01009                                 }
01010                             }
01011                         }
01012                         
01013                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01014                         /* semaphore error check */
01015                         if (osOK != sem_ercd)
01016                         {
01017                             /* set error return value */
01018                             ercd = EFAULT;
01019                         }
01020                             
01021                     break;
01022                         
01023                     case SCUX_IOCTL_SET_PIN_CLK:
01024     
01025                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
01026                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/                     
01027                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
01028                         /* <-MISRA 10.6 */
01029                         /* <-MISRA 1.2 */
01030                         /* semaphore error check */
01031                         if ((-1) == sem_wait_ercd)
01032                         {
01033                             /* set error return value */
01034                             ercd = EFAULT;
01035                         }
01036                         else
01037                         {
01038                             if (SCUX_CH_STOP != p_info_ch->ch_stat)
01039                             {
01040                                 ercd = EBUSY;
01041                             }
01042                             else
01043                             {
01044                                 if (NULL == p_buf)
01045                                 {
01046                                     ercd = EFAULT;
01047                                 }
01048                                 else
01049                                 {
01050                                     ercd = SCUX_IoctlSetPinClk(p_info_ch->channel, (scux_ssif_pin_clk_t *)p_buf);
01051                                 }
01052                             }
01053                         }
01054                         
01055                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01056                         /* semaphore error check */
01057                         if (osOK != sem_ercd)
01058                         {
01059                             /* set error return value */
01060                             ercd = EFAULT;
01061                         }
01062                         
01063                     break;
01064     
01065                     case SCUX_IOCTL_SET_PIN_MODE:
01066     
01067                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
01068                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/                     
01069                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
01070                         /* <-MISRA 10.6 */
01071                         /* <-MISRA 1.2 */
01072                         /* semaphore error check */
01073                         if ((-1) == sem_wait_ercd)
01074                         {
01075                             /* set error return value */
01076                             ercd = EFAULT;
01077                         }
01078                         else
01079                         {
01080                             if (SCUX_CH_STOP != p_info_ch->ch_stat)
01081                             {
01082                                 ercd = EBUSY;
01083                             }
01084                             else
01085                             {
01086                                 if (NULL == p_buf)
01087                                 {
01088                                     ercd = EFAULT;
01089                                 }
01090                                 else
01091                                 {
01092                                     ercd = SCUX_IoctlSetPinMode(p_info_ch->channel, (scux_ssif_pin_mode_t *)p_buf);
01093                                 }
01094                             }
01095                         }
01096                         
01097                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01098                         /* semaphore error check */
01099                         if (osOK != sem_ercd)
01100                         {
01101                             /* set error return value */
01102                             ercd = EFAULT;
01103                         }                    
01104                             
01105                     break;
01106                     
01107                     case SCUX_IOCTL_SET_SRC_CFG:
01108     
01109                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
01110                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/                     
01111                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
01112                         /* <-MISRA 10.6 */
01113                         /* <-MISRA 1.2 */
01114                         /* semaphore error check */
01115                         if ((-1) == sem_wait_ercd)
01116                         {
01117                             /* set error return value */
01118                             ercd = EFAULT;
01119                         }
01120                         else
01121                         {
01122                             if (SCUX_CH_STOP != p_info_ch->ch_stat)
01123                             {
01124                                 ercd = EBUSY;
01125                             }
01126                             else
01127                             {
01128                                 if (NULL == p_buf)
01129                                 {
01130                                     ercd = EFAULT;
01131                                 }
01132                                 else
01133                                 {
01134                                     SCUX_IoctlSetSrcCfg(p_info_ch->channel, (scux_src_cfg_t *)p_buf);
01135                                 }
01136                             }
01137                         }
01138                         
01139                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01140                         /* semaphore error check */
01141                         if (osOK != sem_ercd)
01142                         {
01143                             /* set error return value */
01144                             ercd = EFAULT;
01145                         }
01146                             
01147                     break;
01148                             
01149                     case SCUX_IOCTL_SET_DVU_CFG:
01150     
01151                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
01152                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/                     
01153                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
01154                         /* <-MISRA 10.6 */
01155                         /* <-MISRA 1.2 */
01156                         /* semaphore error check */
01157                         if ((-1) == sem_wait_ercd)
01158                         {
01159                             /* set error return value */
01160                             ercd = EFAULT;
01161                         }
01162                         else
01163                         {
01164                             if (SCUX_CH_STOP != p_info_ch->ch_stat)
01165                             {
01166                                 ercd = EBUSY;
01167                             }
01168                             else
01169                             {
01170                                 if (NULL == p_buf)
01171                                 {
01172                                     ercd = EFAULT;
01173                                 }
01174                                 else
01175                                 {
01176                                     SCUX_IoctlSetDvuCfg(p_info_ch->channel, (scux_dvu_cfg_t *)p_buf);
01177                                 }
01178                             }   
01179                         }
01180                         
01181                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01182                         /* semaphore error check */
01183                         if (osOK != sem_ercd)
01184                         {
01185                             /* set error return value */
01186                             ercd = EFAULT;
01187                         }                    
01188                         
01189                     break;
01190                        
01191                     case SCUX_IOCTL_SET_DVU_DIGI_VOL:
01192                         
01193                         if (NULL == p_buf)
01194                         {
01195                             ercd = EFAULT;
01196                         }
01197                         else
01198                         {
01199                             ercd = SCUX_IoctlSetDvuDigiVol(p_info_ch->channel, (scux_dvu_digi_vol_t *)p_buf);
01200                         }
01201                             
01202                     break;
01203                         
01204                     case SCUX_IOCTL_SET_DVU_RAMP_VOL:
01205                         
01206                         if (NULL == p_buf)
01207                         {
01208                             ercd = EFAULT;
01209                         }
01210                         else
01211                         {
01212                             ercd = SCUX_IoctlSetDvuRampVol(p_info_ch->channel, (scux_dvu_ramp_vol_t *)p_buf);
01213                         }
01214                             
01215                     break;
01216                         
01217                     case SCUX_IOCTL_SET_ZEROCROSS_MUTE:
01218                         
01219                         if (NULL == p_buf)
01220                         {
01221                             ercd = EFAULT;
01222                         }
01223                         else
01224                         {
01225                             ercd = SCUX_IoctlSetDvuZerocrossMute(p_info_ch->channel, (scux_zc_mute_t *)p_buf);
01226                         }
01227                             
01228                     break;
01229                         
01230                     case SCUX_IOCTL_SET_STOP_MUTE:
01231                         
01232                         if (NULL == p_buf)
01233                         {
01234                             ercd = EFAULT;
01235                         }
01236                         else
01237                         {
01238                             ercd = SCUX_IoctlSetStopMute(p_info_ch->channel, *(uint32_t *)p_buf);
01239                         }
01240                             
01241                     break;
01242                         
01243                     case SCUX_IOCTL_SET_MIX_CFG:
01244                         
01245                         if (NULL == p_buf)
01246                         {
01247                             ercd = EFAULT;
01248                         }
01249                         else
01250                         {
01251                             ercd = SCUX_IoctlSetMixCfg((scux_mix_cfg_t *)p_buf);
01252                         }
01253                             
01254                     break;
01255                         
01256                     case SCUX_IOCTL_SET_MIX_VOL:
01257                         
01258                         if (NULL == p_buf)
01259                         {
01260                             ercd = EFAULT;
01261                         }
01262                         else
01263                         {
01264                             ercd = SCUX_IoctlSetMixVol(p_info_ch->channel, *(uint32_t *)p_buf);
01265                         }
01266                     
01267                     break;
01268                         
01269                     case SCUX_IOCTL_SET_SSIF_CFG:
01270     
01271                         /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
01272                         /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/                     
01273                         sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
01274                         /* <-MISRA 10.6 */
01275                         /* <-MISRA 1.2 */
01276                         /* semaphore error check */
01277                         if ((-1) == sem_wait_ercd)
01278                         {
01279                             /* set error return value */
01280                             ercd = EFAULT;
01281                         }
01282                         else
01283                         {
01284                             if (SCUX_CH_STOP != p_info_ch->ch_stat)
01285                             {
01286                                 ercd = EBUSY;
01287                             }
01288                             else
01289                             {
01290                                 if (NULL == p_buf)
01291                                 {
01292                                     ercd = EFAULT;
01293                                 }
01294                                 else
01295                                 {
01296                                     ercd = SCUX_IoctlSetSsifCfg((scux_ssif_cfg_t *)p_buf);
01297                                 }
01298                             }
01299                         }
01300                         
01301                         sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01302                         /* semaphore error check */
01303                         if (osOK != sem_ercd)
01304                         {
01305                             /* set error return value */
01306                             ercd = EFAULT;
01307                         }                    
01308                             
01309                     break;
01310                         
01311                     case SCUX_IOCTL_GET_WRITE_STAT:
01312                     
01313                         if (NULL == p_buf)
01314                         {
01315                             ercd = EFAULT;
01316                         }
01317                         else
01318                         {
01319                             SCUX_IoctlGetWriteStat(p_info_ch->channel, (uint32_t *)p_buf);
01320                         }
01321                             
01322                     break;
01323                     
01324                     case SCUX_IOCTL_GET_READ_STAT:
01325                     
01326                         if (NULL == p_buf)
01327                         {
01328                             ercd = EFAULT;
01329                         }
01330                         else
01331                         {
01332                             SCUX_IoctlGetReadStat(p_info_ch->channel, (uint32_t *)p_buf);
01333                         }
01334                             
01335                     break;
01336                         
01337                     case SCUX_IOCTL_GET_DVU_STAT:
01338                     
01339                         if (NULL == p_buf)
01340                         {
01341                             ercd = EFAULT;
01342                         }
01343                         else
01344                         {
01345                             SCUX_IoctlGetDvuStat(p_info_ch->channel, (uint32_t *)p_buf);
01346                         }
01347                             
01348                     break;
01349                     
01350                     case SCUX_IOCTL_GET_MUTE_STAT:
01351                     
01352                         if (NULL == p_buf)
01353                         {
01354                             ercd = EFAULT;
01355                         }
01356                         else
01357                         {
01358                             SCUX_IoctlGetMuteStat(p_info_ch->channel, (uint32_t *)p_buf);
01359                         }
01360                             
01361                     break;
01362                         
01363                     case SCUX_IOCTL_GET_MIX_STAT:
01364                         
01365                         if (NULL == p_buf)
01366                         {
01367                             ercd = EFAULT;
01368                         }
01369                         else
01370                         {
01371                             SCUX_IoctlGetMixStat(p_info_ch->channel, (uint32_t *)p_buf);
01372                         }
01373                             
01374                     break;
01375                                             
01376                     default:
01377                         ercd = EINVAL;
01378                     break;
01379                 }
01380             }
01381         }
01382     }
01383     
01384     if (ESUCCESS != ercd)
01385     {
01386         retval = EERROR;
01387     }
01388     SCUX_SetErrCode(ercd, p_errno);
01389     
01390     return retval;
01391     
01392 }
01393 
01394 /******************************************************************************
01395 End of function R_SCUX_Ioctl
01396 ******************************************************************************/
01397 
01398 /**************************************************************************//**
01399 * Function Name: R_SCUX_WriteAsync
01400 * @brief         SCUX driver asynchronous write.
01401 *
01402 *                Description:<br>
01403 *                
01404 * @param[in]     p_fd   :channel handle which was returned by R_SCUX_Open
01405 * @param[in]     p_aio  :aio control block.
01406 * @param[in,out] p_errno:pointer of error code
01407 *                               error code -
01408 *                               EBADF : Channel status isn't SCUX_CH_STOP or SCUX_CH_STOP_WAIT. 
01409 *                               EINVAL : p_fd is NULL.
01410 *                               EINVAL : write size is 0.
01411 *                               EFAULT : Internal error is occured.
01412 *                               
01413 * @retval        ESUCCESS -
01414 *                  Operation successful.
01415 *                EERROR -
01416 *                  Error occured.
01417 ******************************************************************************/
01418 static int_t R_SCUX_WriteAsync(void * const p_fd, AIOCB * const p_aio, int32_t * const p_errno)
01419 {
01420     int_t retval = ESUCCESS;
01421     int_t ercd = ESUCCESS;
01422     int_t sem_ercd;
01423     int32_t  sem_wait_ercd;
01424     int_t was_masked;
01425     scux_info_ch_t * const p_info_ch = p_fd;
01426     scux_info_drv_t * const p_info_drv = SCUX_GetDrvInstance();
01427     
01428     if ((NULL == p_info_ch) || (NULL == p_aio) || (NULL == p_info_drv))
01429     {
01430         ercd = EFAULT;
01431     }
01432     else
01433     {
01434         if (0U == p_aio->aio_nbytes)
01435         {
01436             ercd = EINVAL;
01437         }
01438         
01439         if (ESUCCESS == ercd)
01440         {
01441             if (SCUX_DRV_INIT != p_info_drv->drv_stat)
01442             {
01443                 ercd = EFAULT;
01444             }
01445         }
01446         
01447         if (ESUCCESS == ercd)
01448         {
01449             /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
01450             /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/ 
01451             sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
01452             /* <-MISRA 10.6 */
01453             /* <-MISRA 1.2 */
01454             /* semaphore error check */
01455             if ((-1) == sem_wait_ercd)
01456             {
01457                 /* set error return value */
01458                 ercd = EFAULT;
01459             }
01460             else
01461             {
01462                 if (false == p_info_ch->enabled)
01463                 {
01464                     ercd = EFAULT;
01465                 }
01466             }
01467             
01468             if (ESUCCESS == ercd)
01469             {
01470 #if defined (__ICCARM__)
01471                 was_masked = __disable_irq_iar();
01472 #else
01473                 was_masked = __disable_irq();
01474 #endif
01475 
01476                 if (ESUCCESS != p_info_ch->err_stat_backup)
01477                 {
01478                     /* set error code */
01479                     ercd = p_info_ch->err_stat_backup;
01480                 }
01481                 else
01482                 {
01483                     switch (p_info_ch->ch_stat)
01484                     {
01485                         case SCUX_CH_UNINIT :
01486                             /* fall through */
01487                         case SCUX_CH_INIT :
01488                             ercd = EFAULT;
01489                         break;              
01490                         
01491                         case SCUX_CH_STOP :
01492                             ercd = EBADF;
01493                         break;                  
01494                         
01495                         case SCUX_CH_TRANS_IDLE :
01496                             /* fall through */
01497                         case SCUX_CH_TRANS_RD :
01498                             if (SCUX_ROUTE_MEM_TO_MEM != (p_info_ch->route_set & SCUX_GET_ROUTE_MASK))
01499                             {
01500                                 ercd = SCUX_DirectWriteStart(p_info_ch, p_aio);
01501                             }
01502                             else
01503                             {
01504                                 ercd = SCUX_CopyWriteStart(p_info_ch, p_aio);
01505                             }
01506                         break;
01507                         
01508                         case SCUX_CH_TRANS_WR :
01509                             /* fall through */
01510                         case SCUX_CH_TRANS_RDWR :
01511                             ahf_addtail(&p_info_ch->tx_que, p_aio);
01512                         break;
01513                         
01514                         case SCUX_CH_STOP_WAIT :
01515                             /* fall through */
01516                         case SCUX_CH_STOP_WAIT_IDLE :
01517                             ercd = EBADF;
01518                         break;
01519                         
01520                         default :
01521                             ercd = EFAULT;
01522                         break;
01523                     }
01524                 }
01525                 
01526                 if (0 == was_masked)
01527                 {
01528                     __enable_irq();
01529                 } 
01530             }
01531             sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01532             /* semaphore error check */
01533             if (osOK != sem_ercd)
01534             {
01535                 /* set error return value */
01536                 ercd = EFAULT;
01537             }
01538         }
01539     }
01540     
01541     if (ESUCCESS != ercd)
01542     {
01543         retval = EERROR;
01544     }
01545     SCUX_SetErrCode(ercd, p_errno);
01546     
01547     return retval;
01548     
01549 }
01550 
01551 /******************************************************************************
01552 End of function R_SCUX_WriteAsync
01553 ******************************************************************************/
01554 /**************************************************************************//**
01555 * Function Name: R_SCUX_ReadAsync
01556 * @brief         SCUX driver asynchronous read.
01557 *
01558 *                Description:<br>
01559 *                
01560 * @param[in]     p_fd   :channel handle which was returned by R_SCUX_open
01561 * @param[in]     p_aio  :aio control block.
01562 * @param[in,out] p_errno:pointer of error code
01563 *                               error code -
01564 *                               EBADF : Channel status isn't SCUX_CH_STOP or SCUX_CH_STOP_WAIT. 
01565 *                               EINVAL : read size is 0.
01566 *                               EACCES : Request for write only mode channel.
01567 *                               EACCES : Route setting is unexpected.
01568 *                               EFAULT : Internal error is occured.
01569 *                               
01570 * @retval        ESUCCESS -
01571 *                  Operation successful.
01572 *                EERROR -
01573 *                  Error occured.
01574 ******************************************************************************/
01575 static int_t R_SCUX_ReadAsync(void * const p_fd, AIOCB * const p_aio, int32_t * const p_errno)
01576 {
01577     int_t retval = ESUCCESS;
01578     int_t ercd = ESUCCESS;
01579     osStatus sem_ercd;
01580     int32_t sem_wait_ercd;
01581     int_t was_masked;
01582     scux_info_ch_t * const p_info_ch = p_fd;
01583     scux_info_drv_t * const p_info_drv = SCUX_GetDrvInstance();
01584     
01585     if ((NULL == p_info_ch) || (NULL == p_info_drv) || (NULL == p_aio))
01586     {
01587         ercd = EFAULT;
01588     }
01589     else
01590     {
01591         if (0U == p_aio->aio_nbytes)
01592         {
01593             ercd = EINVAL;
01594         }
01595         
01596         if (ESUCCESS == ercd)
01597         {
01598             if (SCUX_DRV_INIT != p_info_drv->drv_stat)
01599             {
01600                 ercd = EFAULT;
01601             }
01602         }
01603         
01604         if (ESUCCESS == ercd)
01605         {
01606             /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
01607             /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/ 
01608             sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
01609             /* <-MISRA 10.6 */
01610             /* <-MISRA 1.2 */
01611             /* semaphore error check */
01612             if ((-1) == sem_wait_ercd)
01613             {
01614                 /* set error return value */
01615                 ercd = EFAULT;
01616             }
01617             else
01618             {
01619                 if (false == p_info_ch->enabled)
01620                 {
01621                     ercd = EFAULT;
01622                 }
01623             }
01624             
01625             if (ESUCCESS == ercd)
01626             {
01627                 if (O_WRONLY == (p_info_ch->open_flags & O_ACCMODE))
01628                 {
01629                     ercd = EACCES;
01630                 }
01631             }
01632             
01633             if (ESUCCESS == ercd)
01634             {
01635                 
01636                 if (SCUX_ROUTE_MEM_TO_MEM != (p_info_ch->route_set & SCUX_GET_ROUTE_MASK))
01637                 {
01638                     ercd = EACCES;
01639                 }
01640                 
01641                 if (ESUCCESS == ercd)
01642                 {
01643 #if defined (__ICCARM__)
01644                     was_masked = __disable_irq_iar();
01645 #else
01646                     was_masked = __disable_irq();
01647 #endif
01648 
01649                     if (ESUCCESS != p_info_ch->err_stat_backup)
01650                     {
01651                         /* set error code */
01652                         ercd = p_info_ch->err_stat_backup;
01653                     }
01654                     else
01655                     {
01656                         switch (p_info_ch->ch_stat)
01657                         {
01658                             case SCUX_CH_UNINIT :
01659                                 /* fall through */
01660                             case SCUX_CH_INIT :
01661                                 ercd = EFAULT;
01662                             break;              
01663                             
01664                             case SCUX_CH_STOP :
01665                                 ercd = EBADF;
01666                             break;                          
01667                             
01668                             case SCUX_CH_TRANS_IDLE :
01669                                 ercd = SCUX_CopyReadStart(p_info_ch, p_aio);
01670                             break;
01671                             
01672                             case SCUX_CH_TRANS_RD :
01673                                 ahf_addtail(&p_info_ch->rx_que, p_aio);
01674                             break;
01675                             
01676                             case SCUX_CH_TRANS_WR :
01677                                 ercd = SCUX_CopyReadStart(p_info_ch, p_aio);
01678                             break;
01679                             
01680                             case SCUX_CH_TRANS_RDWR :
01681                                 /* fall through */
01682                             case SCUX_CH_STOP_WAIT :
01683                                 ahf_addtail(&p_info_ch->rx_que, p_aio);
01684                             break;
01685                             
01686                             case SCUX_CH_STOP_WAIT_IDLE :
01687                                 ercd = SCUX_CopyReadStart(p_info_ch, p_aio);
01688                             break;                        
01689                             
01690                             default :
01691                                 ercd = EFAULT;
01692                             break;
01693                         }
01694                     }                 
01695                     
01696                     if (0 == was_masked)
01697                     {
01698                         __enable_irq();
01699                     }
01700                 }
01701             }
01702             sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01703             /* semaphore error check */
01704             if (osOK != sem_ercd)
01705             {
01706                 /* set error return value */
01707                 ercd = EFAULT;
01708             }
01709         }
01710     }
01711     
01712     if (ESUCCESS != ercd)
01713     {
01714         retval = EERROR;
01715     }
01716     SCUX_SetErrCode(ercd, p_errno);
01717     
01718     return retval;
01719     
01720 }
01721 
01722 /******************************************************************************
01723 End of function R_SCUX_ReadAsync
01724 ******************************************************************************/
01725 
01726 /**************************************************************************//**
01727 * Function Name: R_SCUX_Cancel
01728 * @brief         Request cancel.
01729 *
01730 *                Description:<br>
01731 *                
01732 * @param[in]     p_fd   :channel handle which was returned by R_SCUX_open
01733 * @param[in]     p_aio  :aio control block.
01734 * @param[in,out] p_errno:pointer of error code
01735 *                               error code -
01736 *                               EFAULT : Internal error is occured.
01737 *                               
01738 * @retval        ESUCCESS -
01739 *                  Operation successful.
01740 *                EERROR -
01741 *                  Error occured.
01742 ******************************************************************************/
01743 static int_t R_SCUX_Cancel(void * const p_fd, AIOCB * const p_aio, int32_t * const p_errno)
01744 {
01745     int_t retval = ESUCCESS;
01746     int_t ercd = ESUCCESS;
01747     osStatus sem_ercd;
01748     int32_t sem_wait_ercd;
01749     scux_info_ch_t * const p_info_ch = p_fd;
01750     scux_info_drv_t * const p_info_drv = SCUX_GetDrvInstance();
01751     
01752     if ((NULL == p_info_ch) || (NULL == p_info_drv))
01753     {
01754         ercd = EFAULT;
01755     }
01756     else
01757     {
01758         if (SCUX_DRV_INIT != p_info_drv->drv_stat)
01759         {
01760             ercd = EFAULT;
01761         }
01762     
01763         if (ESUCCESS == ercd)
01764         {
01765             /* ->MISRA 1.2 It is confirming in advance whether to be NULL or not. */
01766             /* ->MISRA 10.6, osWaitForever is defined by the header got from related section*/ 
01767             sem_wait_ercd = osSemaphoreWait(p_info_ch->sem_ch_scux_access, osWaitForever);
01768             /* <-MISRA 10.6 */
01769             /* <-MISRA 1.2 */
01770             /* semaphore error check */
01771             if ((-1) == sem_wait_ercd)
01772             {
01773                 /* set error return value */
01774                 ercd = EFAULT;
01775             }
01776             
01777             if (ESUCCESS == ercd)
01778             {
01779                 if (false == p_info_ch->enabled)
01780                 {
01781                     ercd = EFAULT;
01782                 }
01783                 
01784                 if (ESUCCESS == ercd)
01785                 {
01786                     if ((SCUX_CH_INIT == p_info_ch->ch_stat) ||
01787                         (SCUX_CH_UNINIT == p_info_ch->ch_stat))
01788                     {
01789                         /* It should not becomde status */
01790                         ercd = EFAULT;
01791                     }
01792                     else if ((SCUX_CH_STOP_WAIT == p_info_ch->ch_stat) ||
01793                               (SCUX_CH_STOP_WAIT_IDLE == p_info_ch->ch_stat) ||
01794                               (SCUX_CH_STOP == p_info_ch->ch_stat))
01795                     {
01796                         /* busy error on flush waiting */
01797                         ercd = EBADF;
01798                     }
01799                     else
01800                     {
01801                         if (NULL == p_aio)
01802                         {
01803                             if (SCUX_ROUTE_MEM_TO_MEM != (p_info_ch->route_set & SCUX_GET_ROUTE_MASK))
01804                             {
01805                                 ercd = SCUX_DirectCancelAll(p_info_ch);
01806                             }
01807                             else
01808                             {
01809                                 ercd = SCUX_CopyCancelAll(p_info_ch);   
01810                             }
01811                         }
01812                         else
01813                         {
01814                             if (SCUX_ROUTE_MEM_TO_MEM != (p_info_ch->route_set & SCUX_GET_ROUTE_MASK))
01815                             {
01816                                 ercd = SCUX_DirectCancelSpecific(p_info_ch, p_aio);
01817                             }
01818                             else
01819                             {
01820                                 ercd = SCUX_CopyCancelSpecific(p_info_ch, p_aio);
01821                             }
01822                         }
01823                     }
01824                 }
01825             }
01826             sem_ercd = osSemaphoreRelease(p_info_ch->sem_ch_scux_access);
01827             /* semaphore error check */
01828             if (osOK != sem_ercd)
01829             {
01830                 /* set error return value */
01831                 ercd = EFAULT;
01832             }
01833         }
01834     }
01835     
01836     if (ESUCCESS != ercd)
01837     {
01838         retval = EERROR;
01839     }
01840     SCUX_SetErrCode(ercd, p_errno);
01841     
01842     return retval;
01843 }
01844 
01845 /******************************************************************************
01846 End of function R_SCUX_Cancel
01847 ******************************************************************************/
01848