/** @file flash.c * Module handling flash memory interface registers. * * The module provides functions to configure the flash and perform read and * writes */ //--includes-------------------------------------------------------------------- #include "flash.h" #include "flash_regs.h" //--local definitions----------------------------------------------------------- //--local variables------------------------------------------------------------- static volatile struct FLASH* regs = (struct FLASH*)FLASH_BASE_ADDRESS; //--public functions------------------------------------------------------------ /** * Sets the correct latency to compensate the core's clock speed. Latency must * never be too low or the system will crash due to errors when accessing the * flash, hence the warning in the header */ void flash_configure(enum FlashPreset preset) { //restore default configuration regs->ACR.word &= ~0x3f; regs->ACR.word |= 0x30; //apply new configuration switch (preset) { case FLASH_PRESET_LOW_CLOCK_SPEED: reg_set(regs->ACR, FLASH_ACR_HLFCYA); //half cycle for power saving break; case FLASH_PRESET_MEDIUM_CLOCK_SPEED: reg_reset(regs->ACR, FLASH_ACR_LATENCY); reg_write(regs->ACR, FLASH_ACR_LATENCY, 0x1); break; case FLASH_PRESET_HIGH_CLOCK_SPEED: reg_reset(regs->ACR, FLASH_ACR_LATENCY); reg_write(regs->ACR, FLASH_ACR_LATENCY, 0x2); break; default: break; } } //--local functions-------------------------------------------------------------