<?xml version="1.0" encoding="UTF-8"?>
<TEI xml:space="preserve" xmlns="http://www.tei-c.org/ns/1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.tei-c.org/ns/1.0 https://raw.githubusercontent.com/kermitt2/grobid/master/grobid-home/schemas/xsd/Grobid.xsd"
 xmlns:xlink="http://www.w3.org/1999/xlink">
	<teiHeader xml:lang="en">
		<fileDesc>
			<titleStmt>
				<title level="a" type="main">Abstract Timers and their Implementation onto the ARM Cortex-M family of MCUs</title>
			</titleStmt>
			<publicationStmt>
				<publisher/>
				<availability status="unknown"><licence/></availability>
			</publicationStmt>
			<sourceDesc>
				<biblStruct>
					<analytic>
						<author>
							<persName><forename type="first">Per</forename><surname>Lindgren</surname></persName>
							<email>per.lindgren@ltu.se</email>
							<affiliation key="aff0">
								<orgName type="institution">University of Technology</orgName>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Emil</forename><surname>Fresk</surname></persName>
							<email>emil.fresk@ltu.se</email>
							<affiliation key="aff0">
								<orgName type="institution">University of Technology</orgName>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Marcus</forename><surname>Lindner</surname></persName>
							<email>marcus.lindner@ltu.se</email>
							<affiliation key="aff0">
								<orgName type="institution">University of Technology</orgName>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Andreas</forename><forename type="middle">Lindner</forename><surname>Luleå</surname></persName>
							<email>andreas.lindner@ltu.se</email>
							<affiliation key="aff0">
								<orgName type="institution">University of Technology</orgName>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">David</forename><surname>Pereira</surname></persName>
							<affiliation key="aff1">
								<orgName type="department">ISEP Email</orgName>
								<orgName type="laboratory">CISTER / INESC TEC</orgName>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Luís</forename><forename type="middle">Miguel</forename><surname>Pinho</surname></persName>
							<affiliation key="aff1">
								<orgName type="department">ISEP Email</orgName>
								<orgName type="laboratory">CISTER / INESC TEC</orgName>
							</affiliation>
						</author>
						<title level="a" type="main">Abstract Timers and their Implementation onto the ARM Cortex-M family of MCUs</title>
					</analytic>
					<monogr>
						<imprint>
							<date/>
						</imprint>
					</monogr>
					<idno type="MD5">38CBBAC3B86056C29CAE55B43DD60B60</idno>
				</biblStruct>
			</sourceDesc>
		</fileDesc>
		<encodingDesc>
			<appInfo>
				<application version="0.7.2" ident="GROBID" when="2023-03-25T08:54+0000">
					<desc>GROBID - A machine learning software for extracting information from scholarly documents</desc>
					<ref target="https://github.com/kermitt2/grobid"/>
				</application>
			</appInfo>
		</encodingDesc>
		<profileDesc>
			<abstract>
