ethan
2022-09-13 2c8058e6575f4e0238a98140d8ddcb5afb11f44c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 /**
  ******************************************************************************
  * @file     xl_eeprom.h
  * @author   software group
  * @brief    This file contains all the functions prototypes for the EERPOM 
  *           firmware library.
  ******************************************************************************
  * @attention
    *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */ 
/* Define to prevent recursive inclusion -------------------------------------*/     
#ifndef __XL_EEPROM_H_
#define __XL_EEPROM_H_
 
#ifdef __cplusplus
extern "C" {
#endif
    
/* Includes ---------------------------------------------------------------*/
#include "xl6600.h"
#include "xl_gpio.h"
#include "xl_port.h"
#include "xl_i2c.h"
#include "xl_nvic.h"
#include "xl_sim.h"
/* Register define ------------------------------------------------------------*/
 
/** EEPROM - Register Layout Typedef */
    
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @addtogroup EEPROM
  * @{
  */
 
/* Exported types ------------------------------------------------------------*/ 
 
/** @defgroup EEPROM_Exported_Constants EEPROMÄ£¿éʹÓòÎÊý¶¨Òå
  * @{
  */
#define USER_HARDWARE_OR_SOFTWARE  1u
 
#define EEPROM_BASE_ADDRESS  0x40000000u
/**
  * @}
  */
 
 
/** @defgroup EEPROM_WORK_SOFTWARE_PIN EEPROMÈí¼þ¹¤×÷ģʽPin¶¨Òå
  * @{
  */
#if (USER_HARDWARE_OR_SOFTWARE == 0u)
    #define  SET_SDA_INPUT()    {*((unsigned long *)0x40100054) &=  ~((uint32_t)1    <<    ((uint8_t)GPIO_PTH3 - (uint8_t)32));  *((unsigned long *)0x40100058) &=  ~((uint32_t)1    <<    ((uint8_t)GPIO_PTH3 - (uint8_t)32));}
    #define  SET_SDA_OUTPUT()   {*((unsigned long *)0x40100054) |=   ((uint32_t)1    <<    ((uint8_t)GPIO_PTH3 - (uint8_t)32));  *((unsigned long *)0x40100058) &=  ~((uint32_t)1    <<    ((uint8_t)GPIO_PTH3 - (uint8_t)32));}
 
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__)
    #define I2C_SDA_H()                  {__asm volatile("cpsid i"); *((unsigned long *)0x40100044)  |= (1<<(GPIO_PTH3 -32));__asm volatile("cpsie i");}
    #define I2C_SDA_L()                  {__asm volatile("cpsid i"); *((unsigned long *)0x40100048)  |= (1<<(GPIO_PTH3 -32));__asm volatile("cpsie i");}
    #define I2C_SCK_H()                 {__asm volatile("cpsid i"); *((unsigned long *)0x40100044)  |= (1<<(GPIO_PTH4 -32));__asm volatile("cpsie i");}
    #define I2C_SCK_L()                 {__asm volatile("cpsid i"); *((unsigned long *)0x40100048)  |= (1<<(GPIO_PTH4 -32));__asm volatile("cpsie i");}
#elif defined(__ARMCC_VERSION) || defined(__CWCC__)
    #define I2C_SDA_H()                  {__disable_irq(); *((unsigned long *)0x40100044)  |= (1<<(GPIO_PTH3 -32));__enable_irq();}
    #define I2C_SDA_L()                  {__disable_irq(); *((unsigned long *)0x40100048)  |= (1<<(GPIO_PTH3 -32));__enable_irq();}
    #define I2C_SCK_H()                 {__disable_irq(); *((unsigned long *)0x40100044)  |= (1<<(GPIO_PTH4 -32));__enable_irq();}
    #define I2C_SCK_L()                 {__disable_irq(); *((unsigned long *)0x40100048)  |= (1<<(GPIO_PTH4 -32));__enable_irq();} 
#endif    
    
#endif
/**
  * @}
  */
 
/** @defgroup EEPROM_TIMER  EEPROM³¬Ê±¼ÆÊýÆ÷¶¨Òå
 * @{
 */
typedef struct
{
    uint8_t timer_start;
    uint32_t timer_cnt;
}Timer_Type;
/**
  * @}
  */
 
/**
    * @defgroup EEPROM_Status   EEPROM״̬ÀàÐͶ¨Òå
    * @{
    */
typedef enum
{
    EEPROM_OK = 0,
    EEPROM_SlaveID_TIMEOUT,
    EEPROM_ADDRESS_TIMEOUT,
    EEPROM_DATA_TIMEOUT,
}EEPROM_Status;
/**
  * @}
  */
 
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/ 
void EEPROM_Init(uint32_t systemclk);
void EEPROM_DeInit(void);
void EEPROM_WriteProtectEn(FunctionalState NewState);
uint8_t EEPROM_WriteByte(uint32_t address,uint8_t data,uint32_t time);
EEPROM_Status EEPROM_WriteBuff(uint32_t address,const uint8_t *data,uint8_t lenght,uint32_t time);
EEPROM_Status EEPROM_WritePage(uint8_t page,const uint8_t *data,uint32_t time);
EEPROM_Status EEPROM_ReadByte(uint32_t address,uint8_t *data,uint32_t time);
EEPROM_Status EEPROM_ReadBuff(uint32_t address,uint8_t *data,uint16_t lenght,uint32_t time);
 
#ifdef __cplusplus
}
#endif    
    
#endif 
/**
  * @}
  */ 
 
/**
  * @}
  */