Example #1
0
void configStart() {
	// Load the config from EEPROM
	readConfigFromEEPROM();

	// Check for config file on SD card
	FRESULT fr = f_stat("config.txt", NULL);
	switch (fr) {
	case FR_OK:
		// Config file exists
		break;
	case FR_NO_FILE:
		// Config file does not exist, create default
		readConfigDefault();
		writeConfigToFile();
		break;
	default:
		// Unknown file read error
		error(ERROR_READ_CONFIG);
	}

	fr = f_stat(converterFn, NULL);
	switch (fr) {
	case FR_OK:
		// Converter file exists
		break;
	case FR_NO_FILE:
		// Create exe file from binary
		writeConverterToFile();
		break;
	default:
		// Unknown file read error
		f_unlink(converterFn);
		error(ERROR_READ_CONFIG);
	}

	fr = f_stat(userGuideFn, NULL);
	switch (fr) {
	case FR_OK:
		// User Guide file exists
		break;
	case FR_NO_FILE:
		writeUserGuideToFile();
		break;
	default:
		// Unknown file read error
		f_unlink(userGuideFn);
		error(ERROR_READ_CONFIG);
	}

	// Read config file from card
	readConfigFromFile();

	// Write config back to card
	writeConfigToFile();

	// Update the config back to EEPROM
	writeConfigToEEPROM();
}
Example #2
0
/*
 * initializes sd card and reads config file
 */
void initSDCard()
{
	int retVal=0;
	int timeout = 0;
	DWORD P1;

//	if(sdcInitDone) //init procedure already started
//		return; // Thread wird sowieso beendet

	curFileID=-99;

	//Set output Pins for LEDs
	DDR03_D7 = 1; //Read (Pin 16)
	DDR03_D6 = 1; //Write (Pin 15)
	PDR03_P7 = 1;
	PDR03_P6 = 1;


	mmc_initPorts();

//	Seg_Hex(0xC);

	//wait for card to be inserted
	while(mmc_getCardStatus() > 0) //it is 0 if we have a card
	{
		//return after 10 sec
		if(timeout > 20)
			return;
#ifdef SDCARD_DEBUG
		printf("waiting for card.. \r\n");
#endif
		os_wait(500);
		timeout++;
	}

//	Seg_Hex(0xF);

	os_wait(200);

	//initialize card
	retVal=mmc_init();

	os_wait(200);

	//mount FAT file system
	P1=0;
	f_mount((BYTE)P1, &fatfs[P1]);

	if(curFileID==-99) //has not been set
		SetCurrentFileID(1,1);

	sdcInitDone=1;
	//read configuration file from sd card
	readConfigFromFile();
	Seg_Hex(0x00);
}