Skip to content

Commit

Permalink
Fix ringbuffers that are not consumed: they need to have events pushe…
Browse files Browse the repository at this point in the history
…d regardless
  • Loading branch information
wegendt-bosch committed Nov 11, 2019
1 parent f94f34d commit 1b5e8cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ class StartupGenerator implements IPlatformStartupGenerator {
StdlibTypeRegistry typeRegistry

override generateMain(CompilationContext context) {
val startupEventHandlers = context.allEventHandlers
val startupEventHandlersAndEvents = context.allEventHandlers
.map[it -> it.event]
.filter[it.value instanceof SystemEventSource]
.map[it.key -> it.value as SystemEventSource]
.map[it.key -> it.value.source]
.filter[it.value.name == "startup"]
.map[it.key]
.filter[it.payload !== null];
return codeFragmentProvider.create('''
Mita_initialize();
Mita_goLive();
int32_t exception = 0;
«FOR startupEventHandler: startupEventHandlers»
«FOR startupEventHandler_event: startupEventHandlersAndEvents»
«val startupEventHandler = startupEventHandler_event.key»
«val event = startupEventHandler_event.value»
«pushGenerator.generate(
startupEventHandler,
new CodeWithContext(
RingbufferGenerator.wrapInRingbuffer(typeRegistry, startupEventHandler, BaseUtils.getType(startupEventHandler.payload)),
RingbufferGenerator.wrapInRingbuffer(typeRegistry, startupEventHandler, BaseUtils.getType(event)),
Optional.empty,
codeFragmentProvider.create('''rb_«startupEventHandler.baseName»''')
),
Expand Down Expand Up @@ -89,8 +89,8 @@ class StartupGenerator implements IPlatformStartupGenerator {
return 0;
''')
.setPreamble('''
«FOR startupEventHandler: startupEventHandlers»
extern ringbuffer_int32_t rb_«startupEventHandler.baseName»;
«FOR startupEventHandler_event: startupEventHandlersAndEvents»
extern ringbuffer_int32_t rb_«startupEventHandler_event.key.baseName»;
«ENDFOR»
''')
.addHeader('time.h', true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import org.eclipse.mita.base.util.BaseUtils
import org.eclipse.mita.base.types.Variance
import org.eclipse.mita.library.stdlib.RingbufferGenerator
import org.eclipse.mita.base.typesystem.StdlibTypeRegistry
import org.eclipse.mita.program.SystemEventSource
import static extension org.eclipse.mita.base.util.BaseUtils.castOrNull;

class MqttGenerator extends AbstractSystemResourceGenerator {

Expand Down Expand Up @@ -501,7 +503,7 @@ class MqttGenerator extends AbstractSystemResourceGenerator {
«FOR handler: eventHandler»
«pushGenerator.generate(
handler,
new CodeWithContext(RingbufferGenerator.wrapInRingbuffer(typeRegistry, handler, BaseUtils.getType(handler.payload)), Optional.empty, codeFragmentProvider.create('''rb_«handler.baseName»''')),
new CodeWithContext(RingbufferGenerator.wrapInRingbuffer(typeRegistry, handler, BaseUtils.getType(handler.event.castOrNull(SystemEventSource).source)), Optional.empty, codeFragmentProvider.create('''rb_«handler.baseName»''')),
codeFragmentProvider.create('''msg''')
exception = CmdProcessor_enqueue(&Mita_EventQueue, «handler.handlerName», NULL, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.eclipse.mita.program.generator.CodeWithContext
import org.eclipse.mita.library.stdlib.RingbufferGenerator
import org.eclipse.mita.base.util.BaseUtils
import java.util.Optional
import static extension org.eclipse.mita.base.util.BaseUtils.castOrNull;

class ButtonGenerator extends AbstractSystemResourceGenerator {

Expand Down Expand Up @@ -80,7 +81,7 @@ class ButtonGenerator extends AbstractSystemResourceGenerator {
«pushGenerator.generate(
changedHandler,
new CodeWithContext(
RingbufferGenerator.wrapInRingbuffer(typeRegistry, changedHandler, BaseUtils.getType(changedHandler.payload)),
RingbufferGenerator.wrapInRingbuffer(typeRegistry, changedHandler, BaseUtils.getType(changedHandler.event.castOrNull(SystemEventSource).source)),
Optional.empty,
codeFragmentProvider.create('''rb_«changedHandler.baseName»''')
),
Expand Down

0 comments on commit 1b5e8cf

Please sign in to comment.