<div xmlns="http://www.tei-c.org/ns/1.0"><p>Real-Time For the Masses (RTFM) is a set of languages and tools being developed to facilitate embedded software development and provide highly efficient implementations geared to static verification. The RTFM-kernel is an architecture designed to provide highly efficient and predicable Stack Resource Policy based scheduling, targeting bare metal (singlecore) platforms.</p><p>We contribute beyond prior work by introducing a platform independent timer abstraction that relies on existing RTFM-kernel primitives. We develop two alternative implementations for the ARM Cortex-M family of MCUs: a generic implementation, using the ARM defined SysTick-/DWT hardware; and a target specific implementation, using the match compare/free running timers. While sacrificing generality, the latter is more flexible and may reduce overall overhead. Invariants for correctness are presented, and methods to static and run-time verification are discussed. Overhead is bound and characterized. In both cases the critical section from release time to dispatch is less than 2us on a 100MHz MCU. Queue and timer mechanisms are directly implemented in the RTFM-core language and can be included in system-wide scheduling analysis.</p></div>
			</abstract>
		</profileDesc>
	</teiHeader>
	<text xml:lang="en">
		<body>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1.">INTRODUCTION</head><p>In the mainstream of embedded programming C-code still remains the predominant means for software development.</p><p>To facilitate the development a vast number of light-weight operating systems are available, e.g., FreeRTOS <ref type="bibr" target="#b0">[1]</ref>, ChibiOS <ref type="bibr" target="#b1">[2]</ref>, and RIOT <ref type="bibr" target="#b2">[3]</ref> and for larger platforms, Linux/POSIX based and Win32 derivates. In common, they provide a thread based concurrency model, where the programmer has to take the full responsibility of coordinating scheduling and resource management as very little support is given by the programming models and supporting tools <ref type="bibr" target="#b3">[4]</ref>.</p><p>In this paper, we explore a language based approach. The reactive programming model of RTFM-core (-core in the following) provides tasks with timing constraints and critical sections (treated as single-unit resources). As such -core provides a model suitable to specify the timely behavior of the embedded software, as well as a formal underpinning amendable to both static and run-time verification. The supporting rtfm-core compiler produces C code that compiled together with a RTFM run-time system renders an executable. The RTFM-kernel is an architecture targeting bare metal (single-core) platforms designed to provide highly efficient and predicable Stack Resource Policy (SRP) based scheduling by exploiting the underlying interrupt hardware.</p><p>However, in prior work no kernel support was given for asynchronous tasks with timing offsets. In this paper we address this problem with the goal to provide a transparent, abstract, and generic way of managing timer queue(s) and underlying hardware timer(s). Transparent w.r.t its use, i.e. the programmer should not need to think in terms of hardware timers when specifying the application at hand. Abstract in terms of the RTFM-kernel, (the obligation of the kernel is merely to manage scheduling) thus we seek a solution where the kernel itself is free of dependencies both to timer queue implementations and timer hardware specifics. Furthermore, the solution should be generic enough to cover a broad range of embedded platforms with little or no effort of porting. Additional requirements for robustness, performance and predictability are efficient, bound time implementations, complying with the task and resource model of SRP, along with invariants for correctness.</p><p>In this paper we contribute beyond prior work by introducing a platform independent timer abstraction that relies on the existing kernel primitives. The proposed abstraction allows application and target specific implementations of timer queues and timer handlers. The timer handlers are treated as ordinary tasks in the system, while each queue is managed under protection of a critical section (resource) in the system.</p><p>Requirements to support abstract timers with respect to analysis and code generation in the rtfm-core compiler are discussed along with their performance implications. As a proof of concept, we develop and characterize two alternative timer implementations for the ARM Cortex-M family of MCUs: a generic (single queue/handler) implementation using the ARM defined SysTick/DWT hardware), and a multi-queue/handler implementation exploiting vendor specific match-compare/free running timer hardware.</p><p>Our experimental results indicate that for both generic and vendor specific timers the critical section from task release time to dispatch is less than 2us on a 100MHz MCU. We show that the vendor specific timers can be exploited to reduce latency, total overhead and priority inversion in the system. Furthermore, we discuss the outsets for SRP based analysis of programs scheduled by virtual timers under the RTFM-kernel.</p><p>Finally we present ongoing and future undertakings and sum up the presented contributions to conclude the work.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.">THE RTFM-CORE LANGUAGE</head><p>The RTFM-core language is based on the notions of tasks and resources in correspondence to the Stack Resource Policy (SRP) model defined in <ref type="bibr" target="#b4">[5]</ref>. For a detailed description on the original work on -core we refer the reader to <ref type="bibr" target="#b5">[6]</ref>. Here we give a brief overview.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.1">RTFM-core programming model</head><p>In -core tasks execute concurrently and run-to-completion. A task may request asynchronous execution of other tasks and claim (named) single-unit resource(s) for the duration of critical section(s) in a nested manner. Functionality is expressed using ordinary C-code. In recent work <ref type="bibr" target="#b6">[7]</ref> the -core language has been extended to provide messages (task execution requests with timing offsets):</p><p>async after X before Y t(...), where X, defines the (baseline) offset from the release time of the sender (baseline); Y , gives the relative deadline and t is the identifier of the task to execute.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.2">RTFM-kernel design</head><p>In short each task is implemented directly as an interrupt handler bound to the interrupt vector. Requesting a task for execution amounts to pending the corresponding interrupt, while claiming a resource for a critical section amounts to manipulating the interrupt hardware such to reflect the semantics of the system ceiling under SRP. The RTFM-kernel encapsulate the operations required for SRP based scheduling in a minimalistic API implemented as C-code macros. Those of interest for the presentation are: RTFM_pend(i), which requests execution of the corresponding task i; RTFM_lock(c), which reads and stores the old ceiling value on the stack and sets the new ceiling; and finally, RTFM_unlock(c), which restores the old ceiling value from the stack.</p><p>Currently the scheduling primitives have been implemented for the ARM Cortex-M range of MCUs <ref type="bibr" target="#b7">[8]</ref>. The system ceiling is enforced either through interrupt masking (M0/M0+), or through (atomic) accesses to the NVIC BASEPRI register (M3 and above).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.3">RTFM-core compiler</head><p>The rtfm-core compiler analyses the declarative (static) task, resource and communication structure, and generates a C-code output referring to the RTFM-kernel primitives. Code generation and kernel primitives can be tailored to Ccompiler specifics (currently supporting gcc and compcert).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.">TIMER ABSTRACTION</head></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.1">Definitions</head><p>We introduce the following definitions:</p><p>Definition We denote a task to be postponed if stemming from an asynchronous message:</p><p>async after X before Y with a defined baseline offset (X &gt; 0). We denote the set of postponed tasks as OT .</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Definition</head><p>We have a set of virtual timers {V T1 . . . V Tn}. Each virtual timer i is associated with a set of postponed tasks ot(V Ti) ∈ OT , and a timer queue tq(V Ti) (sorted by release time).</p><p>Definition We introduce a mapping M from virtual timers V T 's to physical timers P T 's, allocated on the target hardware.</p><formula xml:id="formula_0">A physical timer is shared if M (V Ti) = M (V Tj), i = j.</formula><p>We have the two edge cases, when M is a 1-1 (complete) mapping between virtual and physical timers, and the case when we have a single (shared) physical timer.</p><p>Definition For a physical timer P Ti, we denote bw(P Ti) as the bit-width and f (P Ti) as the frequency of operation (in Hz), ra(P Ti) as the range of the timer (in seconds), derived from 2 bw /f , and pr(P Ti) as the precision of the timer (in seconds), given as pr = 1/f . E.g., the range is given by 2 bw(P T i ) /f , e.g. a 32-bit timer operating a 1MHz gives a range of 2 32 /1 * 10 6 Hz = 4295s, with a precision of 1 * 10 −6 s = 1us.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2">ARM Cortex-M defined timers</head><p>The Cortex-M range of MCUs share the ARM defined core providing a 24-bit SysTick timer and a 32-bit debug timer (defined in the DWT unit).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2.1">SysTick timer</head><p>The SysTick timer is provided in order to generate periodic interrupts. When enabled, it counts downwards, and when transitioning from 1 to 0 it sets a flag and (optionally) generates a SysTick interrupt. On zero, it assumes the value of the RELOAD register, hence a periodic behavior can be achieved with a minimal of programming effort. The current counter value (CURRENT) can be read, while a write to CURRENT, forces CURRENT = RELOAD. The frequency of operation, is determined by setting the clock source (core/external). (Some implementations provide the option to prescale the core clock, e.g., /8.) The priority of the SysTick interrupt is programmable, and an interrupt can be pended by setting the PENDSTSET bit in the ICSR (Interrupt Control and State Register). The SysTick timer is stopped when the processor is halted during debug.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2.2">Debug timer</head><p>The debug unit (DWT) provides a 32-bit, free running cycle count register (DWT_CYCCNT). However, the DWT is instrumental for providing debugging support, and hence not free to arbitrary use. However we can safely enable and read the current DWT_CYCCNT value and use it as a 32-bit glitch-free time base. When the CPU is halted (e.g., during debugging) the counter is stopped.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.3">Generic timer implementation</head><p>A flow chart is given in Figure <ref type="figure" target="#fig_0">1</ref>. Whenever a new message enters first in the queue (Fyes) the timer handler (task) is invoked. In the timer handler, if the release time has already expired (Eyes), the queued task is pended for execution, else (Eno) the timer is programmed for releasing the the task at its time for expire. In case a task is pended, the timer is iteratively dequeued until either the queue is empty (Qno), or the release time not expired (Eno). In the latter case, the timer is setup to generate an interrupt for next task to be released.</p><p>The timer handler is sketched in Listing 1, while the Sy-sTick (set timer specific) implementation is outlined in Listing 2, along with a flow chart for its operation Figure <ref type="figure">2</ref>.  T_CURR is a macro to read the DWT_CYCCNT (debug cycle counter) while T_ENABLE()/T_DISABLE() are macros to enable/disable the SysTick interrupt.</p><p>The SYSTICK_MASK is defined to the max reload value for the 24-bit counter. For brevity, initialization code is omitted. However, worth to mention is that we read DWT_CYCCNT to obtain a defined point in time (baseline) for the birth of the system. As a proof of concept we have implemented a simple insertion sort queue (Listings 3 and 4).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.3.1">Invariants for correctness</head><p>The invariants concern the logic of the interaction between the queue and the timer handler. Figure <ref type="figure">3</ref>, depicts the overall timer operation. The following invariants should hold: • Idle state:</p><formula xml:id="formula_1">1 #define SYSTIC_MASK ((1&lt;&lt;24)-1) 2 void T_SET(RT_Time t) { 3 RT_time diff = t -T_CURR(); 4 if (diff &gt; SYSTIC_MASK) { 5 SYSTICK_RELOAD = SYSTIC_MASK; 6 } else { 7 if (diff &lt;= 0) { 8 PEND_SYSTIC() 9 } 10 SYSTICK_RELOAD = (diff &amp; SYSTIC_MASK)</formula><p>the timer queue is empty, and the timer interrupt is disabled.</p><p>• Wait state:</p><p>the timer queue is non-empty, and the timer interrupt is enabled.</p><p>The invariants are upheld by the implementation following the (informal) reasoning.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Queue correctness.</head><p>Idle Assume the timer is in Idle state (the queue is empty), and the application emits an async after X ... t (...).</p><p>Since the timer queue is empty we follow the right branch (Fyes), i.e., we enqueue (X, t), and enable the timer interrupt T_ENABLE() and pend the timer interrupt T_PEND, which causes the transition T1 to be taken. At this point, the queue is non-empty, and the timer is enabled.</p><p>Wait Assume the timer is in Wait state (the queue is nonempty), and the application emits an async after X ... t (...).</p><p>In this case we take an (implicit) T2 transition and remain in Wait state.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Timer handler correctness.</head><p>Idle Assuming the Idle invariant, the timer interrupt is disabled. (Thus, the time-interrupt handler is not invoked even in case a compare match occurs and the interrupt is raised.) Wait The time-interrupt handler is invoked when an interrupt occurs and the interrupt is enabled. The interrupt has been raised either due to a T1 transition or due to the timer hardware on a compare match. Assuming the Wait invariants there is (at least) one element in the queue, thus we can safely access tq_h for the &lt;expire?&gt; check. From there the following cases apply:</p><p>Eno On Eno we program the SysTick timer [set timer], and return from the time-interrupt handler [exit]. This corresponds to a transition T2 where we remain in Wait state (waiting for a compare match). This occurs in the case the timer is programmed first time or on an overflow (when range of the timer is insufficient to reach the release time of the queued task). Notice, the latter may occur repeatedly until the &lt;expire?&gt; condition is met.</p><p>Eyes We release the expired task [pend task] and check if more messages are queued &lt;dequeue?&gt;. From the following cases apply:</p><p>Qno No further messages are queued and we disable the interrupt [disable]. This corresponds to the transition T3 back to Idle state. At this point, the queue is empty and the interrupt is disabled.</p><p>Qyes There is still at least one message in the queue, and we check the &lt;expired?&gt; condition for the next queued task (a T2 transition).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.3.2">Correctness under Concurrency</head><p>The sending task (accessing the timer queue through emitting an async after X ...) and the timer handler runs concurrently, and potentially preemptively, to other tasks. Hence, we may be exposed to race conditions. To this end we may either turn to re-entrant (lock-free) queue implementations <ref type="bibr" target="#b8">[9]</ref> or protect the queue as a resource in the system. For this presentation, we turn to the locking mechanisms provided by the RTFM-kernel. In Figure <ref type="figure" target="#fig_0">1</ref>, the LOCKED(R(tq)) areas (marked yellow/boxed), indicates the critical sections on the resource R(tq). For the implementation this amounts to RT_LOCK(lq, R(tq)) on entering and RT_UNLOCK(lq) on exiting. Since the queue operations are protected by the resource R(tq), they are from the outset of concurrency safe. While the release of an expired task t [pend task] is executed while holding the resource R(tq), the SRP protocol ensures that t is only dispatched if it has a priority higher than the current ceiling. If t accesses the queue (through an async after X ...), then R(tq) ≥ p(t) which prevents dispatching t until R(tq) is unlocked. (Moreover, under the assumption that the timer handler task is given a priority equal or greater than t, t will not be dispatched until the timer handler task finish.)</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.3.3">Characterization</head><p>The presented timer abstraction and its implementation gives the following key characteristics:</p><p>• Given a bound size queue, tq_enq is a bound time operation,</p><p>• tq_deq is a constant time operation (accessing and advancing only the head of the list),</p><p>• timer handling is safe w.r.t. invariants, and it</p><p>• allows implementation (and analysis) as part of the -core application<ref type="foot" target="#foot_0">1</ref> .</p><p>Timing characteristics have been determined by measuring the clock cycle count (DWT_CYCCNT) on the current implementations (as presented in the paper). The experiments have been conducted on a STM32 F4, running at full speed (168MHz). The measurements have been repeated and consistent cycle counts have been observed. For the experiments we have used gcc v4.8.3 (OL gives the optimization level), with the default settings for the target architecture. All measurements include the overhead of the instrumentation code, hence safe and pessimistic w.r.t. actual performance.</p><p>The queue implementation has been characterized, Table <ref type="table" target="#tab_3">1</ref>. The Baseline gives the cycle count (including the call/return) overhead for inserting last in a queue holding 1 element. The LC gives the Linear coefficient (added cost for each element in worst case). As expected for insertion sort, we found the coefficient indeed to be linear.</p><p>Table <ref type="table" target="#tab_4">2</ref>, shows the latency from set release-time to dispatch in clock cycles. This gives an upper bound to the dispatch overhead, (dispatching multiple queued tasks without leaving the handler always infer lower latency). The blocking (related to tq) inferred by the timer handler is brought to a constant by escaping the critical section for each iteration. The Best/Nominal values, give the execution path when the queued task is not at the end of the queue, while the Worst case includes disabling the timer interrupt. From this we can conclude that the generic implementation is capable of a low latency dispatch (&lt; 2us, scaled to a 100MHz MCU). We have given the necessary WCET characterization for blocking, useful to SRP based timing analysis (e.g., response time and overall schedulability).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.4">Vendor specific timers</head><p>An ARM Cortex based MCU typically comprise an ARM defined core and a set of vendor specific peripherals (typically including a set of timers/counters). Each counter/timer has a defined set of features (supporting the intended use). The requirements for implementing the abstract timer architecture boils down to the following:</p><p>• n-bit width counter (+ for larger n) with</p><p>• interrupt capability (r), programmable priority (+)</p><p>• frequency (rate) relation to core-clock defined (r) or programmable (+), and</p><p>• programmable reload (r), match compare register (+).</p><p>While (r) this is required/sufficient, the suitability is improved (+) by a larger bit width, programmable priority, programmable frequency and match compare functionality.</p><p>As representative uses cases we have studied two popular ARM Cortex MCUs, namely the NXP LPC1769 and the STM32 F4. In the case of the NXP LPC1769 (and similar) a Repetitive Interrupt Timer (RIT) is provided, and a set of 4 equivalent and fully programmable 32-bit timers (the latter meeting all our requirements suitability criteria). In the case of the STM32 F407VET (and similar), we find a set of 12 16-bit timers and 2 32-bit timers, meeting the requirements and suitability criteria.</p><p>For the implementation, the specialization to a vendor specific timer is isolated to the [set timer]. The writing the match compare is always 32-bit under the ARM memory model, (the underlying timer hardware merely discards the 16 MSBs), hence the characterization applies in all cases. In Table <ref type="table" target="#tab_5">3</ref> gives the overhead for the isolated SetSysTick, while Table <ref type="table" target="#tab_6">4</ref> depicts the overhead of setting a Vendor Specific (STM32 F407VET 32-bit) timer. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.5">Compiler support</head><p>In order to automatically generate code for the proposed virtual timers, the -core to C compiler is required to undertake the following (additional) steps in the analysis:1) derive the set of postponed tasks OT , 2) associate each postponed task ti ∈ OT to a V Tj, such that p(V Tj) = p(ti) (i.e., assign a virtual timer to each priority level in the tasks set OT ), 3) derive a mapping M from V T to P T . 4) derive for each tqi, whereP Ti ∈ P T the static queue length (tqi being a potentially shared queue for P Ti, M (V Ti) = P Ti). 5) associate each tqi to a resource R(tqi), with a ceiling value assigned under SRP (derived from the priorities of the tasks accessing the queue, and 6) derive a time base tb(P Ti) for each P Ti. 7) Generate C code definitions accordingly.</p><p>In the generated C-code, each task has a defined baseline set by reading the hardware timer (T_CURR()) for externally triggered task or given by the sending task). To the kernel we introduce a (queue and timer implementation independent) macro RTFM_async_i(...) scaling the virtual time based (in us) to that of the target P Ii. Our prototype -core compiler implementation, assumes the case of a single (shared) physical timer. (The evaluation of multiple timers has been conducted by manually.)</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.6">Timing performance</head><p>For scheduling analysis the timer handlers can be seen as ordinary tasks, invoked once for the release of each message (plus the number of the range overflows present, e.g. in case of SysTick based solutions). With the outset that the mapping M is complete there will be no priority inversion introduced by the timer handlers (as they operate operate at the same priority as the tasks they release). A timer handler t h for shared timer, may preempt a task tj (p(t h ) &gt; p(tj)), while p(tr) ≤ p(tj), tr being the released task.</p><p>For vendor specific timers we typically have the option to set the frequency f (P Tn) (increased frequency gives a improved precision, while at the same time may increase the background load for processing timer overruns). The precision occurs as a jitter parameter to the scheduling. (In case the timer operates at the core clock frequency of the MCU (e.g., for our SysTick implementation), jitter is 0.)</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.7">Run-time verification</head><p>The proof of correctness for the implementation is informal. To this end, the T_ENABLE()/T_DISABLE() macros and tq_eng/tq_deq implementations have been extended to check the invariants. For run-time verification of timing constraints, the code generation for tasks is extended to check on return of each task ti the condition:</p><p>bl_t_i + dl_t_i &gt; T_CURR(), where bl_t_i is the (dynamic) task release time (baseline) and dl_t_i the specified (relative) deadline.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.8">Assumptions</head><p>Following the general -core assumption on schedulability, any message can have at most one outstanding instance. This allows the required (safe) queue length to be derived directly as the sum of tasks associated to the queue In consequence baseline offsets (after X ...) must be less or equal to the sender's inter-arrival time.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.">RELATED AND FUTURE WORK</head><p>In the context of light-weight operating systems, neither ChibiOS <ref type="bibr" target="#b1">[2]</ref>, RIOT <ref type="bibr" target="#b2">[3]</ref> nor FreeRTOS <ref type="bibr" target="#b0">[1]</ref> provide official characterized queue/timer implementations. TinyOS <ref type="bibr" target="#b9">[10]</ref> (TEP 102/108) suggest an HAL virtualization layer. However, timers in TinyOS are outside their model of computation and treated as any other (arbitrary) event source. Contiki <ref type="bibr" target="#b10">[11]</ref> provides the Rtimer library for scheduling real-time task, however unlike our approach their timer tasks are unsafe. Hence, our work presented can be considered as a baseline for future benchmarking.</p><p>Future work includes supporting baseline offsets larger than inter-arrival time for the sender. As mentioned in Section 3.5, the support for abstract timers is currently limited to a single queue/timer handler. The time-base T_CURR is 32-bit, defined by the DWT. This limits the absolute time offsets. Longer offsets can be obtained at application level (manually keeping track of number of activations until desired time has expired). Automatic allocation and assignment of (potentially multiple) timer handlers according the requirements of the application can support arbitrary offsets, as well as reducing priority inversion and overall overhead. Besides temporal properties, issues of energy consumption may be considered for multi-domain optimization. Moreover, the presented abstract timer architecture allows for multiple alternative queue implementations. By analyzing the task set, the compiler could chose the best fit (linear, heap, etc.) for each queue according to its characteristics (Section 3.3.3) and overall requirements (w.r.t. timing, memory, etc.).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.">CONCLUSIONS</head><p>In this paper we have introduced abstract timers to the purpose of platform independent support for postponed tasks. The abstraction allows timer tasks (handlers) and queues to be statically allocated and included in system wide compiletime analysis under the task and resource model of RTFM. We have proposed a generic timer implementation that relies solely on the ARM defined Cortex-M core and existing RTFM-kernel primitives, and is thus directly applicable to a wide range of commercially available MCUs. Correctness has been argued from invariants for queue and timer task interactions and queue consistency in a concurrent setting. Our experiments validate the feasibility of the abstract timer architecture and the presented characterizations of queuing overhead and generic/vendor specific timer implementations gives concrete bounds, useful as input to further response time and schedulability analysis.</p></div><figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_0"><head>Figure 1 :</head><label>1</label><figDesc>Figure 1: Timer queue (left) and timer handler (right) flow charts.</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_1"><head>2 T 3 Figure 3 :</head><label>233</label><figDesc>Figure 3: Timer states, Idle is the initial state.</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_3"><head>Table 1 :</head><label>1</label><figDesc>Complexity of the queueing algorithm.</figDesc><table><row><cell>OL</cell><cell>Baseline</cell><cell>LC</cell></row><row><cell>O0</cell><cell>178</cell><cell>26.5</cell></row><row><cell>O1</cell><cell>95</cell><cell>10</cell></row><row><cell>O2</cell><cell>78</cell><cell>9</cell></row><row><cell>O3</cell><cell>78</cell><cell>9</cell></row><row><cell>Og</cell><cell>96</cell><cell>9.5</cell></row></table></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_4"><head>Table 2 :</head><label>2</label><figDesc>Latency from set release time to dispatch.</figDesc><table><row><cell>OL</cell><cell>Best</cell><cell>Nominal</cell><cell>Worst</cell></row><row><cell></cell><cell>Case</cell><cell>Case</cell><cell>Case</cell></row><row><cell>O0</cell><cell>229</cell><cell>298</cell><cell>338</cell></row><row><cell>O1</cell><cell>122</cell><cell>153</cell><cell>188</cell></row><row><cell>O2</cell><cell>123</cell><cell>153</cell><cell>217</cell></row><row><cell>O3</cell><cell>123</cell><cell>153</cell><cell>217</cell></row><row><cell>Og</cell><cell>124</cell><cell>155</cell><cell>195</cell></row></table></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_5"><head>Table 3 :</head><label>3</label><figDesc>Characterization of the Timer Set function for the SysTick Timer.</figDesc><table><row><cell>OL</cell><cell>Best Case</cell><cell>Worst Case</cell></row><row><cell>O0</cell><cell>54</cell><cell>67</cell></row><row><cell>O1</cell><cell>35</cell><cell>49</cell></row><row><cell>O2</cell><cell>33</cell><cell>41</cell></row><row><cell>O3</cell><cell>33</cell><cell>41</cell></row><row><cell>Og</cell><cell>33</cell><cell>41</cell></row></table></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_6"><head>Table 4 :</head><label>4</label><figDesc>Characterization of the Timer Set function for a Vendor Specific timer.</figDesc><table><row><cell>OL</cell><cell>Best Case</cell><cell>Worst Case</cell></row><row><cell>O0</cell><cell>37</cell><cell>45</cell></row><row><cell>O1</cell><cell>21</cell><cell>28</cell></row><row><cell>O2</cell><cell>21</cell><cell>22</cell></row><row><cell>O3</cell><cell>21</cell><cell>22</cell></row><row><cell>Og</cell><cell>21</cell><cell>22</cell></row></table></figure>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="1" xml:id="foot_0">In particular, the tq_enq is part of the execution time for the sending task, and the critical section (holding R(tq)) of the timer handler is constant time (although the execution of the timer handler may involve iterations). Notice here the "slight escape" from the critical section when releasing multiple tasks.</note>
		</body>
		<back>

			<div type="funding">
