This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DSP/BIOS TSK_disable() and malloc()

Other Parts Discussed in Thread: OMAP-L138

Hi,

We're using DSP/BIOS 5.41.03.17 on the OMAP-L138 and had the following code:

  TSK_disable() ;

  x = malloc( 128 ) ;

  ...

  TSK_enable() ;

  free (x) ;

For some reason after calling this code the system would hang in future malloc() calls.  Moving malloc() before TSK_disable() made everything work again.  Is the above code bad?  If so, is placing TSK_disable() around any function listed at "http://processors.wiki.ti.com/index.php/DSP_BIOS_FAQ#Q:_Can_runtime_support_.28RTS.29_functions_be_called_when_using_DSP.2FBIOS.3F" considered bad?

 

On a related note, is it OK to do things like the following?

1) TSK_disable() ; my_global_flag = 0; SEM_postBinary(...) ; TSK_enable() ;

2) key = _disable_interrupts() ; my_global_flag2 = 0 ; SEM_postBinary(...) ; _restore_interrupts(key) ;

 

Thanks,

Will

 

  • Will --


    malloc() uses the MEM module internally.  MEM uses LCK to keep the heap thread safe.   LCK uses SEM for mutex.   You should not call SEM_pend/post() from within a TSK_disable/enable block.  So, you should not call malloc() within such a block.

    Similarly for SEM_post().  You should not call SEM_post() with interrupts disabled.  The appendix of the BIOS5.x API manual summarizes calling context for assorted APIs.

    -Karl-

  • Hi Karl,

    That makes sense about malloc().

    However, I'm confused about SEM_post().  On page 461 SPRU403Q says "If SEM_post is called from within a TSK_disable/TSK_enable block, the semaphore operation is not processed until TSK_enable is called."  From that statement it appears SEM_post() can be called within a TSK_disable/enable block.  Is that correct?

    How can I tell if a function can be called with interrupts disabled?  I've just assumed that if a function can be called from a SWI or HWI, then it can be called with interrupts disabled.  On page 602 (Appendix A) SEM_post() can be called from a SWI or HWI.  Is this an invalid assumption?  If so, where can I find information on if a function can be called with interrupts disabled?

    Thanks,

    Will

     

  • Will,

    It should be okay to call SEM_post()  within a TSK_disable/enable block.

    Its not correct to assume that a function can be called with interrupts disabled just because it can be call from a SWI or HWI.  BIOS SWIs and HWIs typically are executed with interrupts enabled not disabled.  I don't think such a table exists but in general you don't want to call a function which could cause a context switch with interrupts disabled.

    Judah

  • ok - thanks!