tkernel_2/kernel/tkernel/src/check.h | bare source | permlink (0.01 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * T-Kernel 2.0 Software Package 4: * 5: * Copyright 2011 by Ken Sakamura. 6: * This software is distributed under the latest version of T-License 2.x. 7: *---------------------------------------------------------------------- 8: * 9: * Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17. 10: * Modified by TRON Forum(http://www.tron.org/) at 2015/06/01. 11: * 12: *---------------------------------------------------------------------- 13: */ 14: 15: /* 16: * check.h (T-Kernel/OS) 17: * Macro for Error Check 18: */ 19: 20: #ifndef _CHECK_ 21: #define _CHECK_ 22: 23: /* 24: * Check object ID range (E_ID) 25: */ 26: #if CHK_ID 27: #define CHECK_TSKID(tskid) { \ 28: if (!in_indp() && ((tskid) == TSK_SELF)) { \ 29: return E_OBJ; \ 30: } else if (!CHK_TSKID(tskid)) { \ 31: return E_ID; \ 32: } \ 33: } 34: #define CHECK_TSKID_SELF(tskid) { \ 35: if ( !( (!in_indp() && (tskid) == TSK_SELF) \ 36: || CHK_TSKID(tskid) ) ) { \ 37: return E_ID; \ 38: } \ 39: } 40: #define CHECK_SEMID(semid) { \ 41: if (!CHK_SEMID(semid)) { \ 42: return E_ID; \ 43: } \ 44: } 45: #define CHECK_FLGID(flgid) { \ 46: if (!CHK_FLGID(flgid)) { \ 47: return E_ID; \ 48: } \ 49: } 50: #define CHECK_MBXID(mbxid) { \ 51: if (!CHK_MBXID(mbxid)) { \ 52: return E_ID; \ 53: } \ 54: } 55: #define CHECK_MBFID(mbfid) { \ 56: if (!CHK_MBFID(mbfid)) { \ 57: return E_ID; \ 58: } \ 59: } 60: #define CHECK_PORID(porid) { \ 61: if (!CHK_PORID(porid)) { \ 62: return E_ID; \ 63: } \ 64: } 65: #define CHECK_MTXID(pisid) { \ 66: if (!CHK_MTXID(pisid)) { \ 67: return E_ID; \ 68: } \ 69: } 70: #define CHECK_MPLID(mplid) { \ 71: if (!CHK_MPLID(mplid)) { \ 72: return E_ID; \ 73: } \ 74: } 75: #define CHECK_MPFID(mpfid) { \ 76: if (!CHK_MPFID(mpfid)) { \ 77: return E_ID; \ 78: } \ 79: } 80: #define CHECK_CYCID(cycid) { \ 81: if (!CHK_CYCID(cycid)) { \ 82: return E_ID; \ 83: } \ 84: } 85: #define CHECK_ALMID(almid) { \ 86: if (!CHK_ALMID(almid)) { \ 87: return E_ID; \ 88: } \ 89: } 90: #define CHECK_RESID(resid) { \ 91: if (!CHK_RESID(resid)) { \ 92: return E_ID; \ 93: } \ 94: } 95: #define CHECK_RESID_ANY(resid) { \ 96: if (!(CHK_RESID(resid) || (resid) == 0)) { \ 97: return E_ID; \ 98: } \ 99: } 100: #define CHECK_SSYID(ssid) { \ 101: if (!CHK_SSYID(ssid)) { \ 102: return E_ID; \ 103: } \ 104: } 105: #define CHECK_SSYID_ALL(ssid) { \ 106: if (!(CHK_SSYID(ssid) || (ssid) == 0)) { \ 107: return E_ID; \ 108: } \ 109: } 110: #else /* CHK_ID */ 111: #define CHECK_TSKID(tskid) 112: #define CHECK_TSKID_SELF(tskid) 113: #define CHECK_SEMID(semid) 114: #define CHECK_FLGID(flgid) 115: #define CHECK_MBXID(mbxid) 116: #define CHECK_MBFID(mbfid) 117: #define CHECK_PORID(porid) 118: #define CHECK_MTXID(pisid) 119: #define CHECK_MPLID(mplid) 120: #define CHECK_MPFID(mpfid) 121: #define CHECK_CYCID(cycid) 122: #define CHECK_ALMID(almid) 123: #define CHECK_RESID(resid) 124: #define CHECK_RESID_ANY(resid) 125: #define CHECK_SSYID(ssid) 126: #define CHECK_SSYID_ALL(ssid) 127: #endif /* CHK_ID */ 128: 129: /* 130: * Check whether its own task is specified (E_OBJ) 131: */ 132: #if CHK_SELF 133: #define CHECK_NONSELF(tskid) { \ 134: if (!in_indp() && (tskid) == ctxtsk->tskid) { \ 135: return E_OBJ; \ 136: } \ 137: } 138: #else /* CHK_SELF */ 139: #define CHECK_NONSELF(tskid) 140: #endif /* CHK_SELF */ 141: 142: /* 143: * Check task priority value (E_PAR) 144: */ 145: #if CHK_PAR 146: #define CHECK_PRI(pri) { \ 147: if (!CHK_PRI(pri)) { \ 148: return E_PAR; \ 149: } \ 150: } 151: #define CHECK_PRI_INI(pri) { \ 152: if ((pri) != TPRI_INI && !CHK_PRI(pri)) { \ 153: return E_PAR; \ 154: } \ 155: } 156: #define CHECK_PRI_RUN(pri) { \ 157: if ((pri) != TPRI_RUN && !CHK_PRI(pri)) { \ 158: return E_PAR; \ 159: } \ 160: } 161: #else /* CHK_PAR */ 162: #define CHECK_PRI(pri) 163: #define CHECK_PRI_INI(pri) 164: #define CHECK_PRI_RUN(pri) 165: #endif /* CHK_PAR */ 166: 167: /* 168: * Check subsystem priority value (E_PAR) 169: */ 170: #if CHK_PAR 171: #define CHECK_SSYPRI(ssypri) { \ 172: if (!CHK_SSYPRI(ssypri)) { \ 173: return E_PAR; \ 174: } \ 175: } 176: #else /* CHK_PAR */ 177: #define CHECK_SSYPRI(ssypri) 178: #endif /* CHK_PAR */ 179: 180: /* 181: * Check timeout specification value (E_PAR) 182: */ 183: #if CHK_PAR 184: #define CHECK_TMOUT(tmout) { \ 185: if (!((tmout) >= TMO_FEVR)) { \ 186: return E_PAR; \ 187: } \ 188: } 189: #else /* CHK_PAR */ 190: #define CHECK_TMOUT(tmout) 191: #endif /* CHK_PAR */ 192: 193: /* 194: * Check other parameter errors (E_PAR) 195: */ 196: #if CHK_PAR 197: #define CHECK_PAR(exp) { \ 198: if (!(exp)) { \ 199: return E_PAR; \ 200: } \ 201: } 202: #else /* CHK_PAR */ 203: #define CHECK_PAR(exp) 204: #endif /* CHK_PAR */ 205: 206: /* 207: * Check reservation attribute error (E_RSATR) 208: */ 209: #if CHK_RSATR 210: #define CHECK_RSATR(atr, maxatr) { \ 211: if ((atr) & ~(maxatr)) { \ 212: return E_RSATR; \ 213: } \ 214: } 215: #else /* CHK_RSATR */ 216: #define CHECK_RSATR(atr, maxatr) 217: #endif /* CHK_RSATR */ 218: 219: /* 220: * Check unsupported function (E_NOSPT) 221: */ 222: #if CHK_NOSPT 223: #define CHECK_NOSPT(exp) { \ 224: if (!(exp)) { \ 225: return E_NOSPT; \ 226: } \ 227: } 228: #else /* CHK_NOSPT */ 229: #define CHECK_NOSPT(exp) 230: #endif /* CHK_NOSPT */ 231: 232: /* 233: * Check whether task-independent part is running (E_CTX) 234: */ 235: #if CHK_CTX 236: #define CHECK_INTSK() { \ 237: if (in_indp()) { \ 238: return E_CTX; \ 239: } \ 240: } 241: #else /* CHK_CTX */ 242: #define CHECK_INTSK() 243: #endif /* CHK_CTX */ 244: 245: /* 246: * Check whether dispatch is in disabled state (E_CTX) 247: */ 248: #if CHK_CTX 249: #define CHECK_DISPATCH() { \ 250: if (in_ddsp()) { \ 251: return E_CTX; \ 252: } \ 253: } 254: #define CHECK_DISPATCH_POL(tmout) { \ 255: if ((tmout) != TMO_POL && in_ddsp()) { \ 256: return E_CTX; \ 257: } \ 258: } 259: #else /* CHK_CTX */ 260: #define CHECK_DISPATCH() 261: #define CHECK_DISPATCH_POL(tmout) 262: #endif /* CHK_CTX */ 263: 264: /* 265: * Check other context errors (E_CTX) 266: */ 267: #if CHK_CTX 268: #define CHECK_CTX(exp) { \ 269: if (!(exp)) { \ 270: return E_CTX; \ 271: } \ 272: } 273: #else /* CHK_CTX */ 274: #define CHECK_CTX(exp) 275: #endif /* CHK_CTX */ 276: 277: /* 278: * Check non-existence co-processor error (E_NOCOP) 279: */ 280: #if CHK_NOCOP 281: #define CHECK_NOCOP(atr) { \ 282: if ( ((atr) & (TA_COP0|TA_COP1|TA_COP2|TA_COP3)) != 0 \ 283: && ((atr) & available_cop) == 0 ) { \ 284: return E_NOCOP; \ 285: } \ 286: } 287: #else 288: #define CHECK_NOCOP(atr) 289: #endif 290: 291: #endif /* _CHECK_ */