Sorry, they were in the original fwd.
G.
Dmitry wrote:
>
> Oops...
> where are bitfields?
> ~d
>
> On Wednesday 19 November 2003 18:29, Garst R. Reese wrote:
> > Dmitry wrote:
> > > hm...
> > > any code snippet?
> > > ~d
> >
> > Sure, let me know if you need more.
> > Thanks,
> > Garst
> >
> > #ifdef _MMC_TEST
> > int main(void)
> > {
> > unsigned int i;
> > union reg16b_t reg16b;
> > mcu_init();
> > spi_init();
> > lcd_init();
> > clear_display();
> > lcd_set_pos(0,0);
> > get_register(MMC_SEND_CSD,®16b);
> > print_register(®16b);
> > print_response(0xEE);
> > print_response(reg16b.csd.READ_BL_LEN);
> > SPI_NONE;
> > }
> > #endif
> >
> >
> > int get_register( unsigned char reg_cmd, union reg16b_t *reg16)
> > {
> > unsigned char arguments[4];
> > unsigned char temp25;
> > int i;
> >
> > arguments[0]=0x00;
> > arguments[1]=0x00;
> > arguments[2]=0x00;
> > arguments[3]=0x00;
> > temp25=mmc_sendcmd(reg_cmd,arguments);
> > if(temp25)
> > {
> > SPI_NONE;
> > SPI_LCD_EN;
> > lcd_write_string("GETREG");
> > print_response(temp25);
> > BREAKPNT;
> > return FALSE;
> > }
> > mmc_get_data((unsigned char*) reg16);
> > return TRUE;
> > }
> >
> >
> > int mmc_get_data(unsigned char* data)
> > {
> > unsigned char temp25;
> > int i ;
> >
> > while((temp25=mmc_get_response())==0); //if card is busy
> > if(temp25!=0xFE)
> > {
> > BREAKPNT;
> > return FALSE;
> > }
> >
> > /*read the data*/
> > for(i=0;i<16;i++)
> > {
> > data[i]=spi_read();
> > }
> >
> > //CRC TOKENs
> > spi_read();
> > spi_read();
> >
> > return TRUE;
> > }
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: SF.net Giveback Program.
> > Does SourceForge.net help you be more productive? Does it
> > help you create better code? SHARE THE LOVE, and help us help
> > YOU! Click Here: http://sourceforge.net/donate/
> > _______________________________________________
> > Mspgcc-users mailing list
> > Mspgcc-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>
> --
> /*****************************************************************
> ("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ
> `6_ 6 ) `-. ( ).`-.__.`) State Polytechnical Univ.
> (_Y_.)' ._ ) `._ `. ``-..-' Radio-Physics Departament
> _..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia
> (il),-'' (li),' ((!.-' +7 (812) 5403923, 5585314
> *****************************************************************/
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Mspgcc-users mailing list
> Mspgcc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
/*
* CVS: $Id: mmc.h,v 1.9 2003/03/08 10:44:00 andreas Exp $
*
*
*/
#ifndef MMC_H
#define MMC_H
#include <io.h>
#include <sys/inttypes.h>
#include "config.h"
union reg16b_t {
struct csd_t {
unsigned CSD_STRUCTURE:2; //
unsigned SPEC_VERS:4; // Version
unsigned R1:2; // reserved
unsigned TAAC:8; // Read Access Time
unsigned NASC:8; // Read Access Time in CLK cycles
unsigned TRAN_SPEED:8; // Max Date Transfer Rate
unsigned CCC:12;// shout be f4 Card Command Class
unsigned READ_BL_LEN:4; // Max. Read Data Block Length
unsigned READ_BL_PARTIAL:1; // Partial Blocks for Read Allowed
unsigned WRITE_BLK_MISALIGN:1; // Write Block Misalignment
unsigned READ_BLK_MISALIGN:1; // Read Block Misalignment
unsigned DSR_IMP:1; // DSR Implemnted
unsigned R2:2; // reserved
unsigned C_SIZE:12;//Device Size
unsigned VDD_R_CURR_MIN:3; //Max. Read Current @Vdd Min.
unsigned VDD_R_CURR_MAX:3; //Max. Read Current @Vdd
unsigned VDD_W_CURR_MIN:3; //Max. Write Current @Vdd Min
unsigned VDD_W_CURR_MAX:3; //Max. Write Current @Vdd
unsigned C_SIZE_MULT:3; //Device Size Multiplier
unsigned SECTOR_SIZE:5; //Erase Sector Size
unsigned ERASE_GRP_SIZE:5; //Erase Group Size
unsigned WP_GRP_SIZE:5; //Write protect group Size
unsigned WP_GRP_ENABLE:1; //Write protect group Enable
unsigned DEFAULT_ECC:2; //
unsigned R2W_FACTOR:3; //Read to Write speed factor
unsigned WRITE_BL_LEN:4; //Max. Write Data Block Length
unsigned WRITE_BL_PARTIAL:1; //Partial blocks allowed 0
unsigned R3:5; //Reseved
unsigned FILE_FORMAT_GRP:1; //File format of selected Group
unsigned COPY:1; //Copy Flag (OTP)
unsigned PERM_WRITE_PROTECT:1; //Permanent write protection
unsigned TMP_WRITE_PROTECT:1; //Temporary write protection.
unsigned FILE_FORMAT:2; //File format of card
unsigned ECC:2; //ECC code
unsigned CRC:7; //CRC
unsigned STOP:1; //always 1
}csd;
unsigned char buff[16];
}csd_register;
// function prototypes
unsigned char spi_read(void);
int mmc_init(void);
unsigned char mmc_sendcmd(unsigned char, unsigned char* arguments);
unsigned char mmc_get_response(void);
void print_response(unsigned char);
void digest(void);
void mmc_write_block(unsigned int address, unsigned int size);
void mmc_lock_unlock(void);
int mmc_get_data(unsigned char* data);
void print_register(union reg16b_t *reg);
unsigned char send_byte(unsigned char );
/*MMC TOKENS*/
#define BUSY_TOKEN 0x00
#ifdef _MULTI_BLOCK_TRANSFER
#define DATA_START 0xFE
#else
#define DATA_START 0xFE
#endif
#define STOP_TRAN 0xFD
#define DATA_ERR_TOKEN //SEE MANUAL FOR BIT DETAIL>.. ADD THIS HERE
/*MMC RESPONSES*/
/*R1 Reposnse BITS*/
#define NO_ERRORS 0x00
#define IN_IDLE_STATE BV(0)
#define ERASE_RESET BV(1)
#define ILLEGAL_CMD BV(2)
#define COM_CRC_ERR BV(3)
#define ERASE_SQNC_ERR BV(4)
#define ADDR_ERR BV(5)
#define PARAM_ERR BV(6)
/*Data Responses*/
#define DATA_RESP_MASK 0x1F
#define DATA_ACCEPTED 0x05
#define DATA_CRC_ERR 0x0B
#define DATA_WRT_ERR 0x0D
/* MMC commands - FOR SPI MODE ONLY */
/* Each command is 48-bits, see send_cmd()
and doc for more details*/
/*Class 0 - Basic Commands*/
#define CMD0 0
#define CMD1 1
#define CMD9 9
#define CMD10 10
#define CMD13 13
#define CMD58 58
#define CMD59 59
/*Class 2 - Block Read*/
#define CMD16 16
#define CMD17 17
/*Class 4 - Block Write */
#define CMD24 24
#define CMD27 27
/*Class 5 - Erase */
#define CMD32 32
#define CMD33 33
#define CMD34 34
#define CMD35 35
#define CMD36 36
#define CMD37 37
#define CMD38 38
/* Class 6 - Write Protection*/
#define CMD28 28
#define CMD29 29
#define CMD30 30
/* Class 7 - Lock Card*/
#define CMD42 42
/* Alternative Names for MMC Commands*/
#define MMC_GO_IDLE_STATE CMD0
#define MMC_SEND_OP_COND CMD1
#define MMC_SEND_CSD CMD9
#define MMC_SEND_CID CMD10
#define MMC_SEND_STATUS CMD13
#define MMC_SET_BLOCKLEN CMD16
#define MMC_READ_SINGLE_BLOCK CMD17
#define MMC_WRITE_BLOCK CMD24
#define MMC_PROGRAM_CSD CMD27
#define MMC_SET_WRITE_PROT CMD28
#define MMC_CLR_WRITE_PROT CMD29
#define MMC_SEND_WRITE_PROT CMD30
#define MMC_TAG_SECTOR_START CMD32
#define MMC_TAG_SECTOR_END CMD33
#define MMC_UNTAG_SECTOR CMD34
#define MMC_TAG_EREASE_GROUP_START CMD35
#define MMC_TAG_EREASE_GROUP_END CMD36
#define MMC_UNTAG_EREASE_GROUP CMD37
#define MMC_EREASE CMD38
#define MMC_LOCK_UNLOCK CMD42
#define MMC_READ_OCR CMD58
#define MMC_CRC_ON_OFF CMD59
/*
struct MMC_CMD{
uint8_t cmd;
union{
uint32_t address; //is this going to be in the right order???
uint8_t adr[4];
};
uint8_t crc; //SPI crc only needed for command 0, otherwise only bit 0
//needs to be set, but 95 does that, so it is good for all
uint8_t resp[2]; //except for command 13, this will be one byte.
};
//uint8_t CID[18]; used for CID CSD registers 16 bytes + 2 byte CRC
} MMC_cmd;
*/
#endif // MMC_H