<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>RTX with CMSIS RTOS : dynamically create MUTEX</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/41110/rtx-with-cmsis-rtos-dynamically-create-mutex</link><description> 
hi 

 
i&amp;#39;m searching how to dynamically create mutex in
CMSIS-RTOS/KEIL. 

 
i saw the osMutexCreate only accept const osMutexDef_t * 

 
do you know how i can manage to create a mutex, runtime and
dynamically allocated in memory please ? 

 
i&amp;#39;m porting</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: RTX with CMSIS RTOS : dynamically create MUTEX</title><link>https://community.arm.com/thread/64179?ContentTypeID=1</link><pubDate>Wed, 25 May 2016 15:43:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3a8ab2b3-7ae0-46c1-a9dd-97b3beb59230</guid><dc:creator>Dennis Collins</dc:creator><description>&lt;p&gt;&lt;p&gt;
I had the same issue. I posted a long explanation and a relatively
short fix at another&lt;br /&gt;
thread, here: &lt;a href="http://www.keil.com/forum/61105/#/msg200445"&gt;http://www.keil.com/forum/61105/#/msg200445&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTX with CMSIS RTOS : dynamically create MUTEX</title><link>https://community.arm.com/thread/108473?ContentTypeID=1</link><pubDate>Wed, 14 Oct 2015 15:04:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:27fd3ccd-73e4-4265-a27a-1f912055208c</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Don&amp;#39;t forget that what Linux does is irrelevant when you get to
embedded systems with often very limited amount of RAM.&lt;/p&gt;

&lt;p&gt;
The design is made on the assumption that you should be able to
write applications with zero involvement of malloc/free, which means
there will not be any issues with any fragmented heap making the
software fail after having been run for a longer time. The smaller
heap you have, the more danger you have of fragmentation killing the
application.&lt;/p&gt;

&lt;p&gt;
So what is done is a general-purpose OS is irrelevant when
discussing an implementation for smaller microcontrollers.&lt;/p&gt;

&lt;p&gt;
It&amp;#39;s possible to abuse the original macros a bit to make it easy
to set up a pool of mutex as an array.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTX with CMSIS RTOS : dynamically create MUTEX</title><link>https://community.arm.com/thread/82841?ContentTypeID=1</link><pubDate>Wed, 14 Oct 2015 00:20:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:93f9f742-b0b5-4d49-8162-e51977f71ddf</guid><dc:creator>karl clao</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi,&lt;/p&gt;

&lt;p&gt;
I thank you for your answer. My difficulty with a pool of mutex is
the following one : I&amp;#39;m porting a library which use a lot of mutex
allocation.&lt;/p&gt;

&lt;p&gt;
- I don&amp;#39;t know how many mutex I need in advance, so i&amp;#39;ll need to
create a big pool and try to profile with a variable how many mutex
creation is done in runtime.&lt;/p&gt;

&lt;p&gt;
- the other drawback of the CMSIS-RTOS/RTX implementation is the
initialization process : - first osMutexDef(mutex_name) as a global
variable. - then mutex_id=osMutexCreate(osMutex (mutex_name)); this
is hard to automatize when there is a important number of semaphore,
like a pool described before. This process is very static.&lt;/p&gt;

&lt;p&gt;
- it seems that some other os have a more adapted (dynamic)
process like FREERTOS (xSemaphoreCreateMutex( void ) or some
proprietary ones like TI SYSBIOS or even Linux.&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Etienne&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTX with CMSIS RTOS : dynamically create MUTEX</title><link>https://community.arm.com/thread/69381?ContentTypeID=1</link><pubDate>Fri, 09 Oct 2015 09:15:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5afe9bc1-2e1d-40e1-8c5f-dbc89d9d0658</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
I would have to assume that the &amp;quot;const&amp;quot; there is a lie, and that
they internally type cast away the const attribute. Because the OS
needs write-access to some memory to implement a mutex.&lt;/p&gt;

&lt;p&gt;
Most probably, the &amp;quot;const&amp;quot; is there just to make sure end-user
code that tries to directly modify the osMutexDef_t object will get a
compilation error.&lt;/p&gt;

&lt;p&gt;
The problem with dynamic creation would be the following text:&lt;br /&gt;
&amp;quot;Define a mutex object that is referenced by osMutex.&lt;/p&gt;

&lt;p&gt;
Parameters&lt;br /&gt;
name name of the mutex object.&lt;br /&gt;
Note&lt;br /&gt;
&lt;b&gt;CAN BE CHANGED: The parameter to osMutexDef shall be consistent
but the macro body is implementation specific in every
CMSIS-RTOS.&lt;/b&gt;&amp;quot;&lt;/p&gt;

&lt;p&gt;
With the macro body implementation specific, you can&amp;#39;t know what
actions that must be taken to get your hands on the block of data
that will then be given to osMutexCreate()&lt;/p&gt;

&lt;p&gt;
What you might be able to do, is have a pool of mutex objects that
you then allocate from and osMutexCreate(). But there are no
osMutexDestroy(), and you can&amp;#39;t know if osMutexCreate() may be called
multiple times for the same object. So you might have to define and
create your pool of mutexes once, and then just allocate a osMutexId
from the pool instead of allocating a osMutexDef.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>