/**
 ******************************************************************************
 * @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])++;
		}
	}
}


int main(void)
{
	prenosDat(100);

	// zapne interni vysokorychlostni oscilator
	RCC->CR |= RCC_CR_HSION;

	// cekej, dokud HSI neni pripraveny
	while (!(RCC->CR & RCC_CR_HSIRDY));

	prenosDat(100);

	// nastavi HSI jako zdroj hodinoveho signalu
	RCC->CFGR |= RCC_CFGR_SW_HSI;

	// cekej, dokud neni zdroj prepnuty
	while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI);

	prenosDat(700);

	// vydeli HSI 4x -> 4 MHz
	RCC->CR |= RCC_CR_HSIDIVEN;

	prenosDat(200);

	// zapne periferii nastaveni napajeni
	RCC->APB1ENR |= RCC_APB1ENR_PWREN;

	// nastavi napetovou uroven 3
	PWR->CR = (3 << PWR_CR_VOS_Pos);

	prenosDat(200);

	// delicka kmitoctu /2 -> systemovy kmitocet = 2 MHz
	RCC->CFGR = (RCC_CFGR_HPRE_DIV2 | (RCC->CFGR & ~(RCC_CFGR_HPRE_Msk)));

	prenosDat(100);

	// delicka kmitoctu /4 -> systemovy kmitocet = 1 MHz
	RCC->CFGR = (RCC_CFGR_HPRE_DIV4 | (RCC->CFGR & ~(RCC_CFGR_HPRE_Msk)));

	prenosDat(50);

	// vypne interni vicerychlostni oscilator
	RCC->CR &= ~RCC_CR_MSION;

	prenosDat(10000);
}
