SD card interface

Committer:
lharoon
Date:
Mon Oct 08 11:14:07 2012 +0000
Revision:
0:22612ae617a0
1st edition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lharoon 0:22612ae617a0 1 /* mbed Microcontroller Library - Stream
lharoon 0:22612ae617a0 2 * Copyright (c) 2007-2009 ARM Limited. All rights reserved.
lharoon 0:22612ae617a0 3 */
lharoon 0:22612ae617a0 4
lharoon 0:22612ae617a0 5 #ifndef MBED_STREAM_H
lharoon 0:22612ae617a0 6 #define MBED_STREAM_H
lharoon 0:22612ae617a0 7
lharoon 0:22612ae617a0 8 #include "FileLike.h"
lharoon 0:22612ae617a0 9 #include "platform.h"
lharoon 0:22612ae617a0 10 #include <cstdio>
lharoon 0:22612ae617a0 11
lharoon 0:22612ae617a0 12 namespace mbed {
lharoon 0:22612ae617a0 13
lharoon 0:22612ae617a0 14 class Stream : public FileLike {
lharoon 0:22612ae617a0 15
lharoon 0:22612ae617a0 16 public:
lharoon 0:22612ae617a0 17
lharoon 0:22612ae617a0 18 Stream(const char *name = NULL);
lharoon 0:22612ae617a0 19 virtual ~Stream();
lharoon 0:22612ae617a0 20
lharoon 0:22612ae617a0 21 int putc(int c) {
lharoon 0:22612ae617a0 22 fflush(_file);
lharoon 0:22612ae617a0 23 return std::fputc(c, _file);
lharoon 0:22612ae617a0 24 }
lharoon 0:22612ae617a0 25 int puts(const char *s) {
lharoon 0:22612ae617a0 26 fflush(_file);
lharoon 0:22612ae617a0 27 return std::fputs(s, _file);
lharoon 0:22612ae617a0 28 }
lharoon 0:22612ae617a0 29 int getc() {
lharoon 0:22612ae617a0 30 fflush(_file);
lharoon 0:22612ae617a0 31 return std::fgetc(_file);
lharoon 0:22612ae617a0 32 }
lharoon 0:22612ae617a0 33 char *gets(char *s, int size) {
lharoon 0:22612ae617a0 34 fflush(_file);
lharoon 0:22612ae617a0 35 return std::fgets(s,size,_file);;
lharoon 0:22612ae617a0 36 }
lharoon 0:22612ae617a0 37 int printf(const char* format, ...);
lharoon 0:22612ae617a0 38 int scanf(const char* format, ...);
lharoon 0:22612ae617a0 39
lharoon 0:22612ae617a0 40 operator std::FILE*() { return _file; }
lharoon 0:22612ae617a0 41
lharoon 0:22612ae617a0 42 #ifdef MBED_RPC
lharoon 0:22612ae617a0 43 virtual const struct rpc_method *get_rpc_methods();
lharoon 0:22612ae617a0 44 #endif
lharoon 0:22612ae617a0 45
lharoon 0:22612ae617a0 46 protected:
lharoon 0:22612ae617a0 47
lharoon 0:22612ae617a0 48 virtual int close();
lharoon 0:22612ae617a0 49 virtual ssize_t write(const void* buffer, size_t length);
lharoon 0:22612ae617a0 50 virtual ssize_t read(void* buffer, size_t length);
lharoon 0:22612ae617a0 51 virtual off_t lseek(off_t offset, int whence);
lharoon 0:22612ae617a0 52 virtual int isatty();
lharoon 0:22612ae617a0 53 virtual int fsync();
lharoon 0:22612ae617a0 54 virtual off_t flen();
lharoon 0:22612ae617a0 55
lharoon 0:22612ae617a0 56 virtual int _putc(int c) = 0;
lharoon 0:22612ae617a0 57 virtual int _getc() = 0;
lharoon 0:22612ae617a0 58
lharoon 0:22612ae617a0 59 std::FILE *_file;
lharoon 0:22612ae617a0 60
lharoon 0:22612ae617a0 61 };
lharoon 0:22612ae617a0 62
lharoon 0:22612ae617a0 63 } // namespace mbed
lharoon 0:22612ae617a0 64
lharoon 0:22612ae617a0 65 #endif
lharoon 0:22612ae617a0 66