/* USER CODE BEGIN Header */
/* you can remove the copyright */

/*
 *  Copyright 2020-2023 Yuntu Microelectronics Co., Ltd.
 *  All rights reserved.
 * 
 *  SPDX-License-Identifier: BSD-3-Clause
 * 
 * @file main.c
 * @brief 
 * 
 */

/* USER CODE END Header */
#include "sdk_project_config.h"
/* Includes ------------------------------------------------------------------*/

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdint.h>
#include <stddef.h>  // 用于 size_t
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define SPI_MASTER_INST  (4)
#define SPI_SLAVE_INST   (2)
#define SPI_TRANS_LENGTH (1024)
#define TIMEOUT          (100)
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
uint8_t masterTxBuff[SPI_TRANS_LENGTH] = {0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C};
uint8_t masterRxBuff[SPI_TRANS_LENGTH];
// uint8_t slaveTxBuff[SPI_TRANS_LENGTH] = {0x02, 0x30, 0x02, 0x30, 0x02, 0x30, 0x02, 0x30};
// uint8_t slaveRxBuff[SPI_TRANS_LENGTH];

uint8_t symbol_Table[SPI_TRANS_LENGTH * 8] = {0};
/* USER CODE END PV */

/* Private function declare --------------------------------------------------*/
/* USER CODE BEGIN PFDC */
/* USER CODE END PFDC */
static void Board_Init(void);

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void SPI4_DMA_EndNotification(void)
{
    
}

void SPI4_EndNotification(void)
{
    
}


/* USER CODE END 0 */


/**
 * @brief  The application entry point.
 * @retval int
 */
int main(void)
{
    /* USER CODE BEGIN 1 */
    uint32_t cnt = 5;
    /* USER CODE END 1 */ 
    Board_Init();
    /* USER CODE BEGIN 2 */
    DMA_DRV_Init(&dmaState,&dmaController_InitConfig,dmaChnState,dmaChnConfigArray,NUM_OF_CONFIGURED_DMA_CHANNEL);
    SPI_DRV_MasterInit(4,&lpspi_MasterConfig0_State,&lpspi_MasterConfig0);

    SPI_DRV_MasterSetDelay(4, 1, 1, 1);

    for (int i = 0; i < SPI_TRANS_LENGTH; i++)
    {
        masterTxBuff[i] = 0xAA+i;
    }   

    // while (cnt--)
    {
        /********************************** 异步收发 **************************************/
        SPI_DRV_MasterTransfer(SPI_MASTER_INST, masterTxBuff, masterRxBuff, SPI_TRANS_LENGTH);
        /**********************************************************************************/
    }
    /* USER CODE END 2 */

    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1)
    {
        /* USER CODE END WHILE */
        /* USER CODE BEGIN 3 */
    }
    /* USER CODE END 3 */
}

static void Board_Init(void)
{
    CLOCK_SYS_Init(g_clockManConfigsArr,CLOCK_MANAGER_CONFIG_CNT,g_clockManCallbacksArr,CLOCK_MANAGER_CALLBACK_CNT);
    if(STATUS_SUCCESS != CLOCK_SYS_UpdateConfiguration(CLOCK_MANAGER_ACTIVE_INDEX,CLOCK_MANAGER_POLICY_AGREEMENT))
    {
        /* USER CODE BEGIN ERROR_HANDLER 1 */
        SystemSoftwareReset();
        /* USER CODE END ERROR_HANDLER 1 */
    }
    PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0,g_pin_mux_InitConfigArr0);
    DMA_DRV_Init(&dmaState,&dmaController_InitConfig,dmaChnState,dmaChnConfigArray,NUM_OF_CONFIGURED_DMA_CHANNEL);
    UTILITY_PRINT_Init();
    SPI_DRV_MasterInit(4,&lpspi_MasterConfig0_State,&lpspi_MasterConfig0);
    SPI_DRV_SlaveInit(2,&spi_SlaveConfig0_State,&spi_SlaveConfig0);
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */
