Exemplo n.º 1
0
uint32_t ssp_drv_set_clk(SSP_ID_Type ssp_id, uint32_t freq)
{
	mdev_t *mdev_p;
	sspdev_data_t *ssp_data_p;
	uint16_t divider;

	if (!IS_SSP_PERIPH(ssp_id) || freq <= 0)
		return -WM_FAIL;
	/* Check ssp_id is initialized */
	mdev_p = mdev_get_handle(mdev_ssp_name[ssp_id]);
	if (!mdev_p) {
		SSP_LOG("Unable to open device %s\r\n",
			mdev_ssp_name[ssp_id]);
		return -WM_FAIL;
	}
	ssp_data_p = (sspdev_data_t *) mdev_p->private_data;
	/* Calculate Divider */
	divider = (uint32_t)(board_cpu_freq()/freq);
	ssp_data_p->freq = (uint32_t)((board_cpu_freq() / divider));

	if (!IS_SSP_DIVIDER(divider)) {
		SSP_LOG("Unable to set %u frequency for %s %d\r\n",
			freq, mdev_ssp_name[ssp_id], divider);
		ssp_data_p->freq = 0;
		return -WM_FAIL;
	}
	switch (ssp_id) {
	case SSP0_ID:
		CLK_ModuleClkEnable(CLK_SSP0);
		CLK_SSPClkSrc(CLK_SSP_ID_0, CLK_SYSTEM);
		CLK_ModuleClkDivider(CLK_SSP0, divider);
		break;
	case SSP1_ID:
		CLK_ModuleClkEnable(CLK_SSP1);
		CLK_SSPClkSrc(CLK_SSP_ID_1, CLK_SYSTEM);
		CLK_ModuleClkDivider(CLK_SSP1, divider);
		break;
	case SSP2_ID:
		CLK_ModuleClkEnable(CLK_SSP2);
		CLK_SSPClkSrc(CLK_SSP_ID_2, CLK_SYSTEM);
		CLK_ModuleClkDivider(CLK_SSP2, divider);
		break;
	}
	return ssp_data_p->freq;
}
Exemplo n.º 2
0
/*
 * Setup the systick timer to generate the tick interrupts at the required
 * frequency.
 */
void prvSetupTimerInterrupt( void )
{
	/* Configure SysTick to interrupt at the requested rate. */
	*(portNVIC_SYSTICK_LOAD) = ( board_cpu_freq() / configTICK_RATE_HZ ) - 1UL;
	*(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE;
}