#ifndef __SYSTEM_HEADER__ #define __SYSTEM_HEADER__ #ifdef __cplusplus extern "C" { #endif /* ************************************** * Includes * * **************************************/ #include "Global_Inc.h" /* ************************************** * Defines * * **************************************/ #define TIMEBASE_1_SECOND 1 #define TIMEBASE_1_MINUTE TIMEBASE_1_SECOND * 60 /* ************************************** * Structs and enums * * **************************************/ typedef struct t_Timer { uint32_t time; uint32_t orig_time; bool repeat_flag; bool busy; void (*Timeout_Callback)(void); }TYPE_TIMER; typedef struct t_CollisionBlock { uint16_t x; uint16_t y; uint8_t w; uint8_t h; }TYPE_COLLISION_BLOCK; /* ************************************** * Global Prototypes * * **************************************/ // Calls init routines void SystemInit(void); // Calls srand() using current global_timer value as seed void SystemSetRandSeed(void); // Tells whether srand() has been called using a pseudo-random value bool SystemIsRandSeedSet(void); // Stops program flow during X cycles void SystemWaitCycles(uint32_t cycles); // To be called from GfxDrawScene after each cycle void SystemRunTimers(void); // 1 cycle-length flag with a frequency of 1 Hz bool System1SecondTick(void); // 1 cycle-length flag with a frequency of 10 Hz bool System100msTick(void); // Returns random value between given minimum and maximum values uint32_t SystemRand(uint32_t min, uint32_t max); // Increases global timer by 1 step void SystemIncreaseGlobalTimer(void); // (Experimental) uint64_t SystemGetGlobalTimer(void); // Returns whether critical section of code is being entered bool SystemIsBusy(void); // Returns whether indicated value is contained inside buffer bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz); // Overload for uint16_t bool SystemContains_u16(uint16_t value, uint16_t * buffer, size_t sz); // Creates a timer instance wiht a determined value and associates it to a callback // Once time expires, callback is automatically called right after GfxDrawScene(). TYPE_TIMER * SystemCreateTimer(uint32_t seconds, bool rf, void (*timer_callback)(void) ); // Reportedly, sets all timer data to zero. void SystemResetTimers(void); // To be called every cycle (i.e.: inside GfxDrawScene() ). void SystemUserTimersHandler(void); // Sets timer remaining time to initial value. void SystemTimerRestart(TYPE_TIMER * timer); // Flushes a timer pointed to by timer. void SystemTimerRemove(TYPE_TIMER * timer); // Compares two arrays of unsigned short type. bool SystemArrayCompare(unsigned short * arr1, unsigned short * arr2, size_t sz); // Checks collision of two objects bool SystemCollisionCheck(TYPE_COLLISION_BLOCK c1, TYPE_COLLISION_BLOCK c2); /* ************************************** * Global Variables * * **************************************/ #ifdef __cplusplus } #endif #endif //__SYSTEM_HEADER__