/* For internal use only. If a peripheral access semphore is not defined, just return STATUS_OK and take no other action. If a peripheral access semphore is defined, attempt to obtain the semphore. Return STATUS_OK if the semphore was obtained, and ERR_TIMEOUT if the semphore did not become available within max_block_time_ticks tick periods.  */
status_code_t freertos_obtain_peripheral_access_semphore(freertos_dma_event_control_t *dma_event_control, portTickType *max_block_time_ticks)
/* For internal use only. If a peripheral access semphore is not defined, just return STATUS_OK and take no other action. If a peripheral access semphore is defined, attempt to obtain the semphore. Return STATUS_OK if the semphore was obtained, and ERR_TIMEOUT if the semphore did not become available within max_block_time_ticks tick periods.  */
status_code_t freertos_obtain_peripheral_access_semphore(freertos_dma_event_control_t *dma_event_control, portTickType *max_block_time_ticks)
{
	status_code_t return_value = STATUS_OK;
	xTimeOutType time_out_definition;
	if (dma_event_control->peripheral_access_sem != NULL) {
		vTaskSetTimeOutState(&time_out_definition);
		if (xSemaphoreTake(dma_event_control->peripheral_access_sem,
				*max_block_time_ticks) == pdFAIL) {
			return_value = ERR_TIMEOUT;
		} else {
			if (xTaskCheckForTimeOut(&time_out_definition,
					max_block_time_ticks) == pdTRUE) {
				*max_block_time_ticks = 0;
			}
		}
	}
	return return_value;
}