os/kernelhwsrv/kernel/eka/nkernsmp/arm/nctimer.cia
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\nkernsmp\arm\nctimer.cia
sl@0
    15
// Fast Millisecond Timer Implementation
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include <e32cia.h>
sl@0
    20
#include <arm.h>
sl@0
    21
sl@0
    22
#ifdef __MSTIM_MACHINE_CODED__
sl@0
    23
sl@0
    24
sl@0
    25
#ifdef _DEBUG
sl@0
    26
#define ASM_KILL_LINK(rp,rs)	asm("mov "#rs", #0xdf ");\
sl@0
    27
								asm("orr "#rs", "#rs", "#rs", lsl #8 ");\
sl@0
    28
								asm("orr "#rs", "#rs", "#rs", lsl #16 ");\
sl@0
    29
								asm("str "#rs", ["#rp"] ");\
sl@0
    30
								asm("str "#rs", ["#rp", #4] ");
sl@0
    31
sl@0
    32
#define ASM_KILL_LINK_OFFSET(rp,rs,offset)	asm("mov "#rs", #0xdf ");\
sl@0
    33
											asm("orr "#rs", "#rs", "#rs", lsl #8 ");\
sl@0
    34
											asm("orr "#rs", "#rs", "#rs", lsl #16 ");\
sl@0
    35
											asm("str "#rs", ["#rp", #"#offset"] ");\
sl@0
    36
											asm("str "#rs", ["#rp", #"#offset"+4] ");
sl@0
    37
#else
sl@0
    38
#define ASM_KILL_LINK(rp,rs)
sl@0
    39
#define ASM_KILL_LINK_OFFSET(rp,rs,offset)
sl@0
    40
#endif
sl@0
    41
sl@0
    42
#ifdef _DEBUG
sl@0
    43
#define __DEBUG_CALLBACK(n)	asm("stmfd sp!, {r0-r3,r12,lr} ");		\
sl@0
    44
							asm("ldr r0, __TheTimerQ ");			\
sl@0
    45
							asm("ldr r12, [r0, #%a0]!" : : "i" _FOFF(NTimerQ,iDebugFn));	\
sl@0
    46
							asm("cmp r12, #0 ");					\
sl@0
    47
							asm("movne r1, #" #n );					\
sl@0
    48
							asm("ldrne r0, [r0, #4] ");				\
sl@0
    49
							asm("movne lr, pc ");					\
sl@0
    50
							__JUMP(ne,r12);							\
sl@0
    51
							asm("ldmfd sp!, {r0-r3,r12,lr} ")
sl@0
    52
#else
sl@0
    53
#define __DEBUG_CALLBACK(n)
sl@0
    54
#endif
sl@0
    55
sl@0
    56
sl@0
    57
/** Start a nanokernel timer in zero-drift periodic mode with ISR or DFC callback.
sl@0
    58
	Queues the timer to expire in the specified number of nanokernel ticks,
sl@0
    59
	measured from the time at which it last expired. This allows exact periodic
sl@0
    60
	timers to be implemented with no drift caused by delays in requeueing the
sl@0
    61
	timer.
sl@0
    62
	The expiry handler will be called in the same context as the previous timer
sl@0
    63
	expiry. Generally the way this is used is that NTimer::OneShot() is used to start 
sl@0
    64
	the first time interval and this specifies whether the callback is in ISR context 
sl@0
    65
	or in the context of the nanokernel timer thread (DfcThread1) or other Dfc thread.
sl@0
    66
	The expiry handler then uses NTimer::Again() to requeue the timer.
sl@0
    67
sl@0
    68
	@param	aTime Timeout in nanokernel ticks
sl@0
    69
	@return	KErrNone if no error
sl@0
    70
	@return	KErrInUse if timer is already active
sl@0
    71
	@return	KErrArgument if the requested expiry time is in the past
sl@0
    72
	@pre	Any context
sl@0
    73
 */
sl@0
    74
__NAKED__ EXPORT_C TInt NTimer::Again(TInt /*aTime*/)
sl@0
    75
	{
sl@0
    76
	asm("mrs r12, cpsr ");
sl@0
    77
	INTS_OFF(r3, r12, INTS_ALL_OFF);	// all interrupts off
sl@0
    78
	asm("ldrb r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iState));		// r3=iState
sl@0
    79
	asm("ldr r2, __TheTimerQ ");
sl@0
    80
	asm("cmp r3, #%a0" : : "i" ((TInt)EIdle));
sl@0
    81
	asm("ldreq r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// r3=iTriggerTime
sl@0
    82
	asm("bne add_mscb_in_use ");		// if already queued return KErrInUse
sl@0
    83
	asm("add r3, r3, r1 ");				// add requested time interval
sl@0
    84
	asm("ldr r1, [r2, #%a0]" : : "i" _FOFF(NTimerQ,iMsCount));		// r1=iMsCount
sl@0
    85
	asm("subs r1, r3, r1 ");			// r1=trigger time-next tick time
sl@0
    86
	asm("strpl r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// iTriggerTime+=aTime
sl@0
    87
	asm("bpl AddMsCallBack ");			// if time interval positive, ok
sl@0
    88
	asm("mov r0, #%a0" : : "i" ((TInt)KErrArgument));	// else return KErrArgument
sl@0
    89
	asm("b add_mscb_0 ");
sl@0
    90
	}
sl@0
    91
sl@0
    92
sl@0
    93
/** Start a nanokernel timer in one-shot mode with ISR callback.
sl@0
    94
	Queues the timer to expire in the specified number of nanokernel ticks. The
sl@0
    95
	actual wait time will be at least that much and may be up to one tick more.
sl@0
    96
	The expiry handler will be called in ISR context.
sl@0
    97
sl@0
    98
	@param	aTime Timeout in nanokernel ticks
sl@0
    99
	@return	KErrNone if no error
sl@0
   100
	@return	KErrInUse if timer is already active
sl@0
   101
	@pre	Any context
sl@0
   102
 */
sl@0
   103
__NAKED__ EXPORT_C TInt NTimer::OneShot(TInt /*aTime*/)
sl@0
   104
	{
sl@0
   105
	asm("mov r2, #0 ");
sl@0
   106
	// fall through
sl@0
   107
	}
sl@0
   108
sl@0
   109
sl@0
   110
/** Start a nanokernel timer in one-shot mode with ISR or DFC callback.
sl@0
   111
	Queues the timer to expire in the specified number of nanokernel ticks. The
sl@0
   112
	actual wait time will be at least that much and may be up to one tick more.
sl@0
   113
	The expiry handler will be called in either ISR context or in the context
sl@0
   114
	of the nanokernel timer thread (DfcThread1).
sl@0
   115
sl@0
   116
	@param	aTime Timeout in nanokernel ticks
sl@0
   117
	@param	aDfc TRUE if DFC callback required, FALSE if ISR callback required.
sl@0
   118
	@return	KErrNone if no error
sl@0
   119
	@return	KErrInUse if timer is already active
sl@0
   120
	@pre	Any context
sl@0
   121
 */
sl@0
   122
__NAKED__ EXPORT_C TInt NTimer::OneShot(TInt /*aTime*/, TBool /*aDfc*/)
sl@0
   123
	{
sl@0
   124
	asm("mrs r12, cpsr ");
sl@0
   125
	INTS_OFF(r3, r12, INTS_ALL_OFF);	// all interrupts off
sl@0
   126
	asm("ldrb r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iState));		// r3=iState
sl@0
   127
	asm("cmp r3, #%a0" : : "i" ((TInt)EIdle));
sl@0
   128
	asm("bne add_mscb_in_use ");		// if already queued return KErrInUse
sl@0
   129
	asm("strb r2, [r0, #%a0]" : : "i" _FOFF(NTimer,iCompleteInDfc));	// iCompleteInDfc=aDfc
sl@0
   130
	asm("ldr r2, __TheTimerQ ");
sl@0
   131
	asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(NTimerQ,iMsCount));	// r3=iMsCount
sl@0
   132
	asm("add r3, r3, r1 ");
sl@0
   133
	asm("str r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// iTriggerTime=ms count + aTime
sl@0
   134
sl@0
   135
	// r0->CallBack, r2=TheTimerQ, r1=time interval, r3=trigger time
sl@0
   136
	asm("AddMsCallBack: ");
sl@0
   137
	asm("cmp r1, #32 ");				// compare interval with 32ms
sl@0
   138
	asm("bge add_mscb_holding ");		// if >=32ms put it on holding queue
sl@0
   139
	asm("ldrb r1, [r0, #%a0]" : : "i" _FOFF(NTimer,iCompleteInDfc));	// r1=iCompleteInDfc
sl@0
   140
	asm("and r3, r3, #0x1f ");			// r3=trigger time & 0x1f
sl@0
   141
	asm("cmp r1, #0 ");
sl@0
   142
	asm("add r1, r2, r3, lsl #4 ");		// r1->IntQ corresponding to trigger time
sl@0
   143
	asm("addne r1, r1, #8 ");			// if (iCompleteInDfc), r1 points to DfcQ
sl@0
   144
	asm("ldr r3, [r1, #4] ");			// r3=pQ->iA.iPrev
sl@0
   145
	asm("str r0, [r1, #4] ");			// pQ->iA.iPrev=pC
sl@0
   146
	asm("str r0, [r3, #0] ");			// pQ->iA.iPrev->iNext=pC
sl@0
   147
	asm("stmia r0, {r1,r3} ");			// pC->iNext=&pQ->iA, pC->iPrev=pQ->iA.iPrev
sl@0
   148
	asm("mov r1, #%a0" : : "i" ((TInt)EFinal));
sl@0
   149
	asm("strb r1, [r0, #%a0]" : : "i" _FOFF(NTimer,iState));		// iState=EFinal
sl@0
   150
	asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// r0=iTriggerTime
sl@0
   151
	asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(NTimerQ,iPresent));	// r3=TheTimerQ->iPresent
sl@0
   152
	asm("and r0, r0, #0x1f ");
sl@0
   153
	asm("mov r1, #1 ");
sl@0
   154
	asm("orr r3, r3, r1, lsl r0 ");		// iPresent |= (1<<index)
sl@0
   155
	asm("str r3, [r2, #%a0]" : : "i" _FOFF(NTimerQ,iPresent));
sl@0
   156
	asm("mov r0, #0 ");					// return KErrNone
sl@0
   157
	asm("msr cpsr, r12 ");
sl@0
   158
	__JUMP(,lr);
sl@0
   159
sl@0
   160
	asm("add_mscb_holding: ");
sl@0
   161
	asm("ldr r3, [r2, #%a0]!" : : "i" _FOFF(NTimerQ,iHoldingQ.iA.iPrev));	// r3=pQ->iPrev, r2=&iHoldingQ.iA.iPrev
sl@0
   162
	asm("mov r1, #%a0" : : "i" ((TInt)EHolding));
sl@0
   163
	asm("strb r1, [r0, #%a0]" : : "i" _FOFF(NTimer,iState));	// iState=EHolding
sl@0
   164
	asm("str r0, [r2], #-4 ");			// pQ->iPrev=pC, r2=&iHoldingQ
sl@0
   165
	asm("str r0, [r3, #0] ");			// pQ->iPrev->iNext=pC
sl@0
   166
	asm("stmia r0, {r2,r3} ");			// pC->iNext=pQ, pC->iPrev=pQ->iPrev
sl@0
   167
	asm("mov r0, #0 ");					// return KErrNone
sl@0
   168
sl@0
   169
	asm("add_mscb_0: ");
sl@0
   170
	asm("msr cpsr, r12 ");
sl@0
   171
	__JUMP(,lr);
sl@0
   172
sl@0
   173
	asm("add_mscb_in_use: ");
sl@0
   174
	asm("mov r0, #%a0" : : "i" ((TInt)KErrInUse));		// return KErrInUse
sl@0
   175
	asm("msr cpsr, r12 ");
sl@0
   176
	__JUMP(,lr);
sl@0
   177
sl@0
   178
	asm("__TheTimerQ: ");
sl@0
   179
	asm(".word TheTimerQ ");
sl@0
   180
	}
sl@0
   181
sl@0
   182
sl@0
   183
/** Starts a nanokernel timer in one-shot mode with callback in dfc thread that provided DFC belongs to.
sl@0
   184
	
sl@0
   185
	Queues the timer to expire in the specified number of nanokernel ticks. The
sl@0
   186
	actual wait time will be at least that much and may be up to one tick more.
sl@0
   187
	On expiry aDfc will be queued in ISR context.
sl@0
   188
sl@0
   189
    Note that NKern::TimerTicks() can be used to convert milliseconds to ticks.
sl@0
   190
sl@0
   191
	@param	aTime Timeout in nanokernel ticks
sl@0
   192
	@param	aDfc - Dfc to be queued when the timer expires.
sl@0
   193
	
sl@0
   194
	@return	KErrNone if no error; KErrInUse if timer is already active.
sl@0
   195
	
sl@0
   196
	@pre	Any context
sl@0
   197
	
sl@0
   198
	@see    NKern::TimerTicks()
sl@0
   199
 */
sl@0
   200
sl@0
   201
__NAKED__ EXPORT_C TInt NTimer::OneShot(TInt /*aTime*/, TDfc& /*aDfc*/)
sl@0
   202
	{
sl@0
   203
	asm("mrs r12, cpsr ");
sl@0
   204
	INTS_OFF(r3, r12, INTS_ALL_OFF);	// all interrupts off
sl@0
   205
	asm("ldrb r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iState));		// r3=iState
sl@0
   206
	asm("cmp r3, #%a0" : : "i" ((TInt)EIdle));
sl@0
   207
	asm("bne add_mscb_in_use ");		// if already queued return KErrInUse
sl@0
   208
	asm("mov r3, #0 ");
sl@0
   209
	asm("strb r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iCompleteInDfc));	// iCompleteInDfc=0
sl@0
   210
	asm("str r3,  [r0, #%a0]" : : "i" _FOFF(NTimer,iFunction));			// iFunction=NULL
sl@0
   211
	asm("str r2,  [r0, #%a0]" : : "i" _FOFF(NTimer,iPtr));				// iPtr= &aDfc
sl@0
   212
	asm("ldr r2, __TheTimerQ ");
sl@0
   213
	asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(NTimerQ,iMsCount));	// r3=iMsCount
sl@0
   214
	asm("add r3, r3, r1 ");
sl@0
   215
	asm("str r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// iTriggerTime=ms count + aTime
sl@0
   216
	asm("b AddMsCallBack ");
sl@0
   217
	}
sl@0
   218
sl@0
   219
sl@0
   220
/** Cancel a nanokernel timer.
sl@0
   221
	Removes this timer from the nanokernel timer queue. Does nothing if the
sl@0
   222
	timer is inactive or has already expired.
sl@0
   223
	Note that if the timer was queued and DFC callback requested it is possible
sl@0
   224
	for the expiry handler to run even after Cancel() has been called. This will
sl@0
   225
	occur in the case where DfcThread1 is preempted just before calling the
sl@0
   226
	expiry handler for this timer and the preempting thread/ISR/IDFC calls
sl@0
   227
	Cancel() on the timer.
sl@0
   228
sl@0
   229
	@pre	Any context
sl@0
   230
 */
sl@0
   231
EXPORT_C __NAKED__ void NTimer::Cancel()
sl@0
   232
	{
sl@0
   233
	asm("mrs r12, cpsr ");
sl@0
   234
	INTS_OFF(r3, r12, INTS_ALL_OFF);	// all interrupts off
sl@0
   235
	asm("ldrb r3, [r0, #%a0]" : : "i" _FOFF(NTimer,iState));
sl@0
   236
	asm("mov r1, #0 ");
sl@0
   237
	asm("cmp r3, #%a0" : : "i" ((TInt)ETransferring));
sl@0
   238
	asm("bcc cancel_idle ");			// if EIdle, nothing to do
sl@0
   239
	asm("strb r1, [r0, #%a0]" : : "i" _FOFF(NTimer,iState));	// iState=EIdle
sl@0
   240
	asm("beq cancel_xfer ");			// if ETransferring, branch
sl@0
   241
	asm("ldmia r0, {r1,r2} ");			// If queued, dequeue - r1=next, r2=prev
sl@0
   242
	asm("cmp r3, #%a0" : : "i" ((TInt)ECritical));
sl@0
   243
	asm("str r1, [r2, #0] ");			// if queued, prev->next=next
sl@0
   244
	asm("str r2, [r1, #4] ");			// and next->prev=prev
sl@0
   245
	ASM_KILL_LINK(r0,r1);
sl@0
   246
	asm("ldrcs r1, __TheTimerQ ");
sl@0
   247
	asm("ldrhi r0, [r0, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// r0=iTriggerTime
sl@0
   248
	asm("ldrhi r3, [r1, #%a0]" : : "i" _FOFF(NTimerQ,iMsCount));	// r3=iMsCount
sl@0
   249
	asm("bcc cancel_idle ");			// if EHolding or EOrdered, finished
sl@0
   250
	asm("beq cancel_critical ");		// if ECritical, branch
sl@0
   251
										// r1->ms timer, state was EFinal
sl@0
   252
	asm("subs r3, r0, r3 ");			// r3=trigger time - next tick
sl@0
   253
	asm("bmi cancel_idle ");			// if trigger time already expired, don't touch iPresent (was on iCompletedQ)
sl@0
   254
	asm("and r0, r0, #0x1f ");			// r0=iTriggerTime&0x1f = queue index
sl@0
   255
	asm("mov r3, r1 ");
sl@0
   256
	asm("ldr r2, [r3, r0, lsl #4]! ");	// r3->iIntQ for this timer, r2=iIntQ head pointer
sl@0
   257
	asm("cmp r2, r3 ");
sl@0
   258
	asm("bne cancel_idle ");			// iIntQ not empty so finished
sl@0
   259
	asm("ldr r2, [r3, #8]! ");			// r2=iDfcQ head pointer
sl@0
   260
	asm("cmp r2, r3 ");
sl@0
   261
	asm("bne cancel_idle ");			// iDfcQ not empty so finished
sl@0
   262
	asm("ldr r2, [r1, #%a0]" : : "i" _FOFF(NTimerQ,iPresent));	// r2=TheTimerQ->iPresent
sl@0
   263
	asm("mov r3, #1 ");
sl@0
   264
	asm("bic r2, r2, r3, lsl r0 ");		// iPresent &= ~(1<<index)
sl@0
   265
	asm("str r2, [r1, #%a0]" : : "i" _FOFF(NTimerQ,iPresent));
sl@0
   266
sl@0
   267
	asm("cancel_idle: ");
sl@0
   268
	asm("msr cpsr, r12 ");
sl@0
   269
	__JUMP(,lr);
sl@0
   270
sl@0
   271
	asm("cancel_xfer: ");
sl@0
   272
	asm("ldr r1, __TheTimerQ ");		// r1->ms timer, state was ETransferring
sl@0
   273
	asm("strb r3, [r1, #%a0]" : : "i" _FOFF(NTimerQ,iTransferringCancelled));
sl@0
   274
	asm("msr cpsr, r12 ");
sl@0
   275
	__JUMP(,lr);
sl@0
   276
sl@0
   277
	asm("cancel_critical: ");			// r1->ms timer, state was ECritical
sl@0
   278
	asm("strb r3, [r1, #%a0]" : : "i" _FOFF(NTimerQ,iCriticalCancelled));
sl@0
   279
	asm("msr cpsr, r12 ");
sl@0
   280
	__JUMP(,lr);
sl@0
   281
	}
sl@0
   282
sl@0
   283
sl@0
   284
/** Return the number of ticks before the next nanokernel timer expiry.
sl@0
   285
	May on occasion return a pessimistic estimate (i.e. too low).
sl@0
   286
	Used by base port to disable the system tick interrupt when the system
sl@0
   287
	is idle.
sl@0
   288
sl@0
   289
	@return	The number of ticks before the next nanokernel timer expiry.
sl@0
   290
	
sl@0
   291
	@pre	Interrupts must be disabled.
sl@0
   292
	
sl@0
   293
	@post	Interrupts are disabled.
sl@0
   294
 */
sl@0
   295
EXPORT_C __NAKED__ TInt NTimerQ::IdleTime()
sl@0
   296
	{
sl@0
   297
	ASM_CHECK_PRECONDITIONS(MASK_INTERRUPTS_DISABLED);
sl@0
   298
sl@0
   299
	asm("ldr r12, __TheTimerQ ");
sl@0
   300
	asm("mvn r0, #0x80000000 ");		// set r0=KMaxTInt initially
sl@0
   301
	asm("ldr r2, [r12, #%a0]!" : : "i" _FOFF(NTimerQ,iOrderedQ));	// r12->iOrderedQ, r2=iOrderedQ first
sl@0
   302
	asm("ldr r3, [r12, #-12] ");		// r3=next tick number
sl@0
   303
	asm("cmp r2, r12 ");				// check if iOrderedQ empty
sl@0
   304
	asm("ldrne r0, [r2, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// if not, r0=ordered Q first->trigger time
sl@0
   305
	asm("ldr r1, [r12, #-8]! ");		// r1=iHoldingQ first, r12->iHoldingQ
sl@0
   306
	asm("bicne r0, r0, #0x0f ");
sl@0
   307
	asm("subne r0, r0, #16 ");			// r0=tick at which transfer to final queue would occur
sl@0
   308
	asm("subne r0, r0, r3 ");			// return value = trigger time - iMsCount
sl@0
   309
	asm("cmp r1, r12 ");				// holding Q empty?
sl@0
   310
	asm("ldr r1, [r12, #-8] ");			// r1=iPresent
sl@0
   311
	asm("and r12, r3, #0x1f ");			// r12=next tick mod 32
sl@0
   312
	asm("beq 1f ");						// branch if holding Q empty
sl@0
   313
	asm("ands r2, r3, #0x0f ");			// else r2=next tick no. mod 16
sl@0
   314
	asm("rsbne r2, r2, #16 ");			// if nonzero, subtract from 16 to give #ticks before next multiple of 16
sl@0
   315
	asm("cmp r2, r0 ");
sl@0
   316
	asm("movlt r0, r2 ");				// update result if necessary
sl@0
   317
	asm("1: ");
sl@0
   318
	asm("movs r1, r1, ror r12 ");		// r1=iPresent rotated so that LSB corresponds to next tick
sl@0
   319
	__JUMP(eq,lr);						// if iPresent=0, finished
sl@0
   320
	asm("mov r3, #0 ");					// r3 will accumulate bit number of least significant 1
sl@0
   321
	asm("movs r2, r1, lsl #16 ");
sl@0
   322
	asm("movne r1, r2 ");
sl@0
   323
	asm("addeq r3, r3, #16 ");
sl@0
   324
	asm("movs r2, r1, lsl #8 ");
sl@0
   325
	asm("movne r1, r2 ");
sl@0
   326
	asm("addeq r3, r3, #8 ");
sl@0
   327
	asm("movs r2, r1, lsl #4 ");
sl@0
   328
	asm("movne r1, r2 ");
sl@0
   329
	asm("addeq r3, r3, #4 ");
sl@0
   330
	asm("movs r2, r1, lsl #2 ");
sl@0
   331
	asm("movne r1, r2 ");
sl@0
   332
	asm("addeq r3, r3, #2 ");
sl@0
   333
	asm("movs r2, r1, lsl #1 ");
sl@0
   334
	asm("addeq r3, r3, #1 ");
sl@0
   335
	asm("cmp r3, r0 ");
sl@0
   336
	asm("movlt r0, r3 ");				// update result if necessary
sl@0
   337
	__JUMP(,lr);
sl@0
   338
	}
sl@0
   339
sl@0
   340
sl@0
   341
/** Tick over the nanokernel timer queue.
sl@0
   342
	This function should be called by the base port in the system tick timer ISR.
sl@0
   343
	It should not be called at any other time.
sl@0
   344
	The value of 'this' to pass is the value returned by NTimerQ::TimerAddress().
sl@0
   345
sl@0
   346
	@see NTimerQ::TimerAddress()
sl@0
   347
 */
sl@0
   348
__NAKED__ EXPORT_C void NTimerQ::Tick()
sl@0
   349
	{
sl@0
   350
	// Enter with r0 pointing to NTimerQ
sl@0
   351
	asm("ldr r1, __TheScheduler ");
sl@0
   352
	asm("mrs r12, cpsr ");
sl@0
   353
sl@0
   354
	// do the timeslice tick - on ARM __SCHEDULER_MACHINE_CODED is mandatory
sl@0
   355
	asm("ldr r2, [r1, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread));
sl@0
   356
	asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(NThread,iTime));
sl@0
   357
	asm("subs r3, r3, #1 ");
sl@0
   358
	asm("strge r3, [r2, #%a0]" : : "i" _FOFF(NThread,iTime));
sl@0
   359
	asm("streqb r12, [r1, #%a0]" : : "i" _FOFF(TScheduler,iRescheduleNeededFlag));	// r12 lower byte is never 0
sl@0
   360
	INTS_OFF(r3, r12, INTS_ALL_OFF);	// disable all interrupts
sl@0
   361
sl@0
   362
	asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iMsCount));	// r1=iMsCount
sl@0
   363
	asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iPresent));	// r3=iPresent
sl@0
   364
	asm("and r2, r1, #0x1f ");			// r2=iMsCount & 0x1f
sl@0
   365
	asm("add r1, r1, #1 ");
sl@0
   366
	asm("str r1, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iMsCount));	// iMsCount++
sl@0
   367
	asm("mov r1, #1 ");
sl@0
   368
	asm("tst r3, r1, lsl r2 ");			// test iPresent bit for this tick
sl@0
   369
	asm("bic r1, r3, r1, lsl r2 ");		// clear iPresent bit
sl@0
   370
	asm("strne r1, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iPresent));	// update iPresent if necessary
sl@0
   371
	asm("bne mstim_tick_1 ");			// if bit was set, we have work to do
sl@0
   372
	asm("tst r2, #0x0f ");				// else test for tick 0 or 16
sl@0
   373
	asm("msrne cpsr_c, r12 ");			// if neither return
sl@0
   374
	__JUMP(ne,lr);
sl@0
   375
sl@0
   376
	asm("mstim_tick_1: ");				// get here if timers complete this tick
sl@0
   377
	asm("stmfd sp!, {r4-r6,lr} ");
sl@0
   378
	asm("add r1, r0, r2, lsl #4 ");		// r1->IntQ for this tick
sl@0
   379
	asm("ldr r3, [r1, #8]! ");			// r1->DfcQ and r3=DfcQ first
sl@0
   380
	asm("mov r5, #0 ");					// r5=doDfc=FALSE
sl@0
   381
	asm("cmp r3, r1 ");
sl@0
   382
	asm("beq mstim_tick_2 ");			// skip if DfcQ empty
sl@0
   383
sl@0
   384
	// Move DFC completions from iDfcQ to iCompletedQ
sl@0
   385
	asm("ldr lr, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iCompletedQ.iA.iPrev));	// lr=last completed
sl@0
   386
	asm("ldr r4, [r1, #4] ");			// r4=DfcQ last
sl@0
   387
	asm("add r5, r0, #%a0" : : "i" _FOFF(NTimerQ,iDfc));	// doDfc=TRUE
sl@0
   388
	asm("str r3, [lr, #0] ");			// old last pending->next = DfcQ first
sl@0
   389
	asm("str r4, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iCompletedQ.iA.iPrev));	// last pending=DfcQ last
sl@0
   390
	asm("str lr, [r3, #4] ");			// DfcQ first->prev = old last pending
sl@0
   391
	asm("add lr, r0, #%a0" : : "i" _FOFF(NTimerQ,iCompletedQ));				// lr=&iCompletedQ.iA
sl@0
   392
	asm("str lr, [r4, #0] ");			// DfcQ last->next=&iPending
sl@0
   393
	asm("str r1, [r1, #0] ");			// DfcQ first=&DfcQ
sl@0
   394
	asm("str r1, [r1, #4] ");			// DfcQ last=&DfcQ
sl@0
   395
sl@0
   396
	asm("mstim_tick_2: ");
sl@0
   397
	asm("tst r2, #0x0f ");				// check for tick 0 or 16
sl@0
   398
	asm("bne mstim_tick_3 ");			// skip if not
sl@0
   399
sl@0
   400
	// Tick 0 or 16 - must check holding queue and ordered queue
sl@0
   401
	asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iHoldingQ));	// r3=iHoldingQ first
sl@0
   402
	asm("add r6, r0, #%a0" : : "i" _FOFF(NTimerQ,iHoldingQ));	// r6=&iHoldingQ
sl@0
   403
	asm("cmp r3, r6 ");
sl@0
   404
	asm("addne r5, r0, #%a0" : : "i" _FOFF(NTimerQ,iDfc));	// if iHoldingQ nonempty, doDfc=TRUE and skip ordered queue check
sl@0
   405
	asm("bne mstim_tick_3 ");			// skip if iHoldingQ nonempty
sl@0
   406
	asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iOrderedQ));	// r3=iOrderedQ first
sl@0
   407
	asm("add r6, r0, #%a0" : : "i" _FOFF(NTimerQ,iOrderedQ));	// r6=&iOrderedQ
sl@0
   408
	asm("cmp r3, r6 ");
sl@0
   409
	asm("beq mstim_tick_3 ");			// skip if iOrderedQ empty
sl@0
   410
	asm("ldr r4, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iMsCount));		// else r4=iMsCount
sl@0
   411
	asm("ldr r3, [r3, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// and r3=trigger time of first on ordered queue
sl@0
   412
	asm("sub r3, r3, r4 ");				// r3=trigger time-iMsCount
sl@0
   413
	asm("cmp r3, #31 ");
sl@0
   414
	asm("addls r5, r0, #%a0" : : "i" _FOFF(NTimerQ,iDfc));	// if first expiry in <=31ms, doDfc=TRUE
sl@0
   415
sl@0
   416
	// Check iIntQ
sl@0
   417
	asm("mstim_tick_3: ");
sl@0
   418
	asm("ldr r3, [r1, #-8]! ");			// r1->iIntQ, r3=iIntQ first
sl@0
   419
	asm("mov r6, r12 ");				// r6=original cpsr
sl@0
   420
	asm("cmp r3, r1 ");					// test if iIntQ empty
sl@0
   421
	asm("beq mstim_tick_4 ");			// branch if it is
sl@0
   422
sl@0
   423
	// Transfer iIntQ to a temporary queue
sl@0
   424
	asm("ldr r4, [r1, #4] ");			// r4=iIntQ last
sl@0
   425
	asm("str r1, [r1, #0] ");			// clear iIntQ
sl@0
   426
	asm("str r1, [r1, #4] ");
sl@0
   427
	asm("stmfd sp!, {r3,r4} ");			// copy queue onto stack
sl@0
   428
	asm("str sp, [r4, #0] ");			// iIntQ last->next=sp
sl@0
   429
	asm("str sp, [r3, #4] ");			// iIntQ first->prev=sp
sl@0
   430
	INTS_OFF_1(r4, r6, INTS_ALL_OFF);	// r4=cpsr with all interrupts off
sl@0
   431
sl@0
   432
	// Walk the temporary queue and complete timers
sl@0
   433
	asm("mstim_tick_5: ");
sl@0
   434
	INTS_OFF_2(r4, r6, INTS_ALL_OFF);	// all interrupts off
sl@0
   435
	asm("ldr r0, [sp, #0] ");			// r0=q.iNext
sl@0
   436
	asm("mov r3, #%a0" : : "i" ((TInt)NTimer::EIdle));
sl@0
   437
	asm("cmp r0, sp ");					// end of queue?
sl@0
   438
	asm("beq mstim_tick_6 ");			// if so, branch out
sl@0
   439
	asm("ldmia r0!, {r1,r2} ");			// r1=next r2=prev, r0->iPtr
sl@0
   440
	asm("strb r3, [r0, #%a0]" : : "i" (_FOFF(NTimer,iState)-8));	// iState=EIdle
sl@0
   441
	ASM_KILL_LINK_OFFSET(r0,r12,-8);
sl@0
   442
	asm("ldmia r0, {r0,r12} ");			// r0=iPtr, r12=iFunction
sl@0
   443
	asm("str r1, [r2, #0] ");			// prev->next=next
sl@0
   444
	asm("str r2, [r1, #4] ");			// next->prev=prev
sl@0
   445
	asm("adr lr, mstim_tick_5 ");		// return to mstim_tick_5
sl@0
   446
	asm("msr cpsr, r6 ");				// restore interrupts
sl@0
   447
	asm("cmp r12, #0 ");				// iFunction==NULL ?
sl@0
   448
	asm("beq mstim_tick_7 ");			// if so queue Dfc (iPtr is a pointer to TDfc )
sl@0
   449
	__JUMP(,r12);						// call timer callback with r0=iPtr
sl@0
   450
	asm("b mstim_tick_6 ");				// skip queuing of Dfc
sl@0
   451
sl@0
   452
	asm("mstim_tick_7: ");
sl@0
   453
	asm("b  " CSM_ZN4TDfc3AddEv);		// add the DFC with r0=iPtr - a pointer to TDfc
sl@0
   454
sl@0
   455
	asm("mstim_tick_6: ");
sl@0
   456
	asm("add sp, sp, #8 ");				// take temporary queue off stack
sl@0
   457
sl@0
   458
	asm("mstim_tick_4: ");
sl@0
   459
	asm("msr cpsr, r6 ");				// restore original interrupt state
sl@0
   460
	asm("movs r0, r5 ");				// DFC needed? if so, r0->iDfc
sl@0
   461
	asm("ldmfd sp!, {r4-r6,lr} ");		// restore registers
sl@0
   462
	asm("bne  " CSM_ZN4TDfc3AddEv);				// add the DFC if required
sl@0
   463
	__JUMP(,lr);						// if no DFC needed, return
sl@0
   464
sl@0
   465
	asm("__TheScheduler: ");
sl@0
   466
	asm(".word TheScheduler ");
sl@0
   467
	}
sl@0
   468
sl@0
   469
__NAKED__ void NTimerQ::DfcFn(TAny* /*aPtr*/)
sl@0
   470
	{
sl@0
   471
	// Enter with r0 pointing to NTimerQ
sl@0
   472
	asm("stmfd sp!, {r7-r11,lr} ");
sl@0
   473
	SET_INTS_1(r11, MODE_SVC, INTS_ALL_ON);		// always called from SVC mode 
sl@0
   474
	SET_INTS_1(r10, MODE_SVC, INTS_ALL_OFF);	// with interruts enabled
sl@0
   475
sl@0
   476
	// First transfer entries on the Ordered queue to the Final queues
sl@0
   477
	asm("mstim_dfc_0: ");
sl@0
   478
	SET_INTS_2(r10, MODE_SVC, INTS_ALL_OFF);	// disable interrupts
sl@0
   479
	asm("ldr r1, [r0, #%a0]!" : : "i" _FOFF(NTimerQ,iOrderedQ));	// r0->iOrderedQ, r1=orderedQ first
sl@0
   480
	asm("cmp r1, r0 ");
sl@0
   481
	asm("beq mstim_dfc_1 ");			// ordered Q empty so move to next stage
sl@0
   482
	asm("ldr r2, [r1, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// r2=r1->trigger time
sl@0
   483
	asm("ldr r3, [r0, #-12] ");			// r3=iMsCount
sl@0
   484
	asm("subs r3, r2, r3 ");			// r3=trigger time-iMsCount
sl@0
   485
	asm("cmp r3, #31 ");				// test if remaining time <32ms or has already passed
sl@0
   486
	asm("bgt mstim_dfc_1 ");			// if >31ms, move to next stage (signed comparison to catch already passed case)
sl@0
   487
	asm("sub r0, r0, #%a0" : : "i" _FOFF(NTimerQ,iOrderedQ));		// r0->NTimerQ
sl@0
   488
	asm("bl dequeaddfinal ");			// <=31ms, so deque and add to final queue
sl@0
   489
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   490
	__DEBUG_CALLBACK(0);
sl@0
   491
	asm("b mstim_dfc_0 ");
sl@0
   492
sl@0
   493
	asm("mstim_dfc_1: ");
sl@0
   494
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   495
	asm("sub r0, r0, #%a0" : : "i" _FOFF(NTimerQ,iOrderedQ));		// r0->NTimerQ
sl@0
   496
	__DEBUG_CALLBACK(1);
sl@0
   497
sl@0
   498
	// Next transfer entries on the Holding queue to the Ordered queue or final queue
sl@0
   499
	asm("mstim_dfc_2: ");
sl@0
   500
	SET_INTS_2(r10, MODE_SVC, INTS_ALL_OFF);	// disable interrupts
sl@0
   501
	asm("ldr r1, [r0, #%a0]!" : : "i" _FOFF(NTimerQ,iHoldingQ));	// r0->iHoldingQ, r1=holdingQ first
sl@0
   502
	asm("cmp r1, r0 ");
sl@0
   503
	asm("beq mstim_dfc_3 ");			// holding Q empty so move to next stage
sl@0
   504
	asm("ldr r2, [r1, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// r2=r1->trigger time
sl@0
   505
	asm("ldr r3, [r0, #-4] ");			// r3=iMsCount
sl@0
   506
	asm("sub r0, r0, #%a0" : : "i" _FOFF(NTimerQ,iHoldingQ));		// r0->NTimerQ
sl@0
   507
	asm("subs r3, r2, r3 ");			// r3=trigger time-iMsCount
sl@0
   508
	asm("cmp r3, #31 ");				// test if remaining time <32ms or has already passed
sl@0
   509
	asm("bgt mstim_dfc_4 ");			// if >31ms, need to put it on the ordered Q (signed comparison to catch late case)
sl@0
   510
	asm("bl dequeaddfinal ");			// <=31ms or already passed, so deque and add to final queue
sl@0
   511
sl@0
   512
	asm("mstim_dfc_7: ");
sl@0
   513
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   514
	__DEBUG_CALLBACK(2);
sl@0
   515
	asm("b mstim_dfc_2 ");				// process next holding Q entry
sl@0
   516
sl@0
   517
	// need to put entry r1 trigger time r2 on the ordered Q
sl@0
   518
	asm("mstim_dfc_4: ");
sl@0
   519
	asm("ldmia r1, {r3,r12} ");			// r3=r1->next, r12=r1->prev
sl@0
   520
	asm("mov r9, #0 ");
sl@0
   521
	asm("strb r9, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iTransferringCancelled));	// iTransferringCancelled=0
sl@0
   522
	asm("str r3, [r12, #0] ");			// prev->next=next
sl@0
   523
	asm("str r12, [r3, #4] ");			// next->prev=prev
sl@0
   524
	asm("mov r3, #%a0" : : "i" ((TInt)NTimer::ETransferring));
sl@0
   525
	asm("strb r3, [r1, #%a0]" : : "i" _FOFF(NTimer,iState));		// r1->iState=ETransferring
sl@0
   526
sl@0
   527
	asm("mstim_dfc_5: ");
sl@0
   528
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   529
	asm("add lr, r0, #%a0" : : "i" _FOFF(NTimerQ,iOrderedQ));	// lr=&iOrderedQ.iA
sl@0
   530
	__DEBUG_CALLBACK(3);
sl@0
   531
	SET_INTS_2(r10, MODE_SVC, INTS_ALL_OFF);	// disable interrupts
sl@0
   532
sl@0
   533
	asm("mstim_dfc_9: ");
sl@0
   534
	asm("ldrb r12, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iTransferringCancelled));
sl@0
   535
	asm("ldr r3, [lr, #0] ");			// r3=iOrderedQ first
sl@0
   536
	asm("cmp r12, #0 ");
sl@0
   537
	asm("bne mstim_dfc_7 ");			// Entry r1 has been cancelled so move to next one
sl@0
   538
	asm("strb r9, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iCriticalCancelled));	// iCriticalCancelled=0
sl@0
   539
sl@0
   540
	// Walk iOrderedQ to find correct position for this entry
sl@0
   541
	asm("mstim_dfc_6: ");
sl@0
   542
	asm("cmp r3, lr ");					// reached end of ordered Q?
sl@0
   543
	asm("ldrne r12, [r3, #%a0]" : : "i" _FOFF(NTimer,iTriggerTime));	// if not, r12=r3->trigger time
sl@0
   544
	asm("beq mstim_dfc_8 ");			// branch if we have
sl@0
   545
	asm("mov r8, #%a0" : : "i" ((TInt)NTimer::ECritical));
sl@0
   546
	asm("subs r12, r12, r2 ");			// r12=r3->trigger - r1->trigger
sl@0
   547
	asm("bpl mstim_dfc_8 ");			// branch if r3 expires after r1
sl@0
   548
	asm("strb r8, [r3, #%a0]" : : "i" _FOFF(NTimer,iState));		// r3->iState=ECritical
sl@0
   549
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   550
	asm("mov r8, #%a0" : : "i" ((TInt)NTimer::EOrdered));
sl@0
   551
	__DEBUG_CALLBACK(4);
sl@0
   552
	SET_INTS_2(r10, MODE_SVC, INTS_ALL_OFF);	// disable interrupts
sl@0
   553
	asm("ldr r12, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iTransferringCancelled));
sl@0
   554
	asm("tst r12, #0xff00 ");			// test iCriticalCancelled
sl@0
   555
	asm("streqb r8, [r3, #%a0]" : : "i" _FOFF(NTimer,iState));	// if not set, r3->iState=EOrdered
sl@0
   556
	asm("cmp r12, #0 ");				// test iTransferringCancelled and iCriticalCancelled
sl@0
   557
	asm("ldreq r3, [r3, #0] ");			// if neither set r3=r3->iNext
sl@0
   558
	asm("beq mstim_dfc_6 ");			// and inspect next ordered Q entry
sl@0
   559
	asm("b mstim_dfc_9 ");				// if either set, start again from beginning of ordered Q
sl@0
   560
sl@0
   561
	asm("mstim_dfc_8: ");				// if we get to here we need to insert r1 before r3
sl@0
   562
	asm("ldr r12, [r3, #4] ");			// r12=r3->iPrev
sl@0
   563
	asm("mov r8, #%a0" : : "i" ((TInt)NTimer::EOrdered));
sl@0
   564
	asm("strb r8, [r1, #%a0]" : : "i" _FOFF(NTimer,iState));		// r1->iState=EOrdered
sl@0
   565
	asm("str r1, [r3, #4] ");			// r3->prev=r1
sl@0
   566
	asm("str r1, [r12, #0] ");			// r3->prev->next=r1
sl@0
   567
	asm("stmia r1, {r3,r12} ");			// r1->next=r3, r1->prev=r3->prev
sl@0
   568
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   569
	__DEBUG_CALLBACK(5);
sl@0
   570
	asm("b mstim_dfc_2 ");				// process next holding Q entry
sl@0
   571
sl@0
   572
	// Get here when all holding Q entries processed
sl@0
   573
	asm("mstim_dfc_3: ");
sl@0
   574
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   575
	__DEBUG_CALLBACK(6);
sl@0
   576
	asm("add r8, r0, #16 ");			// r8->iCompletedQ
sl@0
   577
sl@0
   578
	// Finally do call backs for timers which requested DFC callback
sl@0
   579
	asm("mstim_dfc_10: ");
sl@0
   580
	SET_INTS_2(r10, MODE_SVC, INTS_ALL_OFF);	// disable interrupts
sl@0
   581
	asm("ldr r9, [r8, #0] ");			// r9=completed Q first
sl@0
   582
	asm("mov r3, #%a0" : : "i" ((TInt)NTimer::EIdle));
sl@0
   583
	asm("cmp r9, r8 ");					// Is completed Q empty?
sl@0
   584
	asm("beq mstim_dfc_11 ");			// branch out if it is
sl@0
   585
	asm("ldmia r9!, {r1,r2} ");			// r1=r9->next, r2=r9->prev, r9->iPtr of completed entry
sl@0
   586
	asm("strb r3, [r9, #%a0]" : : "i" (_FOFF(NTimer,iState)-8));	// iState=EIdle for completed entry
sl@0
   587
	asm("ldmia r9, {r0,r3} ");			// r0=iPtr, r3=function address
sl@0
   588
	ASM_KILL_LINK_OFFSET(r9,r12,-8);
sl@0
   589
	asm("str r1, [r2, #0] ");			// prev->next=next
sl@0
   590
	asm("str r2, [r1, #4] ");			// next->prev=prev
sl@0
   591
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   592
	__DEBUG_CALLBACK(7);
sl@0
   593
	asm("adr lr, mstim_dfc_10 ");		// return to mstim_dfc_10
sl@0
   594
	__JUMP(,r3);						// call back with r0=iPtr
sl@0
   595
sl@0
   596
	// All done
sl@0
   597
	asm("mstim_dfc_11: ");	
sl@0
   598
	SET_INTS_2(r11, MODE_SVC, INTS_ALL_ON);	// let interrupts in
sl@0
   599
	asm("ldmfd sp!, {r7-r11,pc} ");		// and return
sl@0
   600
sl@0
   601
	// Subroutine dequeaddfinal
sl@0
   602
	// Deque the NTimer pointed to by r1 and put it on its final queue
sl@0
   603
	// Enter with r0->NTimerQ, r1->NTimer, r2=r1->iTriggerTime
sl@0
   604
	// Enter and leave with interrupts disabled
sl@0
   605
	// Can modify r1-r3,r8,r9,r12
sl@0
   606
	asm("dequeaddfinal: ");
sl@0
   607
	asm("ldmia r1, {r8,r9} ");			// r8=r1->next, r9=r1->prev
sl@0
   608
	asm("mov r3, #%a0" : : "i" ((TInt)NTimer::EFinal));
sl@0
   609
	asm("strb r3, [r1, #%a0]" : : "i" _FOFF(NTimer,iState));	// iState=EFinal
sl@0
   610
	asm("str r8, [r9, #0] ");			// prev->next=next
sl@0
   611
	asm("str r9, [r8, #4] ");			// next->prev=prev
sl@0
   612
	asm("ldr r12, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iPresent));	// r12=timer iPresent
sl@0
   613
	asm("and r2, r2, #0x1f ");			// r2=trigger time & 0x1f
sl@0
   614
	asm("mov r3, #1 ");
sl@0
   615
	asm("orr r12, r12, r3, lsl r2 ");	// set bit in iPresent
sl@0
   616
	asm("ldrb r3, [r1, #%a0]" : : "i" _FOFF(NTimer,iCompleteInDfc));	// r3=iCompleteInDfc
sl@0
   617
	asm("str r12, [r0, #%a0]" : : "i" _FOFF(NTimerQ,iPresent));
sl@0
   618
	asm("add r2, r0, r2, lsl #4 ");		// r2->iIntQ for this timer
sl@0
   619
	asm("cmp r3, #0 ");
sl@0
   620
	asm("addne r2, r2, #8 ");			// if iCompleteInDfc, r2->iDfcQ for this timer
sl@0
   621
	asm("ldr r12, [r2, #4] ");			// r12->last on queue
sl@0
   622
	asm("str r1, [r2, #4] ");			// queue->last=this
sl@0
   623
	asm("str r1, [r12, #0] ");			// last->next=this
sl@0
   624
	asm("stmia r1, {r2,r12} ");			// this->next=&queue, this->prev=last on queue
sl@0
   625
	__JUMP(,lr);
sl@0
   626
	}
sl@0
   627
#endif
sl@0
   628