This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to implement the application-level SVC_Handler?

I want to implement a set of API functions in a separately compiled HEX, just like SoftDevice. It means that I need to use the SVC mechanism, just like what SoftDevice does. However, SoftDevice (S110) already implements a SVC_Handler. How can I implement my own application-level SVC_Handler, which can cooperate with the one in SoftDevice? Thanks.

(From the SoftDevice S110 Specification, I can only find that the SVC numbers reserved for our application are 0x00-0x0F. However, the specification doesn't mention how to use those reserved SVC numbers.)

  • I've looked into this a bit involving work on getting the CMSIS RTOS running with the softdevice on the nRF51822. If I recall correctly, the softdevice takes over the lower 80K of flash memory including the vector table starting at address 0x0000000. Your own application code will be located at 0x00014000 with its own interrupt vector table starting at that location. Because the nRF51822 is based on the Cortex M0, the vector table cannot be relocated, and the vector table at address 0x00000000 is always used when an interrupt occurs and execution is directed into the softdevice interrupt handlers. If the softdevice has no interest in the interrupt, it will examine the application vector table at 0x00014000 and then directly call the application interrupt handler which is referenced in the corresponding application vector table.

    In the case of the SVC interrupt it's only slightly more involved. The softdevice SVC interrupt handler will examine whether SVC numbers reserved for application code are being used. If so, the softdevice will then automatically call the application SVC handler via the application vector table at 0x00014000. Otherwise, the softdevice will handle the SVC interrupt on it's own.

    To answer your question, you really don't have to do anything special. Just create a SVC interrupt handler as you would any other interrupt handler and it will be automatically included in the application vector table at 0x00014000. The application vector table is defined in arm_startup_nrf51.s and contains tha weak reference to the symbol "SVC_Handler" which is what you need to name your SVC handler. The softdevice will automatically redirect its handling of the SVC interrupt to your application handler at that symbol name if it is using an SVC number reserved for application code. If you use a SVC number that is not reserved for application code, your handler will simply never be called by the softdevice SVC handler and likely result in an error in the softdevice.

  • Really appreciate your answer and detailed explanation. Nordic should include your description in their documentation. Thank you so much.

  • just to add one thing - the list of available SVC calls is in the softdevice documentation for each of the softdevices. For all those I've looked at, 0x00-0x0F are the only ones available. It's enough, just about.

Related