# GPIO Interrupt service routine based task handling in MSP432

**URL:** <https://forums.freertos.org/t/gpio-interrupt-service-routine-based-task-handling-in-msp432/7886>\
**Category:** Kernel\
**Created:** [May 30, 2019, 5:48am UTC](https://forums.freertos.org/t/gpio-interrupt-service-routine-based-task-handling-in-msp432/7886 "2019-05-30T05:48:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 30, 2019, 5:48am UTC](https://forums.freertos.org/t/gpio-interrupt-service-routine-based-task-handling-in-msp432/7886/1 "2019-05-30T05:48:13Z")

</div>

**[basugouda](https://sourceforge.net/u/basugouda/)** wrote on [Thursday, May 30, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/4fcbb75e27/#340d):

Hi  
I am trying to use a simple task from a gpio interrupt handler using MSP432  
I am using the semaphore for executing

The problem is once the interrupt occurs it is jumping to the idle state by dissabling the interrupts by itself

May I know what could be the problem I am litrally stuck here.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 30, 2019, 4:09pm UTC](https://forums.freertos.org/t/gpio-interrupt-service-routine-based-task-handling-in-msp432/7886/2 "2019-05-30T16:09:16Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, May 30, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/4fcbb75e27/#340d/d076):

I think I understand the first part of this, but am unsure of the second  
part:

> I am trying to use a simple task from a gpio interrupt handler using MSP432  
> I am using the semaphore for executing

So you are using a semaphore to unblock a task from an interrupt service  
routine? If so, please show the code.

> The problem is once the interrupt occurs it is jumping to the idle state  
> by dissabling the interrupts by itself

This is the bit I’m not sure about. By idle state, do you mean the  
interrupt service routine is not returning to the task you unblocked  
with the semaphore, but returning to the idle task instead? If so, does  
it then run the task you unblocked with the semaphore after the next  
tick interrupt? If that is the case then it is probably a result of the  
way the interrupt is using the API - and showing the code (as requested  
above) will let me see that.

I’m not sure what you mean when you say ‘by disabling the interrupts by  
itself’.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 31, 2019, 8:22am UTC](https://forums.freertos.org/t/gpio-interrupt-service-routine-based-task-handling-in-msp432/7886/3 "2019-05-31T08:22:40Z")

</div>

**[basugouda](https://sourceforge.net/u/basugouda/)** wrote on [Friday, May 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/4fcbb75e27/#a0cc):

Thank you for your reply

## I was trying to unblock two tasks which are using one semaphore, Both the tasks are ISR based. I am not sure whether this is right way to do using a single semaphore for two ISR based tasks.

* * *

void uart\_data(void \*p){

```
	while(1){
			xSemaphoreTake( xBinarySemaphore,portMAX_DELAY );
		  MAP_UART_transmitData(EUSCI_A0_BASE, MAP_UART_receiveData(EUSCI_A0_BASE));
			
		}

```

}

void led\_t(void \*p){

```
	while(1){
		 xSemaphoreTake( xBinarySemaphore,portMAX_DELAY );
		 MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2,GPIO_PIN1);
		 
		}

```

}

void EUSCIA0\_IRQHandler(void)  
{  
BaseType\_t checkIfYieldRequired = pdFALSE;  
uint32\_t status = MAP\_UART\_getEnabledInterruptStatus(EUSCI\_A0\_BASE);  
MAP\_UART\_clearInterruptFlag(EUSCI\_A0\_BASE, status);

```
if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)
{
	xSemaphoreGiveFromISR( xBinarySemaphore, &checkIfYieldRequired );
	portYIELD_FROM_ISR(checkIfYieldRequired);
		}

```

}

void PORT1\_IRQHandler(void)  
{  
BaseType\_t checkIfYieldRequired1 = pdFALSE;  
uint32\_t status = MAP\_GPIO\_getEnabledInterruptStatus(GPIO\_PORT\_P1);  
MAP\_GPIO\_clearInterruptFlag(GPIO\_PORT\_P1, status);

```
if(status & GPIO_PIN1)
{
	xSemaphoreGiveFromISR( xBinarySemaphore, &checkIfYieldRequired1 );
	portYIELD_FROM_ISR(checkIfYieldRequired1);
		}

```

}  
int main(void){  
//xBinarySemaphore=xSemaphoreCreateBinary();  
xBinarySemaphore=xSemaphoreCreateCounting;  
hw\_init();  
xTaskCreate(toggle\_led\_red,“toggle\_led”,20,(void \*)0,tskIDLE\_PRIORITY,&led\_red);  
if(xBinarySemaphore!=NULL){  
xTaskCreate(uart\_data,“UART”,200,(void \*)0,tskIDLE\_PRIORITY,&UART);  
xTaskCreate(led\_t,“LED”,200,(void \*)0,tskIDLE\_PRIORITY,&led);  
vTaskStartScheduler();  
}

```
while(1){}

```

}

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 31, 2019, 10:46am UTC](https://forums.freertos.org/t/gpio-interrupt-service-routine-based-task-handling-in-msp432/7886/4 "2019-05-31T10:46:37Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Friday, May 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/4fcbb75e27/#9cd2):

One comment, by having two tasks wait on the same semaphore, only one of them will get it when the ISR gives it (If they have different priorities, it will be the one with the higher priority, with the same priority as you have in your test, it isn’t specified which one).

You also have two ISRs set the same semaphore, so the task that is woken isn’t based on which interrupt occured. My first guess is that you want to create two different semaphores, one for the GPIO, and one for the UART.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 3, 2019, 9:26am UTC](https://forums.freertos.org/t/gpio-interrupt-service-routine-based-task-handling-in-msp432/7886/5 "2019-06-03T09:26:47Z")

</div>

**[basugouda](https://sourceforge.net/u/basugouda/)** wrote on [Monday, June 03, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/4fcbb75e27/#f880):

Thank you for your response I was trying the exact thing which you are telling using a single semaphore to two ISR and found that we got to use two semaphores.

Thanks you for your response
