/* ISR called when the SPI peripheral transitions from the transferring state to the IDLE state.  */
void spi_tei_isr(void)
/* ISR called when the SPI peripheral transitions from the transferring state to the IDLE state.  */
void spi_tei_isr(void)
{
    FSP_CONTEXT_SAVE;
    IRQn_Type irq = R_FSP_CurrentIrqGet();
    R_BSP_IrqStatusClear(irq);
    spi_instance_ctrl_t * p_ctrl = (spi_instance_ctrl_t *) R_FSP_IsrContextGet(irq);
    if ((0 == p_ctrl->p_regs->SPSR_b.IDLNF) || (SPI_MODE_SLAVE == p_ctrl->p_cfg->operating_mode))
    {
        R_BSP_IrqDisable(irq);
        p_ctrl->p_regs->SPCR_b.SPE = 0;
        r_spi_call_callback(p_ctrl, SPI_EVENT_TRANSFER_COMPLETE);
    }
    FSP_CONTEXT_RESTORE;
}