PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pic24_util.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30 // Documentation for this file. If the \file tag isn't present,
31 // this file won't be documented.
32 /** \file
33  * This file contains miscellaneous functions that
34  * that do not fall under any particular category.
35  * See pic24_util.c for details on how
36  * these functions were implemented.
37  */
38 
39 #ifndef _PIC24_UTIL_H_
40 #define _PIC24_UTIL_H_
41 
42 #include <stdint.h>
43 #include "pic24_chip.h"
44 #include "pic24_libconfig.h"
45 
46 /** \name Bitfield to struct conversion
47  * <a name="bitfieldMacros">Given</a> a bitfield struct representing an SFR,
48  * convert this to a word (uint16_t) or to the
49  * high and low bytes (uint8_t) of that word.
50  * Note: though this looks ugly, it introduces
51  * no unexpected compiler overhead at -O1. See
52  * \ref u16_INTTREGlast for an example.
53  */
54 //@{
55 /// Convert a bitfield to a word (uint16_t).
56 #define BITS2WORD(sfrBitfield) ( *((uint16_t*) &sfrBitfield) )
57 /// Return the low byte (as a uint8_t) of a bitfield.
58 #define BITS2BYTEL(sfrBitfield) ( ((uint8_t*) &sfrBitfield)[0] )
59 /// Return the high byte (as a uint8_t) of a bitfield.
60 #define BITS2BYTEH(sfrBitfield) ( ((uint8_t*) &sfrBitfield)[1] )
61 //@}
62 
63 /** Report an error on reset via \ref reportError,
64  * also printing the file and
65  * line number where this macro was called via
66  * a call to \ref ERROR_FILE_LINE.
67  * \param msg Error message to report
68  */
69 #define REPORT_ERROR(msg) reportError(ERROR_FILE_LINE(msg))
70 
71 #ifdef SIM
72 #define HELLO_MSG "****************************************************\n" \
73  "* SIMULATION MODE - DO NOT RUN ON A REAL PIC! *\n" \
74  "****************************************************\n" \
75  "\n" __FILE__ ", built on " __DATE__ " at " __TIME__ "\n"
76 // Output a warning during compilation also
77 #warning ***********************************************
78 #warning * SIMULATION MODE - DO NOT RUN ON A REAL PIC! *
79 #warning ***********************************************
80 #else
81 #define HELLO_MSG "\n" __FILE__ ", built on " __DATE__ " at " __TIME__ "\n"
82 #endif
83 
84 
85 void reportError(const char* szErrorMessage);
87 void checkDeviceAndRevision(void);
88 void checkOscOption(void);
89 void printResetCause(void);
90 void configPinsForLowPower(void);
91 void configBasic(const char* psz_helloMsg);
92 uint32_t roundFloatToUint32(float f_x);
93 uint16_t roundFloatToUint16(float f_x);
94 
95 extern _PERSISTENT const char* sz_lastTimeoutError;
96 
97 #if USE_HEARTBEAT
99 #endif
100 
101 void configHeartbeat(void);
102 void doHeartbeat(void);
103 void toggleHeartbeat(void);
104 
105 #endif