os_cpu_a.c 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2021, Meco Jianting Man <jiantingman@foxmail.com>
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-09-18 Meco Man first version
  9. */
  10. /*
  11. ;********************************************************************************************************
  12. ; uC/OS-II
  13. ; The Real-Time Kernel
  14. ;
  15. ; Copyright 1992-2020 Silicon Laboratories Inc. www.silabs.com
  16. ;
  17. ; SPDX-License-Identifier: APACHE-2.0
  18. ;
  19. ; This software is subject to an open source license and is distributed by
  20. ; Silicon Laboratories Inc. pursuant to the terms of the Apache License,
  21. ; Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
  22. ;
  23. ;********************************************************************************************************
  24. */
  25. #include "os_cpu.h"
  26. #include <rthw.h>
  27. /*
  28. ;********************************************************************************************************
  29. ; PUBLIC FUNCTIONS
  30. ;********************************************************************************************************
  31. */
  32. /*
  33. ;********************************************************************************************************
  34. ; CRITICAL SECTION METHOD 3 FUNCTIONS
  35. ;
  36. ; Description : Disable/Enable Kernel aware interrupts by preserving the state of BASEPRI. Generally speaking,
  37. ; the state of the BASEPRI interrupt exception processing is stored in the local variable
  38. ; 'cpu_sr' & Kernel Aware interrupts are then disabled ('cpu_sr' is allocated in all functions
  39. ; that need to disable Kernel aware interrupts). The previous BASEPRI interrupt state is restored
  40. ; by copying 'cpu_sr' into the BASEPRI register.
  41. ;
  42. ; Prototypes : OS_CPU_SR OS_CPU_SR_Save (OS_CPU_SR new_basepri);
  43. ; void OS_CPU_SR_Restore(OS_CPU_SR cpu_sr);
  44. ;
  45. ;
  46. ; Note(s) : 1) These functions are used in general like this:
  47. ;
  48. ; void Task (void *p_arg)
  49. ; {
  50. ; #if OS_CRITICAL_METHOD == 3 // Allocate storage for CPU status register
  51. ; OS_CPU_SR cpu_sr;
  52. ; #endif
  53. ;
  54. ; :
  55. ; :
  56. ; OS_ENTER_CRITICAL(); // cpu_sr = OS_CPU_SR_Save(new_basepri);
  57. ; :
  58. ; :
  59. ; OS_EXIT_CRITICAL(); // OS_CPU_RestoreSR(cpu_sr);
  60. ; :
  61. ; :
  62. ; }
  63. ;
  64. ; 2) Increasing priority using a write to BASEPRI does not take effect immediately.
  65. ; (a) IMPLICATION This erratum means that the instruction after an MSR to boost BASEPRI
  66. ; might incorrectly be preempted by an insufficient high priority exception.
  67. ;
  68. ; (b) WORKAROUND The MSR to boost BASEPRI can be replaced by the following code sequence:
  69. ;
  70. ; CPSID i
  71. ; MSR to BASEPRI
  72. ; DSB
  73. ; ISB
  74. ; CPSIE i
  75. ;********************************************************************************************************
  76. */
  77. #if OS_CRITICAL_METHOD == 3
  78. OS_CPU_SR OS_CPU_SR_Save (void)
  79. {
  80. return rt_hw_interrupt_disable();
  81. }
  82. void OS_CPU_SR_Restore (OS_CPU_SR cpu_sr)
  83. {
  84. rt_hw_interrupt_enable(cpu_sr);
  85. }
  86. #endif