xtensa_overlay_os_hook.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // xtensa_overlay_os_hook.c -- Overlay manager OS hooks for FreeRTOS.
  2. // Copyright (c) 2015-2015 Cadence Design Systems Inc.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included
  13. // in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #include "FreeRTOS.h"
  23. #include "semphr.h"
  24. #if configUSE_MUTEX
  25. /* Mutex object that controls access to the overlay. Currently only one
  26. * overlay region is supported so one mutex suffices.
  27. */
  28. static SemaphoreHandle_t xt_overlay_mutex;
  29. /* This function should be overridden to provide OS specific init such
  30. * as the creation of a mutex lock that can be used for overlay locking.
  31. * Typically this mutex would be set up with priority inheritance. See
  32. * overlay manager documentation for more details.
  33. */
  34. void xt_overlay_init_os(void)
  35. {
  36. /* Create the mutex for overlay access. Priority inheritance is
  37. * required.
  38. */
  39. xt_overlay_mutex = xSemaphoreCreateMutex();
  40. }
  41. /* This function locks access to shared overlay resources, typically
  42. * by acquiring a mutex.
  43. */
  44. void xt_overlay_lock(void)
  45. {
  46. xSemaphoreTake(xt_overlay_mutex, 0);
  47. }
  48. /* This function releases access to shared overlay resources, typically
  49. * by unlocking a mutex.
  50. */
  51. void xt_overlay_unlock(void)
  52. {
  53. xSemaphoreGive(xt_overlay_mutex);
  54. }
  55. #endif