source: UsbWattMeter/trunk/asp_dcre/kernel/mempfix.c@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 12.7 KB
Line 
1/*
2 * TOPPERS/ASP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Advanced Standard Profile Kernel
5 *
6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2005-2014 by Embedded and Real-Time Systems Laboratory
9 * Graduate School of Information Science, Nagoya Univ., JAPAN
10 *
11 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
12 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
13 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
14 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
15 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
16 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
17 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
18 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
19ƒƒ“ƒgi—˜—p
20 * ŽÒƒ}ƒjƒ…
21ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
22 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
23 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
24 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
25 * ‚ƁD
26 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
27ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
28ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
29 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
30 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
31 * •ñ‚·‚邱‚ƁD
32 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
33 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
34 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
35 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
36 * –Ɛӂ·‚邱‚ƁD
37 *
38 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
39 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
40 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
41 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
42 * ‚̐ӔC‚𕉂í‚È‚¢D
43 *
44 * @(#) $Id: mempfix.c 164 2016-03-07 11:33:50Z coas-nagasima $
45 */
46
47/*
48 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹‹@”\
49 */
50
51#include "kernel_impl.h"
52#include "check.h"
53#include "task.h"
54#include "wait.h"
55#include "mempfix.h"
56
57/*
58 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
59 */
60#ifndef LOG_ACRE_MPF_ENTER
61#define LOG_ACRE_MPF_ENTER(pk_cmpf)
62#endif /* LOG_ACRE_MPF_ENTER */
63
64#ifndef LOG_ACRE_MPF_LEAVE
65#define LOG_ACRE_MPF_LEAVE(ercd)
66#endif /* LOG_ACRE_MPF_LEAVE */
67
68#ifndef LOG_DEL_MPF_ENTER
69#define LOG_DEL_MPF_ENTER(mpfid)
70#endif /* LOG_DEL_MPF_ENTER */
71
72#ifndef LOG_DEL_MPF_LEAVE
73#define LOG_DEL_MPF_LEAVE(ercd)
74#endif /* LOG_DEL_MPF_LEAVE */
75
76#ifndef LOG_GET_MPF_ENTER
77#define LOG_GET_MPF_ENTER(mpfid, p_blk)
78#endif /* LOG_GET_MPF_ENTER */
79
80#ifndef LOG_GET_MPF_LEAVE
81#define LOG_GET_MPF_LEAVE(ercd, blk)
82#endif /* LOG_GET_MPF_LEAVE */
83
84#ifndef LOG_PGET_MPF_ENTER
85#define LOG_PGET_MPF_ENTER(mpfid, p_blk)
86#endif /* LOG_PGET_MPF_ENTER */
87
88#ifndef LOG_PGET_MPF_LEAVE
89#define LOG_PGET_MPF_LEAVE(ercd, blk)
90#endif /* LOG_PGET_MPF_LEAVE */
91
92#ifndef LOG_TGET_MPF_ENTER
93#define LOG_TGET_MPF_ENTER(mpfid, p_blk, tmout)
94#endif /* LOG_TGET_MPF_ENTER */
95
96#ifndef LOG_TGET_MPF_LEAVE
97#define LOG_TGET_MPF_LEAVE(ercd, blk)
98#endif /* LOG_TGET_MPF_LEAVE */
99
100#ifndef LOG_REL_MPF_ENTER
101#define LOG_REL_MPF_ENTER(mpfid, blk)
102#endif /* LOG_REL_MPF_ENTER */
103
104#ifndef LOG_REL_MPF_LEAVE
105#define LOG_REL_MPF_LEAVE(ercd)
106#endif /* LOG_REL_MPF_LEAVE */
107
108#ifndef LOG_INI_MPF_ENTER
109#define LOG_INI_MPF_ENTER(mpfid)
110#endif /* LOG_INI_MPF_ENTER */
111
112#ifndef LOG_INI_MPF_LEAVE
113#define LOG_INI_MPF_LEAVE(ercd)
114#endif /* LOG_INI_MPF_LEAVE */
115
116#ifndef LOG_REF_MPF_ENTER
117#define LOG_REF_MPF_ENTER(mpfid, pk_rmpf)
118#endif /* LOG_REF_MPF_ENTER */
119
120#ifndef LOG_REF_MPF_LEAVE
121#define LOG_REF_MPF_LEAVE(ercd, pk_rmpf)
122#endif /* LOG_REF_MPF_LEAVE */
123
124/*
125 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹‚̐”
126 */
127#define tnum_mpf ((uint_t)(tmax_mpfid - TMIN_MPFID + 1))
128#define tnum_smpf ((uint_t)(tmax_smpfid - TMIN_MPFID + 1))
129
130/*
131 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹ID‚©‚çŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹ŠÇ—ƒuƒƒbƒN‚ðŽæ‚èo‚·‚½
132 * ‚߂̃}ƒNƒ
133 */
134#define INDEX_MPF(mpfid) ((uint_t)((mpfid) - TMIN_MPFID))
135#define get_mpfcb(mpfid) (&(mpfcb_table[INDEX_MPF(mpfid)]))
136
137/*
138 * “ÁŽê‚ȃCƒ“ƒfƒbƒNƒX’l‚Ì’è‹`
139 */
140#define INDEX_NULL (~0U) /* ‹ó‚«ƒuƒƒbƒNƒŠƒXƒg‚̍Ōã */
141#define INDEX_ALLOC (~1U) /* Š„“–‚čς݂̃uƒƒbƒN */
142
143#ifdef TOPPERS_mpfini
144
145/*
146 * Žg—p‚µ‚Ä‚¢‚È‚¢ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹ŠÇ—ƒuƒƒbƒN‚̃ŠƒXƒg
147 */
148QUEUE free_mpfcb;
149
150/*
151 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹‹@”\‚̏‰Šú‰»
152 */
153void
154initialize_mempfix(void)
155{
156 uint_t i, j;
157 MPFCB *p_mpfcb;
158 MPFINIB *p_mpfinib;
159
160 for (i = 0; i < tnum_smpf; i++) {
161 p_mpfcb = &(mpfcb_table[i]);
162 queue_initialize(&(p_mpfcb->wait_queue));
163 p_mpfcb->p_mpfinib = &(mpfinib_table[i]);
164 p_mpfcb->fblkcnt = p_mpfcb->p_mpfinib->blkcnt;
165 p_mpfcb->unused = 0U;
166 p_mpfcb->freelist = INDEX_NULL;
167 }
168 queue_initialize(&free_mpfcb);
169 for (j = 0; i < tnum_mpf; i++, j++) {
170 p_mpfcb = &(mpfcb_table[i]);
171 p_mpfinib = &(ampfinib_table[j]);
172 p_mpfinib->mpfatr = TA_NOEXS;
173 p_mpfcb->p_mpfinib = ((const MPFINIB *) p_mpfinib);
174 queue_insert_prev(&free_mpfcb, &(p_mpfcb->wait_queue));
175 }
176}
177
178#endif /* TOPPERS_mpfini */
179
180/*
181 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹‚©‚çƒuƒƒbƒN‚ðŠl“¾
182 */
183#ifdef TOPPERS_mpfget
184
185void
186get_mpf_block(MPFCB *p_mpfcb, void **p_blk)
187{
188 uint_t blkidx;
189
190 if (p_mpfcb->freelist != INDEX_NULL) {
191 blkidx = p_mpfcb->freelist;
192 p_mpfcb->freelist = (p_mpfcb->p_mpfinib->p_mpfmb + blkidx)->next;
193 }
194 else {
195 blkidx = p_mpfcb->unused;
196 p_mpfcb->unused++;
197 }
198 *p_blk = (void *)((char *)(p_mpfcb->p_mpfinib->mpf)
199 + p_mpfcb->p_mpfinib->blksz * blkidx);
200 p_mpfcb->fblkcnt--;
201 (p_mpfcb->p_mpfinib->p_mpfmb + blkidx)->next = INDEX_ALLOC;
202}
203
204#endif /* TOPPERS_mpfget */
205
206/*
207 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹‚̐¶¬
208 */
209#ifdef TOPPERS_acre_mpf
210
211ER_UINT
212acre_mpf(const T_CMPF *pk_cmpf)
213{
214 MPFCB *p_mpfcb;
215 MPFINIB *p_mpfinib;
216 ATR mpfatr;
217 void *mpf;
218 MPFMB *p_mpfmb;
219 ER ercd;
220
221 LOG_ACRE_MPF_ENTER(pk_cmpf);
222 CHECK_TSKCTX_UNL();
223 CHECK_RSATR(pk_cmpf->mpfatr, TA_TPRI);
224 CHECK_PAR(pk_cmpf->blkcnt != 0);
225 CHECK_PAR(pk_cmpf->blksz != 0);
226 if (pk_cmpf->mpf != NULL) {
227 CHECK_ALIGN_MPF(pk_cmpf->mpf);
228 }
229 if (pk_cmpf->mpfmb != NULL) {
230 CHECK_ALIGN_MB(pk_cmpf->mpfmb);
231 }
232 mpfatr = pk_cmpf->mpfatr;
233 mpf = pk_cmpf->mpf;
234 p_mpfmb = pk_cmpf->mpfmb;
235
236 t_lock_cpu();
237 if (tnum_mpf == 0 || queue_empty(&free_mpfcb)) {
238 ercd = E_NOID;
239 }
240 else {
241 if (mpf == NULL) {
242 mpf = kernel_malloc(ROUND_MPF_T(pk_cmpf->blksz) * pk_cmpf->blkcnt);
243 mpfatr |= TA_MEMALLOC;
244 }
245 if (mpf == NULL) {
246 ercd = E_NOMEM;
247 }
248 else {
249 if (p_mpfmb == NULL) {
250 p_mpfmb = kernel_malloc(sizeof(MPFMB) * pk_cmpf->blkcnt);
251 mpfatr |= TA_MBALLOC;
252 }
253 if (p_mpfmb == NULL) {
254 if (pk_cmpf->mpf == NULL) {
255 kernel_free(mpf);
256 }
257 ercd = E_NOMEM;
258 }
259 else {
260 p_mpfcb = ((MPFCB *) queue_delete_next(&free_mpfcb));
261 p_mpfinib = (MPFINIB *)(p_mpfcb->p_mpfinib);
262 p_mpfinib->mpfatr = mpfatr;
263 p_mpfinib->blkcnt = pk_cmpf->blkcnt;
264 p_mpfinib->blksz = ROUND_MPF_T(pk_cmpf->blksz);
265 p_mpfinib->mpf = mpf;
266 p_mpfinib->p_mpfmb = p_mpfmb;
267
268 queue_initialize(&(p_mpfcb->wait_queue));
269 p_mpfcb->fblkcnt = p_mpfcb->p_mpfinib->blkcnt;
270 p_mpfcb->unused = 0U;
271 p_mpfcb->freelist = INDEX_NULL;
272 ercd = MPFID(p_mpfcb);
273 }
274 }
275 }
276 t_unlock_cpu();
277
278 error_exit:
279 LOG_ACRE_MPF_LEAVE(ercd);
280 return(ercd);
281}
282
283#endif /* TOPPERS_acre_mpf */
284
285/*
286 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹‚̍폜
287 */
288#ifdef TOPPERS_del_mpf
289
290ER
291del_mpf(ID mpfid)
292{
293 MPFCB *p_mpfcb;
294 MPFINIB *p_mpfinib;
295 bool_t dspreq;
296 ER ercd;
297
298 LOG_DEL_MPF_ENTER(mpfid);
299 CHECK_TSKCTX_UNL();
300 CHECK_MPFID(mpfid);
301 p_mpfcb = get_mpfcb(mpfid);
302
303 t_lock_cpu();
304 if (p_mpfcb->p_mpfinib->mpfatr == TA_NOEXS) {
305 ercd = E_NOEXS;
306 }
307 else if (MPFID(p_mpfcb) > tmax_smpfid) {
308 dspreq = init_wait_queue(&(p_mpfcb->wait_queue));
309 p_mpfinib = (MPFINIB *)(p_mpfcb->p_mpfinib);
310 if ((p_mpfinib->mpfatr & TA_MEMALLOC) != 0U) {
311 kernel_free(p_mpfinib->mpf);
312 }
313 if ((p_mpfinib->mpfatr & TA_MBALLOC) != 0U) {
314 kernel_free(p_mpfinib->p_mpfmb);
315 }
316 p_mpfinib->mpfatr = TA_NOEXS;
317 queue_insert_prev(&free_mpfcb, &(p_mpfcb->wait_queue));
318 if (dspreq) {
319 dispatch();
320 }
321 ercd = E_OK;
322 }
323 else {
324 ercd = E_OBJ;
325 }
326 t_unlock_cpu();
327
328 error_exit:
329 LOG_DEL_MPF_LEAVE(ercd);
330 return(ercd);
331}
332
333#endif /* TOPPERS_del_mpf */
334
335/*
336 * ŒÅ’è’·ƒƒ‚ƒŠƒuƒƒbƒN‚ÌŠl“¾
337 */
338#ifdef TOPPERS_get_mpf
339
340ER
341get_mpf(ID mpfid, void **p_blk)
342{
343 MPFCB *p_mpfcb;
344 WINFO_MPF winfo_mpf;
345 ER ercd;
346
347 LOG_GET_MPF_ENTER(mpfid, p_blk);
348 CHECK_DISPATCH();
349 CHECK_MPFID(mpfid);
350 p_mpfcb = get_mpfcb(mpfid);
351
352 t_lock_cpu();
353 if (p_mpfcb->p_mpfinib->mpfatr == TA_NOEXS) {
354 ercd = E_NOEXS;
355 }
356 else if (p_mpfcb->fblkcnt > 0) {
357 get_mpf_block(p_mpfcb, p_blk);
358 ercd = E_OK;
359 }
360 else {
361 p_runtsk->tstat = (TS_WAITING | TS_WAIT_MPF);
362 wobj_make_wait((WOBJCB *) p_mpfcb, (WINFO_WOBJ *) &winfo_mpf);
363 dispatch();
364 ercd = winfo_mpf.winfo.wercd;
365 if (ercd == E_OK) {
366 *p_blk = winfo_mpf.blk;
367 }
368 }
369 t_unlock_cpu();
370
371 error_exit:
372 LOG_GET_MPF_LEAVE(ercd, *p_blk);
373 return(ercd);
374}
375
376#endif /* TOPPERS_get_mpf */
377
378/*
379 * ŒÅ’è’·ƒƒ‚ƒŠƒuƒƒbƒN‚ÌŠl“¾iƒ|[ƒŠƒ“ƒOj
380 */
381#ifdef TOPPERS_pget_mpf
382
383ER
384pget_mpf(ID mpfid, void **p_blk)
385{
386 MPFCB *p_mpfcb;
387 ER ercd;
388
389 LOG_PGET_MPF_ENTER(mpfid, p_blk);
390 CHECK_TSKCTX_UNL();
391 CHECK_MPFID(mpfid);
392 p_mpfcb = get_mpfcb(mpfid);
393
394 t_lock_cpu();
395 if (p_mpfcb->p_mpfinib->mpfatr == TA_NOEXS) {
396 ercd = E_NOEXS;
397 }
398 else if (p_mpfcb->fblkcnt > 0) {
399 get_mpf_block(p_mpfcb, p_blk);
400 ercd = E_OK;
401 }
402 else {
403 ercd = E_TMOUT;
404 }
405 t_unlock_cpu();
406
407 error_exit:
408 LOG_PGET_MPF_LEAVE(ercd, *p_blk);
409 return(ercd);
410}
411
412#endif /* TOPPERS_pget_mpf */
413
414/*
415 * ŒÅ’è’·ƒƒ‚ƒŠƒuƒƒbƒN‚ÌŠl“¾iƒ^ƒCƒ€ƒAƒEƒg‚ ‚èj
416 */
417#ifdef TOPPERS_tget_mpf
418
419ER
420tget_mpf(ID mpfid, void **p_blk, TMO tmout)
421{
422 MPFCB *p_mpfcb;
423 WINFO_MPF winfo_mpf;
424 TMEVTB tmevtb;
425 ER ercd;
426
427 LOG_TGET_MPF_ENTER(mpfid, p_blk, tmout);
428 CHECK_DISPATCH();
429 CHECK_MPFID(mpfid);
430 CHECK_TMOUT(tmout);
431 p_mpfcb = get_mpfcb(mpfid);
432
433 t_lock_cpu();
434 if (p_mpfcb->p_mpfinib->mpfatr == TA_NOEXS) {
435 ercd = E_NOEXS;
436 }
437 else if (p_mpfcb->fblkcnt > 0) {
438 get_mpf_block(p_mpfcb, p_blk);
439 ercd = E_OK;
440 }
441 else if (tmout == TMO_POL) {
442 ercd = E_TMOUT;
443 }
444 else {
445 p_runtsk->tstat = (TS_WAITING | TS_WAIT_MPF);
446 wobj_make_wait_tmout((WOBJCB *) p_mpfcb, (WINFO_WOBJ *) &winfo_mpf,
447 &tmevtb, tmout);
448 dispatch();
449 ercd = winfo_mpf.winfo.wercd;
450 if (ercd == E_OK) {
451 *p_blk = winfo_mpf.blk;
452 }
453 }
454 t_unlock_cpu();
455
456 error_exit:
457 LOG_TGET_MPF_LEAVE(ercd, *p_blk);
458 return(ercd);
459}
460
461#endif /* TOPPERS_tget_mpf */
462
463/*
464 * ŒÅ’è’·ƒƒ‚ƒŠƒuƒƒbƒN‚Ì•Ô‹p
465 */
466#ifdef TOPPERS_rel_mpf
467
468ER
469rel_mpf(ID mpfid, void *blk)
470{
471 MPFCB *p_mpfcb;
472 SIZE blkoffset;
473 uint_t blkidx;
474 TCB *p_tcb;
475 ER ercd;
476
477 LOG_REL_MPF_ENTER(mpfid, blk);
478 CHECK_TSKCTX_UNL();
479 CHECK_MPFID(mpfid);
480 p_mpfcb = get_mpfcb(mpfid);
481
482 t_lock_cpu();
483 if (p_mpfcb->p_mpfinib->mpfatr == TA_NOEXS) {
484 ercd = E_NOEXS;
485 }
486 else {
487 blkoffset = ((char *) blk) - (char *)(p_mpfcb->p_mpfinib->mpf);
488 blkidx = (uint_t)(blkoffset / p_mpfcb->p_mpfinib->blksz);
489 if (!(p_mpfcb->p_mpfinib->mpf <= blk)
490 || !(blkoffset % p_mpfcb->p_mpfinib->blksz == 0U)
491 || !(blkoffset / p_mpfcb->p_mpfinib->blksz < p_mpfcb->unused)
492 || !((p_mpfcb->p_mpfinib->p_mpfmb + blkidx)->next
493 == INDEX_ALLOC)) {
494 ercd = E_PAR;
495 }
496 else if (!queue_empty(&(p_mpfcb->wait_queue))) {
497 p_tcb = (TCB *) queue_delete_next(&(p_mpfcb->wait_queue));
498 ((WINFO_MPF *)(p_tcb->p_winfo))->blk = blk;
499 if (wait_complete(p_tcb)) {
500 dispatch();
501 }
502 ercd = E_OK;
503 }
504 else {
505 p_mpfcb->fblkcnt++;
506 (p_mpfcb->p_mpfinib->p_mpfmb + blkidx)->next = p_mpfcb->freelist;
507 p_mpfcb->freelist = blkidx;
508 ercd = E_OK;
509 }
510 }
511 t_unlock_cpu();
512
513 error_exit:
514 LOG_REL_MPF_LEAVE(ercd);
515 return(ercd);
516}
517
518#endif /* TOPPERS_rel_mpf */
519
520/*
521 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹‚̍ú‰»
522 */
523#ifdef TOPPERS_ini_mpf
524
525ER
526ini_mpf(ID mpfid)
527{
528 MPFCB *p_mpfcb;
529 bool_t dspreq;
530 ER ercd;
531
532 LOG_INI_MPF_ENTER(mpfid);
533 CHECK_TSKCTX_UNL();
534 CHECK_MPFID(mpfid);
535 p_mpfcb = get_mpfcb(mpfid);
536
537 t_lock_cpu();
538 if (p_mpfcb->p_mpfinib->mpfatr == TA_NOEXS) {
539 ercd = E_NOEXS;
540 }
541 else {
542 dspreq = init_wait_queue(&(p_mpfcb->wait_queue));
543 p_mpfcb->fblkcnt = p_mpfcb->p_mpfinib->blkcnt;
544 p_mpfcb->unused = 0U;
545 p_mpfcb->freelist = INDEX_NULL;
546 if (dspreq) {
547 dispatch();
548 }
549 ercd = E_OK;
550 }
551 t_unlock_cpu();
552
553 error_exit:
554 LOG_INI_MPF_LEAVE(ercd);
555 return(ercd);
556}
557
558#endif /* TOPPERS_ini_mpf */
559
560/*
561 * ŒÅ’è’·ƒƒ‚ƒŠƒv[ƒ‹‚̏ó‘ÔŽQÆ
562 */
563#ifdef TOPPERS_ref_mpf
564
565ER
566ref_mpf(ID mpfid, T_RMPF *pk_rmpf)
567{
568 MPFCB *p_mpfcb;
569 ER ercd;
570
571 LOG_REF_MPF_ENTER(mpfid, pk_rmpf);
572 CHECK_TSKCTX_UNL();
573 CHECK_MPFID(mpfid);
574 p_mpfcb = get_mpfcb(mpfid);
575
576 t_lock_cpu();
577 if (p_mpfcb->p_mpfinib->mpfatr == TA_NOEXS) {
578 ercd = E_NOEXS;
579 }
580 else {
581 pk_rmpf->wtskid = wait_tskid(&(p_mpfcb->wait_queue));
582 pk_rmpf->fblkcnt = p_mpfcb->fblkcnt;
583 ercd = E_OK;
584 }
585 t_unlock_cpu();
586
587 error_exit:
588 LOG_REF_MPF_LEAVE(ercd, pk_rmpf);
589 return(ercd);
590}
591
592#endif /* TOPPERS_ref_mpf */
Note: See TracBrowser for help on using the repository browser.