Flash memory E2Rom 等常用到的页写算法
发布时间:2020-12-15 20:05:29 所属栏目:百科 来源:网络整理
导读:long xxxPageWrite(long uAddr,const void *pSrcData,long iLen){ #define PAGE_SIZE 128 //页面大小 #define MAX_ADDRESS 0x10000UL //最大地址 long iDoneBytes=0; //写入的长度 long iOffset,iNewWrLen; unsigned char PageBuff[PAGE_SIZE]; //页面缓冲区
long xxxPageWrite(long uAddr,const void *pSrcData,long iLen) { #define PAGE_SIZE 128 //页面大小 #define MAX_ADDRESS 0x10000UL //最大地址 long iDoneBytes=0; //写入的长度 long iOffset,iNewWrLen; unsigned char PageBuff[PAGE_SIZE]; //页面缓冲区 const char *pData = (const char *)pSrcData; //源数据 while(iDoneBytes < iLen) { iOffset = (uAddr % PAGE_SIZE); //页内偏移 uAddr -= iOffset; //地址对齐到页起始 if((uAddr + PAGE_SIZE) > MAX_ADDRESS)//超出最大地址 break; //需要写入的字节数 iNewWrLen = min(PAGE_SIZE,iLen - iDoneBytes) - iOffset; if(iOffset //起始部分没有对齐 || iNewWrLen != PAGE_SIZE //非整页数据 || 0)//需要读出原始数据 { //整页读出 //读出从 uAddr 开始的 PAGE_SIZE 个字节数据到 PageBuff //比如 I2cRead(uAddr,PageBuff,PAGE_SIZE); } //合并新写入数据 memcpy(PageBuff + iOffset,pData,iNewWrLen); //页面写入 { //循环写入PageBuff 的 PAGE_SIZE个字节的数据 到 uAddr //比如 I2cWrite(uAddr,PAGE_SIZE); } //准备下帧 uAddr += PAGE_SIZE; //页写地址 pData += iNewWrLen; //源数据地址 iDoneBytes += iNewWrLen; //写入的长度 } return iDoneBytes; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- cocos2dx 中的SEL_Callfunc,SEL_CallfuncN,SEL_CallfuncNd的
- 试着用React写项目-利用react-router解决跳转路由等问题(四
- ajax – 隐藏字段“ufprt”被添加到Razor Umbraco表格 – 为
- 如何判断sqlite列是否为AUTOINCREMENT?
- 如何在iphone中以编程方式获取“常规 – >日期和时间 – >
- ruby轨道 – 载波波亚马逊S3图像不显示
- ruby-on-rails – Rails中的Twitter-Bootstrap和Forms
- 用 AXMLPrinter2、baksmali、smali、dex2jar 反编译.xml文件
- FLTK学习-2-新手入门参考
- c# – 如何确定字符串的大小并压缩它