text: /*
   * Copyright 2017 NXP
   * All rights reserved.
   *
   * SPDX-License-Identifier: BSD-3-Clause
   */
  
  /*  Standard C Included Files */
  #include <string.h>
  /*  SDK Included Files */
  #include "pin_mux.h"
  #include "board.h"
  #include "fsl_debug_console.h"
  #include "fsl_i2c.h"
  #include "Driver_I2C.h"
  #include "fsl_i2c_cmsis.h"
  #include "fsl_i2c_dma.h"
  
  #include "fsl_power.h"
  /*******************************************************************************
   * Definitions
   ******************************************************************************/
  #define EXAMPLE_I2C_SLAVE (Driver_I2C4)
  
  #define I2C_DATA_LENGTH       32U
  #define I2C_MASTER_SLAVE_ADDR 0x7E
  
  /*******************************************************************************
   * Prototypes
   ******************************************************************************/
  
  /*******************************************************************************
   * Variables
   ******************************************************************************/
  
  uint8_t g_slave_buff[I2C_DATA_LENGTH];
  volatile bool g_SlaveCompletionFlag = false;
  
  /*******************************************************************************
   * Code
   ******************************************************************************/
  
  uint32_t I2C4_GetFreq(void)
  {
      return CLOCK_GetFlexCommClkFreq(4U);
  }
  
  void I2C_SlaveSignalEvent_t(uint32_t event)
  {
      /*  Transfer done */
      if (event == ARM_I2C_EVENT_TRANSFER_DONE)
      {
          g_SlaveCompletionFlag = true;
      }
  }
  
  /*!
   * @brief Main function
   */
  int main(void)
  {
      /* set BOD VBAT level to 1.65V */
      POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
      /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
      CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
  
      /* attach 12 MHz clock to FLEXCOMM8 (I2C slave) */
      CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4);
  
      /* reset FLEXCOMM for I2C */
      RESET_PeripheralReset(kFC4_RST_SHIFT_RSTn);
  
      BOARD_InitPins();
      BOARD_BootClockPLL150M();
      BOARD_InitDebugConsole();
  
      PRINTF("\r\nCMSIS I2C board2board DMA example -- Slave transfer.\r\n\r\n");
  
      /*Init I2C*/
      EXAMPLE_I2C_SLAVE.Initialize(I2C_SlaveSignalEvent_t);
  
      EXAMPLE_I2C_SLAVE.PowerControl(ARM_POWER_FULL);
  
      /*config slave addr*/
      EXAMPLE_I2C_SLAVE.Control(ARM_I2C_OWN_ADDRESS, I2C_MASTER_SLAVE_ADDR);
  
      for (uint32_t i = 0U; i < I2C_DATA_LENGTH; i++)
      {
          g_slave_buff[i] = 0;
      }
  
      /*start transfer*/
      EXAMPLE_I2C_SLAVE.SlaveReceive(g_slave_buff, I2C_DATA_LENGTH);
  
      /*  Wait for transfer completed. */
      while (!g_SlaveCompletionFlag)
      {
      }
  
      /*  Reset slave completion flag to false. */
      g_SlaveCompletionFlag = false;
  
      EXAMPLE_I2C_SLAVE.SlaveTransmit(g_slave_buff, I2C_DATA_LENGTH);
  
      /* Wait for master receive completed.*/
  
      PRINTF("Slave received data :");
      for (uint32_t i = 0U; i < I2C_DATA_LENGTH; i++)
      {
          if (i % 8 == 0)
          {
              PRINTF("\r\n");
          }
          PRINTF("0x%2x  ", g_slave_buff[i]);
      }
      PRINTF("\r\n\r\n");
  
      while (!g_SlaveCompletionFlag)
      {
      }
      g_SlaveCompletionFlag = false;
  
      PRINTF("\r\nEnd of I2C example .\r\n");
      while (1)
      {
      }
  }
  