void clearMMCCard() { if (initMMC() == MMC_SUCCESS) // card found { //card_state |= 1; memset(&mmc_buffer,0,512); mmcReadRegister (10, 16); mmc_buffer[7]=0; /*Clear first 1000 blocks*/ int blockClearCnt; for (blockClearCnt = 0; blockClearCnt < 2048; blockClearCnt++) { memset(&mmc_buffer,'0',512); mmcWriteBlock(512 * blockClearCnt); } /* // Fill first Block (0) with 'A' memset(&mmc_buffer,'0',512); //set breakpoint and trace mmc_buffer contents mmcWriteBlock(0); // Fill second Block (1)-AbsAddr 512 with 'B' memset(&mmc_buffer,'1',512); mmcWriteBlock(512); // Read first Block back to buffer memset(&mmc_buffer,0x00,512); mmcReadBlock(0,512); // Read first Block back to buffer memset(&mmc_buffer,0x00,512); mmcReadBlock(512,512); */ } }
/**************************************************************************//** * \brief Read the card ID directly from the MMC card * * This function reads the flash card ID directly from the MMC register inside * the card. It includes some simple all 0/1 detection for faulty values. * * \param[out] cardID 16-byte buffer to store the card ID into * \retval 0 Card ID read successfully * \retval -1 Card ID could not be read * \retval -2 Card ID read as all 0's * \retval -3 Card ID read as all 1's *****************************************************************************/ int flashReadCardID(unsigned char *cardID) { unsigned int i; if(mmcReadRegister(MMC_SEND_CID, CARD_ID_LEN, cardID) == MMC_SUCCESS) { for(i = 0; i < CARD_ID_LEN; i++) { if(cardID[i] != 0) break; } if(i == CARD_ID_LEN) return -2; for(i = 0; i < CARD_ID_LEN; i++) { if(cardID[i] != 0xFF) break; } if(i == CARD_ID_LEN) return -3; return 0; } else return -1; }
//*-------------------------------------------------------------------------------------- //* Function Name : Main //* Object : Software entry point //* Input Parameters : none. //* Output Parameters : none. //*-------------------------------------------------------------------------------------- int main(void) { char data[MSG_SIZE]; unsigned int length; int stepCnt = 0; unsigned char str[10]; /**** System init ****/ //InitFrec(); Init_CP_WP(); //chek for CP and WP //CP - card present while(((AT91C_BASE_PIOA->PIO_PDSR) & BIT15)) { /*put your card present event here*/ } //WP - write protect //while(((AT91C_BASE_PIOA->PIO_PDSR) & BIT16)) { /*put your write protect event here*/ } if (initMMC() == MMC_SUCCESS) { //card_state |= 1; memset(&mmc_buffer,0,512); mmcReadRegister (10, 16); mmc_buffer[7]=0; } flashInit(); Init_PWM(); // Enable User Reset and set its minimal assertion to 960 us AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24); // Led init // First, enable the clock of the PIOB AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ; //* to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only. AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, OUTPUT_MASK ); //* Clear the LED's. /* AT91F_PIO_SetOutput( AT91C_BASE_PIOA, OUTPUT_MASK ); AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, OUTPUT_MASK ); */ // Init USB device AT91F_USB_Open(); AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, OUTPUT_MASK ); // Init USB device // Wait for the end of enumeration setForce(40000); int pCDCEnablingCounter = 0; while (!pCDC.IsConfigured(&pCDC) && pCDCEnablingCounter < 2500000){ pCDCEnablingCounter++; }; if (pCDCEnablingCounter < 2500000) { CDC = 1; } setForce(0); // Set Usart in interrupt //Usart_init(); //Read and set settings memcpy(settings, OUR_FLASH_ADDR, 128); int i;memset(&mmc_buffer, 0x00, 512); int j; char *settingsBlocks[50]; char settingsDelim[] = "~"; char *settingsParts = strtok( settings, settingsDelim ); i = 0; while( settingsParts != NULL ) { settingsBlocks[i++] = settingsParts; settingsParts = strtok( NULL, settingsDelim ); } for (j = 0; j < i; j++) { parseSettings(settingsBlocks[j]); } InitADC(); Init_PWM(); AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SW1_MASK); AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SW2_MASK); AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_GREEN); AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_YELLOW); setForce(0); //startBlinking(250000); /**** MMC CARD ****/ init_extint(); while (1) { cnt++; if (cnt > 50000) { cnt = 0; printTrace("COUNTER RESET\n"); } } }