Repetier-Firmware 0.2
Repetier/SdFatUtil.h
Go to the documentation of this file.
00001 /* Arduino SdFat Library
00002  * Copyright (C) 2008 by William Greiman
00003  *
00004  * This file is part of the Arduino SdFat Library
00005  *
00006  * This Library is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015 
00016  * You should have received a copy of the GNU General Public License
00017  * along with the Arduino SdFat Library.  If not, see
00018  * <http://www.gnu.org/licenses/>.
00019  */
00020 #ifndef SdFatUtil_h
00021 #define SdFatUtil_h
00022 
00026 #include <WProgram.h>
00027 #include <avr/pgmspace.h>
00029 #define PgmPrint(x) SerialPrint_P(PSTR(x))
00030 
00031 #define PgmPrintln(x) SerialPrintln_P(PSTR(x))
00032 
00033 #define NOINLINE __attribute__((noinline))
00034 //------------------------------------------------------------------------------
00036 static int FreeRam(void) {
00037   extern int  __bss_end;
00038   extern int* __brkval;
00039   int free_memory;
00040   if (reinterpret_cast<int>(__brkval) == 0) {
00041     // if no heap use from end of bss section
00042     free_memory = reinterpret_cast<int>(&free_memory)
00043                   - reinterpret_cast<int>(&__bss_end);
00044   } else {
00045     // use from top of stack to heap
00046     free_memory = reinterpret_cast<int>(&free_memory)
00047                   - reinterpret_cast<int>(__brkval);
00048   }
00049   return free_memory;
00050 }
00051 //------------------------------------------------------------------------------
00057 static NOINLINE void SerialPrint_P(PGM_P str) {
00058   for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.print(c);
00059 }
00060 //------------------------------------------------------------------------------
00066 static NOINLINE void SerialPrintln_P(PGM_P str) {
00067   SerialPrint_P(str);
00068   Serial.println();
00069 }
00070 #endif  // #define SdFatUtil_h
 All Data Structures Files Functions Variables Typedefs Friends Defines