/*******************************************************************************
 * DISCLAIMER
 * This software is supplied by Renesas Electronics Corporation and is only
 * intended for use with Renesas products. No other uses are authorized. This
 * software is owned by Renesas Electronics Corporation and is protected under
 * all applicable laws, including copyright laws.
 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * Renesas reserves the right, without notice, to make changes to this software
 * and to discontinue the availability of this software. By using this software,
 * you agree to the additional terms and conditions found by accessing the
 * following link:
 * http://www.renesas.com/disclaimer
 * Copyright 2015-2022 Renesas Electronics Corporation All rights reserved.
 *******************************************************************************/

/*******************************************************************************
 * DESCRIPTION   : RPC driver for QSPI Flash header
 ******************************************************************************/
/******************************************************************************
 * @file          rpcqspidrv.h
 * - Version      : 0.03
 * @brief         RPC driver for QSPI Flash header
 * .
 *****************************************************************************/
/******************************************************************************
 * History : DD.MM.YYYY Version  Description
 *         : 16.02.2022 0.01     First Release
 *         : 01.04.2022 0.02     Add definitions.
 *         : 09.11.2022 0.03     License notation change.
 *****************************************************************************/

#ifndef RPCQSPIDRV_H__
#define RPCQSPIDRV_H__

#include <stdint.h>
#include <bit.h>

#define SPI_IOADDRESS_TOP		0x08000000		/* RPC memory space 0x08000000-0x0BFFFFFF = 64MBytes */
#define RPC_CLK_40M				0x01
#define RPC_CLK_80M				0x02
#define RPC_CLK_160M			0x03

#define DEVICE_ID_MASK          (0x00FFFFFFU)

#define RPC_WRITE_BUF_SIZE      (0x100U)        /* 256byte:RPC Write Buffer size */
#define FLASH_SECTOR_SIZE       (0x00010000U)   /* Flash 1sector is 64KiB */
#define FLASH_SECTOR_MASK       ((~(FLASH_SECTOR_SIZE-1)) & 0xFFFFFFFFU)

#define DRCMR_SMCMR_CMD_SHIFT           (16U)

void init_rpc_qspi_flash_4fastread_ext_mode(void);
void init_rpc_qspi_flash(void);
void sector_erase_4byte_qspi_flash(uint32_t sector_addr);
void write_data_4pp_with_buf_qspi_flash(uint32_t addr, uint32_t source_addr);
void read_any_register_qspi_flash(uint32_t addr, unsigned char *readData);		/* Add24bit,Data8bit */
void write_any_register_qspi_flash(uint32_t addr, unsigned char writeData);		/* Add24bit,Data8bit */
void set_rpc_clock_mode(uint32_t mode);
void wait_rpc_tx_end(void);

void parameter_sector_erase_4kb_qspi_flash(uint32_t sector_addr);
void reset_rpc(void);
void set_rpc_ssl_delay(void);

void power_on_rpc(void);
uint32_t read_wip_status_register(uint32_t *status);    /* for MT25QU01GB */
uint32_t read_qspi_flash_id(uint32_t *readData);		/* for QSPIx1ch */
uint32_t read_status_qspi_flash(uint32_t *readData);	/* for QSPIx1ch */
void write_command_qspi_flash(uint32_t command);		/* for QSPIx1ch */

#endif  /* RPCQSPIDRV_H__ */
