aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/TemperatureDataLogger/TemperatureDataLogger.txt
blob: 136d0385be379fd7790a57be36de54c6d4894367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/** \file
 *
 *  This file contains special DoxyGen information for the generation of the main page and other special
 *  documentation pages. It is not a project source file.
 */
 
/** \mainpage Temperature Datalogger Project
 *
 *  \section SSec_Compat Demo Compatibility:
 *
 *  The following list indicates what microcontrollers are compatible with this demo.
 *
 *  - Series 7 USB AVRs
 *  - Series 6 USB AVRs
 *  - Series 4 USB AVRs (with >16KB of FLASH)
 *
 *  \section SSec_Info USB Information:
 *
 *  The following table gives a rundown of the USB utilization of this demo.
 *
 *  <table>
 *   <tr>
 *    <td><b>USB Mode:</b></td>
 *    <td>Device</td>
 *   </tr>
 *   <tr>
 *    <td><b>USB Classes:</b></td>
 *    <td>Mass Storage Device \n
 *        Human Interface Device</td>
 *   </tr>
 *   <tr> 
 *    <td><b>USB Subclasses:</b></td>
 *    <td>Bulk-Only Transport \n
 *        Keyboard Subclass</td>
 *   </tr>
 *   <tr>
 *    <td><b>Relevant Standards:</b></td>
 *    <td>USBIF Mass Storage Standard \n
 *        USB Bulk-Only Transport Standard \n
 *        SCSI Primary Commands Specification \n
 *        SCSI Block Commands Specification \n
 *        USBIF HID Specification, USBIF HID Usage Tables</td>
 *   </tr>
 *   <tr>
 *    <td><b>Usable Speeds:</b></td>
 *    <td>Full Speed Mode</td>
 *   </tr>
 *  </table>
 *
 *  \section SSec_Description Project Description: 
 *
 *  Temperature Data Logger project. This project is a very basic USB data logger for the current temperature as reported by
 *  the board's temperature sensor, writing the temperature to a file stored on the board's Dataflash in a FAT filesystem
 *  each time a specified interval elapses. When inserted into a PC, the datalogger will appear as a standard USB Mass Storage
 *  device with a single text file, which contains the logged data. Files are named according to the current date when the
 *  logging commences.
 *
 *  A DS1307 or compatible RTC IC is designed to be attached to the AVR's TWI bus, for the management of timestamps on the
 *  sampled data. This project will not function correctly if the RTC chip is omitted unless the DUMMY_RTC compile time token
 *  is specified - see \ref SSec_Options.
 *
 *  Due to the host's need for exclusive access to the filesystem, the device will not log samples while connected to a host.
 *  For the logger to store data, the Dataflash must first be formatted by the host so that it contains a valid FAT filesystem.
 *
 *  This project uses the FatFS library from ELM Chan (http://elm-chan.org/fsw/ff/00index_e.html) and the .NET HID device library
 *  LibHIDNet (http://sourceforge.net/projects/libhidnet/).
 *
 *  \section SSec_Options Project Options
 *
 *  The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.
 *
 *  <table>
 *   <tr>
 *    <td><b>Define Name:</b></td>
 *    <td><b>Location:</b></td>
 *    <td><b>Description:</b></td>
 *   </tr>
 *   <tr>
 *    <td>DUMMY_RTC</td>
 *    <td>Makefile CDEFS</td>
 *    <td>When a DS1307 RTC chip is not fitted, this token can be defined to make the demo assume a 1/1/1 01:01:01 date/time
 *        stamp at all times, effectively transforming the project into a basic data logger with no specified sample times.</td>
 *   </tr>
 *  </table>
 */
ord; -- Flists descriptors. package Flistt is new Tables (Table_Component_Type => Entry_Type, Table_Index_Type => Flist_Type, Table_Low_Bound => 4, Table_Initial => 32); -- Table of all elements. package Els is new Tables (Table_Component_Type => El_Type, Table_Index_Type => El_Index_Type, Table_Low_Bound => 0, Table_Initial => 128); type Flist_Array is array (Natural range <>) of Flist_Type; -- Linked list of free flist. For length less than the last index, the -- index corresponds to the length. All free lists whose length is equal -- or greater than the last index are grouped to the last index. Free_Flists : Flist_Array (0 .. 16) := (others => Null_Flist); -- Get the chain for a free flist for large length. It is stored at the -- first element of the list. function Free_Next (Flist : Flist_Type) return Flist_Type is begin return Flist_Type (Els.Table (Flistt.Table (Flist).Els)); end Free_Next; function Create_Flist (Len : Natural) return Flist_Type is Res : Flist_Type; Prev : Flist_Type; Next : Flist_Type; begin if Len >= Free_Flists'Last then -- Large length. Res := Free_Flists (Free_Flists'Last); Prev := Null_Flist; while Res /= Null_Flist and then Length (Res) /= Len loop Prev := Res; Res := Free_Next (Res); end loop; if Res /= Null_Flist then Next := Free_Next (Res); if Prev = Null_Flist then Free_Flists (Free_Flists'Last) := Next; else Els.Table (Flistt.Table (Prev).Els) := El_Type (Next); end if; end if; else -- Small length. The Len field contains the next free list. Res := Free_Flists (Len); if Res /= Null_Flist then Free_Flists (Len) := Flist_Type (Flistt.Table (Res).Len); Flistt.Table (Res).Len := Nat32 (Len); elsif Len = 0 then -- Quick case for len = 0. Res := Flistt.Allocate (1); Flistt.Table (Res) := (Els => 0, Len => 0); return Res; end if; end if; if Res = Null_Flist then Res := Flistt.Allocate (1); Flistt.Table (Res) := (Els => Els.Allocate (Len), Len => Nat32 (Len)); end if; -- Clear the list. declare Idx : constant El_Index_Type := Flistt.Table (Res).Els; begin Els.Table (Idx .. Idx + El_Index_Type (Len) - 1) := (others => 0); end; return Res; end Create_Flist; procedure Destroy_Flist (Flist : in out Flist_Type) is Len : constant Natural := Length (Flist); Prev : Flist_Type; begin -- Prepend to the array of free flists. if Len >= Free_Flists'Last then Prev := Free_Flists (Free_Flists'Last); Free_Flists (Free_Flists'Last) := Flist; Els.Table (Flistt.Table (Flist).Els) := El_Type (Prev); else Prev := Free_Flists (Len); Free_Flists (Len) := Flist; Flistt.Table (Flist).Len := Nat32 (Prev); end if; Flist := Null_Flist; end Destroy_Flist; function Flast (Flist : Flist_Type) return Integer is begin return Integer (Flistt.Table (Flist).Len - 1); end Flast; function Length (Flist : Flist_Type) return Natural is begin return Natural (Flistt.Table (Flist).Len); end Length; function Get_Nth_Element (Flist : Flist_Type; N : Natural) return El_Type is E : Entry_Type renames Flistt.Table (Flist); begin pragma Assert (N < Natural (E.Len)); return Els.Table (E.Els + El_Index_Type (N)); end Get_Nth_Element; procedure Set_Nth_Element (Flist : Flist_Type; N : Natural; V : El_Type) is E : Entry_Type renames Flistt.Table (Flist); begin pragma Assert (N < Natural (E.Len)); Els.Table (E.Els + El_Index_Type (N)) := V; end Set_Nth_Element; end Flists;