/* Free a previously allocated memory block from the Membag pool. 
This function frees memory which has been allocated previously via a successful call to  */
void membag_free(const void *ptr)
/* Free a previously allocated memory block from the Membag pool. 
This function frees memory which has been allocated previously via a successful call to  */
void membag_free(const void *ptr)
{
	uint8_t i;
	uintptr_t p = (uintptr_t)ptr;
	uint8_t block_index;
	for (i = 0; i < ARRAY_LEN(membag_list); i++) {
		if (p >= membag_list[i].start && p < membag_list[i].end) {
			block_index = (p - membag_list[i].start) / membag_list[i].block_size;
			membag_list[i].allocated &= ~((uint32_t)1 << block_index);
			membag_list[i].blocks_free++;
			return;
		}
	}
}