Presentation is loading. Please wait.

Presentation is loading. Please wait.

DSP/BIOS System Integration Workshop Copyright © 2004 Texas Instruments. All rights reserved. T TO Technical Training Organization 1 1.Introduction 2.Real-Time.

Similar presentations


Presentation on theme: "DSP/BIOS System Integration Workshop Copyright © 2004 Texas Instruments. All rights reserved. T TO Technical Training Organization 1 1.Introduction 2.Real-Time."— Presentation transcript:

1 DSP/BIOS System Integration Workshop Copyright © 2004 Texas Instruments. All rights reserved. T TO Technical Training Organization 1 1.Introduction 2.Real-Time System Design Considerations 3.Hardware Interrupts (HWI) 4.Software Interrupts (SWI) 5.Task Authoring (TSK) 6.Data Streaming (SIO) 7.Multi-Threading (CLK, PRD) 8.BIOS Instrumentation (LOG, STS, SYS, TRC) 9.Static Systems (GCONF, TCONF) 10.Cache (BCACHE) 11.Dynamic Systems (MEM, BUF) 12.Flash Programming (HexAIS, Flashburn) 13.Inter-Thread Communication (MSGQ,...) 14.DSP Algorithm Standard (XDAIS) 15.Input Output Mini-Drivers (IOM) 16.Direct Memory Access (DMA) 17.Review

2 Objectives  Describe the way BIOS can implement a time base  Setup a time base via the BIOS CLK module  Describe the results of invoking various BIOS CLK API  Set functions to run at a periodic rate via the PRD module  Describe how to implement delayed ‘one-shot’ functions  Describe how the scheduler can be managed via BIOS API  List various BIOS scheduler management API  Select and incorporate scheduler management API to obtain desired performance in a given system T TO Technical Training Organization 2

3  Clock Manager : CLK  Periodic Functions : PRD  Scheduler Control API for:  HWI & IDL  SWI  TSK  Review  Lab Multi-Threading  Can BIOS keep track of time for me?  Can time instead of data availability be used to launch threads?  Can BIOS keep track of time for me?  Can time instead of data availability be used to launch threads? T TO Technical Training Organization 3

4 BIOS Clock Services – CLK API CPU clock  4 or 8 Timer Counter Period Timer ISR Timer Interrupt Low Rate ClockHigh Rate Clock Low Res Clock CLK API Description CLK_getltime Get low-resolution time (32-bit value) CLK_gethtime Get high-resolution time (32-bit value) CLK_getprd Get period register value CLK_countspms Get number of hardware timer counts per millisecond  CLK abstracts details of HW timer to provide low-res time / system tick  Timer period is set and CLK objects specified in BIOS configuration  CLK can drive periodic objects directly, or at different rates as PRD SWI  CLK time values are often helpful in real-time analysis (next module) CLK_countspmsCLK_getprdCLK_getltimeCLK_gethtime System Tick CLK Object(s) + x f T TO Technical Training Organization 4

5 Setup of CLK via Configuration Tool Setup of the CLK Module 1. right click on CLK mgr 2. select “Properties” 3. define Low res clock rate via usecs/int 4. optionally, set other parameters as desired Optional: Making a new CLK object 1. right click on CLK mgr 2. select “Insert CLK” 3. type CLK name 4. right click on new CLK 5. select “Properties” 6. type function to run T TO Technical Training Organization All CLK objects are invoked each Lo Res tick – PRD fxns can run at different intervals – next... 5

6 Multi-Threading  Can I have a number of functions, each invoked at a given periodic rate?  Can I invoke a function that will run once after a given time has passed?  Can I have a number of functions, each invoked at a given periodic rate?  Can I invoke a function that will run once after a given time has passed?  Clock Manager : CLK  Periodic Functions : PRD  Scheduler Control API for:  HWI & IDL  SWI  TSK  Review  Lab T TO Technical Training Organization 6

7 DSP/BIOS Periodic Functions  A special SWI that provides preemptive scheduling for periodic functions  While SIO indicates data available and SEM indicates posting by other thread, when time is the gating event PRD is most ideal choice  Also useful for modeling interrupts to simulate peripherals (IO devices) T TO Technical Training Organization 7

8 Periodic Events – PRD SWI Timer ISR System Tick CLK Object(s) PRD_clock... PRD_tick...  PRD_tick() is invoked by PRD_clock by default (also TSK_tick)  PRD_tick() may be called by any desired user function as well  PRD_tick() launches the PRD_swi which  Scans the list of PRD_obj’s  Determines if the specified time for the given PRD_obj has elapsed  If so, the function associated with the PRD_obj is called  All PRD_obj functions must complete within ONE system (PRD) tick  Recommended: make PRD_swi highest priority SWI  If routines are short and tick is long - no problem  Long functions can be broken up with posts of other threads PRD_swi PRD_obj... PRD Object Period4 FunctionfuncX() Typecontinuous Arg00 Arg10 Period # of ticks before calling fxn Function Function to execute Type Continuous or One-shot T TO Technical Training Organization 8

9 Setup of PRD via Configuration Tool Creating a PRD 1. right click on PRD mgr 2. select “Insert PRD” 3. type PRD name 4. right click on new PRD 5. select “Properties” 6. indicate desired period (ticks) mode function arguments  A PRD can directly launch a regular SWI by specifying:  function: _SWI_post  arg0:_mySWI allowing control of priority, and meeting requirement for all PRDs to complete before the next PRD tick T TO Technical Training Organization _myFxn 9

10 TCONF Setup of PRD Module & Object PRD.OBJMEMSEG = prog.get("myMEM"); where to locate PRD Objects PRD.USECLK = "true"; CLK MOD will feed PRD PRD.MICROSECONDS = 1000.0; uSecs/tick – skip if using CLK var myPrd = PRD.create(“myPrd"); create a PRD Object myPrd.period = 1024; # of ticks between calls to PRD Obj * myPrd.mode = "continuous"; type – continuous or “one-shot” myPrd.fxn = prog.extern(“_myFxn"); function PRD Obj will run myPrd.arg0 = 0; user arguments - optional myPrd.arg1 = 0; T TO Technical Training Organization * Underlying interrupt rate is largest binary number divisible into period value, so for lowest overhead, pick a binary number when possible 10

11 One-shot Periodic Functions  Allows delayed execution of a function by n system ticks  PRD_start() invokes each iteration of the one-shot function  PRD_stop() can be used to abort a one-shot prior to timeout  Example of use: software watchdog function...7475767778798081... Low-res clock (incremented by system tick) PRD Object X Period4 FunctionfuncX() Type 1 shot Arg00 Arg10 PRD_start() funcX() 0123401234 T TO Technical Training Organization 11

12 PRD API Description PRD_tick Advance tick counter, dispatch periodic functions PRD_start Arm a periodic function for onetime execution PRD_stop Stop a periodic function from execution PRD_getticks Get the current tick counter  Tick counter can be manually incremented by the user with PRD_tick()  One-shot periodic functions are managed with PRD_start() & PRD_stop()  Inspection of tick count is possible with PRD_getticks()  Continuous periodic functions are set up via the BIOS configuration tool and are generally not managed at run-time via BIOS API PRD API Review T TO Technical Training Organization 12

13  Clock Manager : CLK  Periodic Functions : PRD  Scheduler Control API for:  HWI & IDL  SWI  TSK  Review  Lab Multi-Threading  Is it possible for me to alter the behaviour of the BIOS scheduler when the need arises? T TO Technical Training Organization 13

