mbed library sources(for async_print)

Dependents:   AsyncPrint

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Jun 15 13:15:08 2015 +0100
Revision:
566:85de60b2bbaf
Parent:
431:255afbe6270c
Synchronized with git revision bf69fa1cfc0d4d59173af0a2d235c2fbc179e45c

Full URL: https://github.com/mbedmicro/mbed/commit/bf69fa1cfc0d4d59173af0a2d235c2fbc179e45c/

commit c4bf11cb6a0f36a1aca90cce128d7a8292df5bda
Merge: 0d58363 77a973c
Author: Mihail Stoyanov <wm@smode.org>
Date: Mon Jun 15 14:41:28 2015 +0300

Merge branch 'master' of https://github.com/mbedmicro/mbed

Conflicts:
workspace_tools/targets.py

commit 0d58363887d11952b26dcefa3229a9a1457b155c
Author: Mihail Stoyanov <wm@smode.org>
Date: Tue Jun 9 16:17:27 2015 +0300

Added Nordic license for the soft device

commit d504a3b58af390c779cb7383df2223d0a500f70a
Merge: 2c5aab7 8902229
Author: Mihail Stoyanov <wm@smode.org>
Date: Tue Jun 9 16:14:47 2015 +0300

Merge branch 'master' of https://github.com/mbedmicro/mbed

commit 2c5aab74eba507d184b74166da059d4100841ff7
Author: Mihail Stoyanov <wm@smode.org>
Date: Wed Jun 3 20:44:25 2015 +0300

Add base MCU support for Cortex-M4. Tidy up targets.py

commit 59b868a517163bf8984baa6c87ad42f86af18391
Merge: 0e23067 927c31a
Author: Mihail Stoyanov <wm@smode.org>
Date: Wed Jun 3 20:39:56 2015 +0300

Merge branch 'master' of https://github.com/mbedmicro/mbed

commit 0e23067718c61808401311bb594ed25fb4ed62c6
Author: Mihail Stoyanov <wm@smode.org>
Date: Tue Jun 2 16:08:08 2015 +0300

Add the Delta NNN40 platform to releases

commit 62a585dcda553b6e3b5c84e90a55b465f0894863
Merge: e1cd545 7a1d25e
Author: Mihail Stoyanov <wm@smode.org>
Date: Tue Jun 2 16:06:44 2015 +0300

Merge branch 'master' of https://github.com/mbedmicro/mbed

Conflicts:
workspace_tools/tests.py

commit e1cd545a9c92c4177f72da964d50d163dae5990f
Merge: 5c5e61f ffd5586
Author: Mihail Stoyanov <wm@smode.org>
Date: Thu May 7 13:07:48 2015 +0300

Merge branch 'master' of https://github.com/mbedmicro/mbed

commit 5c5e61f0ac38d91ad04738fd33af36f91452d984
Author: Mihail Stoyanov <wm@smode.org>
Date: Thu May 7 13:07:35 2015 +0300

Remove the Disco L053 from RTOS tests as it's not ready yet

commit e75efe346742fa22e124861fddf1b51c291f4219
Author: Mihail Stoyanov <wm@smode.org>
Date: Wed May 6 13:49:05 2015 +0300

