📄 t_event.c
字号:
/*************************************************************************
* FILENAME: $RCSfile: t_event.c,v $
* VERSION : $Revision: 1.3 $
* DATE : $Date: 2000/11/09 15:24:53 $
* Copyright (c) 1997-2000 Texas Instruments Incorporated
*
* Target Event Example:
*____________________________________________________________________
* - Sends 3 events to the host:
* - boiling (event without data)
* - this event is triggered whenever the critical
* temperature of boiling is reached.
* - freezing (event without data)
* - this event is triggered whenever the critical
* temperature of freezing is reached.
* - read_gauge (event with data)
* - this event is triggered at regular intervals when a
* temperature sample is taken.
* - The events without data are logged via a call to
* RTDX_Log_Event().
* - The events with data are logged via a call to
* RTDX_Log_Event_Data().
*
* - The program completes after 100 samples have been taken.
*
* - This example shows:
* - the use of Event Classes.
* - how data can be recorded with the event.
*
* - This is the module to be run on the TARGET.
* - This program is meant to be used with the RTDX Excel project's
* VBA module h_event().
*************************************************************************/
#include <stdio.h> /* fprintf(), puts() */
#include <stdlib.h> /* abort() */
#include <rtdx.h> /* RTDX */
#include <rtdx_evt.h> /* RTDX_Log_Event* */
#include "target.h" /* TARGET_INITIALIZE() */
/* Define classes of events */
#define Critical_Temp_Class 0x0001 /* critical temp. class */
#define Sample_Temp_Class 0x0002 /* sample temp. class */
/* Declare events & give class */
RTDX_event boiling = { Critical_Temp_Class };
RTDX_event freezing = { Critical_Temp_Class };
RTDX_event read_gauge = { Sample_Temp_Class };
/* Define critical temperatures (celcius) */
#define BOILING 100
#define FREEZING 0
#define NUMBER_OF_SAMPLES 100
typedef enum { FALSE, TRUE } BOOL;
/* Function prototypes */
int read_temperature(void);
void enable_disable_event_class(BOOL critical_temp);
void main( void )
{
BOOL critical_temp = FALSE; /* critical temp. flag */
struct { /* contains data for sample */
int temp; /* temp. to be recorded */
int sample; /* sample number */
} data;
/* Target Specific Initialization */
TARGET_INITIALIZE();
/* Initialize sample number */
data.sample = 0;
/* Loop until "NUMBER_OF_SAMPLES" are taken... */
while ( data.sample < NUMBER_OF_SAMPLES ) {
/* Check to see if a critical event was logged. */
/* - This is done first to prevent successive critical */
/* events from being logged. */
enable_disable_event_class(critical_temp);
/* Check temperature "sensor" */
data.temp = read_temperature();
/* If temperature reads boiling */
if ( data.temp >= BOILING ) {
/* Log boiling event */
if ( !RTDX_Log_Event(&boiling) ) {
fprintf(stderr, "\nError: RTDX_Log_Event() failed!\n");
abort();
}
/* Set flag for critical temperature */
critical_temp = TRUE;
} else if ( data.temp <= FREEZING ) { /* if freezing... */
/* Log freezing event */
if ( !RTDX_Log_Event(&freezing) ) {
fprintf(stderr, "\nError: RTDX_Log_Event() failed!\n");
abort();
}
/* Set flag for critical temperature */
critical_temp = TRUE;
} else { /* Else log sample */
/* Increment sample counter */
data.sample++;
/* Log temperature sample */
if ( !RTDX_Log_Event_Data( &read_gauge, &data,
sizeof(data) ) ) {
fprintf(stderr, "\nError: RTDX_Log_Event_Data()" \
"failed!\n");
abort();
}
/* Unset flag for critical temperature */
critical_temp = FALSE;
}
/* Wait for Target-to-Host transfer to complete */
while ( RTDX_writing != NULL ) {
#if RTDX_POLLING_IMPLEMENTATION
/* If polling implementation of RTDX... */
/* ...call RTDX_Poll to do data transfer */
RTDX_Poll();
#endif
}
}
puts("\nProgram Completed!");
}
/* -------------------------------------------------------------------- */
/* Simulate a temperature control by linearly changing the */
/* temperature from BOILING to FREEZING and back */
/* -------------------------------------------------------------------- */
int read_temperature(void)
{
static int temp = 50; /* Initial temperature */
static int increment = 10; /* Temperature increment */
temp += increment; /* Change temperature */
/* If critical temperature is BOILING or FREEZING */
if ( temp > BOILING || temp < FREEZING )
/* Reverse increment direction */
increment *= -1;
return(temp);
}
/* -------------------------------------------------------------------- */
/* This function eliminates multiple events of the same type being */
/* logged in seccession. It will allow only the first BOILING or */
/* FREEZING event to be logged. Once the temperature has returned to */
/* a non-critical region, these events are re-enabled in case the */
/* temperature enters the critical region again. */
/* -------------------------------------------------------------------- */
void enable_disable_event_class(BOOL critical_temp)
{
if ( critical_temp == TRUE ) {
/* Disable critical event class */
RTDX_Disable_Event_Class( Critical_Temp_Class );
} else {
/* Re-enable critical event class */
RTDX_Enable_Event_Class( Critical_Temp_Class );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -