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 Daiki Kato

SSIF

The SSIF driver implements transmission and reception functionality which uses the SSIF in the RZ/A Series.

Hello World!

Import program

00001 #include "mbed.h"
00002 #include "R_BSP_Ssif.h"
00003 #include "sine_data_tbl.h"
00004 
00005 //I2S send only, The upper limit of write buffer is 8.
00006 R_BSP_Ssif ssif(P4_4, P4_5, P4_7, P4_6, 0x80, 8, 0);
00007 
00008 static void callback_ssif_write_end(void * p_data, int32_t result, void * p_app_data) {
00009     if (result < 0) {
00010         printf("ssif write callback error %d\n", result);
00011     }
00012 }
00013 
00014 int main() {
00015     rbsp_data_conf_t   ssif_write_end_conf = {&callback_ssif_write_end, NULL};
00016     ssif_channel_cfg_t ssif_cfg;
00017     int32_t            result;
00018 
00019     //I2S Master, 44.1kHz, 16bit, 2ch
00020     ssif_cfg.enabled                = true;
00021     ssif_cfg.int_level              = 0x78;
00022     ssif_cfg.slave_mode             = false;
00023     ssif_cfg.sample_freq            = 44100u;
00024     ssif_cfg.clk_select             = SSIF_CFG_CKS_AUDIO_X1;
00025     ssif_cfg.multi_ch               = SSIF_CFG_MULTI_CH_1;
00026     ssif_cfg.data_word              = SSIF_CFG_DATA_WORD_16;
00027     ssif_cfg.system_word            = SSIF_CFG_SYSTEM_WORD_32;
00028     ssif_cfg.bclk_pol               = SSIF_CFG_FALLING;
00029     ssif_cfg.ws_pol                 = SSIF_CFG_WS_LOW;
00030     ssif_cfg.padding_pol            = SSIF_CFG_PADDING_LOW;
00031     ssif_cfg.serial_alignment       = SSIF_CFG_DATA_FIRST;
00032     ssif_cfg.parallel_alignment     = SSIF_CFG_LEFT;
00033     ssif_cfg.ws_delay               = SSIF_CFG_DELAY;
00034     ssif_cfg.noise_cancel           = SSIF_CFG_DISABLE_NOISE_CANCEL;
00035     ssif_cfg.tdm_mode               = SSIF_CFG_DISABLE_TDM;
00036     ssif_cfg.romdec_direct.mode     = SSIF_CFG_DISABLE_ROMDEC_DIRECT;
00037     ssif_cfg.romdec_direct.p_cbfunc = NULL;
00038     result = ssif.ConfigChannel(&ssif_cfg);
00039     if (result < 0) {
00040         printf("ssif config error %d\n", result);
00041     }
00042 
00043     while (1) {
00044         //The upper limit of write buffer is 8.
00045         result = ssif.write((void *)sin_data_44100Hz_16bit_2ch, 
00046                             sizeof(sin_data_44100Hz_16bit_2ch), &ssif_write_end_conf);
00047         if (result < 0) {
00048             printf("ssif write api error %d\n", result);
00049         }
00050     }
00051 }

API

Import library

Public Member Functions

R_BSP_Ssif (PinName sck, PinName ws, PinName tx, PinName rx, uint8_t int_level=0x80, int32_t max_write_num=16, int32_t max_read_num=16)
Constructor.
virtual ~R_BSP_Ssif ()
Destructor.
int32_t GetSsifChNo (void)
Get a value of SSIF channel number.
bool ConfigChannel (const ssif_channel_cfg_t *const p_ch_cfg)
Save configuration to the SSIF driver.
bool GetStatus (uint32_t *const p_status)
Get a value of SSISR register.
int32_t write (void *const p_data, uint32_t data_size, const rbsp_data_conf_t *const p_data_conf=NULL)
Write count bytes to the file associated.
int32_t read (void *const p_data, uint32_t data_size, const rbsp_data_conf_t *const p_data_conf=NULL)
Read count bytes to the file associated.

Protected Member Functions

void write_init (void *handle, void *p_func_a, int32_t max_buff_num=16)
Write init.
void read_init (void *handle, void *p_func_a, int32_t max_buff_num=16)
Read init.

Interface

See the Pinout page for more details


SCUX

The SCUX module consists of a sampling rate converter, a digital volume unit, and a mixer.
The SCUX driver can perform asynchronous and synchronous sampling rate conversions using the sampling rate converter. The SCUX driver uses the DMA transfer mode to input and output audio data.

Hello World!

Import program

00001 #include "mbed.h"
00002 #include "R_BSP_Scux.h"
00003 #include "USBHostMSD.h"
00004 
00005 R_BSP_Scux scux(SCUX_CH_0);
00006 
00007 #define WRITE_SAMPLE_NUM (128)
00008 #define READ_SAMPLE_NUM  (2048)
00009 
00010 const short sin_data[WRITE_SAMPLE_NUM] = {
00011  0x0000,0x0000,0x0C8C,0x0C8C,0x18F9,0x18F9,0x2528,0x2528
00012 ,0x30FB,0x30FB,0x3C56,0x3C56,0x471C,0x471C,0x5133,0x5133
00013 ,0x5A82,0x5A82,0x62F1,0x62F1,0x6A6D,0x6A6D,0x70E2,0x70E2
00014 ,0x7641,0x7641,0x7A7C,0x7A7C,0x7D89,0x7D89,0x7F61,0x7F61
00015 ,0x7FFF,0x7FFF,0x7F61,0x7F61,0x7D89,0x7D89,0x7A7C,0x7A7C
00016 ,0x7641,0x7641,0x70E2,0x70E2,0x6A6D,0x6A6D,0x62F1,0x62F1
00017 ,0x5A82,0x5A82,0x5133,0x5133,0x471C,0x471C,0x3C56,0x3C56
00018 ,0x30FB,0x30FB,0x2528,0x2528,0x18F9,0x18F9,0x0C8C,0x0C8C
00019 ,0x0000,0x0000,0xF374,0xF374,0xE707,0xE707,0xDAD8,0xDAD8
00020 ,0xCF05,0xCF05,0xC3AA,0xC3AA,0xB8E4,0xB8E4,0xAECD,0xAECD
00021 ,0xA57E,0xA57E,0x9D0F,0x9D0F,0x9593,0x9593,0x8F1E,0x8F1E
00022 ,0x89BF,0x89BF,0x8584,0x8584,0x8277,0x8277,0x809F,0x809F
00023 ,0x8001,0x8001,0x809F,0x809F,0x8277,0x8277,0x8584,0x8584
00024 ,0x89BF,0x89BF,0x8F1E,0x8F1E,0x9593,0x9593,0x9D0F,0x9D0F
00025 ,0xA57E,0xA57E,0xAECD,0xAECD,0xB8E4,0xB8E4,0xC3AA,0xC3AA
00026 ,0xCF05,0xCF05,0xDAD8,0xDAD8,0xE707,0xE707,0xF374,0xF374
00027 };
00028 
00029 #if defined(__ICCARM__)
00030 #pragma data_alignment=4
00031 short write_buff[WRITE_SAMPLE_NUM]@ ".mirrorram";
00032 #pragma data_alignment=4
00033 short read_buff[READ_SAMPLE_NUM]@ ".mirrorram";
00034 #else
00035 short write_buff[WRITE_SAMPLE_NUM] __attribute((section("NC_BSS"),aligned(4)));
00036 short read_buff[READ_SAMPLE_NUM] __attribute((section("NC_BSS"),aligned(4)));
00037 #endif
00038 
00039 void scux_setup(void);
00040 void write_task(void const*);
00041 void file_output_to_usb(void);
00042 
00043 int main(void) {
00044     // set up SRC parameters.
00045     scux_setup();
00046 
00047     printf("Sampling rate conversion Start.\n");
00048     // start accepting transmit/receive requests.
00049     scux.TransStart();
00050 
00051     // create a new thread to write to SCUX.
00052     Thread writeTask(write_task, NULL, osPriorityNormal, 1024 * 4);
00053 
00054     // receive request to the SCUX driver.
00055     scux.read(read_buff, sizeof(read_buff));
00056     printf("Sampling rate conversion End.\n");
00057 
00058     // output binary file to USB port 0.
00059     file_output_to_usb();
00060 }
00061 
00062 void scux_setup(void) {
00063     scux_src_usr_cfg_t src_cfg;
00064 
00065     src_cfg.src_enable           = true;
00066     src_cfg.word_len             = SCUX_DATA_LEN_16;
00067     src_cfg.mode_sync            = true;
00068     src_cfg.input_rate           = SAMPLING_RATE_48000HZ;
00069     src_cfg.output_rate          = SAMPLING_RATE_96000HZ;
00070     src_cfg.select_in_data_ch[0] = SELECT_IN_DATA_CH_0;
00071     src_cfg.select_in_data_ch[1] = SELECT_IN_DATA_CH_1;
00072 
00073     scux.SetSrcCfg(&src_cfg);
00074 }
00075 
00076 void scux_flush_callback(int scux_ch) {
00077     // do nothing
00078 }
00079 
00080 void write_task(void const*) {
00081     memcpy(write_buff, sin_data, sizeof(write_buff));
00082     // send request to the SCUX driver.
00083     scux.write(write_buff, sizeof(write_buff));
00084 
00085     // stop the acceptance of transmit/receive requests.
00086     scux.FlushStop(&scux_flush_callback);
00087 }
00088 
00089 void file_output_to_usb(void) {
00090     FILE * fp = NULL;
00091     int i;
00092 
00093     USBHostMSD msd("usb");
00094 
00095     // try to connect a MSD device
00096     for(i = 0; i < 10; i++) {
00097         if (msd.connect()) {
00098             break;
00099         }
00100         wait(0.5);
00101     }
00102 
00103     if (msd.connected()) {
00104         fp = fopen("/usb/scux_input.dat", "rb");
00105         if (fp == NULL) {
00106             fp = fopen("/usb/scux_input.dat", "wb");
00107             if (fp != NULL) {
00108                 fwrite(write_buff, sizeof(short), WRITE_SAMPLE_NUM, fp);
00109                 fclose(fp);
00110                 printf("Output binary file(Input data) to USB.\n");
00111             } else {
00112                 printf("Failed to output binary file(Input data).\n");
00113             }
00114         } else {
00115             printf("Binary file(Input data) exists.\n");
00116             fclose(fp);
00117         }
00118 
00119         fp = fopen("/usb/scux_output.dat", "rb");
00120         if (fp == NULL) {
00121             fp = fopen("/usb/scux_output.dat", "wb");
00122             if (fp != NULL) {
00123                 fwrite(read_buff, sizeof(short), READ_SAMPLE_NUM, fp);
00124                 fclose(fp);
00125                 printf("Output binary file(Output data) to USB.\n");
00126             } else {
00127                 printf("Failed to output binary file(Output data).\n");
00128             }
00129         } else {
00130             printf("Binary file(Output data) exists.\n");
00131             fclose(fp);
00132         }
00133     } else {
00134         printf("Failed to connect to the USB device.\n");
00135     }
00136 } 

