Function tc_find_mck_divisor()

Find the best PBA/MCK divisor.

uint32_t tc_find_mck_divisor(
		uint32_t ul_freq,
		uint32_t ul_mck,
		uint32_t * p_uldiv,
		uint32_t * ul_tcclks,
		uint32_t ul_boardmck)

For SAM4L devices: Finds the best PBA divisor given the timer frequency and PBA clock. The result is guaranteed to satisfy the following equation:
(ul_pbaclk / (2* DIV * 65536)) <= freq <= (ul_pbaclk / (2* DIV)) 
with DIV being the lowest possible value, to maximize timing adjust resolution.
For non SAM4L devices: Finds the best MCK divisor given the timer frequency and MCK. The result is guaranteed to satisfy the following equation:
(MCK / (DIV * 65536)) <= freq <= (MCK / DIV) 
with DIV being the lowest possible value, to maximize timing adjust resolution.
Table 1. Parameters
Data direction Parameter name Description

[in]

ul_freq

Desired timer frequency

[in]

ul_mck

PBA clock frequency

[out]

p_uldiv

Divisor value

[out]

p_ultcclks

TCCLKS field value for divisor

[in]

ul_boardmck

Board clock frequency (set to 0 for SAM4L devices)

Returns

The divisor found status.

Table 2. Return Values
Return value Description

0

No suitable divisor was found

1

A divisor was found