From 67c1d9504dfe173a743369150f18a1f47025d8e2 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 10 Jul 2013 14:11:14 +0200 Subject: [PATCH] Intentation fixes --- ert_linux/ert_linux_multitasking_main.tlc | 246 +++++++++++----------- 1 file changed, 123 insertions(+), 123 deletions(-) diff --git a/ert_linux/ert_linux_multitasking_main.tlc b/ert_linux/ert_linux_multitasking_main.tlc index 82e161e..7b5754f 100644 --- a/ert_linux/ert_linux_multitasking_main.tlc +++ b/ert_linux/ert_linux_multitasking_main.tlc @@ -23,31 +23,31 @@ %% %function generateDeclarations() Output -/* Multirate - Multitasking case main file */ - -#include /* This ert_main.c example uses printf/fflush */ -#include /* Thread library header file */ -#include /* OS scheduler header file */ -#include /* Semaphores library header file */ -#include "pthread_periodic.h" /* Periodic threads library header file*/ -#include "%.h" /* Model's header file */ -#include "rtwtypes.h" /* MathWorks types */ -%if extMode == 1 -#include "ext_work.h" /* External mode header file */ -%endif - -/** - * Maximal priority used by main loop thread. - */ -#define MAX_PRIO sched_get_priority_max(SCHED_FIFO) - 4 - -/** - * Thread handler of the main loop thread. - * Fundamental sample time = %s - */ -pthread_t main_loop_thread; - -%foreach i = numSampleTimes + /* Multirate - Multitasking case main file */ + + #include /* This ert_main.c example uses printf/fflush */ + #include /* Thread library header file */ + #include /* OS scheduler header file */ + #include /* Semaphores library header file */ + #include "pthread_periodic.h" /* Periodic threads library header file*/ + #include "%.h" /* Model's header file */ + #include "rtwtypes.h" /* MathWorks types */ + %if extMode == 1 + #include "ext_work.h" /* External mode header file */ + %endif + + /** + * Maximal priority used by main loop thread. + */ + #define MAX_PRIO sched_get_priority_max(SCHED_FIFO) - 4 + + /** + * Thread handler of the main loop thread. + * Fundamental sample time = %s + */ + pthread_t main_loop_thread; + + %foreach i = numSampleTimes %assign s = sampleTime% %assign o = offset% @@ -61,12 +61,12 @@ pthread_t main_loop_thread; * Semaphore used to suspend rt_OneStep% loop until next simulation step. */ sem_t step%_semaphore; -%endforeach + %endforeach -/** - * Flag if the simulation has been terminated. - */ -int simulationFinished = 0; + /** + * Flag if the simulation has been terminated. + */ + int simulationFinished = 0; %endfunction @@ -76,7 +76,7 @@ int simulationFinished = 0; %% %function generateRtOneStep() Output -%foreach i = numSampleTimes + %foreach i = numSampleTimes %assign s = sampleTime% %assign o = offset% @@ -101,7 +101,7 @@ int simulationFinished = 0; sem_wait(&step%_semaphore); /* sem_val = 0 */ } } -%endforeach + %endforeach %endfunction @@ -110,91 +110,91 @@ int simulationFinished = 0; %% %function generateMain() Output -/** - * This is the thread function of the main loop. - * Fundamental sample time = %s - */ -void * main_loop() -{ - struct timespec start; - struct timespec period; + /** + * This is the thread function of the main loop. + * Fundamental sample time = %s + */ + void * main_loop() + { + struct timespec start; + struct timespec period; boolean_T eventFlags[%]; /* Model has % rates */ int_T i; /* Setting up the pririty of the main loop */ - struct sched_param scheduling_parameters; - scheduling_parameters.sched_priority = sched_get_priority_max(SCHED_FIFO) - 4; - if (0 != pthread_setschedparam(pthread_self(), SCHED_FIFO, &scheduling_parameters)) - { - %%log_message("[ERROR] Failed to set main thread priority, Login as root and start again", VERBOSEL); - printf("[ERROR] Failed to set main thread priority. Login as root and start again.\n"); - } + struct sched_param scheduling_parameters; + scheduling_parameters.sched_priority = sched_get_priority_max(SCHED_FIFO) - 4; + if (0 != pthread_setschedparam(pthread_self(), SCHED_FIFO, &scheduling_parameters)) + { + %%log_message("[ERROR] Failed to set main thread priority, Login as root and start again", VERBOSEL); + printf("[ERROR] Failed to set main thread priority. Login as root and start again.\n"); + } - period.tv_sec = (unsigned long long)%; - period.tv_nsec = (unsigned long long)((%-period.tv_sec)*1000000000); + period.tv_sec = (unsigned long long)%; + period.tv_nsec = (unsigned long long)((%-period.tv_sec)*1000000000); - clock_gettime(CLOCK_REALTIME, &start); - pthread_make_periodic_np(pthread_self(), &start, &period); + clock_gettime(CLOCK_REALTIME, &start); + pthread_make_periodic_np(pthread_self(), &start, &period); int step_sem_value; /* Main loop, running until all the threads are terminated */ while(rtmGetErrorStatus(%_M) == NULL && !rtmGetStopRequested(%_M)) { - pthread_wait_np(); - %_SetEventsForThisBaseStep(eventFlags); - - /* Base sampling rate */ - sem_getvalue(&step0_semaphore, &step_sem_value); - if(step_sem_value) { - rtmSetErrorStatus(%_M, "Overrun"); - printf("Loop 0 overrun, sample time=%s, offset=%s is too fast\n"); - break; - } - sem_post(&step0_semaphore); - sem_post(&step0_semaphore); - - %foreach i = numSampleTimes-1 - %assign s = sampleTime% - %assign o = offset% - /* Sampling rate %, sample time = %, offset = % */ - if (eventFlags[%]) { - sem_getvalue(&step%_semaphore, &step_sem_value); - if(step_sem_value) { - rtmSetErrorStatus(%_M, "Overrun"); - printf("Loop % overrun, sample time=%s, offset=%s is too fast\n"); - break; - } - sem_post(&step%_semaphore); - sem_post(&step%_semaphore); - } - %endforeach - - %if extMode == 1 - rtExtModeCheckEndTrigger(); - %endif + pthread_wait_np(); + %_SetEventsForThisBaseStep(eventFlags); + + /* Base sampling rate */ + sem_getvalue(&step0_semaphore, &step_sem_value); + if(step_sem_value) { + rtmSetErrorStatus(%_M, "Overrun"); + printf("Loop 0 overrun, sample time=%s, offset=%s is too fast\n"); + break; + } + sem_post(&step0_semaphore); + sem_post(&step0_semaphore); + + %foreach i = numSampleTimes-1 + %assign s = sampleTime% + %assign o = offset% + /* Sampling rate %, sample time = %, offset = % */ + if (eventFlags[%]) { + sem_getvalue(&step%_semaphore, &step_sem_value); + if(step_sem_value) { + rtmSetErrorStatus(%_M, "Overrun"); + printf("Loop % overrun, sample time=%s, offset=%s is too fast\n"); + break; + } + sem_post(&step%_semaphore); + sem_post(&step%_semaphore); + } + %endforeach + + %if extMode == 1 + rtExtModeCheckEndTrigger(); + %endif } simulationFinished = 1; /* Final step */ %foreach i = numSampleTimes - sem_post(&step%_semaphore); - sem_post(&step%_semaphore); + sem_post(&step%_semaphore); + sem_post(&step%_semaphore); %endforeach -} - -/** - * This is the main function of the model. - * Multirate - Multitasking case main file - */ -int_T main(int_T argc, const char_T *argv[]) -{ -%if extMode == 1 - /* External mode */ - rtERTExtModeParseArgs(argc, argv); -%else - (void)(argc); - (void *)(argv); -%endif + } + + /** + * This is the main function of the model. + * Multirate - Multitasking case main file + */ + int_T main(int_T argc, const char_T *argv[]) + { + %if extMode == 1 + /* External mode */ + rtERTExtModeParseArgs(argc, argv); + %else + (void)(argc); + (void *)(argv); + %endif /* Initialize periodic thread library */ pthread_periodic_init_np(); @@ -203,27 +203,27 @@ int_T main(int_T argc, const char_T *argv[]) %_initialize(1); simulationFinished = 0; -%foreach i = numSampleTimes - %assign s = sampleTime% - %assign o = offset% - - /* Initializing the step semaphore of the loop %*/ - if(sem_init(&step%_semaphore, 0, 0) < 0) { - printf("[ERROR] Step semaphore % initialization failed!\n"); - %%log_message("[ERROR] Step semaphore % initialization failed", VERBOSEL); - return(1); - } - - /* Starting loop % thread for sample time = %s, offset = %s. */ - pthread_create(&rt_OneStep%_thread, NULL, rt_OneStep%, NULL); -%endforeach + %foreach i = numSampleTimes + %assign s = sampleTime% + %assign o = offset% + + /* Initializing the step semaphore of the loop %*/ + if(sem_init(&step%_semaphore, 0, 0) < 0) { + printf("[ERROR] Step semaphore % initialization failed!\n"); + %%log_message("[ERROR] Step semaphore % initialization failed", VERBOSEL); + return(1); + } + + /* Starting loop % thread for sample time = %s, offset = %s. */ + pthread_create(&rt_OneStep%_thread, NULL, rt_OneStep%, NULL); + %endforeach /* Starting the main loop */ pthread_create(&main_loop_thread, NULL, main_loop, NULL); pthread_join(main_loop_thread, NULL); -%foreach i = numSampleTimes - pthread_join(rt_OneStep%_thread, NULL); -%endforeach + %foreach i = numSampleTimes + pthread_join(rt_OneStep%_thread, NULL); + %endforeach /* Terminate model */ %_terminate(); @@ -231,14 +231,14 @@ int_T main(int_T argc, const char_T *argv[]) const char_T *errStatus = rtmGetErrorStatus(%_M); int_T i; if(errStatus != NULL && strcmp(errStatus, "Simulation finished")) { - %%printf("%s\n", rtmGetErrorStatus(%_M)); - if(!strcmp(errStatus, "Overrun")) { - printf("ISR overrun - sampling rate too fast\n"); - } - return(1); + %%printf("%s\n", rtmGetErrorStatus(%_M)); + if(!strcmp(errStatus, "Overrun")) { + printf("ISR overrun - sampling rate too fast\n"); + } + return(1); } return 0; -} + } %endfunction %% [EOF] linux_ert_target_miltitasking_main.tlc -- 2.39.2