summaryrefslogtreecommitdiff
path: root/bsp/essemi/es8p508x/libraries/Library/Source/lib_iap.c
blob: 9cd1bb4daf4d0b6a76424fbb1644d93c59172059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************
 *Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd.
 *�����  
 *��  ��:  Liut
 *��  ��:  V1.00
 *��  ��:  2017/07/14
 *��  ����  
 *��  ע��  ������ ES8P508оƬ
 ����������ѧϰ����ʾʹ�ã����û�ֱ�����ô����������ķ��ջ������е��κη������Ρ�
 ***************************************************************/
#include "lib_iap.h"

/*************************************************
 * @brief  IAP ҳ�������.�ص��̻���ROM�еij���
 * @param  address: ҳ�׵�ַ
 * @retval None
 ***********************************************/
ErrorStatus IAP_PageErase(uint32_t address)
{
    IAP_PE IAPPageErase = (IAP_PE)(*(uint32_t *)IAP_PageErase_addr);

    ErrorStatus result;
    __ASM("CPSID i");
    result = (*IAPPageErase)(address);
    __ASM("CPSIE i");
    return  result;
}

/*************************************************
 * @brief  IAP �����Ա��.�ص��̻���ROM�еij���
 * @param  address: ����׵�ַ
 * @param  data: �������
 * @retval None
 ************************************************/
ErrorStatus IAP_WordProgram(uint32_t address, uint32_t data)
{
    IAP_WP IAPWordProgram = (IAP_WP)(*(uint32_t *)IAP_WordProgram_addr);

    ErrorStatus result;
    __ASM("CPSID i");
    result = (*IAPWordProgram)( address,  data);
    __ASM("CPSIE i");
    return  result;
}

/************************************************
 * @brief  IAP �����Ա��.�ص��̻���ROM�еij���
 * @param  address: ����׵�ַ
 * @param  data[]: �������
 * @param  length: ������ݳ��ȣ��ֽڣ�
 * @param  address: ���ҳ�Ƿ��Ȳ���
 *     @arg 0: ������
 *     @arg 1: ����
 * @retval None
 **********************************************/
ErrorStatus IAP_PageProgram(uint32_t address, uint32_t data[], uint32_t length, uint32_t erase)  //@0x100001c5
{
    IAP_PP IAPPageProgram = (IAP_PP)(*(uint32_t *)IAP_PageProgram_addr);

    ErrorStatus result;
    __ASM("CPSID i");
    result = (*IAPPageProgram)(address,data,length,erase);
    __ASM("CPSIE i");
    return  result;
}
/*************************************
  ��������IARead
  ��  ����Flash��
  ����ֵ���ڴ��ַ--��ȡ���ݵĴ�ŵ�ַ
  Flash��ַ
  ��ȡ���ݵij��ȣ���λΪ�֣�4�ֽڣ�
  ����ֵ���ɹ�/ʧ��
 **************************************/
ErrorStatus IAPRead(uint32_t *Ram_Addr, uint32_t Flash_Addr, uint8_t Len)
{
    uint8_t i;
    uint32_t *ram_addr;
    const uint32_t *flash_addr;

    ram_addr = Ram_Addr;
    flash_addr = (const uint32_t *)Flash_Addr;

    if (Len == 0)
        return ERROR;

    for (i = 0; i < Len; ++i)
    {
        *ram_addr = *flash_addr;
        ++ram_addr;
        ++flash_addr;
    }

    return SUCCESS;
}

/************************END OF FILE**************************/