Forum Discussion
Hi, Kian,
Thank you for the detailed answers. We will stay with the critical section. Found a few other statements to access the same memory with same HAL API calls in either read or write in tasks and one interrupt service routine. Added OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() to each of them. Going to run more tests to see if no more exceptions occur.
Note: The previous test with mentioned changes indeed did not have exceptions but I also removed the statement
Hi Patrick,
Just checking up on this case whether you still having issues on the exceptions triggering with your changes?
Thanks
Regards
Kian
- PatrickY1 year ago
New Contributor
Hi, Kian,
As expected, after the synchronization with the critical section to all access the address of both event and interrupt enable through HAL library calls altera_avalon_fifo_clear_event() and altera_avalon_fifo_write_ienable(), no exceptions occur in the application. That is, the issue is resolved.
But I have couple questions about the exception with unknown reason happened before the critical section is used.
- Does the unprotected access to the shared resource/address cause an exception? Usually the unprotected access could cause data corruption, thereafter when the corrupted data are used, which would cause some error or exception such as memory access violation or invalid data to use, etc. But the unprotected access itself would not cause the exception.
- Per the “Embedded Peripherals IP User Guide” document, if altera_avalon_fifo_clear_event() fails, it returns ALTERA_AVALON_FIFO_EVENT_CLEAR_ERROR and altera_avalon_fifo_write_ienable() fails, it returns ALTERA_AVALON_FIFO_IENABLE_WRITE_ERROR. Does either error cause any exception? If it does, no reason is specified?
Thank you in advance.
Best regards,
Patrick
- KianHinT_altera1 year ago
Frequent Contributor
Hi Patrick
Sorry for the delay in getting back to you as last week was festive holiday in our region. Glad that the issue been resolved.
As per your questions
1. Does the unprotected access to the shared resource/address cause an exception? Usually the unprotected access could cause data corruption, thereafter when the corrupted data are used, which would cause some error or exception such as memory access violation or invalid data to use, etc. But the unprotected access itself would not cause the exception.
Yes, exceptions happen when multiple functions (eg in this case the clear_event and write_ienable) is trying to access to the same register at the same/similar time due to RTOS task scheduler. If only 1 unprotected function/task is assessing the shared resource/address , this access is valid and will not cause exception to occur.
2. Per the “Embedded Peripherals IP User Guide” document, if altera_avalon_fifo_clear_event() fails, it returns ALTERA_AVALON_FIFO_EVENT_CLEAR_ERROR and altera_avalon_fifo_write_ienable() fails, it returns ALTERA_AVALON_FIFO_IENABLE_WRITE_ERROR. Does either error cause any exception? If it does, no reason is specified?
The HAL API will not cause any exception in the processor. (It is designed not to)
User are recommended to read the return value, and check if it is 0, before continuing to next operation
ret_code = altera_avalon_fifo_clear_event(....);
if(ret_code !=0)
{
printf_error();
return 0;
}
Thanks
Regards
Kian