<?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>_free_box failing, memory pool filling up</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/26719/_free_box-failing-memory-pool-filling-up</link><description> 
Hi, 

 
I am using RL-ARM 4.01 on a STMicro Cortex-M3 (uVision V4.00a),
and having some trouble with mailboxes. The key issue is that
_free_box is failing (have verified this in debug), and as a result I
run out of memory in the memory pool very quickly</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: _free_box failing, memory pool filling up</title><link>https://community.arm.com/thread/125923?ContentTypeID=1</link><pubDate>Mon, 28 Dec 2009 14:18:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a5334ab4-0dd3-403a-94bf-9a25ecbd8f6a</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I had previously been putting the following at the top of my
file&lt;b&gt;s&lt;/b&gt;:&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Therein lies a considerable problem. You should only ever be
adding a declaration to &lt;b&gt;one&lt;/b&gt; file: the header file exporting
the interface of the C file defining the things in question. As a
rule of thumb you should never put &amp;#39;extern&amp;#39; in a *.c file, nor
&amp;#39;static&amp;#39; in a header file.&lt;/p&gt;

&lt;p&gt;
Among the things this avoids is a conflict between the actual
definition of a variable (or function) in one module and the
declarations seen in the others; which has a considerable probability
of causing just the kind of problem you&amp;#39;ve been discussing here. So
don&amp;#39;t do that.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: _free_box failing, memory pool filling up</title><link>https://community.arm.com/thread/115470?ContentTypeID=1</link><pubDate>Tue, 22 Dec 2009 19:32:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:af44b0e3-dc6a-4b2b-a849-36bf205364af</guid><dc:creator>David Merrill</dc:creator><description>&lt;p&gt;&lt;p&gt;
I got it working, though I don&amp;#39;t totally understand the solution.
Turns out the way I was extern-ing the mailbox and memory pool into
my various libraries was incorrect in some way. I had previously been
putting the following at the top of my files:&lt;/p&gt;

&lt;pre&gt;
extern OS_MBX Outbox_mailbox;
extern void * Outbox_mpool;
&lt;/pre&gt;

&lt;p&gt;
...but when I changed this to the following, it started working
properly:&lt;/p&gt;

&lt;pre&gt;
extern OS_MBX Outbox_mailbox;
extern u32 Outbox_mpool[];
&lt;/pre&gt;

&lt;p&gt;
I&amp;#39;m considering the case closed with respect to debugging, but I
am curious why the first declaration messed things up, while the new
one works.&lt;/p&gt;

&lt;p&gt;
thanks,&lt;br /&gt;
-David&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: _free_box failing, memory pool filling up</title><link>https://community.arm.com/thread/78017?ContentTypeID=1</link><pubDate>Tue, 22 Dec 2009 16:25:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f8a818d7-f619-4bfb-9754-b84b8a745b2e</guid><dc:creator>David Merrill</dc:creator><description>&lt;p&gt;&lt;p&gt;
yes, I have checked to make sure that the pointer to the message
is within the memory bounds of the pool.. the message format is:&lt;/p&gt;

&lt;pre&gt;
typedef struct {
t_command command; // is a uint8_t
uint8_t address;
uint8_t length;
uint8_t payload[29];
} t_Message_mailbox;
&lt;/pre&gt;

&lt;p&gt;
Note that the struct is 32 bytes long, though I&amp;#39;m not sure how the
byte-alignment is working out -- anyone know if this struct is
actually taking up more than 32 bytes?&lt;/p&gt;

&lt;p&gt;
To initialize the mailboxes, I have the following 2 declarations
at the top of my code (macros):&lt;/p&gt;

&lt;pre&gt;
os_mbx_declare(Outbox_mailbox, 16);
_declare_box(Outbox_mpool,sizeof(t_Message_mailbox),16);
&lt;/pre&gt;

&lt;p&gt;
Then these are happening before use:&lt;/p&gt;

&lt;pre&gt;
_init_box(Outbox_mpool,sizeof(Outbox_mpool),sizeof(t_Message_mailbox));
os_mbx_init(Outbox_mailbox,sizeof(Outbox_mailbox));
&lt;/pre&gt;

&lt;p&gt;
The memory pool begins at: 0x20006BC4, and the first message
allocated with _alloc_box is at address 0x20006BF0 (44 bytes in).&lt;/p&gt;

&lt;p&gt;
The message that the code is retrieving from the mailbox with the
following line of code is the same one as the code stuck into the
mailbox. Retrieval is with the following code (this is the call to
_free_box that is failing):&lt;/p&gt;

&lt;pre&gt;
rv = os_mbx_wait(Outbox_mailbox, (void **)&amp;amp;outboxMsgPtr, 0xffff);
        ProcessMessage(outboxMsgPtr);

        if (_free_box(Outbox_mpool,outboxMsgPtr)) {
                // @todo error here
        }
&lt;/pre&gt;

&lt;p&gt;
..and for completeness, the code that sticks the message into the
mailbox is the following:&lt;/p&gt;

&lt;pre&gt;
        entries = os_mbx_check(Outbox_mailbox);
        if (entries &amp;gt; 0) {
                mptr = _alloc_box(Outbox_mpool);
                mptr-&amp;gt;command = (t_command)this_cmd;
                mptr-&amp;gt;length = 4;
                mptr-&amp;gt;payload[0] = recentPacketIDX &amp;gt;&amp;gt; 24;
                mptr-&amp;gt;payload[1] = recentPacketIDX &amp;gt;&amp;gt; 16;
                mptr-&amp;gt;payload[2] = recentPacketIDX &amp;gt;&amp;gt; 8;
                mptr-&amp;gt;payload[3] = recentPacketIDX;
                os_mbx_send(Outbox_mailbox,mptr,0xFFFF);

        } else {
                        // @todo: error here, mailbox was full!
        }
&lt;/pre&gt;

&lt;p&gt;
So basically I&amp;#39;m stumped. As far as I can tell I&amp;#39;m declaring and
initializing the mailboxes correctly, sticking messages in and
getting them out correctly, and calling _free_box on the right thing.
Anyone have thoughts on why _free_box would be failing?&lt;/p&gt;

&lt;p&gt;
thanks in advance.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: _free_box failing, memory pool filling up</title><link>https://community.arm.com/thread/57491?ContentTypeID=1</link><pubDate>Tue, 22 Dec 2009 15:08:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:32925aa7-50c9-4b4c-9e8b-27837c490b5b</guid><dc:creator>Robet McNamara</dc:creator><description>&lt;p&gt;&lt;p&gt;
Verify that the pointer that is being passed into _free_box is
actually within the membox.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>