You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
4.1 KiB
84 lines
4.1 KiB
//#############################################################################################################################################################################################################
|
|
#include "SYSTEM.h"
|
|
#include "config.h"
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
volatile uint32_t SystemSystickCounter;
|
|
|
|
uint32_t System_GetSysTick(void)
|
|
{
|
|
cli();
|
|
uint32_t SystemSysTick_Temp = SystemSystickCounter;
|
|
sei();
|
|
return SystemSysTick_Temp;
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
uint32_t HAL_GetTick(void) // redefine _weak HAL function For HAL Inits
|
|
{
|
|
cli();
|
|
uint32_t SystemSysTick_Temp = SystemSystickCounter;
|
|
sei();
|
|
return SystemSysTick_Temp;
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
uint32_t System_GetSysTickDifference(uint32_t TimeInstance)
|
|
{
|
|
cli();
|
|
uint32_t SystemSysTick_Temp = SystemSystickCounter;
|
|
sei();
|
|
if (TimeInstance<=SystemSysTick_Temp )
|
|
{
|
|
return (uint32_t)(SystemSysTick_Temp-TimeInstance);
|
|
}
|
|
else
|
|
{
|
|
return (uint32_t)(0xFFFFFFFF-TimeInstance+SystemSysTick_Temp);
|
|
}
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
void System_SWReboot(void)
|
|
{
|
|
cli();
|
|
wdt_enable(WDTO_15MS);
|
|
while(1); //Dumb reset
|
|
}
|
|
//#############################################################################################################################################################################################################
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
void System_InitSysTick(void)
|
|
{
|
|
SystemSystickCounter=0;
|
|
TCNT0=0xFF-250; // 1 ms
|
|
TCCR0B=0; // no clock
|
|
TIMSK0=0; // Overflow Interrupt Disable
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
ISR(TIMER0_OVF_vect) // 1ms timer0 interrupt
|
|
{
|
|
TCNT0=0xFF-250; // 1 ms
|
|
if (SystemSystickCounter==0xFFFFFFFF) SystemSystickCounter=0;
|
|
else SystemSystickCounter++;
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
void System_SystickTimerStart(void)
|
|
{
|
|
SystemSystickCounter=0;
|
|
TCNT0=0xFF-250; // 1 ms
|
|
TCCR0B=3; // clkI/O/64 (from prescaller)
|
|
TIMSK0=1<<TOIE0; // Overflow Interrupt Enable
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
void System_SystickTimerStop(void)
|
|
{
|
|
TCCR0B=0; // no clock
|
|
TIMSK0=0; // Overflow Interrupt Disable
|
|
}
|
|
void readDeviceData(FLASH_DATABLOCK* data, FLASH_ADDR_T addr) {
|
|
uint8_t* dst = (uint8_t*)data;
|
|
const FLASH_ADDR_T src = (addr*2);
|
|
|
|
for (size_t i = 0; i < sizeof(FLASH_DATABLOCK); i++) {
|
|
dst[i] = pgm_read_byte_far(src + i);
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
//#############################################################################################################################################################################################################
|