1 /* 2 OrangutanResources.h - Measures available RAM on the AVR 3 */ 4 5 /* 6 * Written by Paul Grayson, 2008. 7 * Copyright (c) 2008-2012 Pololu Corporation. For more information, see 8 * 9 * http://www.pololu.com 10 * http://forum.pololu.com 11 * http://www.pololu.com/docs/0J18 12 * 13 * You may freely modify and share this code, as long as you keep this 14 * notice intact (including the two links above). Licensed under the 15 * Creative Commons BY-SA 3.0 license: 16 * 17 * http://creativecommons.org/licenses/by-sa/3.0/ 18 * 19 * Disclaimer: To the extent permitted by law, Pololu provides this work 20 * without any warranty. It might be defective, in which case you agree 21 * to be responsible for all resulting costs and damages. 22 */ 23 24 #ifndef OrangutanResources_h 25 #define OrangutanResources_h 26 27 #include <avr/io.h> 28 #include <avr/interrupt.h> 29 #include "../OrangutanResources/include/OrangutanModel.h" 30 31 #if defined(_ORANGUTAN_SVP) || defined(_ORANGUTAN_X2) 32 #define JTAG_RESET (1 << JTRF) 33 #endif 34 #define WATCHDOG_RESET (1 << WDRF) 35 #define BROWNOUT_RESET (1 << BORF) 36 #define EXTERNAL_RESET (1 << EXTRF) 37 #define POWERON_RESET (1 << PORF) 38 39 #ifdef __cplusplus 40 41 class OrangutanResources 42 { 43 public: 44 45 // constructor (doesn't do anything) 46 OrangutanResources(); 47 48 // Returns an estimate of the available free RAM on the AVR, in 49 // bytes. This is computed as the difference between the bottom 50 // of the stack and the top of the static variable space or the 51 // top of the space used by malloc(). 52 static int getFreeRAM(); 53 54 // returns the register that contains latched flags indicating 55 // previous reset sources. Individual flags can be accessed by 56 // ANDing the result with the x_RESET constants defined in this 57 // file. For example: 58 // if (OrangutanResources::getResetFlags() & WATCHDOG_RESET) .. getResetFlags()59 static inline unsigned char getResetFlags() 60 { 61 return MCUSR; 62 } 63 64 // clear latched reset flags clearResetFlags()65 static inline void clearResetFlags() 66 { 67 MCUSR = 0; 68 } 69 }; 70 71 extern "C" { 72 #endif // __cplusplus 73 74 int get_free_ram(void); 75 76 // returns the register that contains latched flags indicating 77 // previous reset sources. Individual flags can be accessed by 78 // ANDing the result with the x_RESET constants defined in this 79 // file. For example: 80 // if (get_reset_flags() & WATCHDOG_RESET) .. get_reset_flags(void)81static inline unsigned char get_reset_flags(void) 82 { 83 return MCUSR; 84 } 85 86 // clear latched reset flags clear_reset_flags(void)87static inline void clear_reset_flags(void) 88 { 89 MCUSR = 0; 90 } 91 92 #ifdef __cplusplus 93 } 94 #endif 95 96 #endif 97 98 // Local Variables: ** 99 // mode: C++ ** 100 // c-basic-offset: 4 ** 101 // tab-width: 4 ** 102 // indent-tabs-mode: t ** 103 // end: ** 104