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:
Tue May 31 01:45:35 2016 +0000
Revision:
11:fb9eda52224e
Parent:
8:cbb9d60c8748
"inline" of the ssif_init function is removed.

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