1 /* $Id: RtemsModuleVisitor.java 114 2010-07-05 07:47:02Z haidw $ */
2 package dol.visitor.rtems;
4 import java.io.FileOutputStream;
5 import java.io.OutputStream;
6 import java.util.HashMap;
7 import java.util.Vector;
9 import dol.datamodel.architecture.Architecture;
10 import dol.datamodel.mapping.ComputationBinding;
11 import dol.datamodel.mapping.Mapping;
12 import dol.datamodel.mapping.Schedule;
13 import dol.datamodel.mapping.ScheduleEntry;
14 import dol.datamodel.mapping.SchedulingPolicy;
15 import dol.datamodel.pn.Channel;
16 import dol.datamodel.pn.Port;
17 import dol.datamodel.pn.Process;
18 import dol.datamodel.pn.ProcessNetwork;
19 import dol.main.UserInterface;
20 import dol.parser.xml.archischema.ArchiXmlParser;
21 import dol.parser.xml.mapschema.MapXmlParser;
22 import dol.util.CodePrintStream;
23 import dol.visitor.PNVisitor;
26 * This class is a class for a visitor that is used to generate
29 public class RtemsModuleVisitor extends PNVisitor {
34 * @param dir path of this file
36 public RtemsModuleVisitor(String dir, HashMap<Port, Integer> portMap) {
42 * Visit process network.
44 * @param x process network that needs to be rendered
46 public void visitComponent(ProcessNetwork x) {
48 _ui = UserInterface.getInstance();
49 String filename = _dir + _delimiter + "main.c";
50 OutputStream file = new FileOutputStream(filename);
51 _mainPS = new CodePrintStream(file);
53 Vector<Process> pList = x.getProcessList();
54 Vector<String> processList = new Vector<String>();
55 for (Process p : x.getProcessList()) {
56 String basename = p.getBasename();
57 if (!processList.contains(basename)) {
58 processList.add(basename);
62 Architecture arch = null;
63 Mapping mapping = null;
65 //create header section
66 if (_ui.getRtemsBSP().equals("pc386")) {
67 _mainPS.println("#include <bsp.h>");
68 _mainPS.println("#include <stdlib.h>");
69 _mainPS.println("#include <stdio.h>");
70 _mainPS.println("#include <inttypes.h>");
72 _mainPS.println("rtems_task Init(rtems_task_argument argument);");
74 _mainPS.println("#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER");
75 _mainPS.println("#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER");
76 _mainPS.println("#define CONFIGURE_RTEMS_INIT_TASKS_TABLE");
77 _mainPS.println("#define CONFIGURE_MAXIMUM_TASKS "
78 + (x.getProcessList().size() + 2));
79 _mainPS.println("#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES "
80 + x.getChannelList().size());
81 _mainPS.println("#define CONFIGURE_INIT");
82 _mainPS.println("#include <rtems/confdefs.h>");
84 } else if (_ui.getRtemsBSP().equals("mparm")) {
85 _mainPS.println("#define TEST_INIT");
86 _mainPS.println("#include <bsp.h>");
87 _mainPS.println("#include <stdlib.h>");
88 _mainPS.println("#include <stdio.h>");
90 _mainPS.println("#define RTEMS_TRACE_MAIN_APP");
91 _mainPS.println("#include \"system.h\"");
92 _mainPS.println("#include \"appsupport.h\"");
93 _mainPS.println("#include \"scratch_queue.h\"");
97 _mainPS.println("#include \"dol.h\"");
98 _mainPS.println("#include \"rtems_process_wrapper.h\"");
101 if (_ui.getRtemsBSP().equals("pc386")) {
102 _mainPS.println("rtems_task CleanupTask(rtems_task_argument arg);");
103 _mainPS.println("rtems_id queue_id["
104 + x.getChannelList().size() + "];");
106 } else if (_ui.getRtemsBSP().equals("mparm")) {
107 //if no mapping is provided, map each process to a new
110 _mainPS.println("#ifdef QUEUE_BUFF_SHAPER");
111 _mainPS.println("#include \"traffic_shaping.h\"");
112 //_mainPS.println("#define shaper_PROCESSOR "
113 // + (pList.size()+1));
114 _mainPS.println("#endif // shaper");
117 if (_ui.getMappingFileName() == null) {
120 for (Process p : pList) {
121 _mainPS.println("#define " + p.getName()
122 + "_PROCESSOR " + ++i); //count from 1
126 _mainPS.print("unsigned int number_of_processes["
127 + pList.size() + "] = { ");
128 for (i = 0; i < pList.size(); i++) {
129 _mainPS.print("1, ");
131 _mainPS.println("};");
134 } else { //map processes according to mapping file
135 ArchiXmlParser archParser = new ArchiXmlParser();
136 arch = archParser.doParse(_ui.getPlatformFileName());
137 MapXmlParser mappingParser = new MapXmlParser(x, arch);
138 mapping = mappingParser.doParse(_ui.getMappingFileName());
139 int numOfUsedProcessors = mapping.getProcessorList().size();
140 int numOfProcessors = arch.getProcessorList().size();
141 int processesPerProcessor[] = new int[numOfProcessors];
143 // need to check processors used start from 0 and
145 for (Process p : pList) {
146 for (ComputationBinding b : mapping.getCompBindList()){
147 int processorIndex = Integer.valueOf(
148 b.getProcessor().getName().
149 replaceAll(".*_", ""));
150 if (b.getProcess().getName().
151 equals(p.getName())) {
152 processesPerProcessor[processorIndex]++;
153 //processor indices start at 1 in MPARM
154 _mainPS.println("#define " + p.getName()
156 + (processorIndex + 1));
162 for (int i=0; i < numOfUsedProcessors; i++) {
163 if (processesPerProcessor[i] < 1)
164 throw new Exception("No process is mapped to "
165 + "PROCESSOR[" + i + "]. For the MPARM "
166 + "platform, processors should be used "
167 + "starting from 0 until N (in the "
168 + "generated code, from 1 to N + 1), and "
169 + "every processor between 0 and N "
170 + "should have at least one process "
176 _mainPS.println("#ifdef QUEUE_BUFF_SHAPER");
177 _mainPS.println("#define shaper_PROCESSOR "
178 + (numOfUsedProcessors+1));
179 _mainPS.println("#endif // shaper");
182 _mainPS.print("unsigned int number_of_processes[]"
184 for (int i = 0; i < numOfUsedProcessors; i++) {
185 _mainPS.print(processesPerProcessor[i] + ", ");
187 _mainPS.println("};");
191 _mainPS.println("unsigned int active_processes;");
192 _mainPS.println("inline void processor_init() "
193 + "{active_processes"
194 + " = number_of_processes[get_id() - 1];}");
197 for (Process p : pList) {
198 _mainPS.println("void " + "rtems_" + p.getName()
199 + "_init(rtems_task_argument arg);");
204 for (String pName : x.getProcessBasenames()) {
205 _mainPS.println("extern rtems_task " + pName
206 + "_task(rtems_task_argument argument);");
210 //declare processes and channels
211 for (Process process : x.getProcessList()) {
212 _mainPS.println("RtemsProcessWrapper *" + process.getName()
217 _mainPS.println("#ifdef PRINTF_TO_DEBUG");
218 _mainPS.println("#undef printf");
219 _mainPS.println("#define printf(...) \\");
220 _mainPS.println(" do { \\");
221 _mainPS.println(" char _buffer[128]; \\");
222 _mainPS.println(" sprintf(_buffer, __VA_ARGS__); \\");
223 _mainPS.println(" SHOW_DEBUG((int)_buffer); \\");
224 _mainPS.println(" } while (0)");
225 _mainPS.println("#endif");
227 _mainPS.println("#ifdef WORKLOAD_EXTRACT");
228 _mainPS.println("void callback(int code, int* arg, int size) "
230 _mainPS.println(" long unsigned int time = get_cycle1();");
231 _mainPS.println(" Thread_Control *x = "
232 + "(Thread_Control*)arg;");
233 _mainPS.println(" SHOW_DEBUG(\"log callback\");");
234 _mainPS.println(" SHOW_DEBUG_INT((int)time);");
235 _mainPS.println(" SHOW_DEBUG_INT(x->Object.id);");
236 _mainPS.println("}");
237 _mainPS.println("#endif");
239 _mainPS.println("rtems_id timer_sem_id;");
242 _mainPS.println("/**");
243 _mainPS.println(" *");
244 _mainPS.println(" */");
245 _mainPS.println("rtems_task Init(rtems_task_argument arg) {");
247 if (_ui.getRtemsBSP().equals("mparm")) {
248 // //////////////////// mparm /////////////////////////
249 int processCount = 0;
251 _mainPS.println(" rtems_id task_id;");
252 _mainPS.println(" rtems_status_code status;");
254 _mainPS.println(" status = rtems_semaphore_create(rtems_build_name('c','s','e','m'), 1, RTEMS_BINARY_SEMAPHORE |RTEMS_NO_PRIORITY_CEILING |RTEMS_LOCAL |RTEMS_PRIORITY, 0,&timer_sem_id);");
255 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
256 _mainPS.println(" printf(\"[init ] Could not create semaphore (status %d).\", status);");
257 _mainPS.println(" rtems_shutdown_executive(0);");
258 _mainPS.println(" }");
263 _mainPS.println(" scratch_queue_autoinit_system();");
266 _mainPS.println("#ifdef WORKLOAD_EXTRACT");
267 _mainPS.println(" rtems_monitor_register_callback"
269 for (Channel c : x.getChannelList()) {
270 _mainPS.println(" SHOW_DEBUG(\"log "
271 + "create_channel\");");
272 _mainPS.println(" SHOW_DEBUG(\"log " + c.getName()
274 _mainPS.println(" SHOW_DEBUG_INT((int)"
275 + (c.getSize() * c.getTokenSize()) + ");");
277 _mainPS.println("#endif");
280 _mainPS.println("#ifdef QUEUE_BUFF_SHAPER");
281 _mainPS.println(" if ((get_id()-1) == shaper_PROCESSOR) "
283 _mainPS.println(" rtems_name name = rtems_build_name"
284 +"('s', 's', '0', ' ');");
288 _mainPS.println(" //one more init to prevent the"
289 + "blocking instatiation of scrach queue");
290 _mainPS.println(" status = rtems_task_create(");
291 _mainPS.println(" name,");
292 _mainPS.println(" 1,");
293 _mainPS.println(" RTEMS_MINIMUM_STACK_SIZE,");
294 _mainPS.println(" RTEMS_DEFAULT_MODES,");
295 _mainPS.println(" RTEMS_LOCAL,");
296 _mainPS.println(" &task_id, -1);");
297 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
298 _mainPS.println(" printf(\"[init ] "
299 + "Could not create init shaper"
300 + "(status %d).\\n\", status);");
301 _mainPS.println(" rtems_shutdown_executive(0);");
302 _mainPS.println(" }");
306 _mainPS.println(" status = rtems_task_start(task_id, "
307 + "shaping_init, arg);");
308 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
309 _mainPS.println(" printf(\"[init ] "
310 + "Could not start init shaping"
311 + " (status %d).\\n\", status);");
312 _mainPS.println(" rtems_shutdown_executive(0);");
313 _mainPS.println(" }");
314 _mainPS.println(" }");
315 _mainPS.println("#endif // QUEUE_BUFF_SHAPER");
318 for (Process process : x.getProcessList()) {
319 _mainPS.println(" if (get_id() == "
320 + process.getName() + "_PROCESSOR) {");
321 _mainPS.println(" processor_init();");
322 _mainPS.println(" rtems_name name = "
324 + "('p', 'i', 0x" + ++processCount
329 _mainPS.println(" //one more init to prevent the"
330 + "blocking instatiation of scrach queue");
331 _mainPS.println(" status = rtems_task_create(");
332 _mainPS.println(" name,");
333 _mainPS.println(" 1,");
334 _mainPS.println(" RTEMS_MINIMUM_STACK_SIZE"
336 _mainPS.println(" RTEMS_DEFAULT_MODES,");
337 _mainPS.println(" RTEMS_LOCAL,");
338 _mainPS.println(" &task_id, -1);");
339 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) "
341 _mainPS.println(" printf(\"[init ] "
342 + "Could not create init task["
343 + process.getName() + "] "
344 +"(status %d).\\n\", status);");
345 _mainPS.println(" rtems_shutdown_executive(0);");
346 _mainPS.println(" }");
350 _mainPS.println(" status = rtems_task_start(task_id, "
351 + "rtems_" + process.getName()
353 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
354 _mainPS.println(" printf(\"[init ] "
355 + "Could not start init task [ "
357 + "] (status %d).\\n\", status);");
358 _mainPS.println(" rtems_shutdown_executive(0);");
359 _mainPS.println(" }");
361 _mainPS.println(" rtems_" + process.getName()
363 _mainPS.println(" rtems_task_delete(RTEMS_SELF);");
365 _mainPS.println(" }");
370 _mainPS.println("#ifdef QUEUE_BUFF_SHAPER");
371 _mainPS.println(" if ((get_id()-1) == shaper_PROCESSOR) "
373 _mainPS.println(" rtems_name name = rtems_build_name"
374 +"('s', 's', '0', ' ');");
378 _mainPS.println(" //one more init to prevent the"
379 + "blocking instatiation of scrach queue");
380 _mainPS.println(" status = rtems_task_create(");
381 _mainPS.println(" name,");
382 _mainPS.println(" 128,");
383 _mainPS.println(" RTEMS_MINIMUM_STACK_SIZE,");
384 _mainPS.println(" RTEMS_DEFAULT_MODES,");
385 _mainPS.println(" RTEMS_LOCAL,");
386 _mainPS.println(" &task_id, -1);");
387 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
388 _mainPS.println(" printf(\"[init ] "
389 + "Could not create init shaper"
390 +"(status %d).\\n\", status);");
391 _mainPS.println(" rtems_shutdown_executive(0);");
392 _mainPS.println(" }");
396 _mainPS.println(" status = rtems_task_start(task_id, "
397 + "shaping_init, arg);");
398 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
399 _mainPS.println(" printf(\"[init ] "
400 + "Could not start init shaping"
401 + " (status %d).\\n\", status);");
402 _mainPS.println(" rtems_shutdown_executive(0);");
403 _mainPS.println(" }");
404 _mainPS.println(" }");
405 _mainPS.println("#endif // QUEUE_BUFF_SHAPER");
408 _mainPS.println("if (number_of_processes[get_id() - 1]"
410 _mainPS.println(" printf(\"No process on processor "
411 + "%d.\", get_id());");
412 _mainPS.println(" rtems_shutdown_executive(0);");
413 _mainPS.println("}");
416 _mainPS.println(" rtems_task_delete(RTEMS_SELF);");
417 _mainPS.println("}");
422 for (Process process : x.getProcessList()) {
423 String processName = process.getName();
424 _mainPS.println("void rtems_" + process.getName()
425 + "_init(rtems_task_argument arg) {");
426 _mainPS.println(" rtems_id task_id;");
427 _mainPS.println(" rtems_status_code status;");
430 _mainPS.println(" " + process.getName()
432 + "(RtemsProcessWrapper *)malloc"
433 + "(sizeof(RtemsProcessWrapper));");
435 int numOfOutports = process.getNumOfOutports();
436 int numOfInports = process.getNumOfInports();
437 if (numOfOutports > 0) {
438 _mainPS.println(" int* "
440 + "_out_port_id = (int *)malloc("
442 + " * sizeof(int));");
443 _mainPS.println(" SCRATCH_QUEUE_PRODUCER **"
446 + "(SCRATCH_QUEUE_PRODUCER **)"
449 + "*sizeof(SCRATCH_QUEUE_PRODUCER));");
452 if (numOfInports > 0) {
453 _mainPS.println(" int *"
455 + "_in_port_id = (int *)malloc("
457 + " * sizeof(int));");
458 _mainPS.println(" SCRATCH_QUEUE_CONSUMER **"
461 + "(SCRATCH_QUEUE_CONSUMER **)"
464 + "*sizeof(SCRATCH_QUEUE_CONSUMER));");
469 _mainPS.println(" status = rtems_task_create(");
470 _mainPS.println(" " + ++processCount + ",");
471 _mainPS.println(" 1,");
472 _mainPS.println(" RTEMS_MINIMUM_STACK_SIZE,");
473 _mainPS.println(" RTEMS_DEFAULT_MODES,");
474 _mainPS.println(" RTEMS_LOCAL,");
475 _mainPS.println(" &task_id, -1);");
476 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
477 _mainPS.println(" printf(\"[init ] "
478 + "Could not create task["
480 +"(status %d).\\n\", status);");
481 _mainPS.println(" rtems_shutdown_executive(0);");
482 _mainPS.println(" }");
484 _mainPS.println("#ifdef WORKLOAD_EXTRACT");
485 _mainPS.println(" SHOW_DEBUG(\"log create_task\");");
486 _mainPS.println(" SHOW_DEBUG_INT(task_id);");
487 _mainPS.println(" SHOW_DEBUG(\"log " + processName + "\");");
488 for (Port port : process.getPortList()) {
489 Channel c = (Channel) port.getPeerResource();
490 if (port.isInPort()) {
491 _mainPS.println(" SHOW_DEBUG(\"log in_port\");");
492 _mainPS.println(" SHOW_DEBUG_INT((int)" + _portMap.get(port) + ");");
493 _mainPS.println(" SHOW_DEBUG(\"log " + c.getName() + "\");");
495 if (port.isOutPort()) {
496 _mainPS.println(" SHOW_DEBUG(\"log out_port\");");
497 _mainPS.println(" SHOW_DEBUG_INT((int)" + _portMap.get(port) + ");");
498 _mainPS.println(" SHOW_DEBUG(\"log " + c.getName() + "\");");
501 _mainPS.println("#endif");
504 // connect ports to channels
505 HashMap<Channel, Integer> channel_map =
506 new HashMap<Channel, Integer>();
507 int channelCount = 1;
508 for (Channel c : x.getChannelList()) {
509 channel_map.put(c, channelCount++);
513 // fill the wrapper, instantiate queues
515 for (Port port : process.getPortList()) {
516 Channel c = (Channel)(port.getPeerResource());
517 if (port.isInPort()) {
518 _mainPS.println(" " + processName + "_in_port_id["
520 + _portMap.get(port) + ";");
521 _mainPS.println(" " + processName
524 _mainPS.println("#if defined (QUEUE_BUFF_IN_PRODUCER) || (QUEUE_BUFF_IN_PRODUCER_DMA)");
525 _mainPS.println(" scratch_queue_autoinit_consumer("
528 _mainPS.println("#elif defined (QUEUE_BUFF_IN_CONSUMER) || (QUEUE_BUFF_IN_CONSUMER_DMA)");
529 _mainPS.println(" scratch_queue_autoinit_consumer("
530 + c.getOrigin().getName()
532 + channel_map.get(c) + ", "
536 _mainPS.println("#elif defined (QUEUE_BUFF_IN_SHARDMEM)");
537 _mainPS.println(" scratch_queue_autoinit_consumer("
540 _mainPS.println("#elif defined (QUEUE_BUFF_SHAPER)");
541 _mainPS.println(" scratch_queue_autoinit_consumer("
544 _mainPS.println("#endif");
548 } else if (port.isOutPort()) {
549 _mainPS.println(" " + processName+"_out_port_id["
551 + _portMap.get(port) + ";");
552 _mainPS.println(" " + processName
556 _mainPS.println("#if defined (QUEUE_BUFF_IN_PRODUCER) || (QUEUE_BUFF_IN_PRODUCER_DMA)");
557 _mainPS.println(" scratch_queue_autoinit_producer("
558 + c.getTarget().getName()
560 + channel_map.get(c) + ", "
564 _mainPS.println("#elif defined (QUEUE_BUFF_IN_CONSUMER) || (QUEUE_BUFF_IN_CONSUMER_DMA)");
565 _mainPS.println(" scratch_queue_autoinit_producer("
568 _mainPS.println("#elif defined (QUEUE_BUFF_IN_SHARDMEM)");
569 _mainPS.println(" scratch_queue_autoinit_producer("
570 + c.getTarget().getName()
572 + channel_map.get(c) + ", "
576 _mainPS.println("#elif defined (QUEUE_BUFF_SHAPER)");
577 _mainPS.println(" scratch_queue_autoinit_producer("
578 + c.getTarget().getName()
580 + channel_map.get(c) + ", "
584 _mainPS.println("#endif");
590 if (numOfInports > 0) {
591 _mainPS.println(" " + processName
592 + "_wrapper->in_port_id = "
595 _mainPS.println(" " + processName
596 + "_wrapper->in_queue_id = "
599 _mainPS.println(" " + processName
600 + "_wrapper->number_of_in_ports = "
601 + numOfInports + ";");
604 if (numOfOutports > 0) {
605 _mainPS.println(" " + processName
606 + "_wrapper->out_port_id = "
609 _mainPS.println(" " + processName
610 + "_wrapper->out_queue_id = "
613 _mainPS.println(" " + processName
614 + "_wrapper->number_of_out_ports = "
615 + numOfOutports + ";");
618 _mainPS.println(" " + processName
619 + "_wrapper->is_detached = 0;");
622 if (mapping != null) {
623 Schedule s = mapping.getScheduleByResource(
624 process.getProcessor().getName());
625 if (s != null && s.getSchedPolicy() ==
626 SchedulingPolicy.FIXEDPRIORITY) {
627 ScheduleEntry e = s.getScheduleEntry(
630 String value = e.getCfgValue("priority");
632 priority = Integer.parseInt(value);
637 _mainPS.println(" " + processName
638 + "_wrapper->priority = " + priority + ";");
640 _mainPS.println(" " + processName
641 + "_wrapper->name = (char *)malloc(("
642 + processName.length()
643 + " + 1) * sizeof(char));");
644 _mainPS.println(" strcpy(" + processName
645 + "_wrapper->name, " + "\""
646 + processName + "\");");
649 _mainPS.println(" status = rtems_task_start("
650 + "task_id, " + process.getBasename()
651 + "_task, " + "(rtems_task_argument)"
652 + process.getName() + "_wrapper);");
653 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) "
655 _mainPS.println(" printf(\"[init ] "
656 + "Could not start " + process.getName()
657 + " (status %d).\\n\", status);");
658 _mainPS.println(" rtems_shutdown_executive(0);");
659 _mainPS.println(" }");
660 _mainPS.println(" rtems_task_delete(RTEMS_SELF);");
661 _mainPS.println("}");
665 } else if (_ui.getRtemsBSP().equals("pc386")) {
666 // //////////////////// pc386 ////////////////////////
667 _mainPS.println(" int j;");
668 _mainPS.println(" rtems_id task_id[" +
669 + (x.getProcessList().size() + 1) + "];");
670 _mainPS.println(" rtems_status_code status;");
673 //initialize process-specific information
674 for (Process process : x.getProcessList()) {
675 int numberOfPorts = x.getProcess(process.getName())
676 .getPortList().size();
677 _mainPS.println(" " + process.getName()
679 + "malloc(sizeof(RtemsProcessWrapper));");
680 _mainPS.println(" int *"
681 + process.getName() + "_port_id = malloc("
682 + numberOfPorts + " * sizeof(int));");
683 _mainPS.println(" int *"
685 + "_port_queue_id = malloc("
686 + numberOfPorts + " * sizeof(int));");
690 //create a task for each process
691 _mainPS.println(" for (j = 0; j < "
692 + (x.getProcessList().size()+1) + "; j++) {");
693 _mainPS.println(" status = rtems_task_create(");
694 _mainPS.println(" j + 1,");
695 _mainPS.println(" 128,");
696 _mainPS.println(" RTEMS_MINIMUM_STACK_SIZE,");
697 _mainPS.println(" RTEMS_DEFAULT_MODES,");
698 _mainPS.println(" RTEMS_DEFAULT_ATTRIBUTES,");
699 _mainPS.println(" &(task_id[j]));");
700 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
701 _mainPS.println(" printf(\"[init ] "
702 + "Could not create task[%d] (status %d).\\n\", "
703 + "(int)j, status);");
704 _mainPS.println(" rtems_shutdown_executive(0);");
705 _mainPS.println(" }");
706 _mainPS.println(" }");
709 //create a message queue for each channel
711 for (Channel channel : x.getChannelList()) {
712 _mainPS.println(" status = "
713 + "rtems_message_queue_create(");
714 _mainPS.println(" " + (j + 1) + ",");
715 _mainPS.println(" " + channel.getSize()
717 _mainPS.println(" 1,");
718 _mainPS.println(" RTEMS_DEFAULT_ATTR"
720 _mainPS.println(" &queue_id[" + j + "]);");
721 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) "
723 _mainPS.println(" printf(\"[init ] "
724 + "Could not create queue[" + j
725 + "] (status %d).\\n\", status);");
726 _mainPS.println(" rtems_shutdown_executive(0);");
727 _mainPS.println(" }");
732 //connect ports to channels
733 HashMap<Channel, Integer> channel_map =
734 new HashMap<Channel, Integer>();
736 for (Channel c : x.getChannelList()) {
737 channel_map.put(c, j++);
740 for (Process process : x.getProcessList()) {
741 String processName = process.getName();
743 for (Port port : process.getPortList()) {
744 Channel c = (Channel)(port.getPeerResource());
746 _mainPS.println(" " + processName + "_port_id["
748 + _portMap.get(port) + ";");
749 _mainPS.println(" " + processName
750 + "_port_queue_id[" + i + "] = queue_id["
751 + channel_map.get(c) + "];");
754 _mainPS.println(" " + processName
755 + "_wrapper->port_id = " + processName
757 _mainPS.println(" " + processName
758 + "_wrapper->port_queue_id = "
760 + "_port_queue_id;");
761 _mainPS.println(" " + processName
762 + "_wrapper->number_of_ports = "
764 _mainPS.println(" " + processName
765 + "_wrapper->is_detached = 0;");
766 _mainPS.println(" " + processName
767 + "_wrapper->name = malloc(("
768 + processName.length()
769 + " + 1) * sizeof(char));");
770 _mainPS.println(" strcpy(" + processName
771 + "_wrapper->name, " + "\""
772 + processName + "\");");
777 _mainPS.println(" printf(\"[init ] "
778 + "Start cleanup.\\n\");");
779 _mainPS.println(" status = rtems_task_start(task_id[0], "
780 + "CleanupTask, 0);");
781 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) {");
782 _mainPS.println(" printf(\"[init ] Could not start "
783 + "cleanup (status %d).\\n\", status);");
784 _mainPS.println(" rtems_shutdown_executive(0);");
785 _mainPS.println(" }");
790 for (Process process : x.getProcessList()) {
791 _mainPS.println(" printf(\"[init ] Start "
792 + process.getName() + ".\\n\");");
793 _mainPS.println(" status = rtems_task_start(task_id["
794 + j + "], " + process.getBasename()
796 + "(rtems_task_argument)"
799 _mainPS.println(" if (status != RTEMS_SUCCESSFUL) "
801 _mainPS.println(" printf(\"[init ] "
802 + "Could not start " + process.getName()
803 + " (status %d).\\n\", status);");
804 _mainPS.println(" rtems_shutdown_executive(0);");
805 _mainPS.println(" }");
810 _mainPS.println(" printf(\"[init ] Done.\\n\");");
811 _mainPS.println(" rtems_task_delete(RTEMS_SELF);");
812 _mainPS.println("}");
815 _mainPS.println("rtems_task CleanupTask(rtems_task_argument "
817 _mainPS.println(" printf(\"[cleanup ] Started.\\n\");");
818 _mainPS.println(" do {");
819 _mainPS.println(" rtems_task_wake_after(0);");
820 _mainPS.println(" } while (");
822 for (Process process : x.getProcessList()) {
825 + "_wrapper->is_detached)");
827 if (j < x.getProcessList().size()) {
828 _mainPS.println(" || ");
830 _mainPS.println(");");
834 _mainPS.println(" printf(\"[cleanup ] Shutdown.\\n\");");
835 _mainPS.println(" rtems_shutdown_executive(0);");
836 _mainPS.println("}");
840 catch (Exception e) {
841 System.out.println("RtemsModuleVisitor: exception occured: "
849 * @param x process that needs to be processed
851 public void visitComponent(Process x) {
856 * @param x channel that needs to be processed
858 public void visitComponent(Channel x) {
861 protected CodePrintStream _mainPS = null;
862 protected String _dir = null;
863 protected HashMap<Port, Integer> _portMap;