Wiley.Symbian.OS.Internals.Real.time.Kernel.Programming.Dec.2005.eBook-DDU (779891), страница 45
Текст из файла (страница 45)
Never negative, but could be zero for timersexpiring at the same time.iPeriodPeriod of this timer in OS ticks or zero for a one-shottimer.TIMERSField203DescriptioniPtrArgument passed to callback function when thistimer expires.iCallBackPointer to function to be called when this timerexpires.iLastLockIf this timer is being used to implement a SymbianOS ‘‘locked’’ timer, this holds the value ofTTickQ::iRtc at the last expiry of this timer.
If thistimer is not being used for a locked timer or has notyet expired, this value is −1.Summary of fields in TTickQ:FieldDescriptioniNext, iPrevLink pointers used to point to first and last entries on a time-orderedqueue of TTickLink objects.iLastDeltaNumber of OS ticks which elapse between the last tick timer expiry andthe time when iMsTimer next triggers – used to incrementiLastTicks and iRtc.iLastTicksOS tick count at point when iMsTimer last triggered.iRtcThe absolute time at the point when iMsTimer last triggered, measuredin nominal OS ticks from 00:00:00 1st January 0AD.iTickPeriodThe current actual length of an OS tick in microseconds.
This may differfrom the nominal tick period if a tracking system is being used to makethe iRtc value follow a hardware RTC. This value may change as aresult of the operation of any such tracking system.iTicksPerSecondNumber of nominal OS ticks in one second of elapsed time.iNominalTickPeriodThe nominal length of an OS tick in microseconds. This value is neverchanged, unlike iTickPeriod.iInTickBoolean flag set to indicate that processing of the tick queue initiated byiMsTimer expiry is underway.iRoundingThe number of microseconds added to the last delta value wheniMsTimer was last set up in order to make the period an integralnumber of nanokernel timer ticks.204KERNEL SERVICESFieldDescriptioniPrevRoundingThe value of iRounding at the point where iMsTimer last triggered.
Each timethe timer is queued, iPrevRounding is used in the calculation of when thetimer should trigger and the rounding applied to that time to obtain an integralnumber of nanokernel ticks is stored in iRounding.iLastMsThe nanokernel tick count at which iMsTimer last triggered.iMsTickPeriodThe period of the nanokernel tick in microseconds.iTickDfcDFC queued by the expiry of iMsTimer. Runs in context of TimerThread andprocesses any Symbian OS timers which have just expired.iMsTimerNanokernel timer used to initiate Symbian OS timer processing. It is alwaysqueued to trigger at the time when the next TtickLink timer should expire.5.5.2.1 Second timersSecond timers are used when an event needs to occur at a specificdate and time of day rather than after a specified interval, and aretypically used for system alarms.
They have a resolution of 1 second. They will also power up the system at the expiry time if theyneed to.We represent a second timer by a TSecondLink object and attachactive timers to a TSecondQ absolute timer queue object, of which asingle instance exists. Each TSecondLink stores the absolute time atwhich it should trigger (measured in nominal OS ticks from 00:00:00 1stJanuary 0AD UTC) and they are linked into the queue in chronologicalorder of expiry time, earliest first.
The second timer queue is drivenfrom the tick timer queue. It contains a TTickLink timer which is setto expire at either the trigger time of the first TSecondLink on thequeue or at the next midnight local time, whichever is the earlier. Whenthis TTickLink timer triggers, it calls back the handlers for TSecondLink timers that have expired, and then requeues the TTickLinktimer. The same mutex (timer mutex) is used to protect the TTickQ andTSecondQ objects, and the handlers are called with the timer mutexheld.
We use the expiry at midnight to signal change notifiers thatmidnight crossover has occurred. In a similar way to TTickQ, whena new TSecondLink is queued, the TTickLink timer may need tobe canceled and requeued, unless it is queued from inside the TSecondQ expiry handler. Again we use an iInTick field to indicate thelatter condition.TIMERS205Summary of fields in TSecondLink:FieldDescriptioniNext, iPrevLink pointers used to attach this object to the system absolute timerqueue (TSecondQ).iTimeThe absolute time when this timer should trigger, measured innominal OS ticks from 00:00:00 1st January 0AD.iPtrArgument passed to callback function when this timer expires.iCallBackPointer to function to be called when this timer expires.Summary of fields in TSecondQ:FieldDescriptioniNext, iPrevLink pointers used to point to first and last entries in a time-orderedqueue of TSecondLink objects.iExpiredBoolean flag set when any TSecondLink timer expires and cleared bythe power model just before initiating the machine power downsequence.
Used by the power model to abort power down if anabsolute timer expires during the power-down sequence.iInTickBoolean flag set to indicate that processing of the second timer queueinitiated by iTimer expiry is underway.iNextTriggerThe absolute time when iTimer will next trigger, measured innominal OS ticks from 00:00:00 1st January 0AD.iMidnightThe absolute time of the next midnight, measured in nominal OS ticksfrom 00:00:00 1st January 0AD.iTicksPerDayNumber of nominal OS ticks in 1 day.iTimerTTickLink timer object used to initiate second queue timerprocessing. It is always queued to trigger either at the time when thenext TSecondLink timer should expire or at the next midnight,whichever is earlier.iWakeUpDfcDFC used to restart the TTickQ and TSecondQ following machinepower down and power up and changes to the system time.206KERNEL SERVICES5.6 SummaryIn this chapter, I have described the wide variety of services that EKA2provides, both to user-mode threads and within the kernel too.
I havealso described the basic objects used by the kernel, and the handlemechanism used to identify them.A key part of the executive call was the SWI instruction, or softwareinterrupt, used to switch the processor from user mode to supervisormode. In the next chapter, I will look at software interrupts – and hardwareinterrupts, exceptions, faults and traps – in more detail.6Interrupts and Exceptionsby Dennis MayEinstein argued that there must be simplified explanations of nature,because God is not capricious or arbitrary. No such faith comforts thesoftware engineer.Fred BrooksWhen talking about microprocessors, we use the term exception torefer to any event, other than the execution of explicit branch or jumpinstructions, which causes the normal sequential execution of instructionsto be modified.
On processor architectures with multiple privilege levels,these events typically cause a transition from a less privileged executionlevel to a more privileged one.On the types of processor that run Symbian OS, there are many eventsthat cause exceptions. These events form six categories, which I willdescribe in the next six sections of this chapter. Although the wordsused to describe the categories are the same throughout the computerindustry, their exact meanings tend to differ – so, even if you are familiarwith this subject, please do skim these next few sections. In Symbian, wecategorize the events from the perspective of the software event handlers,so our terms will probably not match the categories given by people whodefine them from a processor architecture perspective.Whenever an exception occurs, the processor stops what it was doing,and begins execution in a defined state from a (new) defined location.But before doing so, it may save some information, such as the programcounter, to allow the original program flow to be resumed.
Whether thisoccurs, and how much information is saved, depends on the nature ofthe exception. I will say more on this later.6.1 Exception types6.1.1 InterruptsAn interrupt is an exception that is not caused directly by programexecution. In most cases, hardware external to the processor core signals208INTERRUPTS AND EXCEPTIONSan interrupt – for example, peripheral devices indicate that they havedata available or require data to be supplied. What differentiates aninterrupt from other exceptions is that it occurs asynchronously to programexecution; in other words, it is not caused by the sequential execution ofan instruction.
Usually an interrupt is serviced as soon as the currentlyexecuting instruction is complete, although on some processors interruptsmay occur in the middle of an instruction, and on others not everyinstruction can be followed by an interrupt.Whenever an interrupt occurs the processor must save enough state toallow the interrupted program to be resumed and to continue executionprecisely as if the interrupt had never occurred. This state always includesthe program counter, which specifies the address of the instruction thatwould have been executed next, had the interrupt not occurred. Thesaved state also includes the processor status and the condition coderegister, which contains the interrupt mask level in effect at the timethe interrupt occurred. The processor will then disable interrupts whosepriority is lower than or equal to that of the one accepted.Interrupts may be maskable or non-maskable.
Maskable interrupts canbe disabled by software; they are then held pending until software enablesthem again. There is no way to turn off non-maskable interrupts – theyare always recognized by the processor.Although the way in which the processor handles interrupts and otherexceptions may be similar, the asynchronous nature of interrupts meansthat their software handlers are very different. In this book, I will alwaysuse the term exception to mean any exception other than an interrupt,and I will always refer to interrupts explicitly by name.6.1.2 ResetsA reset causes the processor to reinitialize its whole state, and to startexecution from a known location in memory.