📄 sd_32m_manager.c
字号:
#include "SD_32M_Manager.h"
#define SECTOR_SIZE 512
#define SECTOR_NUMBER_PER_PHOTORECORD 9
#define PHOTO_RECORD_NUM 7280
#define START_PHOTO_RECORD_SECTOR 70000
#define END_PHOTO_RECORD_SECTOR 77280
#define SD_HIDEN_SIZE 32*1024*1024
/********************************************************************************************************************
** 函数名称: SD32M_mgr* flashManagerCreate(void)
** Name: SD32M_mgr* flashManagerCreate(void)
** 功能描述: 建立SD卡管理器
** Function: Create Manager for SD Card
** 输 入: NULL
** Input: NULL
** 输 出: SD卡管理器
** Output: Manager for SD Card
*********************************************************************************************************************/
SD32M_mgr* SD32MmanagerCreate(void)
{
SD32M_mgr* this = NULL;
UINT8 *pSector=NULL;
UINT32 count;
this = (SD32M_mgr*)MEM_alloc(0,sizeof(SD32M_mgr),0);
MMC_Init();
if (this == NULL)
{
return NULL;
}
else
{
this->realPhotoRecordNum = 0;
this->save_photo_record = SD32MmgrSavePhotoRecord;
this->get_photo_record = SD32MmgrGetPhotoRecord;
this->clear_record = SD32MmgrClearRecord;
this->init_sd32M = SD32MmgrInitSD32M;
pSector = (UINT8*)MEM_alloc(0,SECTOR_SIZE,0);
if(pSector){
//do with photo record
for(count = START_PHOTO_RECORD_SECTOR;count <= END_PHOTO_RECORD_SECTOR;count=count+9)
{
RBC_Read(count, 1, pSector);
if((pSector[0]==0x55)&&pSector[1]==0xAA)
this->realPhotoRecordNum++;
else
break;
}
//free space
MEM_free(0,pSector,SECTOR_SIZE);
}
return this;
}
}
/********************************************************************************************************************
** 函数名称: static UINT8 SD32MmgrSavePhotoRecord(SD32M_mgr* p, photo_record_inf* pRecord)
** Name: static UINT8 SD32MmgrSavePhotoRecord(SD32M_mgr* p, photo_record_inf* pRecord)
** 功能描述: 将照片存入SD卡中
** Function: Save photo to SD card
** 输 入: SD32M_mgr* p:SD卡管理器指针
photo_record_inf* pRecord:照片信息
** Input: SD32M_mgr* p:Pointer to SD Card Manager
photo_record_inf* pRecord:Photo information
** 输 出: 0:成功 1:失败
** Output: 0:Success 1: Fail
*********************************************************************************************************************/
static UINT8 SD32MmgrSavePhotoRecord(SD32M_mgr* p, photo_record_inf* pRecord)
{
SD32M_mgr* this;
UINT32 sector;
this = p;
if ((this == NULL)||(pRecord == NULL))
{
return NULL;
}
else if(this->realPhotoRecordNum >= PHOTO_RECORD_NUM)
{
return NULL;
}
else
{
sector = START_PHOTO_RECORD_SECTOR + (this->realPhotoRecordNum) * SECTOR_NUMBER_PER_PHOTORECORD;
RBC_Write(sector, SECTOR_NUMBER_PER_PHOTORECORD, pRecord);
this->realPhotoRecordNum++;
return TRUE;
}
}
/********************************************************************************************************************
** 函数名称: static UINT8 SD32MmgrGetPhotoRecord(SD32M_mgr* p, photo_record_inf* pRecord, UINT32 index)
** Name: static UINT8 SD32MmgrGetPhotoRecord(SD32M_mgr* p, photo_record_inf* pRecord, UINT32 index)
** 功能描述: 从SD卡中取得照片信息
** Function: Get photo record from SD Card
** 输 入: SD32M_mgr* p:SD卡管理器指针
photo_record_inf* pRecord:照片信息
UINT32 index:照片记录的位置
** Input: SD32M_mgr* p:Pointer to SD Card Manager
photo_record_inf* pRecord:Photo information
UINT32 index:index position of the photo record
** 输 出: 0:成功 1:失败
** Output: 0:Success 1: Fail
*********************************************************************************************************************/
static UINT8 SD32MmgrGetPhotoRecord(SD32M_mgr* p, photo_record_inf* pRecord, UINT32 index)
{
SD32M_mgr* this;
UINT32 sector;
this = p;
if ((this == NULL)||(pRecord == NULL)||((index+1) > this->realPhotoRecordNum))
{
return NULL;
}
else
{
sector = START_PHOTO_RECORD_SECTOR + index * SECTOR_NUMBER_PER_PHOTORECORD;
RBC_Read(sector, SECTOR_NUMBER_PER_PHOTORECORD, pRecord);
return TRUE;
}
}
/********************************************************************************************************************
** 函数名称: static UINT8 SD32MmgrClearRecord(SD32M_mgr* p)
** Name: static UINT8 SD32MmgrClearRecord(SD32M_mgr* p)
** 功能描述: 从SD卡中取得照片信息
** Function: Get photo record from SD Card
** 输 入: SD32M_mgr* p:SD卡管理器指针
** Input: SD32M_mgr* p:Pointer to SD Card Manager
** 输 出: 0:成功 1:失败
** Output: 0:Success 1: Fail
*********************************************************************************************************************/
static UINT8 SD32MmgrClearRecord(SD32M_mgr* p)
{
SD32M_mgr* this;
UINT32 sector;
this = p;
if (this == NULL)
{
return NULL;
}
else
{
for(sector = START_PHOTO_RECORD_SECTOR;sector <= END_PHOTO_RECORD_SECTOR;sector++)
{
SD_EraseBlock(sector, 0);
}
this->realPhotoRecordNum = 0;
return TRUE;
}
}
/********************************************************************************************************************
** 函数名称: UINT8 SD32MmgrInitSD32M(SD32M_mgr* p)
** Name: UINT8 SD32MmgrInitSD32M(SD32M_mgr* p)
** 功能描述: 初始化SD卡中隐藏的32M空间
** Function: Initialize the hiden 32M memory space
** 输 入: SD32M_mgr* p :SD卡32M空间管理器
** Input: SD32M_mgr* p :The manager of the hiden 32M memory space
** 输 出:
** Output:
*********************************************************************************************************************/
static int SD32MmgrInitSD32M(SD32M_mgr* p)
{
SD32M_mgr* this;
UINT8* psector;
int index;
int i;
UINT8 temp8;
this = p;
if(this == NULL)
{
return NULL;
}
psector = (UINT8*)MEM_alloc(0, SECTOR_SIZE,0);
if(psector == NULL)
return NULL;
index = 0;
for(i=START_PHOTO_RECORD_SECTOR;i<END_PHOTO_RECORD_SECTOR;i=i+9)
{
temp8 = RBC_Read(i,1,psector);
if(temp8!=CH_OK)
return -1;
if((psector[0]=='H')&&(psector[1]=='W'))
{
index++ ;
}
else
break;
}
return index;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -