📄 bspcspi.c
字号:
//
// Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004-2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
// File: bspcspi.c
//
// Provides BSP-specific configuration routines for the CSPI peripheral.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include "bsp.h"
//-----------------------------------------------------------------------------
// External Functions
//-----------------------------------------------------------------------------
// External Variables
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
// Types
//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
// Local Variables
//-----------------------------------------------------------------------------
//
// Function: CalculateDivRate
//
// This is a private function to calculate the data
// rate divider from input frequency.
//
// Parameters:
// dwFrequency
// [in] Frequency requested.
//
// Returns:
// Data rate divisor for requested frequency.
//
//-----------------------------------------------------------------------------
UINT32 BSPCSPICalculateDivRate(UINT32 dwFrequency)
{
UINT32 n;
UINT32 dwDivisor;
UINT32 dwCspiClk;
DDKClockGetFreq(DDK_CLOCK_SIGNAL_PERDIV2, &dwCspiClk);
for (n = CSPI_CONTROLREG_DATARATE_DIV4;
n < CSPI_CONTROLREG_DATARATE_DIV512; n++) {
if (n % 2)
dwDivisor = 3 * (2 << (((n-1)/2 - 1))); // odd
else
dwDivisor = 2 * (2 << ((n/2) - 1)); // even
if ((dwCspiClk / dwDivisor) <= dwFrequency) break;
}
return dwDivisor;
}
//-----------------------------------------------------------------------------
//
// Function: SetIOMux
//
// This is a private function which request IOMUX for
// the corresponding CSPI Bus.
//
// Parameters:
// dwIndex
// [in] CSPI port to be configured.
//
// Returns:
// TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPCSPISetIOMux(UINT32 dwIndex)
{
DDK_GPIO_CFG cfg;
if (dwIndex == 1)
DDK_GPIO_SET_CONFIG(cfg, CSPI1);
else if(dwIndex == 2)
DDK_GPIO_SET_CONFIG(cfg, CSPI2);
else if(dwIndex == 3)
DDK_GPIO_SET_CONFIG(cfg, CSPI3);
return DDKGpioEnable(&cfg);
}
//-----------------------------------------------------------------------------
//
// Function: ReleaseIOMux
//
// This is a private function which releases the
// IOMUX pins selected for the CSPI bus.
//
// Parameters:
// dwIndex
// [in] CSPI port to be released.
//
// Returns:
// TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPCSPIReleaseIOMux(UINT32 dwIndex)
{
DDK_GPIO_CFG cfg;
if (dwIndex == 1)
DDK_GPIO_SET_CONFIG(cfg, CSPI1);
else if(dwIndex == 2)
DDK_GPIO_SET_CONFIG(cfg, CSPI2);
else if(dwIndex == 3)
DDK_GPIO_SET_CONFIG(cfg, CSPI3);
return DDKGpioDisable(&cfg);
}
//-----------------------------------------------------------------------------
//
// Function: EnableClock
//
// Provides the platform-specific CSPI clock gating control to enable/disable
// module clocks.
//
// Parameters:
// dwIndex
// [in] CSPI port to be configured.
// bEnable
// [in] Set to TRUE to enable CSPI clocks, set to FALSE to disable
// CSPI clocks.
//
// Returns:
// TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPCSPIEnableClock(UINT32 dwIndex, BOOL bEnable)
{
DDK_CLOCK_GATE_INDEX index;
DDK_CLOCK_GATE_MODE mode = bEnable ?
DDK_CLOCK_GATE_MODE_ENABLE : DDK_CLOCK_GATE_MODE_DISABLE;
if (dwIndex == 1)
index = DDK_CLOCK_GATE_INDEX_CSPI1;
else if(dwIndex == 2)
index = DDK_CLOCK_GATE_INDEX_CSPI2;
else if(dwIndex == 3)
index = DDK_CLOCK_GATE_INDEX_CSPI3;
return DDKClockSetGatingMode(index, mode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -