Digital Systems: Hardware Organization and Design

Digital Systems: Hardware Organization and Design

TIBIOS BIOS TI TSKTask TaskAuthoring Authoring TSK Sunday, March 01, 20 20 Dr. Veton Kpuska 1 Dr. Veton Kpuska 2 2 Modify SWI based code to employ TSK Describe the TSK object Create a TSK with the CCS GUI Author TSK code using simple data block pointers Sunday, March 01, 202 0 Demonstrate the use of semaphores in tasks Describe the fundamental concepts of tasks 1 2 3 4 5 6

Objectives Objectives Dr. Veton Kpuska 3 3 Lab Review Task Object Semaphores (SEM) TSK Scheduling TSK vs. SWI Sunday, March 01, 202 0 1 2 3 4 5 6 Outline Outline Dr. Veton Kpuska 3 4 Lab Review Task Object Semaphores (SEM) TSK Scheduling TSK vs. SWI

Sunday, March 01, 202 0 1 2 3 4 5 6 Tasksvs. vs.SWI SWI Tasks TSKvs. vs.SWI SWI TSK Sunday, March 01, 20 20 Dr. Veton Kpuska 5 SchedulerStates: States: Scheduler TSKvs. vs.SWI SWI TSK SWI SWI TSK TSK

Created Created Created Created Inactive Inactive post post Posted Posted completed completed Ready 1 2 Ready when when highest highest priority priority preempted preempted when when preempted highest Blocked highest preempted Blocked priority

priority pend Running 1 2 pend Running Running 1 2 Running Sunday, March 01, 202 0 Ready 1 2 Ready Terminated Terminated Dr. Veton Kpuska 6 TasksAre: Are: Tasks Ready to Run when Created by BIOS startup if specified in GCONF by TSK_create() in dynamic systems (mod 11) Preemptive Blocked when Pending on an unavailable resource Returned to Ready state when resource is posted May be Terminated when no longer needed Sunday, March 01, 202 0

Dr. Veton Kpuska 7 SWIvs. vs.TSK TSK SWI SWI Feature TSK Preemptable - Block, Suspend - Delete prior to completion by other threads - User Name, Error Number, Environment Pointer

Can interface with SIO Faster context switch speed Slower - Context preserved across accesses to thread NO* Can call SEM_pend() System Stack Individual ASM, C API callable by C * SEM_pend with timeout of 0 is allowed Sunday, March 01, 202 0 Dr. Veton Kpuska

8 TSKScheduling Scheduling TSK TSK Scheduling Semaphores (SEM) Task Object Review Lab Sunday, March 01, 202 0 TSK vs. SWI 1 2 3 4 5 6 Dr. Veton Kpuska 9 3 TaskScheduling Scheduling Task Sunday, March 01, 20 20 Dr. Veton Kpuska 10

DSP/BIOSScheduler Scheduler DSP/BIOS HWI priorities set by hardware Hardware Interrupts Hardware Interrupts Fixed number, preemption optional SWI SWI 14 SWI priority levels Any number possible, all preemptive TSK TSK 15 TSK priority levels Tasks Tasks Any number possible, all preemptive IDL

IDL Continuous loop Non-realtime in nature Priority Software Interrupts Software Interrupts Backgroun Backgroun d d Soft Soft R/T R/T HWI HWI Foregroun Foregroun d d Hard Hard R/T R/T Background Background

Sunday, March 01, 202 0 Dr. Veton Kpuska 11 DSP/BIOSScheduler Scheduler DSP/BIOS All TSKs are preempted by all SWIs and HWIs All SWIs are preempted by all HWIs Preemption amongst HWI is determined by user In absence of HWI, SWI, and TSK, IDL functions run in a loop Sunday, March 01, 202 0 Dr. Veton Kpuska 12 ThreadPreemption PreemptionExample Example Thread postreturnpostreturn swi1 swi2 HWI postreturn

