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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers R_BSP_SerialFamily.cpp Source File

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 
00053     if ((channel >= 0) && (channel <= 9) && (function_list != NULL)) {
00054         ch_no     = channel;
00055         functions = function_list;
00056 
00057         if ((functions->initialise_one != NULL) && (functions->open != NULL)) {
00058             R_BSP_CMN_Init();
00059             instance = functions->initialise_one(ch_no, config_data, &wk_errno);
00060             if ((int32_t)instance != EERROR) {
00061                 path_name[PATH_TOP_PART]  = PATH_SEPARATOR;
00062                 path_name[CH_ID_PART]     = CHARACTER_0 + ch_no;
00063                 path_name[TERM_CHAR_PART] = '\0';
00064                 ch_handle = (void *)functions->open(instance, path_name, O_RDWR, 0, &wk_errno);
00065                 if ((int32_t)ch_handle != EERROR) {
00066                     if (functions->write_a != NULL) {
00067                         write_init(ch_handle, (void *)functions->write_a, max_write_num);
00068                     }
00069                     if (functions->read_a != NULL) {
00070                         read_init(ch_handle, (void *)functions->read_a, max_read_num);
00071                     }
00072                     ret = true;
00073                 } else {
00074                     (void)((RBSP_MBED_FNS *)functions)->uninitialise_one(ch_no, instance, NULL);
00075                 }
00076             }
00077         }
00078     }
00079 
00080     if (ret == false) {
00081         functions = NULL;
00082         instance  = NULL;
00083         ch_handle = NULL;
00084         ch_no     = -1;
00085     }
00086 
00087     return ret;
00088 }
00089 
00090 bool R_BSP_SerialFamily::ioctl(int request, ...) {
00091     bool    ret = true;
00092     int32_t wk_errno;
00093     void *buf;
00094     va_list ap;
00095 
00096     if (functions == NULL) {
00097         ret = false;
00098     } else if (functions->ioctl == NULL) {
00099         ret = false;
00100     } else {
00101         va_start(ap, request);
00102         buf = (void *)va_arg(ap, void*);
00103         functions->ioctl(ch_handle, request, buf, &wk_errno);
00104         va_end(ap);
00105         if (wk_errno != ESUCCESS) {
00106             ret = false;
00107         }
00108     }
00109 
00110     return ret;
00111 }