Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
NyLPC_cFifoBuffer.h
00001 /********************************************************************************* 00002 * PROJECT: MiMic 00003 * -------------------------------------------------------------------------------- 00004 * 00005 * This file is part of MiMic 00006 * Copyright (C)2011 Ryo Iizuka 00007 * 00008 * MiMic is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published 00010 * by the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 * For further information please contact. 00022 * http://nyatla.jp/ 00023 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp> 00024 * 00025 *********************************************************************************/ 00026 /** 00027 * @file 00028 * このファイルは、NyLPC_cFifoBufferクラスを定義します。 00029 */ 00030 #ifndef NyLPC_TcFifoBuffer_H 00031 #define NyLPC_TcFifoBuffer_H 00032 00033 #include "NyLPC_stdlib.h" 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif /* __cplusplus */ 00038 00039 /** 00040 * クラス型を定義します。 00041 * NyLPC_cFifoBufferクラスは、固定長のメモリを、最大bit長のFIFOメモリーとして扱うためのラップクラスです。 00042 */ 00043 typedef struct NyLPC_TcFifoBuffer NyLPC_TcFifoBuffer_t; 00044 00045 /** 00046 * NyLPC_TcFifoBufferクラスの構造体です。 00047 */ 00048 struct NyLPC_TcFifoBuffer 00049 { 00050 /** 配列の最大サイズ*/ 00051 NyLPC_TUInt16 size; 00052 /** 配列の現在の長さ*/ 00053 NyLPC_TUInt16 len; 00054 /** バッファ領域*/ 00055 void* buf; 00056 }; 00057 00058 /** 00059 * コンストラクタです。 00060 * i_instを、i_bufをラップするインスタンスとして初期化します。 00061 * i_bufは、finalizeを呼び出すまで、クラスが参照します。 00062 * インスタンスを削除するまでの間、維持してください。 00063 * @param i_inst 00064 * 初期化するメモリブロックのアドレス。 00065 * @param i_buf 00066 * ラップするメモリブロックのアドレス 00067 * @param i_buf_size 00068 * i_bufのサイズ。 00069 */ 00070 void NyLPC_cFifoBuffer_initialize(NyLPC_TcFifoBuffer_t* i_inst,void* i_buf,NyLPC_TUInt16 i_buf_size); 00071 00072 /** 00073 * デストラクタです。 00074 * インスタンスの確保しているリソースを開放します。 00075 * @param i_inst 00076 * 開放するインスタンスのポインタ 00077 */ 00078 #define NyLPC_cFifoBuffer_finalize(i_inst) 00079 00080 /** 00081 * この関数は、FIFOバッファの有効データ長を0にしてリセットします。 00082 * @param i_inst 00083 * 操作するインスタンスのポインタ 00084 */ 00085 #define NyLPC_cFifoBuffer_clear(i_inst) (i_inst)->len=0; 00086 00087 /** 00088 * この関数は、バッファの後方にデータをコピーして追記します。 00089 * 十分なサイズがない場合、ASSERTします。 00090 * 書込み可能な最大サイズは、getSpace関数で得ることが出来ます。 00091 * @param i_inst 00092 * 操作するインスタンスのポインタ 00093 * @param i_data 00094 * 追記するデータ。 00095 * @param i_data_len 00096 * 追記するデータのサイズ 00097 * 00098 */ 00099 void NyLPC_cFifoBuffer_push(NyLPC_TcFifoBuffer_t* i_inst,const void* i_data,NyLPC_TUInt16 i_data_len); 00100 /** 00101 * 先にメモリ領域を確保して、そのアドレスを返します。 00102 */ 00103 void* NyLPC_cFifoBuffer_prePush(NyLPC_TcFifoBuffer_t* i_inst,NyLPC_TUInt16 i_data_len); 00104 00105 00106 /** 00107 * この関数は、バッファの先頭からデータを削除します。 00108 * 十分なデータがない場合、ASSERTします。 00109 * この関数は、戻り値を返しません。getPtrで得たポインタからデータを読み込んだ後に、読み込んだデータをバッファから削除するために使います。 00110 * @param i_inst 00111 * 操作するインスタンスのポインタ 00112 * @param i_data 00113 * 削除するデータのサイズ。getLengthの戻り値以下である必要があります。 00114 */ 00115 void NyLPC_cFifoBuffer_pop(NyLPC_TcFifoBuffer_t* i_inst,NyLPC_TUInt16 i_len); 00116 00117 /** 00118 * バッファの先頭ポインタを得ます。 00119 * @param i_inst 00120 * 操作するインスタンスのポインタ 00121 * @return 00122 * バッファの先頭ポインタを返します。値は、次回にpush/popをするまでの間有効です。 00123 */ 00124 void* NyLPC_cFifoBuffer_getPtr(const NyLPC_TcFifoBuffer_t* i_inst); 00125 00126 /** 00127 * 格納しているデータの長さを返します。 00128 * getPtrで得たポインタから読み出せるデータのサイズに相当します。 00129 * @param i_inst 00130 * 操作するインスタンスのポインタ 00131 * @return 00132 * 読み出せるデータの長さです。 00133 */ 00134 NyLPC_TUInt16 NyLPC_cFifoBuffer_getLength(const NyLPC_TcFifoBuffer_t* i_inst); 00135 00136 /** 00137 * バッファの残量を計算して返します。 00138 * この値は、push関数で追記できるデータサイズと同じです。 00139 * @param i_inst 00140 * 操作するインスタンスのポインタ 00141 * @return 00142 * バッファの空き領域のサイズです。 00143 */ 00144 NyLPC_TUInt16 NyLPC_cFifoBuffer_getSpace(const NyLPC_TcFifoBuffer_t* i_inst); 00145 00146 #ifdef __cplusplus 00147 } 00148 #endif /* __cplusplus */ 00149 00150 #endif
Generated on Tue Jul 12 2022 16:22:57 by
1.7.2
