⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmc.lst

📁 MMC/SD on Olimex Sam7-EX256
💻 LST
📖 第 1 页 / 共 4 页
字号:
 169:mmc.c         ****   //followed by an error code
 170:mmc.c         ****   //data will be 0xff until response
 171:mmc.c         ****   int i=0;
 172:mmc.c         **** 
 173:mmc.c         ****   char response;
 174:mmc.c         ****   char rvalue;
 175:mmc.c         ****   while(i<=64)
 176:mmc.c         ****   {
 177:mmc.c         ****    response=spiSendByte(0xff);
 178:mmc.c         ****    response &= 0x1f;
 179:mmc.c         ****    switch(response)
 180:mmc.c         ****     {
 181:mmc.c         ****      case 0x05: rvalue=MMC_SUCCESS;break;
 182:mmc.c         ****      case 0x0b: return(MMC_CRC_ERROR);
 183:mmc.c         ****      case 0x0d: return(MMC_WRITE_ERROR);
 184:mmc.c         ****      default:
 185:mmc.c         **** 	      rvalue = MMC_OTHER_ERROR;
 186:mmc.c         **** 	      break;
 187:mmc.c         ****     }
 188:mmc.c         ****    if(rvalue==MMC_SUCCESS)break;
 189:mmc.c         ****     i++;
 190:mmc.c         ****   }
 191:mmc.c         ****   i=0;
 192:mmc.c         ****   do
 193:mmc.c         ****   {
 194:mmc.c         ****    response=spiSendByte(0xff);
 195:mmc.c         ****    i++;
 196:mmc.c         ****   }while(response==0);
 197:mmc.c         ****   return response;
 198:mmc.c         **** }
 199:mmc.c         **** // The card will respond with a standard response token followed by a data
 200:mmc.c         **** // block suffixed with a 16 bit CRC.
 201:mmc.c         **** 
 202:mmc.c         **** // Ti Modification: long int -> long ; int -> long
 203:mmc.c         **** char mmcReadBlock(const unsigned long address, const unsigned long count)
 204:mmc.c         **** {
 205:mmc.c         ****   unsigned long i = 0;
 206:mmc.c         ****   char rvalue = MMC_RESPONSE_ERROR;
 207:mmc.c         **** 
 208:mmc.c         ****   // Set the block length to read
 209:mmc.c         ****   if (mmcSetBlockLength (count) == MMC_SUCCESS)	// block length could be set
 210:mmc.c         ****     {
 211:mmc.c         ****       //SS = LOW (on)
 212:mmc.c         ****       //CS_LOW ();
 213:mmc.c         ****       // send read command MMC_READ_SINGLE_BLOCK=CMD17
 214:mmc.c         ****       mmcSendCmd (17,address, 0xFF);
 215:mmc.c         ****       // Send 8 Clock pulses of delay, check if the MMC acknowledged the read block command
 216:mmc.c         ****       // it will do this by sending an affirmative response
 217:mmc.c         ****       // in the R1 format (0x00 is no errors)
 218:mmc.c         ****       if (mmcGetResponse() == 0x00)
 219:mmc.c         **** 	{
 220:mmc.c         **** 	  // now look for the data token to signify the start of
 221:mmc.c         **** 	  // the data
 222:mmc.c         **** 	  if (mmcGetXXResponse(MMC_START_DATA_BLOCK_TOKEN) == MMC_START_DATA_BLOCK_TOKEN)
 223:mmc.c         **** 	    {
 224:mmc.c         **** 	      // clock the actual data transfer and receive the bytes; spi_read automatically finds the Da 225:mmc.c         **** 	      for (i = 0; i < 512; i++)
 226:mmc.c         **** 		mmc_buffer[i] = spiSendByte(0xff);	// is executed with card inserted
 227:mmc.c         **** 
 228:mmc.c         **** 	      // get CRC bytes (not really needed by us, but required by MMC)
 229:mmc.c         **** 	      spiSendByte(0xff);
 230:mmc.c         **** 	      spiSendByte(0xff);
 231:mmc.c         **** 	      rvalue = MMC_SUCCESS;
 232:mmc.c         **** 	    }
 233:mmc.c         **** 	  else
 234:mmc.c         **** 	    {
 235:mmc.c         **** 	      // the data token was never received
 236:mmc.c         **** 	      rvalue = MMC_DATA_TOKEN_ERROR;	// 3
 237:mmc.c         **** 	    }
 238:mmc.c         **** 	}
 239:mmc.c         ****       else
 240:mmc.c         **** 	{
 241:mmc.c         **** 	  // the MMC never acknowledge the read command
 242:mmc.c         **** 	  rvalue = MMC_RESPONSE_ERROR;	// 2
 243:mmc.c         **** 	}
 244:mmc.c         ****     }
 245:mmc.c         ****   else
 246:mmc.c         ****     {
 247:mmc.c         ****       rvalue = MMC_BLOCK_SET_ERROR;	// 1
 248:mmc.c         ****     }
 249:mmc.c         ****   //CS_HIGH ();
 250:mmc.c         ****   spiSendByte(0xff);
 251:mmc.c         ****   return rvalue;
 252:mmc.c         **** }				// mmc_read_block
 253:mmc.c         **** 
 254:mmc.c         **** 
 255:mmc.c         **** 
 256:mmc.c         **** //---------------------------------------------------------------------
 257:mmc.c         **** // Ti Modification: long int -> long
 258:mmc.c         **** char mmcWriteBlock (const unsigned long address)
 259:mmc.c         **** {
 260:mmc.c         ****   unsigned long i = 0;
 261:mmc.c         ****   char rvalue = MMC_RESPONSE_ERROR;	// MMC_SUCCESS;
 262:mmc.c         ****   //char c = 0x00;
 263:mmc.c         **** 
 264:mmc.c         ****   // Set the block length to read
 265:mmc.c         ****   if (mmcSetBlockLength (512) == MMC_SUCCESS)	// block length could be set
 266:mmc.c         ****     {
 267:mmc.c         ****       // SS = LOW (on)
 268:mmc.c         ****       //CS_LOW ();
 269:mmc.c         ****       // send write command
 270:mmc.c         ****       mmcSendCmd (24,address, 0xFF);
 271:mmc.c         **** 
 272:mmc.c         ****       // check if the MMC acknowledged the write block command
 273:mmc.c         ****       // it will do this by sending an affirmative response
 274:mmc.c         ****       // in the R1 format (0x00 is no errors)
 275:mmc.c         ****       if (mmcGetXXResponse(MMC_R1_RESPONSE) == MMC_R1_RESPONSE)
 276:mmc.c         **** 	{
 277:mmc.c         **** 	  spiSendByte(0xff);
 278:mmc.c         **** 	  // send the data token to signify the start of the data
 279:mmc.c         **** 	  spiSendByte(0xfe);
 280:mmc.c         **** 	  // clock the actual data transfer and transmitt the bytes
 281:mmc.c         **** 	  for (i = 0; i < 512; i++)
 282:mmc.c         **** 	    spiSendByte(mmc_buffer[i]);	// mmc_buffer[i];       Test: i & 0xff
 283:mmc.c         **** 	  // put CRC bytes (not really needed by us, but required by MMC)
 284:mmc.c         **** 	  spiSendByte(0xff);
 285:mmc.c         **** 	  spiSendByte(0xff);
 286:mmc.c         **** 	  // read the data response xxx0<status>1 : status 010: Data accected, status 101: Data
 287:mmc.c         **** 	  //   rejected due to a crc error, status 110: Data rejected due to a Write error.
 288:mmc.c         ****           mmcCheckBusy();
 289:mmc.c         **** 	}
 290:mmc.c         ****       else
 291:mmc.c         **** 	{
 292:mmc.c         **** 	  // the MMC never acknowledge the write command
 293:mmc.c         **** 	  rvalue = MMC_RESPONSE_ERROR;	// 2
 294:mmc.c         **** 	}
 295:mmc.c         ****     }
 296:mmc.c         ****   else
 297:mmc.c         ****     {
 298:mmc.c         ****       rvalue = MMC_BLOCK_SET_ERROR;	// 1
 299:mmc.c         ****     }
 300:mmc.c         ****   //give the MMC the required clocks to finish up what ever it needs to do
 301:mmc.c         ****   //for (i = 0; i < 9; ++i)
 302:mmc.c         ****   //spiSendByte(0xff);
 303:mmc.c         **** 
 304:mmc.c         ****   //CS_HIGH ();
 305:mmc.c         ****   // Send 8 Clock pulses of delay.
 306:mmc.c         ****   spiSendByte(0xff);
 307:mmc.c         ****   return rvalue;
 308:mmc.c         **** }// mmc_write_block
 309:mmc.c         **** 
 310:mmc.c         **** 
 311:mmc.c         **** //---------------------------------------------------------------------
 312:mmc.c         **** void mmcSendCmd (const char cmd, unsigned long data, const char crc)
 313:mmc.c         **** {
 314:mmc.c         ****   char frame[6];
 315:mmc.c         ****   char temp;
 316:mmc.c         ****   int i;
 317:mmc.c         **** 
 318:mmc.c         ****   frame[0]=(cmd|0x40);
 319:mmc.c         ****   for(i=3;i>=0;i--){
 320:mmc.c         ****     temp=(char)(data>>(8*i));
 321:mmc.c         ****     frame[4-i]=(temp);
 322:mmc.c         ****   }
 323:mmc.c         ****   frame[5]=(crc);
 324:mmc.c         ****   for(i=0;i<6;i++)
 325:mmc.c         ****     spiSendByte(frame[i]);
 326:mmc.c         **** }
 327:mmc.c         **** 
 328:mmc.c         **** 
 329:mmc.c         **** //--------------- set blocklength 2^n ------------------------------------------------------
 330:mmc.c         **** // Ti Modification: long int-> long
 331:mmc.c         **** char mmcSetBlockLength (const unsigned long blocklength)
 332:mmc.c         **** {
 333:mmc.c         ****   //char rValue = MMC_TIMEOUT_ERROR;
 334:mmc.c         ****   //char i = 0;
 335:mmc.c         **** 
 336:mmc.c         ****   // SS = LOW (on)
 337:mmc.c         ****   //CS_LOW ();
 338:mmc.c         **** 
 339:mmc.c         ****   // Set the block length to read
 340:mmc.c         ****   //MMC_SET_BLOCKLEN =CMD16
 341:mmc.c         ****   mmcSendCmd(16, blocklength, 0xFF);
 342:mmc.c         **** 
 343:mmc.c         ****   // get response from MMC - make sure that its 0x00 (R1 ok response format)
 344:mmc.c         ****   if(mmcGetResponse()!=0x00);
 345:mmc.c         **** 
 346:mmc.c         ****   //CS_HIGH ();
 347:mmc.c         **** 
 348:mmc.c         ****   // Send 8 Clock pulses of delay.
 349:mmc.c         ****   spiSendByte(0xff);
 350:mmc.c         **** 
 351:mmc.c         ****   return MMC_SUCCESS;
 352:mmc.c         **** }				
 353:mmc.c         **** 
 354:mmc.c         **** 
 355:mmc.c         **** unsigned char spiSendByte(const unsigned char data)
 356:mmc.c         **** {
 171              		.loc 1 356 0 172              	.LVL3: 357:mmc.c         ****     /*
 358:mmc.c         ****     unsigned char spib;
 359:mmc.c         **** 
 360:mmc.c         ****     //while(SSIOST_bit.BUSY != 0);    // Wait until the character can be sent
 361:mmc.c         ****     SSIOINT_bit.TXCMP = 1;            //clear interrupt register
 362:mmc.c         ****     SSIOBUF = data;                   // Send the data
 363:mmc.c         **** 
 364:mmc.c         ****     while((SSIOINT & 0x02) != 0x02);   // Wait for the transfer to complete
 365:mmc.c         ****     spib = SSIOBUF;                   // Get the data received
 366:mmc.c         ****     SSIOINT_bit.RXCMP = 1;            //clear interrupt register
 367:mmc.c         ****     return spib;                      //return transmited character
 368:mmc.c         ****     */
 369:mmc.c         **** 
 370:mmc.c         ****   /*
 371:mmc.c         ****     //NOTE!!! This function send character to SPI bus when mode is MASTER
 372:mmc.c         ****     //NOTE!!! This function receive character from SPI when mode is SLAVE
 373:mmc.c         ****     unsigned int spib;
 374:mmc.c         **** 
 375:mmc.c         ****     //while(SSPSR_bit.BSY);      // Wait until the character can be sent
 376:mmc.c         ****     while(SSPSR_bit.TNF == 0);
 377:mmc.c         ****     SSPDR = data;              // Send the data
 378:mmc.c         **** 
 379:mmc.c         ****     //while(!SPSR0_bit.SPIF);     // Wait for the transfer to complete
 380:mmc.c         ****     while(SSPSR_bit.RNE == 0);    // Wait until the character can be sent
 381:mmc.c         ****     spib = SSPDR;                 // Get the data received
 382:mmc.c         ****     return spib;
 383:mmc.c         ****     //return 0;
 384:mmc.c         ****   */
 385:mmc.c         **** 
 386:mmc.c         **** 
 387:mmc.c         ****     /*
 388:mmc.c         ****     unsigned int spib;
 389:mmc.c         **** 
 390:mmc.c         ****     while((s_pSpi->SPI_SR & AT91C_SPI_RDRF) == 1);    // Wait until the character can be sent
 391:mmc.c         ****     s_pSpi->SPI_RDR = data;                           // Send the data
 392:mmc.c         **** 
 393:mmc.c         ****     while((s_pSpi->SPI_SR & AT91C_SPI_TDRE) == 1);    // Wait for the transfer to complete
 394:mmc.c         ****     spib = s_pSpi->SPI_TDR;                // Get the data received
 395:mmc.c         ****     return spib;
 396:mmc.c         ****     */
 397:mmc.c         **** 
 398:mmc.c         ****     unsigned int spib;
 399:mmc.c         **** 
 400:mmc.c         ****     //while((s_pSpi->SPI_SR & AT91C_SPI_TDRE) == 0);      // Wait for the transfer to complete
 401:mmc.c         ****     while((s_pSpi->SPI_SR & AT91C_SPI_TXEMPTY) == 0);
 173              		.loc 1 401 0 174 0080 074B     		ldr	r3, .L27 175              		.loc 1 356 0 176 0082 0006     		lsl	r0, r0, #24 177              	.LVL4: 178              		.loc 1 401 0 179 0084 1A68     		ldr	r2, [r3] 180              		.loc 1 356 0 181              		@ lr needed for prologue 182              		.loc 1 356 0 183 0086 000E     		lsr	r0, r0, #24 184              	.LVL5: 185              	.L18: 186              		.loc 1 401 0 187 0088 1369     		ldr	r3, [r2, #16] 188 008a 9905     		lsl	r1, r3, #22 189 008c FCD5     		bpl	.L18 402:mmc.c         ****     s_pSpi->SPI_TDR = (data & 0xFFFF);    // Send the data
 190              		.loc 1 402 0 191 008e D060     		str	r0, [r2, #12] 192              	.L20: 403:mmc.c         **** 
 404:mmc.c         ****     while((s_pSpi->SPI_SR & AT91C_SPI_RDRF) == 0);      // Wait until the character can be sent
 193              		.loc 1 404 0 194 0090 1369     		ldr	r3, [r2, #16] 195 0092 D907     		lsl	r1, r3, #31 196 0094 FCD5     		bpl	.L20 405:mmc.c         ****     spib = ((s_pSpi->SPI_RDR) & 0xFFFF);                // Get the data received
 197              		.loc 1 405 0 198 0096 9068     		ldr	r0, [r2, #8] 199              	.LVL6: 200 0098 0006     		lsl	r0, r0, #24 201 009a 000E     		lsr	r0, r0, #24 406:mmc.c         ****     return spib;
 407:mmc.c         **** 
 408:mmc.c         **** }
 202              		.loc 1 408 0 203              		@ sp needed for prologue 204 009c 7047     		bx	lr 205              	.L28: 206 009e 0000     		.align	2 207              	.L27: 208 00a0 00000000 		.word	s_pSpi 209              	.LFE13: 211              		.align	2 212              		.global	mmcSendCmd 213              		.code 16 214              		.thumb_func 216              	mmcSendCmd: 217              	.LFB11: 218              		.loc 1 313 0 219 00a4 10B5     		push	{r4, lr} 220              	.LCFI0: 221              	.LVL7: 222 00a6 0006     		lsl	r0, r0, #24 223              	.LVL8: 224 00a8 82B0     		sub	sp, sp, #8 225              	.LCFI1: 226              	.LVL9: 227              		.loc 1 318 0 228 00aa 4023     		mov	r3, #64 229              		.loc 1 313 0 230 00ac 000E     		lsr	r0, r0, #24 231              	.LVL10: 232              		.loc 1 318 0 233 00ae 1843     		orr	r0, r0, r3 234              	.LVL11: 235 00b0 6B46     		mov	r3, sp 236              		.loc 1 313 0 237 00b2 1206     		lsl	r2, r2, #24 238              	.LVL12: 239              		.loc 1 318 0 240 00b4 0233     		add	r3, r3, #2 241 00b6 6C46     		mov	r4, sp 242 00b8 1870     		strb	r0, [r3] 243              		.loc 1 313 0 244 00ba 120E     		lsr	r2, r2, #24 245              	.LVL13: 246              		.loc 1 318 0 247 00bc 1820     		mov	r0, #24 248 00be 0334     		add	r4, r4, #3 249              	.L30: 250              		.loc 1 321 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -