/* Waiting the specified bit in the register change to SET/RESET.  */
ald_status_t ald_wait_flag(uint32_t *reg, uint32_t bit, flag_status_t status, uint32_t timeout)
/* Waiting the specified bit in the register change to SET/RESET.  */
ald_status_t ald_wait_flag(uint32_t *reg, uint32_t bit, flag_status_t status, uint32_t timeout)
{
	uint32_t tick = ald_get_tick();
	assert_param(timeout > 0);
	if (status == SET) {
		while (!(IS_BIT_SET(*reg, bit))) {
			if (((ald_get_tick()) - tick) > timeout)
				return TIMEOUT;
		}
	}
	else {
		while ((IS_BIT_SET(*reg, bit))) {
			if (((ald_get_tick()) - tick) > timeout)
				return TIMEOUT;
		}
	}
	return OK;
}