whycyhl
2022-05-05 94861120b14313f81fc666e612c48c9e8a81f1e7
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
/************************** Copyright (c) **********************************
**                 FUZHOU FUGUANG ELECTRONICS Co.,LTD.
**                        ¸£Öݸ£¹âµç×ÓÓÐÏÞ¹«Ë¾
**                       http://www.fuguang.com
**
**-------------- File Info -------------------------------------------------
** File name:            SST25VF_Driver.h
** Last modified Date:  2008-11-16
** Last Version:        1.0
** Descriptions:        SST25VF Drivers lib
**
**--------------------------------------------------------------------------
** Created by:            mxpopstar
** Created date:        2008-11-16
** Version:                1.0
** Descriptions:        The original version
**
**--------------------------------------------------------------------------
** Modified by:            mxpopstar
** Modified date:        2008-11-20
** Version:
** Descriptions:        SST25VF Drivers lib
**
***************************************************************************/
//
 
#ifndef SST25VF_Driver_H
#define SST25VF_Driver_H
 
//--------------------------------------------------------------------------------------------------
//--------------------- IOPORT -----------------------------------------------------
#define     SST25VF_CS_DDR            DDRG
#define     SST25VF_CS_PORT            PORTG
#define     SST25VF_CS_PIN            PG2
#define     SST25VF_SPI_OFF            SST25VF_CS_PORT |= (1<<SST25VF_CS_PIN)            //PING2
#define     SST25VF_SPI_ON            SST25VF_CS_PORT &= ~(1<<SST25VF_CS_PIN)
//----------------------------------------------------------------------------------
#define     SST25VF_MOSI_DDR        DDRB
#define     SST25VF_MOSI_PORT        PORTB
#define     SST25VF_MOSI_PIN        PB2
#define     SST25VF_MOSI_1           SST25VF_MOSI_PORT |= (1<<SST25VF_MOSI_PIN)        //PINB2
#define     SST25VF_MOSI_0           SST25VF_MOSI_PORT &= ~(1<<SST25VF_MOSI_PIN)
//----------------------------------------------------------------------------------
#define     SST25VF_MISO_DDR        DDRB
#define     SST25VF_MISO_PORT        PORTB
#define     SST25VF_MISO_PIN        PB3
#define     SST25VF_MISO_PNAME        PINB
#define     SST25VF_MISO_1            (SST25VF_MISO_PNAME & (1<<SST25VF_MISO_PIN))    //PINB3
//----------------------------------------------------------------------------------
#define     SST25VF_SCK_DDR            DDRB
#define     SST25VF_SCK_PORT        PORTB
#define     SST25VF_SCK_PIN            PB1
#define     SST25VF_SCK_1            SST25VF_SCK_PORT |= (1<<SST25VF_SCK_PIN)        //PINB1
#define     SST25VF_SCK_0            SST25VF_SCK_PORT &= ~(1<<SST25VF_SCK_PIN)
//----------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/*
//--------------------- IOPORT --------------------------------
#define SST25VF_SPI_OFF         PORTG |= 1<<PG2       //PING2  
#define SST25VF_SPI_ON          PORTG &= ~(1<<PG2)
 
#define SST25VF_MOSI_1          PORTB |= 0x04        //PINB2
#define SST25VF_MOSI_0          PORTB &= (~0x04)
#define SST25VF_MISO_1          PINB & 0x08          //PINB3
 
#define SST25VF_SCK_1           PORTB |= 0x02        //PINB1
#define SST25VF_SCK_0           PORTB &= (~0x02)
*/
//--------------------- CMD -----------------------------------
#define     SSTMemorySize                0x100000UL
#define     SSTBlockSize                32768UL
#define     SSTBlockSum                    32
 
#define     SST25VF_WriteEN                0x06
#define     SST25VF_FlashProtectNone    0x00
#define     SST25VF_WriteAAI_EN            0x40
//--------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
 
#include<avr/io.h>
#include <util/delay.h>
#include "Define.h"
#include "FileManage.h"
 
void InitIO_SST25VF(void);
void Config_SST25VF(void);
void ReadID_SST25VF(unsigned char *id);
unsigned char ReadSR_SST25VF(void);
void WriteSR_SST25VF(const unsigned char data);
void EraseChip_SST25VF(void);
void Erase32K_SST25VF(const unsigned long addr);
void Erase4K_SST25VF(const unsigned long addr);
unsigned char SpiRead_SST25VF(void);
void WriteCMD_SST25VF(const unsigned char cmd);
unsigned char ReadBlock_SST25VF(const unsigned char tag,  
                                const unsigned char BlockSum, 
                                const unsigned char device);
void ReadFileInf(const unsigned long addr, File_Inf *fileinf);
unsigned char ReadByte_SST25VF(const unsigned long addr);
void WriteByte_SST25VF(const unsigned long addr, const unsigned char data);
void WriteBlock_SST25VF(const unsigned long addr, volatile const void *data, 
                        const unsigned int count);
 
#endif
//