Files

54 lines
1.2 KiB
C
Raw Permalink Normal View History

2016-10-07 23:44:50 +02:00
/*
* System.h
*
* Created on: 10.02.2013
* Author: skuser
*/
#ifndef SYSTEM_H
#define SYSTEM_H
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <stddef.h>
#include <stdbool.h>
#include "Common.h"
#define F_RTC 1000
#define SYSTEM_MILLISECONDS_TO_RTC_CYCLES(x) \
( (uint16_t) ( (double) F_RTC * x / 1E3 + 0.5) )
2019-11-15 12:10:19 +01:00
// Tick about 120ms
2016-10-07 23:44:50 +02:00
#define SYSTEM_TICK_WIDTH 7 /* Bits */
2019-11-15 12:10:19 +01:00
#define SYSTEM_TICK_PERIOD 106 /* (1<<7) */
2016-10-07 23:44:50 +02:00
#define SYSTEM_TICK_MS (SYSTEM_TICK_PERIOD)
#define SYSTEM_TICK_FREQ (1000 / SYSTEM_TICK_PERIOD)
#define SYSTEM_SMODE_PSAVE SLEEP_SMODE_PSAVE_gc
#define SYSTEM_SMODE_IDLE SLEEP_SMODE_IDLE_gc
/* Use GPIORE and GPIORF as global tick register */
#define SYSTEM_TICK_REGISTER (*((volatile uint16_t*) &GPIORE))
void SystemInit(void);
void SystemReset(void);
void SystemEnterBootloader(void);
void SystemStartUSBClock(void);
void SystemStopUSBClock(void);
void SystemInterruptInit(void);
2019-11-15 12:10:19 +01:00
bool SystemTick100ms(void);
2016-10-07 23:44:50 +02:00
2019-11-15 10:21:40 +01:00
INLINE void SystemTickClearFlag(void) {
while (RTC.STATUS & RTC_SYNCBUSY_bm)
;
RTC.INTFLAGS = RTC_COMPIF_bm;
}
2016-10-07 23:44:50 +02:00
INLINE uint16_t SystemGetSysTick(void) {
2017-11-07 15:53:23 +01:00
return SYSTEM_TICK_REGISTER | RTC.CNT;
2016-10-07 23:44:50 +02:00
}
#endif /* SYSTEM_H */