<div xmlns="http://www.tei-c.org/ns/1.0"><p>This work was partially supported by Portuguese National Funds through FCT (Portuguese Foundation for Science and Technology) and by ERDF (European Regional Development Fund) through COMPETE (Operational Programme â ȂŸThematic Factors of Competitivenessâ Ȃ Ź), within project FCOMP-01-0124-FEDER-037281 (CISTER); and by FCT and EU ARTEMIS JU, within project ARTEMIS/0001/2013, JU grant nr. 621429 (EMC2) EWiLi'15, October 8th, 2015, Amsterdam, The Netherlands.</p></div>
			</div>

			<div type="references">

				<listBibl>

<biblStruct xml:id="b0">
	<monogr>
		<title/>
		<author>
			<persName><surname>Freertos</surname></persName>
		</author>
		<ptr target="http://www.freertos.org" />
		<imprint>
			<date type="published" when="2015-09-18">2015-09-18</date>
		</imprint>
	</monogr>
	<note>webpage</note>
</biblStruct>

<biblStruct xml:id="b1">
	<monogr>
		<title/>
		<author>
			<persName><forename type="first">/</forename><surname>Chibios</surname></persName>
		</author>
		<author>
			<persName><surname>Rt</surname></persName>
		</author>
		<ptr target="http://www.chibios.org" />
		<imprint>
			<date type="published" when="2015-09-18">2015-09-18</date>
		</imprint>
	</monogr>
	<note>webpage</note>
