247 lines
6.8 KiB
C++
247 lines
6.8 KiB
C++
/**************************************************************/
|
|
/* swim2Tests.cpp Date: 2018/08/9 */
|
|
/* */
|
|
/* Copyright (c) 2018-2019 GIS. All rights reserved. */
|
|
/* */
|
|
/**************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "swim2Tests.h"
|
|
|
|
// --------------------------------------------------
|
|
// SWIM entry tests
|
|
// --------------------------------------------------
|
|
int swim2Tests::swim_entry_test (CSwim2Auto* pSwim, int node, int testGroup)
|
|
{
|
|
int error = 0;
|
|
uint32_t status;
|
|
|
|
VPrint("Starting SWIM entry tests\n");
|
|
|
|
// Set high speed mode
|
|
pSwim->pControl->SetHighSpeed(1);
|
|
|
|
// Put TB receiver in entry detection mode
|
|
setEntryMode(true);
|
|
|
|
// Send entry sequence, and reset to low speed
|
|
pSwim->pControl->SetHighSpeed(0);
|
|
pSwim->pControl->SetSendEntrySeq(1);
|
|
|
|
// Wait until not busy
|
|
while(pSwim->pStatus->GetTxbusy())
|
|
{
|
|
usleepSim(1);
|
|
}
|
|
|
|
uint32_t swimRxh, swimRxl;
|
|
|
|
// Fetch receiver values
|
|
getRxData(swimRxh, swimRxl);
|
|
|
|
// Check expected receiver signature for entry sequence
|
|
if (swimRxh != SWIM_ENTRY_SIGNATURE_HI and swimRxl != SWIM_ENTRY_SIGNATURE_LO)
|
|
{
|
|
VPrint("**ERROR %03d : SWIM entry failure (0x%08x%08x).\n", testGroup + 0, swimRxh, swimRxl);
|
|
error |= 1;
|
|
}
|
|
|
|
// Put TB receiver out of entry detection mode
|
|
setEntryMode(false);
|
|
|
|
// Send SWRST (low speed)
|
|
pSwim->pControl->SetSendSrst(1);
|
|
|
|
// Wait until not busy
|
|
while(pSwim->pStatus->GetTxbusy())
|
|
{
|
|
usleepSim(1);
|
|
}
|
|
|
|
// Fetch the receiver values and check for SWRST
|
|
struct swimRx_t swimVal;
|
|
getRxData(swimRxh, swimRxl);
|
|
|
|
swimVal = decodeswimRx(swimRxl, swimRxh);
|
|
|
|
if (swimVal.srst != SWIM_SWRST_CMD)
|
|
{
|
|
VPrint("**ERROR %03d : SWIM entry SWRST failure.\n", testGroup + 1);
|
|
error |= 1;
|
|
}
|
|
|
|
return error;
|
|
}
|
|
|
|
// --------------------------------------------------
|
|
// SWIM TX/RX tests
|
|
// --------------------------------------------------
|
|
int swim2Tests::swim_txrx_test (CSwim2Auto* pSwim, int node, int testGroup)
|
|
{
|
|
int error = 0;
|
|
uint32_t status;;
|
|
|
|
VPrint("Starting SWIM TX/RX tests\n");
|
|
|
|
// Send WOTF (1 byte) : addr 0x123456, byte 0x55
|
|
uint32_t addr = 0x123456;
|
|
uint32_t data = 0x55;
|
|
pSwim->pTxByte->SetTxByte((addr << 8) | data);
|
|
|
|
// Read back CSR_TX_BYTE_ADDR
|
|
if ((status = pSwim->pTxByte->GetTxByte()) != ((addr << 8) | data))
|
|
{
|
|
VPrint("**ERROR %03d : SWIM TX_BYTE register read failure on WOTF (got 0x%08x exp 0x%08x)\n", testGroup + 2, status, ((addr << 8) | data));
|
|
error |= 1;
|
|
}
|
|
|
|
// Wait
|
|
while(pSwim->pStatus->GetTxbusy())
|
|
{
|
|
usleepSim(100);
|
|
}
|
|
|
|
struct swimRx_t swimVal;
|
|
uint32_t swimRxl;
|
|
uint32_t swimRxh;
|
|
getRxData(swimRxh, swimRxl);
|
|
|
|
if (swimCheckValue(swimRxl, swimRxh, SWIM_WOTF_CMD, 1, addr, data, swimVal))
|
|
{
|
|
VPrint("**ERROR %03d : SWIM WOTF received data failure (0x%08x%08x).\n", testGroup + 3, swimRxh, swimRxl);
|
|
error |= 1;
|
|
}
|
|
|
|
// Send ROTF (1 byte) : addr 0x654321
|
|
addr = 0x654321;
|
|
data = 0; // don't care
|
|
pSwim->pRxByte->SetRxByte((addr << 8) | data);
|
|
|
|
// Read back CSR_RX_BYTE_ADDR
|
|
if (((status = pSwim->pRxByte->GetRxByte() ) >> 8) != addr)
|
|
{
|
|
VPrint("**ERROR %03d : SWIM RX_BYTE register read failure on ROTF (got 0x%08x exp 0x%08x)\n", testGroup + 4, status, ((addr << 8)));
|
|
error |= 1;
|
|
}
|
|
|
|
// Wait
|
|
while(pSwim->pStatus->GetRxbusy() || pSwim->pStatus->GetTxbusy())
|
|
{
|
|
usleepSim(100);
|
|
}
|
|
|
|
uint32_t expData = 0xaa;
|
|
|
|
getRxData(swimRxh, swimRxl);
|
|
|
|
// Check the received data
|
|
if (swimCheckValue(swimRxl, swimRxh, SWIM_ROTF_CMD, 1, addr, expData, swimVal))
|
|
{
|
|
VPrint("**ERROR %03d : SWIM ROTF received data failure (0x%08x%08x).\n", testGroup + 5, swimRxh, swimRxl);
|
|
error |= 1;
|
|
}
|
|
|
|
// Read RX byte
|
|
if ((status = pSwim->pRxByte->GetByte()) != expData)
|
|
{
|
|
VPrint("**ERROR %03d : SWIM RX_BYTE read failure (got 0x%02x exp 0x%02x).\n", testGroup + 6, status, expData);
|
|
error |= 1;
|
|
}
|
|
|
|
// Clear RX
|
|
pSwim->pControl->SetClrRx(1);
|
|
|
|
// Send a block write command
|
|
addr = 0x250864;
|
|
pSwim->pTxBlock->SetWaddr(addr);
|
|
|
|
// Check TX busy is set
|
|
if (!(status = pSwim->pStatus->GetTxbusy()))
|
|
{
|
|
VPrint("**ERROR %03d : SWIM TXBUSY status failure on block write.\n", testGroup + 7);
|
|
error |= 1;
|
|
}
|
|
|
|
// Wait
|
|
while(pSwim->pStatus->GetTxbusy())
|
|
{
|
|
usleepSim(100);
|
|
}
|
|
|
|
// Check count is 128
|
|
if ((status = pSwim->pBlkRemaining->GetBlkRemaining()) != 128)
|
|
{
|
|
VPrint("**ERROR %03d : BLK_REMAINING count 128 check failure (got 0x%02x exp 0x%02x).\n", testGroup + 8, status, 128);
|
|
error |= 1;
|
|
}
|
|
|
|
// Check TXBUSY is clear
|
|
if ((status = pSwim->pStatus->GetTxbusy()))
|
|
{
|
|
VPrint("**ERROR %03d : SWIM TXBUSY not clear failure.\n", testGroup + 9);
|
|
error |= 1;
|
|
}
|
|
|
|
// Send 1 byte
|
|
data = 0x5a;
|
|
pSwim->pPushByte->SetPushByte(data);
|
|
|
|
// Wait
|
|
while(pSwim->pStatus->GetTxbusy())
|
|
{
|
|
usleepSim(10);
|
|
}
|
|
|
|
getRxData(swimRxh, swimRxl);
|
|
|
|
// Check the received data
|
|
if (swimCheckValue(swimRxl, swimRxh, SWIM_WOTF_CMD, 128, addr, data, swimVal))
|
|
{
|
|
VPrint("**ERROR %03d : SWIM Block write command received data failure. (0x%08x%08x).\n", testGroup + 10, swimRxh, swimRxl);
|
|
error |= 1;
|
|
}
|
|
|
|
// Check block count is 127
|
|
if ((status = pSwim->pBlkRemaining->GetBlkRemaining()) != 127)
|
|
{
|
|
VPrint("**ERROR %03d : BLK_REMAINING count 127 check failure (got 0x%02x exp 0x%02x).\n", testGroup + 11, status, 127);
|
|
error |= 1;
|
|
}
|
|
|
|
bool foundError = false;
|
|
// Send the rest of the block data
|
|
for (int idx = 1; idx < 128; idx++)
|
|
{
|
|
// Send 1 byte
|
|
pSwim->pPushByte->SetPushByte(data + idx);
|
|
|
|
// Check block count is 127 - idx
|
|
if ((status = pSwim->pBlkRemaining->GetBlkRemaining()) != (127 - idx) && !foundError)
|
|
{
|
|
VPrint("**ERROR %03d : SWIM BLK_REMAINING count check failure (got %d exp %d).\n", testGroup + 12, status, (127 - idx));
|
|
foundError = true;
|
|
error |= 1;
|
|
}
|
|
|
|
// Wait
|
|
while(pSwim->pStatus->GetTxbusy())
|
|
{
|
|
usleepSim(10);
|
|
}
|
|
|
|
// Check receiver data
|
|
getRxData(swimRxh, swimRxl);
|
|
|
|
swimCheckValue(swimRxl, swimRxh, SWIM_WOTF_CMD, 128, addr, data + idx, swimVal);
|
|
|
|
if (swimVal.data != (data + idx) && !foundError)
|
|
{
|
|
VPrint("**ERROR %03d : SWIM received data on block write failure from idx %s.\n", testGroup + 13, idx);
|
|
foundError = true;
|
|
error |= 1;
|
|
}
|
|
}
|
|
|
|
return error;
|
|
}
|