API

Import library

Public Member Functions

R_BSP_Scux ( scux_ch_num_t channel, uint8_t int_level=0x80, int32_t max_write_num=16, int32_t max_read_num=16)
Constructor: Initializes and opens the channel designated by the SCUX driver.
virtual ~R_BSP_Scux (void)
Destructor: Closes the channel designated by the SCUX driver and exits.
bool TransStart (void)
Sets up the SCUX HW and starts operation, then starts accepting write/read requests.
bool FlushStop (void(*const callback)(int32_t))
Stops accepting write/read requests, flushes out all data in the SCUX that is requested for transfer, then stops the HW operation.
bool ClearStop (void)
Discards all data in the SCUX that is requested for transfer before stopping the hardware operation and stops accepting write/read requests.
bool SetSrcCfg (const scux_src_usr_cfg_t *const p_src_param)
Sets up SRC parameters.
bool GetWriteStat (uint32_t *const p_write_stat)
Obtains the state information of the write request.
bool GetReadStat (uint32_t *const p_read_stat)
Obtains the state information of the read request.
int32_t write (void *const p_data, uint32_t data_size, const rbsp_data_conf_t *const p_data_conf=NULL)
Write count bytes to the file associated.
int32_t read (void *const p_data, uint32_t data_size, const rbsp_data_conf_t *const p_data_conf=NULL)
Read count bytes to the file associated.

Protected Member Functions

void write_init (void *handle, void *p_func_a, int32_t max_buff_num=16)
Write init.
void read_init (void *handle, void *p_func_a, int32_t max_buff_num=16)
Read init.

Write request state transition diagram

/media/uploads/dkato/scux_write_state_transition.png

Read request state transition diagram

/media/uploads/dkato/scux_read_state_transition.png

Committer:
dkato
Date:
Wed Dec 16 06:33:17 2015 +0000
Revision:
7:30ebba78fff0
Parent:
0:702bf7b2b7d8
Child:
8:cbb9d60c8748
Standardization of processing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:702bf7b2b7d8 1 /*******************************************************************************
dkato 0:702bf7b2b7d8 2 * DISCLAIMER
dkato 0:702bf7b2b7d8 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:702bf7b2b7d8 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:702bf7b2b7d8 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:702bf7b2b7d8 6 * all applicable laws, including copyright laws.
dkato 0:702bf7b2b7d8 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:702bf7b2b7d8 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:702bf7b2b7d8 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:702bf7b2b7d8 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:702bf7b2b7d8 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:702bf7b2b7d8 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:702bf7b2b7d8 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:702bf7b2b7d8 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:702bf7b2b7d8 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:702bf7b2b7d8 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:702bf7b2b7d8 17 * and to discontinue the availability of this software. By using this software,
dkato 0:702bf7b2b7d8 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:702bf7b2b7d8 19 * following link:
dkato 0:702bf7b2b7d8 20 * http://www.renesas.com/disclaimer
dkato 0:702bf7b2b7d8 21 * Copyright (C) 2013-2014 Renesas Electronics Corporation. All rights reserved.
dkato 0:702bf7b2b7d8 22 *******************************************************************************/
dkato 0:702bf7b2b7d8 23
dkato 0:702bf7b2b7d8 24 /*******************************************************************************
dkato 0:702bf7b2b7d8 25 * File Name : ssif_if.c
dkato 0:702bf7b2b7d8 26 * $Rev: 891 $
dkato 0:702bf7b2b7d8 27 * $Date:: 2014-06-27 10:40:52 +0900#$
dkato 0:702bf7b2b7d8 28 * Description : SSIF driver interface functions
dkato 0:702bf7b2b7d8 29 ******************************************************************************/
dkato 0:702bf7b2b7d8 30
dkato 0:702bf7b2b7d8 31 /*******************************************************************************
dkato 0:702bf7b2b7d8 32 Includes <System Includes>, "Project Includes"
dkato 0:702bf7b2b7d8 33 *******************************************************************************/
dkato 0:702bf7b2b7d8 34 #include "cmsis_os.h"
dkato 0:702bf7b2b7d8 35 #if(1) /* mbed */
dkato 7:30ebba78fff0 36 #include "r_bsp_cmn.h"
dkato 0:702bf7b2b7d8 37 #else
dkato 0:702bf7b2b7d8 38 #include "ioif_public.h"
dkato 0:702bf7b2b7d8 39 #endif
dkato 0:702bf7b2b7d8 40 #include "ssif.h"
dkato 0:702bf7b2b7d8 41
dkato 0:702bf7b2b7d8 42 /*******************************************************************************
dkato 0:702bf7b2b7d8 43 Typedef definitions
dkato 0:702bf7b2b7d8 44 *******************************************************************************/
dkato 0:702bf7b2b7d8 45
dkato 0:702bf7b2b7d8 46
dkato 0:702bf7b2b7d8 47 /*******************************************************************************
dkato 0:702bf7b2b7d8 48 Macro definitions
dkato 0:702bf7b2b7d8 49 *******************************************************************************/
dkato 0:702bf7b2b7d8 50
dkato 0:702bf7b2b7d8 51
dkato 0:702bf7b2b7d8 52 /*******************************************************************************
dkato 0:702bf7b2b7d8 53 Exported global variables (to be accessed by other files)
dkato 0:702bf7b2b7d8 54 *******************************************************************************/
dkato 0:702bf7b2b7d8 55
dkato 0:702bf7b2b7d8 56
dkato 0:702bf7b2b7d8 57 /*******************************************************************************
dkato 0:702bf7b2b7d8 58 Private global variables and functions
dkato 0:702bf7b2b7d8 59 *******************************************************************************/
dkato 0:702bf7b2b7d8 60
dkato 0:702bf7b2b7d8 61 #if(1) /* mbed */
dkato 0:702bf7b2b7d8 62 static ssif_drv_stat_t ch_drv_stat[SSIF_NUM_CHANS] = {SSIF_DRVSTS_UNINIT};
dkato 7:30ebba78fff0 63
dkato 7:30ebba78fff0 64 static void* R_SSIF_InitOne(const int_t channel, const void* const config_data, int32_t* const p_errno);
dkato 7:30ebba78fff0 65 static int_t R_SSIF_UnInitOne(const int_t channel, const void* const driver_instance, int32_t* const p_errno);
dkato 7:30ebba78fff0 66 #endif /* end mbed */
dkato 0:702bf7b2b7d8 67 static void* R_SSIF_Init(void* const config_data, int32_t* const p_errno);
dkato 0:702bf7b2b7d8 68 static int_t R_SSIF_UnInit(void* const driver_instance, int32_t* const p_errno);
dkato 0:702bf7b2b7d8 69 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);
dkato 0:702bf7b2b7d8 70 static int_t R_SSIF_Close(void* const p_fd, int32_t* const p_errno);
dkato 0:702bf7b2b7d8 71 static int_t R_SSIF_Ioctl(void* const p_fd, const int_t request, void* const p_buf, int32_t* const p_errno);
dkato 0:702bf7b2b7d8 72 static int_t R_SSIF_WriteAsync(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno);
dkato 0:702bf7b2b7d8 73 static int_t R_SSIF_ReadAsync(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno);
dkato 0:702bf7b2b7d8 74 static int_t R_SSIF_Cancel(void* const p_fd, AIOCB* p_aio, int32_t* const p_errno);
dkato 0:702bf7b2b7d8 75
dkato 0:702bf7b2b7d8 76 static size_t SSIF_StrnLen(const char_t p_str[], const size_t maxlen);
dkato 0:702bf7b2b7d8 77 static int32_t SSIF_Strncmp(const char_t p_str1[], const char_t p_str2[], const uint32_t maxlen);
dkato 0:702bf7b2b7d8 78 static void SSIF_SetErrCode(const int_t error_code, int32_t* const p_errno);
dkato 0:702bf7b2b7d8 79
dkato 0:702bf7b2b7d8 80 /******************************************************************************
dkato 0:702bf7b2b7d8 81 Exported global functions (to be accessed by other files)
dkato 0:702bf7b2b7d8 82 ******************************************************************************/
dkato 0:702bf7b2b7d8 83
dkato 0:702bf7b2b7d8 84 #if(1) /* mbed */
dkato 7:30ebba78fff0 85 /******************************************************************************
dkato 7:30ebba78fff0 86 * Function Name: R_SSIF_MakeCbTbl_mbed
dkato 7:30ebba78fff0 87 * @brief Make the SSIF driver function callback table
dkato 7:30ebba78fff0 88 *
dkato 7:30ebba78fff0 89 * Description:<br>
dkato 7:30ebba78fff0 90 *
dkato 7:30ebba78fff0 91 * @param none
dkato 7:30ebba78fff0 92 * @retval pointer of SSIF driver function callback table
dkato 7:30ebba78fff0 93 ******************************************************************************/
dkato 7:30ebba78fff0 94 /* ->IPA M1.1.1 : This is liblary funciotn that is called from other module. */
dkato 7:30ebba78fff0 95 RBSP_MBED_FNS* R_SSIF_MakeCbTbl_mbed(void)
dkato 7:30ebba78fff0 96 /* <-IPA M1.1.1 */
dkato 7:30ebba78fff0 97 {
dkato 7:30ebba78fff0 98 static RBSP_MBED_FNS ssif_apitbl_mbed;
dkato 7:30ebba78fff0 99
dkato 7:30ebba78fff0 100 ssif_apitbl_mbed.initialise_one = &R_SSIF_InitOne;
dkato 7:30ebba78fff0 101 ssif_apitbl_mbed.uninitialise_one = &R_SSIF_UnInitOne;
dkato 7:30ebba78fff0 102 ssif_apitbl_mbed.open = &R_SSIF_Open;
dkato 7:30ebba78fff0 103 ssif_apitbl_mbed.close = &R_SSIF_Close;
dkato 7:30ebba78fff0 104 ssif_apitbl_mbed.ioctl = &R_SSIF_Ioctl;
dkato 7:30ebba78fff0 105 ssif_apitbl_mbed.read_a = &R_SSIF_ReadAsync;
dkato 7:30ebba78fff0 106 ssif_apitbl_mbed.write_a = &R_SSIF_WriteAsync;
dkato 7:30ebba78fff0 107
dkato 7:30ebba78fff0 108 return &ssif_apitbl_mbed;
dkato 7:30ebba78fff0 109 }
dkato 0:702bf7b2b7d8 110 #else
dkato 0:702bf7b2b7d8 111 /******************************************************************************
dkato 0:702bf7b2b7d8 112 * Function Name: R_SSIF_MakeCbTbl
dkato 0:702bf7b2b7d8 113 * @brief Make the SSIF driver function callback table
dkato 0:702bf7b2b7d8 114 *
dkato 0:702bf7b2b7d8 115 * Description:<br>
dkato 0:702bf7b2b7d8 116 *
dkato 0:702bf7b2b7d8 117 * @param none
dkato 0:702bf7b2b7d8 118 * @retval pointer of SSIF driver function callback table
dkato 0:702bf7b2b7d8 119 ******************************************************************************/
dkato 0:702bf7b2b7d8 120 /* ->IPA M1.1.1 : This is liblary funciotn that is called from other module. */
dkato 0:702bf7b2b7d8 121 IOIF_DRV_API* R_SSIF_MakeCbTbl(void)
dkato 0:702bf7b2b7d8 122 /* <-IPA M1.1.1 */
dkato 0:702bf7b2b7d8 123 {
dkato 0:702bf7b2b7d8 124 static IOIF_DRV_API ssif_apitbl;
dkato 0:702bf7b2b7d8 125
dkato 0:702bf7b2b7d8 126 /* ->MISRA 16.4, IPA M4.5.1 : This is IOIF library API type definitnon that can't be modified. */
dkato 0:702bf7b2b7d8 127 ssif_apitbl.family = IOIF_SERIAL_FAMILY;
dkato 0:702bf7b2b7d8 128 ssif_apitbl.fns.serial.initialise = &R_SSIF_Init;
dkato 0:702bf7b2b7d8 129 ssif_apitbl.fns.serial.uninitialise = &R_SSIF_UnInit;
dkato 0:702bf7b2b7d8 130 ssif_apitbl.fns.serial.open = &R_SSIF_Open;
dkato 0:702bf7b2b7d8 131 ssif_apitbl.fns.serial.close = &R_SSIF_Close;
dkato 0:702bf7b2b7d8 132 ssif_apitbl.fns.serial.ioctl = &R_SSIF_Ioctl;
dkato 0:702bf7b2b7d8 133 ssif_apitbl.fns.serial.read_a = &R_SSIF_ReadAsync;
dkato 0:702bf7b2b7d8 134 ssif_apitbl.fns.serial.write_a = &R_SSIF_WriteAsync;
dkato 0:702bf7b2b7d8 135 ssif_apitbl.fns.serial.cancel = &R_SSIF_Cancel;
dkato 0:702bf7b2b7d8 136 /* <-MISRA 16.4, IPA M4.5.1 */
dkato 0:702bf7b2b7d8 137
dkato 0:702bf7b2b7d8 138 return &ssif_apitbl;
dkato 0:702bf7b2b7d8 139 }
dkato 7:30ebba78fff0 140 #endif /* end mbed */
dkato 0:702bf7b2b7d8 141
dkato 0:702bf7b2b7d8 142 /******************************************************************************
dkato 0:702bf7b2b7d8 143 * Function Name: R_SSIF_SWLtoLen
dkato 0:702bf7b2b7d8 144 * @brief Convert SSICR:SWL bits to system word length
dkato 0:702bf7b2b7d8 145 *
dkato 0:702bf7b2b7d8 146 * Description:<br>
dkato 0:702bf7b2b7d8 147 *
dkato 0:702bf7b2b7d8 148 * @param[in] ssicr_swl :SSICR register SWL field value(0 to 7)
dkato 0:702bf7b2b7d8 149 * @retval 8 to 256 :system word length(byte)
dkato 0:702bf7b2b7d8 150 ******************************************************************************/
dkato 0:702bf7b2b7d8 151 int_t R_SSIF_SWLtoLen(const ssif_chcfg_system_word_t ssicr_swl)
dkato 0:702bf7b2b7d8 152 {
dkato 0:702bf7b2b7d8 153 return SSIF_SWLtoLen(ssicr_swl);
dkato 0:702bf7b2b7d8 154 }
dkato 0:702bf7b2b7d8 155
dkato 0:702bf7b2b7d8 156 /******************************************************************************
dkato 0:702bf7b2b7d8 157 Private functions
dkato 0:702bf7b2b7d8 158 ******************************************************************************/
dkato 0:702bf7b2b7d8 159
dkato 7:30ebba78fff0 160 #if(1) /* mbed */
dkato 0:702bf7b2b7d8 161 /******************************************************************************
dkato 7:30ebba78fff0 162 * Function Name: R_SSIF_InitOne
dkato 0:702bf7b2b7d8 163 * @brief Initialise the SSIF driver.
dkato 0:702bf7b2b7d8 164 *
dkato 0:702bf7b2b7d8 165 * Description:<br>
dkato 0:702bf7b2b7d8 166 *
dkato 7:30ebba78fff0 167 * @param[in] channel :channel number
dkato 0:702bf7b2b7d8 168 * @param[in] config_data :pointer of several parameters array per channels
dkato 0:702bf7b2b7d8 169 * @param[in,out] p_errno :pointer of error code
dkato 0:702bf7b2b7d8 170 * @retval not ERRROR :driver instance.
dkato 0:702bf7b2b7d8 171 * @retval EERROR :Failure.
dkato 0:702bf7b2b7d8 172 ******************************************************************************/
dkato 0:702bf7b2b7d8 173 /* ->MISRA 16.7, IPA M1.11.1 : This is IOIF library API type definitnon that can't be modified. */
dkato 7:30ebba78fff0 174 static void* R_SSIF_InitOne(const int_t channel, const void* const config_data, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 175 /* <-MISRA 16.7, IPA M1.11.1 */
dkato 0:702bf7b2b7d8 176 {
dkato 0:702bf7b2b7d8 177 int_t ercd;
dkato 0:702bf7b2b7d8 178 void* p_ret = (void*)EERROR;
dkato 0:702bf7b2b7d8 179
dkato 0:702bf7b2b7d8 180 if (NULL == config_data)
dkato 0:702bf7b2b7d8 181 {
dkato 0:702bf7b2b7d8 182 ercd = EFAULT;
dkato 0:702bf7b2b7d8 183 }
dkato 0:702bf7b2b7d8 184 else if (channel >= SSIF_NUM_CHANS)
dkato 0:702bf7b2b7d8 185 {
dkato 0:702bf7b2b7d8 186 ercd = EFAULT;
dkato 0:702bf7b2b7d8 187 }
dkato 0:702bf7b2b7d8 188 else
dkato 0:702bf7b2b7d8 189 {
dkato 7:30ebba78fff0 190 g_ssif_info_drv.drv_stat = SSIF_DRVSTS_INIT;
dkato 0:702bf7b2b7d8 191 ch_drv_stat[channel] = SSIF_DRVSTS_INIT;
dkato 0:702bf7b2b7d8 192
dkato 7:30ebba78fff0 193 ercd = SSIF_InitialiseOne(channel, (const ssif_channel_cfg_t*)config_data);
dkato 0:702bf7b2b7d8 194
dkato 0:702bf7b2b7d8 195 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 196 {
dkato 0:702bf7b2b7d8 197 p_ret = (void*)&g_ssif_info_drv;
dkato 0:702bf7b2b7d8 198 }
dkato 0:702bf7b2b7d8 199 else
dkato 0:702bf7b2b7d8 200 {
dkato 0:702bf7b2b7d8 201 ch_drv_stat[channel] = SSIF_DRVSTS_UNINIT;
dkato 0:702bf7b2b7d8 202 }
dkato 0:702bf7b2b7d8 203 }
dkato 0:702bf7b2b7d8 204
dkato 0:702bf7b2b7d8 205 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 206
dkato 0:702bf7b2b7d8 207 return p_ret;
dkato 0:702bf7b2b7d8 208 }
dkato 7:30ebba78fff0 209
dkato 7:30ebba78fff0 210 /******************************************************************************
dkato 7:30ebba78fff0 211 * Function Name: R_SSIF_UnInitOne
dkato 7:30ebba78fff0 212 * @brief Uninitialise the SSIF deiver.
dkato 7:30ebba78fff0 213 *
dkato 7:30ebba78fff0 214 * Description:<br>
dkato 7:30ebba78fff0 215 *
dkato 7:30ebba78fff0 216 * @param[in] channel :channel number
dkato 7:30ebba78fff0 217 * @param[in,out] driver_instance :driver instance which was returned by<br>
dkato 7:30ebba78fff0 218 R_SSIF_Init
dkato 7:30ebba78fff0 219 * @param[in,out] p_errno :pointer of error code
dkato 7:30ebba78fff0 220 * @retval ESUCCESS :Success.
dkato 7:30ebba78fff0 221 * @retval EERROR :Failure.
dkato 7:30ebba78fff0 222 ******************************************************************************/
dkato 7:30ebba78fff0 223 static int_t R_SSIF_UnInitOne(const int_t channel, const void* const driver_instance, int32_t* const p_errno)
dkato 7:30ebba78fff0 224 {
dkato 7:30ebba78fff0 225 int_t ercd;
dkato 7:30ebba78fff0 226 int_t ret = ESUCCESS;
dkato 7:30ebba78fff0 227
dkato 7:30ebba78fff0 228 if (NULL == driver_instance)
dkato 7:30ebba78fff0 229 {
dkato 7:30ebba78fff0 230 ercd = EFAULT;
dkato 7:30ebba78fff0 231 }
dkato 7:30ebba78fff0 232 else if (channel >= SSIF_NUM_CHANS)
dkato 7:30ebba78fff0 233 {
dkato 7:30ebba78fff0 234 ercd = EFAULT;
dkato 7:30ebba78fff0 235 }
dkato 7:30ebba78fff0 236 else
dkato 7:30ebba78fff0 237 {
dkato 7:30ebba78fff0 238 if (SSIF_DRVSTS_INIT != ch_drv_stat[channel])
dkato 7:30ebba78fff0 239 {
dkato 7:30ebba78fff0 240 ercd = EFAULT;
dkato 7:30ebba78fff0 241 }
dkato 7:30ebba78fff0 242 else
dkato 7:30ebba78fff0 243 {
dkato 7:30ebba78fff0 244 ercd = SSIF_UnInitialiseOne(channel);
dkato 7:30ebba78fff0 245 ch_drv_stat[channel] = SSIF_DRVSTS_UNINIT;
dkato 7:30ebba78fff0 246 }
dkato 7:30ebba78fff0 247 }
dkato 7:30ebba78fff0 248
dkato 7:30ebba78fff0 249 if (ESUCCESS != ercd)
dkato 7:30ebba78fff0 250 {
dkato 7:30ebba78fff0 251 ret = EERROR;
dkato 7:30ebba78fff0 252 }
dkato 7:30ebba78fff0 253 SSIF_SetErrCode(ercd, p_errno);
dkato 7:30ebba78fff0 254
dkato 7:30ebba78fff0 255 return ret;
dkato 7:30ebba78fff0 256 }
dkato 7:30ebba78fff0 257
dkato 7:30ebba78fff0 258 #endif /* end mbed */
dkato 7:30ebba78fff0 259
dkato 7:30ebba78fff0 260 /******************************************************************************
dkato 7:30ebba78fff0 261 * Function Name: R_SSIF_Init
dkato 7:30ebba78fff0 262 * @brief Initialise the SSIF driver.
dkato 7:30ebba78fff0 263 *
dkato 7:30ebba78fff0 264 * Description:<br>
dkato 7:30ebba78fff0 265 *
dkato 7:30ebba78fff0 266 * @param[in] config_data :pointer of several parameters array per channels
dkato 7:30ebba78fff0 267 * @param[in,out] p_errno :pointer of error code
dkato 7:30ebba78fff0 268 * @retval not ERRROR :driver instance.
dkato 7:30ebba78fff0 269 * @retval EERROR :Failure.
dkato 7:30ebba78fff0 270 ******************************************************************************/
dkato 7:30ebba78fff0 271 /* ->MISRA 16.7, IPA M1.11.1 : This is IOIF library API type definitnon that can't be modified. */
dkato 0:702bf7b2b7d8 272 static void* R_SSIF_Init(void* const config_data, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 273 /* <-MISRA 16.7, IPA M1.11.1 */
dkato 0:702bf7b2b7d8 274 {
dkato 0:702bf7b2b7d8 275 int_t ercd;
dkato 0:702bf7b2b7d8 276 void* p_ret = (void*)EERROR;
dkato 0:702bf7b2b7d8 277
dkato 0:702bf7b2b7d8 278 if (NULL == config_data)
dkato 0:702bf7b2b7d8 279 {
dkato 0:702bf7b2b7d8 280 ercd = EFAULT;
dkato 0:702bf7b2b7d8 281 }
dkato 0:702bf7b2b7d8 282 else if (SSIF_DRVSTS_UNINIT != g_ssif_info_drv.drv_stat)
dkato 0:702bf7b2b7d8 283 {
dkato 0:702bf7b2b7d8 284 ercd = EBUSY;
dkato 0:702bf7b2b7d8 285 }
dkato 0:702bf7b2b7d8 286 else
dkato 0:702bf7b2b7d8 287 {
dkato 0:702bf7b2b7d8 288 g_ssif_info_drv.drv_stat = SSIF_DRVSTS_INIT;
dkato 0:702bf7b2b7d8 289
dkato 0:702bf7b2b7d8 290 ercd = SSIF_Initialise((ssif_channel_cfg_t*)config_data);
dkato 0:702bf7b2b7d8 291
dkato 0:702bf7b2b7d8 292 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 293 {
dkato 0:702bf7b2b7d8 294 p_ret = (void*)&g_ssif_info_drv;
dkato 0:702bf7b2b7d8 295 }
dkato 0:702bf7b2b7d8 296 else
dkato 0:702bf7b2b7d8 297 {
dkato 0:702bf7b2b7d8 298 g_ssif_info_drv.drv_stat = SSIF_DRVSTS_UNINIT;
dkato 0:702bf7b2b7d8 299 }
dkato 0:702bf7b2b7d8 300 }
dkato 0:702bf7b2b7d8 301
dkato 0:702bf7b2b7d8 302 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 303
dkato 0:702bf7b2b7d8 304 return p_ret;
dkato 0:702bf7b2b7d8 305 }
dkato 0:702bf7b2b7d8 306
dkato 0:702bf7b2b7d8 307 /******************************************************************************
dkato 0:702bf7b2b7d8 308 * Function Name: R_SSIF_UnInit
dkato 0:702bf7b2b7d8 309 * @brief Uninitialise the SSIF deiver.
dkato 0:702bf7b2b7d8 310 *
dkato 0:702bf7b2b7d8 311 * Description:<br>
dkato 0:702bf7b2b7d8 312 *
dkato 0:702bf7b2b7d8 313 * @param[in,out] driver_instance :driver instance which was returned by<br>
dkato 0:702bf7b2b7d8 314 R_SSIF_Init
dkato 0:702bf7b2b7d8 315 * @param[in,out] p_errno :pointer of error code
dkato 0:702bf7b2b7d8 316 * @retval ESUCCESS :Success.
dkato 0:702bf7b2b7d8 317 * @retval EERROR :Failure.
dkato 0:702bf7b2b7d8 318 ******************************************************************************/
dkato 0:702bf7b2b7d8 319 static int_t R_SSIF_UnInit(void* const driver_instance, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 320 {
dkato 0:702bf7b2b7d8 321 int_t ercd;
dkato 0:702bf7b2b7d8 322 int_t ret = ESUCCESS;
dkato 0:702bf7b2b7d8 323 ssif_info_drv_t* const p_info_drv = driver_instance;
dkato 0:702bf7b2b7d8 324
dkato 0:702bf7b2b7d8 325 if (NULL == p_info_drv)
dkato 0:702bf7b2b7d8 326 {
dkato 0:702bf7b2b7d8 327 ercd = EFAULT;
dkato 0:702bf7b2b7d8 328 }
dkato 0:702bf7b2b7d8 329 else
dkato 0:702bf7b2b7d8 330 {
dkato 0:702bf7b2b7d8 331 if (SSIF_DRVSTS_INIT != p_info_drv->drv_stat)
dkato 0:702bf7b2b7d8 332 {
dkato 0:702bf7b2b7d8 333 ercd = EFAULT;
dkato 0:702bf7b2b7d8 334 }
dkato 0:702bf7b2b7d8 335 else
dkato 0:702bf7b2b7d8 336 {
dkato 0:702bf7b2b7d8 337 ercd = SSIF_UnInitialise();
dkato 0:702bf7b2b7d8 338 p_info_drv->drv_stat = SSIF_DRVSTS_UNINIT;
dkato 0:702bf7b2b7d8 339 }
dkato 0:702bf7b2b7d8 340 }
dkato 0:702bf7b2b7d8 341
dkato 0:702bf7b2b7d8 342 if (ESUCCESS != ercd)
dkato 0:702bf7b2b7d8 343 {
dkato 0:702bf7b2b7d8 344 ret = EERROR;
dkato 0:702bf7b2b7d8 345 }
dkato 0:702bf7b2b7d8 346 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 347
dkato 0:702bf7b2b7d8 348 return ret;
dkato 0:702bf7b2b7d8 349 }
dkato 0:702bf7b2b7d8 350
dkato 0:702bf7b2b7d8 351 /******************************************************************************
dkato 0:702bf7b2b7d8 352 * Function Name: R_SSIF_Open
dkato 0:702bf7b2b7d8 353 * @brief Open an SSIF channel
dkato 0:702bf7b2b7d8 354 *
dkato 0:702bf7b2b7d8 355 * Description:<br>
dkato 0:702bf7b2b7d8 356 *
dkato 0:702bf7b2b7d8 357 * @param[in,out] p_drv_instance :driver instance which was returned by<br>
dkato 0:702bf7b2b7d8 358 R_SSIF_Init
dkato 0:702bf7b2b7d8 359 * @param[in] p_path_name :string of channel
dkato 0:702bf7b2b7d8 360 * @param[in] flags :access mode whether the channel is opened<br>
dkato 0:702bf7b2b7d8 361 for a read or a write
dkato 0:702bf7b2b7d8 362 * @param[in] mode :not used
dkato 0:702bf7b2b7d8 363 * @param[in,out] p_errno :pointer of error code
dkato 0:702bf7b2b7d8 364 * @retval not EERROR :channel handle
dkato 0:702bf7b2b7d8 365 * @retval EERROR :Failure.
dkato 0:702bf7b2b7d8 366 ******************************************************************************/
dkato 0:702bf7b2b7d8 367 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)
dkato 0:702bf7b2b7d8 368 {
dkato 0:702bf7b2b7d8 369 uint32_t ssif_ch;
dkato 0:702bf7b2b7d8 370 void* p_channelHandle;
dkato 0:702bf7b2b7d8 371 size_t len;
dkato 0:702bf7b2b7d8 372 size_t req_path_len;
dkato 0:702bf7b2b7d8 373 ssif_info_drv_t* const p_info_drv = p_driver_instance;
dkato 0:702bf7b2b7d8 374 ssif_info_ch_t* p_info_ch = NULL;
dkato 0:702bf7b2b7d8 375 int_t ret;
dkato 0:702bf7b2b7d8 376 int_t ercd = ESUCCESS;
dkato 0:702bf7b2b7d8 377 osStatus os_ercd;
dkato 0:702bf7b2b7d8 378 int32_t os_ret;
dkato 0:702bf7b2b7d8 379 static const char_t* const ch_name_string[SSIF_NUM_CHANS] =
dkato 0:702bf7b2b7d8 380 {
dkato 0:702bf7b2b7d8 381 SSIF_CHSTR_0,
dkato 0:702bf7b2b7d8 382 SSIF_CHSTR_1,
dkato 0:702bf7b2b7d8 383 SSIF_CHSTR_2,
dkato 0:702bf7b2b7d8 384 SSIF_CHSTR_3,
dkato 0:702bf7b2b7d8 385 SSIF_CHSTR_4,
dkato 0:702bf7b2b7d8 386 SSIF_CHSTR_5
dkato 0:702bf7b2b7d8 387 };
dkato 0:702bf7b2b7d8 388
dkato 0:702bf7b2b7d8 389 UNUSED_ARG(mode);
dkato 0:702bf7b2b7d8 390
dkato 0:702bf7b2b7d8 391 if ((NULL == p_info_drv) || (NULL == p_path_name))
dkato 0:702bf7b2b7d8 392 {
dkato 0:702bf7b2b7d8 393 ercd = EFAULT;
dkato 0:702bf7b2b7d8 394 }
dkato 0:702bf7b2b7d8 395 else
dkato 0:702bf7b2b7d8 396 {
dkato 0:702bf7b2b7d8 397 req_path_len = strlen(p_path_name);
dkato 0:702bf7b2b7d8 398 if (0u == req_path_len)
dkato 0:702bf7b2b7d8 399 {
dkato 0:702bf7b2b7d8 400 ercd = ENOENT;
dkato 0:702bf7b2b7d8 401 }
dkato 0:702bf7b2b7d8 402
dkato 0:702bf7b2b7d8 403 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 404 {
dkato 0:702bf7b2b7d8 405 if (SSIF_DRVSTS_INIT != p_info_drv->drv_stat)
dkato 0:702bf7b2b7d8 406 {
dkato 0:702bf7b2b7d8 407 ercd = EFAULT;
dkato 0:702bf7b2b7d8 408 }
dkato 0:702bf7b2b7d8 409 }
dkato 0:702bf7b2b7d8 410
dkato 0:702bf7b2b7d8 411 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 412 {
dkato 0:702bf7b2b7d8 413 /* Serch the same pathname */
dkato 0:702bf7b2b7d8 414 for (ssif_ch = 0u; (ssif_ch < SSIF_NUM_CHANS) && (p_info_ch == NULL); ssif_ch++)
dkato 0:702bf7b2b7d8 415 {
dkato 0:702bf7b2b7d8 416 len = SSIF_StrnLen(ch_name_string[ssif_ch], SSIF_MAX_PATH_LEN);
dkato 0:702bf7b2b7d8 417
dkato 0:702bf7b2b7d8 418 if (req_path_len < len)
dkato 0:702bf7b2b7d8 419 {
dkato 0:702bf7b2b7d8 420 len = req_path_len;
dkato 0:702bf7b2b7d8 421 }
dkato 0:702bf7b2b7d8 422
dkato 0:702bf7b2b7d8 423 if (0 == SSIF_Strncmp(p_path_name, ch_name_string[ssif_ch], len))
dkato 0:702bf7b2b7d8 424 {
dkato 0:702bf7b2b7d8 425 /* found a match */
dkato 0:702bf7b2b7d8 426 p_info_ch = &p_info_drv->info_ch[ssif_ch];
dkato 0:702bf7b2b7d8 427 }
dkato 0:702bf7b2b7d8 428 }
dkato 0:702bf7b2b7d8 429 }
dkato 0:702bf7b2b7d8 430 }
dkato 0:702bf7b2b7d8 431
dkato 0:702bf7b2b7d8 432 if (NULL == p_info_ch)
dkato 0:702bf7b2b7d8 433 {
dkato 0:702bf7b2b7d8 434 ercd = ENOENT;
dkato 0:702bf7b2b7d8 435 }
dkato 0:702bf7b2b7d8 436 else
dkato 0:702bf7b2b7d8 437 {
dkato 0:702bf7b2b7d8 438 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 439 {
dkato 0:702bf7b2b7d8 440 if (false == p_info_ch->enabled)
dkato 0:702bf7b2b7d8 441 {
dkato 0:702bf7b2b7d8 442 ercd = ENOTSUP;
dkato 0:702bf7b2b7d8 443 }
dkato 0:702bf7b2b7d8 444 }
dkato 0:702bf7b2b7d8 445
dkato 0:702bf7b2b7d8 446 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 447 {
dkato 0:702bf7b2b7d8 448 if (SSIF_CHSTS_INIT != p_info_ch->ch_stat)
dkato 0:702bf7b2b7d8 449 {
dkato 0:702bf7b2b7d8 450 ercd = EBADF;
dkato 0:702bf7b2b7d8 451 }
dkato 0:702bf7b2b7d8 452 }
dkato 0:702bf7b2b7d8 453
dkato 0:702bf7b2b7d8 454 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 455 {
dkato 0:702bf7b2b7d8 456 /* ->MISRA 10.6 : This macro is defined by CMSIS-RTOS that can't be modified. */
dkato 0:702bf7b2b7d8 457 os_ret = osSemaphoreWait(p_info_ch->sem_access, osWaitForever);
dkato 0:702bf7b2b7d8 458 /* <-MISRA 10.6 */
dkato 0:702bf7b2b7d8 459
dkato 0:702bf7b2b7d8 460 if ((-1) == os_ret)
dkato 0:702bf7b2b7d8 461 {
dkato 0:702bf7b2b7d8 462 ercd = EFAULT;
dkato 0:702bf7b2b7d8 463 }
dkato 0:702bf7b2b7d8 464 else
dkato 0:702bf7b2b7d8 465 {
dkato 0:702bf7b2b7d8 466 p_info_ch->openflag = flags;
dkato 0:702bf7b2b7d8 467 p_info_ch->p_aio_tx_curr = NULL;
dkato 0:702bf7b2b7d8 468 p_info_ch->p_aio_rx_curr = NULL;
dkato 0:702bf7b2b7d8 469
dkato 0:702bf7b2b7d8 470 ercd = SSIF_EnableChannel(p_info_ch);
dkato 0:702bf7b2b7d8 471
dkato 0:702bf7b2b7d8 472 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 473 {
dkato 0:702bf7b2b7d8 474 p_info_ch->ch_stat = SSIF_CHSTS_OPEN;
dkato 0:702bf7b2b7d8 475 }
dkato 0:702bf7b2b7d8 476 }
dkato 0:702bf7b2b7d8 477 os_ercd = osSemaphoreRelease(p_info_ch->sem_access);
dkato 0:702bf7b2b7d8 478 if (osOK != os_ercd)
dkato 0:702bf7b2b7d8 479 {
dkato 0:702bf7b2b7d8 480 ercd = EFAULT;
dkato 0:702bf7b2b7d8 481 }
dkato 0:702bf7b2b7d8 482 }
dkato 0:702bf7b2b7d8 483 }
dkato 0:702bf7b2b7d8 484
dkato 0:702bf7b2b7d8 485 if (ESUCCESS != ercd)
dkato 0:702bf7b2b7d8 486 {
dkato 0:702bf7b2b7d8 487 ret = EERROR; /* EERROR(-1) */
dkato 0:702bf7b2b7d8 488 }
dkato 0:702bf7b2b7d8 489 else
dkato 0:702bf7b2b7d8 490 {
dkato 0:702bf7b2b7d8 491 p_channelHandle = (void*)p_info_ch;
dkato 0:702bf7b2b7d8 492 ret = (int_t)p_channelHandle;
dkato 0:702bf7b2b7d8 493 }
dkato 0:702bf7b2b7d8 494 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 495
dkato 0:702bf7b2b7d8 496 return ret;
dkato 0:702bf7b2b7d8 497 }
dkato 0:702bf7b2b7d8 498
dkato 0:702bf7b2b7d8 499 /******************************************************************************
dkato 0:702bf7b2b7d8 500 * Function Name: R_SSIF_Close
dkato 0:702bf7b2b7d8 501 * @brief Close an SSIF channel.
dkato 0:702bf7b2b7d8 502 *
dkato 0:702bf7b2b7d8 503 * Description:<br>
dkato 0:702bf7b2b7d8 504 *
dkato 0:702bf7b2b7d8 505 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open
dkato 0:702bf7b2b7d8 506 * @param[in,out] p_errno :pointer of error code
dkato 0:702bf7b2b7d8 507 * @retval ESUCCESS :Success.
dkato 0:702bf7b2b7d8 508 * @retval EERROR :Failure.
dkato 0:702bf7b2b7d8 509 ******************************************************************************/
dkato 0:702bf7b2b7d8 510 static int_t R_SSIF_Close(void* const p_fd, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 511 {
dkato 0:702bf7b2b7d8 512 ssif_info_ch_t* const p_info_ch = p_fd;
dkato 0:702bf7b2b7d8 513 int_t ret = ESUCCESS;
dkato 0:702bf7b2b7d8 514 int_t ercd;
dkato 0:702bf7b2b7d8 515 osStatus os_ercd;
dkato 0:702bf7b2b7d8 516 int32_t os_ret;
dkato 0:702bf7b2b7d8 517
dkato 0:702bf7b2b7d8 518 if (NULL == p_info_ch)
dkato 0:702bf7b2b7d8 519 {
dkato 0:702bf7b2b7d8 520 ercd = EFAULT;
dkato 0:702bf7b2b7d8 521 }
dkato 0:702bf7b2b7d8 522 else
dkato 0:702bf7b2b7d8 523 {
dkato 0:702bf7b2b7d8 524 /* ->MISRA 10.6 : This macro is defined by CMSIS-RTOS that can't be modified. */
dkato 0:702bf7b2b7d8 525 /* Get semaphore to access the channel data */
dkato 0:702bf7b2b7d8 526 os_ret = osSemaphoreWait(p_info_ch->sem_access, osWaitForever);
dkato 0:702bf7b2b7d8 527 /* <-MISRA 10.6 */
dkato 0:702bf7b2b7d8 528
dkato 0:702bf7b2b7d8 529 if ((-1) == os_ret)
dkato 0:702bf7b2b7d8 530 {
dkato 0:702bf7b2b7d8 531 ercd = EFAULT;
dkato 0:702bf7b2b7d8 532 }
dkato 0:702bf7b2b7d8 533 else
dkato 0:702bf7b2b7d8 534 {
dkato 0:702bf7b2b7d8 535 if (SSIF_CHSTS_OPEN != p_info_ch->ch_stat)
dkato 0:702bf7b2b7d8 536 {
dkato 0:702bf7b2b7d8 537 ercd = EFAULT;
dkato 0:702bf7b2b7d8 538 }
dkato 0:702bf7b2b7d8 539 else
dkato 0:702bf7b2b7d8 540 {
dkato 0:702bf7b2b7d8 541 SSIF_PostAsyncCancel(p_info_ch, NULL);
dkato 0:702bf7b2b7d8 542
dkato 0:702bf7b2b7d8 543 ercd = SSIF_DisableChannel(p_info_ch);
dkato 0:702bf7b2b7d8 544
dkato 0:702bf7b2b7d8 545 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 546 {
dkato 0:702bf7b2b7d8 547 p_info_ch->ch_stat = SSIF_CHSTS_INIT;
dkato 0:702bf7b2b7d8 548 }
dkato 0:702bf7b2b7d8 549 }
dkato 0:702bf7b2b7d8 550
dkato 0:702bf7b2b7d8 551 /* Relese semaphore */
dkato 0:702bf7b2b7d8 552 os_ercd = osSemaphoreRelease(p_info_ch->sem_access);
dkato 0:702bf7b2b7d8 553
dkato 0:702bf7b2b7d8 554 if (osOK != os_ercd)
dkato 0:702bf7b2b7d8 555 {
dkato 0:702bf7b2b7d8 556 ercd = EFAULT;
dkato 0:702bf7b2b7d8 557 }
dkato 0:702bf7b2b7d8 558 }
dkato 0:702bf7b2b7d8 559 }
dkato 0:702bf7b2b7d8 560
dkato 0:702bf7b2b7d8 561 if (ESUCCESS != ercd)
dkato 0:702bf7b2b7d8 562 {
dkato 0:702bf7b2b7d8 563 ret = EERROR; /* EERROR(-1) */
dkato 0:702bf7b2b7d8 564 }
dkato 0:702bf7b2b7d8 565 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 566
dkato 0:702bf7b2b7d8 567 return ret;
dkato 0:702bf7b2b7d8 568 }
dkato 0:702bf7b2b7d8 569
dkato 0:702bf7b2b7d8 570 /******************************************************************************
dkato 0:702bf7b2b7d8 571 * Function Name: R_SSIF_Ioctl
dkato 0:702bf7b2b7d8 572 * @brief IOCTL function of the SSIF deiver
dkato 0:702bf7b2b7d8 573 *
dkato 0:702bf7b2b7d8 574 * Description:<br>
dkato 0:702bf7b2b7d8 575 *
dkato 0:702bf7b2b7d8 576 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open
dkato 0:702bf7b2b7d8 577 * @param[in] request :IOCTL request code
dkato 0:702bf7b2b7d8 578 * @param[in,out] p_buf :Meaning depends upon request.
dkato 0:702bf7b2b7d8 579 * @param[in,out] p_errno :pointer of error code
dkato 0:702bf7b2b7d8 580 * @retval ESUCCESS :Success.
dkato 0:702bf7b2b7d8 581 * @retval EERROR :Failure.
dkato 0:702bf7b2b7d8 582 ******************************************************************************/
dkato 0:702bf7b2b7d8 583 static int_t R_SSIF_Ioctl(void* const p_fd, const int_t request, void* const p_buf, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 584 {
dkato 0:702bf7b2b7d8 585 ssif_info_ch_t* const p_info_ch = p_fd;
dkato 0:702bf7b2b7d8 586 int_t ret = ESUCCESS;
dkato 0:702bf7b2b7d8 587 int_t ercd = ESUCCESS;
dkato 0:702bf7b2b7d8 588 osStatus os_ercd;
dkato 0:702bf7b2b7d8 589 int32_t os_ret;
dkato 0:702bf7b2b7d8 590
dkato 0:702bf7b2b7d8 591 if (NULL == p_info_ch)
dkato 0:702bf7b2b7d8 592 {
dkato 0:702bf7b2b7d8 593 ercd = EFAULT;
dkato 0:702bf7b2b7d8 594 }
dkato 0:702bf7b2b7d8 595 else
dkato 0:702bf7b2b7d8 596 {
dkato 0:702bf7b2b7d8 597 if (SSIF_CHSTS_OPEN != p_info_ch->ch_stat)
dkato 0:702bf7b2b7d8 598 {
dkato 0:702bf7b2b7d8 599 ercd = EFAULT;
dkato 0:702bf7b2b7d8 600 }
dkato 0:702bf7b2b7d8 601 else
dkato 0:702bf7b2b7d8 602 {
dkato 0:702bf7b2b7d8 603 /* ->MISRA 10.6 : This macro is defined by CMSIS-RTOS that can't be modified. */
dkato 0:702bf7b2b7d8 604 os_ret = osSemaphoreWait(p_info_ch->sem_access, osWaitForever);
dkato 0:702bf7b2b7d8 605 /* <-MISRA 10.6 */
dkato 0:702bf7b2b7d8 606
dkato 0:702bf7b2b7d8 607 if ((-1) == os_ret)
dkato 0:702bf7b2b7d8 608 {
dkato 0:702bf7b2b7d8 609 ercd = EFAULT;
dkato 0:702bf7b2b7d8 610 }
dkato 0:702bf7b2b7d8 611
dkato 0:702bf7b2b7d8 612 if (ESUCCESS == ercd)
dkato 0:702bf7b2b7d8 613 {
dkato 0:702bf7b2b7d8 614 switch (request)
dkato 0:702bf7b2b7d8 615 {
dkato 0:702bf7b2b7d8 616 case SSIF_CONFIG_CHANNEL:
dkato 0:702bf7b2b7d8 617 {
dkato 0:702bf7b2b7d8 618 if (NULL == p_buf)
dkato 0:702bf7b2b7d8 619 {
dkato 0:702bf7b2b7d8 620 ercd = EFAULT;
dkato 0:702bf7b2b7d8 621 }
dkato 0:702bf7b2b7d8 622 else
dkato 0:702bf7b2b7d8 623 {
dkato 0:702bf7b2b7d8 624 ssif_channel_cfg_t* const ch_info = (ssif_channel_cfg_t*)p_buf;
dkato 0:702bf7b2b7d8 625 ercd = SSIF_IOCTL_ConfigChannel(p_info_ch, ch_info);
dkato 0:702bf7b2b7d8 626 }
dkato 0:702bf7b2b7d8 627 break;
dkato 0:702bf7b2b7d8 628 }
dkato 0:702bf7b2b7d8 629
dkato 0:702bf7b2b7d8 630 case SSIF_GET_STATUS:
dkato 0:702bf7b2b7d8 631 {
dkato 0:702bf7b2b7d8 632 if (NULL == p_buf)
dkato 0:702bf7b2b7d8 633 {
dkato 0:702bf7b2b7d8 634 ercd = EFAULT;
dkato 0:702bf7b2b7d8 635 }
dkato 0:702bf7b2b7d8 636 else
dkato 0:702bf7b2b7d8 637 {
dkato 0:702bf7b2b7d8 638 ercd = SSIF_IOCTL_GetStatus(p_info_ch, (uint32_t*)p_buf);
dkato 0:702bf7b2b7d8 639 }
dkato 0:702bf7b2b7d8 640 break;
dkato 0:702bf7b2b7d8 641 }
dkato 0:702bf7b2b7d8 642
dkato 0:702bf7b2b7d8 643 default:
dkato 0:702bf7b2b7d8 644 {
dkato 0:702bf7b2b7d8 645 ercd = EINVAL;
dkato 0:702bf7b2b7d8 646 break;
dkato 0:702bf7b2b7d8 647 }
dkato 0:702bf7b2b7d8 648 } /* switch */
dkato 0:702bf7b2b7d8 649 }
dkato 0:702bf7b2b7d8 650 }
dkato 0:702bf7b2b7d8 651
dkato 0:702bf7b2b7d8 652 os_ercd = osSemaphoreRelease(p_info_ch->sem_access);
dkato 0:702bf7b2b7d8 653 if (osOK != os_ercd)
dkato 0:702bf7b2b7d8 654 {
dkato 0:702bf7b2b7d8 655 ercd = EFAULT;
dkato 0:702bf7b2b7d8 656 }
dkato 0:702bf7b2b7d8 657 }
dkato 0:702bf7b2b7d8 658
dkato 0:702bf7b2b7d8 659 if (ESUCCESS != ercd)
dkato 0:702bf7b2b7d8 660 {
dkato 0:702bf7b2b7d8 661 ret = EERROR; /* EERROR(-1) */
dkato 0:702bf7b2b7d8 662 }
dkato 0:702bf7b2b7d8 663 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 664
dkato 0:702bf7b2b7d8 665 return ret;
dkato 0:702bf7b2b7d8 666 }
dkato 0:702bf7b2b7d8 667
dkato 0:702bf7b2b7d8 668 /******************************************************************************
dkato 0:702bf7b2b7d8 669 * Function Name: R_SSIF_WriteAsync
dkato 0:702bf7b2b7d8 670 * @brief Enqueue asynchronous write request
dkato 0:702bf7b2b7d8 671 *
dkato 0:702bf7b2b7d8 672 * Description:<br>
dkato 0:702bf7b2b7d8 673 *
dkato 0:702bf7b2b7d8 674 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open
dkato 0:702bf7b2b7d8 675 * @param[in] p_aio :aio control block of write request
dkato 0:702bf7b2b7d8 676 * @param[in,out] p_errno :pointer of error code
dkato 0:702bf7b2b7d8 677 * @retval ESUCCESS :Success.
dkato 0:702bf7b2b7d8 678 * @retval EERROR :Failure.
dkato 0:702bf7b2b7d8 679 ******************************************************************************/
dkato 0:702bf7b2b7d8 680 static int_t R_SSIF_WriteAsync(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 681 {
dkato 0:702bf7b2b7d8 682 ssif_info_ch_t* const p_info_ch = p_fd;
dkato 0:702bf7b2b7d8 683 int_t ret = ESUCCESS;
dkato 0:702bf7b2b7d8 684 int_t ercd = ESUCCESS;
dkato 0:702bf7b2b7d8 685
dkato 0:702bf7b2b7d8 686 if ((NULL == p_info_ch) || (NULL == p_aio))
dkato 0:702bf7b2b7d8 687 {
dkato 0:702bf7b2b7d8 688 ercd = EFAULT;
dkato 0:702bf7b2b7d8 689 }
dkato 0:702bf7b2b7d8 690 else
dkato 0:702bf7b2b7d8 691 {
dkato 0:702bf7b2b7d8 692 if (((uint32_t)O_RDONLY) == ((uint32_t)p_info_ch->openflag & O_ACCMODE))
dkato 0:702bf7b2b7d8 693 {
dkato 0:702bf7b2b7d8 694 ercd = EACCES;
dkato 0:702bf7b2b7d8 695 }
dkato 0:702bf7b2b7d8 696 else if (0u == p_aio->aio_nbytes)
dkato 0:702bf7b2b7d8 697 {
dkato 0:702bf7b2b7d8 698 ercd = EINVAL;
dkato 0:702bf7b2b7d8 699 }
dkato 0:702bf7b2b7d8 700 else
dkato 0:702bf7b2b7d8 701 {
dkato 0:702bf7b2b7d8 702 p_aio->aio_return = SSIF_ASYNC_W;
dkato 0:702bf7b2b7d8 703 SSIF_PostAsyncIo(p_info_ch, p_aio);
dkato 0:702bf7b2b7d8 704 }
dkato 0:702bf7b2b7d8 705 }
dkato 0:702bf7b2b7d8 706
dkato 0:702bf7b2b7d8 707 if (ESUCCESS != ercd)
dkato 0:702bf7b2b7d8 708 {
dkato 0:702bf7b2b7d8 709 ret = EERROR; /* EERROR(-1) */
dkato 0:702bf7b2b7d8 710 }
dkato 0:702bf7b2b7d8 711 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 712
dkato 0:702bf7b2b7d8 713 return ret;
dkato 0:702bf7b2b7d8 714 }
dkato 0:702bf7b2b7d8 715
dkato 0:702bf7b2b7d8 716 /******************************************************************************
dkato 0:702bf7b2b7d8 717 * Function Name: R_SSIF_ReadAsync
dkato 0:702bf7b2b7d8 718 * @brief Enqueue asynchronous read request
dkato 0:702bf7b2b7d8 719 *
dkato 0:702bf7b2b7d8 720 * Description:<br>
dkato 0:702bf7b2b7d8 721 *
dkato 0:702bf7b2b7d8 722 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open
dkato 0:702bf7b2b7d8 723 * @param[in] p_aio :aio control block of read request
dkato 0:702bf7b2b7d8 724 * @param[in,out] p_errno :pointer of error code
dkato 0:702bf7b2b7d8 725 * @retval ESUCCESS :Success.
dkato 0:702bf7b2b7d8 726 * @retval EERROR :Failure.
dkato 0:702bf7b2b7d8 727 ******************************************************************************/
dkato 0:702bf7b2b7d8 728 static int_t R_SSIF_ReadAsync(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 729 {
dkato 0:702bf7b2b7d8 730 ssif_info_ch_t* const p_info_ch = p_fd;
dkato 0:702bf7b2b7d8 731 int_t ret = ESUCCESS;
dkato 0:702bf7b2b7d8 732 int_t ercd = ESUCCESS;
dkato 0:702bf7b2b7d8 733
dkato 0:702bf7b2b7d8 734 if ((NULL == p_info_ch) || (NULL == p_aio))
dkato 0:702bf7b2b7d8 735 {
dkato 0:702bf7b2b7d8 736 ercd = EFAULT;
dkato 0:702bf7b2b7d8 737 }
dkato 0:702bf7b2b7d8 738 else
dkato 0:702bf7b2b7d8 739 {
dkato 0:702bf7b2b7d8 740 if ((O_WRONLY == ((uint32_t)p_info_ch->openflag & O_ACCMODE))
dkato 0:702bf7b2b7d8 741 || (SSIF_CFG_ENABLE_ROMDEC_DIRECT
dkato 0:702bf7b2b7d8 742 == p_info_ch->romdec_direct.mode))
dkato 0:702bf7b2b7d8 743 {
dkato 0:702bf7b2b7d8 744 ercd = EACCES;
dkato 0:702bf7b2b7d8 745 }
dkato 0:702bf7b2b7d8 746 else if (0u == p_aio->aio_nbytes)
dkato 0:702bf7b2b7d8 747 {
dkato 0:702bf7b2b7d8 748 ercd = EINVAL;
dkato 0:702bf7b2b7d8 749 }
dkato 0:702bf7b2b7d8 750 else
dkato 0:702bf7b2b7d8 751 {
dkato 0:702bf7b2b7d8 752 p_aio->aio_return = SSIF_ASYNC_R;
dkato 0:702bf7b2b7d8 753 SSIF_PostAsyncIo(p_info_ch, p_aio);
dkato 0:702bf7b2b7d8 754 }
dkato 0:702bf7b2b7d8 755 }
dkato 0:702bf7b2b7d8 756
dkato 0:702bf7b2b7d8 757 if (ESUCCESS != ercd)
dkato 0:702bf7b2b7d8 758 {
dkato 0:702bf7b2b7d8 759 ret = EERROR; /* EERROR(-1) */
dkato 0:702bf7b2b7d8 760 }
dkato 0:702bf7b2b7d8 761 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 762
dkato 0:702bf7b2b7d8 763 return ret;
dkato 0:702bf7b2b7d8 764 }
dkato 0:702bf7b2b7d8 765
dkato 0:702bf7b2b7d8 766 /******************************************************************************
dkato 0:702bf7b2b7d8 767 * Function Name: R_SSIF_Cancel
dkato 0:702bf7b2b7d8 768 * @brief Cancel read or write request(s)
dkato 0:702bf7b2b7d8 769 *
dkato 0:702bf7b2b7d8 770 * Description:<br>
dkato 0:702bf7b2b7d8 771 *
dkato 0:702bf7b2b7d8 772 * @param[in,out] p_fd :channel handle which was returned by R_SSIF_Open
dkato 0:702bf7b2b7d8 773 * @param[in] p_aio :aio control block to cancel or NULL to cancel all.
dkato 0:702bf7b2b7d8 774 * @param[in,out] p_errno :pointer of error code
dkato 0:702bf7b2b7d8 775 * @retval ESUCCESS :Success.
dkato 0:702bf7b2b7d8 776 * @retval EERROR :Failure.
dkato 0:702bf7b2b7d8 777 ******************************************************************************/
dkato 0:702bf7b2b7d8 778 static int_t R_SSIF_Cancel(void* const p_fd, AIOCB* const p_aio, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 779 {
dkato 0:702bf7b2b7d8 780 ssif_info_ch_t* const p_info_ch = p_fd;
dkato 0:702bf7b2b7d8 781 int_t ret = ESUCCESS;
dkato 0:702bf7b2b7d8 782 int_t ercd = ESUCCESS;
dkato 0:702bf7b2b7d8 783 osStatus os_ercd;
dkato 0:702bf7b2b7d8 784 int32_t os_ret;
dkato 0:702bf7b2b7d8 785
dkato 0:702bf7b2b7d8 786 if (NULL == p_info_ch)
dkato 0:702bf7b2b7d8 787 {
dkato 0:702bf7b2b7d8 788 ercd = EFAULT;
dkato 0:702bf7b2b7d8 789 }
dkato 0:702bf7b2b7d8 790 else
dkato 0:702bf7b2b7d8 791 {
dkato 0:702bf7b2b7d8 792 /* ->MISRA 10.6 : This macro is defined by CMSIS-RTOS that can't be modified. */
dkato 0:702bf7b2b7d8 793 /* Get semaphore to access the channel data */
dkato 0:702bf7b2b7d8 794 os_ret = osSemaphoreWait(p_info_ch->sem_access, osWaitForever);
dkato 0:702bf7b2b7d8 795 /* <-MISRA 10.6 */
dkato 0:702bf7b2b7d8 796
dkato 0:702bf7b2b7d8 797 if ((-1) == os_ret)
dkato 0:702bf7b2b7d8 798 {
dkato 0:702bf7b2b7d8 799 ercd = EFAULT;
dkato 0:702bf7b2b7d8 800 }
dkato 0:702bf7b2b7d8 801 else
dkato 0:702bf7b2b7d8 802 {
dkato 0:702bf7b2b7d8 803 if (SSIF_CHSTS_OPEN != p_info_ch->ch_stat)
dkato 0:702bf7b2b7d8 804 {
dkato 0:702bf7b2b7d8 805 ercd = EFAULT;
dkato 0:702bf7b2b7d8 806 }
dkato 0:702bf7b2b7d8 807 else
dkato 0:702bf7b2b7d8 808 {
dkato 0:702bf7b2b7d8 809 SSIF_PostAsyncCancel(p_info_ch, p_aio);
dkato 0:702bf7b2b7d8 810 }
dkato 0:702bf7b2b7d8 811
dkato 0:702bf7b2b7d8 812 os_ercd = osSemaphoreRelease(p_info_ch->sem_access);
dkato 0:702bf7b2b7d8 813
dkato 0:702bf7b2b7d8 814 if (osOK != os_ercd)
dkato 0:702bf7b2b7d8 815 {
dkato 0:702bf7b2b7d8 816 ercd = EFAULT;
dkato 0:702bf7b2b7d8 817 }
dkato 0:702bf7b2b7d8 818 }
dkato 0:702bf7b2b7d8 819 }
dkato 0:702bf7b2b7d8 820
dkato 0:702bf7b2b7d8 821 if (ESUCCESS != ercd)
dkato 0:702bf7b2b7d8 822 {
dkato 0:702bf7b2b7d8 823 ret = EERROR; /* EERROR(-1) */
dkato 0:702bf7b2b7d8 824 }
dkato 0:702bf7b2b7d8 825 SSIF_SetErrCode(ercd, p_errno);
dkato 0:702bf7b2b7d8 826
dkato 0:702bf7b2b7d8 827 return ret;
dkato 0:702bf7b2b7d8 828 }
dkato 0:702bf7b2b7d8 829
dkato 0:702bf7b2b7d8 830 /******************************************************************************
dkato 0:702bf7b2b7d8 831 * Function Name: SSIF_StrnLen
dkato 0:702bf7b2b7d8 832 * @brief computes the length of the string
dkato 0:702bf7b2b7d8 833 *
dkato 0:702bf7b2b7d8 834 * Description:<br>
dkato 0:702bf7b2b7d8 835 *
dkato 0:702bf7b2b7d8 836 * @param[in] p_str :pointer of string.
dkato 0:702bf7b2b7d8 837 * @param[in] maxlen :maximum length of inspection
dkato 0:702bf7b2b7d8 838 * @retval < maxlen :number of characters in the string
dkato 0:702bf7b2b7d8 839 * @retval maxlen :string is longer than maxlen
dkato 0:702bf7b2b7d8 840 ******************************************************************************/
dkato 0:702bf7b2b7d8 841 static size_t SSIF_StrnLen(const char_t p_str[], const size_t maxlen)
dkato 0:702bf7b2b7d8 842 {
dkato 0:702bf7b2b7d8 843 size_t len;
dkato 0:702bf7b2b7d8 844
dkato 0:702bf7b2b7d8 845 if (NULL == p_str)
dkato 0:702bf7b2b7d8 846 {
dkato 0:702bf7b2b7d8 847 len = 0;
dkato 0:702bf7b2b7d8 848 }
dkato 0:702bf7b2b7d8 849 else
dkato 0:702bf7b2b7d8 850 {
dkato 0:702bf7b2b7d8 851 for (len = 0; len < maxlen; len++)
dkato 0:702bf7b2b7d8 852 {
dkato 0:702bf7b2b7d8 853 if ((int_t)p_str[len] == '\0')
dkato 0:702bf7b2b7d8 854 {
dkato 0:702bf7b2b7d8 855 break;
dkato 0:702bf7b2b7d8 856 }
dkato 0:702bf7b2b7d8 857 }
dkato 0:702bf7b2b7d8 858 }
dkato 0:702bf7b2b7d8 859
dkato 0:702bf7b2b7d8 860 return len;
dkato 0:702bf7b2b7d8 861 }
dkato 0:702bf7b2b7d8 862
dkato 0:702bf7b2b7d8 863 /******************************************************************************
dkato 0:702bf7b2b7d8 864 * Function Name: SSIF_Strncmp
dkato 0:702bf7b2b7d8 865 * @brief Compare two strings
dkato 0:702bf7b2b7d8 866 *
dkato 0:702bf7b2b7d8 867 * Description:<br>
dkato 0:702bf7b2b7d8 868 *
dkato 0:702bf7b2b7d8 869 * @param[in] p_str1 :pointer of string1
dkato 0:702bf7b2b7d8 870 * @param[in] p_str2 :pointer of string2
dkato 0:702bf7b2b7d8 871 * @param[in] maxlen :maximum length of comparison
dkato 0:702bf7b2b7d8 872 * @retval zero :strings are same.
dkato 0:702bf7b2b7d8 873 * @retval non zero :strings are different.
dkato 0:702bf7b2b7d8 874 ******************************************************************************/
dkato 0:702bf7b2b7d8 875 static int32_t SSIF_Strncmp(const char_t p_str1[], const char_t p_str2[], const uint32_t maxlen)
dkato 0:702bf7b2b7d8 876 {
dkato 0:702bf7b2b7d8 877 int32_t result = 0;
dkato 0:702bf7b2b7d8 878 uint32_t index;
dkato 0:702bf7b2b7d8 879
dkato 0:702bf7b2b7d8 880 if ((NULL == p_str1) || (NULL == p_str2))
dkato 0:702bf7b2b7d8 881 {
dkato 0:702bf7b2b7d8 882 result = -1;
dkato 0:702bf7b2b7d8 883 }
dkato 0:702bf7b2b7d8 884 else
dkato 0:702bf7b2b7d8 885 {
dkato 0:702bf7b2b7d8 886 for (index = 0; index < maxlen; index++)
dkato 0:702bf7b2b7d8 887 {
dkato 0:702bf7b2b7d8 888 /* compare charctor */
dkato 0:702bf7b2b7d8 889 result = ((int_t)p_str1[index]) - ((int_t)p_str2[index]);
dkato 0:702bf7b2b7d8 890 if ((result != 0)
dkato 0:702bf7b2b7d8 891 || ((int_t)p_str1[index] == '\0')
dkato 0:702bf7b2b7d8 892 || ((int_t)p_str2[index] == '\0'))
dkato 0:702bf7b2b7d8 893 {
dkato 0:702bf7b2b7d8 894 /* "charactor mismatch" or "end of string" */
dkato 0:702bf7b2b7d8 895 break;
dkato 0:702bf7b2b7d8 896 }
dkato 0:702bf7b2b7d8 897 }
dkato 0:702bf7b2b7d8 898 }
dkato 0:702bf7b2b7d8 899
dkato 0:702bf7b2b7d8 900 return result;
dkato 0:702bf7b2b7d8 901 }
dkato 0:702bf7b2b7d8 902
dkato 0:702bf7b2b7d8 903 /******************************************************************************
dkato 0:702bf7b2b7d8 904 * Function Name: SSIF_SetErrCode
dkato 0:702bf7b2b7d8 905 * @brief Set error code to error code pointer.
dkato 0:702bf7b2b7d8 906 *
dkato 0:702bf7b2b7d8 907 * Description:<br>
dkato 0:702bf7b2b7d8 908 * If error code pointer is NULL, do nothing.
dkato 0:702bf7b2b7d8 909 * @param[in] error_code :Error code.
dkato 0:702bf7b2b7d8 910 * @param[in,out] p_errno :Pointer of set error code.
dkato 0:702bf7b2b7d8 911 * @retval none
dkato 0:702bf7b2b7d8 912 ******************************************************************************/
dkato 0:702bf7b2b7d8 913 static void SSIF_SetErrCode(const int_t error_code, int32_t* const p_errno)
dkato 0:702bf7b2b7d8 914 {
dkato 0:702bf7b2b7d8 915 if (NULL != p_errno)
dkato 0:702bf7b2b7d8 916 {
dkato 0:702bf7b2b7d8 917 *p_errno = error_code;
dkato 0:702bf7b2b7d8 918 }
dkato 0:702bf7b2b7d8 919
dkato 0:702bf7b2b7d8 920 return;
dkato 0:702bf7b2b7d8 921 }
dkato 0:702bf7b2b7d8 922