[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_0_eng / packages / ti / board / diag / mcspi / src / mcspi_diag.c
diff --git a/psdk_cust/pdk_k2g_1_0_1_0_eng/packages/ti/board/diag/mcspi/src/mcspi_diag.c b/psdk_cust/pdk_k2g_1_0_1_0_eng/packages/ti/board/diag/mcspi/src/mcspi_diag.c
+++ /dev/null
@@ -1,254 +0,0 @@
-
-/*
- * Copyright (c) 2014, Texas Instruments Incorporated
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/* TI-RTOS Header files */
-#include <ti/drv/uart/UART_stdio.h>
-#include <ti/csl/soc/am572x/src/cslr_control_core_pad_io.h>
-#include <stdlib.h>
-
-#include <ti/drv/gpio/GPIO.h>
-#include <ti/drv/gpio/soc/GPIO_v1.h>
-
-#include <ti/drv/spi/SPI.h>
-#include <ti/drv/spi/soc/QSPI_v1.h>
-#include <ti/drv/spi/soc/SPI_v1.h>
-
-#include "board.h"
-#include "board_cfg.h"
-
-
-/**********************************************************************
- ************************** Macros ************************************
- **********************************************************************/
-
-/* Board specific definitions */
-#define MCSPI_INSTANCE (3U)
-
-/* GPIO pin value definitions */
-#define GPIO_PIN_VAL_LOW (0U)
-#define GPIO_PIN_VAL_HIGH (1U)
-
-#define CSL_MCSPI_PER_CNT (4U)
-#define CSL_QSPI_PER_CNT 1U
-
-/**********************************************************************
- ************************** Internal functions ************************
- **********************************************************************/
-/* Board init function */
-extern void Board_initSPI(void);
-
-void AppDelay(uint32_t delayVal);
-
-/* Function to control load signal to the industrial input module */
-void LoadData(void);
-
-/* Function to verify data */
-bool VerifyData(uint8_t *expData, uint8_t *rxData, uint32_t length);
-
-/**********************************************************************
- ************************** Global Variables **************************
- **********************************************************************/
-
-
-extern const SPI_Config SPI_config[];
-
-/* ON Board LED pins which are connected to GPIO pins. */
-typedef enum AM57X_IDK_GPIOName {
- AM57X_IDK_SPI_LD_PIN = 0U,
- AM57X_IDK_GPIO_COUNT
-}AM57X_IDK_GPIOName;
-
-/*
- * ======== test function ========
- */
-int spi_test()
-{
- SPI_Params spiParams; /* SPI params structure */
- SPI_Handle handle; /* SPI handle */
- SPI_Transaction transaction; /* SPI transaction */
- bool retVal = false; /* return value */
- int i;
- char p = 'r';
-
- /* Buffer containing the known data that needs to be written to flash */
- uint8_t txBuf[1U];
-
- /* Buffer containing the received data */
- uint8_t rxBuf[1U] = {0xFFU};
-
- /* Transfer length */
- uint32_t transferLength;
-
- for (i=0; i<CSL_MCSPI_PER_CNT; i++)
- {
- ((SPI_v1_HWAttrs *)SPI_config[i].hwAttrs)->enableIntr = false;
- }
-
- for (i=CSL_MCSPI_PER_CNT; i<CSL_MCSPI_PER_CNT+CSL_QSPI_PER_CNT; i++)
- {
- ((QSPI_HwAttrs *)SPI_config[i].hwAttrs)->intrEnable = false;
- }
-
- /* Init GPIO driver */
- GPIO_init();
-
- /* Init SPI driver */
- SPI_init();
-
- /* Default SPI configuration parameters */
- SPI_Params_init(&spiParams);
- spiParams.frameFormat = SPI_POL1_PHA0;
-
- /* Open QSPI driver */
- handle = SPI_open((MCSPI_INSTANCE - 1U), &spiParams);
-
- do {
-
- /* Load data */
- LoadData();
-
- /* Initiate transfer */
- txBuf[0] = 0xAAU;
- transferLength = 1U;
- transaction.count = transferLength;
- transaction.txBuf = &txBuf[0];
- transaction.rxBuf = &rxBuf[0];
- retVal = SPI_transfer(handle, &transaction);
- AppDelay(100000);
-
- if(false == retVal)
- {
- UART_printf("\nError occurred in spi transfer \n");
- UART_printf("Data received: %x\n", rxBuf[0]);
- UART_printf("Status code returned by LLD is: %d\n", (int) transaction.status);
- p = 'n';
- }
- else
- {
- UART_printf("Data transferred: %x\n", txBuf[0]);
- UART_printf("Data received: %x\n", rxBuf[0]);
- UART_printf("Press 'y' to verify pass, 'r' to read again,\n");
- UART_printf("or any other character to indicate failure: ");
- UART_scanFmt("%c", &p);
- UART_printf("User input: %c\n", p);
- }
- if (p == 'r') UART_printf("\nReading again\n");
- } while (p == 'r');
-
- if ( (p == 'y') || (p == 'Y') ) {
- UART_printf("\nTest PASSED!\n");
- return 0;
- }
- else {
- UART_printf("\nTest FAILED!\n");
- return -1;
- }
-
- SPI_close(handle);
-}
-
-int mcspi_test()
-{
- UART_printf("\n*********************************************\n");
- UART_printf ("* MCSPI Test *\n");
- UART_printf ("*********************************************\n");
-
- UART_printf("\nTesting MCSPI...\n");
-
- return spi_test();
-}
-
-
-/*
- * ======== main ========
- */
-int main(void)
-{
- Board_initCfg boardCfg;
-#ifdef PDK_RAW_BOOT
- boardCfg = BOARD_INIT_MODULE_CLOCK |
- BOARD_INIT_PINMUX_CONFIG |
- BOARD_INIT_UART_STDIO;
-#else
- boardCfg = BOARD_INIT_UART_STDIO;
-#endif
- Board_init(boardCfg);
-
- return mcspi_test();
-}
-
-/*
- * ======== Function to control load signal to load data ========
- */
-void LoadData(void)
-{
- GPIO_write(AM57X_IDK_SPI_LD_PIN, GPIO_PIN_VAL_LOW);
- AppDelay(10000);
- GPIO_write(AM57X_IDK_SPI_LD_PIN, GPIO_PIN_VAL_HIGH);
- AppDelay(10000);
-}
-
-/*
- * ======== CompareData ========
- */
-bool VerifyData(uint8_t *expData, uint8_t *rxData, uint32_t length)
-{
- uint32_t idx = 0;
- uint32_t match = 1;
- bool retVal = false;
-
- for(idx = 0; ((idx < length) && (match != 0)); idx++)
- {
- if(*expData != *rxData) match = 0;
- expData++;
- rxData++;
- }
-
- if(match == 1) retVal = true;
-
- return retVal;
-}
-
-/*
- * ======== AppDelay ========
- */
-void AppDelay(uint32_t delayVal)
-{
- uint32_t cnt = 0;
- while(cnt < delayVal)
- {
- asm("");
- cnt++;
- }
-}
-