Initializing worker thread returns error

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MaRi_4773796
Level 2
Level 2
10 replies posted 5 replies posted 5 likes given

I am attempting to use a work thread to handle asynchronous events on a 20721, and have run into issues in the initialization of the thread itself.  The code for initialization looks like

 

wiced_worker_thread_t *buttonThreadHandle;

buttonThreadHandle = wiced_rtos_create_worker_thread();
wiced_result_t result =
    wiced_rtos_init_worker_thread(buttonThreadHandle, THREAD_PRIORITY, THREAD_STACK_SIZE, 5);

 


where the thread priority is set to 4 and the stack size is set to 1024.   The resulting code returned from the initialization routine is 0x28 - which is  simply ERROR.  I have increased the max number of buffer pools from 6 to 7.  What am I doing wrong here?

0 Likes
1 Solution
MaRi_4773796
Level 2
Level 2
10 replies posted 5 replies posted 5 likes given

OK...so found the reason for this error - buffer pools had been misconfigured.  My current settings look like the default now

const wiced_bt_cfg_buf_pool_t wiced_bt_cfg_buf_pools[] =
{
/*  { buf_size, buf_count } */
    { 64,       12  },      /* Small Buffer Pool */
    { 360,      8   },      /* Medium Buffer Pool (used for HCI & RFCOMM control messages, min recommended size is 360) */
    { 720,      5   },      /* Large Buffer Pool  (used for HCI ACL messages) */
    { 1024,     0   },      /* Extra Large Buffer Pool - Used for avdt media packets and miscellaneous (if not needed, set buf_count to 0) */
};

This fixed it.  But now having an issue with the firing of an asynchronous event.  When an event is sent, I am getting an error.  Thoughts?

View solution in original post

8 Replies
MaRi_4773796
Level 2
Level 2
10 replies posted 5 replies posted 5 likes given

OK...so found the reason for this error - buffer pools had been misconfigured.  My current settings look like the default now

const wiced_bt_cfg_buf_pool_t wiced_bt_cfg_buf_pools[] =
{
/*  { buf_size, buf_count } */
    { 64,       12  },      /* Small Buffer Pool */
    { 360,      8   },      /* Medium Buffer Pool (used for HCI & RFCOMM control messages, min recommended size is 360) */
    { 720,      5   },      /* Large Buffer Pool  (used for HCI ACL messages) */
    { 1024,     0   },      /* Extra Large Buffer Pool - Used for avdt media packets and miscellaneous (if not needed, set buf_count to 0) */
};

This fixed it.  But now having an issue with the firing of an asynchronous event.  When an event is sent, I am getting an error.  Thoughts?

Hi,

Could you please monitor the buffer usage statistics periodically? Check any allocated  buffer is overflowing. wiced_bt_get_buffer_usage(). Also you can try increasing the large buffer pool or extra large buffer pools as per the available remaining memory. (Use wiced_memory_get_free_bytes() for checking memeory usage.)

 

Please refer this document to know what are recommended in setting buffer pools. 

https://github.com/cypresssemiconductorco/btsdk-docs/blob/master/docs/BT-SDK/WICED-Application-Buffe... 

Thanks,

-Dheeraj

Thanks Dheeraj - I have seen this document.  What would be nice is if the document actually gave some specifics on how to set up the memory pools - i.e. a strategy for design based on use that goes beyond what is provided (such as how much space should be allocated for the stack of a worker thread).

0 Likes

Dheeraj,

Do you have an example of how to use wiced_bt_get_buffer_usage?  Do you allocated enough space for returning all pool statistics?  What happens if you don't provide enough space?

Matt

0 Likes

Hi,

You can try calling below function where ever you want to print the buffer statistics. 

 

void deb_print_buf_use()

{

    wiced_bt_buffer_statistics_t buff_stat[4];

    wiced_bt_get_buffer_usage(buff_stat, sizeof(buff_stat));

    WICED_BT_TRACE("pool size/cur/max/total %d/%d/%d/%d %d/%d/%d/%d %d/%d/%d/%d %d/%d/%d/%d\n",

        buff_stat[0].pool_size, buff_stat[0].current_allocated_count, buff_stat[0].max_allocated_count, buff_stat[0].total_count,

        buff_stat[1].pool_size, buff_stat[1].current_allocated_count, buff_stat[1].max_allocated_count, buff_stat[1].total_count,

        buff_stat[2].pool_size, buff_stat[2].current_allocated_count, buff_stat[2].max_allocated_count, buff_stat[2].total_count,

        buff_stat[3].pool_size, buff_stat[3].current_allocated_count, buff_stat[3].max_allocated_count, buff_stat[3].total_count);

}

 

Thanks,

-Dheeraj

Thanks, Dheeraj.  I had gotten it earlier.  But I am not certain what to make of it.  I basically have it printing every 10 s and I get output that looks like this:

 

Buffer Allocation:
ID      Pool Size       Current Allocated       Max Allocated   Total
0       64              3                       12              12
1       360             1                       3               8
2       720             0                       0               5
3       1024            0                       0               0
4       16              0                       0               5

 

In this context, what does buffer overflow mean?  Given that I am maxing out my smallest buffer pool, should I be allocating more to this pool?

 

0 Likes

Hi,

May I know what is ID No. 4?  

It would be great if you can share the code snippet with us so that we can try reproducing the error at our side. 

Thanks,

-Dheeraj

0 Likes
MaRi_4773796
Level 2
Level 2
10 replies posted 5 replies posted 5 likes given

So the reason that I was unable to get the event to fire properly is that I was not providing a sufficient stack size it seems.  Initially this was set to 512 - bumped to 4096.