test_ahb_arb_asm.S 935 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "sdkconfig.h"
  2. #if CONFIG_IDF_TARGET_ESP32
  3. /*
  4. This little bit of code is executed in-place by one CPU, but copied to a different memory region
  5. by the other CPU. Make sure it stays position-independent.
  6. */
  7. .text
  8. .align 4
  9. .global test_s32c1i_lock
  10. .type test_s32c1i_lock,@function
  11. //Args:
  12. //a2 - lock addr
  13. //a3 - val to lock with
  14. //a4 - val to unlock with
  15. //a5 - addr to increase
  16. test_s32c1i_lock:
  17. entry a1, 64
  18. wsr a4, SCOMPARE1
  19. lockloop:
  20. mov a6, a3
  21. s32c1i a6, a2, 0
  22. bne a4, a6, lockloop
  23. l32i a6, a5, 0
  24. //Give other CPU the time to mess up the inc if the lock somehow malfunctions
  25. nop
  26. nop
  27. nop
  28. nop
  29. nop
  30. nop
  31. nop
  32. nop
  33. nop
  34. nop
  35. nop
  36. nop
  37. nop
  38. nop
  39. nop
  40. nop
  41. addi a6, a6, 1
  42. s32i a6, a5, 0
  43. //No need to actually let this loop but hey, a hang indicates an error, right?
  44. wsr a3, SCOMPARE1
  45. unlockloop:
  46. mov a6, a4
  47. s32c1i a6, a2, 0
  48. bne a3, a6, unlockloop
  49. retw
  50. #endif // CONFIG_IDF_TARGET_ESP32