# \[PIC32\] using ISR before the scheduler start

**URL:** <https://forums.freertos.org/t/pic32-using-isr-before-the-scheduler-start/1263>\
**Category:** Kernel\
**Created:** [February 16, 2012, 3:12pm UTC](https://forums.freertos.org/t/pic32-using-isr-before-the-scheduler-start/1263 "2012-02-16T15:12:30Z")\
**Posts on this page:** 4\
**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:** [February 16, 2012, 3:12pm UTC](https://forums.freertos.org/t/pic32-using-isr-before-the-scheduler-start/1263/1 "2012-02-16T15:12:30Z")

</div>

**[steeljans](https://sourceforge.net/u/steeljans/)** wrote on [Thursday, February 16, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/36054962/#b4b3):

Hello!  
I’m working on an application that use two timers.  
The firts timer is set to priority 7 while the second is set to priority 6.  
i need the isr to be raised before the start of the the os scheduler so I initialize the interrupt before declaring any tasks.  
I encounter a strange behavior changing the value of configMAX\_SYSCALL\_INTERRUPT\_PRIORITY.  
Setting it on 0x7 i get both the isr to work correctly “after” the scheduler start.  
If i set it on a value lower than 6 i get them to work correctly “before” the scheduler start.  
What i’m doing wrong?  
Thanks in advance for any help.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 16, 2012, 5:04pm UTC](https://forums.freertos.org/t/pic32-using-isr-before-the-scheduler-start/1263/2 "2012-02-16T17:04:57Z")

</div>

**[steeljans](https://sourceforge.net/u/steeljans/)** wrote on [Thursday, February 16, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/36054962/#35b4):

I found that a possibly cause of my problem is the freertos interrupt masking.  
In fact if i set configMAX\_SYSCALL\_INTERRUPT\_PRIORITY = 7 it mask my two timer whose priorities are 7 and 6.  
So there is a way to unmask interrupts before the scheduler starts?  
I need to do something like that:  
int main(void)  
{  
&nbsp; unmaskinterrupts();  
&nbsp; // my function that wait for timers interrupts raising…  
&nbsp; maskinterrupts();  
&nbsp;  
&nbsp; createtasks();

&nbsp; vTaskStartScheduler();  
}

Thanks again!  
&nbsp;

---

<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:** [February 16, 2012, 7:25pm UTC](https://forums.freertos.org/t/pic32-using-isr-before-the-scheduler-start/1263/3 "2012-02-16T19:25:29Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, February 16, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/36054962/#f490):

In the general case, it is not good to allow interrupts to execute before the kernel is started.&nbsp; That is because there is potential for a crash if the ISR attempts to call a FreeRTOS API function before the scheduler has started - or even worse, attempts a context switch (the latter case will definitely cause a crash).&nbsp; Therefore, FreeRTOS API functions will return with interrupts masked to the defined max syscall priority when they are called before the scheduler is started.&nbsp; For example, calling xTaskCreate() before the scheduler is started will result in interrupts being masked.

You can manually unmask the interrupt by calling taskENABLE\_INTERRUPTS(), but interrupts will be masked again if another FreeRTOS API function is called before vTaskStartScheduler().

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 17, 2012, 12:01pm UTC](https://forums.freertos.org/t/pic32-using-isr-before-the-scheduler-start/1263/4 "2012-02-17T12:01:44Z")

</div>

**[steeljans](https://sourceforge.net/u/steeljans/)** wrote on [Friday, February 17, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/36054962/#58bc):

Thanks a lot!  
It works perfectly.
