<commit_before>/* MicroDAQ model Standalone main file template
*
* Copyright (C) 2015 Embedded Solutions
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*/

#include <stdio.h>
#include <stdint.h>

#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/hal/Timer.h>
#include <ti/sysbios/knl/Semaphore.h>

#define MODEL_TSAMP     ($$MODEL_TSAMP$$)
#define MODEL_DURATION  ($$MODEL_DURATION$$)
#define USEC_PER_SEC    (1000000)

#define XNAME(x,y)      x##y
#define NAME(x,y)       XNAME(x,y)
#define XSTR(x)         #x
#define STR(x)          XSTR(x)uo

int NAME(MODEL, _init)(void);
int NAME(MODEL, _isr)(double t);
int NAME(MODEL, _end)(void);
double NAME(MODEL, _get_tsamp)(void);

/* Real-time task */ 
void rt_task(UArg arg0);

volatile double model_exec_timer = 0.0; 
volatile double model_stop_flag = 0.0; 
#pragma NOINIT(model_tsamp);
double model_tsamp;

double get_scicos_time( void )
{
    return model_exec_timer; 
}

double get_scicos_tsamp(void)
{
    return model_tsamp;
}

double NAME(MODEL, _get_tsamp)(void)
{ 
    return model_tsamp;
}

Int main()
{   
    Clock_Params clkParams;
    Timer_Params user_sys_tick_params;
    Timer_Handle user_sys_tick_timer;

    /* Create a periodic Clock Instance with period = 1 system time units */
    Clock_Params_init(&clkParams);      
    clkParams.period = 1;
    clkParams.startFlag = TRUE;
    Clock_create(rt_task, 2, &clkParams, NULL);

    /* Create timer for user system tick */
    Timer_Params_init(&user_sys_tick_params);

    if(model_tsamp <= 0.0)
		model_tsamp = MODEL_TSAMP;

	user_sys_tick_params.period = (uint32_t)(model_tsamp * USEC_PER_SEC);

    user_sys_tick_params.periodType = Timer_PeriodType_MICROSECS;
    user_sys_tick_params.arg = 1;
    user_sys_tick_timer = Timer_create(1, 
            (ti_sysbios_hal_Timer_FuncPtr)Clock_tick, 
            &user_sys_tick_params, NULL);

    if (user_sys_tick_timer == NULL) 
        System_abort("Unable to create user system tick timer!");

    /* Init model */ 
    NAME(MODEL, _init)();

    BIOS_start();
}

/* Real-time task */ 
Void rt_task(UArg arg0)
{
    static int end_called = 0; 

	if( model_exec_timer <= MODEL_DURATION || MODEL_DURATION == -1 )
    {
        /* Call model isr function */ 
        NAME(MODEL, _isr)(model_exec_timer);    
    }
    else 
    {
	if(!end_called)
	{
       	    /* Call model end function */ 
       	    NAME(MODEL, _end)();    
	    end_called = 1; 
	}

    }

    /* increment execution timer */ <commit_msg>Adde model_stop_flag to standalone mode<commit_after>/* MicroDAQ model Standalone main file template
*
* Copyright (C) 2015 Embedded Solutions
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*/

#include <stdio.h>
#include <stdint.h>

#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/hal/Timer.h>
#include <ti/sysbios/knl/Semaphore.h>

#define MODEL_TSAMP     ($$MODEL_TSAMP$$)
#define MODEL_DURATION  ($$MODEL_DURATION$$)
#define USEC_PER_SEC    (1000000)

#define XNAME(x,y)      x##y
#define NAME(x,y)       XNAME(x,y)
#define XSTR(x)         #x
#define STR(x)          XSTR(x)uo

int NAME(MODEL, _init)(void);
int NAME(MODEL, _isr)(double t);
int NAME(MODEL, _end)(void);
double NAME(MODEL, _get_tsamp)(void);

/* Real-time task */ 
void rt_task(UArg arg0);

volatile double model_exec_timer = 0.0; 
volatile double model_stop_flag = 0.0; 
#pragma NOINIT(model_tsamp);
double model_tsamp;

double get_scicos_time( void )
{
    return model_exec_timer; 
}

double get_scicos_tsamp(void)
{
    return model_tsamp;
}

double NAME(MODEL, _get_tsamp)(void)
{ 
    return model_tsamp;
}

Int main()
{   
    Clock_Params clkParams;
    Timer_Params user_sys_tick_params;
    Timer_Handle user_sys_tick_timer;

    /* Create a periodic Clock Instance with period = 1 system time units */
    Clock_Params_init(&clkParams);      
    clkParams.period = 1;
    clkParams.startFlag = TRUE;
    Clock_create(rt_task, 2, &clkParams, NULL);

    /* Create timer for user system tick */
    Timer_Params_init(&user_sys_tick_params);

    if(model_tsamp <= 0.0)
		model_tsamp = MODEL_TSAMP;

	user_sys_tick_params.period = (uint32_t)(model_tsamp * USEC_PER_SEC);

    user_sys_tick_params.periodType = Timer_PeriodType_MICROSECS;
    user_sys_tick_params.arg = 1;
    user_sys_tick_timer = Timer_create(1, 
            (ti_sysbios_hal_Timer_FuncPtr)Clock_tick, 
            &user_sys_tick_params, NULL);

    if (user_sys_tick_timer == NULL) 
        System_abort("Unable to create user system tick timer!");

    /* Init model */ 
    NAME(MODEL, _init)();

    BIOS_start();
}

/* Real-time task */ 
Void rt_task(UArg arg0)
{
    static int end_called = 0; 

	if( model_stop_flag == 0.0 && ( model_exec_timer <= MODEL_DURATION || MODEL_DURATION == -1 ))
    {
        /* Call model isr function */ 
        NAME(MODEL, _isr)(model_exec_timer);    
    }
    else 
    {
	if(!end_called)
	{
       	    /* Call model end function */ 
       	    NAME(MODEL, _end)();    
	    end_called = 1; 
	}

    }

    /* increment execution timer */ 
{'fraction_non_alphanumeric': 0.11825613079019073, 'fraction_numerical': 0.010899182561307902, 'mean_word_length': 3.3594615993665875, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7049270', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2029, 'n_words': 444}