test public
Dependencies: HttpServer_snapshot_mbed-os
R_BSP_SerialFamily.cpp
00001 /******************************************************************************* 00002 * DISCLAIMER 00003 * This software is supplied by Renesas Electronics Corporation and is only 00004 * intended for use with Renesas products. No other uses are authorized. This 00005 * software is owned by Renesas Electronics Corporation and is protected under 00006 * all applicable laws, including copyright laws. 00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING 00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT 00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. 00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS 00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE 00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR 00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE 00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 00016 * Renesas reserves the right, without notice, to make changes to this software 00017 * and to discontinue the availability of this software. By using this software, 00018 * you agree to the additional terms and conditions found by accessing the 00019 * following link: 00020 * http://www.renesas.com/disclaimer* 00021 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved. 00022 *******************************************************************************/ 00023 00024 #include "r_bsp_cmn.h" 00025 #include "R_BSP_SerialFamily.h" 00026 #include "posix_types.h" 00027 #include "r_errno.h" 00028 00029 #define PATH_NAME_LENGTH (3) /* Path name length */ 00030 #define PATH_TOP_PART (0) /* Path top part */ 00031 #define CH_ID_PART (1) /* Channel identifier part */ 00032 #define TERM_CHAR_PART (2) /* Termination character part */ 00033 #define PATH_SEPARATOR ('\\') /* Path separator */ 00034 #define CHARACTER_0 (0x30) /* character 0 */ 00035 00036 R_BSP_SerialFamily::~R_BSP_SerialFamily() { 00037 if (functions != NULL) { 00038 if ((ch_handle != NULL) && (functions->close != NULL)) { 00039 (void)functions->close(ch_handle, NULL); 00040 } 00041 if ((ch_no != -1) && (instance != NULL) && (functions->uninitialise_one != NULL)) { 00042 (void)functions->uninitialise_one(ch_no, instance, NULL); 00043 } 00044 } 00045 } 00046 00047 bool R_BSP_SerialFamily::init_channel(RBSP_MBED_FNS * function_list, int channel, void * const config_data, 00048 int32_t max_write_num, int32_t max_read_num) { 00049 bool ret = false; 00050 int32_t wk_errno; 00051 char_t path_name[PATH_NAME_LENGTH]; 00052 int_t flags; 00053 00054 if ((max_write_num > 0) && (max_read_num > 0)) { 00055 flags = O_RDWR_RBSP; 00056 } else if (max_write_num > 0) { 00057 flags = O_WRONLY_RBSP; 00058 } else if (max_read_num > 0) { 00059 flags = O_RDONLY_RBSP; 00060 } else { 00061 flags = 0; 00062 } 00063 00064 if ((channel >= 0) && (channel <= 9) && (function_list != NULL) && (flags != 0)) { 00065 ch_no = channel; 00066 functions = function_list; 00067 00068 if ((functions->initialise_one != NULL) && (functions->open != NULL)) { 00069 R_BSP_CMN_Init(); 00070 instance = functions->initialise_one(ch_no, config_data, &wk_errno); 00071 if ((int32_t)instance != EERROR) { 00072 path_name[PATH_TOP_PART] = PATH_SEPARATOR; 00073 path_name[CH_ID_PART] = CHARACTER_0 + ch_no; 00074 path_name[TERM_CHAR_PART] = '\0'; 00075 ch_handle = (void *)functions->open(instance, path_name, flags, 0, &wk_errno); 00076 if ((int32_t)ch_handle != EERROR) { 00077 if (functions->write_a != NULL) { 00078 write_init(ch_handle, (void *)functions->write_a, max_write_num); 00079 } 00080 if (functions->read_a != NULL) { 00081 read_init(ch_handle, (void *)functions->read_a, max_read_num); 00082 } 00083 ret = true; 00084 } else { 00085 (void)((RBSP_MBED_FNS *)functions)->uninitialise_one(ch_no, instance, NULL); 00086 } 00087 } 00088 } 00089 } 00090 00091 if (ret == false) { 00092 functions = NULL; 00093 instance = NULL; 00094 ch_handle = NULL; 00095 ch_no = -1; 00096 } 00097 00098 return ret; 00099 } 00100 00101 bool R_BSP_SerialFamily::ioctl(int request, ...) { 00102 bool ret = true; 00103 int32_t wk_errno; 00104 void *buf; 00105 va_list ap; 00106 00107 if (functions == NULL) { 00108 ret = false; 00109 } else if (functions->ioctl == NULL) { 00110 ret = false; 00111 } else { 00112 va_start(ap, request); 00113 buf = (void *)va_arg(ap, void*); 00114 functions->ioctl(ch_handle, request, buf, &wk_errno); 00115 va_end(ap); 00116 if (wk_errno != ESUCCESS) { 00117 ret = false; 00118 } 00119 } 00120 00121 return ret; 00122 }
Generated on Wed Jul 13 2022 05:33:36 by 1.7.2