cmsis_test.c 914 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdio.h>
  2. #if PICO_RP2040
  3. #include "RP2040.h"
  4. #else
  5. #include "RP2350.h"
  6. #endif
  7. #include "pico/stdlib.h"
  8. #include "hardware/irq.h"
  9. __STATIC_FORCEINLINE int some_function(int i) {
  10. return __CLZ(i);
  11. }
  12. static bool pendsv_called, irq_handler_called;
  13. void PendSV_Handler(void) {
  14. pendsv_called = true;
  15. }
  16. void DMA_IRQ_0_Handler(void) {
  17. irq_handler_called = true;
  18. irq_clear(DMA_IRQ_0_IRQn);
  19. }
  20. int main(void) {
  21. stdio_init_all();
  22. for(int i=0;i<10;i++) {
  23. printf("%d %d\n", i, some_function(i));
  24. }
  25. SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
  26. printf("PENDSV: ");
  27. puts(pendsv_called ? "SUCCESS" : "FAILURE");
  28. printf("DMA_IRQ_0: ");
  29. irq_set_enabled(DMA_IRQ_0_IRQn, true);
  30. irq_set_pending(DMA_IRQ_0_IRQn);
  31. puts(irq_handler_called ? "SUCCESS" : "FAILURE");
  32. bool ok = pendsv_called && irq_handler_called;
  33. puts(ok ? "PASSED" : "FAILED");
  34. return !ok;
  35. }