swi2 post post sem1 sem2 return return SWI 2 SWI 1 postreturn sem2 return pend sem2 pend sem2 interrupt TSK 2 pend sem1 pend sem2 pend sem1 TSK 1 interrupt interrupt IDL interrupt

Events over time Sunday, March 01, 202 0 Dr. Veton Kpuska 13 Dr. Veton Kpuska 3 14 Lab Review Task Object Semaphores(SEM) (SEM) Semaphores TSK Scheduling TSK vs. SWI Sunday, March 01, 202 0 1 2 33 4 5 6 TSKScheduling Scheduling TSK Semaphores(SEM) (SEM) Semaphores

Sunday, March 01, 20 20 Dr. Veton Kpuska 15 TaskCode CodeTopology: Topology: Task SEMPosting Posting SEM Void taskFunction() Void { taskFunction() { Initialization (runs once only) /* Prolog */ /* Prolog */ while (condition) { while (condition) { SEM_pend(); SEM_pend(); /* Process */ /* Process */ } Perform desired DSP work... } /* Epilog */ /* Epilog */ } Processing loop - option:

termination condition Wait for resources to be available Shutdown (runs once - at most) } Sunday, March 01, 202 0 Dr. Veton Kpuska 16 TaskCode CodeTopology: Topology: Task SEMPosting Posting SEM TSK can encompass three phases of activity SEM can be used to signal resource availability to TSK SEM_pend() blocks TSK until next buffer is available Sunday, March 01, 202 0 Dr. Veton Kpuska 17 SemaphorePending: Pending: Semaphore SEM_pend() SEM_pend() SEM_pend(&sem,timeout) Pend SEM_pend(&sem,timeout) Pend

yes yes timeout = 0 false false true true Count > 0 Count > 0 Decrement count Decrement count no timeout timeout Block task expires Block task expires SEM SEM posted Return posted Return FALSE FALSE Semaphore Structure: Semaphore Structure: Non-negative 16-bit counter Non-negative 16-bit counter Pending queue (FIFO) Pending queue (FIFO) Return Return

TRUE TRUE #define SYS_FOREVER (Uns) #define SYS_POLL (Uns) Sunday, March 01, 202 0 Dr. Veton Kpuska -1 // wait forever 0 // dont wait 18 SemaphorePost: Post: Semaphore SEM_post() SEM_post() SEM_post(&sem) Increment Increment count count False Post Post Task True Task pending on pending on sem? sem? Semaphore Structure: Semaphore Structure: Non-negative count

Non-negative count Pending queue (FIFO) Pending queue (FIFO) Ready first Ready first waiting waiting task task Task switch will Task switch will occur if higher occur if higher priority task is priority task is made ready made ready Return Return Sunday, March 01, 202 0 Dr. Veton Kpuska 19 Creationof ofSEM SEMObject Object Creation Creating a new SEM Obj Creating a new SEM Obj 1. right click on SEM mgr 1. right click on SEM mgr 2. select Insert SEM

2. select Insert SEM 3. type object name 3. type object name 4. right click on new SEM 4. right click on new SEM 5. select Properties 5. select Properties 6. indicate desired 6. indicate desired User Comment (FYI) User Comment (FYI) Initial SEM count Initial SEM count Sunday, March 01, 202 0 var mySem = SEM.create("mySem"); mySem.comment = "my SEM"; mySem.count = 0; Dr. Veton Kpuska 20 SEMAPI APISummary Summary SEM SEM API Description SEM_pend SEM_post Wait for the semaphore Signal the semaphore SEM_pendBinary

SEM_postBinary Wait for binary semaphore to = 1 Write a 1 to the specified semaphore SEM_count SEM_reset SEM_new SEM_ipost Get the current semaphore count Reset SEM count to the argument-specified value Puts specified count value in specified SEM SEM_create SEM_delete Create a semaphore Delete a semaphore Sunday, March 01, 202 0 SEM_post in ISR obsolete use SEM_post Dr. Veton Kpuska Mod 11 21 Dr. Veton Kpuska 3 22 Lab Review TaskObject

Object Task Semaphores (SEM) TSK Scheduling TSK vs. SWI Sunday, March 01, 202 0 1 2 3 44 5 6 TSKScheduling Scheduling TSK TaskObject Object Task Sunday, March 01, 20 20 Dr. Veton Kpuska 23 StaticCreation Creationof ofTSK TSK Static Creating a new TSK 1.right click on TSK mgr 2.select Insert TSK

3.type TSK name 4.right click on new TSK 5.select Properties 6.indicate desired priority stack properties function arguments etc Sunday, March 01, 202 0 Dr. Veton Kpuska 24 TaskObject ObjectConcepts... Concepts... Task Task object: fxn * environ * priority 6 stack Stores local variables name Nested function calls Makes blocking possible

Interrupts run on the inst2 fxn system stack environ * Pointer to task function Priority: changable Pointer to tasks stack myTsk Pointer to text name of TSK Environment: pointer to user defined structure: lpf1 * * priority 6 stack * name lpf2 struct struct

myEnv myEnv TSK TSK stack stack C fxn, C fxn, eg: bk FIR eg: bk FIR struct struct myEnv myEnv TSK TSK stack stack TSK_setenv(TSK_self(),&myEnv); hMyEnv = TSK_getenv(&myTsk); Sunday, March 01, 202 0 Dr. Veton Kpuska 25 TSKObject Object TSK typedef struct TSK_Obj { KNL_Obj kobj; Ptr stack; size_t stacksize; Int stackseg;

String name; Ptr environ; Int errno; Bool exitflag; } TSK_Obj, *TSK_Handle; // from TSK.h // kernel object // used w TSK_delete() // ditto // stack allocn RAM // printable name // environment pointer // TSK_seterr()/_geterr() // FALSE for server tasks struct KNL_Obj { QUE_Elem QUE_Elem QUE_Elem QUE_Handle Int Uns Ptr Uns Int STS_Obj Bool }; // from KNL.h // ready/sem queue // alarm queue elem // set priority queue // task's ready queue // task priority

// 1 << priority // current stack ptr // timeout value // blocked, ready, ... // for TSK_deltatime() // woken by sem or t-out ready; alarm; setpri; queue; priority; mask; sp; timeout; mode; *sts; signalled; Sunday, March 01, 202 0 typedef struct TSK_Stat { TSK_Attrs attrs; TSK_Mode mode; Ptr sp; size_t used; } TSK_Stat; typedef struct TSK_Attrs { Int priority; Ptr stack; size_t stacksize; Int

stackseg; Ptr environ; String name; Bool exitflag; Bool initstackflag; } TSK_Attrs; // task attributes // running, blocked... // stack ptr // stack max // task priority // stack supplied // size of stack // stack allocn seg // environment pointer // printable name // server tasks = false // FALSE: no stack init typedef struct TSK_Config { Int STACKSEG; Int PRIORITY; size_t STACKSIZE; Fxn CREATEFXN; Fxn DELETEFXN; Fxn EXITFXN; Fxn SWITCHFXN;

Fxn READYFXN; } TSK_Config; Dr. Veton Kpuska 26 TSKScheduling Scheduling TSK Sunday, March 01, 202 0 Dr. Veton Kpuska 27 3 Review Review Sunday, March 01, 20 20 Dr. Veton Kpuska 28 TSKAPI APISummary Summary TSK

TSK API Description TSK_exit Terminate execution of the current task TSK_getenv Get task environment TSK_setenv Set task environment TSK_getname Get task name TSK_create Create a task ready for execution TSK_delete Delete a task Mod 11 Mod 11 Most TSK API are used outside the TSK so other parts of the system can interact with or control the TSK Most TSK API are to allow: TSK scheduler management (Mod 7) TSK monitor & debug (Mod 8) Dynamic creation & deletion of TSK (Mod 11) TSK author usually has no need for any TSK API within the TSK code itself

