本文介紹RTE的運行體(runnable)。
An AUTOSAR component defines one or more "runnable entities". A runnable entity is a piece of code with a single entry point and an associate set of data. A softwarecomponent description provides definitions for each runnable entity within the softwarecomponent.
For components implemented using C or C++ the entry point of a runnable entity is implemented by a function with global scope defined within a software-component's source code. The following sections consider the function signature and prototype.
組件內部可以定義一組運行體。每個運行體內部有一個入口和與之關聯的數據。
例如:
構件運行體為:
/* Model step function */ void Runnable_Component1 ( void ) { /* local block i/o variables */ real_T rtb_BufferInput_InsertedFor_Dat; { uint8_T rtb_BufferInput_InsertedFor_Eve; /* SignalConversion: '<Root>/BufferInput_InsertedFor_DataIN_at_outport_0' incorporates: * Inport: '<Root>/DataIN' */ rtb_BufferInput_InsertedFor_Dat = Rte_IRead_Runnable_Component1_DataINPort_Data(); /* SignalConversion: '<Root>/BufferInput_InsertedFor_Event_at_outport_0' incorporates: * Inport: '<Root>/Event' */ Rte_Read_EventPort_Event ( &rtb_BufferInput_InsertedFor_Eve ); /* Outputs for enable SubSystem: '<Root>/Runable1' incorporates: * EnablePort: '<S1>/Enable' */ if ( rtb_BufferInput_InsertedFor_Eve > 0 ) { /* S-Function (sfun_autosar_clientop): '<S1>/BSW_ADD' incorporates: * Constant: '<Root>/1' */ Rte_Call_AddPort_Add ( rtb_BufferInput_InsertedFor_Dat, Component1_P._Value, &Component1_B.BSW_ADD ); } /* end of Outputs for SubSystem: '<Root>/Runable1' */ /* SignalConversion: '<Root>/BufferOutput_InsertedFor_DataOUT_at_inport_0' */ Rte_Write_DataOutPort_Data ( Component1_B.BSW_ADD ); } }
使用一個xml描述這個運行體(可以看作是定義階段所掃描生成的),結構如下:
<RUNNABLE-ENTITY> <SHORT-NAME>Runnable_Component1</SHORT-NAME> <CAN-BE-INVOKED-CONCURRENTLY>false</CAN-BE-INVOKED-CONCURRENTLY> <DATA-READ-ACCESSS> <DATA-READ-ACCESS> <SHORT-NAME>IN_DataINPort_Data</SHORT-NAME> <DATA-ELEMENT-IREF> <R-PORT-PROTOTYPE-REF DEST="R-PORT-PROTOTYPE">/SWC/Component1/DataINPort</R-PORT-PROTOTYPE-REF> <DATA-ELEMENT-PROTOTYPE-REF DEST="DATA-ELEMENT-PROTOTYPE">/Component1/if/MathDataInterface/Data</DATA-ELEMENT-PROTOTYPE-REF> </DATA-ELEMENT-IREF> </DATA-READ-ACCESS> </DATA-READ-ACCESSS> <DATA-RECEIVE-POINTS> <DATA-RECEIVE-POINT> <SHORT-NAME>IN_EventPort_Event</SHORT-NAME> <DATA-ELEMENT-IREF> <R-PORT-PROTOTYPE-REF DEST="R-PORT-PROTOTYPE">/SWC/Component1/EventPort</R-PORT-PROTOTYPE-REF> <DATA-ELEMENT-PROTOTYPE-REF DEST="DATA-ELEMENT-PROTOTYPE">/Component1/if/EventInterface/Event</DATA-ELEMENT-PROTOTYPE-REF> </DATA-ELEMENT-IREF> </DATA-RECEIVE-POINT> </DATA-RECEIVE-POINTS> <DATA-SEND-POINTS> <DATA-SEND-POINT> <SHORT-NAME>OUT_DataOutPort_Data</SHORT-NAME> <DATA-ELEMENT-IREF> <P-PORT-PROTOTYPE-REF DEST="P-PORT-PROTOTYPE">/SWC/Component1/DataOutPort</P-PORT-PROTOTYPE-REF> <DATA-ELEMENT-PROTOTYPE-REF DEST="DATA-ELEMENT-PROTOTYPE">/Component1/if/MathDataInterface/Data</DATA-ELEMENT-PROTOTYPE-REF> </DATA-ELEMENT-IREF> </DATA-SEND-POINT> </DATA-SEND-POINTS> <SERVER-CALL-POINTS> <SYNCHRONOUS-SERVER-CALL-POINT> <SHORT-NAME>SC_AddPort_Add</SHORT-NAME> <OPERATION-IREFS> <OPERATION-IREF> <R-PORT-PROTOTYPE-REF DEST="R-PORT-PROTOTYPE">/SWC/Component1/AddPort</R-PORT-PROTOTYPE-REF> <OPERATION-PROTOTYPE-REF DEST="OPERATION-PROTOTYPE">/BSW/if/BSW_ADD/Add</OPERATION-PROTOTYPE-REF> </OPERATION-IREF> </OPERATION-IREFS> <TIMEOUT>0.000001</TIMEOUT> </SYNCHRONOUS-SERVER-CALL-POINT> </SERVER-CALL-POINTS> <SYMBOL>Runnable_Component1</SYMBOL> </RUNNABLE-ENTITY>
上面的<SYMBOL>Runnable_Component1</SYMBOL> 提示鏈接器連接這個符號。
1. 簽名(Signature)
The definition of all runnable entities, whatever the RTEEvent that triggers their execution, follows the same basic form. [rte sws 1126]
<void|Std_ReturnType> <name>([IN Rte_Instance <instance>], [role parameters])
Where <name> 3 is the symbol describing the runnable's entry point rte sws in 0053. The definition of the role parameters is defined in Section 5.7.3.
所有運行體,不管是怎樣觸發,函數定義都是下面這個格式:
<void|Std_ReturnType> <name>([IN Rte_Instance <instance>], [role parameters])
如前面的例子:
void Runnable_Component1(void)
參數的意義為:
IN Rte_Instance <instance> - 本實體的指針,因為一個構件可以多重實例化,所以有時候必須要判斷一下自己是哪個實體。
role parameters - 指明是誰觸發的這個運行體,有時候一個運行體可以被多個事件觸發,需要確定一下自己是哪個事件出發的。
Section 5.2.6.4 contains details on a recommended naming conventions for runnable entities based on the RTEEvent that triggers the runnable entity. The recommended naming convention makes explicit the functions that implement runnable entities as well as clearly associating the runnable entity and the applicable data element or operation.
2. 入口點原型(Entry Point Prototype)
The RTE determines the required role parameters, and hence the prototype of the entry point, for a runnable entity based on information in the input information (see Appendix B). The entry point defined in the component source must be compatible with the parameters passed by the RTE when the runnable entity is triggered by the RTE and therefore the RTE generator is required to emit a prototype for the function. [rte sws 1132] The RTE generator shall emit a prototype for the runnable entity's entry point in the application header file.
RTE通過角色參數判斷入口點類型,所以運行體入口必須要定義得復合參數類型,以便於RTE生成函數的觸發。
The prototype for a function implementing the entry point of a runnable entity is emitted for both "RTE Contract" and "RTE Generation" phases. The function name for the prototype is the runnable entity's entry point. The prototype of the entry point function includes the runnable entity's instance handle and its role parameters, see Figure 5.2.
[rte sws 1016] The function implementing the entry point of a runnable entity shall define an instance handle as the first formal parameter.
第一個參數必須是組件實例。
The RTE will ensure that when the runnable entity is triggered the instance handle parameter indicates the correct component instance. The remaining parameters passed to the runnable entity depend on the RTEEvent that triggers execution of the runnable entity.
[rte sws 1130] A function implementing a runnable entity entry point shall only have the return type Std_ReturnType, if the runnable entity represents a server operation and the AUTOSAR interface description of that client server communication lists potential application errors. All other functions implementing a runnable entity entry point shall have a return type of void.
如果運行體是一個server operation,則返回正確與否,否則返回void。
[rte sws ext 2704] Only the least significant six bit of the return value of a server runnable shall be used by the application to indicate an error. The upper two bit shall be zero. See also rte sws 2573.
返回值的最高2位必須是0。