SdFatUtil.cpp

changeset 0
2c8ba1964db7
equal deleted inserted replaced
-1:000000000000 0:2c8ba1964db7
1 /* Arduino SdFat Library
2 * Copyright (C) 2008 by William Greiman
3 *
4 * This file is part of the Arduino SdFat Library
5 *
6 * This Library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with the Arduino SdFat Library. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20 #include "Marlin.h"
21
22 #ifdef SDSUPPORT
23 #include "SdFatUtil.h"
24
25 //------------------------------------------------------------------------------
26 /** Amount of free RAM
27 * \return The number of free bytes.
28 */
29 int SdFatUtil::FreeRam() {
30 extern int __bss_end;
31 extern int* __brkval;
32 int free_memory;
33 if (reinterpret_cast<int>(__brkval) == 0) {
34 // if no heap use from end of bss section
35 free_memory = reinterpret_cast<int>(&free_memory)
36 - reinterpret_cast<int>(&__bss_end);
37 } else {
38 // use from top of stack to heap
39 free_memory = reinterpret_cast<int>(&free_memory)
40 - reinterpret_cast<int>(__brkval);
41 }
42 return free_memory;
43 }
44 //------------------------------------------------------------------------------
45 /** %Print a string in flash memory.
46 *
47 * \param[in] pr Print object for output.
48 * \param[in] str Pointer to string stored in flash memory.
49 */
50 void SdFatUtil::print_P( PGM_P str) {
51 for (uint8_t c; (c = pgm_read_byte(str)); str++) MYSERIAL.write(c);
52 }
53 //------------------------------------------------------------------------------
54 /** %Print a string in flash memory followed by a CR/LF.
55 *
56 * \param[in] pr Print object for output.
57 * \param[in] str Pointer to string stored in flash memory.
58 */
59 void SdFatUtil::println_P( PGM_P str) {
60 print_P( str);
61 MYSERIAL.println();
62 }
63 //------------------------------------------------------------------------------
64 /** %Print a string in flash memory to Serial.
65 *
66 * \param[in] str Pointer to string stored in flash memory.
67 */
68 void SdFatUtil::SerialPrint_P(PGM_P str) {
69 print_P(str);
70 }
71 //------------------------------------------------------------------------------
72 /** %Print a string in flash memory to Serial followed by a CR/LF.
73 *
74 * \param[in] str Pointer to string stored in flash memory.
75 */
76 void SdFatUtil::SerialPrintln_P(PGM_P str) {
77 println_P( str);
78 }
79 #endif

mercurial