School this scheduler is implemented in C in the

School of Electrical and Electronic Engineering, Newcastle University      EEE8068: Wireless EmbeddedSystems Coursework Report      Student: Chen Minhui 1. AbstractIn this experiment, a Time Triggered CooperativeScheduler (TTCS) was required to design and this scheduler is to control 8different LEDs in the ARM board to flash in different periods and with differentspecifically phases and the brightness of LED is implemented by the PWMtechnique. When a LED in the system meets an overrun occasion, this LED willstop to do nothing and other LEDs run normally.

And this scheduler isimplemented in C in the UNIX environment. For this experiment, I have finishedthe task that makes all LEDs stop to do nothing while pressing the button, butfor the rest part which makes the rest LEDs work normally except for theoverrun LED, I have not finish yet. The practice of designing a scheduler tocontrol 8 tasks can promote the understanding of scheduling concepts and learnhow to design a TTCS scheduler.2.

Best services for writing your paper according to Trustpilot

Premium Partner
From $18.00 per page
4,8 / 5
4,80
Writers Experience
4,80
Delivery
4,90
Support
4,70
Price
Recommended Service
From $13.90 per page
4,6 / 5
4,70
Writers Experience
4,70
Delivery
4,60
Support
4,60
Price
From $20.00 per page
4,5 / 5
4,80
Writers Experience
4,50
Delivery
4,40
Support
4,10
Price
* All Partners were chosen among 50+ writing services by our Customer Satisfaction Team

Introduction2.1 Task specificationAccording to the handout,a Time Triggered Cooperative Scheduler (TTCS) was asked to implement in C and thisTTCS scheduler is to control 8 different LEDs on an ARM board toflash with different periods. Specifically, these LEDs are implemented by eightshort periodic tasks, and four of them are required to flash in every tick interval,while two tasks are required to flash in every odd tick interval and two tasksare required to flash in every even tick interval. When the overrun is happening,the running task which is followed by the normal sequence of task execution shouldbe interrupted by the timer.

The tasks in the line after the overrunning taskmay not be started under the overrun conditions, but the relevant data (e.g. theflashing period and the phase of LED flashing) must be right. 2.

2 SchedulerThe scheduler refers to using the schedulingalgorithm to schedule the tasks in a specific sequence. There are many partsinside a scheduler (e.g., interrupts, timer, one or several processors, taskqueue, CPU modes, task model, scheduler model, protection from overruns, etc.).And for this experiment, this scheduler should be a Time Triggered CooperativeScheduler (TTCS) as required in the task specification.

As this scheduler iscooperative, therefore when one task is running, the next task should waitrather than pre-empt the running task. 12.3 ToolchainIn this task, the X-server Xming software andCygwin are required to use, as the programming environment is based on the UNIXcommand-line shell. After the two software running, rxvt-x can be started. In thecommand window of rxvt-x, it is required to create design directory by typingmkdir eee8068cwrk in the command window and then change current directory tothe design directory by typing cd eee8068cwrk. After these steps, it is requiredto copy the standard design files: Makefile, armfpga.

ld, ex.h, howto.txt, andstartup.s files into the design directory. When the coding of scheduler isfinished, the debugger kmd should be copied on to the drive D:, as it will notrun from drive H:, and then the code can be tested to flash the LED withdifferent periods in the board.2.

4 Hardware PlatformThe platform is based on an ARM-XLINIX board(SAM9261), which is a complete system-on-chip built around the processor withan extended DSP instruction set and Java accelerator. The SAM9261 is an optimizedhost processor for applications with an LCD display. The 160 Kbyte integratedSRAM can be configured as a frame buffer to minimise the impact for LCD refreshon the overall processor performance and the External Bus Interfaceincorporates controllers for synchronous DRAM (SDRAM) and Static memories andfeatures specific interface circuitry for Compact Flash and NAND Flash. (Atmel | SMART SAM9261 Datasheet, n.d.)2 The boardinternal structure shown below:Figure 1: SAM9261 Board Internal Structure3. Implementation3.