</biblStruct>

<biblStruct xml:id="b2">
	<monogr>
		<title/>
		<author>
			<persName><surname>Riot</surname></persName>
		</author>
		<ptr target="http://riot-os.org" />
		<imprint>
			<date type="published" when="2015-09-18">2015-09-18</date>
		</imprint>
	</monogr>
	<note>webpage</note>
</biblStruct>

<biblStruct xml:id="b3">
	<analytic>
		<title level="a" type="main">The problem with threads</title>
		<author>
			<persName><forename type="first">E</forename><forename type="middle">A</forename><surname>Lee</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">Computer</title>
		<imprint>
			<biblScope unit="volume">39</biblScope>
			<biblScope unit="issue">5</biblScope>
			<biblScope unit="page" from="33" to="42" />
			<date type="published" when="2006-05">May 2006</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b4">
	<analytic>
		<title level="a" type="main">A stack-based resource allocation policy for realtime processes</title>
		<author>
			<persName><forename type="first">T</forename><surname>Baker</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">Real-Time Systems Symposium</title>
				<imprint>
			<date type="published" when="1990-12">1990. 11th. Dec. 1990</date>
			<biblScope unit="page" from="191" to="200" />
		</imprint>
	</monogr>
	<note>Proceedings.</note>
</biblStruct>

<biblStruct xml:id="b5">
	<analytic>
		<title level="a" type="main">RTFM-core: Language and Implementation</title>
		<author>
			<persName><forename type="first">P</forename><surname>Lindgren</surname></persName>
		</author>
		<author>
			<persName><forename type="first">M</forename><surname>Lindner</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">ESWEEK/CPSArch 2014</title>
				<imprint>
			<date type="published" when="2014">2014</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b6">
	<analytic>
		<title level="a" type="main">A real-time semantics for the IEC 61499 standard</title>
		<author>
			<persName><forename type="first">P</forename><surname>Lindgren</surname></persName>
		</author>
		<author>
			<persName><forename type="first">M</forename><surname>Lindner</surname></persName>
		</author>
		<author>
			<persName><forename type="first">A</forename><surname>Lindner</surname></persName>
		</author>
		<author>
			<persName><forename type="first">V</forename><surname>Vyatkin</surname></persName>
		</author>
		<author>
			<persName><forename type="first">D</forename><surname>Pereira</surname></persName>
		</author>
		<author>
			<persName><forename type="first">L</forename><forename type="middle">M</forename><surname>Pinho</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">ETFA 2015</title>
				<meeting><address><addrLine>Luxembourg</addrLine></address></meeting>
		<imprint>
			<date type="published" when="2015">September 8-11, 2015. 2015</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b7">
	<analytic>
		<title level="a" type="main">Real-time for the masses, step 1: Programming API and static priority SRP kernel primitives</title>
		<author>
			<persName><forename type="first">J</forename><surname>Eriksson</surname></persName>
		</author>
		<author>
			<persName><forename type="first">F</forename><surname>Häggstrom</surname></persName>
		</author>
		<author>
			<persName><forename type="first">S</forename><surname>Aittamaa</surname></persName>
		</author>
		<author>
			<persName><forename type="first">A</forename><surname>Kruglyak</surname></persName>
		</author>
		<author>
			<persName><forename type="first">P</forename><surname>Lindgren</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">SIES. IEEE</title>
				<imprint>
			<date type="published" when="2013">2013</date>
			<biblScope unit="page" from="110" to="113" />
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b8">
	<analytic>
		<title level="a" type="main">A methodology for creating fast wait-free data structures</title>
		<author>
			<persName><forename type="first">A</forename><surname>Kogan</surname></persName>
		</author>
		<author>
			<persName><forename type="first">E</forename><surname>Petrank</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">ser. PPoPP &apos;12</title>
				<meeting><address><addrLine>New York, NY, USA</addrLine></address></meeting>
		<imprint>
			<publisher>ACM</publisher>
			<date type="published" when="2012">2012</date>
			<biblScope unit="page" from="141" to="150" />
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b9">
	<analytic>
		<title level="a" type="main">TinyOS: An operating system for sensor networks</title>
		<author>
			<persName><forename type="first">P</forename><surname>Levis</surname></persName>
		</author>
		<author>
			<persName><forename type="first">S</forename><surname>Madden</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">Ambient Intelligence</title>
				<imprint>
			<publisher>Springer Verlag</publisher>
			<date type="published" when="2004">2004</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b10">
	<analytic>
		<title level="a" type="main">Contiki -a lightweight and flexible operating system for tiny networked sensors</title>
		<author>
			<persName><forename type="first">A</forename><surname>Dunkels</surname></persName>
		</author>
		<author>
			<persName><forename type="first">B</forename><surname>Grönvall</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">Emnets-I</title>
				<imprint>
			<date type="published" when="2004-11">Nov. 2004</date>
		</imprint>
	</monogr>
</biblStruct>

				</listBibl>
			</div>
		</back>
	</text>
</TEI>
