Commit 9e878798 authored by Juergen Haug's avatar Juergen Haug
Browse files

[gen.c] added check for message sizes

Change-Id: I8c61e19df3702748dad6eb1d9c6ae75b5044e32e
parent 33763117
......@@ -15,12 +15,15 @@
package org.eclipse.etrice.generator.c.gen
import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.HashMultimap
import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.ArrayList
import java.util.Collection
import java.util.HashMap
import java.util.HashSet
import org.eclipse.etrice.core.common.base.LiteralType
import org.eclipse.etrice.core.common.base.StringLiteral
import org.eclipse.etrice.core.common.converter.TimeConverter
import org.eclipse.etrice.core.etmap.util.ETMapUtil
......@@ -33,20 +36,19 @@ import org.eclipse.etrice.core.genmodel.etricegen.PortInstance
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
import org.eclipse.etrice.core.room.CommunicationType
import org.eclipse.etrice.core.room.EnumerationType
import org.eclipse.etrice.core.room.Message
import org.eclipse.etrice.core.room.Port
import org.eclipse.etrice.core.room.PrimitiveType
import org.eclipse.etrice.core.room.SAP
import org.eclipse.etrice.core.room.SPP
import org.eclipse.etrice.core.room.util.RoomHelpers
import org.eclipse.etrice.generator.base.io.IGeneratorFileIO
import org.eclipse.etrice.generator.c.setup.GeneratorOptionsHelper
import org.eclipse.etrice.generator.fsm.base.IntelligentSeparator
import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.TypeHelpers
import org.eclipse.etrice.generator.fsm.base.IntelligentSeparator
import org.eclipse.etrice.core.common.base.LiteralType
import org.eclipse.etrice.core.room.EnumerationType
import org.eclipse.etrice.core.room.PrimitiveType
import org.eclipse.etrice.core.room.Message
@Singleton
class NodeGen {
......@@ -135,7 +137,7 @@ class NodeGen {
val nr = ETMapUtil::getNodeRef(ssi)
val ssc = ssi.subSystemClass
val clsname = nr.name+"_"+ssi.name
val threads = nr.type.threads.filter(t|usedThreads.contains(t))
val threads = nr.type.threads.filter(t|usedThreads.contains(t)).toList
val loggedPorts = ssi.eAllContents.filter(PortInstance)
.filter[!relay && port.conjugated && protocol.commType == CommunicationType.DATA_DRIVEN].toList
......@@ -183,6 +185,12 @@ class NodeGen {
#include "nr.getInstSourceFileName(ssi)"
#include "nr.getDispSourceFileName(ssi)"
/* check message data fit into message queues */
FOR thread: threads.sortBy[name]
typedef char assert_thread.name_msg_size[(ET_MESSAGE_SIZE(0) <= thread.name.toUpperCase_BLOCK_SIZE) *2-1];
ENDFOR
ssi.generateMessageSizeCheck
static void clsname_initMessageServices(void) {
ET_MSC_LOGGER_SYNC_ENTRY("clsname", "initMessageServices")
{
......@@ -807,4 +815,31 @@ class NodeGen {
val annotations = acs.map[annotations.filter[type.name == 'SubSystemUserCode']].flatten
annotations.map[attributes].flatten.map[value].filter(StringLiteral).map[value].join(NEWLINE)
}
private def generateMessageSizeCheck(SubSystemInstance ssi) {
val ais = ssi.allContainedInstances
// actor -> receiving data types
val actor2types = ArrayListMultimap.create => [ multiMap |
ais.forEach [ ai |
multiMap.putAll(ai, ai.orderedIfItemInstances.filter[!peers.isEmpty].
map[interfaceItem.getMessageListDeep(false)].flatten.map[data?.refType].filterNull.filter[!ref].map[type]
)
]
]
// data type -> receiving threads
val type2threads = HashMultimap.create => [ multiMap |
ais.forEach [ ai |
actor2types.get(ai).forEach [ type |
multiMap.put(type, ETMapUtil::getMappedThread(ai).thread)
]
]
]
// compile assert: data type size <= smallest thread block size
type2threads.keySet.sortBy[name].map [ type |
val smallestThread = type2threads.get(type).sortBy[msgblocksize].head
'''
typedef char assert_type.name_msg_size[(ET_MESSAGE_SIZE(sizeof(type.typeName)) <= smallestThread.name.toUpperCase_BLOCK_SIZE) *2-1];
'''
].join
}
}
......@@ -27,6 +27,8 @@
ET_EXTERN_C_BEGIN
#define ET_MESSAGE_SIZE(dataSize) (MEM_CEIL(sizeof(etMessage)) + dataSize)
/**
* the message structure
*/
......
......@@ -27,19 +27,17 @@ void etPort_receive(const etPort* self, const etMessage* msg) {
}
*/
void etPort_sendMessage(const etPort* self, etInt16 evtId, int size, void* data) {
int offset = MEM_CEIL(sizeof(etMessage));
int totalSize = offset+size;
etMessage* msg = NULL;
void etPort_sendMessage(const etPort *self, etInt16 evtId, int size, void *data) {
ET_MSC_LOGGER_SYNC_ENTRY("etPort", "sendMessage")
if(self->msgService == NULL) return;
msg = etMessageService_getMessageBuffer(self->msgService, totalSize);
if (msg!=NULL) {
if (self->msgService == NULL) return;
etMessage *msg = etMessageService_getMessageBuffer(self->msgService, ET_MESSAGE_SIZE(size));
if (msg != NULL) {
msg->address = self->peerAddress;
msg->evtID = evtId;
if (size>0 && data!=NULL) {
memcpy(((char*)msg)+offset, data, size);
if (size > 0 && data != NULL) {
int offset = MEM_CEIL(sizeof(etMessage));
memcpy(((char*) msg) + offset, data, size);
}
etMessageService_pushMessage(self->msgService, msg);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment