Skip to content

Commit

Permalink
Initial work on Events (#373)
Browse files Browse the repository at this point in the history
- created declaration for PAL events
- move declaration from PAL header to to events header
- update CMakes to include these
- add implementation of bool timer event in ChibiOS
- enable bool timer event in interpreter
- adjust managed heap size for Discovery4 target
- update code formating to improve readability
- update managed heap size for ST_STM32F429I_DISCOVERY target

Signed-off-by: José Simões <[email protected]>
  • Loading branch information
josesimoes authored Jun 30, 2017
1 parent a123e0f commit 0347c48
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CMake/Modules/FindNF_CoreCLR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ set(NF_CoreCLR_SRCS

# PAL stubs
COM_stubs.c
Events_stubs.cpp

)

Expand Down Expand Up @@ -187,6 +188,7 @@ foreach(SRC_FILE ${NF_CoreCLR_SRCS})

# PAL stubs
${PROJECT_SOURCE_DIR}/src/PAL/COM
${PROJECT_SOURCE_DIR}/src/PAL/Events

CMAKE_FIND_ROOT_PATH_BOTH
)
Expand Down
12 changes: 7 additions & 5 deletions src/CLR/Core/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,19 @@ HRESULT CLR_RT_Thread::Execute()
_ASSERTE(!CLR_EE_DBG_IS( Stopped ));
#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING)

// UNDONE: FIXME
// ::Events_SetBoolTimer( (bool*)&m_timeQuantumExpired, CLR_RT_Thread::c_TimeQuantum_Milliseconds );
::Events_SetBoolTimer( (bool*)&m_timeQuantumExpired, CLR_RT_Thread::c_TimeQuantum_Milliseconds );

while(m_timeQuantumExpired == false && !CLR_EE_DBG_IS( Stopped ))
{
CLR_RT_StackFrame* stack;

if(SUCCEEDED(hr))
{
hr = Execute_Inner(); if(SUCCEEDED(hr)) NANOCLR_LEAVE();
hr = Execute_Inner();
if(SUCCEEDED(hr))
{
NANOCLR_LEAVE();
}
}

switch(hr)
Expand Down Expand Up @@ -603,8 +606,7 @@ HRESULT CLR_RT_Thread::Execute()

g_CLR_RT_ExecutionEngine.m_currentThread = currentThreadSav;

// UNDONE: FIXME
// ::Events_SetBoolTimer( NULL, 0 );
::Events_SetBoolTimer( NULL, 0 );

NANOCLR_CLEANUP_END();
}
Expand Down
24 changes: 24 additions & 0 deletions src/PAL/Events/Events_stubs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//

#include <nanoPAL_Events.h>

__nfweak bool Events_Initialize()
{
NATIVE_PROFILE_PAL_EVENTS();
return true;
}

__nfweak bool Events_Uninitialize()
{
NATIVE_PROFILE_PAL_EVENTS();
return true;
}

__nfweak void Events_SetBoolTimer( bool* timerCompleteFlag, unsigned int millisecondsFromNow )
{
NATIVE_PROFILE_PAL_EVENTS();
}
63 changes: 32 additions & 31 deletions src/PAL/Include/nanoPAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <nanoPAL_Time.h>
#include <nanoHAL_v2.h>
#include <nanoPAL_BlockStorage.h>
#include <nanoPAL_Events.h>

//#include <AsyncProcCalls_decl.h>

Expand Down Expand Up @@ -152,50 +153,50 @@ struct HAL_COMPLETION : public HAL_CONTINUATION

//#include <Power_decl.h> (must be before events_decl.h)

//
// !!! KEEP IN SYNC WITH Microsoft.SPOT.Hardware.SleepLevel !!!
//
enum SLEEP_LEVEL
{
SLEEP_LEVEL__AWAKE = 0x00,
SLEEP_LEVEL__SELECTIVE_OFF = 0x10,
SLEEP_LEVEL__SLEEP = 0x20,
SLEEP_LEVEL__DEEP_SLEEP = 0x30,
SLEEP_LEVEL__OFF = 0x40,
};













//#include <events_decl.h>

// destructive read system event flags
unsigned int Events_Get( unsigned int EventsOfInterest );

// non-destructive read system event flags
unsigned int Events_MaskedRead( unsigned int EventsOfInterest );


// returns 0 for timeout, non-zero are events that have happened and were asked to be waiting on (non-destructive read)
// timeout limit is about 3034 milliseconds currently
// values greater than this are capped to this

// sleep relative time into the future, or until a SystemEvent occurs, which occurs first
// timeout is a non-negative number of 1mSec ticks, or -1 (any negative value) to sleep forever until a SystemEvent occurs

// Events_WaitForEvents(0, n), sleeps for n milliseconds independent of events
// Events_WaitForEvents(0, EVENTS_TIMEOUT_INFINITE) sleeps forever. Don't do that.
// Events_WaitForEvents(flags, EVENTS_TIMEOUT_INFINITE) waits forever for that event.

#define EVENTS_TIMEOUT_INFINITE 0xFFFFFFFF

unsigned int Events_WaitForEvents ( unsigned int sleepLevel, unsigned int WakeupSystemEvents, unsigned int Timeout_Milliseconds );
unsigned int Events_WaitForEventsInternal( unsigned int sleepLevel, unsigned int WakeupSystemEvents, unsigned int Timeout_Milliseconds );

__inline unsigned int Events_WaitForEvents( unsigned int WakeupSystemEvents, unsigned int Timeout_Milliseconds )
{
return Events_WaitForEvents( SLEEP_LEVEL__SLEEP, WakeupSystemEvents, Timeout_Milliseconds );
}

