SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
On the input side, the CIM enables channels on a channel-by-channel basis (in the REQMASK register); unused channels may be masked to prevent spurious interrupts. Each interrupt channel can be designated to send either an FIQ or IRQ request to the CPU (in the FIQPR register).
Interrupt Mask Register REQMASK and FIQ/IRQ Program Control Register FIRQPR are writeable in privilege mode only. A write in user mode to these Registers causes a peripheral illegal access exception. One way of setting the CPU in privilege mode is through software interrupt. A software interrupt is a synchronous exception generated by the execution of a particular instruction. A C application can invoke a software interrupt by associating a software interrupt number with a function name through use of the SWI_ALIAS pragma and then calling the software interrupt as if it were a function. A C code example of using software interrupt is shown below:
#pragma SWI_ALIAS (write_firqpr, 8)
void write_firqpr(unsigned long value);
#pragma SWI_ALIAS (write_reqmask, 9)
void write_reqmask(unsigned long value);
#pragma INTERRUPT(software_interrupt,SWI)
void software_interrupt(Uint32 arg1, Uint32 arg2, Uint32 arg3, Uint8 swi_number)
{
//make sure interrupts are disabled
asm(" MRS r3, cpsr "); // get psr
asm(" ORR r3, r3, #0xc0 "); // set interrupt disables
asm(" MSR cpsr, r3"); // restore psr
asm(" LDRB R3,[R14,#-1]"); // get swi number into R3 as fourth operand
switch (swi_number) // handle flash write/erase and ROM backdoor first
{
...
case 8: //write to fiq/irq program_control_register
CimRegs.FIRQPR.all = arg1;
return;
case 9: //write to fiq/irq program_control_register
CimRegs.REQMASK.all = arg1;
return;
...
default:
break;
}
}
The INTERRUPT pragma enables handling interrupts directly with C code. This pragma specifies that the function to which it is applied is an interrupt. The type of interrupt is specified by the pragma. The software interrupt will change the CPU to privilege mode. The SWI_ALIAS pragma tells the function write_friqpr() and write_reqmask() are software interrupts. Calls to these functions are compiled as software interrupts. A C code example of calling these functions is shown below.
write_firqpr(0x0C000000); //make them all irqs except dpwm4 and dpwm3.
write_reqmask(0x0C010000); //enable only pwm1cmp, dpwm3 and dpwm4