/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2022. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */

/******************************************************************************
* @version: V1.0.0  demo
******************************************************************************/

/*!
 * 例程说明：
 * 1、在SRAM取消读写保护， 可用于空片，并且使能读写保护导致无法烧录的情况
 */

/*!
 * @file main.c
 *
 * @brief This file is main.c.
 *
 */

/* ===========================================  Includes  =========================================== */
#include "ac7802x.h"
#include "ac780x_eflash_reg.h"

/* ============================================  Define  ============================================ */

/* ===========================================  Typedef  ============================================ */

/* ==========================================  Variables  =========================================== */

/* ====================================  Functions declaration  ===================================== */

/* ======================================  Functions define  ======================================== */

/*!
 * @brief   DisableRWProtect 取消读写保护
 *          如芯片使能读保护，且读保护已经生效， 调用此函数会取消读报护，并且全片擦除！！！
 *          使用前需保证 PA6、PA1为高电平， PA0为低电平， 芯片以SRAM boot 模式启动
 * @param   none
 * @return  none
 */
void DisableRWProtect(void)
{
    uint32_t PflashWriteProtectArray[2] = {0};                                  /*! 每一位代表P-Flash 的1个page, PflashWriteProtectArray[0]为0~31page,PflashWriteProtectArray[1] 为32~64page */
    uint32_t DflashWriteProtectArray[1] = {0};                                  /*! 每一位代表D-Flash 的1个block */
    EFLASH_DisableReadProtection();                                             /*！取消读保护 */
    EFLASH_SetWriteProtection(PflashWriteProtectArray);                         /*! 取消P-Flash每一页写保护, 即每一位写入0 */
    EFLASH_DFSetWriteProtection(DflashWriteProtectArray);                       /*! 取消D-Flash 每一块写保护， 即每一位写入0 */
}
/*!
 * @brief   main函数
 *
 * @param   none
 * @return  int
 */
int main(void)
{
    EFLASH_UnlockCtrl();                                                        /*! 解锁Flash控制器 */
    DisableRWProtect();                                                         /*！取消读写保护， 如果已经使能读报护并生效后，再执行此函数会导致全片擦除 */
    EFLASH_LockCtrl();                                                          /*！加锁 */
    while(1);
}

/* =============================================  EOF  ============================================== */


