📄 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
#define CSPI_MAX_DIV_RATE 9 // 2^9= 512
//-----------------------------------------------------------------------------
// 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 dwDivisor;
UINT32 dwCspiClk;
DDKClockGetFreq(DDK_CLOCK_SIGNAL_IPG, &dwCspiClk);
for (dwDivisor = 2; (dwDivisor < CSPI_MAX_DIV_RATE) && ((dwCspiClk >> dwDivisor) > dwFrequency); dwDivisor++);
return (dwDivisor - 2);
}
//-----------------------------------------------------------------------------
//
// 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)
{
BOOL rc = FALSE;
if(dwIndex == 1)
{
// Configure IOMUX to request CSPI1 pins
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SPI_RDY, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SCLK, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SS2, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SS1, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SS0, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_MISO, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_MOSI, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
rc = TRUE;
}
else if(dwIndex == 2)
{
// Configure IOMUX to request CSPI2 pins
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SPI_RDY, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SCLK, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SS2, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SS1, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SS0, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_MISO, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_MOSI, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
rc = TRUE;
}
else if(dwIndex == 3)
{
// Configure IOMUX to request CSPI3 pins
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI3_MISO, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI3_MOSI, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI3_SPI_RDY, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI3_SCLK, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
// CSPI3_SS0
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SS0, DDK_IOMUX_OUT_ALT1, DDK_IOMUX_OUT_ALT1);
// CSPI3_SS1
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SS1, DDK_IOMUX_OUT_ALT1, DDK_IOMUX_OUT_ALT1);
// CSPI3_SS2
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SS0, DDK_IOMUX_OUT_ALT2, DDK_IOMUX_OUT_ALT2);
//DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SS2, DDK_IOMUX_OUT_ALT2, DDK_IOMUX_OUT_ALT2);
rc = TRUE;
}
return rc;
}
//-----------------------------------------------------------------------------
//
// 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)
{
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: EnableClock
//
// Provides the platform-specific SPI clock gating control to enable/disable
// module clocks.
//
// Parameters:
// Index
// [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 Index, BOOL bEnable)
{
BOOL rc = FALSE;
DDK_CLOCK_GATE_MODE mode = bEnable ?
DDK_CLOCK_GATE_MODE_ENABLED_ALL : DDK_CLOCK_GATE_MODE_DISABLED;
switch(Index)
{
case 1:
rc = DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_CSPI1, mode);
break;
case 2:
rc = DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_CSPI2, mode);
break;
case 3:
rc = DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_CSPI3, mode);
break;
default:
ERRORMSG(TRUE, (TEXT("Invalid Index\r\n")));
}
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: BSPCspiGetChannelPriority
//
// This function returns the sdma priority for cspi
//
// Parameters:
// None
//
// Returns:
// The channel Priority.
//
//-----------------------------------------------------------------------------
UINT8 BSPCspiGetChannelPriority(void)
{
return BSP_SDMA_CHNPRI_CSPI;
}
//-----------------------------------------------------------------------------
//
// Function: BSPCspiIsDMAEnabled
//
// This function returns whether sdma is
// enabled or diabled for a given cspi index
//
// Parameters:
// CSPI Index
//
// Returns:
// Whether DMA is Enabled for a given CSPI index.
//
//-----------------------------------------------------------------------------
BOOL BSPCspiIsDMAEnabled(UINT8 Index)
{
switch (Index)
{
case 1:
return BSP_SDMA_SUPPORT_CSPI1;
case 2:
return BSP_SDMA_SUPPORT_CSPI2;
case 3:
return BSP_SDMA_SUPPORT_CSPI3;
default:
ERRORMSG(TRUE, (TEXT("Invalid Index\r\n")));
}
return FALSE;
}
//-----------------------------------------------------------------------------
//
// Function: BSPCspiAcquireGprBit
//
// This function is a wrapper for CSPI to acquire a muxed SDMA request line.
//
// Parameters:
// Index
// [in] Index of the CSPI
// Returns:
// TRUE if success.
//
//-----------------------------------------------------------------------------
BOOL BSPCspiAcquireGprBit(UINT8 Index)
{
switch(Index)
{
case 1:
return DDKIomuxSetGprBit(DDK_IOMUX_GPR_CSPI1_UART3, 0);
case 2:
return TRUE;
case 3:
return DDKIomuxSetGprBit(DDK_IOMUX_GPR_CSPI3_UART5, 0);
default:
ERRORMSG(TRUE, (TEXT("Invalid Index\r\n")));
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -