diff options
| author | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-03-03 18:39:09 +0100 |
|---|---|---|
| committer | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-03-03 19:40:00 +0100 |
| commit | 792e22676786a577b2edc0ed0ed78e51c5b38245 (patch) | |
| tree | 3a5b1092af322003be3189bf6d58f362dcfe1dca /src/Interrupts.c | |
| parent | 62adc2edd17cbd39272715d29d1b4c8650ef7dde (diff) | |
| download | opensend-792e22676786a577b2edc0ed0ed78e51c5b38245.tar.gz | |
Refactoring
Diffstat (limited to 'src/Interrupts.c')
| -rw-r--r-- | src/Interrupts.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/Interrupts.c b/src/Interrupts.c new file mode 100644 index 0000000..ce407cf --- /dev/null +++ b/src/Interrupts.c @@ -0,0 +1,126 @@ +/*******************************************************************//** +* +* \file Interrupts.c +* +* \author Xavier Del Campo +* +* \brief Implementation of Interrupts module. +* +************************************************************************/ + +/* ************************************* + * Includes + * *************************************/ + +#include "Interrupts.h" +#include <psx.h> +#include <stdint.h> +#include <stddef.h> + +/* ************************************* + * Defines + * *************************************/ + +#ifndef I_MASK +/*******************************************************************//** +* +* \brief Interrupt mask register. +* +* According to NoCash specifications, I_MASK bits are +* structured as follows: +* +* \arg Bit 0 IRQ0 VBLANK (PAL=50Hz, NTSC=60Hz) +* \arg Bit 1 IRQ1 GPU +* \arg Bit 2 IRQ2 CDROM +* \arg Bit 3 IRQ3 DMA +* \arg Bit 4 IRQ4 TMR0 Timer 0 aka Root Counter 0 +* \arg Bit 5 IRQ5 TMR1 Timer 1 aka Root Counter 1 +* \arg Bit 6 IRQ6 TMR2 Timer 2 aka Root Counter 2 +* \arg Bit 7 IRQ7 Controller and Memory Card +* \arg Bit 8 IRQ8 SIO +* \arg Bit 9 IRQ9 SPU +* \arg Bit 10 IRQ10 Controller - Lightpen Interrupt +* \arg Bits 11-15 Not used (always zero) +* \arg Bits 16-31 Garbage +* +************************************************************************/ +#define I_MASK (*(volatile unsigned int*)0x1F801074) +#endif /* I_MASK */ + +/* ************************************* + * Types definition + * *************************************/ + +/* ************************************* + * Global variables definition + * *************************************/ + +/* ************************************* + * Local variables definition + * *************************************/ + +/* ************************************* + * Local prototypes declaration + * *************************************/ + +/* ************************************* + * Functions definition + * *************************************/ + +/*******************************************************************//** +* +* \brief Enables an interrupt source given by intSource. +* +* \param intSource +* HW interrupt source. +* +* \see \ref InterruptSource for a list of possible HW interrupt causes. +* +************************************************************************/ +void InterruptsEnableInt(const enum InterruptSource intSource) +{ + if (intSource < MAX_INTERRUPT_SOURCES) + { + /* Disable interrupts while I_MASK is modified. */ + EnterCriticalSection(); + + /* Set bit for selected interrupt source. */ + I_MASK |= 1 << intSource; + + /* Re-enable interrupts. */ + ExitCriticalSection(); + } + else + { + /* Invalid selected InterruptSource instance. Exit. */ + } +} + +/*******************************************************************//** +* +* \brief Disables an interrupt source given by intSource. +* +* \param intSource +* HW interrupt source. +* +* \see \ref InterruptSource for a list of possible HW interrupt causes. +* +************************************************************************/ +void InterruptsDisableInt(const enum InterruptSource intSource) +{ + if (intSource < MAX_INTERRUPT_SOURCES) + { + /* Disable interrupts while I_MASK is modified. */ + EnterCriticalSection(); + + /* Remove bit for selected interrupt source. */ + I_MASK &= ~(1 << intSource); + + /* Re-enable interrupts while I_MASK is modified. */ + ExitCriticalSection(); + } + else + { + /* Invalid selected InterruptSource instance. Exit. */ + } +} |
