Choco OS  V.0.16.9.0
Join to the chocolate world
oc_mcs.h
Go to the documentation of this file.
1 
40 #ifndef SYSTEM_PORTABLE_INC_MCS_OC_MCS_H_
41 #define SYSTEM_PORTABLE_INC_MCS_OC_MCS_H_
42 
43 #include <oc_interrupts_defs.h>
44 #include <oc_assert.h>
45 #include <oc_stdtypes.h>
46 #include <stdbool.h>
47 #include <oc_mcs_defs.h>
48 #include <stddef.h>
49 #include <oc_memory.h>
50 #include <oc_errors.h>
51 
57 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
58 
61 //==========================================================================================================================================
76 //==========================================================================================================================================
77 #define oC_MCS_IsStackPushDecrementPointer() oC_MCS_STACK_PUSH_DECREMENTS_POINTER
78 
79 //==========================================================================================================================================
88 //==========================================================================================================================================
89 #define oC_MCS_AlignStackPointer(Pointer) ((void*)oC_MCS_AlignSize((void*)Pointer,oC_MCS_STACK_MEMORY_ALIGNMENT))
90 //==========================================================================================================================================
99 //==========================================================================================================================================
100 #define oC_MCS_AlignPointer(Pointer) ((void*)oC_MCS_AlignSize((void*)Pointer,oC_MCS_MEMORY_ALIGNMENT))
101 //==========================================================================================================================================
110 //==========================================================================================================================================
111 #define oC_MCS_AlignSize(Size,Alignment) ((((oC_UInt_t)(Size)) + (Alignment) - 1) & ~((Alignment)-1))
112 
113 //==========================================================================================================================================
118 //==========================================================================================================================================
119 #define oC_MCS_IsStackPointerAligned(Pointer) (oC_MCS_AlignStackPointer(Pointer) == ((void*)(Pointer)))
120 
121 //==========================================================================================================================================
126 //==========================================================================================================================================
127 #define oC_MCS_IsPointerAligned(Pointer) (oC_MCS_AlignPointer(Pointer) == Pointer)
128 
129 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
130 
137 #define _________________________________________TYPES_SECTION______________________________________________________________________________
138 
141 //==========================================================================================================================================
148 //==========================================================================================================================================
149 typedef enum
150 {
151 /* This definition is for removing text "System" from the IRQn enumerator name */
152 #define System
153 /* Definition for creating IRQn type enumerator name */
154 #define IRQn_(NAME,TYPE) oC_1WORD_FROM_3(TYPE , NAME , _IRQn)
155 /* Definition for creation of interrupt number enumerator in IRQn_Type */
156 #define CREATE_INTERRUPT_NUMBER( BASE_NAME , INTERRUPT_TYPE , INTERRUPT_NUMBER , ...) IRQn_(BASE_NAME , INTERRUPT_TYPE) = INTERRUPT_NUMBER ,
157 
158  /* This creates enumerator values from definitions in interrupts defs file */
159  oC_MACHINE_INTERRUPTS_LIST(CREATE_INTERRUPT_NUMBER)
160 
161 /* Removes all definitions that are not needed anymore */
162 #undef CREATE_INTERRUPT_NUMBER
163 #undef System
164 } IRQn_Type;
165 
166 //==========================================================================================================================================
173 //==========================================================================================================================================
174 typedef enum
175 {
177  oC_InterruptPriority_Minimum = oC_MINIMUM_INTERRUPT_PRIORITY ,
178  oC_InterruptPriority_Maximum = oC_MAXIMUM_INTERRUPT_PRIORITY
180 
181 //==========================================================================================================================================
189 //==========================================================================================================================================
190 typedef void (*oC_ContextHandler_t)( void * ContextParameter );
191 
192 //==========================================================================================================================================
198 //==========================================================================================================================================
199 typedef void (*oC_ContextExitHandler_t)(void);
200 
201 //==========================================================================================================================================
207 //==========================================================================================================================================
208 typedef struct
209 {
210  void * StackPointer;
211  void * Buffer;
212  oC_Int_t BufferSize;
214 
215 //==========================================================================================================================================
221 //==========================================================================================================================================
222 typedef struct
223 {
224  const void * BaseAddress;
225  oC_MemorySize_t Size;
226  bool AlignSize;
230  bool Shareable;
231  bool Cacheable;
232  bool Bufforable;
233  uint32_t RegionNumber;
235 
236 //==========================================================================================================================================
242 //==========================================================================================================================================
243 typedef enum
244 {
248 
249 //==========================================================================================================================================
255 //==========================================================================================================================================
257 
258 //==========================================================================================================================================
264 //==========================================================================================================================================
265 typedef void (*oC_FindNextStackHandler_t)( void );
266 
267 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
268 
270 
271 
277 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________
278 
281 //==========================================================================================================================================
289 //==========================================================================================================================================
290 extern bool oC_MCS_InitializeModule( void );
291 
292 //==========================================================================================================================================
296 //==========================================================================================================================================
297 extern void * oC_MCS_GetHardFaultReason( void );
298 
299 //==========================================================================================================================================
309 //==========================================================================================================================================
310 extern void oC_MCS_EnableInterrupts( void );
311 //==========================================================================================================================================
321 //==========================================================================================================================================
322 extern void oC_MCS_DisableInterrupts( void );
323 
324 //==========================================================================================================================================
334 //==========================================================================================================================================
335 extern bool oC_MCS_AreInterruptsEnabled( void );
336 
337 //==========================================================================================================================================
349 //==========================================================================================================================================
350 extern bool oC_MCS_EnableInterrupt( IRQn_Type InterruptNumber );
351 
352 //==========================================================================================================================================
364 //==========================================================================================================================================
365 extern bool oC_MCS_DisableInterrupt( IRQn_Type InterruptNumber );
366 
367 //==========================================================================================================================================
379 //==========================================================================================================================================
380 extern bool oC_MCS_IsInterruptEnabled( IRQn_Type InterruptNumber );
381 
382 //==========================================================================================================================================
396 //==========================================================================================================================================
397 extern bool oC_MCS_SetInterruptPriority( IRQn_Type InterruptNumber , oC_InterruptPriotity_t Priority );
398 
399 //==========================================================================================================================================
411 //==========================================================================================================================================
413 
414 //==========================================================================================================================================
423 //==========================================================================================================================================
424 extern void oC_MCS_Reboot( void );
425 
426 //==========================================================================================================================================
445 //==========================================================================================================================================
446 extern bool oC_MCS_InitializeStack(
447  oC_Stack_t * outStack ,
448  void * Buffer ,
449  oC_Int_t BufferSize ,
450  oC_ContextHandler_t ContextHandler ,
451  void * HandlerParameter ,
452  oC_ContextExitHandler_t ExitHandler
453  );
454 
455 //==========================================================================================================================================
463 //==========================================================================================================================================
464 extern void * oC_MCS_GetCurrentProcessStackPointer( void );
465 
466 //==========================================================================================================================================
474 //==========================================================================================================================================
475 extern void * oC_MCS_GetCurrentMainStackPointer( void );
476 
477 //==========================================================================================================================================
487 //==========================================================================================================================================
488 extern oC_Int_t oC_MCS_GetStackSize( oC_Stack_t Stack );
489 
490 //==========================================================================================================================================
502 //==========================================================================================================================================
503 extern oC_Int_t oC_MCS_GetFreeStackSize( oC_Stack_t Stack );
504 
505 //==========================================================================================================================================
513 //==========================================================================================================================================
514 extern oC_Stack_t oC_MCS_GetCurrentStack( void );
515 
516 //==========================================================================================================================================
525 //==========================================================================================================================================
526 extern oC_Int_t oC_MCS_GetMinimumStackBufferSize( oC_Int_t StackSize );
527 
528 //==========================================================================================================================================
565 //==========================================================================================================================================
566 extern bool oC_MCS_SetNextStack( oC_Stack_t Stack );
567 
568 //==========================================================================================================================================
582 //==========================================================================================================================================
583 extern bool oC_MCS_ConfigureSystemTimer( oC_UInt_t Prescaler , oC_FindNextStackHandler_t FindNextStackHandler );
584 
585 //==========================================================================================================================================
589 //==========================================================================================================================================
590 extern oC_Stack_t oC_MCS_GetSystemStack( void );
591 
592 //==========================================================================================================================================
600 //==========================================================================================================================================
601 extern bool oC_MCS_ReturnToSystemStack( void );
602 
603 //==========================================================================================================================================
611 //==========================================================================================================================================
612 extern void oC_MCS_Delay( register oC_UInt_t Cycles );
613 
614 //==========================================================================================================================================
625 //==========================================================================================================================================
626 extern oC_ErrorCode_t oC_MCS_ConfigureMemoryRegion( const oC_MCS_MemoryRegionConfig_t * Config );
627 
628 //==========================================================================================================================================
632 //==========================================================================================================================================
633 extern uint32_t oC_MCS_GetMaximumNumberOfRegions( void );
634 
635 //==========================================================================================================================================
639 //==========================================================================================================================================
640 extern uint32_t oC_MCS_GetNumberOfRegions( void );
641 
642 //==========================================================================================================================================
650 //==========================================================================================================================================
651 extern bool oC_MCS_ReadFreeRegionNumber( uint32_t * outFreeRegionNumber );
652 
653 //==========================================================================================================================================
664 //==========================================================================================================================================
666 
667 //==========================================================================================================================================
675 //==========================================================================================================================================
677 
678 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________
679 
686 #define _________________________________________GLOBAL_VARIABLES_SECTION___________________________________________________________________
687 
688 extern int16_t oC_MCS_CriticalSectionCounter;
689 
690 #undef _________________________________________GLOBAL_VARIABLES_SECTION___________________________________________________________________
691 
692 
698 #define _________________________________________STATIC_INLINE_SECTION______________________________________________________________________
699 
700 //==========================================================================================================================================
720 //==========================================================================================================================================
721 static inline bool oC_MCS_ChangeCriticalSectionCounter( int8_t ValueToAdd )
722 {
723  static const int16_t criticalCounterMax = INT16_MAX - INT8_MAX;
724 
725  oC_MCS_CriticalSectionCounter += ValueToAdd;
726 
727  /* This assertion fails, when the critical counter was decremented too much time */
728  oC_ASSERT(oC_MCS_CriticalSectionCounter >= 0);
729 
730  /* This assertion fails, when the critical counter achieve maximum safe value */
731  oC_ASSERT(oC_MCS_CriticalSectionCounter < criticalCounterMax);
732 
733  return oC_MCS_CriticalSectionCounter == 0;
734 }
735 
736 //==========================================================================================================================================
754 //==========================================================================================================================================
755 static inline void oC_MCS_EnterCriticalSection( void )
756 {
757  /* Add 1 to the critical section counter */
759 
761 }
762 
763 //==========================================================================================================================================
783 //==========================================================================================================================================
784 static inline bool oC_MCS_ExitCriticalSection( void )
785 {
786  bool interruptsEnabled = false;
787 
789  {
791  }
792 
793  return interruptsEnabled;
794 }
795 
796 //==========================================================================================================================================
822 //==========================================================================================================================================
823 static inline bool oC_MCS_IsCriticalSectionActive( void )
824 {
825  return oC_MCS_ChangeCriticalSectionCounter(0) == false;
826 }
827 
828 #undef _________________________________________STATIC_INLINE_SECTION______________________________________________________________________
829 
830 
831 #endif /* SYSTEM_PORTABLE_INC_MCS_ARM_ARM_CORTEX_M7_OC_MCS_H_ */
stores stack data
Definition: oc_mcs.h:208
oC_Int_t oC_MCS_GetMinimumStackBufferSize(oC_Int_t StackSize)
returns minimum stack buffer size
Definition: oc_mcs.c:601
void * oC_MCS_GetCurrentProcessStackPointer(void)
returns current value of PSP
Definition: oc_mcs.c:510
bool Cacheable
True if the region should be cacheable - If you set a region to be cacheable: When you load from that...
Definition: oc_mcs.h:231
The file with interface for the GPIO driver.
void * Buffer
Definition: oc_mcs.h:211
oC_MemorySize_t Size
Size of the region.
Definition: oc_mcs.h:225
bool oC_MCS_SetMemoryAccessMode(oC_MCS_MemoryAccessMode_t Mode)
sets the memory access mode
Definition: oc_mcs.c:847
void(* oC_FindNextStackHandler_t)(void)
stores pointer to function for searching next stack
Definition: oc_mcs.h:265
Memory controller is configured to allow for memory access only for regions that can be accessible by...
Definition: oc_mcs.h:245
void * oC_MCS_GetHardFaultReason(void)
returns address that cause a hard fault
Definition: oc_mcs.c:321
int16_t oC_MCS_CriticalSectionCounter
global variable with critical section nesting counter
Definition: oc_mcs.c:134
oC_Stack_t oC_MCS_GetSystemStack(void)
returns pointer to the system stack
Definition: oc_mcs.c:659
bool oC_MCS_SetInterruptPriority(IRQn_Type InterruptNumber, oC_InterruptPriotity_t Priority)
sets interrupt priority
Definition: oc_mcs.c:400
bool oC_MCS_ReturnToSystemStack(void)
sets next stack as system stack
Definition: oc_mcs.c:669
static bool oC_MCS_IsCriticalSectionActive(void)
checks if critical section is active
Definition: oc_mcs.h:823
void oC_MCS_Reboot(void)
Software reboots of machine.
Definition: oc_mcs.c:421
oC_InterruptPriotity_t
stores priority of interrupts
Definition: oc_mcs.h:174
void * oC_MCS_GetCurrentMainStackPointer(void)
returns current value of MSP
Definition: oc_mcs.c:520
void * StackPointer
Definition: oc_mcs.h:210
const void * BaseAddress
Base address of the region - this must point to the start of the region.
Definition: oc_mcs.h:224
bool oC_MCS_InitializeStack(oC_Stack_t *outStack, void *Buffer, oC_Int_t BufferSize, oC_ContextHandler_t ContextHandler, void *HandlerParameter, oC_ContextExitHandler_t ExitHandler)
initializes stack for the system
Definition: oc_mcs.c:432
static bool oC_MCS_ChangeCriticalSectionCounter(int8_t ValueToAdd)
Increment or decrement counter for critical sections.
Definition: oc_mcs.h:721
bool oC_MCS_EnableInterrupt(IRQn_Type InterruptNumber)
enables interrupt with specified number
Definition: oc_mcs.c:368
void(* oC_ContextHandler_t)(void *ContextParameter)
stores handler of function, that handles context
Definition: oc_mcs.h:190
uint32_t RegionNumber
Number of the region to configure.
Definition: oc_mcs.h:233
oC_ErrorCode_t oC_MCS_ConfigureMemoryRegion(const oC_MCS_MemoryRegionConfig_t *Config)
configures memory region
Definition: oc_mcs.c:701
#define oC_MACHINE_INTERRUPTS_LIST(ADD_INTERRUPT)
Definition of interrupts.
oC_Int_t oC_MCS_GetFreeStackSize(oC_Stack_t Stack)
returns number of free stack
Definition: oc_mcs.c:551
bool oC_MCS_SetNextStack(oC_Stack_t Stack)
sets next stack for context switching
Definition: oc_mcs.c:613
void oC_MCS_Delay(register oC_UInt_t Cycles)
delays operations for cycles
Definition: oc_mcs.c:679
void(* oC_ContextExitHandler_t)(void)
stores handler of function called, when context handling is finished
Definition: oc_mcs.h:199
bool Bufforable
True if the region should be bufforable - Bufferable means whether a write to the address can be buff...
Definition: oc_mcs.h:232
Value for functions, that returns priority to provide error handling.
Definition: oc_mcs.h:176
bool oC_MCS_IsInterruptEnabled(IRQn_Type InterruptNumber)
checks if interrupt is enabled
Definition: oc_mcs.c:390
oC_Access_t UserAccess
Definition of access for user space.
Definition: oc_mcs.h:228
oC_Access_t
Type for storing access (R/W/RW)
Definition: oc_memory.h:89
bool oC_MCS_ConfigureSystemTimer(oC_UInt_t Prescaler, oC_FindNextStackHandler_t FindNextStackHandler)
configures system timer
Definition: oc_mcs.c:634
bool oC_MCS_AreInterruptsEnabled(void)
Checks if interrupts are enabled in HW.
Definition: oc_mcs.c:356
oC_Int_t oC_MCS_GetStackSize(oC_Stack_t Stack)
returns size of stack
Definition: oc_mcs.c:529
Memory controller is configured to allow for memory access for regions that can be accessible by a pr...
Definition: oc_mcs.h:246
FILE__DESCRIPTION
uint32_t oC_MCS_GetNumberOfRegions(void)
returns number of regions that are currently configured
Definition: oc_mcs.c:773
bool oC_MCS_InitializeModule(void)
initializes module to work
Definition: oc_mcs.c:299
IRQn_Type
type for the CMSIS library, that contains definitions of interrupts
Definition: oc_mcs.h:149
static void oC_MCS_EnterCriticalSection(void)
Enters to critical section.
Definition: oc_mcs.h:755
oC_MCS_MemoryAccessMode_t
stores memory access mode
Definition: oc_mcs.h:243
oC_Stack_t oC_MCS_GetCurrentStack(void)
returns current stack
Definition: oc_mcs.c:591
configuration structure for the memory region
Definition: oc_mcs.h:222
oC_InterruptPriotity_t oC_MCS_GetInterruptPriority(IRQn_Type InterruptNumber)
returns interrupt priority
Definition: oc_mcs.c:411
oC_Access_t PrivilegedAccess
Definition of access for privileged space (portable or core)
Definition: oc_mcs.h:229
void oC_MCS_DisableInterrupts(void)
Globally disables interrupts (always)
Definition: oc_mcs.c:346
bool oC_MCS_ReadFreeRegionNumber(uint32_t *outFreeRegionNumber)
reads number of a free region
Definition: oc_mcs.c:807
static bool oC_MCS_ExitCriticalSection(void)
Exits from critical section.
Definition: oc_mcs.h:784
void oC_MCS_EnableInterrupts(void)
Globally enables interrupts (always)
Definition: oc_mcs.c:331
The lowest value for priority.
Definition: oc_mcs.h:177
oC_MCS_MemoryAccessMode_t oC_MCS_GetMemoryAccessMode(void)
reads memory access mode
Definition: oc_mcs.c:870
bool Shareable
For a shareable memory region that is implemented, the memory system provides data synchronization be...
Definition: oc_mcs.h:230
oC_Int_t BufferSize
Definition: oc_mcs.h:212
oC_Power_t Power
Power state for the region (enabled or disabled)
Definition: oc_mcs.h:227
oC_StackData_t * oC_Stack_t
type for storing stack reference
Definition: oc_mcs.h:256
bool oC_MCS_DisableInterrupt(IRQn_Type InterruptNumber)
disables interrupt with specified number
Definition: oc_mcs.c:379
FILE__DESCRIPTION
oC_Power_t
stores registers power state
Definition: oc_stdtypes.h:249
bool AlignSize
True if the MCS should find the size nearest to the value given as the Size field.
Definition: oc_mcs.h:226
uint32_t oC_MCS_GetMaximumNumberOfRegions(void)
returns maximum number of regions handled by the machine
Definition: oc_mcs.c:763
The most important interrupt priority, that is possible in the machine.
Definition: oc_mcs.h:178