femtoos_headers/femtoos_locals.h

Go to the documentation of this file.
00001 /*
00002  * Femto OS v 0.91 - Copyright (C) 2008-2009 Ruud Vlaming
00003  *
00004  * This file is part of the Femto OS distribution.
00005  *
00006  * This program is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, version 3 of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * Please note that, due to the GPLv3 license, for application of this
00019  * work and/or combined work in embedded systems special obligations apply.
00020  * If these are not to you liking, please know the Femto OS is dual
00021  * licensed. A commercial license and support are available.
00022  * See http://www.femtoos.org/ for details.
00023  */
00024 
00025 #ifndef FEMTOOS_LOCALS_H
00026 #define FEMTOOS_LOCALS_H
00027 
00028 
00029 /* The context save makes use of the OS to store the background variables. In order to
00030  * facilitate this, and simplify code over there, we define here the addresses needed.
00031  * This must be done for the OS stack as well as the ISR stack. Of course these definitions
00032  * depend on the direction of the stack growth.
00033  * Be ware, the endianness is relevant too. These values are for little endian encoding,
00034  * and are to be adjusted when we have big endian encoding. I have no big endian hardware
00035  * to test, so it makes little sense to add that much untested code. In fact i don't even
00036  * have hardware with cfgSysStackGrowthUp so that code must be faulty too.
00037  * Depending on the device the size of an address can be two or three bytes large. We must
00038  * distinguish between the two. FirstByte,SecondByte and ThirdByte refer to the bytes
00039  * as they are peeled of one stack to store on an other. StackInit refers to the absolute
00040  * beginning of the stack, whereas StactStart provides the location of the new stackpointer,
00041  * after the address have been transplanted (place of the stack pointer upon return to the OS.)
00042  * In case there is only a two byte program counter the 'ThirdByte' macros are not used.
00043  */
00044 
00045 #if (cfgSysStackGrowthUp == cfgTrue)
00046   #define OSstackFirstByte             (1 + defThreeByteStackAdd)
00047   #define OSstackSecondByte            (0 + defThreeByteStackAdd)
00048   #define OSstackThirdByte             (0)
00049   #define OSstackStart                 (2 + defThreeByteStackAdd)
00050   #define OSstackInit                  (0)
00051 #else
00052   #define OSstackFirstByte             ((StackSizeOS) - 2 - defThreeByteStackAdd)
00053   #define OSstackSecondByte            ((StackSizeOS) - 1 - defThreeByteStackAdd)
00054   #define OSstackThirdByte             ((StackSizeOS) - 1)
00055   #define OSstackStart                 ((StackSizeOS) - 3 - defThreeByteStackAdd)
00056   #define OSstackInit                  ((StackSizeOS) - 1)
00057 #endif
00058 
00059 /* When switching to an ISR we need a place where to temporarily store current
00060  * stackpointer. We could have defined a special variable for this, but it
00061  * seems more appropriate to use the ISR stack itself for this purpose. Therefore
00062  * not all of the ISR stack can be used by the ISR itself.
00063  * ISRstackStart defines the place of the stack pointer when starting the isr.
00064  */
00065 
00066 #if (cfgSysStackGrowthUp == cfgTrue)
00067   #define ISRstackSPH                  (0)
00068   #define ISRstackSPL                  (1)
00069   #define ISRstackFirstByte            (3 + defThreeByteStackAdd)
00070   #define ISRstackSecondByte           (2 + defThreeByteStackAdd)
00071   #define ISRstackThirdByte            (1 + defThreeByteStackAdd)
00072   #define ISRstackStart                (4 + defThreeByteStackAdd)
00073   #define ISRstackLastByte             ((StackSizeISR)-1)
00074   #define ISRstackInit                 (0)
00075 #else
00076   #define ISRstackSPH                  ((StackSizeISR) - 1)
00077   #define ISRstackSPL                  ((StackSizeISR) - 2)
00078   #define ISRstackFirstByte            ((StackSizeISR) - 4 - defThreeByteStackAdd)
00079   #define ISRstackSecondByte           ((StackSizeISR) - 3 - defThreeByteStackAdd)
00080   #define ISRstackThirdByte            ((StackSizeISR) - 2 - defThreeByteStackAdd)
00081   #define ISRstackStart                ((StackSizeISR) - 5 - defThreeByteStackAdd)
00082   #define ISRstackLastByte             (0)
00083   #define ISRstackInit                 ((StackSizeISR)-1)
00084 #endif
00085 
00086 /* For use of shared stack, we need the place where the stack starts */
00087 #if (cfgSysStackGrowthUp == cfgTrue)
00088   #define SHRstackFirstByte             (1 + defThreeByteStackAdd)
00089   #define SHRstackSecondByte            (0 + defThreeByteStackAdd)
00090   #define SHRstackThirdByte             (0)
00091   #define SHRstackStart                 (2 + defThreeByteStackAdd)
00092   #define SHRstackInit                  (0)
00093 #else
00094   #define SHRstackFirstByte             ((StackSizeShared) - 2 - defThreeByteStackAdd)
00095   #define SHRstackSecondByte            ((StackSizeShared) - 1 - defThreeByteStackAdd)
00096   #define SHRstackThirdByte             ((StackSizeShared) - 1)
00097   #define SHRstackStart                 ((StackSizeShared) - 3 - defThreeByteStackAdd)
00098   #define SHRstackInit                  ((StackSizeShared) - 1)
00099 #endif
00100 
00101 
00106 #if (cfgSysInline == cfgTrue)
00107   #define defConditionalInline  __attribute__ (( always_inline ))
00108 #else
00109   #define defConditionalInline
00110 #endif
00111 
00130 #define defTickFrequency              (devClockFrequency / cfgSysClockDivider / cfgSysSubTickDivider/ cfgSysSubTicksPerFullTick )
00131 #define defSleepInfinite              0xFF
00132 #define defSleepMaximum               0xFE
00133 #define defSleepTickBlockTime         (32000 / (defTickFrequency/8))
00134 #define defSleepThreshold             ((((cfgNumSleepThreshold + (defSleepTickBlockTime/2)) / 256) < defSleepInfinite) ? ((cfgNumSleepThreshold + (defSleepTickBlockTime/2)) / 256) : defSleepMaximum)
00135 #define defSleepDivider               ( (((2*defSleepRealPeriod) / defSleepTickBlockTime)+1) / 2 )
00136 
00141 #define defOsStackMinimum              (sizeof(TtaskSave))
00142 
00146 #define defSubTicksMax                 0xFF
00147 
00152 #define defNumberOfPriorities          8
00153 
00154 
00167 #if ( (cfgUseTaskWatchdog == cfgTrue) || (includeTaskRecreate == cfgTrue) || (includeTaskRestart == cfgTrue) || (defStackInitByte != 0x00) )
00168   #define defStackClean cfgTrue
00169 #else
00170   #define defStackClean cfgFalse
00171 #endif
00172 
00173 /* Definitions to find the current task */
00174 #define defCurrentTaskMask             0x80
00175 
00176 /* Definition for a empty stack. THe size is the size
00177  * defined in cfgShared below 16 bits, which can be used
00178  * as signal. Effectively this is zero. But we could use
00179  * the values 1,2 and 3 also, since they are all 'invalid'.
00180  */
00181 #define defStackEmpty                  (cfgShared & MaxStackSize_Task)
00182 
00183 
00184 /* Definition of the task status byte
00185  * 8 bit structure: smbdpppr
00186  * s:    stopstate   (go/halt)
00187  * m:    mode:       (suspend/sleep/access/sync)
00188  * b     blockstate: (blocked/free)
00189  * d:    delaystate
00190  * ppp:  priority
00191  * r:    dressstate  (runable/done, slot/event, read,write)
00192  *
00193  * The first three bits can be coupled to the states as follows:
00194  *
00195  * 0001 terminated (suspended blocked) never delayed!
00196  * 001x suspended (suspended unblocked) can be delayed [LSB kep for switchblock]
00197  * 010x sleeping blocked on sync (but not on fs, this is forbidden) (LSB: slot/event) can be delayed
00198  * 011x sleeping free can be delayed [LSB kept for switchblock]
00199  * 100x running blocked on fs (LSB:read/write) , can be delayed, switchblock lost after release
00200  * 101x running shared, can be delayed, (LSB shared runable/done), switchblock lost after release
00201  * 110x running blocked (LSB: slot/event) , can be delayed, switchblock lost after release
00202  * 111x running free (LSB: runable/done) , can be delayed
00203  *
00204  * The delay bit is orthogonal to these states, and without meaning in the
00205  * terminated state. A delay in any other blocked state may end and
00206  * depending on the state may wakeup the state.
00207  *
00208  * The defRestart States are coupled to these states.
00209  */
00210 
00211 
00212 /* Definitions of the masks you need to read a specific state */
00213 #define defBaseStopStateGetMask        0x80
00214 #define defBaseModeGetMask             0x40
00215 #define defBaseBlockStateGetMask       0x20
00216 #define defBaseDelayStateGetMask       0x10
00217 #define defBasePrioGetMask             0x0E
00218 #define defBaseDressGetMask            0x01
00219 #define defBaseSuspendedGetMask        0xE0
00220 #define defBaseTerminatedGetMask       0xF0
00221 #define defBaseSleepingGetMask         0xC0
00222 #define defBaseRestartGetMask          0xC0
00223 #define defBaseRunningGetMask          0xF0
00224 #define defBaseNoBlocksGetMask         0xE0
00225 #define defBaseSyncBlockedGetMask      0xE0
00226 #define defBaseFileBlockedGetMask      0xE0
00227 #define defBaseSharedGetMask           0xE0
00228 #define defBaseRunOrSharedGetMask      0xA0
00229 
00230 /* Definitions of the masks you need to write a specific state */
00231 #define defBaseStopStateSetMask        (~defBaseStopStateGetMask)
00232 #define defBaseModeSetMask             (~defBaseModeGetMask)
00233 #define defBaseBlockStateSetMask       (~defBaseBlockStateGetMask)
00234 #define defBaseDelayStateSetMask       (~defBaseDelayStateGetMask)
00235 #define defBasePrioSetMask             (~defBasePrioGetMask)
00236 #define defBaseDressSetMask            (~defBaseDressGetMask)
00237 #define defBaseSuspendedSetMask        (~defBaseSuspendedGetMask)
00238 #define defBaseTerminatedSetMask       (~defBaseTerminatedGetMask)
00239 #define defBaseSleepingSetMask         (~defBaseSleepingGetMask)
00240 #define defBaseRestartSetMask          (~defBaseRestartGetMask)
00241 #define defBaseRunningSetMask          (~defBaseRunningGetMask)
00242 #define defBaseNoBlocksSetMask         (~defBaseNoBlocksGetMask)
00243 #define defBaseSyncBlockedSetMask      (~defBaseSyncBlockedGetMask)
00244 #define defBaseFileBlockedSetMask      (~defBaseFileBlockedGetMask)
00245 #define defBaseSharedSetMask           (~defBaseSharedGetMask)
00246 
00247 /* Definitions of the states */
00248 #define defBaseStopStateGo             0x80
00249 #define defBaseStopStateHalt           0x00
00250 #define defBaseModeSleep               0x40
00251 #define defBaseModeSuspend             0x00
00252 #define defBaseModeSync                0x40
00253 #define defBaseModeAccess              0x00
00254 #define defBaseModeRun                 0x40
00255 #define defBaseModeShared              0x00
00256 #define defBaseBlockStateFree          0x20
00257 #define defBaseBlockStateBlocked       0x00
00258 #define defBaseDelayStateWake          0x10
00259 #define defBaseDelayStateDelayed       0x00
00260 #define defBaseDressRunable            0x01
00261 #define defBaseDressDone               0x00
00262 #define defBaseDressSlot               0x01
00263 #define defBaseDressEvent              0x00
00264 #define defBaseDressRead               0x01
00265 #define defBaseDressWrite              0x00
00266 
00267 #define defBaseRunningTask             0xF0
00268 #define defBaseNoBlocksTask            0xE0
00269 #define defBaseSyncBlockedTask         0xC0
00270 #define defBaseSharedTask              0xA0
00271 #define defBaseFileBlockedTask         0x80
00272 #define defBaseSleepingTask            0x40
00273 #define defBaseSuspendedTask           0x20
00274 #define defBaseTerminatedTask          0x10
00275 
00276 /* Definition of the shift values for the numerics */
00277 #define defBasePrioShift               1
00278 
00279 
00280 /* Definition of the uiInitialStatus (start-state) byte
00281  * 8 bit structure: mmsipppt
00282  * mm:   start-mode:  (terminated, suspended, sleeping, running)
00283  * s:    shared-state  (set/reset)
00284  * i     tick interrupt (set/reset)
00285  * ppp:  priority
00286  * t:    global interrupt (set/reset)
00287  *
00288  * The mode has the following meaning
00289  * 00 start suspended
00290  * 01 start sleeping
00291  * 11 start running (or shared depending on share bit)
00292  *
00293  * To come from these states to the task status we must translate
00294  * (only first nibble)
00295  *
00296  * 00x => 0001 (terminated)
00297  * 00x => 001x (suspended)
00298  * 01x => 011x (sleeping)
00299  * 111 => 101x (shared)
00300  * 110 => 111x (running)
00301  *
00302  * Converting from start-state to task-state requires the elimination
00303  * of the shared task bit. That bit is the most significant bit of the
00304  * start-state but is absent in the task status byte.
00305  */
00306 
00307 #define defInitialStartGetMask         0xC0
00308 #define defInitialSharedGetMask        0x20
00309 #define defInitialInterruptGetMask     0x11
00310 #define defInitialPriorityGetMask      0x0E
00311 
00312 #define defInitialStartSetMask         (~defInitialStartGetMask)
00313 #define defInitialSharedSetMask        (~defInitialSharedGetMask)
00314 #define defInitialInterruptSetMask     (~defInitialInterruptGetMask)
00315 #define defInitialPrioritySetMask      (~defInitialPriorityGetMask)
00316 
00317 #define defInitialInterruptAbsent      0x00
00318 #define defInitialSharePresent         0x20
00319 #define defInitialShareAbsent          0x00
00320 
00321 
00322 /* Definitions for initialization control Note that the first
00323  * two bits of this format are reserved for the copy pattern
00324  * given by defRestartSuspended, defRestartSleeping,
00325  * defRestartDefault or defRestartRunning.  These defintions
00326  * are closely coupled to the defInitial ones. Do
00327  * not just change them. */
00328 #define defInitContextGetMask          0x20
00329 #define defInitProcessGetMask          0x10
00330 #define defInitSharedGetMask           0x08
00331 #define defInitStatusCopyGetMask       0x04
00332 #define defInitStatusPrioGetMask       0x02
00333 #define defInitLockGetMask             0x01
00334 
00335 #define defInitStatusStartSetMask      (~defInitStatusStartGetMask)
00336 #define defInitStatusCopySetMask       (~defInitStatusCopyGetMask)
00337 #define defInitContextSetMask          (~defInitContextGetMask)
00338 #define defInitProcessSetMask          (~defInitProcessGetMask)
00339 #define defInitStatusPrioSetMask       (~defInitStatusPrioGetMask)
00340 #define defInitLockSetMask             (~defInitLockGetMask)
00341 
00342 #define defInitContextRenew            0x20
00343 #define defInitContextKeep             0x00
00344 #define defInitProcessAll              0x10
00345 #define defInitProcessSharedOnly       0x00
00346 #define defInitSharedActive            0x08
00347 #define defInitSharedPassive           0x00
00348 #define defInitStatusCopyDo            0x04
00349 #define defInitStatusCopyDont          0x00
00350 #define defInitStatusPrioRenew         0x02
00351 #define defInitStatusPrioKeep          0x00
00352 #define defInitLockRelease             0x01
00353 #define defInitLockKeep                0x00
00354 
00355 
00356 
00357 
00358 /* Definitions for the uiFsStatus byte. The whole state of the Femto File System is
00359  * kept in one byte. 8 bit structure: rwqbtttt
00360  * r: read mode, reading is possible, all blocking FS tasks are write request.
00361  * w: write mode, one task has access, further tasks are blocked.
00362  * q: request bit, if set, write is requested, no further reads are allowed.
00363  * b: burn block. As long as this bit is set, writing is prohibited.
00364  * tttt: number of the task currently writing the FS in case of writemode
00365  * tttt: number of tasks holding a readlock in case of readmode
00366  */
00367 
00368 /* Definitions for the File System */
00369 
00370 #define defFsReadBlockGetMask          0x80
00371 #define defFsWriteBlockGetMask         0x40
00372 #define defFsSleepRequestGetMask       0x20
00373 #define defFsBurnBlockGetMask          0x10
00374 #define defFsWriteNumberGetMask        0x0F
00375 #define defFsReadCountGetMask          0x0F
00376 #define defFsFreeGetMask               (~defFsSleepRequestGetMask)
00377 
00378 #define defFsReadBlockSetMask          (~defFsReadBlockGetMask)
00379 #define defFsWriteBlockSetMask         (~defFsWriteBlockGetMask)
00380 #define defFsSleepRequestSetMask       (~defFsSleepRequestGetMask)
00381 #define defFsBurnBlockSetMask          (~defFsBurnBlockGetMask)
00382 #define defFsWriteNumberSetMask        (~defFsWriteNumberGetMask)
00383 #define defFsReadCountSetMask          (~defFsReadCountGetMask)
00384 #define defFsFreeSetMask               (~defFsFreeGetMask)
00385 
00386 #define defFsReadBlockActive           0x80
00387 #define defFsReadBlockReleaseRequest   0x80
00388 #define defFsWriteBlockActive          0x40
00389 #define defFsSleepRequestActive        0x20
00390 #define defFsBurnBlockActive           0x10
00391 #define defFsReadBlockClear            0x00
00392 #define defFsWriteBlockClear           0x00
00393 #define defFsSleepRequestClear         0x00
00394 #define defFsBurnBlockClear            0x00
00395 #define defFsFree                      0x00
00396 
00397 #define defFsSetReleaseRequest         (defFsReadBlockReleaseRequest | defFsWriteBlockActive | defFsBurnBlockActive)
00398 #define defFsReadInc                   0x01
00399 
00400 #define defFsField                     uiTaskMonitor
00401 #define defFsReadGetMask               0x80
00402 #define defFsWriteGetMask              0x40
00403 #define defFsReadSetMask               (~defFsReadGetMask)
00404 #define defFsWriteSetMask              (~defFsWriteGetMask)
00405 #define defFsReadActive                0x80
00406 #define defFsReadClear                 0x00
00407 #define defFsWriteActive               0x40
00408 #define defFsWriteClear                0x00
00409 
00410 
00411 
00412 /* Definition of the Task Monitor byte
00413  * 8 bit structure: rws.wwrr
00414  * rw:    read,write mode for the filesystem (if needed)
00415  * s:     suspend request
00416  * .:     unused
00417  * ww:    watchdog countdown
00418  * rr:    return state (if a return is needed, the value true/false)
00419  * Note: the T status and the return state must be located on the same
00420  * byte sine they are used to the context save for processing.
00421  */
00422 
00423 
00424 
00425 /* Definition of the fields */
00426 #define defDogField                    uiTaskMonitor
00427 #define defRetField                    uiTaskMonitor
00428 #define defSusField                    uiTaskMonitor
00429 
00430 /* Definitions of the masks you need to read a specific state.  Note
00431  * that the position of the Ret bits is not totally free. If changed,
00432  * also consider the effects upon the xOS.pxSave.uiReturn background
00433  * variable and coupled assembly statements, and the value of the
00434  * defParaRetToRetShift parameter.  */
00435 #define defDogGetMask                  0x0C
00436 #define defRetGetMask                  0x03
00437 #define defSusGetMask                  0x20
00438 
00439 /* Definitions of the masks you need to write a specific state.*/
00440 #define defRetSetMask                  (~defRetGetMask)
00441 #define defDogSetMask                  (~defDogGetMask)
00442 #define defSusSetMask                  (~defSusGetMask)
00443 
00444 
00445 /* Definitions of the states. Note these are 'counted' or shiftable states,
00446  * so do not change the order or values. Counted states are states the are
00447  * changed from one value to an other with a counter. Shiftable states are
00448  * states that are coupled to other states. These values cannot be changed
00449  * without detailed inspection of the code. defRetLoop is not used at the
00450  * moment and will not lead to a returned value.
00451  * The RetNone value is coupled to 0x03 and not to 0x00 so we can easily
00452  * use the result directly as output when it must be true (0x01) or false
00453  * (0x00). */
00454 #define defDogDead                     0x00
00455 #define defDogBark                     0x04
00456 #define defDogWake                     0x08
00457 #define defDogSleep                    0x0C
00458 #define defRetFalse                    0x00
00459 #define defRetTrue                     0x01
00460 #define defRetLoop                     0x02
00461 #define defRetNon                      0x03
00462 
00463 /* these are not shiftable*/
00464 #define defSusRequest                  0x20
00465 #define defSusClear                    0x00
00466 
00467 /* Definition of the shift values for the numerics */
00468 #define defRetShift                    0
00469 #define defDogShift                    2
00470 
00471 /* Definition of the occupied bits for the return value */
00472 #define defRet0                        0
00473 #define defRet1                        1
00474 
00475 /* Definition of the count values for the numerics */
00476 #define defDogDec                      0x04
00477 
00478 
00479 /* To check the suspend mode we need a few masks (generates shorter code) */
00480 #define  defSuspendNowGetMask          0x01
00481 #define  defSuspendCheckGetMask        0x02
00482 #define  defSuspendClearGetMask        0x04
00483 
00484 
00485 /* Definition of the Task Levels byte
00486  *
00487  * 8 bit structure: sssttggg (width's are variable)
00488  * ggg:   counter for levels of global critical sections
00489  * tt:    counter for levels of tick critical sections
00490  * sss:   counter for levels of switch critical sections
00491  */
00492 
00493 #if (cfgIntGlobalOnly == cfgTrue)
00494   #define defNumGlobWidth              (cfgNumGlobWidth + cfgNumTickWidth)
00495   #define defNumTickWidth              (0)
00496   #define defNumSwitchWidth            (cfgNumSwitchWidth)
00497 #else
00498   #define defNumGlobWidth              (cfgNumGlobWidth)
00499   #define defNumTickWidth              (cfgNumTickWidth)
00500   #define defNumSwitchWidth            (cfgNumSwitchWidth)
00501 #endif
00502 
00503 #define defGlobField                   uiTaskLevels
00504 #define defGlobShift                   (0)
00505 #define defGlobGetMask                 (( (1 << defNumGlobWidth) - 1) << defGlobShift)
00506 #define defGlobSetMask                 (~defGlobGetMask)
00507 #define defGlobInc                     (1 << defGlobShift)
00508 #define defGlobMax                     (defGlobGetMask)
00509 #define defGlobMin                     (0x00)
00510 
00511 #define defTickField                   uiTaskLevels
00512 #define defTickShift                   (defNumGlobWidth)
00513 #define defTickGetMask                 (( (1 << defNumTickWidth) - 1) << defTickShift)
00514 #define defTickSetMask                 (~defTickGetMask)
00515 #define defTickInc                     (1 << defTickShift)
00516 #define defTickMax                     (defTickGetMask)
00517 #define defTickMin                     (0x00)
00518 
00519 #define defSwitchField                 uiTaskLevels
00520 #define defSwitchShift                 (defNumGlobWidth + defNumTickWidth)
00521 #define defSwitchGetMask               (( (1 << defNumSwitchWidth) - 1) << defSwitchShift)
00522 #define defSwitchSetMask               (~defSwitchGetMask)
00523 #define defSwitchInc                   (1 << defSwitchShift)
00524 #define defSwitchMax                   (defSwitchGetMask)
00525 #define defSwitchMin                   (0x00)
00526 
00527 
00528 
00529 /* Initializer for the Task Monitor field */
00530 #if (defUseBoolReturns == cfgTrue)
00531   #define defTaskMonitorInit           ( defFsReadClear | defFsWriteClear | defSusClear | defDogDead | defRetNon )
00532 #else
00533   #define defTaskMonitorInit           ( defFsReadClear | defFsWriteClear | defSusClear | defDogDead )
00534 #endif
00535 
00536 /* Initializer for the Task levels field */
00537 #define defTaskLevelsInit              ( defGlobMin | defSwitchMin )
00538 
00539 
00543 #define defInitCPUStatusRegister   (portInitCPUStatusRegister & ~((1 << portInitModeInterruptLoc) | (1 << portInitGlobalInterruptLoc) | (1 << portInitTickInterruptLoc)) )
00544 
00545 /* Definitions for the Queu subfield. Note that the Write- and ReadEmpty bytes are, and
00546  * must be, 0x00. This is because upon initial use we want to make use of the .bss cleaning,
00547  * to save code. The values of the StateFull/StateNotFull must be defined accordingly.
00548  * A special state for the empty queu cannot be defined if we demand that there is no
00549  * initialization before first use of the queu mechanism. Note that for emptying a queu
00550  * it suffices to write the Empty values to the queu filling variable. */
00551 #define defQueuFillingWriteEmpty       0x00
00552 #define defQueuFillingReadEmpty        0x00
00553 #define defQueuFillingGetMask          0x80
00554 #define defQueuFillingSetMask          (~defQueuFillingGetMask)
00555 #define defQueuFillingStateFull        0x80
00556 #define defQueuFillingStateNotFull     0x00
00557 
00558 
00559 /* Definitions for the uiOsStatus byte. The whole state of the Femto OS is kept in one byte.
00560  * 8 bit structure: ccnstttt
00561  * cc:   context state of the OS: This indicates in which state the OS is at the moment.
00562  * n:    presence of a near wake: one or more tasks have to waked with 256 ticks.
00563  * s:    share bit. If set we have shared task running.
00564  * tttt: number of the current task: Number of the task that is currently running.
00565  */
00566 
00567 /* Definitions of the masks you need to read a specific state */
00568 #define defContextGetMask              0xC0
00569 #define defNearWakeStateGetMask        0x20
00570 #define defShareStateGetMask           0x10
00571 #define defTaskNumberGetMask           0x0F
00572 
00573 /* Definitions of the masks you need to write a specific state */
00574 #define defContextSetMask              (~defContextGetMask)
00575 #define defNearWakeStateSetMask        (~defNearWakeStateGetMask)
00576 #define defShareStateSetMask           (~defShareStateGetMask)
00577 #define defTaskNumberSetMask           (~defTaskNumberGetMask)
00578 
00579 /* Definition for the context state determination.
00580  * We defined two bits to mark in which situation the system is. That can be sleeping,
00581  * isr, idle, task or OS. These are five states, but since we can never mixup a
00582  * sleep state with an isr state we may choose the same id for both states, and thus
00583  * save a one bit. So this can be coded using 2 bits.
00584  * In the portSaveContext the defContextStateSaveBit definition is used to test the
00585  * particular bit. If it is set, the saveContext itself is skipped, since it is assumed
00586  * we come from an idle or sleep state. Make sure this definition relates to the other
00587  * defContext definitions.
00588  * Note you cannot just change these definitions to you liking, assembly code has to
00589  * be adapted as well.
00590  */
00591 #define defContextStateSaveBit         7
00592 #define defContextStateSleep           0xC0
00593 #define defContextStateIsr             0xC0
00594 #define defContextStateIdle            0x80
00595 #define defContextStateTask            0x40
00596 #define defContextStateOs              0x00
00597 
00598 /* Definitions for the nearwake and switch state. */
00599 #define defNearWakeStatePresent        0x20
00600 #define defNearWakeStateAbsent         0x00
00601 #define defShareStateRunning           0x10
00602 #define defShareStateAbsent            0x00
00603 
00604 /* Definition of the shift values for the numerics */
00605 #define defOsTaskNumberShift           0
00606 #define defFsTaskNumberShift           0
00607 #define defFsCounterShift              0
00608 
00609 /* These are results mask for the privSwitchContext() method. Make sure all defs are
00610  * bitwise unique. It tells the Femto OS what action to take, and if the Watchdog
00611  * has barked.
00612  */
00613 #define defAssignmentSleep             0x80
00614 #define defAssignmentIdle              0x40
00615 #define defAssignmentTask              0x00
00616 #define defAssignmentWatchdog          0x10
00617 #define defAssignmentAbsent            0x00
00618 
00619 /* Definitions for parameter passing in the synchronization sections. Note that the
00620  * SyncRetState patterns are coupled to the defRetXXX bit patterns. Do not alter just
00621  * like that. Msb is still free for use.*/
00622 #define defParaLockMask                0x40
00623 #define defParaLockStateUnlock         0x40
00624 #define defParaLockStateKeep           0x00
00625 #define defParaRetMask                 0x30
00626 #define defParaRetStateNon             0x30
00627 #define defParaRetStateLoop            0x20
00628 #define defParaRetStateTrue            0x10
00629 #define defParaRetStateFalse           0x00
00630 #define defParaRetToRetShift           4
00631 
00632 
00633 /* In privOperateSlotStack we make use control bits derived from the task status.
00634  * Referencing is done only to make sure we have no bit collisions, and does
00635  * not have a further meaning, except for the block state (defSlotLoopBlockMask)
00636  * which is internally derived in privOperateSlotStack*/
00637 #define defSlotLoopBlockMask           defBaseBlockStateGetMask
00638 #define defSlotLoopSearchMask          defBaseDelayStateGetMask
00639 #define defSlotLoopBlockBlocked        defBaseBlockStateBlocked
00640 #define defSlotLoopBlockNon            defBaseBlockStateFree
00641 #define defSlotLoopSearchActive        defBaseDelayStateWake
00642 #define defSlotLoopSearchNon           defBaseDelayStateDelayed
00643 
00644 /* Operations below must occupy mutual exclusive bits */
00645 #define defSlotOperateIncreaseMask     0x10
00646 #define defSlotOperateDecreaseMask     0x20
00647 #define defSlotOperateSQMMask          0x40
00648 #define defSlotOperateSFreeMask        0x80
00649 #define defSlotOperateIncreaseAction   0x10
00650 #define defSlotOperateDecreaseAction   0x20
00651 #define defSlotOperateNoAction         0x00
00652 #define defSlotOperateSearchDefault    0x00
00653 #define defSlotOperateQMAbsent         0x40
00654 #define defSlotOperateSearchFree       0x80
00655 
00656 /* There are two slots per byte */
00657 #define defSlotLeftGetMask             0xF0
00658 #define defSlotRightGetMask            0x0F
00659 #define defSlotLeftSetMask             (~defSlotLeftGetMask)
00660 #define defSlotRightSetMask            (~defSlotRightGetMask)
00661 #define defSlotLeftShift               4
00662 #define defSlotRightShift              0
00663 
00664 /* This is the free slot */
00665 #define defSlotFree                    0x00
00666 #define defSlotLeftFree                0x00
00667 #define defSlotRightFree               0x00
00668 
00669 /* Slot mask for slot flash definition */
00670 #define defSlotDepthMask               0x07
00671 #define defSlotDepthAbsent             0x00
00672 
00673 
00674 /* Definitions for the handling of the checks on the stack
00675  * (avr specific, thought through the portable section usable for other
00676  * purposes. These cannot be changed since their structure is 'hardcoded'
00677  * in the portable sections of the code. Check before you change! */
00678 #define defCheckStackBit               7
00679 #define defCheckStackGetMask           0x80
00680 #define defCheckStackStateError        0x80
00681 #define defCheckStackStateOK           0x00
00682 
00683 /* Definitions for switching and ticking  */
00684 #define defActionNone                  0x00
00685 #define defActionTaskGetMask           0x01
00686 #define defActionTickGetMask           0x02
00687 #define defActionRunGetMask            (defContextStateTask)
00688 #define defActionTaskStateSwitch       0x01
00689 #define defActionTaskStateKeep         0x00
00690 #define defActionTickStateTick         0x02
00691 #define defActionTickStateNone         0x00
00692 #define defActionRunStateIdle          (defContextStateTask)
00693 #define defActionRunStateTask          0x00
00694 
00695 /* Definition used to check slot numbers */
00696 #define defCheckSlotTypeError          0xF0
00697 
00698 /* Definition to fire all events */
00699 #define defAllEventsSet                0xFF
00700 #define defAllEventsReset              0x00
00701 
00702 
00703 /* Definitions for the error handling */
00704 #define errSignLeft                    7
00705 #define errSignRight                   6
00706 #define errTaskStateGetMask            0x80
00707 #define errOsStateGetMask              0x40
00708 #define errMessageGetMask              0x3F
00709 #define errCallIdGetMask               0x3F
00710 
00711 #define errTaskStateCurrent            0x80
00712 #define errTaskStateNon                0x00
00713 #define errTaskStateInfo               0x00
00714 #define errOsStateForce                0x40
00715 #define errOsStateAsIs                 0x00
00716 
00717 
00718 
00719 #define errTaskNumberGetMask           0x0F
00720 #define errInfoNumberGetMask           0xF0
00721 #define errSignGetMask                 0xC0
00722 #define errTaskNumberSetMask           (~errTaskNumberGetMask)
00723 #define errInfoNumberSetMask           (~errInfoNumberGetMask)
00724 #define errSignSetMask                 (~errSignGetMask)
00725 
00726 #define errFatalError                  0x20
00727 #define errNoInfo                      0x00
00728 #define errCurrentTask                 0x00
00729 #define errTaskNumberShift             0
00730 #define errInfoNumberShift             4
00731 #define errTraceErrorBase              0xC0
00732 
00733 
00734 /* All system internal calls on operation on the interrupt status
00735  * are routed trough privXXX. The mapping is given below, and depends
00736  * on the setting of the configuration parameters. */
00737 
00738 #define privEnableGlobalInterrupts()       portEnableGlobalInterrupts()
00739 #define privDisableGlobalInterrupts()      portDisableGlobalInterrupts()
00740 #define privEnableTickInterrupts()         portEnableTickInterrupts()
00741 #define privDisableTickInterrupts()        portDisableTickInterrupts()
00742 #define privEnterGlobalCritical()          portEnterGlobalInterrupts()
00743 #define privExitGlobalCritical()           portExitGlobalInterrupts()
00744 
00745 #if (cfgIntGlobalOnly == cfgTrue)
00746   #define privEnterSysCritical()           portEnterGlobalInterrupts()
00747   #define privExitSysCritical()            portExitGlobalInterrupts()
00748 #elif (cfgIntOsProtected == cfgTrue)
00749   #define privEnterSysCritical()           portEnterGlobalInterrupts()
00750   #define privExitSysCritical()            portExitGlobalInterrupts()
00751 #else
00752   #define privEnterSysCritical()           portEnterTickInterrupts()
00753   #define privExitSysCritical()            portExitTickInterrupts()
00754 #endif
00755 
00756 /* Stack manipulation definitions. */
00757 #if (defStackSpaceExceedsOneByte == cfgTrue)
00758   #define privInitStack portSetFullStack
00759   #define privSetStack  portSetFullStack
00760   #define privGetStack  portGetFullStack
00761 #else
00762   #define privInitStack portSetFullStack
00763   #define privSetStack  portSetReducedStack
00764   #define privGetStack  portGetReducedStack
00765 #endif
00766 
00767 /* Re-routing for event tracking */
00768 #if (cfgCheckTrace == cfgTrue)
00769   #define privTrace(Event)                  portTrace(Event)
00770   #define privTraceAPI(CallID)              portTrace((traceAPIcallBase | CallID))
00771   #define privShowReset()                   do { portTrace(traceReset); portShowReset(); } while(false)
00772 #else
00773   #define privTrace(Event)
00774   #define privShowReset()                   portShowReset()
00775   #define privTraceAPI(CallID)
00776 #endif
00777 
00778 
00779 #endif /* FEMTOOS_LOCALS_H */

Generated on Fri Oct 16 00:05:21 2009 for FemtoOS by  doxygen 1.5.2