compactflash.h

Code to work with CompactFlash (by Yann Hendrikx).



#ifndef _compactflash.h
#define _compactflash.h

// ports
#define CF_DATA   portb
#define CF_ADDR   porte
#define CF_CONTROL porta

// flags
#define CE1 5 
#define CD2 0
#define RESET 1
#define OE 4
#define WE 3
#define RDY 2

// addresses
#define DATA_REG 0
#define ERROR_REG 1
#define FEATURES_REG 1
#define BLOCKCOUNT_REG 2
#define BLOCKLOW_REG 3
#define BLOCKMIDDLE_REG 4
#define BLOCKHIGH_REG 5
#define HEAD_REG 6
#define STATUS_REG 7
#define COMMAND_REG 7

// commands
#define DIAGNOSTIC 0x90
#define IDENTIFY 0xEC
#define WRITE_BLOCK 0x30
#define READ_BLOCK 0x20

char compactFlashPosition = 0;
char compactFlashBufferSize = 4;
char compactFlashBuffer[64];                                      // 128 or 256 is not possible! Could be a bug!

void compactFlashInit();

void compactFlashWrite(char addr, char data);
char compactFlashRead(char addr);
void compactFlashReadBuffer(char offset, char length);
void compactFlashWriteBuffer(char offset, char length);
void compactFlashFillBuffer();
void compactFlashClearBuffer();

char compactFlashPresent();
void compactFlashWait();
void compactFlashReset();

void compactFlashReadBlock(char blockHigh, char blockMiddle, char blockLow);
void compactFlashWriteBlock(char blockHigh, char blockMiddle, char blockLow);
void compactFlashIdentify();
char compactFlashDiagnostic();

#include "compactflash.c"

#endif



http://www.sourceboost.com/home.html

Copyright © 2002-2006 SourceBoost Technologies