Sunday, March 01, 202 0 Dr. Veton Kpuska 29 TSKAPI APISummary Summary TSK TSK API Description TSK_settime Set task statistics initial time TSK_deltatime Record time elapsed since TSK made ready TSK_getsts Get task STS object TSK_seterr Set task error number TSK_geterr Get task error number TSK_stat Retrieve the status of a task TSK_checkstacks

Check for stack overflow TSK_disable Disable DSP/BIOS task scheduler TSK_enable Enable DSP/BIOS task scheduler TSK_getpri Get task priority TSK_setpri Set a tasks execution priority TSK_tick Advance system alarm clock TSK_itick Advance system alarm clock (ISR) TSK_sleep Delay execution of the current task TSK_time Return current value of system clock TSK_yield Yield processor to equal priority task Sunday, March 01, 202

0 Dr. Veton Kpuska Mod 8 Mod 7 30 21 TSKScheduling Scheduling TSK Sunday, March 01, 202 0 Dr. Veton Kpuska 31 3 Lab Lab Sunday, March 01, 20 20 Dr. Veton Kpuska 32 Lab5: 5:Task TaskThread Thread--TSK TSK

Lab BIOS\Labs\HW Audio In (48 KHz) Audio Out (48 KHz) ADC McBSP ADC McBSP AIC33 DRR AIC33 DRR mcbsp.c mcbsp.c DAC McBSP DAC McBSP AIC33 DXR AIC33 DXR BIOS\Labs\Algos BIOS\Labs\Algos FIR.c FIR.c FIR Code FIR Code coeffs.c coeffs.c Coefficients Coefficients Sunday, March 01, 202

