/**
 ******************************************************************************
 * @file           : main.c
 * @author         : Auto-generated by STM32CubeIDE
 * @brief          : Main program body
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under BSD 3-Clause license,
 * the "License"; You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                        opensource.org/licenses/BSD-3-Clause
 *
 ******************************************************************************
 */

#include "stm32l073xx.h"

#if !defined(__SOFT_FP__) && defined(__ARM_FP)
  #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif

#define VELIKOST_DAT 1000
uint32_t data1[VELIKOST_DAT];

void prenosDat(uint32_t pocetIteraci)
{
	uint32_t data2[VELIKOST_DAT];

	for(uint32_t x = 0U; x < pocetIteraci; x++)
	{
		for(uint32_t y = 0U; y < VELIKOST_DAT; y++)
		{
			data1[y] = (data2[y])++;
		}
	}
}

__attribute__((section("sram_funkce")))
void prenosDatSram(uint32_t pocetIteraci)
{
	uint32_t data2[VELIKOST_DAT];

	for(uint32_t x = 0U; x < pocetIteraci; x++)
	{
		for(uint32_t y = 0U; y < VELIKOST_DAT; y++)
		{
			data1[y] = (data2[y])++;
		}
	}
}


// externi promenne z linkeru
extern unsigned sram_funkce_zacatek, sram_funkce_konec,
				sram_funkce_adresa_rom;

int main(void)
{
	// ziskani adres bloku pameti
	volatile unsigned *src = &sram_funkce_adresa_rom;
	volatile unsigned *dest = &sram_funkce_zacatek;

	// presune funkci z ROM do RAM
	while (dest < &sram_funkce_konec) {
	  *dest = *src;
	  src++;
	  dest++;
	}

	// nastavi kmitocet vicerychlostniho oscilatoru na 4,194
	//RCC->ICSCR |= ((6 << RCC_ICSCR_MSIRANGE_Pos) & RCC_ICSCR_MSIRANGE_Msk);

	while(1)
	{
		prenosDat(1500);
		prenosDatSram(1500);
	}


	while(1);
}