1 Scheduler Basic StructureForthis TTCS scheduler, according to the requirement, there should be 6 tasksexecuted in each tick. For each timeline TTS task, its task model can be shownin figure 2. The task queue is updated on each tick and their code is stored inROM. As there are 8 tasks in the specification and thus 6 tasks should beexecuted in each tick, so its timeline TTS state graph can be described as infigure 3Figure 2: Timeline TTS Task Model Figure 3: Timeline TTS Task State Graph3.2 Naked FunctionsAllfunctions in the scheduler are implemented as ‘naked functions’, because it hasno prologue or epilogue and stack needs to be reinitialised at the beginning. 3By observing the figure 3, 6 naked functions mainly should be built and theyare respectively main(), irq(), dispatcher(), task(), swi(), and sleep_state().Each naked function executes a specific work.     Main() – Initialization       Irq() – Update       Dispatcher() – Dispatcher       Task() – Tasks (User Mode)       swi() – Hardware drivers       sleep_state() – Sleep 3.

3 InterruptsThereare two types of interrupt used in the system and they are respectivelyhardware interrupt and software interrupt. The hardware interrupt is raisedfrom a clocked source outside the system every 1 millisecond. The functioncalled irq() is used to reset the variable “tog” which is used to decide which6 tasks should be executed in every tick as in each tick, only 6 LEDs can be executed.The only way to switch different modes (e.g. supervisor mode and user mode) isto use the software interruption instruction.3.4 Scheduler developmentBasedon the basic structure of the scheduler, some development need to be added toachieve the task specification and make the code can be compiled.

3.4.1 MainFunction & Sleep FunctionFor the main function, it aims toinitialise the timer after the previous interrupt finished. The IRQ function istriggered by a condition when “*TIMER_COMPARE_P” has the same value as “*TIMER_P”.

  And sleep function will be executed until thetimer raises first interrupt.             3.4.

2 InterruptFunctionInside the irq function, “irq” signal should be reset and the “*TIMER_COMPARE_P”should be programmed to the next interrupt. As the CPU mode is changed, fromIRQ to SVC, then interrupts become disabled, and “IRQ_ENABLE” should be neededagain. In the following step, a variable tog is set to execute which 6 tasksand for this 6 tasks, the tasks 0,1,2,3 should be always executed in each tick.If tog meet the occasion (‘tog=0’), the task 4 and 5 (LED 4 and 5) should beexecuted. If tog meet the occasion (‘tog=1’), the task 6 and 7 (LED 6 and 7)should be executed.3.

4.3 DispatcherFunctionThemain function of the dispatcher function is to reset the task queue. There is aglobal variable “q_index” to represent which task should be executed, startingfrom task 0.

After arranging the task queue, task function can be executed.Equally as before, when switching from “SVC_MODE” to “USR_MODE”, “IRQ_ENABLE”should be executed. A struct can be defined in the starting part to simplifythe code and to make the flash period and other relevant parameters ofdifferent LEDs corresponds to specific tasks (e.g.

{0,0,500,20,0,0,1000} fortask 0). The struct is shown below.3.4.4 TaskFunctionThetask function mainly contains 3 parts: the sawtooth function, the brightnessfunction and the pwm_counter function. The sawtooth function. The sawtoothfunction is shown as below. For the sawtooth function, it aims to make thevariable (dataa.

b_cnt) add “1” continuously until the variable(dataa.b_cnt) satisfies the “if” statement. When it meets the condition of “if”statement, the variable (dataa.b_cnt) will be 0.Thesecond part is brightness function as shown below. The value of the parameter(dataa.brightness) can be divided into two parts by using an “if” statementto choose between rising and falling part.

This is because that for a flashingcondition, it contains a stage to rise to maximum brightness and another stagefrom maximum brightness to darkness. Thethird part is to light the LEDs by using Pulse Width Modulation (PWM) and theperiod of PWM are required to be set as 20ms (dataa.modulus).

A variable(pwm_counter) is defined which add “1” continuously when the variable is lessthan 20 and when it is equal to 20, it will be 0. As the brightness of LED iscontrolled by PWM, hence the occasion when the LED has maximum brightness(dataa.half_bcnt_mod)should happen simultaneously with the stage that the variable (pwm_counter)should be the value of “dataa.modulus”. According to the analysis above, arelationship between the four parameters can be built shown below: Then,a problem here should be solved that the task function executes a task everytime, which means only one LED can work, but 6 LEDs are asked to worksimultaneously. Thus, by programming as “led_temp |= 1<

4.6 OverrunFunctionInsidethe overrun part, a variable “button” should be defined as the button addresson the board to achieve the task when the button is pressed, the overrunoccasion happens. And inside the task function, task 1 is set as the overruntask and when the button is pressed, all LEDs will stop to do nothing. For theprogram of the task which can make the rest LEDs work as previously except forthe overrun LED, it has not been implemented. 4. ResultsByrecording a video to counter the values of relevant parameters of 8 LEDs in oneminute for 3 times, the relevant data can be recorded into the table shownbelow in table 1.  LED Number   Count Actual Duration Estimated Duration  0 57 1.05 1.

0 1 52 1.15 1.1 2 48 1.20 1.2 3 45 1.33 1.3 4 43 1.

40 1.4 5 39 1.53 1.5 6 37 1.62 1.6 7 35 1.71 1.7 Table 1:LEDs Flashing Times in one minuteByobserving the two columns: Actual Duration and Estimated Duration from thetable, the task specification that LEDs must flash with the periods of 1.

0s,1.1s, 1.2s, 1.3s, 1.4s, 1.

5s, 1.6s and 1.7s correspondingly has been achievedas the values of the actual duration column is almost same with that of theestimated duration column.

Also, in each period of flashing, an LED is requiredto gain and reduce its brightness gradually. By observing the recording videoand the diagram below, it is obvious that the LEDs gain and reduce itsbrightness gradually. (The recording video cannot be upload in the report, so Ijust take several photos of them.).Figure 4?LEDs Flashing Testing1Figure 5: LEDs Flashing Testing 2 Figure 6: LEDs Flashing Testing 3For the overrun occasion, when the button is pressed, allLEDs stop to do nothing and the relevant diagrams shown as below:                                         Figure 7: Overrun Condition All LEDs Stop 1Figure 9: Overrun Condition All LEDs STOP 2Figure 10: Overrun Condition All LEDs Stop 35.

ConclusionThemost part of this scheduler has been finished except for that when the overrunhappens, the other LEDs still work normally and only the overrun LED stop to donothing. I proceed to the part that when I press the button, all LEDs stop todo nothing. Afterthis experience of designing a TTCS scheduler, I learned how the processorschedules the tasks by using a timer to trigger and scheduling can be in differenttypes (e.g. Time Triggered). Also, by switching different modes (supervisormode and user mode) with the software interrupt, the data can be saved indifferent registers.

Also, by designing the scheduler to make the LEDs flash onthe ARM board, I have learned the flow of designing on an ARM board. Moreimportantly, I have learned how to implement theoretical knowledge to the realworld.6. Reference1 Buttazzo, G.

C. (2011). Hardreal-time computing systems: predictable scheduling algorithms andapplications (Vol. 24).

Springer Science & Business Media.2 Atmel | SMART SAM9261 Datasheet. (n.d.). Retrieved fromhttp://ww1.

microchip.com/downloads/en/DeviceDoc/Atmel-6062-ARM926EJ-S-Microprocessor-SAM9261_Datasheet.pdf3 Naked Functions. (n.d.). Retrieved fromhttps://msdn.

microsoft.com/en-us/library/21d5kd3a.aspx7. AppendixScheduler Code