BIGSTACK.H
[目次 | 型・クラス・構造体 | マクロ]
1|/**************************************************************************
2|* 1. <<< 大きいスタック (BigStack) >>>
3|***************************************************************************/
4|
5|#ifndef __BIGSTACK_H
6|#define __BIGSTACK_H
7|
8|#ifdef count
9|#undef count
10|#endif
11|#ifdef sp
12|#undef sp
13|#endif
14|
15|
16|/**************************************************************************
17|* 2. <<< コンポーネント・プロパティ >>>
18|***************************************************************************/
19|
20|/*----------------------------------------------------------------------
21|[Module Property]
22|name = BigStack
23|title = 大きいスタック
24|category = コンテナ
25|src = bigstack.c
26|depend =
27|priority = StdLibs
28|accord =
29|----------------------------------------------------------------------*/
30|
31|
32|
33|/**************************************************************************
34|* 3. <<< モジュール設定 >>>
35|***************************************************************************/
36|
37|#ifndef BIGSTACK_SETTING
38|#define BIGSTACK_SETTING
39| #define BIGSTACK_CHKSIZE /* 最大使用サイズを計測する */
40|#endif
41|
42|
43|
44|/*************************************************************************
45|* 4. <<< 優先ヘッダ >>>
46|**************************************************************************/
47|#ifndef USES_PRIORITY_HEADER
48|/*[START_OF_PRIORITY_HEADER]*/
49|
50|#define USES_BIGSTACK
51|#define STDLIBS_INCLUDE_STDDEF_H
52|#ifndef BIGSTACK_TYPEDEF
53|#define BIGSTACK_TYPEDEF
54|typedef struct _BigStack BigStack;
55|#endif
56|
57|/*[END_OF_PRIORITY_HEADER]*/
58|#endif
59|
60|
61|#define BigStack_Full (281) /* [ComponeGID:Errors_code] */
62|#define BigStack_badStartEnd (282) /* [ComponeGID:Errors_code] */
63|
64|
65|
66|/*--------------------------------------------------------------*/
67|/*5. <<< Interface Area -------------------------------------- >>> */
68|/*--------------------------------------------------------------*/
69|
70|#ifdef __cplusplus
71|extern "C" {
72|#endif
73|
74|
75|/**************************************************************************
76|* 6. <<< [BigStack_Sys] ビッグスタック・システム >>>
77|*【補足】
78|*・マルチタスク環境では、スタートアップ・タスクが BigStack_Sys_init を
79|* 呼び出す必要があります。
80|***************************************************************************/
81|#ifdef USES_MULTASK
82|
83|extern BigStack* BigStack_Sys_arr; /* 配列 */
84|extern int BigStack_Sys_mArr;
85|
86|void BigStack_Sys_init( BigStack* works, int mWork );
87|
88|#endif
89|
90|extern BigStack BigStack_Sys_arrX;
91|
92|/**************************************************************************
93|* 7. <<< [BigStack] ビッグスタック領域 >>>
94|*【補足】
95|*・BigStack 共通モジュールを使用しているモジュールを使用するときは、
96|* メイン(アプリケーション)で、BigStack モジュールを初期化する必要が
97|* あります。本ライブラリを使用する全てのタスクのスタートアップに以下のように
98|* 記述してください。
99|*
100|* static char s[65536]; // サイズは、スタックの使用状況による
101|* BigStack_init( s, sizeof(s) );
102|*
103|***************************************************************************/
104|struct _BigStack {
105| char* mem; /* 大きいスタックのある先頭メモリアドレス */
106| unsigned int size;
107| char* sp;
108| char* block1;
109| #ifdef BIGSTACK_CHKSIZE
110| int max; /* 最大使用サイズ */
111| #endif
112| #ifndef NDEBUG
113| int count;
114| #endif
115| ERRORS_INITCHK_VAR
116|};
117|
118|void BigStack_init( char* mem, size_t mem_sizeof );
119|void BigStack_start(void);
120|char* BigStack_alloc( unsigned int size );
121|void BigStack_end(void);
122|#ifndef ERRORS_CUT_DEBUG_TOOL
123| void BigStack_print(void);
124|#endif
125|void BIGSTACK_CHECK(void);
126|void BIGSTACK_DEBUG1(int* work);
127|void BIGSTACK_DEBUG2(int* work);
128|
129|
130|/* 以下は内部用 */
131|void BigStack_init_imp( BigStack*, char* mem, size_t mem_sizeof );
132|void BigStack_start_imp( BigStack* );
133|char* BigStack_alloc_imp( BigStack*, unsigned int size );
134|void BigStack_end_imp( BigStack* );
135|#ifndef ERRORS_CUT_DEBUG_TOOL
136| void BigStack_print_imp( BigStack* );
137|#endif
138|
139|
140|#ifdef __cplusplus
141|}
142|#endif
143|
144|#endif
145|
146|/*--------------------------------------------------------------*/
147|/*8. <<< Mapping Area ---------------------------------------- >>> */
148|/*--------------------------------------------------------------*/
149|
150|
151|/**************************************************************************
152|* 9. <<< BigStack マルチタスク対応 >>>
153|* 10. <<< [BigStack_init, BigStack_start, BigStack_alloc, BigStack_end] >>>
154|* 11. <<< [BigStack_print] >>>
155|***************************************************************************/
156|#ifdef USES_MULTASK
157| #define BigStack_init( mem, size ) \
158| BigStack_init_imp( &BigStack_Sys_arr[MulTask_Sys_getCurIndex()], mem, size )
159| #define BigStack_start() \
160| BigStack_start_imp( &BigStack_Sys_arr[MulTask_Sys_getCurIndex()] )
161| #define BigStack_alloc( size ) \
162| BigStack_alloc_imp( &BigStack_Sys_arr[MulTask_Sys_getCurIndex()], size )
163| #define BigStack_end() \
164| BigStack_end_imp( &BigStack_Sys_arr[MulTask_Sys_getCurIndex()] )
165| #define BigStack_print() \
166| BigStack_print_imp( &BigStack_Sys_arr[MulTask_Sys_getCurIndex()] )
167|#else
168| #define BigStack_init( mem, size ) \
169| BigStack_init_imp( &BigStack_Sys_arrX, mem, size )
170| #define BigStack_start() \
171| BigStack_start_imp( &BigStack_Sys_arrX )
172| #define BigStack_alloc( size ) \
173| BigStack_alloc_imp( &BigStack_Sys_arrX, size )
174| #define BigStack_end() \
175| BigStack_end_imp( &BigStack_Sys_arrX )
176| #define BigStack_print() \
177| BigStack_print_imp( &BigStack_Sys_arrX )
178|#endif
179|
180|
181|
182|/**************************************************************************
183|* 12. <<< [BIGSTACK_CHECK] スタックブロックの start - end 対応のチェック >>>
184|*【補足】
185|*・プログラム終了直前に呼び出します。
186|*・start と end の実行回数が異なると ASSERT に引っかかります。
187|***************************************************************************/
188|#ifdef NDEBUG
189| #define BIGSTACK_CHECK()
190|#else
191| #ifdef USES_MULTASK
192| #define BIGSTACK_CHECK() \
193| if ( BigStack_Sys_arr[MulTask_Sys_getCurID()].block1 != NULL ) { \
194| error2_0( BigStack_badStartEnd, \
195| "BigStack_start と BigStack_end の対応関係がおかしい" ); \
196| }
197| #else
198| #define BIGSTACK_CHECK() \
199| if ( BigStack_Sys_arrX.block1 != NULL ) { \
200| error2_0( BigStack_badStartEnd, \
201| "BigStack_start と BigStack_end の対応関係がおかしい" ); \
202| }
203| #endif
204|#endif
205|
206|
207|/**************************************************************************
208|* 13. <<< スタックブロックの start - end 対応のデバッグ >>>
209|* 14. <<< [BIGSTACK_DEBUG1, BIGSTACK_DEBUG2, BIGSTACK_DEBUG3] >>>
210|*【引数】
211|* ・int* work; ワーク領域(ローカル変数のアドレスを指定)
212|*【型】
213|* void BIGSTACK_DEBUG1(int* work);
214|* void BIGSTACK_DEBUG2(int* work);
215|* void BIGSTACK_DEBUG3(int* work);
216|*【補足】
217|*・BIGSTACK_DEBUG1 でのスタックポインタの位置が
218|* BIGSTACK_DEBUG2 または BIGSTACK_DEBUG3 での位置と同じかどうか
219|* チェックしてデバッグのヒントを取得します。
220|*・異常が見つかったら Errors_errPrintf で通知しますがエラーにはなりません。
221|*・BIGSTACK_DEBUG3 は、そこを通過したことも Errors_errPrintf で通知します。
222|***************************************************************************/
223|#ifdef ERRORS_CUT_DEBUG_TOOL
224| #define BIGSTACK_DEBUG1( work ) __cut_debug_tool
225| #define BIGSTACK_DEBUG2( work ) __cut_debug_tool
226| #define BIGSTACK_DEBUG3( work ) __cut_debug_tool
227|#else
228|
229| #ifdef USES_MULTASK
230| #define BIGSTACK_DEBUG1( work ) \
231| *(work) = BigStack_Sys_arr[MulTask_Sys_getCurIndex()].count
232| #define BIGSTACK_DEBUG2( work ) \
233| if ( *(work) != BigStack_Sys_arr[MulTask_Sys_getCurIndex()].count ) \
234| Errors_errPrintf( "BIGSTACK_DEBUG ERROR(%+d) in %s(%d)", \
235| BigStack_Sys_arr[MulTask_Sys_getCurIndex()].count - *(work), \
236| __FILE__, __LINE__ )
237| #define BIGSTACK_DEBUG3( work ) \
238| if ( *(work) != BigStack_Sys_arr[MulTask_Sys_getCurIndex()].count ) \
239| Errors_errPrintf( "BIGSTACK_DEBUG ERROR(%+d) in %s(%d)", \
240| BigStack_Sys_arr[MulTask_Sys_getCurIndex()].count - *(work), \
241| __FILE__, __LINE__ ); \
242| else \
243| Errors_errPrintf( "BIGSTACK_DEBUG through in %s(%d)", __FILE__, __LINE__ )
244| #else
245| #define BIGSTACK_DEBUG1( work ) \
246| *(work) = BigStack_Sys_arrX.count
247| #define BIGSTACK_DEBUG2( work ) \
248| if ( *(work) != BigStack_Sys_arrX.count ) \
249| Errors_errPrintf( "BIGSTACK_DEBUG ERROR(%+d) in %s(%d)", \
250| BigStack_Sys_arrX.count - *(work), \
251| __FILE__, __LINE__ )
252| #define BIGSTACK_DEBUG3( work ) \
253| if ( *(work) != BigStack_Sys_arrX.count ) \
254| Errors_errPrintf( "BIGSTACK_DEBUG ERROR(%+d) in %s(%d)", \
255| BigStack_Sys_arrX.count - *(work), \
256| __FILE__, __LINE__ ); \
257| else \
258| Errors_errPrintf( "BIGSTACK_DEBUG through in %s(%d)", __FILE__, __LINE__ )
259| #endif
260|
261|#endif
262|
263|
264|