📄 t_event.c
字号:
/************************************************************************** $RCSfile: t_event.c,v $* $Revision: 1.18 $* $Date: 2001/03/19 16:58:09 $* 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.* - Events without data are logged via a call to RTDX_Log_Event().* - Events with data are logged via a call to RTDX_Log_Event_Data().** - The program completes after 100 samples have been taken.** - This TARGET example shows:* - the use of Event Classes.* - how data can be recorded with the event.*************************************************************************/#include <stdio.h> /* fprintf(), puts() */#include <stdlib.h> /* abort() */#include <rtdx.h> /* RTDX Target Interface */#include <rtdx_evt.h> /* RTDX Target Event Interface */#include "target.h" /* TARGET_INITIALIZE() *//* Define critical temperatures (celcius) */#define BOILING 100#define FREEZING 0#define MIN_TEMP -30#define MAX_TEMP +130#define NUMBER_OF_SAMPLES 100/************************************************************************** Internal Function Prototypes & Data structures*************************************************************************/void read_temperature(void);/* 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 };typedef enum { FALSE, TRUE } BOOL;/************************************************************************** The main application.* - read temperature gauge in a loop until all samples taken.*************************************************************************/void main( void ){ register unsigned Samples = NUMBER_OF_SAMPLES; /* Target initialization for RTDX */ TARGET_INITIALIZE(); /* Loop until "NUMBER_OF_SAMPLES" are taken... */ do { read_temperature(); /* Check temperature "sensor" */ } while( Samples-- > 0 ); puts("\nProgram Completed!");}/************************************************************************** Simulate a temperature control by linearly changing the* temperature from BOILING to FREEZING and back*************************************************************************/void read_temperature(void){ static int temp = 50; /* Initial temperature */ static int increment = 10; /* Temperature increment */ /* Log temperature sample */ if ( !RTDX_Log_Event_Data( &read_gauge, &temp, sizeof temp) ) { fprintf(stderr, "\nError: RTDX_Log_Event_Data() failed!\n"); abort(); } /* Check for critical temperatures */ if( (temp >= BOILING) || (temp <= FREEZING) ) { /* Determine which critical temperature. */ RTDX_event *pEvent; if ( temp >= BOILING ) { pEvent = &boiling; } else if ( temp <= FREEZING ) { pEvent = &freezing; } if ( RTDX_Log_Event(pEvent) ) { /* Disable critical event class */ /* - disables future critical events so only appears once. */ RTDX_Disable_Event_Class( Critical_Temp_Class ); } else { fprintf(stderr, "\nError: RTDX_Log_Event() failed!\n"); abort(); } } else { /* Temperature no longer outside critical limits. */ /* - Re-enable critical event class to re-enabling future */ /* critical events to appear again. */ RTDX_Enable_Event_Class( Critical_Temp_Class ); } /* Wait for data transfer */ while ( RTDX_writing != NULL ) {#if RTDX_POLLING_IMPLEMENTATION RTDX_Poll(); /* Call Poll to do data transfer */#endif } if( (temp <= MIN_TEMP) || (temp >= MAX_TEMP) ) { increment *= -1; /* Reverse increment direction */ } temp += increment; /* Change temperature */ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -