AzureMXChip/MXCHIPAZ3166/core/lib/threadx/ports/win32/vs_2019/src/tx_initialize_low_level.c
VOID   _tx_initialize_low_level(VOID)
{

/* Deprecate TX_WIN32_MULTI_CORE build option and default to restricting
   execution to one core.  */

#ifndef TX_WIN32_BYPASS_AFFINITY_SETUP

    /* Limit this ThreadX simulation on Win32 to a single core.  */
    if (SetProcessAffinityMask( GetCurrentProcess(), 1 ) == 0)
    {
    
        /* Error restricting the process to one core.  */
        printf("ThreadX Win32 error restricting the process to one core!\n");
        while(1)
        {
        }
    }
#endif

    /* Pickup the first available memory address.  */

    /* Save the first available memory address.  */
    _tx_initialize_unused_memory =  malloc(TX_WIN32_MEMORY_SIZE);

    /* Pickup the unique Id of the current thread, which will also be the Id of the scheduler.  */
    _tx_win32_scheduler_id =        GetCurrentThreadId();

    /* Create the system critical section mutex. This is used by the system to block all other access,
       analogous to an interrupt lockout on an embedded target.  */
    _tx_win32_critical_section.tx_win32_critical_section_mutex_handle =  CreateMutex(NULL, FALSE, NULL);
    _tx_win32_critical_section.tx_win32_critical_section_nested_count =  0;
    _tx_win32_critical_section.tx_win32_critical_section_owner =         0;
       
    /* Create the semaphore that regulates when the scheduler executes.  */
    _tx_win32_scheduler_semaphore =  CreateSemaphore(NULL, 0, 1, NULL);

    /* Initialize the global interrupt disabled flag.  */
    _tx_win32_global_int_disabled_flag =  TX_FALSE;
    
    /* Setup periodic timer interrupt.  */
    _tx_win32_timer_handle =
        CreateThread(NULL, 0, _tx_win32_timer_interrupt, (LPVOID) &_tx_win32_timer_handle,CREATE_SUSPENDED, &_tx_win32_timer_id);

    /* Check for a good thread create.  */
    if (!_tx_win32_timer_handle)
    {

        /* Error creating the timer interrupt.  */
        printf("ThreadX Win32 error creating timer interrupt thread!\n");
        while(1)
        {
        }
    }

    /* Otherwise, we have a good thread create.  Now set the priority to
       a level lower than the system thread but higher than the application
       threads.  */
    SetThreadPriority(_tx_win32_timer_handle, THREAD_PRIORITY_BELOW_NORMAL);

    /* Done, return to caller.  */
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _tx_initialize_low_level                          Win32/Visual      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    William E. Lamie, Microsoft Corporation                             */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function is responsible for any low-level processor            */
/*    initialization, including setting up interrupt vectors, setting     */
/*    up a periodic timer interrupt source, saving the system stack       */
/*    pointer for use in ISR processing later, and finding the first      */
/*    available RAM memory address for tx_application_define.             */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    CreateMutex                           Win32 create mutex            */
/*    CreateThread                          Win32 create thread           */
/*    CreateSemaphore                       Win32 create semaphore        */
/*    GetCurrentThreadId                    Win32 get current thread ID   */
/*    SetProcessAffinityMask                Win32 process affinity set    */
/*    SetThreadPriority                     Win32 set thread priority     */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    _tx_initialize_kernel_enter           ThreadX entry function        */
/*                                                                        */
/*  RELEASE HISTORY                                                       */
/*                                                                        */
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  09-30-2020     William E. Lamie         Initial Version 6.1           */
/*                                                                        */
/**************************************************************************/
FUNCTION                                               RELEASE



William E. Lamie, Microsoft Corporation

DESCRIPTION

This function is responsible for any low-level processor
initialization, including setting up interrupt vectors, setting
up a periodic timer interrupt source, saving the system stack
pointer for use in ISR processing later, and finding the first
available RAM memory address for tx_application_define.

INPUT

None

OUTPUT

None

CALLS

CreateMutex                           Win32 create mutex
CreateThread                          Win32 create thread
CreateSemaphore                       Win32 create semaphore
GetCurrentThreadId                    Win32 get current thread ID
SetProcessAffinityMask                Win32 process affinity set
SetThreadPriority                     Win32 set thread priority

CALLED BY



RELEASE HISTORY

DATE              NAME                      DESCRIPTION


FUNCTION RELEASE William E . Lamie Microsoft Corporation DESCRIPTION This function is responsible for any low - level processor initialization including setting up interrupt vectors setting up a periodic timer interrupt source saving the system stack pointer for use in ISR processing later and finding the first available RAM memory address for tx_application_define . INPUT None OUTPUT None CALLS CreateMutex Win32 create mutex CreateThread Win32 create thread CreateSemaphore Win32 create semaphore GetCurrentThreadId Win32 get current thread ID SetProcessAffinityMask Win32 process affinity set SetThreadPriority Win32 set thread priority CALLED BY RELEASE HISTORY DATE NAME DESCRIPTION
VOID   _tx_initialize_low_level(VOID)
{
#ifndef TX_WIN32_BYPASS_AFFINITY_SETUP
    if (SetProcessAffinityMask( GetCurrentProcess(), 1 ) == 0)
    {
        printf("ThreadX Win32 error restricting the process to one core!\n");
        while(1)
        {
        }
    }
#endif
    _tx_initialize_unused_memory =  malloc(TX_WIN32_MEMORY_SIZE);
    _tx_win32_scheduler_id =        GetCurrentThreadId();
    _tx_win32_critical_section.tx_win32_critical_section_mutex_handle =  CreateMutex(NULL, FALSE, NULL);
    _tx_win32_critical_section.tx_win32_critical_section_nested_count =  0;
    _tx_win32_critical_section.tx_win32_critical_section_owner =         0;
    _tx_win32_scheduler_semaphore =  CreateSemaphore(NULL, 0, 1, NULL);
    _tx_win32_global_int_disabled_flag =  TX_FALSE;
    _tx_win32_timer_handle =
        CreateThread(NULL, 0, _tx_win32_timer_interrupt, (LPVOID) &_tx_win32_timer_handle,CREATE_SUSPENDED, &_tx_win32_timer_id);
    if (!_tx_win32_timer_handle)
    {
        printf("ThreadX Win32 error creating timer interrupt thread!\n");
        while(1)
        {
        }
    }
    SetThreadPriority(_tx_win32_timer_handle, THREAD_PRIORITY_BELOW_NORMAL);
}
VOID _tx_initialize_low_level ( VOID ) { #ifndef TX_WIN32_BYPASS_AFFINITY_SETUP if ( SetProcessAffinityMask ( GetCurrentProcess ( ) , 1 ) == 0 ) { printf ( " \n " ) ; while ( 1 ) { } } #endif _tx_initialize_unused_memory = malloc ( TX_WIN32_MEMORY_SIZE ) ; _tx_win32_scheduler_id = GetCurrentThreadId ( ) ; _tx_win32_critical_section . tx_win32_critical_section_mutex_handle = CreateMutex ( NULL , FALSE , NULL ) ; _tx_win32_critical_section . tx_win32_critical_section_nested_count = 0 ; _tx_win32_critical_section . tx_win32_critical_section_owner = 0 ; _tx_win32_scheduler_semaphore = CreateSemaphore ( NULL , 0 , 1 , NULL ) ; _tx_win32_global_int_disabled_flag = TX_FALSE ; _tx_win32_timer_handle = CreateThread ( NULL , 0 , _tx_win32_timer_interrupt , ( LPVOID ) & _tx_win32_timer_handle , CREATE_SUSPENDED , & _tx_win32_timer_id ) ; if ( ! _tx_win32_timer_handle ) { printf ( " \n " ) ; while ( 1 ) { } } SetThreadPriority ( _tx_win32_timer_handle , THREAD_PRIORITY_BELOW_NORMAL ) ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE
/* Deprecate TX_WIN32_MULTI_CORE build option and default to restricting
   execution to one core.  */ /* Limit this ThreadX simulation on Win32 to a single core.  */ /* Error restricting the process to one core.  */ /* Pickup the first available memory address.  */ /* Save the first available memory address.  */ /* Pickup the unique Id of the current thread, which will also be the Id of the scheduler.  */ /* Create the system critical section mutex. This is used by the system to block all other access,
       analogous to an interrupt lockout on an embedded target.  */ /* Create the semaphore that regulates when the scheduler executes.  */ /* Initialize the global interrupt disabled flag.  */ /* Setup periodic timer interrupt.  */ /* Check for a good thread create.  */ /* Error creating the timer interrupt.  */ /* Otherwise, we have a good thread create.  Now set the priority to
       a level lower than the system thread but higher than the application
       threads.  */ /* Done, return to caller.  */