I'm currently using S32K311 with NXP MBDT on Simulink (R2024a), S32CT.
I have followed the examples of LIN provided on the MBDT, configured S32K311 as LIN Slave on LIN_Channel0 using S32CT. I need help implementing LIN Sleep and Wakeup functionality.
Here's what I have so far -
I have created a sample LDF and a sample test configuration on Vector CANoe. Created just 2 frames - command frame (Frame ID 0x00, PID 0x80) and Status frame (Frame ID 0x01, PID 0xC1). I am able to send Sleep request(0x3C 00 FF FF FF FF FF FF FF) using the same Config and observed that the Slave stops responding as soon as the Sleep request is sent. This is a snippet of LIN Trace.
Now from the Simulink model perspective, here is the implementation I followed.
Following the example, within 'Initialize' subsystem, I have LIN_WakeupInternal added.
Using LINIf_HeaderIndication, checking for Channel as LIN_Channel0 and PID as 0x3C for GoToSleep request as shown below
Inside, 0x3C Request subsystem
I have also added 'Lin_CheckWakeup' function and I monitored the checkWakeupStatus data store block (iniitalized to 1) on FreeMaster which always returns 0.
I have also read the Documentation on Lin and LinIf supported functionalities which talks about 'EcuM_WakeupSourceType' Is it something to do with enabling this option on S32CT?
Now, at this point, I don't know how to implement WakeUp functionality and resume the LIN Trace activity. I couldn't find any resources on this and I need help. Please let me know how to proceed.
Hi @beginner100,
From what I have gathered you have implemented a go to sleep functionality for your slave node which is triggered by the master node. After calling the GoToSleepInternal function, your LIN hardware should stop reacting to messages being sent on the bus as this is the intended behavior. So far, there seems to be no issue with the functionality of your application.
Would you like help implementing a triggered wakeup functionality separately from the triggered sleep functionality that you have already implemented? If so, please let me know which are the details of the behavior you expect your application to have.
As for the EcuM wakeup source - it is a separate wakeup mechanism that makes use of the EcuM driver. MBDT does not currently support implementing the associated callbacks with this driver from Simulink, which means you are required to implement them in C code. We recommend using the LinIf blocks for implementing the wakeup functionality as it can be done solely from Simulink, without requiring writing any code.
Hi @rares_butilca.
Yes, you got it right. Gotosleep is implemented. I need help implementing a triggered wakeup functionality as soon as a Wakeup request is sent from LIN Master (via Vector CANoe).
Coming to the expectation of the application that I'm working on, after a wakeup request is sent on LIN Master, all the data store parameters, internal counters, variables are to be initialized as well.
I see there's 'Initialize' block in the LIN Example (attached snippet below), can this be used to reset all the data store parameters, variables, any counters to their initial values upon wakeup ? It is definitely performing an internal wakeup and also checking wakeup status.
If you can send me a sample model or steps which can cover both Sleep and Wakeup functionalities, that would be much appreciated. I just want to understand the right way of implementing these functionalities.
Thank you!
Hi again,
The initialize block is ran once at the beginning of the application before anything else in the model. That block should contain initialization logic for your application, such as turning on external peripherals, setting up internal peripherals, etc. In our example, it is used to wake up the LIN channel as to prepare it to receive messages on the bus right away.
For understanding how to model a triggered wakeup, let's break it down into its components and first understand what each function is used for.
Figure 1
CheckWakeup is used to validate whether the Lin channel has been woken up either internally or by the bus it is connected to. This is the function you want to use to check whether a wakeup call has been detected on the bus by the LIN hardware.
Figure 2
LinIf is composed of functions that are being called by various other drivers to notify various events. The WakeupConfirmation function is the one you are looking for since it is going to be called by CheckWakeup when a wakeup is successfully detected.
The LinIf block allows you to attach a logic to these functions. The above image shows how to declare what the function is going to do by attaching a function call subsystem that implements the logic of WakeupConfirmation. Here you should be implementing the behavior of your application on a wakeup detection.
Figure 3
WakeUpInternal is used for waking up your channel without sending a wakeup signal on the bus - this is the function you want to use as a slave node. This function does the actual wakeup of the channel (makes the channel exit its sleeping state) and should be called by your application before expecting to receive any messages on the bus. The recommendation here is to use this function within WakeupConfirmation so as to wake up your channel right upon a wakeup trigger detection.
So as to conclude, your application should look something like this:
1) Use an initialize block only if you have something you want your application to do before anything else - at the beginning.
2) Place the CheckWakeup function(Figure 1) in your model where you want the wakeup detection to be checked.
3) Place a LinIf block with the function set to WakeupConfirmation along with a function call subsystem in your top model or a non-triggered subsystem so as to declare the behavior of the said function. (Here you can also reset the data stores that you mentioned, initialize the counter, etc.)
4) Do not forget about doing the actual wakeup of the channel. Use the function WakeupInternal (Figure 3) inside the function call subsystem mentioned at the previous step.
NOTE: For being able to use the WakeupConfirmation successfully, you should have the settings Lin Channel Wake UP Support enabled in the configuration of your LIN channel.