/**====================================================================================**
* @brief Get free TMOS memory. This function same as tmos_memory_get_max_block_len()
* @param precision_sz - test space precision in bytes
* @retval Free space in bytes
**====================================================================================**/
ufast16_t BSP_TMOS_FreeMem(ufast16_t precizion_sz)
{
ufast16_t test_sz = BLE_MEMHEAP_SIZE / 4, hi_lim = BLE_MEMHEAP_SIZE, lo_lim = 0;
uint8_t *alloc_p;
while( 1 )
{
if ( (alloc_p = tmos_msg_allocate(test_sz)) != NULL )
{
tmos_msg_deallocate(alloc_p);
lo_lim = test_sz;
}
else
hi_lim = test_sz;
if ( (ufast16_t)(hi_lim - lo_lim) <= precizion_sz )
break;
test_sz = (lo_lim + hi_lim) / 2;
}
return lo_lim;
}