RZ/A1H CMSIS-RTOS RTX BSP for GR-PEACH.
Dependents: GR-PEACH_Azure_Speech ImageZoomInout_Sample ImageRotaion_Sample ImageScroll_Sample ... more
Fork of R_BSP by
ssif_if.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) 2013-2014 Renesas Electronics Corporation. All rights reserved. 00022 *******************************************************************************/ 00023 00024 /******************************************************************************* 00025 * File Name : ssif_if.c 00026 * $Rev: 891 $ 00027 * $Date:: 2014-06-27 10:40:52 +0900#$ 00028 * Description : SSIF driver interface functions 00029 ******************************************************************************/ 00030 00031 /******************************************************************************* 00032 Includes <System Includes>, "Project Includes" 00033 *******************************************************************************/ 00034 #include "cmsis_os.h" 00035 #if(1) /* mbed */ 00036 #include "r_bsp_cmn.h" 00037 #else 00038 #include "ioif_public.h" 00039 #endif 00040 #include "ssif.h" 00041 00042 /******************************************************************************* 00043 Typedef definitions 00044 *******************************************************************************/ 00045 00046 00047 /******************************************************************************* 00048 Macro definitions 00049 *******************************************************************************/ 00050 00051 00052 /******************************************************************************* 00053 Exported global variables (to be accessed by other files) 00054 *******************************************************************************/ 00055 00056 00057 /******************************************************************************* 00058 Private global variables and functions 00059 *******************************************************************************/ 00060 00061 #if(1) /* mbed */ 00062 static ssif_drv_stat_t ch_drv_stat[SSIF_NUM_CHANS] = {SSIF_DRVSTS_UNINIT}; 00063 00064 static void* R_SSIF_InitOne(const int_t channel, const void* const config_data, int32_t* const p_errno); 00065 static int_t R_SSIF_UnInitOne(const int_t channel, const void* const driver_instance, int32_t* const p_errno); 00066 #else /* not mbed */ 00067 static void* R_SSIF_Init(void* const config_data, int32_t* const p_errno); 00068 static int_t R_SSIF_UnInit(void* const driver_instance, int32_t* const p_errno); 00069 #endif /* end mbed */ 00070 static int_t R_SSIF_Open(void* const p_driver_instance, const char_t* const p_path_name, const int_t flags, const int_t mode, int32_t* const p_errno); 00071 static int_t R_SSIF_Close(void* const p_fd, int32_t* const p_errno); 00072 static int_t R_SSIF_Ioctl(void* const p_fd, const int_t request, void* const p_buf, int32_t* const p_errno); 00073 static int_t R_SSIF_WriteAsync(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno); 00074 static int_t R_SSIF_ReadAsync(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno); 00075 static int_t R_SSIF_Cancel(void* const p_fd, AIOCB* p_aio, int32_t* const p_errno); 00076 00077 static size_t SSIF_StrnLen(const char_t p_str[], const size_t maxlen); 00078 static int32_t SSIF_Strncmp(const char_t p_str1[], const char_t p_str2[], const uint32_t maxlen); 00079 static void SSIF_SetErrCode(const int_t error_code, int32_t* const p_errno); 00080 00081 /****************************************************************************** 00082 Exported global functions (to be accessed by other files) 00083 ******************************************************************************/ 00084 00085 #if(1) /* mbed */ 00086 /****************************************************************************** 00087 * Function Name: R_SSIF_MakeCbTbl_mbed 00088 * @brief Make the SSIF driver function callback table 00089 * 00090 * Description:<br> 00091 * 00092 * @param none 00093 * @retval pointer of SSIF driver function callback table 00094 ******************************************************************************/ 00095 /* ->IPA M1.1.1 : This is liblary funciotn that is called from other module. */ 00096 RBSP_MBED_FNS* R_SSIF_MakeCbTbl_mbed(void) 00097 /* <-IPA M1.1.1 */ 00098 { 00099 static RBSP_MBED_FNS ssif_apitbl_mbed; 00100 00101 ssif_apitbl_mbed.initialise_one = &R_SSIF_InitOne; 00102 ssif_apitbl_mbed.uninitialise_one = &R_SSIF_UnInitOne; 00103 ssif_apitbl_mbed.open = &R_SSIF_Open; 00104 ssif_apitbl_mbed.close = &R_SSIF_Close; 00105 ssif_apitbl_mbed.ioctl = &R_SSIF_Ioctl; 00106 ssif_apitbl_mbed.read_a = &R_SSIF_ReadAsync; 00107 ssif_apitbl_mbed.write_a = &R_SSIF_WriteAsync; 00108 ssif_apitbl_mbed.cancel = &R_SSIF_Cancel; 00109 00110 return &ssif_apitbl_mbed; 00111 } 00112 #else /* not mbed */ 00113 /****************************************************************************** 00114 * Function Name: R_SSIF_MakeCbTbl 00115 * @brief Make the SSIF driver function callback table 00116 * 00117 * Description:<br> 00118 * 00119 * @param none 00120 * @retval pointer of SSIF driver function callback table 00121 ******************************************************************************/ 00122 /* ->IPA M1.1.1 : This is liblary funciotn that is called from other module. */ 00123 IOIF_DRV_API* R_SSIF_MakeCbTbl(void) 00124 /* <-IPA M1.1.1 */ 00125 { 00126 static IOIF_DRV_API ssif_apitbl; 00127 00128 /* ->MISRA 16.4, IPA M4.5.1 : This is IOIF library API type definitnon that can't be modified. */ 00129 ssif_apitbl.family = IOIF_SERIAL_FAMILY; 00130 ssif_apitbl.fns.serial.initialise = &R_SSIF_Init; 00131 ssif_apitbl.fns.serial.uninitialise = &R_SSIF_UnInit; 00132 ssif_apitbl.fns.serial.open = &R_SSIF_Open; 00133 ssif_apitbl.fns.serial.close = &R_SSIF_Close; 00134 ssif_apitbl.fns.serial.ioctl = &R_SSIF_Ioctl; 00135 ssif_apitbl.fns.serial.read_a = &R_SSIF_ReadAsync; 00136 ssif_apitbl.fns.serial.write_a = &R_SSIF_WriteAsync; 00137 ssif_apitbl.fns.serial.cancel = &R_SSIF_Cancel; 00138 /* <-MISRA 16.4, IPA M4.5.1 */ 00139 00140 return &ssif_apitbl; 00141 } 00142 #endif /* end mbed */ 00143 00144 /****************************************************************************** 00145 * Function Name: R_SSIF_SWLtoLen 00146 * @brief Convert SSICR:SWL bits to system word length 00147 * 00148 * Description:<br> 00149 * 00150 * @param[in] ssicr_swl :SSICR register SWL field value(0 to 7) 00151 * @retval 8 to 256 :system word length(byte) 00152 ******************************************************************************/ 00153 int_t R_SSIF_SWLtoLen(const ssif_chcfg_system_word_t ssicr_swl) 00154 { 00155 return SSIF_SWLtoLen(ssicr_swl); 00156 } 00157 00158 /****************************************************************************** 00159 Private functions 00160 ******************************************************************************/ 00161 00162 #if(1) /* mbed */ 00163 /****************************************************************************** 00164 * Function Name: R_SSIF_InitOne 00165 * @brief Initialise the SSIF driver. 00166 * 00167 * Description:<br> 00168 * 00169 * @param[in] channel :channel number 00170 * @param[in] config_data :pointer of several parameters array per channels 00171 * @param[in,out] p_errno :pointer of error code 00172 * @retval not ERRROR :driver instance. 00173 * @retval EERROR :Failure. 00174 ******************************************************************************/ 00175 /* ->MISRA 16.7, IPA M1.11.1 : This is IOIF library API type definitnon that can't be modified. */ 00176 static void* R_SSIF_InitOne(const int_t channel, const void* const config_data, int32_t* const p_errno) 00177 /* <-MISRA 16.7, IPA M1.11.1 */ 00178 { 00179 int_t ercd; 00180 void* p_ret = (void*)EERROR; 00181 00182 if (NULL == config_data) 00183 { 00184 ercd = EFAULT; 00185 } 00186 else if (channel >= SSIF_NUM_CHANS) 00187 { 00188 ercd = EFAULT; 00189 } 00190 else 00191 { 00192 g_ssif_info_drv.drv_stat = SSIF_DRVSTS_INIT; 00193 ch_drv_stat[channel] = SSIF_DRVSTS_INIT; 00194 00195 ercd = SSIF_InitialiseOne(channel, (const ssif_channel_cfg_t*)config_data); 00196 00197 if (ESUCCESS == ercd) 00198 { 00199 p_ret = (void*)&g_ssif_info_drv; 00200 } 00201 else 00202 { 00203 ch_drv_stat[channel] = SSIF_DRVSTS_UNINIT; 00204 } 00205 } 00206 00207 SSIF_SetErrCode(ercd, p_errno); 00208 00209 return p_ret; 00210 } 00211 00212 /****************************************************************************** 00213 * Function Name: R_SSIF_UnInitOne 00214 * @brief Uninitialise the SSIF deiver. 00215 * 00216 * Description:<br> 00217 * 00218 * @param[in] channel :channel number 00219 * @param[in,out] driver_instance :driver instance which was returned by<br> 00220 R_SSIF_Init 00221 * @param[in,out] p_errno :pointer of error code 00222 * @retval ESUCCESS :Success. 00223 * @retval EERROR :Failure. 00224 ******************************************************************************/ 00225 static int_t R_SSIF_UnInitOne(const int_t channel, const void* const driver_instance, int32_t* const p_errno) 00226 { 00227 int_t ercd; 00228 int_t ret = ESUCCESS; 00229 00230 if (NULL == driver_instance) 00231 { 00232 ercd = EFAULT; 00233 } 00234 else if (channel >= SSIF_NUM_CHANS) 00235 { 00236 ercd = EFAULT; 00237 } 00238 else 00239 { 00240 if (SSIF_DRVSTS_INIT != ch_drv_stat[channel]) 00241 { 00242 ercd = EFAULT; 00243 } 00244 else 00245 { 00246 ercd = SSIF_UnInitialiseOne(channel); 00247 ch_drv_stat[channel] = SSIF_DRVSTS_UNINIT; 00248 } 00249 } 00250 00251 if (ESUCCESS != ercd) 00252 { 00253 ret = EERROR; 00254 } 00255 SSIF_SetErrCode(ercd, p_errno); 00256 00257 return ret; 00258 } 00259 00260 #else /* not mbed */ 00261 00262 /****************************************************************************** 00263 * Function Name: R_SSIF_Init 00264 * @brief Initialise the SSIF driver. 00265 * 00266 * Description:<br> 00267 * 00268 * @param[in] config_data :pointer of several parameters array per channels 00269 * @param[in,out] p_errno :pointer of error code 00270 * @retval not ERRROR :driver instance. 00271 * @retval EERROR :Failure. 00272 ******************************************************************************/ 00273 /* ->MISRA 16.7, IPA M1.11.1 : This is IOIF library API type definitnon that can't be modified. */ 00274 static void* R_SSIF_Init(void* const config_data, int32_t* const p_errno) 00275 /* <-MISRA 16.7, IPA M1.11.1 */ 00276 { 00277 int_t ercd; 00278 void* p_ret = (void*)EERROR; 00279 00280 if (NULL == config_data) 00281 { 00282 ercd = EFAULT; 00283 } 00284 else if (SSIF_DRVSTS_UNINIT != g_ssif_info_drv.drv_stat) 00285 { 00286 ercd = EBUSY; 00287 } 00288 else 00289 { 00290 g_ssif_info_drv.drv_stat = SSIF_DRVSTS_INIT; 00291 00292 ercd = SSIF_Initialise((ssif_channel_cfg_t*)config_data); 00293 00294 if (ESUCCESS == ercd) 00295 { 00296 p_ret = (void*)&g_ssif_info_drv; 00297 } 00298 else 00299 { 00300 g_ssif_info_drv.drv_stat = SSIF_DRVSTS_UNINIT; 00301 } 00302 } 00303 00304 SSIF_SetErrCode(ercd, p_errno); 00305 00306 return p_ret; 00307 } 00308 00309 /****************************************************************************** 00310 * Function Name: R_SSIF_UnInit 00311 * @brief Uninitialise the SSIF deiver. 00312 * 00313 * Description:<br> 00314 * 00315 * @param[in,out] driver_instance :driver instance which was returned by<br> 00316 R_SSIF_Init 00317 * @param[in,out] p_errno :pointer of error code 00318 * @retval ESUCCESS :Success. 00319 * @retval EERROR :Failure. 00320 ******************************************************************************/ 00321 static int_t R_SSIF_UnInit(void* const driver_instance, int32_t* const p_errno) 00322 { 00323 int_t ercd; 00324 int_t ret = ESUCCESS; 00325 ssif_info_drv_t* const p_info_drv = driver_instance; 00326 00327 if (NULL == p_info_drv) 00328 { 00329 ercd = EFAULT; 00330 } 00331 else 00332 { 00333 if (SSIF_DRVSTS_INIT != p_info_drv->drv_stat) 00334 { 00335 ercd = EFAULT; 00336 } 00337 else 00338 { 00339 ercd = SSIF_UnInitialise(); 00340 p_info_drv->drv_stat = SSIF_DRVSTS_UNINIT; 00341 } 00342 } 00343 00344 if (ESUCCESS != ercd) 00345 { 00346 ret = EERROR; 00347 } 00348 SSIF_SetErrCode(ercd, p_errno); 00349 00350 return ret; 00351 } 00352 #endif /* end mbed */ 00353 00354 /****************************************************************************** 00355 * Function Name: R_SSIF_Open 00356 * @brief Open an SSIF channel 00357 * 00358 * Description:<br> 00359 * 00360 * @param[in,out] p_drv_instance :driver instance which was returned by<br> 00361 R_SSIF_Init 00362 * @param[in] p_path_name :string of channel 00363 * @param[in] flags :access mode whether the channel is opened<br> 00364 for a read or a write 00365 * @param[in] mode :not used 00366 * @param[in,out] p_errno :pointer of error code 00367 * @retval not EERROR :channel handle 00368 * @retval EERROR :Failure. 00369 ******************************************************************************/ 00370 static int_t R_SSIF_Open(void* const p_driver_instance, const char_t* const p_path_name, const int_t flags, const int_t mode, int32_t* const p_errno) 00371 { 00372 uint32_t ssif_ch; 00373 void* p_channelHandle; 00374 size_t len; 00375 size_t req_path_len; 00376 ssif_info_drv_t* const p_info_drv = p_driver_instance; 00377 ssif_info_ch_t* p_info_ch = NULL; 00378 int_t ret; 00379 int_t ercd = ESUCCESS; 00380 osStatus os_ercd; 00381 int32_t os_ret; 00382 static const char_t* const ch_name_string[SSIF_NUM_CHANS] = 00383 { 00384 SSIF_CHSTR_0, 00385 SSIF_CHSTR_1, 00386 SSIF_CHSTR_2, 00387 SSIF_CHSTR_3, 00388 SSIF_CHSTR_4, 00389 SSIF_CHSTR_5 00390 }; 00391 00392 UNUSED_ARG(mode); 00393 00394 if ((NULL == p_info_drv) || (NULL == p_path_name)) 00395 { 00396 ercd = EFAULT; 00397 } 00398 else 00399 { 00400 req_path_len = strlen(p_path_name); 00401 if (0u == req_path_len) 00402 { 00403 ercd = ENOENT; 00404 } 00405 00406 if (ESUCCESS == ercd) 00407 { 00408 if (SSIF_DRVSTS_INIT != p_info_drv->drv_stat) 00409 { 00410 ercd = EFAULT; 00411 } 00412 } 00413 00414 if (ESUCCESS == ercd) 00415 { 00416 /* Serch the same pathname */ 00417 for (ssif_ch = 0u; (ssif_ch < SSIF_NUM_CHANS) && (p_info_ch == NULL); ssif_ch++) 00418 { 00419 len = SSIF_StrnLen(ch_name_string[ssif_ch], SSIF_MAX_PATH_LEN); 00420 00421 if (req_path_len < len) 00422 { 00423 len = req_path_len; 00424 } 00425 00426 if (0 == SSIF_Strncmp(p_path_name, ch_name_string[ssif_ch], len)) 00427 { 00428 /* found a match */ 00429 p_info_ch = &p_info_drv->info_ch[ssif_ch]; 00430 } 00431 } 00432 } 00433 } 00434 00435 if (NULL == p_info_ch) 00436 { 00437 ercd = ENOENT; 00438 } 00439 else 00440 { 00441 if (ESUCCESS == ercd) 00442 { 00443 if (false == p_info_ch->enabled) 00444 { 00445 ercd = ENOTSUP; 00446 } 00447 } 00448 00449 if (ESUCCESS == ercd) 00450 { 00451 if (SSIF_CHSTS_INIT != p_info_ch->ch_stat) 00452 { 00453 ercd = EBADF; 00454 } 00455 } 00456 00457 if (ESUCCESS == ercd) 00458 { 00459 /* ->MISRA 10.6 : This macro is defined by CMSIS-RTOS that can't be modified. */ 00460 os_ret = osSemaphoreWait(p_info_ch->sem_access, osWaitForever); 00461 /* <-MISRA 10.6 */ 00462 00463 if ((-1) == os_ret) 00464 { 00465 ercd = EFAULT; 00466 } 00467 else 00468 { 00469 p_info_ch->openflag = flags; 00470 p_info_ch->p_aio_tx_curr = NULL; 00471 p_info_ch->p_aio_rx_curr = NULL; 00472 00473 ercd = SSIF_EnableChannel(p_info_ch); 00474 00475 if (ESUCCESS == ercd) 00476 { 00477 p_info_ch->ch_stat = SSIF_CHSTS_OPEN; 00478 } 00479 } 00480 os_ercd = osSemaphoreRelease(p_info_ch->sem_access); 00481 if (osOK != os_ercd) 00482 { 00483 ercd = EFAULT; 00484 } 00485 } 00486 } 00487 00488 if (ESUCCESS != ercd) 00489 { 00490 ret = EERROR; /* EERROR(-1) */ 00491 } 00492 else 00493 { 00494 p_channelHandle = (void*)p_info_ch; 00495 ret = (int_t)p_channelHandle; 00496 } 00497 SSIF_SetErrCode(ercd, p_errno); 00498 00499 return ret; 00500 } 00501 00502 /****************************************************************************** 00503 * Function Name: R_SSIF_Close 00504 * @brief Close an SSIF channel. 00505 * 00506 * Description:<br> 00507 * 00508 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open 00509 * @param[in,out] p_errno :pointer of error code 00510 * @retval ESUCCESS :Success. 00511 * @retval EERROR :Failure. 00512 ******************************************************************************/ 00513 static int_t R_SSIF_Close(void* const p_fd, int32_t* const p_errno) 00514 { 00515 ssif_info_ch_t* const p_info_ch = p_fd; 00516 int_t ret = ESUCCESS; 00517 int_t ercd; 00518 osStatus os_ercd; 00519 int32_t os_ret; 00520 00521 if (NULL == p_info_ch) 00522 { 00523 ercd = EFAULT; 00524 } 00525 else 00526 { 00527 /* ->MISRA 10.6 : This macro is defined by CMSIS-RTOS that can't be modified. */ 00528 /* Get semaphore to access the channel data */ 00529 os_ret = osSemaphoreWait(p_info_ch->sem_access, osWaitForever); 00530 /* <-MISRA 10.6 */ 00531 00532 if ((-1) == os_ret) 00533 { 00534 ercd = EFAULT; 00535 } 00536 else 00537 { 00538 if (SSIF_CHSTS_OPEN != p_info_ch->ch_stat) 00539 { 00540 ercd = EFAULT; 00541 } 00542 else 00543 { 00544 SSIF_PostAsyncCancel(p_info_ch, NULL); 00545 00546 ercd = SSIF_DisableChannel(p_info_ch); 00547 00548 if (ESUCCESS == ercd) 00549 { 00550 p_info_ch->ch_stat = SSIF_CHSTS_INIT; 00551 } 00552 } 00553 00554 /* Relese semaphore */ 00555 os_ercd = osSemaphoreRelease(p_info_ch->sem_access); 00556 00557 if (osOK != os_ercd) 00558 { 00559 ercd = EFAULT; 00560 } 00561 } 00562 } 00563 00564 if (ESUCCESS != ercd) 00565 { 00566 ret = EERROR; /* EERROR(-1) */ 00567 } 00568 SSIF_SetErrCode(ercd, p_errno); 00569 00570 return ret; 00571 } 00572 00573 /****************************************************************************** 00574 * Function Name: R_SSIF_Ioctl 00575 * @brief IOCTL function of the SSIF deiver 00576 * 00577 * Description:<br> 00578 * 00579 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open 00580 * @param[in] request :IOCTL request code 00581 * @param[in,out] p_buf :Meaning depends upon request. 00582 * @param[in,out] p_errno :pointer of error code 00583 * @retval ESUCCESS :Success. 00584 * @retval EERROR :Failure. 00585 ******************************************************************************/ 00586 static int_t R_SSIF_Ioctl(void* const p_fd, const int_t request, void* const p_buf, int32_t* const p_errno) 00587 { 00588 ssif_info_ch_t* const p_info_ch = p_fd; 00589 int_t ret = ESUCCESS; 00590 int_t ercd = ESUCCESS; 00591 osStatus os_ercd; 00592 int32_t os_ret; 00593 00594 if (NULL == p_info_ch) 00595 { 00596 ercd = EFAULT; 00597 } 00598 else 00599 { 00600 if (SSIF_CHSTS_OPEN != p_info_ch->ch_stat) 00601 { 00602 ercd = EFAULT; 00603 } 00604 else 00605 { 00606 /* ->MISRA 10.6 : This macro is defined by CMSIS-RTOS that can't be modified. */ 00607 os_ret = osSemaphoreWait(p_info_ch->sem_access, osWaitForever); 00608 /* <-MISRA 10.6 */ 00609 00610 if ((-1) == os_ret) 00611 { 00612 ercd = EFAULT; 00613 } 00614 00615 if (ESUCCESS == ercd) 00616 { 00617 switch (request) 00618 { 00619 case SSIF_CONFIG_CHANNEL: 00620 { 00621 if (NULL == p_buf) 00622 { 00623 ercd = EFAULT; 00624 } 00625 else 00626 { 00627 ssif_channel_cfg_t* const ch_info = (ssif_channel_cfg_t*)p_buf; 00628 ercd = SSIF_IOCTL_ConfigChannel(p_info_ch, ch_info); 00629 } 00630 break; 00631 } 00632 00633 case SSIF_GET_STATUS: 00634 { 00635 if (NULL == p_buf) 00636 { 00637 ercd = EFAULT; 00638 } 00639 else 00640 { 00641 ercd = SSIF_IOCTL_GetStatus(p_info_ch, (uint32_t*)p_buf); 00642 } 00643 break; 00644 } 00645 00646 default: 00647 { 00648 ercd = EINVAL; 00649 break; 00650 } 00651 } /* switch */ 00652 } 00653 } 00654 00655 os_ercd = osSemaphoreRelease(p_info_ch->sem_access); 00656 if (osOK != os_ercd) 00657 { 00658 ercd = EFAULT; 00659 } 00660 } 00661 00662 if (ESUCCESS != ercd) 00663 { 00664 ret = EERROR; /* EERROR(-1) */ 00665 } 00666 SSIF_SetErrCode(ercd, p_errno); 00667 00668 return ret; 00669 } 00670 00671 /****************************************************************************** 00672 * Function Name: R_SSIF_WriteAsync 00673 * @brief Enqueue asynchronous write request 00674 * 00675 * Description:<br> 00676 * 00677 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open 00678 * @param[in] p_aio :aio control block of write request 00679 * @param[in,out] p_errno :pointer of error code 00680 * @retval ESUCCESS :Success. 00681 * @retval EERROR :Failure. 00682 ******************************************************************************/ 00683 static int_t R_SSIF_WriteAsync(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno) 00684 { 00685 ssif_info_ch_t* const p_info_ch = p_fd; 00686 int_t ret = ESUCCESS; 00687 int_t ercd = ESUCCESS; 00688 00689 if ((NULL == p_info_ch) || (NULL == p_aio)) 00690 { 00691 ercd = EFAULT; 00692 } 00693 else 00694 { 00695 if (((uint32_t)O_RDONLY) == ((uint32_t)p_info_ch->openflag & O_ACCMODE)) 00696 { 00697 ercd = EACCES; 00698 } 00699 else if (0u == p_aio->aio_nbytes) 00700 { 00701 ercd = EINVAL; 00702 } 00703 else 00704 { 00705 p_aio->aio_return = SSIF_ASYNC_W; 00706 SSIF_PostAsyncIo(p_info_ch, p_aio); 00707 } 00708 } 00709 00710 if (ESUCCESS != ercd) 00711 { 00712 ret = EERROR; /* EERROR(-1) */ 00713 } 00714 SSIF_SetErrCode(ercd, p_errno); 00715 00716 return ret; 00717 } 00718 00719 /****************************************************************************** 00720 * Function Name: R_SSIF_ReadAsync 00721 * @brief Enqueue asynchronous read request 00722 * 00723 * Description:<br> 00724 * 00725 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open 00726 * @param[in] p_aio :aio control block of read request 00727 * @param[in,out] p_errno :pointer of error code 00728 * @retval ESUCCESS :Success. 00729 * @retval EERROR :Failure. 00730 ******************************************************************************/ 00731 static int_t R_SSIF_ReadAsync(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno) 00732 { 00733 ssif_info_ch_t* const p_info_ch = p_fd; 00734 int_t ret = ESUCCESS; 00735 int_t ercd = ESUCCESS; 00736 00737 if ((NULL == p_info_ch) || (NULL == p_aio)) 00738 { 00739 ercd = EFAULT; 00740 } 00741 else 00742 { 00743 if ((O_WRONLY == ((uint32_t)p_info_ch->openflag & O_ACCMODE)) 00744 || (SSIF_CFG_ENABLE_ROMDEC_DIRECT 00745 == p_info_ch->romdec_direct.mode)) 00746 { 00747 ercd = EACCES; 00748 } 00749 else if (0u == p_aio->aio_nbytes) 00750 { 00751 ercd = EINVAL; 00752 } 00753 else 00754 { 00755 p_aio->aio_return = SSIF_ASYNC_R; 00756 SSIF_PostAsyncIo(p_info_ch, p_aio); 00757 } 00758 } 00759 00760 if (ESUCCESS != ercd) 00761 { 00762 ret = EERROR; /* EERROR(-1) */ 00763 } 00764 SSIF_SetErrCode(ercd, p_errno); 00765 00766 return ret; 00767 } 00768 00769 /****************************************************************************** 00770 * Function Name: R_SSIF_Cancel 00771 * @brief Cancel read or write request(s) 00772 * 00773 * Description:<br> 00774 * 00775 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open 00776 * @param[in] p_aio :aio control block to cancel or NULL to cancel all. 00777 * @param[in,out] p_errno :pointer of error code 00778 * @retval ESUCCESS :Success. 00779 * @retval EERROR :Failure. 00780 ******************************************************************************/ 00781 static int_t R_SSIF_Cancel(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno) 00782 { 00783 ssif_info_ch_t* const p_info_ch = p_fd; 00784 int_t ret = ESUCCESS; 00785 int_t ercd = ESUCCESS; 00786 osStatus os_ercd; 00787 int32_t os_ret; 00788 00789 if (NULL == p_info_ch) 00790 { 00791 ercd = EFAULT; 00792 } 00793 else 00794 { 00795 /* ->MISRA 10.6 : This macro is defined by CMSIS-RTOS that can't be modified. */ 00796 /* Get semaphore to access the channel data */ 00797 os_ret = osSemaphoreWait(p_info_ch->sem_access, osWaitForever); 00798 /* <-MISRA 10.6 */ 00799 00800 if ((-1) == os_ret) 00801 { 00802 ercd = EFAULT; 00803 } 00804 else 00805 { 00806 if (SSIF_CHSTS_OPEN != p_info_ch->ch_stat) 00807 { 00808 ercd = EFAULT; 00809 } 00810 else 00811 { 00812 SSIF_PostAsyncCancel(p_info_ch, p_aio); 00813 } 00814 00815 os_ercd = osSemaphoreRelease(p_info_ch->sem_access); 00816 00817 if (osOK != os_ercd) 00818 { 00819 ercd = EFAULT; 00820 } 00821 } 00822 } 00823 00824 if (ESUCCESS != ercd) 00825 { 00826 ret = EERROR; /* EERROR(-1) */ 00827 } 00828 SSIF_SetErrCode(ercd, p_errno); 00829 00830 return ret; 00831 } 00832 00833 /****************************************************************************** 00834 * Function Name: SSIF_StrnLen 00835 * @brief computes the length of the string 00836 * 00837 * Description:<br> 00838 * 00839 * @param[in] p_str :pointer of string. 00840 * @param[in] maxlen :maximum length of inspection 00841 * @retval < maxlen :number of characters in the string 00842 * @retval maxlen :string is longer than maxlen 00843 ******************************************************************************/ 00844 static size_t SSIF_StrnLen(const char_t p_str[], const size_t maxlen) 00845 { 00846 size_t len; 00847 00848 if (NULL == p_str) 00849 { 00850 len = 0; 00851 } 00852 else 00853 { 00854 for (len = 0; len < maxlen; len++) 00855 { 00856 if ((int_t)p_str[len] == '\0') 00857 { 00858 break; 00859 } 00860 } 00861 } 00862 00863 return len; 00864 } 00865 00866 /****************************************************************************** 00867 * Function Name: SSIF_Strncmp 00868 * @brief Compare two strings 00869 * 00870 * Description:<br> 00871 * 00872 * @param[in] p_str1 :pointer of string1 00873 * @param[in] p_str2 :pointer of string2 00874 * @param[in] maxlen :maximum length of comparison 00875 * @retval zero :strings are same. 00876 * @retval non zero :strings are different. 00877 ******************************************************************************/ 00878 static int32_t SSIF_Strncmp(const char_t p_str1[], const char_t p_str2[], const uint32_t maxlen) 00879 { 00880 int32_t result = 0; 00881 uint32_t index; 00882 00883 if ((NULL == p_str1) || (NULL == p_str2)) 00884 { 00885 result = -1; 00886 } 00887 else 00888 { 00889 for (index = 0; index < maxlen; index++) 00890 { 00891 /* compare charctor */ 00892 result = ((int_t)p_str1[index]) - ((int_t)p_str2[index]); 00893 if ((result != 0) 00894 || ((int_t)p_str1[index] == '\0') 00895 || ((int_t)p_str2[index] == '\0')) 00896 { 00897 /* "charactor mismatch" or "end of string" */ 00898 break; 00899 } 00900 } 00901 } 00902 00903 return result; 00904 } 00905 00906 /****************************************************************************** 00907 * Function Name: SSIF_SetErrCode 00908 * @brief Set error code to error code pointer. 00909 * 00910 * Description:<br> 00911 * If error code pointer is NULL, do nothing. 00912 * @param[in] error_code :Error code. 00913 * @param[in,out] p_errno :Pointer of set error code. 00914 * @retval none 00915 ******************************************************************************/ 00916 static void SSIF_SetErrCode(const int_t error_code, int32_t* const p_errno) 00917 { 00918 if (NULL != p_errno) 00919 { 00920 *p_errno = error_code; 00921 } 00922 00923 return; 00924 } 00925
Generated on Tue Jul 12 2022 20:43:58 by 1.7.2