How to write isr function

cisrmicrocontroller

I used uart receive using polling method. But same I want to use in ISR. How can I write a ISR function. For example if I am using CC2541. In the manual I have seen that Vector Table for Port 1(where UART is connected) is P1INT_VECTOR. But I don't know how to write a function. After some search I found many people used a function like below.

#pragma vector = P1INT_VECTOR
__interrupt void p0_ISR(void)
{
    /*Some statement*/
}

But I don't know what is p0_ISR. I didn't see this in the manual or datasheet. This interrupt function has any prototype?. Can some one help me to understand this. So that I can implement to every microcontroller not only CC2541

Best Answer

Interrupts do not take arguments or return values. Basically, it's just a bare subroutine that gets 'called' by the hardware. An interrupt signal into the core generates the equivalent of a 'call' instruction wherever the processor happens to be executing code, storing the current address and then jumping directly into the ISR.

Generally a UART interrupt will grab a byte out of the UART receive register and then store it in a global receive buffer. You'll need to be careful with how you access the global receive buffer outside of the ISR as it is possible for the ISR to be called WHILE you are updating receive buffer metadata (pointers, counters, etc). You need to write code that can deal with this properly, either by carefully making sure the ISR cannot trample over the read routine or by disabling interrupts briefly to prevent the ISR from running at critical moments. There are standard concurrent programming techniques that can be used here.

There are a couple of (somewhat complex) interrupt-driven UART drivers for both transmit and receive in this repository: https://github.com/alexforencich/templates