test public

Dependencies:   HttpServer_snapshot_mbed-os

Committer:
anhtran
Date:
Fri Oct 18 03:09:43 2019 +0000
Revision:
0:e9fd5575b10e
abc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anhtran 0:e9fd5575b10e 1 /*******************************************************************************
anhtran 0:e9fd5575b10e 2 * DISCLAIMER
anhtran 0:e9fd5575b10e 3 * This software is supplied by Renesas Electronics Corporation and is only
anhtran 0:e9fd5575b10e 4 * intended for use with Renesas products. No other uses are authorized. This
anhtran 0:e9fd5575b10e 5 * software is owned by Renesas Electronics Corporation and is protected under
anhtran 0:e9fd5575b10e 6 * all applicable laws, including copyright laws.
anhtran 0:e9fd5575b10e 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
anhtran 0:e9fd5575b10e 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
anhtran 0:e9fd5575b10e 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
anhtran 0:e9fd5575b10e 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
anhtran 0:e9fd5575b10e 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
anhtran 0:e9fd5575b10e 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
anhtran 0:e9fd5575b10e 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
anhtran 0:e9fd5575b10e 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
anhtran 0:e9fd5575b10e 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
anhtran 0:e9fd5575b10e 16 * Renesas reserves the right, without notice, to make changes to this software
anhtran 0:e9fd5575b10e 17 * and to discontinue the availability of this software. By using this software,
anhtran 0:e9fd5575b10e 18 * you agree to the additional terms and conditions found by accessing the
anhtran 0:e9fd5575b10e 19 * following link:
anhtran 0:e9fd5575b10e 20 * http://www.renesas.com/disclaimer*
anhtran 0:e9fd5575b10e 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
anhtran 0:e9fd5575b10e 22 *******************************************************************************/
anhtran 0:e9fd5575b10e 23 /**************************************************************************//**
anhtran 0:e9fd5575b10e 24 * @file R_BSP_Aio.h
anhtran 0:e9fd5575b10e 25 * @brief R_BSP_Aio API
anhtran 0:e9fd5575b10e 26 ******************************************************************************/
anhtran 0:e9fd5575b10e 27
anhtran 0:e9fd5575b10e 28 #ifndef R_BSP_AIO_H
anhtran 0:e9fd5575b10e 29 #define R_BSP_AIO_H
anhtran 0:e9fd5575b10e 30
anhtran 0:e9fd5575b10e 31 #include <stdint.h>
anhtran 0:e9fd5575b10e 32 #include "rtos.h"
anhtran 0:e9fd5575b10e 33
anhtran 0:e9fd5575b10e 34 /** Callback function type
anhtran 0:e9fd5575b10e 35 *
anhtran 0:e9fd5575b10e 36 * @param p_data Location of the data.
anhtran 0:e9fd5575b10e 37 * @param result Number of bytes transmit on success. negative number on error.
anhtran 0:e9fd5575b10e 38 * @param p_app_data User definition data.
anhtran 0:e9fd5575b10e 39 */
anhtran 0:e9fd5575b10e 40 typedef void (*rbsp_notify_func_t)(void * p_data, int32_t result, void * p_app_data);
anhtran 0:e9fd5575b10e 41
anhtran 0:e9fd5575b10e 42 /** Asynchronous control block structure */
anhtran 0:e9fd5575b10e 43 typedef struct {
anhtran 0:e9fd5575b10e 44 rbsp_notify_func_t p_notify_func; /**< Callback function type. */
anhtran 0:e9fd5575b10e 45 void * p_app_data; /**< User definition data. */
anhtran 0:e9fd5575b10e 46 } rbsp_data_conf_t;
anhtran 0:e9fd5575b10e 47
anhtran 0:e9fd5575b10e 48 /**
anhtran 0:e9fd5575b10e 49 * A class to communicate a R_BSP_Aio
anhtran 0:e9fd5575b10e 50 */
anhtran 0:e9fd5575b10e 51 class R_BSP_Aio {
anhtran 0:e9fd5575b10e 52
anhtran 0:e9fd5575b10e 53 public:
anhtran 0:e9fd5575b10e 54
anhtran 0:e9fd5575b10e 55 /** Write count bytes to the file associated
anhtran 0:e9fd5575b10e 56 *
anhtran 0:e9fd5575b10e 57 * @param p_data Location of the data.
anhtran 0:e9fd5575b10e 58 * @param data_size Number of bytes to write.
anhtran 0:e9fd5575b10e 59 * @param p_data_conf Asynchronous control block structure.
anhtran 0:e9fd5575b10e 60 * @return Number of bytes written on success. negative number on error.
anhtran 0:e9fd5575b10e 61 */
anhtran 0:e9fd5575b10e 62 int32_t write(void * const p_data, uint32_t data_size, const rbsp_data_conf_t * const p_data_conf = NULL);
anhtran 0:e9fd5575b10e 63
anhtran 0:e9fd5575b10e 64 /** Read count bytes to the file associated
anhtran 0:e9fd5575b10e 65 *
anhtran 0:e9fd5575b10e 66 * @param p_data Location of the data.
anhtran 0:e9fd5575b10e 67 * @param data_size Number of bytes to read.
anhtran 0:e9fd5575b10e 68 * @param p_data_conf Asynchronous control block structure.
anhtran 0:e9fd5575b10e 69 * @return Number of bytes read on success. negative number on error.
anhtran 0:e9fd5575b10e 70 */
anhtran 0:e9fd5575b10e 71 int32_t read(void * const p_data, uint32_t data_size, const rbsp_data_conf_t * const p_data_conf = NULL);
anhtran 0:e9fd5575b10e 72
anhtran 0:e9fd5575b10e 73 protected:
anhtran 0:e9fd5575b10e 74
anhtran 0:e9fd5575b10e 75 /** Constructor
anhtran 0:e9fd5575b10e 76 *
anhtran 0:e9fd5575b10e 77 */
anhtran 0:e9fd5575b10e 78 R_BSP_Aio();
anhtran 0:e9fd5575b10e 79
anhtran 0:e9fd5575b10e 80 /** Destructor
anhtran 0:e9fd5575b10e 81 *
anhtran 0:e9fd5575b10e 82 */
anhtran 0:e9fd5575b10e 83 virtual ~R_BSP_Aio();
anhtran 0:e9fd5575b10e 84
anhtran 0:e9fd5575b10e 85 /** Write init
anhtran 0:e9fd5575b10e 86 *
anhtran 0:e9fd5575b10e 87 * @param handle channel handle.
anhtran 0:e9fd5575b10e 88 * @param p_func_a Pointer of write function.
anhtran 0:e9fd5575b10e 89 * @param max_buff_num The upper limit of write buffer.
anhtran 0:e9fd5575b10e 90 */
anhtran 0:e9fd5575b10e 91 void write_init(void * handle, void * p_func_a, int32_t max_buff_num = 16) {
anhtran 0:e9fd5575b10e 92 init(&write_ctl, handle, p_func_a, max_buff_num);
anhtran 0:e9fd5575b10e 93 };
anhtran 0:e9fd5575b10e 94
anhtran 0:e9fd5575b10e 95 /** Read init
anhtran 0:e9fd5575b10e 96 *
anhtran 0:e9fd5575b10e 97 * @param handle channel handle.
anhtran 0:e9fd5575b10e 98 * @param p_func_a Pointer of read function.
anhtran 0:e9fd5575b10e 99 * @param max_buff_num The upper limit of read buffer.
anhtran 0:e9fd5575b10e 100 */
anhtran 0:e9fd5575b10e 101 void read_init(void * handle, void * p_func_a, int32_t max_buff_num = 16) {
anhtran 0:e9fd5575b10e 102 init(&read_ctl, handle, p_func_a, max_buff_num);
anhtran 0:e9fd5575b10e 103 };
anhtran 0:e9fd5575b10e 104 private:
anhtran 0:e9fd5575b10e 105 typedef struct {
anhtran 0:e9fd5575b10e 106 rbsp_notify_func_t p_cb_func;
anhtran 0:e9fd5575b10e 107 void * p_cb_data;
anhtran 0:e9fd5575b10e 108 Semaphore * p_sem;
anhtran 0:e9fd5575b10e 109 void * p_aio;
anhtran 0:e9fd5575b10e 110 } rbsp_sival_t;
anhtran 0:e9fd5575b10e 111
anhtran 0:e9fd5575b10e 112 typedef struct {
anhtran 0:e9fd5575b10e 113 void * ch_handle;
anhtran 0:e9fd5575b10e 114 void * p_async_func;
anhtran 0:e9fd5575b10e 115 void * p_aio_top;
anhtran 0:e9fd5575b10e 116 int32_t index;
anhtran 0:e9fd5575b10e 117 rbsp_sival_t * p_sival_top;
anhtran 0:e9fd5575b10e 118 Semaphore * p_sem_ctl;
anhtran 0:e9fd5575b10e 119 int32_t MaxNum;
anhtran 0:e9fd5575b10e 120 } rbsp_serial_ctl_t;
anhtran 0:e9fd5575b10e 121
anhtran 0:e9fd5575b10e 122 typedef struct {
anhtran 0:e9fd5575b10e 123 Semaphore * p_sem;
anhtran 0:e9fd5575b10e 124 int32_t result;
anhtran 0:e9fd5575b10e 125 } rbsp_sync_t;
anhtran 0:e9fd5575b10e 126
anhtran 0:e9fd5575b10e 127 void init(rbsp_serial_ctl_t * p_ctl, void * handle, void * p_func_a, int32_t max_buff_num);
anhtran 0:e9fd5575b10e 128 static int32_t sync_trans(rbsp_serial_ctl_t * p_ctl, void * const p_data, uint32_t data_size);
anhtran 0:e9fd5575b10e 129 static void callback_sync_trans(void * p_data, int32_t result, void * p_app_data);
anhtran 0:e9fd5575b10e 130 static int32_t aio_trans(rbsp_serial_ctl_t * const p_ctl, void * const p_data, uint32_t data_size,
anhtran 0:e9fd5575b10e 131 const rbsp_data_conf_t * const p_data_conf);
anhtran 0:e9fd5575b10e 132 static void callback_aio_trans(union sigval signo);
anhtran 0:e9fd5575b10e 133
anhtran 0:e9fd5575b10e 134 rbsp_serial_ctl_t write_ctl;
anhtran 0:e9fd5575b10e 135 rbsp_serial_ctl_t read_ctl;
anhtran 0:e9fd5575b10e 136 };
anhtran 0:e9fd5575b10e 137 #endif