just an example of what SDCC can do for YOU
[fw/sdcc] / device / examples / ds390 / ow390 / thermo21.h
1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
3 // 
4 // Permission is hereby granted, free of charge, to any person obtaining a 
5 // copy of this software and associated documentation files (the "Software"), 
6 // to deal in the Software without restriction, including without limitation 
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 
8 // and/or sell copies of the Software, and to permit persons to whom the 
9 // Software is furnished to do so, subject to the following conditions:
10 // 
11 // The above copyright notice and this permission notice shall be included 
12 // in all copies or substantial portions of the Software.
13 // 
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
16 // MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES 
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
20 // OTHER DEALINGS IN THE SOFTWARE.
21 // 
22 // Except as contained in this notice, the name of Dallas Semiconductor 
23 // shall not be used except as stated in the Dallas Semiconductor 
24 // Branding Policy. 
25 //---------------------------------------------------------------------------
26 //
27 //  thermo.h - Include file for Thermochron demo.
28 //
29 //  Version: 2.00
30 //    
31 //    History:
32 //           1.03 -> 2.00  Reorganization of Public Domain Kit 
33
34 #ifndef THERMO_TYPES
35
36 #define THERMO_TYPES
37
38 // hacks for sdcc->TINI
39 #define NULL ((void*)0)
40 #define FILE void
41 #define stdin ((void *)0)
42 #define stdout ((void *)0)
43 #define stderr ((void *)0)
44 int fprintf (FILE *fp, xdata char *format, ...) reentrant;
45
46 // defines
47 #define STATUS_PAGE    16
48 #define THERMO_FAM     0x21
49
50 #include <stdlib.h>
51
52 // Typedefs
53 #ifndef OW_UCHAR
54    #define OW_UCHAR
55    typedef unsigned char  uchar;
56    #ifdef WIN32
57       typedef unsigned short ushort;
58       typedef unsigned long  ulong;
59    #endif
60 #endif
61
62 // structure to hold the mission status 
63 typedef struct 
64 {
65    uchar serial_num[8];          // serial number of thermochron
66
67    uchar mission_in_progress;    // 1 mission in progres, 0 mission over
68
69    uchar sample_rate;            // minutes between samples
70
71    uchar rollover_enable;        // 1 if roll-over enabled
72    uchar rollover_occurred;      // 1 if roll-over occurred
73
74    ushort start_delay;           // minutes before mission starts
75
76    ulong mission_start_time;     // date/time when mission started
77    ulong current_time;           // current real-time clock value
78    ulong download_time;          // download stations time of reading
79
80    ulong mission_samples;        // number of samples in this mission
81    ulong samples_total;          // total number of samples taken by device
82     
83    uchar high_threshold;         // raw temp of high threshold
84    uchar low_threshold;          // raw temp of low threshold
85
86    // skip alarm modes and status for now
87
88    uchar status_raw[32];
89
90 } MissionStatus;
91
92 // structure to hold the histogram data 
93 typedef struct 
94 {
95    ushort bin_count[56];    // counter per bin 0 to 55 
96    float  start_range[56];  // start temp range (C) in bin 0 to 55
97    float  end_range[56];    // end temp range (C) in bin 0 to 55
98
99    uchar  hist_raw[128];    // raw data for histogram
100
101 } Histogram;
102
103 // structure to hold the histogram data 
104 typedef struct 
105 {
106    int num_low;               // number of low events
107    ulong low_start_time[12];  // start time of event 0 to 12
108    ulong low_end_time[12];    // end time of event 0 to 12 
109    int num_high;              // number of high events
110    ulong high_start_time[12]; // start time of event 0 to 12
111    ulong high_end_time[12];   // end time of event 0 to 12
112
113    uchar  alarm_raw[96];     // raw data for alarm events
114
115 } TempAlarmEvents;
116
117 // structure to hold the log data 
118 typedef struct 
119 {
120    int   num_log;             // number of logs
121    float temp[2048];          // temperature log in (C) 
122    ulong start_time;          // start time of log
123    int   interval;            // interval in seconds between logs
124
125    uchar log_raw[2048];       // raw data for log
126
127 } Log;
128
129 // structure to hold all of the thermochron data state
130 typedef struct
131 {
132    MissionStatus MissStat;    // mission state
133    Histogram HistData;        // histogram data
134    TempAlarmEvents AlarmData; // temperature alarm event data
135    Log LogData;               // log data
136
137 } ThermoStateType;
138
139 // type structure to holde time/date 
140 typedef struct          
141 {
142      ushort  second;
143      ushort  minute;
144      ushort  hour;
145      ushort  day;
146      ushort  month;
147      ushort  year;
148 } timedate;
149
150 // structure to hold each state in the StateMachine
151 typedef struct
152 {
153    int  Step;
154    char StepDescription[50];
155
156 } ThermoScript;
157
158 // Global Function Prototypes 
159  int DownloadThermo(int,uchar *,ThermoStateType *, FILE *);
160 int ReadThermoStatus(int,uchar *,ThermoStateType *, FILE *);
161 int MissionThermo(int,uchar *,ThermoStateType *, FILE *);
162 void  SecondsToDate(timedate *, ulong);
163 ulong DateToSeconds(timedate *);
164 uchar BCDToBin(uchar);
165  void  InterpretStatus(MissionStatus *);
166  void  MissionStatusToString(MissionStatus *, int, char *);
167 void  FormatMission(MissionStatus *);
168  void  InterpretHistogram(Histogram *);
169  void  HistogramToString(Histogram *, int, char *);
170  void  InterpretAlarms(TempAlarmEvents *, MissionStatus *);
171  void  AlarmsToString(TempAlarmEvents *, char *);
172  void  InterpretLog(Log *, MissionStatus *);
173  void  LogToString(Log *, int, char *);
174  void  DebugToString(MissionStatus *, TempAlarmEvents *, Histogram *, Log *, char *); 
175 float TempToFloat(uchar, int);
176 float CToF(float);
177 uchar ToBCD(short);
178
179 #endif