📄 ms.c
字号:
//===============================================================================
// TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
//
// Property of Texas Instruments
// For Unrestricted Internal Use Only
// Unauthorized reproduction and/or distribution is strictly prohibited.
// This product is protected under copyright law and trade secret law
// as an unpublished work.
// Created 2000, (C) Copyright 2000 Texas Instruments. All rights reserved.
//
// Filename : ms.c
//
// Description : Common functions for MS interface validation
// Used by hel_ms_0 and hel_ms_dma
//
// Project : Helen
//
// Author : Hiro UCHIKAWA (hirojii@ti.com)
//===============================================================================
#include "test.h"
#include "global_types.h"
#include "result.h"
#include "intvecs.h"
#include "ms.h"
#include "gdma.h"
#include "gdmatest.h"
#include "reset.h"
#include "errorcodes.h"
UWORD32 TxDataTable[6] = {0x12345678, 0x23456789,
0x3456789a, 0x456789ab,
0x56789abc, 0x6789abcd};
UWORD32 RxDataTable[6];
UWORD32 *RxDataTableAdd;
UWORD32 *TxDataTableAdd;
UWORD32 *DmaTxAdd;
UWORD32 *DmaRxAdd;
//---------------------------------------------------------------------------
// MS_MrstBitValueAtReset
//---------------------------------------------------------------------------
// Performs a local module reset, non GCM but MS internal
// The bit is automatically cleared by h/w after reset being effective
//---------------------------------------------------------------------------
void MS_MrstBitValueAtReset(void)
{
// Write MSCNTL Register for Reset
REGU16(MS_CNTL_REG_SUPERVISOR_ADDR) |= 0x0100;
}
//---------------------------------------------------------------------------
// MS_GcmReset
//---------------------------------------------------------------------------
// Performs a local module reset, it is GCM not MS internal
//---------------------------------------------------------------------------
void MS_GcmReset(void)
{
// Write MSGCMRESET Register for Reset
REGU32(MS_GCM_RESET_REG_SUPERVISOR_ADDR) = 0x00000000;
// Write MSGCMRESET Register for Release
REGU32(MS_GCM_RESET_REG_SUPERVISOR_ADDR) = 0x00000001;
}
//---------------------------------------------------------------------------
// MS_GcmClkEnable
//---------------------------------------------------------------------------
// Enables MS CLK at GCM
//---------------------------------------------------------------------------
void MS_GcmClkEnable(void)
{
// Write MSGCMCLK Register to Enable MSCLK
REGU32(MS_GCM_CLK_REG_SUPERVISOR_ADDR) = 0x00000001;
}
//---------------------------------------------------------------------------
// MS_GcmClkDisable
//---------------------------------------------------------------------------
// Disables MS CLK at GCM
//---------------------------------------------------------------------------
void MS_GcmClkDisable(void)
{
// Write MSGCMCLK Register to Disable MSCLK
REGU32(MS_GCM_CLK_REG_SUPERVISOR_ADDR) = 0x00000000;
}
//---------------------------------------------------------------------------
// MS_GcmRegValueAtReset
//---------------------------------------------------------------------------
// Verifies GCM RHEA register values at reset
//---------------------------------------------------------------------------
BOOL MS_GcmRegValueAtReset(void) //BOOL(FALSE=0,TRUE=1)
{
BOOL ok =True;
ok &=((REGU32(MS_GCM_CLK_REG_SUPERVISOR_ADDR) & MS_GCM_CLK_REG_MSK) == MS_GCM_CLK_REG_VALUE_AT_RESET);
ok &=((REGU32(MS_GCM_RESET_REG_SUPERVISOR_ADDR) & MS_GCM_RESET_REG_MSK) == MS_GCM_RESET_REG_VALUE_AT_RESET);
return(ok);
}
//---------------------------------------------------------------------------
// MS_GcmRegClkEnValueAtReset
//---------------------------------------------------------------------------
// Verifies ONLY GCM CLKEN RHEA register value at reset
//---------------------------------------------------------------------------
BOOL MS_GcmRegClkEnValueAtReset(void) //BOOL(FALSE=0,TRUE=1)
{
BOOL ok =True;
ok &=((REGU32(MS_GCM_CLK_REG_SUPERVISOR_ADDR) & MS_GCM_CLK_REG_MSK) == MS_GCM_CLK_REG_VALUE_AT_RESET);
return(ok);
}
//---------------------------------------------------------------------------
// MS_TestRegisterValueAtReset
//---------------------------------------------------------------------------
// Verifies all predictable register values at reset
//---------------------------------------------------------------------------
BOOL MS_TestRegisterValueAtReset(void) //BOOL(FALSE=0,TRUE=1)
{
BOOL ok =True;
ok &=((REGU16(MS_CMD_REG_SUPERVISOR_ADDR) & MS_CMD_REG_MSK) == MS_CMD_REG_VALUE_AT_RESET);
ok &=((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & MS_STAT_REG_MSK) == MS_STAT_REG_VALUE_AT_RESET);
ok &=((REGU16(MS_CNTL_REG_SUPERVISOR_ADDR) & MS_CNTL_REG_MSK) == MS_CNTL_REG_VALUE_AT_RESET);
ok &=((REGU16(MS_I_DATA_REG_SUPERVISOR_ADDR) & MS_I_DATA_REG_MSK) == MS_I_DATA_REG_VALUE_AT_RESET);
ok &=((REGU16(MS_I_CTL_REG_SUPERVISOR_ADDR) & MS_I_CTL_REG_MSK) == MS_I_CTL_REG_VALUE_AT_RESET);
ok &=((REGU16(MS_PP_CTL_REG_SUPERVISOR_ADDR) & MS_PP_CTL_REG_MSK) == MS_PP_CTL_REG_VALUE_AT_RESET);
ok &=((REGU16(MS_FIFO_CTL_REG_SUPERVISOR_ADDR) & MS_FIFO_CTL_REG_MSK) == MS_FIFO_CTL_REG_VALUE_AT_RESET);
ok &=((REGU16(MS_FIFO_CNT_REG_SUPERVISOR_ADDR) & MS_FIFO_CNT_REG_MSK) == MS_FIFO_CNT_REG_VALUE_AT_RESET);
return(ok);
}
//---------------------------------------------------------------------------
// MS_GcmRegisterTest
//---------------------------------------------------------------------------
// Performs a write and a read it back, then compare both values for a reg
// This is for GCM RHEA registers
//---------------------------------------------------------------------------
BOOL MS_GcmRegisterTest(void)
{
BOOL ok =True;
// Write a one at LSB and read back check, CLKEN reg
REGU32(MS_GCM_CLK_REG_SUPERVISOR_ADDR) = 0x00000001;
ok &=(REGU32(MS_GCM_CLK_REG_SUPERVISOR_ADDR) == 0x00000001);
// Write a zero at LSB and read back check, CLKEN reg
REGU32(MS_GCM_CLK_REG_SUPERVISOR_ADDR) = 0x00000000;
ok &=(REGU32(MS_GCM_CLK_REG_SUPERVISOR_ADDR) == 0x00000000);
// Write a zero at LSB and read back check, RESET reg
REGU32(MS_GCM_RESET_REG_SUPERVISOR_ADDR) = 0x00000000;
ok &=(REGU32(MS_GCM_RESET_REG_SUPERVISOR_ADDR) == 0x00000000);
// Write a one at LSB and read back check, RESET reg
REGU32(MS_GCM_RESET_REG_SUPERVISOR_ADDR) = 0x00000001;
ok &=(REGU32(MS_GCM_RESET_REG_SUPERVISOR_ADDR) == 0x00000001);
return(ok);
}
//---------------------------------------------------------------------------
// MS_RegisterTest
//---------------------------------------------------------------------------
// Performs a write and a read it back, then compare both values for a reg
//---------------------------------------------------------------------------
BOOL MS_RegisterTest(UWORD32 RegAdd, UWORD16 TestValue)
{
BOOL ok =True;
// Write the TestValue into the RegAdd register
REGU16(RegAdd) = TestValue;
// Read the value back from the RegAdd register,
// and then compare with the TestValue
ok &=((REGU16(RegAdd) & TestValue) == TestValue);
return(ok);
}
//---------------------------------------------------------------------------
// MS_RxTxTest8
//---------------------------------------------------------------------------
// Simply transmits a data byte(plus 2 CRC bytes) to STUB and receives
// the same data byte(plus 2 CRC bytes) from STUB. At the end, it does
// comparison and if the data byte and CRC check are OK, then says OK.
// Only this test applies POWER SAVE mode for SCLK.
//---------------------------------------------------------------------------
BOOL MS_RxTxTest8(void)
{
BOOL ok = True;
UWORD8 RxData;
UWORD8 TxData = 0xa1;
UWORD32 i;
// Module Reset
MS_MrstBitValueAtReset();
// Enable I/F and select MSByte mode and power save mode
REGU16(MS_CNTL_REG_SUPERVISOR_ADDR) |= 0x8060;
// Tx Protocol Part
// Wait the BS's condition good
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
// Write the TxData to MSTXDATA Register
REGU8(MS_TX_DATA_REG_SUPERVISOR_ADDR) = TxData;
// Set the TPC command to write mode and
// and Set the Number of TxByte (1byte)
REGU16(MS_CMD_REG_SUPERVISOR_ADDR) = 0xb001; // Start Tx
// Rx Protocol Part
// Wait the BS's condition good
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
// Set the TPC commande to read mode
// and Set the Number of RxByte (1byte)
REGU16(MS_CMD_REG_SUPERVISOR_ADDR) = 0x4001; // Start Rx
// Wait until a receive protocol completion
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
// Read the RxData
RxData = REGU8(MS_RX_DATA_REG_SUPERVISOR_ADDR);
// Check if TxData == RxData, and if no CRC error
// Returns True if both are OK, else False
ok &= (TxData == RxData);
ok &= ((REGU16(MS_I_DATA_REG_SUPERVISOR_ADDR) & 0x0002) == 0x0000);
return(ok);
}
//---------------------------------------------------------------------------
// MS_RxTxTest16
//---------------------------------------------------------------------------
// Simply transmits 2 data bytes(plus 2 CRC bytes) to STUB and receives
// the same data bytes(plus 2 CRC bytes) from STUB. At the end, it does
// comparison and if the data bytes and CRC check are OK, then says OK.
//---------------------------------------------------------------------------
BOOL MS_RxTxTest16(void)
{
BOOL ok = True;
UWORD16 RxData;
UWORD16 TxData = 0xa1b2;
UWORD32 i;
// Module Reset
MS_MrstBitValueAtReset();
// Enable I/F and select MSByte mode
REGU16(MS_CNTL_REG_SUPERVISOR_ADDR) |= 0x8020;
// Tx Protocol Part
// Wait the BS's condition good
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
// Write the TxData to MSTXDATA Register
REGU16(MS_TX_DATA_REG_SUPERVISOR_ADDR) = TxData;
// Set the TPC command to write mode and
// and Set the Number of TxByte (2bytes)
REGU16(MS_CMD_REG_SUPERVISOR_ADDR) = 0xb002; // Start Tx
// Rx Protocol Part
// Wait the BS's condition good
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
// Set the TPC commande to read mode
// and Set the Number of RxByte (2bytes)
REGU16(MS_CMD_REG_SUPERVISOR_ADDR) = 0x4002; // Start Rx
// Wait until a receive protocol completion
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
// Read the RxData
RxData = REGU16(MS_RX_DATA_REG_SUPERVISOR_ADDR);
// Check if TxData == RxData, and if no CRC error
// Returns True if both are OK, else False
ok &= (TxData == RxData);
ok &= ((REGU16(MS_I_DATA_REG_SUPERVISOR_ADDR) & 0x0002) == 0x0000);
return(ok);
}
//---------------------------------------------------------------------------
// MS_RxTxTest32
//---------------------------------------------------------------------------
// Simply transmits 4 data bytes(plus 2 CRC bytes) to STUB and receives
// the same data bytes(plus 2 CRC bytes) from STUB. At the end, it does
// comparison and if the data bytes and CRC check are OK, then says OK.
//---------------------------------------------------------------------------
BOOL MS_RxTxTest32(void)
{
BOOL ok = True;
UWORD32 RxData;
UWORD32 TxData = 0xa1b2c3d4;
UWORD32 i;
// Module Reset
MS_MrstBitValueAtReset();
// Enable I/F and select MSByte mode
REGU16(MS_CNTL_REG_SUPERVISOR_ADDR) |= 0x8020;
// Tx Protocol Part
// Wait the BS's condition good
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
// Write the TxData to MSTXDATA Register
REGU32(MS_TX_DATA_REG_SUPERVISOR_ADDR) = TxData;
// Set the TPC command to write mode and
// and Set the Number of TxByte (4bytes)
REGU16(MS_CMD_REG_SUPERVISOR_ADDR) = 0xb004; // Start Tx
// Rx Protocol Part
// Wait the BS's condition good
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
// Set the TPC commande to read mode
// and Set the Number of RxByte (2bytes)
REGU16(MS_CMD_REG_SUPERVISOR_ADDR) = 0x4004; // Start Rx
// Wait until a receive protocol completion
i = 0;
while ((REGU16(MS_STAT_REG_SUPERVISOR_ADDR) & 0x0300) != 0x0000)
{
(volatile unsigned short *)i++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -