1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** ThreadX Component */
17 /** */
18 /** Initialization */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define TX_SOURCE_CODE
24 #define TX_THREAD_SMP_SOURCE_CODE
25
26
27 /* Include necessary system files. */
28
29 #include "tx_api.h"
30 #include "tx_initialize.h"
31 #include "tx_timer.h"
32 #include "tx_thread.h"
33
34
35
36 /**************************************************************************/
37 /* */
38 /* FUNCTION RELEASE */
39 /* */
40 /* _tx_thread_smp_high_level_initialize PORTABLE SMP */
41 /* 6.1.3 */
42 /* AUTHOR */
43 /* */
44 /* William E. Lamie, Microsoft Corporation */
45 /* */
46 /* DESCRIPTION */
47 /* */
48 /* This function initializes the ThreadX SMP data structures and */
49 /* CPU registers. */
50 /* */
51 /* INPUT */
52 /* */
53 /* None */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* None */
58 /* */
59 /* CALLS */
60 /* */
61 /* None */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* _tx_initialize_kernel_enter ThreadX entry */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 09-30-2020 William E. Lamie Initial Version 6.1 */
72 /* 12-31-2020 William E. Lamie Modified comments, added */
73 /* cast to address a MISRA */
74 /* compliant issue, */
75 /* resulting in version 6.1.3 */
76 /* */
77 /**************************************************************************/
_tx_thread_smp_high_level_initialize(void)78 void _tx_thread_smp_high_level_initialize(void)
79 {
80
81 /* Clear the system error flag. */
82 _tx_thread_smp_system_error = TX_FALSE;
83
84 /* Ensure that the system state variable is set to indicate
85 initialization is in progress. Note that this variable is
86 later used to represent interrupt nesting. */
87 _tx_thread_smp_current_state_set(TX_INITIALIZE_IN_PROGRESS);
88
89 /* Clear the thread protection. */
90 TX_MEMSET(&_tx_thread_smp_protection, 0, sizeof(TX_THREAD_SMP_PROTECT));
91
92 /* Set the field of the protection to all ones to indicate it is invalid. */
93 _tx_thread_smp_protection.tx_thread_smp_protect_core = ((ULONG) 0xFFFFFFFFUL);
94
95 /* Clear the thread schedule list. */
96 TX_MEMSET(&_tx_thread_smp_schedule_list[0], 0, sizeof(_tx_thread_smp_schedule_list));
97
98 /* Initialize core list. */
99 TX_MEMSET(&_tx_thread_smp_protect_wait_list[0], 0xff, sizeof(_tx_thread_smp_protect_wait_list));
100
101 /* Set the wait list size so we can access it from assembly functions. */
102 _tx_thread_smp_protect_wait_list_size = ((ULONG) TX_THREAD_SMP_PROTECT_WAIT_LIST_SIZE);
103
104 #ifndef TX_THREAD_SMP_DYNAMIC_CORE_MAX
105
106 /* Call low-level SMP initialize. */
107 _tx_thread_smp_low_level_initialize(((UINT) TX_THREAD_SMP_MAX_CORES));
108 #else
109
110 /* Determine if the dynamic maximum number of cores is 0. If so, default it
111 to the compile-time maximum. */
112 if (_tx_thread_smp_max_cores == 0)
113 {
114
115 /* Default to the compile-time maximum. */
116 _tx_thread_smp_max_cores = TX_THREAD_SMP_MAX_CORES;
117 }
118
119 /* Call low-level SMP initialize. */
120 _tx_thread_smp_low_level_initialize(_tx_thread_smp_max_cores);
121 #endif
122 }
123