void Events_SetBoolTimer(bool* TimerCompleteFlag, unsigned int MillisecondsFromNow);






















//#include <palevent_decl.h>
Expand Down
61 changes: 61 additions & 0 deletions src/PAL/Include/nanoPAL_Events.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#ifndef _NANOPAL_EVENTS_H_
#define _NANOPAL_EVENTS_H_ 1

#include <nanoWeak.h>
#include <netmf_errors.h>

//
// !!! KEEP IN SYNC WITH Microsoft.SPOT.Hardware.SleepLevel !!!
//
enum SLEEP_LEVEL
{
SLEEP_LEVEL__AWAKE = 0x00,
SLEEP_LEVEL__SELECTIVE_OFF = 0x10,
SLEEP_LEVEL__SLEEP = 0x20,
SLEEP_LEVEL__DEEP_SLEEP = 0x30,
SLEEP_LEVEL__OFF = 0x40,
};

#define EVENTS_TIMEOUT_INFINITE 0xFFFFFFFF

#if NATIVE_PROFILE_PAL & NATIVE_PROFILE_PAL_EVENTS__flag
#define NATIVE_PROFILE_PAL_EVENTS() Native_Profiler profiler_obj
#else
#define NATIVE_PROFILE_PAL_EVENTS()
#endif

// destructive read system event flags
unsigned int Events_Get( unsigned int EventsOfInterest );

// non-destructive read system event flags
unsigned int Events_MaskedRead( unsigned int EventsOfInterest );

// returns 0 for timeout, non-zero are events that have happened and were asked to be waiting on (non-destructive read)
// timeout limit is about 3034 milliseconds currently
// values greater than this are capped to this

// sleep relative time into the future, or until a SystemEvent occurs, which occurs first
// timeout is a non-negative number of 1mSec ticks, or -1 (any negative value) to sleep forever until a SystemEvent occurs

// Events_WaitForEvents(0, n), sleeps for n milliseconds independent of events
// Events_WaitForEvents(0, EVENTS_TIMEOUT_INFINITE) sleeps forever. Don't do that.
// Events_WaitForEvents(flags, EVENTS_TIMEOUT_INFINITE) waits forever for that event.

unsigned int Events_WaitForEvents ( unsigned int sleepLevel, unsigned int WakeupSystemEvents, unsigned int Timeout_Milliseconds );
unsigned int Events_WaitForEventsInternal( unsigned int sleepLevel, unsigned int WakeupSystemEvents, unsigned int Timeout_Milliseconds );

__inline unsigned int Events_WaitForEvents( unsigned int WakeupSystemEvents, unsigned int Timeout_Milliseconds )
{
return Events_WaitForEvents( SLEEP_LEVEL__SLEEP, WakeupSystemEvents, Timeout_Milliseconds );
}

__nfweak bool Events_Initialize();
__nfweak bool Events_Uninitialize();
__nfweak void Events_SetBoolTimer( bool* timerCompleteFlag, unsigned int millisecondsFromNow );

#endif //_NANOPAL_EVENTS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAG
# the size of the CLR managed heap is defined here
###################################################
set_property(TARGET ${NANOBOOTER_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x0")
set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x2A758")
set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x2A748")


set(NANOBOOTER_HEX_FILE ${PROJECT_SOURCE_DIR}/build/${NANOBOOTER_PROJECT_NAME}.hex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAG
# the size of the CLR managed heap is defined here
###################################################
set_property(TARGET ${NANOBOOTER_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x0")
set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x1A680")
set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x1A670")


set(NANOBOOTER_HEX_FILE ${PROJECT_SOURCE_DIR}/build/${NANOBOOTER_PROJECT_NAME}.hex)
Expand Down
6 changes: 6 additions & 0 deletions targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/CLR_Star
# append target HAL source files
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_Time.cpp")

# append target PAL source files
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/targetPAL_Events.cpp")

# append other CLR core files
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/CLRStartup.cpp")
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/Memory.cpp")
Expand All @@ -43,5 +46,8 @@ list(APPEND TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
list(APPEND TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core)

# append PAL include directory
list(APPEND TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/PAL/Include)

# make var global
set(TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS} CACHE INTERNAL "make global")
48 changes: 48 additions & 0 deletions targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Events.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include <nanoPAL_Events.h>
#include <nanoPAL.h>
#include <target_platform.h>
#include <hal.h>

// events timer
static virtual_timer_t eventsBoolTimer;

bool Events_Initialize()
{
NATIVE_PROFILE_PAL_EVENTS();
return true;
}

bool Events_Uninitialize()
{
NATIVE_PROFILE_PAL_EVENTS();

chVTResetI(&eventsBoolTimer);

return true;
}

static void local_Events_SetBoolTimer_Callback( void* arg )
{
NATIVE_PROFILE_PAL_EVENTS();
bool* timerCompleteFlag = (bool*)arg;

*timerCompleteFlag = true;
}

void Events_SetBoolTimer( bool* timerCompleteFlag, unsigned int millisecondsFromNow )
{
NATIVE_PROFILE_PAL_EVENTS();

// we assume only 1 can be active, abort previous just in case
chVTResetI(&eventsBoolTimer);

if(timerCompleteFlag != NULL)
{
chVTSetI(&eventsBoolTimer, MS2ST(millisecondsFromNow), local_Events_SetBoolTimer_Callback, timerCompleteFlag);
}
}

0 comments on commit 0347c48

Please sign in to comment.