xos_internal.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (c) 2003-2015 Cadence Design Systems, Inc.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining
  4. // a copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to
  8. // permit persons to whom the Software is furnished to do so, subject to
  9. // the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included
  12. // in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  18. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  19. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  20. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #ifndef __XOS_INTERNAL_H__
  22. #define __XOS_INTERNAL_H__
  23. #if !defined(__XOS_H__) || !defined(_XOS_INCLUDE_INTERNAL_)
  24. #error "xos_internal.h must be included by defining _XOS_INCLUDE_INTERNAL_ before including xos.h"
  25. #endif
  26. #include <xtensa/config/core.h>
  27. #include "xos_common.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. // Use this macro to suppress compiler warnings for unused variables.
  32. #define UNUSED(x) (void)(x)
  33. #if XOS_DEBUG
  34. #include <stdio.h>
  35. #include <xtensa/xtutil.h>
  36. # define DPRINTF printf
  37. #else
  38. # define DPRINTF(x...) do {} while(0)
  39. #endif
  40. //-----------------------------------------------------------------------------
  41. // Internal flags for thread creation.
  42. //-----------------------------------------------------------------------------
  43. #define XOS_THREAD_FAKE 0x8000 // Don't allocate stack (init and idle threads).
  44. //-----------------------------------------------------------------------------
  45. // Interrupt handler table entry. This structure defines one entry in the XOS
  46. // interrupt handler table.
  47. //-----------------------------------------------------------------------------
  48. typedef struct XosIntEntry {
  49. XosIntFunc * handler; // Pointer to handler function.
  50. void * arg; // Argument passed to handler function.
  51. #if XOS_OPT_INTERRUPT_SWPRI
  52. unsigned char level; // Interrupt level.
  53. unsigned char priority; // Interrupt priority.
  54. short reserved; // Reserved.
  55. unsigned int primask; // Mask of interrupts at higher priority.
  56. #else
  57. unsigned int ps; // Value of PS when running the handler.
  58. #endif
  59. } XosIntEntry;
  60. //-----------------------------------------------------------------------------
  61. // Extern variables.
  62. //-----------------------------------------------------------------------------
  63. extern unsigned xos_intlevel_mask;
  64. extern unsigned xos_intenable_mask;
  65. extern XosIntEntry xos_interrupt_table[XCHAL_NUM_INTERRUPTS];
  66. extern uint32_t xos_clock_freq;
  67. extern uint32_t xos_tick_period;
  68. extern uint64_t xos_system_ticks;
  69. extern uint64_t xos_system_cycles;
  70. extern uint32_t xos_num_ctx_switches;
  71. /*
  72. One thing I noticed is different between my initial idea of stack
  73. assignments to RTC threads, when comparing to interrupts, is that I
  74. expected each RTC thread priority to have its own stack, whereas
  75. interrupts of different priorities share an interrupt stack.
  76. It's not really a difference in memory usage, because when assigning
  77. multiple priorities to a stack, you have to add-up worst-case for
  78. all priorities. One possible functional difference is that with
  79. separate stacks per priority, it's possible to dynamically change
  80. the priority of an RTC thread (while it's running). Not sure how
  81. valuable that might be -- changing priority is useful with priority
  82. inheritance, to avoid priority inversion, but I don't know how often
  83. an RTC thread might acquire a lock (it couldn't block on acquiring a
  84. lock in the usual sense -- it could get queued waiting and be restarted
  85. when it becomes available, or use try_lock instead of lock).
  86. */
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* __XOS_INTERNAL_H__ */