Click here for back issues.
https://www.simulationroom999.com/blog/diagnostic-communication-en-back-issue/
Introduction.
Let’s simulate ISO-TP. series.
This time, we will work on pulling out only CanTp from A-COMSTACK.
Which is AUTOSAR-CanTp?
Now, let’s pull out only CanTp from A-COMSTACK.
Specifically, cantp.c is the main body of CanTp.
However, cantp.c alone is not complete.
Various header files are required for dependency reasons.
We need to work in the following flow.
(1) Bring cantp.c
(2) Gather header files so that the build of cantp.c may pass.
(2) is especially hard.
Required files
For now, let’s list the header files that are needed.
Compiler_Cfg.h
ComStack_Types.h
MemMap.h
Os.h
Platform_Types.h
Rte_Os_Type.h
Rte_Type.h
Std_Types.h
t_syslog.h
CanTp.h
CanTp_Cbk.h
CanTp_Cfg.h
Compiler.h
SchM_CanTp.h
CanIf.h
PduR_CanTp.h
Since the environment is designed to run on TOPPERS ATK2, it is also necessary to bring headers from there.
TOPPERS ATK2
Then, we should have a stub to realize main function, timer interrupt, and exclusive control, and we should be good for now.
Timer interrupt emulation
We need to realize a timer interrupt.
Here, we use the Windows multimedia timer.
Specifically, we use the timeSetEvent API.
The point is that it uses a “multimedia timer”.
This is different from the normal timer API.
The usage is similar, and the callback method is the same.
The difference is that a real-time thread is running in the background.
This makes it far more accurate than a normal timer.
In this case, we want accuracy on the order of 1[ms], so we decided to use a multimedia timer.
The concrete code is as follows.
// Callback function called as a timer event
static void CALLBACK
callback(unsigned int timerID, unsigned int msg, unsigned int usrParam, unsigned int dw1, unsigned int dw2)
{
_pcallback();
}
void setcallback( void (*pcallback)())
{
unsigned int timer;
_pcallback = pcallback;
// Start of timer event
timer = timeSetEvent(1, 1, (LPTIMECALLBACK) callback, (DWORD) NULL, TIME_PERIODIC);
if(timer == 0) { printf("Failed to generate timer event\n"); exit(0); }
// loop
while(1) {
Sleep(5000);
}
// End of timer event
timeKillEvent(timer);
}
It is an infinite loop, but this time there is no program exit condition, so the assumption is that the entire process is terminated.
This allows an emulation equivalent to a ms-order timer interrupt.
Exclusion control
Exclusion control also uses Win32API.
Specifically, Mutex.
If you include Windows-related headers on the AUTOSAR code side, type definitions may conflict, so it is better to wrap them in a function and separate them as a separate source.
The concrete code is as follows.
void* _CreateMutex(void* lpMutexAttributes, int bInitialOwner,char* lpName)
{
return CreateMutex( (LPSECURITY_ATTRIBUTES)lpMutexAttributes, bInitialOwner, lpName);
}
unsigned int _WaitForSigleObject(void* hHandle, unsigned int dwMilliseconds )
{
return WaitForSingleObject( hHandle,dwMilliseconds);
}
int _ReleaseMutex( void* hMutex )
{
return ReleaseMutex( hMutex );
}
Mutex is used as an entry and exit point for interrupt-emulated callback functions.
For example, the following is an example of a receive interrupt callback.
int rx_interrupt( void *param, canMessage* msg )
{
_WaitForSigleObject( hMutex,-1);
/* processing of something */
_ReleaseMutex(hMutex);
return 0;
}
One problem is that multiple interrupts cannot be emulated.
However, this time, we are not concerned about multiple interrupts, since CanTp only needs to recognize them as interrupts.
I think we have at least the bare minimum of what we need to do.
I think we will face the AUTOSAR specification next time.
Conclusion
- The body of CanTp for A-COMSTACK is cantp.c.
- Many header files also need to be brought in.
- Timer interrupt and exclusion are realized by Win32API.
Click here for back issues.
コメント