SdFatUtil.cpp

Sat, 07 Nov 2015 13:23:07 +0100

author
mbayer
date
Sat, 07 Nov 2015 13:23:07 +0100
changeset 0
2c8ba1964db7
permissions
-rw-r--r--

Initial code from reprappro Marlin repository

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

mercurial