14 Scheduler Management API  Generally, threads are automatically managed by BIOS according to the priorities of each thread  Sometimes, however, it is desirable to alter the normal BIOS scheduler operation, for example:  When deadlines are approaching a thread can temporarily be given higher priority or even exclusive use of the processor  When multiple threads share a resource, priorities can be modified to avoid higher priority threads interrupting critical sections of lower priority threads  To implement time slicing amongst equal priority threads (equal threads are normally “FIFO” serviced)  To allow TSKS to ‘sleep’ for a time  In these cases, API can be invoked to alter the behaviour of the scheduler with respect to HWI, SWI, and TSK as required T TO Technical Training Organization 14

15 Multi-Threading What kind of control can I have on how hardware interrupts and the idle thread are scheduled by BIOS?  Clock Manager : CLK  Periodic Functions : PRD  Scheduler Control API for:  HWI & IDL  SWI  TSK  Review  Lab T TO Technical Training Organization 15

16 HWI_disable and _restore API oldCSR = HWI_disable(); //“critical section”... //scheduler inhibited... HWI_restore(oldCSR);  HWI_disable() Creates a period where no asynchronous events may occur  Interrupts that come in during this period will be held off until HWI is re-enabled (if a given interrupt occurs more than once in this period, the additional events will be lost)  HWI_restore() does not necessarily enable interrupts, but instead asserts to state prior to HWI_disable() T TO Technical Training Organization 16

17 HWI and IDL Scheduler API HWI, IDL APIDescription HWI_enableGlobally enable hardware interrupts HWI_disableGlobally disable hardware interrupts HWI_restoreRestore global interrupt enable state IDL_runMake one pass through idle functions* * Not commonly used, not callable by HWI or SWI T TO Technical Training Organization 17 Interrupt management intrinsics: Faster than the BIOS API Unsigned int_disable_interrupts(); Unsigned int_enable_interrupts(); Void_restore_interrupts(unsigned int);

18 Multi-Threading What kind of control can I have on how software interrupts are scheduled by BIOS?  Clock Manager : CLK  Periodic Functions : PRD  Scheduler Control API for:  HWI & IDL  SWI  TSK  Review  Lab T TO Technical Training Organization 18

19 Disabling & Enabling Software Interrupts  Similar to HWI_disable/_restore  Concludes with SWI_enable (not “SWI_restore”)  Acts on SWI scheduling only – HWI continue unchanged  Nestable - number of levels managed by BIOS SWI_disable(); //“critical section”... //SWI scheduler inhibited... SWI_enable(); SWI_disable(); //“critical section”... //SWI scheduler inhibited... SWI_enable(); T TO Technical Training Organization 19

20 Temporary Elevation of SWI Priority  SWI_raisepri() cannot lower priority (actually disables lower priority levels)  Priority returns to the original value when the SWI exits  Original Priority (“origPrio”) should be a local variable  Priority values are bit positions, not integer numbers (eg: priority 7 would be...0100 0000 b)  To elevate a SWI above one (or several other) SWI, use in conjunction with SWI_getpri, as per the example below: origPrio = SWI_raisepri(1<<7); //critical section... //lower prio SWIs inhibited... SWI_restorepri(origPrio); origPrio = SWI_raisepri(SWI_getpri(&swiX)|SWI_getpri(&swiY)); //critical section... //SWI scheduler inhibited... SWI_restorepri(origPrio); For Priority level “X” select 1<<X as the argument to raisepri T TO Technical Training Organization 20

21 Why Isn’t SWI “LowerPri” Available? LowMedHigh Case 1 : Normal Preemption Case 2 : w. SWI_raisepri() 1 2 3 6 5 4 Low Med*V.Hi *raised to ‘Very High’ 1 2 6 3 STACK 4 5 High Case 3 : “lowered” priority? Med High*V.Lo *lowered to ‘Very Low’ 1 2 3 x STACK 4 5 Low T TO Technical Training Organization 21

22 SWI Scheduler API SWI API Description SWI_disable Disable software interrupts SWI_enable Enable software interrupts SWI_getpri Return an SWI’s priority mask SWI_raisepri Temporarily raise an SWI’s priority SWI_restorepri Restore an SWI’s priority to object value SWI_self Return address of SWI’s object T TO Technical Training Organization 22

23 Multi-Threading What kind of control can I have on how tasks are scheduled by BIOS?  Clock Manager : CLK  Periodic Functions : PRD  Scheduler Control API for:  HWI & IDL  SWI  TSK  Review  Lab T TO Technical Training Organization 23

24 Disabling & Enabling Task Scheduling  Similar to SWI_disable/_enable  Acts on TSK scheduling only – SWI &HWI continue unchanged  Nestable - number of levels managed by BIOS TSK_disable(); //“critical section”... //TSK scheduler inhibited... TSK_enable(); TSK_disable(); //“critical section”... //TSK scheduler inhibited... TSK_enable(); T TO Technical Training Organization 24

25 Modification of a Task’s Priority  TSK_setpri() can raise or lower priority  Return argument of TSK_setpri() is previous priority  New priority remains until set again or TSK is deleted and re-created  TSK priority is an integer value: 1 to 15 (unlike SWI, using binary weighted numbers)  To suspend a TSK, set its priority to negative one (-1)  Suspended TSK not part of BIOS TSK scheduling queue  TSK can be activated at any time (by some other thread) via TSK_setpri()  Handy option for statically created TSKs that don’t need to run right away  A TSK can be suspended at any time under BIOS, by itself or another thread origPrio = TSK_setpri(TSK_self(),7); //critical section... //TSK priority increased or reduced... TSK_setpri(TSK_self(),origPrio); T TO Technical Training Organization 25

26 TSK_yield : Time Slicing TSK_D TSK_C TSK_B TSK_A Time Must be Equal Priority! Running Ready  TSK_yield() instructs the BIOS scheduler to move the current TSK to the end of the priority queue  If another TSK of equal priority is ready, it will then be the active TSK  This API can be invoked at any time by the active TSK or any SWI/HWI  If a PRD calls TSK_yield, time slicing amongst equal priority TSKs is achieved T TO Technical Training Organization 26

27 TSK_sleep and TSK_tick  TSK_sleep(Uns sleeptime)  Blocks execution of current TSK for n TSK ticks  TSK_tick()  Similar to PRD_tick for PRD SWIs  Advances the task alarm tick by one count  Default - called from PRD_clock (system tick)  If ‘ticks’ are events and not time, TSK_tick can be called from any thread  TSK_itick() is for use inside ISRs w/o dispatcher T TO Technical Training Organization 27

28 READY RUNNING BLOCKED TERMINATED Task Control Block Model TSK_exit() TSK_sleep() TSK_tick() TSK_yield() BIOS Startup SEM_post() SEM_pend() TSK_setpri() T TO Technical Training Organization 28

29 TSK Scheduler API TSK API Description TSK_disable Disable DSP/BIOS task scheduler TSK_enable Enable DSP/BIOS task scheduler TSK_self Returns address of task object TSK_getpri Get task priority TSK_setpri Set a tasks execution priority TSK_yield Yield processor to equal priority task TSK_sleep Delay execution of the current task TSK_tick Advance system alarm clock TSK_itick Advance system alarm clock (ISR) TSK_time Return current value of system clock T TO Technical Training Organization 29

30 Multi-Threading  Questions ? ...  Questions ? ...  Clock Manager : CLK  Periodic Functions : PRD  Scheduler Control API for:  HWI & IDL  SWI  TSK  Review  Lab T TO Technical Training Organization 30

31 Multi-Threading Adding 2nd thread - dummy load - LED blinker CLK/PRD API to launch dummy thread Use some sched mgmt API to influence performance Adding 2nd thread - dummy load - LED blinker CLK/PRD API to launch dummy thread Use some sched mgmt API to influence performance  Clock Manager : CLK  Periodic Functions : PRD  Scheduler Control API for:  HWI & IDL  SWI  TSK  Review  Lab T TO Technical Training Organization 31

32 CLK – 100mS fxnLoad() read DIP sw’s call asm fn: load (load amt spec’d by sw values) Audio Out (48 KHz) Lab 7a: Multiple Threads ADC AIC33 Audio In (48 KHz) McBSP DRR FIR.c FIR Code DAC AIC33 McBSP DXR udevCodec coeffs.c Coefficients BIOS provided BIOS\Labs\Algos  Begin with Lab 6 solution  Add Load.c and NopLoop.asm (Algos dir) to project  In TCF file: set up CLK rate, create PRD SWI running at 100mSec rate, calling fxnLoad  Build, load, run; test audio w. range of DIP cases dioCodec IOM SIO PRD SWI fxnLoad() 32 DIP Sw’s: T TO Technical Training Organization 00 none 10 low 01 hi 11 >100% 32 tskProcBuf procBuf while() SIO_reclaim(&sioIn) for (i =0, i<HIST; i ++) pIn [i-HIST] = pPriorIn ][ 2*BUF-HIST ]; if( sw0 == 1 ) FIR(in[ pIn-HIST ],out[ pOut ]) else {pOut[i]=pIn[i]} C:\ dvsdk _1_01_00_15 \ psp _1_00_02_00

33 Audio Out (48 KHz) Lab 7b: Multiple Threads - Improved ADC AIC33 Audio In (48 KHz) McBSP DRR FIR.c FIR Code DAC AIC33 McBSP DXR udevCodec coeffs.c Coefficients BIOS provided BIOS\Labs\Algos dioCodec IOM SIO CLK – 100mS PRD SWI Function: _ SEM_post Arg0: _mySem TSK tskLoad() SEM_pend(mySem) call fxnLoad fxnLoad() read DIP sw’s call asm fn: load (load amt spec’d by sw values)  Have PRD SWI post SEM  Put call to fxnLoad in TSK while loop  Add SEM pend to TSK while loop  Create SEM for above signalling  Build, load, run; test audio w. range of DIP cases 32 T TO Technical Training Organization DIP Sw’s: 00 none 10 low 01 hi 11 >100% 33 tskProcBuf procBuf while() SIO_reclaim(&sioIn) for (i =0, i<HIST; i ++) pIn [i-HIST] = pPriorIn ][ 2*BUF-HIST ]; if( sw0 == 1 ) FIR(in[ pIn-HIST ],out[ pOut ]) else {pOut[i]=pIn[i]} C:\ dvsdk _1_01_00_15 \ psp _1_00_02_00

34 T TO Technical Training Organization void fxnLoad(void) { short i; unsigned char mask, dips; static Bool blink = 0; EVMDM6437_I2C_read( I2C_GPIO_GROUP_0, &dips, 1 ); if(hw_sw0 == (dips>>4&1)) {sw0 = hw_sw0 = !(dips>>4&1);} if(hw_sw1 == (dips>>5&1)) {sw1 = hw_sw1 = !(dips>>5&1);} if( ( hw_sw2==(dips>>6&1)) | (hw_sw3== (dips>>7&1)) ){ sw2 = hw_sw2 = !(dips>>6&1); sw3 = hw_sw3 = !(dips>>7&1); } switch(2*sw2+sw3){ case (3) : for (i=0; i< 7; i++){load(5000);} case (2) : for (i=0; i<12; i++){load(5000);} case (1) : load(5500); case (0) : load( 100); } blink^=1; mask = (char)( 0x0F^((1^blink)<<2*sw2+sw3) ); EVMDM6437_I2C_write( I2C_GPIO_GROUP_1, &mask, 1 ); IDL_run(); } Load.c 34

35 ti Technical Training Organization 38


Download ppt "DSP/BIOS System Integration Workshop Copyright © 2004 Texas Instruments. All rights reserved. T TO Technical Training Organization 1 1.Introduction 2.Real-Time."

Similar presentations


Ads by Google