串行flash驱动,我写的代码与库中代码的对比

好的代码一定有好的数据结构

typedef struct
{
 int port;
   char *shadow;
   char mask;
} sf_cspin;

typedef struct sf_device_st
{
 struct sf_device_st *next;  //next element in linked list
 long pages; //number of usable pages in flash device
   unsigned int pagesize; //size (in bytes) of pages in flash device
   int addressbytes; // number of bytes used for page addressing
   int pagebitshift; // number of 'don't care' bits following the page address
   int write_state;  // state for multi-page writes (used by filesystem)
   long write_page;  // page currently being written (used by filesystem)
   sf_cspin cspin;
} sf_device;

#ifndef SFLASH_DEVTABLE_SIZE
#define SFLASH_DEVTABLE_SIZE 10
#endif
typedef struct {
 int id_code;
   long pages;
   unsigned int pagesize;
   int addressbytes;
   int pagebitshift;
} sf_devtable_entry;

const sf_devtable_entry sf_devtable[SFLASH_DEVTABLE_SIZE] =
{
   {0x001C, 2047L, 264, 3, 9}, // AT45DB041B
 {0x0024, 4095L, 264, 3, 9}, // AT45DB081B
 {0x0034, 8191L, 528, 3, 11}, // AT45DB321
 {0x003C, 8191L, 1056, 3, 11}, // AT45DB642
 {0x0010, 16383L, 1056, 4, 11}, // AT45DB1282
}; 

优点:方便以后定义新的类型。增强通用性

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值