0 BIOS\Labs\Work isrAudio HWI12 pInBuf[bkCnt]=MCBSP_read MCBSP_write(pOutBuf[bkCnt]) if(bkCnt=2*BUF) { QUE_put(&from DevQbufs) SEM_post(&mySem) bkCnt=0; } procBuf tskProcBuf while() SEM_pend(&mySem) for (i =0, i

Modify SWI to run as TSK; add SEM_pend and while loop TCF: remove SWI obj, add TSK and SEM objs Modify HWI to post SEM instead of SWI Build, load, test, verify performance Sunday, March 01, 202 0 Dr. Veton Kpuska 34 Lab55::Summary Summary Lab In the TCF file: replace the processing SWI with a TSK create a SEM In audio.c: In the isrAudio (HWI) function: Post a SEM instead of the SWI In the procBuf (TSK) function Add a while loop and SEM_pend to the remaining code in procBuf() Build, download, run, and verify the correct operation of the new solution Optionally, copy the solution files to C:\BIOS\mySols\05 Sunday, March 01, 202 0 Dr. Veton Kpuska 35 Lab5: 5:Procedure ProcedureOverview Overview Lab

Below are the steps required to adapt the SWI-based processing thread to a TSK-based version. 1. If necessary, start CCS and open the solution from lab 4. Build the project and verify it performs properly In myWork.tcf : 2. Replace the SWI that called procBuf with a TSK named tskProcBuf 3. Create a SEM named semBufRdy In isr.c 4. Replace the SWI_post() with a SEM_post() of semBufRdy Sunday, March 01, 202 0 Dr. Veton Kpuska 36 Lab5: 5:Procedure ProcedureOverview Overview Lab In proc.c 5. Add a while(1) loop around all the iterative code in procBuf. 6. Add a SEM_pend on the newly created semaphore as the first line of the while loop Having completed the adaptation steps you can now: 7. Build, load, run, and verify the correct operation of the new solution 8. (optional) Relocate the initialization of the messages and toDevQ to the prolog of the TSK. While not required, this makes the TSK a more complete (and instantiable) component 9. Using windows explorer, copy all files from C:\BIOS\Labs\ Work to C:\BIOS\mySols\05 Sunday, March 01, 202 0

Dr. Veton Kpuska 37 LabDetails Details Lab HWI based lab 3 SWI based lab 4 Filter Off On Filter Off On Debug 18% 61% Debug 3.8% 45% TSK based Filter Off On Release 4.7% 6.5% Release

2.3% 3.7% lab 5 Debug 3.8% 45% Sunday, March 01, 202 0 Release 2.5% 3.8% Observations: Moving from SWI to TSK showed results within 0.1% of being the same So the extra overhead of TSK vs. SWI doesnt really amount to much at all, and could easily be countered by a small increase in buffer size, which will have much greater effect than thread type Dr. Veton Kpuska 38 TIBIOS BIOSTSK TSK TI END END

Sunday, March 01, 20 20 Dr. Veton Kpuska 39

Recently Viewed Presentations

  • ENSC 301: Sustainable Development Series

    ENSC 301: Sustainable Development Series

    Arial ヒラギノ角ゴ Pro W3 Times New Roman MS Pゴシック Wingdings Tahoma Times ENSC 301_Intro Lecture 1_ENSC 301_Intro Lecture Multifunctional agricultural landscapes in the urban fringe Multi-functionality Multi-functionality in agriculture Multi-functional agricultural landscapes Question Case Studies Data collection Qualatative ...
  • Frog Dissection - Allen Independent School District

    Frog Dissection - Allen Independent School District

    Frog Dissection Lab Practicum Test Review Study these frog parts and questions for the lab practical test. It will be VERY similar to the slides seen here. ... Tongue Vomerine teeth Nervous, integumentary, digestive systems Maxillary teeth- they go all...
  • A4B Project Management Seminar January 14th 2010 Agenda

    A4B Project Management Seminar January 14th 2010 Agenda

    A4B Project Management Seminar January 14th 2010 Applying to A4B - the Competitive Calls Calls issued in November 2009 Deadline February 26th 2010 Projects to start June 1st 2010 KTC and CIRPS only Only 2 submissions allowed per institution Key...
  • Unit III - sritsense.weebly.com

    Unit III - sritsense.weebly.com

    Add the squares together, and then take the square root of that sum to find the distance. For this example, 25 added to 16 is 41, and the square root of 41 is 6.403. (This is the Pythagorean Theorem at...
  • Soil Conservation - MRS. KUZMICKI

    Soil Conservation - MRS. KUZMICKI

    Contour Plowing Plowing along curves or contours of a slope to prevent water from running straight downhill 5. Wind Breaks Rows of trees between fields to "break" or reduce the force of winds. Soil Conservation Examples Find a partner. Read...
  • The Dynamics of Taiwan&#x27;s Party Politics and the 2010 ...

    The Dynamics of Taiwan's Party Politics and the 2010 ...

    The Dynamics of Taiwan's Party Politics and the 2010 Municipal Election Yun-han Chu December 6, 2010 CDDRL, Stanford University * * * * The Nature of the 2010 Election A mid-term score-card for Ma's presidency DPP tried to define the...
  • Separable Verbs - worldofteaching.com

    Separable Verbs - worldofteaching.com

    Separable Verbs There is a group of verbs in German called separable verbs = trennbare Verben They consist of a prefix and the main verb ab waschen This is how they appear in the infinitive: As one word! abwaschen When...
  • Chapter 1 Introduction

    Chapter 1 Introduction

    O 50.7% Mg 15.3% Fe 15.2% Si 14.4% S 3.0% Al 1.4% Ca 1.0% Most important elements Partial Melting: The Origin of Basalt and Granite Asthenosphere 40% Silica Melting Basaltic magma = 50% silica (1100o C) Forms the rock basalt...