1 /*********************************************************************************
\r
3 * --------------------------------------------------------------------------------
\r
5 * This file is part of MiMic
\r
6 * Copyright (C)2011 Ryo Iizuka
\r
8 * MiMic is free software: you can redistribute it and/or modify
\r
9 * it under the terms of the GNU Lesser General Public License as published
\r
10 * by the Free Software Foundation, either version 3 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU Lesser General Public License
\r
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
21 * For further information please contact.
\r
23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
25 *********************************************************************************/
\r
28 * このファイルは、ルートモジュールにあるヘッダファイルを集積します。
\r
31 #ifndef NyLPC_stdlib_h
\r
32 #define NyLPC_stdlib_h
\r
33 #include "NyLPC_config.h"
\r
39 #endif /* __cplusplus */
\r
41 /**********************************************************************
\r
45 **********************************************************************/
\r
48 * 引数チェック専用のASSERT構文です。
\r
51 #define NyLPC_ArgAssert(e) if(!(e)){NyLPC_assertHook(NULL,-1);};
\r
57 #define NyLPC_Assert(e) if(!(e)){NyLPC_assertHook(NULL,-1);};
\r
63 #define NyAR_DebugHook() {NyLPC_debugHook(__FILE__,__LINE__);};
\r
66 * Abortマクロです。プログラムを異常終了するときのエントリポイントになります。
\r
67 * デバック時/リリース時のどちらでも有効です。
\r
69 #define NyLPC_Abort() {NyLPC_abortHook(__FILE__,__LINE__);}; //もうだめ
\r
72 * Abortマクロです。eが偽の時に、異常終了します。
\r
73 * デバック時/リリース時のどちらでも有効です。
\r
77 #define NyLPC_AbortIfNot(e) if(!(e)){NyLPC_abortHook(__FILE__,__LINE__);};
\r
80 * 警告表示用のマクロです。デバックに使います。
\r
83 #define NyLPC_Warning() {NyLPC_debugHook(__FILE__,__LINE__);};
\r
86 * 警告表示用のマクロです。eが偽の時に、警告を出します。
\r
91 #define NyLPC_WarningIfNot(e) if(!(e)){NyLPC_debugHook(__FILE__,__LINE__);};
\r
94 * トレースマクロです。デバックに使います。
\r
95 * 内部変数に、最後にコールされたファイル名と、行番号を保存します。
\r
98 #define NyLPC_Trace() {NyLPC_debugHook(__FILE__,__LINE__);};
\r
107 void NyLPC_assertHook(const char* m,int l);
\r
115 void NyLPC_abortHook(const char* m,int l);
\r
123 void NyLPC_debugHook(const char* m,int l);
\r
127 * アサートを検出した回数を保存します。
\r
129 extern unsigned int NyLPC_assert_counter;
\r
132 * アサートを検出した回数を保存します。
\r
134 extern unsigned int NyLPC_abort_counter;
\r
137 * アサートを検出した回数を保存します。
\r
139 extern unsigned int NyLPC_debug_counter;
\r
142 * GOTO方式のエラーハンドラを記述するためのマクロです。
\r
146 #define NyLPC_OnErrorGoto(l) goto l
\r
150 /**********************************************************************
\r
154 **********************************************************************/
\r
159 typedef long NyLPC_TBool;
\r
162 * TRUEを表します。この値は、ifで評価したときに真を返すことを保障します。
\r
164 #define NyLPC_TBool_TRUE (0==0)
\r
166 * FALSEを表します。この値は、ifで評価したときに偽を返すことを保障します。
\r
168 #define NyLPC_TBool_FALSE (0!=0)
\r
171 * ウェーイを表します。この値は、NyLPC_TBool_FALSEと同じです。
\r
173 #define NyLPC_TBool_VEII NyLPC_TBool_FALSE
\r
180 typedef char NyLPC_TChar;
\r
184 typedef char NyLPC_TInt8;
\r
188 typedef short NyLPC_TInt16;
\r
192 typedef long NyLPC_TInt32;
\r
194 //----------------------------------------------------------------------
\r
196 //----------------------------------------------------------------------
\r
201 typedef unsigned char NyLPC_TUInt8;
\r
204 * ビット操作関数です。bfのビット番号bに、1をセットします。
\r
210 #define NyLPC_TUInt8_setBit(bf,b) NyLPC_TUInt32_setBit(bf,b)
\r
212 * ビット操作関数です。bfのビット番号bに、0をセットします。
\r
218 #define NyLPC_TUInt8_unsetBit(bf,b) NyLPC_TUInt32_unsetBit(bf,b)
\r
220 * ビット判定関数です。bfのビット番号bが1であるかを確認します。
\r
228 #define NyLPC_TUInt8_isBitOn(bf,b) NyLPC_TUInt32_isBitOn(bf,b)
\r
233 #define NyLPC_TUInt8_TRUE NyLPC_TBool_TRUE
\r
237 #define NyLPC_TUInt8_FALSE NyLPC_TBool_FALSE
\r
239 * 8bit長のFALSEをNyLPC_TBoolへ変換します。
\r
245 #define NyLPC_TUInt8_castto_TBool(a) ((a)?NyLPC_TBool_TRUE:NyLPC_TBool_FALSE)
\r
247 //----------------------------------------------------------------------
\r
249 //----------------------------------------------------------------------
\r
254 typedef unsigned short NyLPC_TUInt16;
\r
259 #define NyLPC_TUInt16_MAX 0xFFFF
\r
262 * ビット操作関数です。bfのビット番号bに、1をセットします。
\r
268 #define NyLPC_TUInt16_setBit(bf,b) NyLPC_TUInt32_setBit(bf,b)
\r
270 * ビット操作関数です。bfのビット番号bに、0をセットします。
\r
276 #define NyLPC_TUInt16_unsetBit(bf,b) NyLPC_TUInt32_unsetBit(bf,b)
\r
278 * ビット判定関数です。bfのビット番号bが1であるかを確認します。
\r
286 #define NyLPC_TUInt16_isBitOn(bf,b) NyLPC_TUInt32_isBitOn(bf,b)
\r
293 * 入れ替えた16ビット値を返します。
\r
296 #define NyLPC_TUInt16_BSWAP(n) (((((NyLPC_TUInt16)(n))<< 8)&0xff00)|((((NyLPC_TUInt16)(n))>> 8)&0x00ff))
\r
302 * NyLPC_TUInt16_BSWAPとの違いは、関数であることです。
\r
306 * 入れ替えた16ビット値を返します。
\r
308 NyLPC_TUInt16 NyLPC_TUInt16_bswap(NyLPC_TUInt16 n);
\r
312 #define NyLPC_TUInt16_TRUE NyLPC_TBool_TRUE
\r
316 #define NyLPC_TUInt16_FALSE NyLPC_TBool_FALSE
\r
318 * 16bit長のFALSEをNyLPC_TBoolへ変換します。
\r
324 #define NyLPC_TUInt16_castto_TBool(a) ((a)?NyLPC_TBool_TRUE:NyLPC_TBool_FALSE)
\r
326 //----------------------------------------------------------------------
\r
331 typedef unsigned long NyLPC_TUInt32;
\r
333 * ビット操作関数です。bfのビットパターンbに、1をセットします。
\r
339 #define NyLPC_TUInt32_setBit(bf,b) bf=(bf|b)
\r
341 * ビット操作関数です。bfのビットパターンbに、0をセットします。
\r
347 #define NyLPC_TUInt32_unsetBit(bf,b) bf=(bf&(~b))
\r
349 * ビット判定関数です。bfのビットパターンbが1であるかを確認します。
\r
357 #define NyLPC_TUInt32_isBitOn(bf,b) ((bf&b)==(b))
\r
364 * 入れ替えた32ビット値を返します。
\r
367 #define NyLPC_TUInt32_BSWAP(n) (((((NyLPC_TUInt32)(n))<<24)&0xff000000)|((((NyLPC_TUInt32)(n))<< 8)&0x00ff0000)|((((NyLPC_TUInt32)(n))>> 8)&0x0000ff00)|((((NyLPC_TUInt32)(n))>>24)&0x000000ff))
\r
370 * NyLPC_TUInt32_BSWAPとの違いは、関数であることです。
\r
374 * 入れ替えた32ビット値を返します。
\r
376 NyLPC_TUInt32 NyLPC_TUInt32_bswap(NyLPC_TUInt32 n);
\r
381 #define NyLPC_TUInt32_TRUE NyLPC_TBool_TRUE
\r
385 #define NyLPC_TUInt32_FALSE NyLPC_TBool_FALSE
\r
387 * 32bit長のFALSEをNyLPC_TBoolへ変換します。
\r
393 #define NyLPC_TUInt32_castto_TBool(a) ((a)?NyLPC_TBool_TRUE:NyLPC_TBool_FALSE)
\r
396 //----------------------------------------------------------------------
\r
399 * 長さ付TChar配列の構造体です。
\r
402 struct NyLPC_TCharArrayPtr
\r
410 * ptrの位置をi_seekだけ進行します。
\r
416 NyLPC_TBool NyLPC_TCharArrayPtr_seek(struct NyLPC_TCharArrayPtr* i_struct,NyLPC_TUInt16 i_seek);
\r
420 * 長さ付TUInt32配列の構造体です。
\r
423 struct NyLPC_TUInt32ArrayPtr
\r
426 NyLPC_TUInt32* ptr;
\r
431 * ptrの位置をi_seekだけ進行します。
\r
432 * 進行すると、len要素がi_seekだけ減少します。
\r
438 NyLPC_TBool NyLPC_TUInt32ArrayPtr_seek(struct NyLPC_TUInt32ArrayPtr* i_struct,NyLPC_TUInt16 i_seek);
\r
440 * 構造体に、参照するバッファの初期位置とサイズをセットします。
\r
441 * セットしたバッファは、前方シークの可能な書き込みバッファとして使用できます。
\r
443 void NyLPC_TUInt32ArrayPtr_setBuf(struct NyLPC_TUInt32ArrayPtr* i_struct,NyLPC_TUInt32* i_ptr,NyLPC_TUInt16 i_len);
\r
449 struct NyLPC_TTextIdTbl{
\r
455 * テーブルを検索してマッチしたIDを返します。テーブルのnがNULLの要素で愁嘆します。
\r
457 NyLPC_TUInt8 NyLPC_TTextIdTbl_getMatchId(const NyLPC_TChar* i_str,const struct NyLPC_TTextIdTbl i_tbl[]);
\r
459 /*********************************************************************************
\r
460 * standard function
\r
461 *********************************************************************************/
\r
462 void NyLPC_itoa(int i_n,char* o_out,int i_digit);
\r
463 void NyLPC_reverse(char* s);
\r
470 #endif /* __cplusplus */
\r
474 /*********************************************************************************
\r
476 *********************************************************************************/
\r
478 #include "../NyLPC_cMiMicEnv.h"
\r
479 #include "../NyLPC_cRingBuffer.h"
\r
480 #include "../NyLPC_cPtrTbl.h"
\r
481 #include "../NyLPC_cFifoBuffer.h"
\r
482 #include "../NyLPC_cPtrStream.h"
\r
483 #include "../NyLPC_cStr.h"
\r
486 #include "../os/NyLPC_cStopwatch.h"
\r
487 #include "../os/NyLPC_cMutex.h"
\r
488 #include "../os/NyLPC_cThread.h"
\r
489 #include "../os/NyLPC_cSemaphore.h"
\r
490 #include "../os/NyLPC_cIsr.h"
\r