mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 189:f392fc9709a3 1 /* mbed Microcontroller Library
AnnaBridge 189:f392fc9709a3 2 * Copyright (c) 2017 ARM Limited
AnnaBridge 189:f392fc9709a3 3 * SPDX-License-Identifier: Apache-2.0
AnnaBridge 189:f392fc9709a3 4 *
AnnaBridge 189:f392fc9709a3 5 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 189:f392fc9709a3 6 * you may not use this file except in compliance with the License.
AnnaBridge 189:f392fc9709a3 7 * You may obtain a copy of the License at
AnnaBridge 189:f392fc9709a3 8 *
AnnaBridge 189:f392fc9709a3 9 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 189:f392fc9709a3 10 *
AnnaBridge 189:f392fc9709a3 11 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 189:f392fc9709a3 12 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 189:f392fc9709a3 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 189:f392fc9709a3 14 * See the License for the specific language governing permissions and
AnnaBridge 189:f392fc9709a3 15 * limitations under the License.
AnnaBridge 189:f392fc9709a3 16 */
AnnaBridge 189:f392fc9709a3 17
AnnaBridge 189:f392fc9709a3 18 #ifndef MBED_SERIALWIREOUTPUT_H
AnnaBridge 189:f392fc9709a3 19 #define MBED_SERIALWIREOUTPUT_H
AnnaBridge 189:f392fc9709a3 20
AnnaBridge 189:f392fc9709a3 21 #if defined(DEVICE_ITM)
AnnaBridge 189:f392fc9709a3 22
AnnaBridge 189:f392fc9709a3 23 #include "hal/itm_api.h"
AnnaBridge 189:f392fc9709a3 24 #include "platform/FileHandle.h"
AnnaBridge 189:f392fc9709a3 25
AnnaBridge 189:f392fc9709a3 26 namespace mbed {
AnnaBridge 189:f392fc9709a3 27
AnnaBridge 189:f392fc9709a3 28 class SerialWireOutput : public FileHandle {
AnnaBridge 189:f392fc9709a3 29
AnnaBridge 189:f392fc9709a3 30 public:
AnnaBridge 189:f392fc9709a3 31
AnnaBridge 189:f392fc9709a3 32 SerialWireOutput(void)
AnnaBridge 189:f392fc9709a3 33 {
AnnaBridge 189:f392fc9709a3 34 /* Initialize ITM using internal init function. */
AnnaBridge 189:f392fc9709a3 35 mbed_itm_init();
AnnaBridge 189:f392fc9709a3 36 }
AnnaBridge 189:f392fc9709a3 37
AnnaBridge 189:f392fc9709a3 38 virtual ssize_t write(const void *buffer, size_t size)
AnnaBridge 189:f392fc9709a3 39 {
AnnaBridge 189:f392fc9709a3 40 mbed_itm_send_block(ITM_PORT_SWO, buffer, size);
AnnaBridge 189:f392fc9709a3 41
AnnaBridge 189:f392fc9709a3 42 return size;
AnnaBridge 189:f392fc9709a3 43 }
AnnaBridge 189:f392fc9709a3 44
AnnaBridge 189:f392fc9709a3 45 virtual ssize_t read(void *buffer, size_t size)
AnnaBridge 189:f392fc9709a3 46 {
AnnaBridge 189:f392fc9709a3 47 /* Reading is not supported by this file handle */
AnnaBridge 189:f392fc9709a3 48 return -EBADF;
AnnaBridge 189:f392fc9709a3 49 }
AnnaBridge 189:f392fc9709a3 50
AnnaBridge 189:f392fc9709a3 51 virtual off_t seek(off_t offset, int whence = SEEK_SET)
AnnaBridge 189:f392fc9709a3 52 {
AnnaBridge 189:f392fc9709a3 53 /* Seeking is not support by this file handler */
AnnaBridge 189:f392fc9709a3 54 return -ESPIPE;
AnnaBridge 189:f392fc9709a3 55 }
AnnaBridge 189:f392fc9709a3 56
AnnaBridge 189:f392fc9709a3 57 virtual off_t size()
AnnaBridge 189:f392fc9709a3 58 {
AnnaBridge 189:f392fc9709a3 59 /* Size is not defined for this file handle */
AnnaBridge 189:f392fc9709a3 60 return -EINVAL;
AnnaBridge 189:f392fc9709a3 61 }
AnnaBridge 189:f392fc9709a3 62
AnnaBridge 189:f392fc9709a3 63 virtual int isatty()
AnnaBridge 189:f392fc9709a3 64 {
AnnaBridge 189:f392fc9709a3 65 /* File handle is used for terminal output */
AnnaBridge 189:f392fc9709a3 66 return true;
AnnaBridge 189:f392fc9709a3 67 }
AnnaBridge 189:f392fc9709a3 68
AnnaBridge 189:f392fc9709a3 69 virtual int close()
AnnaBridge 189:f392fc9709a3 70 {
AnnaBridge 189:f392fc9709a3 71 return 0;
AnnaBridge 189:f392fc9709a3 72 }
AnnaBridge 189:f392fc9709a3 73 };
AnnaBridge 189:f392fc9709a3 74
AnnaBridge 189:f392fc9709a3 75 } // namespace mbed
AnnaBridge 189:f392fc9709a3 76
AnnaBridge 189:f392fc9709a3 77 #endif // DEVICE_ITM
AnnaBridge 189:f392fc9709a3 78
AnnaBridge 189:f392fc9709a3 79 #endif // MBED_SERIALWIREOUTPUT_H