Work progress but I encounter a pb again with the following code.
When calls are commented, I receive 1 so tp is correctly initialized (I suppose ).
But when I try to do only delay or delayNoInterrupt or call them with acquire and release, application became unresponsive. As it is very difficult to debug native code (if it can be !), I would like to know if I have forgotten Something obvious ?
TinyCLR_Result Interop_TestInterop_TestInterop_LedInterop::GetResult___I4(const TinyCLR_Interop_MethodData md) {
auto ip = (const TinyCLR_Interop_Provider*)md.ApiProvider.FindDefault(&md.ApiProvider, TinyCLR_Api_Type::InteropProvider);
TinyCLR_Interop_ManagedValue self;
TinyCLR_Interop_ManagedValue ret;
ret.Type = TinyCLR_Interop_ManagedValueType::I4;
ip->GetThisObject(ip, md.Stack, self);
ip->GetReturn(ip, md.Stack, ret);
auto tp = (const TinyCLR_Time_Provider*)md.ApiProvider.Find(&md.ApiProvider, "GHIElectronics.TinyCLR.NativeApis.STM32F4.TimeProvider", TinyCLR_Api_Type::TimeProvider);
if (tp != nullptr)
{
ret.Data.Numeric->I4 = 1;
// each of the following call conduct to a "crash"
//tp->Acquire(tp);
//tp->Delay(tp,100000ULL);
//tp->Release(tp);
}
else
{
ret.Data.Numeric->I4 = 0;
}
return TinyCLR_Result::Success;
}
Find returns const TinyCLR_Api_Info*, not const void* like FindBySelector, FindDefault, and FindByIndex. Those last three are helper methods that call Find and extract a specific implementation from the const TinyCLR_Api_Info* using the const void* Implementation member.
Try:
auto timeApi = md.ApiProvider.Find(&md.ApiProvider, "GHIElectronics.TinyCLR.NativeApis.STM32F4.TimeProvider", TinyCLR_Api_Type::TimeProvider);
if (timeApi != nullptr && timeApi->Count == 1) {
auto tp = (const TinyCLR_Time_Provider*)timeApi->Implementation;
if (tp != nullptr) {
//...
}
}
One note on the Implementation field. If Count is 0, then it’s nullptr as you’d expect. If it’s one, then it’s a pointer directly to the actual implementation. If it’s greater than one, then it’s an array of Count pointers to actual implementations.
#include "Device.h"
#include "../../Drivers/DevicesInterop/GHIElectronics_TinyCLR_InteropUtil.h"
#include "InterTest.h"
/*
how to call this intertest.h
*/
void STM32F4_Startup_OnSoftResetDevice(const TinyCLR_Api_Manager* apiManager, const TinyCLR_Interop_Manager* interopManager) {
DevicesInterop_Add(interopManager);
/*
how to include into firmware
*/
}