cpu_up.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-04-19 Shell Fixup UP irq spinlock
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. /**
  13. * @brief Initialize a static spinlock object.
  14. *
  15. * @param lock is a pointer to the spinlock to initialize.
  16. */
  17. void rt_spin_lock_init(struct rt_spinlock *lock)
  18. {
  19. RT_UNUSED(lock);
  20. }
  21. /**
  22. * @brief This function will lock the spinlock, will lock the thread scheduler.
  23. *
  24. * @note If the spinlock is locked, the current CPU will keep polling the spinlock state
  25. * until the spinlock is unlocked.
  26. *
  27. * @param lock is a pointer to the spinlock.
  28. */
  29. void rt_spin_lock(struct rt_spinlock *lock)
  30. {
  31. rt_enter_critical();
  32. RT_SPIN_LOCK_DEBUG(lock);
  33. }
  34. /**
  35. * @brief This function will unlock the spinlock, will unlock the thread scheduler.
  36. *
  37. * @param lock is a pointer to the spinlock.
  38. */
  39. void rt_spin_unlock(struct rt_spinlock *lock)
  40. {
  41. rt_base_t critical_level;
  42. RT_SPIN_UNLOCK_DEBUG(lock, critical_level);
  43. rt_exit_critical_safe(critical_level);
  44. }
  45. /**
  46. * @brief This function will disable the local interrupt and then lock the spinlock, will lock the thread scheduler.
  47. *
  48. * @note If the spinlock is locked, the current CPU will keep polling the spinlock state
  49. * until the spinlock is unlocked.
  50. *
  51. * @param lock is a pointer to the spinlock.
  52. *
  53. * @return Return current cpu interrupt status.
  54. */
  55. rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
  56. {
  57. rt_base_t level;
  58. RT_UNUSED(lock);
  59. level = rt_hw_interrupt_disable();
  60. rt_enter_critical();
  61. RT_SPIN_LOCK_DEBUG(lock);
  62. return level;
  63. }
  64. /**
  65. * @brief This function will unlock the spinlock and then restore current cpu interrupt status, will unlock the thread scheduler.
  66. *
  67. * @param lock is a pointer to the spinlock.
  68. *
  69. * @param level is interrupt status returned by rt_spin_lock_irqsave().
  70. */
  71. void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
  72. {
  73. rt_base_t critical_level;
  74. RT_SPIN_UNLOCK_DEBUG(lock, critical_level);
  75. rt_exit_critical_safe(critical_level);
  76. rt_hw_interrupt_enable(level);
  77. }