Tidy up targets.py

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 13:0645d8841f51 1 /* mbed Microcontroller Library
bogdanm 13:0645d8841f51 2 * Copyright (c) 2006-2013 ARM Limited
bogdanm 13:0645d8841f51 3 *
bogdanm 13:0645d8841f51 4 * Licensed under the Apache License, Version 2.0 (the "License");
bogdanm 13:0645d8841f51 5 * you may not use this file except in compliance with the License.
bogdanm 13:0645d8841f51 6 * You may obtain a copy of the License at
bogdanm 13:0645d8841f51 7 *
bogdanm 13:0645d8841f51 8 * http://www.apache.org/licenses/LICENSE-2.0
bogdanm 13:0645d8841f51 9 *
bogdanm 13:0645d8841f51 10 * Unless required by applicable law or agreed to in writing, software
bogdanm 13:0645d8841f51 11 * distributed under the License is distributed on an "AS IS" BASIS,
bogdanm 13:0645d8841f51 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bogdanm 13:0645d8841f51 13 * See the License for the specific language governing permissions and
bogdanm 13:0645d8841f51 14 * limitations under the License.
bogdanm 13:0645d8841f51 15 */
bogdanm 13:0645d8841f51 16 #include "Stream.h"
bogdanm 13:0645d8841f51 17
bogdanm 13:0645d8841f51 18 #include <cstdarg>
bogdanm 13:0645d8841f51 19
bogdanm 13:0645d8841f51 20 namespace mbed {
bogdanm 13:0645d8841f51 21
mbed_official 212:34d62c0b2af6 22 Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
bogdanm 13:0645d8841f51 23 /* open ourselves */
bogdanm 13:0645d8841f51 24 char buf[12]; /* :0x12345678 + null byte */
bogdanm 13:0645d8841f51 25 std::sprintf(buf, ":%p", this);
bogdanm 13:0645d8841f51 26 _file = std::fopen(buf, "w+");
mbed_official 431:255afbe6270c 27 mbed_set_unbuffered_stream(_file);
bogdanm 13:0645d8841f51 28 }
bogdanm 13:0645d8841f51 29
bogdanm 13:0645d8841f51 30 Stream::~Stream() {
bogdanm 13:0645d8841f51 31 fclose(_file);
bogdanm 13:0645d8841f51 32 }
bogdanm 13:0645d8841f51 33
bogdanm 13:0645d8841f51 34 int Stream::putc(int c) {
bogdanm 13:0645d8841f51 35 fflush(_file);
bogdanm 13:0645d8841f51 36 return std::fputc(c, _file);
bogdanm 13:0645d8841f51 37 }
bogdanm 13:0645d8841f51 38 int Stream::puts(const char *s) {
bogdanm 13:0645d8841f51 39 fflush(_file);
bogdanm 13:0645d8841f51 40 return std::fputs(s, _file);
bogdanm 13:0645d8841f51 41 }
bogdanm 13:0645d8841f51 42 int Stream::getc() {
bogdanm 13:0645d8841f51 43 fflush(_file);
mbed_official 431:255afbe6270c 44 return mbed_getc(_file);
bogdanm 13:0645d8841f51 45 }
bogdanm 13:0645d8841f51 46 char* Stream::gets(char *s, int size) {
bogdanm 13:0645d8841f51 47 fflush(_file);
mbed_official 431:255afbe6270c 48 return mbed_gets(s,size,_file);
bogdanm 13:0645d8841f51 49 }
bogdanm 13:0645d8841f51 50
bogdanm 13:0645d8841f51 51 int Stream::close() {
bogdanm 13:0645d8841f51 52 return 0;
bogdanm 13:0645d8841f51 53 }
bogdanm 13:0645d8841f51 54
bogdanm 13:0645d8841f51 55 ssize_t Stream::write(const void* buffer, size_t length) {
bogdanm 13:0645d8841f51 56 const char* ptr = (const char*)buffer;
bogdanm 13:0645d8841f51 57 const char* end = ptr + length;
bogdanm 13:0645d8841f51 58 while (ptr != end) {
bogdanm 13:0645d8841f51 59 if (_putc(*ptr++) == EOF) {
bogdanm 13:0645d8841f51 60 break;
bogdanm 13:0645d8841f51 61 }
bogdanm 13:0645d8841f51 62 }
bogdanm 13:0645d8841f51 63 return ptr - (const char*)buffer;
bogdanm 13:0645d8841f51 64 }
bogdanm 13:0645d8841f51 65
bogdanm 13:0645d8841f51 66 ssize_t Stream::read(void* buffer, size_t length) {
bogdanm 13:0645d8841f51 67 char* ptr = (char*)buffer;
bogdanm 13:0645d8841f51 68 char* end = ptr + length;
bogdanm 13:0645d8841f51 69 while (ptr != end) {
bogdanm 13:0645d8841f51 70 int c = _getc();
bogdanm 13:0645d8841f51 71 if (c==EOF) break;
bogdanm 13:0645d8841f51 72 *ptr++ = c;
bogdanm 13:0645d8841f51 73 }
bogdanm 13:0645d8841f51 74 return ptr - (const char*)buffer;
bogdanm 13:0645d8841f51 75 }
bogdanm 13:0645d8841f51 76
bogdanm 13:0645d8841f51 77 off_t Stream::lseek(off_t offset, int whence) {
bogdanm 13:0645d8841f51 78 return 0;
bogdanm 13:0645d8841f51 79 }
bogdanm 13:0645d8841f51 80
bogdanm 13:0645d8841f51 81 int Stream::isatty() {
bogdanm 13:0645d8841f51 82 return 0;
bogdanm 13:0645d8841f51 83 }
bogdanm 13:0645d8841f51 84
bogdanm 13:0645d8841f51 85 int Stream::fsync() {
bogdanm 13:0645d8841f51 86 return 0;
bogdanm 13:0645d8841f51 87 }
bogdanm 13:0645d8841f51 88
bogdanm 13:0645d8841f51 89 off_t Stream::flen() {
bogdanm 13:0645d8841f51 90 return 0;
bogdanm 13:0645d8841f51 91 }
bogdanm 13:0645d8841f51 92
bogdanm 13:0645d8841f51 93 int Stream::printf(const char* format, ...) {
bogdanm 13:0645d8841f51 94 std::va_list arg;
bogdanm 13:0645d8841f51 95 va_start(arg, format);
bogdanm 13:0645d8841f51 96 fflush(_file);
bogdanm 13:0645d8841f51 97 int r = vfprintf(_file, format, arg);
bogdanm 13:0645d8841f51 98 va_end(arg);
bogdanm 13:0645d8841f51 99 return r;
bogdanm 13:0645d8841f51 100 }
bogdanm 13:0645d8841f51 101
bogdanm 13:0645d8841f51 102 int Stream::scanf(const char* format, ...) {
bogdanm 13:0645d8841f51 103 std::va_list arg;
bogdanm 13:0645d8841f51 104 va_start(arg, format);
bogdanm 13:0645d8841f51 105 fflush(_file);
bogdanm 13:0645d8841f51 106 int r = vfscanf(_file, format, arg);
bogdanm 13:0645d8841f51 107 va_end(arg);
bogdanm 13:0645d8841f51 108 return r;
bogdanm 13:0645d8841f51 109 }
bogdanm 13:0645d8841f51 110
bogdanm 13:0645d8841f51 111 } // namespace mbed