diff options
| author | XaviDCR92 <xavi.dcr@gmail.com> | 2017-07-24 22:39:16 +0200 |
|---|---|---|
| committer | XaviDCR92 <xavi.dcr@gmail.com> | 2017-07-24 22:39:16 +0200 |
| commit | f071adf8f590bb2d2ceee7d93bea120c9d754788 (patch) | |
| tree | e5cd62882fed370bc2d0f75ca6f10fe4b65d5940 /Source/System.c | |
| parent | 41d8caba3b3e7611d657c0ee4cecd1cdbdf0c814 (diff) | |
* Some improvements made to improve peformance and stability.
- Removed Pad module (useless).
* Some functions removed from System and Gfx.
Diffstat (limited to 'Source/System.c')
| -rw-r--r-- | Source/System.c | 406 |
1 files changed, 6 insertions, 400 deletions
diff --git a/Source/System.c b/Source/System.c index e636925..852fea1 100644 --- a/Source/System.c +++ b/Source/System.c @@ -13,13 +13,12 @@ #define END_STACK_PATTERN (uint32_t) 0x18022015 #define BEGIN_STACK_ADDRESS (uint32_t*) 0x801FFF00 #define STACK_SIZE 0x1000 -#define I_MASK (*(unsigned int*)0x1F801074) +#define I_MASK (*(volatile unsigned int*)0x1F801074) /* ************************************* * Local Prototypes * *************************************/ - -static void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step); + static void SystemSetStackPattern(void); /* ************************************* @@ -36,14 +35,8 @@ static bool rand_seed; static volatile bool refresh_needed; //Timers static bool one_second_timer; -static bool hundred_ms_timer; -static bool five_hundred_ms_timer; -//Emergency mode flag. Toggled on pad connected/disconnected -static bool emergency_mode; //Critical section is entered (i.e.: when accessing fopen() or other BIOS functions static volatile bool system_busy; -//Timer array. -static TYPE_TIMER timer_array[SYSTEM_MAX_TIMERS]; /* ******************************************************************* * @@ -77,10 +70,6 @@ void SystemInit(void) #endif //_PAL_MODE_ //SPU init SsInit(); - //Reset all user-handled timers - SystemResetTimers(); - //Pads init - PadInit(); //Set Drawing Environment GfxInitDrawEnv(); //Set Display Environment @@ -251,92 +240,7 @@ void SystemDisableScreenRefresh(void) bool System1SecondTick(void) { - return one_second_timer; -} - -/* ******************************************************************* - * - * @name: bool System100msTick(void) - * - * @author: Xavier Del Campo - * - * @return: bool variable with a 1-cycle-length pulse that gets - * set every 100 milliseconds. - * - * *******************************************************************/ - -bool System100msTick(void) -{ - return hundred_ms_timer; -} - -/* ******************************************************************* - * - * @name bool System500msTick(void) - * - * @author: Xavier Del Campo - * - * @return: bool variable with a 1-cycle-length pulse that gets - * set every 500 milliseconds. - * - * *******************************************************************/ - -bool System500msTick(void) -{ - return five_hundred_ms_timer; -} - -/* ******************************************************************* - * - * @name void SystemRunTimers(void) - * - * @author: Xavier Del Campo - * - * @brief: general timer handler - * - * @remarks: 1 second, 500 ms and 100 ms ticks get updated here. - * - * *******************************************************************/ - -void SystemRunTimers(void) -{ - static uint64_t last_one_second_tick; - static uint64_t last_100_ms_tick; - static uint64_t last_500_ms_tick; - - SystemCheckTimer(&one_second_timer, &last_one_second_tick, REFRESH_FREQUENCY); - -#ifdef _PAL_MODE_ - SystemCheckTimer(&hundred_ms_timer, &last_100_ms_tick, 2 /* 2 * 50 ms = 100 ms */); - SystemCheckTimer(&five_hundred_ms_timer, &last_500_ms_tick, 10 /* 10 * 50 ms = 500 ms */); -#else // _PAL_MODE_ - SystemCheckTimer(&hundred_ms_timer, &last_100_ms_tick, 3); -#endif // _PAL_MODE_ - -} - -/* ******************************************************************************** - * - * @name void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step) - * - * @author: Xavier Del Campo - * - * @brief: Checks if needed time step has been elapsed. If true, flag gets set. - * - * *******************************************************************************/ - -void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step) -{ - if(*timer == true) - { - *timer = false; - } - - if(global_timer >= (*last_timer + step) ) - { - *timer = true; - *last_timer = global_timer; - } + return !(global_timer % REFRESH_FREQUENCY); } /* **************************************************************************************** @@ -461,23 +365,6 @@ void SystemClearBuffer(void) /* ****************************************************************** * - * @name void SystemWaitCycles(uint32_t cycles) - * - * @author: Xavier Del Campo - * - * @return: halts program execution for n-"cycles" - * - * *****************************************************************/ - -void SystemWaitCycles(uint32_t cycles) -{ - uint64_t currentTime = global_timer; - - while(global_timer < (currentTime + cycles) ); -} - -/* ****************************************************************** - * * @name uint32_t SystemRand(uint32_t min, uint32_t max) * * @author: Xavier Del Campo @@ -496,38 +383,6 @@ uint32_t SystemRand(uint32_t min, uint32_t max) /* *********************************************************************** * - * @name void SystemSetEmergencyMode(bool value) - * - * @author: Xavier Del Campo - * - * @brief: Sets emergency mode flag. - * - * @remarks: emergency mode is set once that a controller is unplugged. - * - * ***********************************************************************/ - -void SystemSetEmergencyMode(bool value) -{ - emergency_mode = value; -} - -/* *********************************************************************** - * - * @name bool SystemGetEmergencyMode(void) - * - * @author: Xavier Del Campo - * - * @return: returns emergency mode flag. - * - * ***********************************************************************/ - -bool SystemGetEmergencyMode(void) -{ - return emergency_mode; -} - -/* *********************************************************************** - * * @name volatile bool SystemIsBusy(void) * * @author: Xavier Del Campo @@ -541,211 +396,6 @@ volatile bool SystemIsBusy(void) return system_busy; } -/* **************************************************************************** - * - * @name bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz) - * - * @author: Xavier Del Campo - * - * @brief: checks if a certain value is contained in a buffer with size "sz". - * - * @return: true if value is contained inside buffer, false otherwise. - * - * ****************************************************************************/ - -bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz) -{ - size_t i = 0; - - for(i = 0; i < sz; i++) - { - if(buffer[i] == value) - { - return true; - } - } - - return false; -} - -/* **************************************************************************** - * - * @name bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz) - * - * @author: Xavier Del Campo - * - * @brief: checks if a certain value is contained in a buffer with size "sz". - * Variant for u16 variables. - * - * @return: true if value is contained inside buffer, false otherwise. - * - * ****************************************************************************/ - -bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz) -{ - size_t i = 0; - - for(i = 0; i < sz; i++) - { - if(buffer[i] == value) - { - return true; - } - } - - return false; -} - -/* ******************************************************************************************** - * - * @name TYPE_TIMER* SystemCreateTimer(uint32_t t, bool rf, void (*timer_callback)(void) ) - * - * @author: Xavier Del Campo - * - * @brief: fills a TYPE_TIMER structure with input parameters - * - * @param: uint32_t t: - * Timeout value (1 unit = 10 ms) - * bool rf: - * Repeat flag - * void (*timer_callback)(void) - * Function to be called on timeout - * - * @return: pointer to TYPE_TIMER structure if filled correctly, NULL pointer otherwise. - * - * ********************************************************************************************/ - -TYPE_TIMER* SystemCreateTimer(uint32_t t, bool rf, void (*timer_callback)(void) ) -{ - bool success = false; - uint8_t i; - - if(t == 0) - { - dprintf("Cannot create timer with time == 0!\n"); - return NULL; - } - - for(i = 0; i < SYSTEM_MAX_TIMERS; i++) - { - if(timer_array[i].busy == false) - { - timer_array[i].Timeout_Callback = timer_callback; - timer_array[i].time = t; - timer_array[i].orig_time = t; - timer_array[i].repeat_flag = rf; - timer_array[i].busy = true; - success = true; - break; - } - } - - if(success == false) - { - dprintf("Could not find any free timer!\n"); - return NULL; - } - - return &timer_array[i]; -} - -/* ******************************************* - * - * @name void SystemResetTimers(void) - * - * @author: Xavier Del Campo - * - * @brief: reportedly, removes all timers. - * - * *******************************************/ - -void SystemResetTimers(void) -{ - uint8_t i; - - for(i = 0; i < SYSTEM_MAX_TIMERS; i++) - { - SystemTimerRemove(&timer_array[i]); - } -} - -/* ***************************************************** - * - * @name void SystemUserTimersHandler(void) - * - * @author: Xavier Del Campo - * - * @brief: reportedly, handles all available timers. - * - * @remarks: calls callback on timeout. - * - * *****************************************************/ - -void SystemUserTimersHandler(void) -{ - uint8_t i; - - for(i = 0; i < SYSTEM_MAX_TIMERS; i++) - { - if(timer_array[i].busy == true) - { - if(System100msTick() == true) - { - timer_array[i].time--; - - if(timer_array[i].time == 0) - { - timer_array[i].Timeout_Callback(); - - if(timer_array[i].repeat_flag == true) - { - timer_array[i].time = timer_array[i].orig_time; - } - } - } - } - } -} - -/* ********************************************************************* - * - * @name void SystemUserTimersHandler(void) - * - * @author: Xavier Del Campo - * - * @brief: sets time left for TYPE_TIMER instance to initial value. - * - * @remarks: specially used when TYPE_TIMER.rf is enabled. - * - * *********************************************************************/ - -void SystemTimerRestart(TYPE_TIMER* timer) -{ - timer->time = timer->orig_time; -} - -/* ********************************************************************* - * - * @name void SystemTimerRemove(TYPE_TIMER* timer) - * - * @author: Xavier Del Campo - * - * @brief: Resets timer parameters to default values so timer instance - * can be recycled. - * - * @remarks: - * - * *********************************************************************/ - -void SystemTimerRemove(TYPE_TIMER* timer) -{ - timer->time = 0; - timer->orig_time = 0; - timer->Timeout_Callback = NULL; - timer->busy = false; - timer->repeat_flag = false; -} - bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz) { size_t i; @@ -826,62 +476,18 @@ int32_t SystemIndexOfStringArray(char* str, char** array) return -1; } - -int32_t SystemIndexOf_U16(uint16_t value, uint16_t* array, uint32_t sz) -{ - int32_t i; - - for(i = 0; i < sz; i++) - { - if(value == array[i]) - { - return i; - } - } - - return -1; -} - -int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t sz) -{ - int32_t i; - - for(i = from; i < sz; i++) - { - if(value == array[i]) - { - return i; - } - } - - return -1; -} - void SystemCyclicHandler(void) -{ - if(UpdatePads() == false) - { - SystemSetEmergencyMode(true); - } - else - { - SystemSetEmergencyMode(false); - } - - SystemRunTimers(); - - SystemUserTimersHandler(); - +{ SystemDisableScreenRefresh(); SystemCheckStack(); } void SystemDisableVBlankInterrupt(void) { - I_MASK &= ~(0x0001); + I_MASK &= ~(0x00000001); } void SystemEnableVBlankInterrupt(void) { - I_MASK |= (0x0001); + I_MASK |= (0x00000001); } |
