Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
mbed-os/drivers/SerialWireOutput.h@2:798925c9e4a8, 2018-05-01 (annotated)
- Committer:
- gustavatmel
- Date:
- Tue May 01 15:55:34 2018 +0000
- Revision:
- 2:798925c9e4a8
- Parent:
- 1:9c5af431a1f1
bluetooth
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gustavatmel | 1:9c5af431a1f1 | 1 | /* mbed Microcontroller Library |
| gustavatmel | 1:9c5af431a1f1 | 2 | * Copyright (c) 2017 ARM Limited |
| gustavatmel | 1:9c5af431a1f1 | 3 | * |
| gustavatmel | 1:9c5af431a1f1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| gustavatmel | 1:9c5af431a1f1 | 5 | * you may not use this file except in compliance with the License. |
| gustavatmel | 1:9c5af431a1f1 | 6 | * You may obtain a copy of the License at |
| gustavatmel | 1:9c5af431a1f1 | 7 | * |
| gustavatmel | 1:9c5af431a1f1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| gustavatmel | 1:9c5af431a1f1 | 9 | * |
| gustavatmel | 1:9c5af431a1f1 | 10 | * Unless required by applicable law or agreed to in writing, software |
| gustavatmel | 1:9c5af431a1f1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| gustavatmel | 1:9c5af431a1f1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| gustavatmel | 1:9c5af431a1f1 | 13 | * See the License for the specific language governing permissions and |
| gustavatmel | 1:9c5af431a1f1 | 14 | * limitations under the License. |
| gustavatmel | 1:9c5af431a1f1 | 15 | */ |
| gustavatmel | 1:9c5af431a1f1 | 16 | |
| gustavatmel | 1:9c5af431a1f1 | 17 | #if defined(DEVICE_ITM) |
| gustavatmel | 1:9c5af431a1f1 | 18 | |
| gustavatmel | 1:9c5af431a1f1 | 19 | #include "hal/itm_api.h" |
| gustavatmel | 1:9c5af431a1f1 | 20 | #include "platform/FileHandle.h" |
| gustavatmel | 1:9c5af431a1f1 | 21 | |
| gustavatmel | 1:9c5af431a1f1 | 22 | namespace mbed { |
| gustavatmel | 1:9c5af431a1f1 | 23 | |
| gustavatmel | 1:9c5af431a1f1 | 24 | class SerialWireOutput : public FileHandle { |
| gustavatmel | 1:9c5af431a1f1 | 25 | |
| gustavatmel | 1:9c5af431a1f1 | 26 | public: |
| gustavatmel | 1:9c5af431a1f1 | 27 | |
| gustavatmel | 1:9c5af431a1f1 | 28 | SerialWireOutput(void) |
| gustavatmel | 1:9c5af431a1f1 | 29 | { |
| gustavatmel | 1:9c5af431a1f1 | 30 | /* Initialize ITM using internal init function. */ |
| gustavatmel | 1:9c5af431a1f1 | 31 | mbed_itm_init(); |
| gustavatmel | 1:9c5af431a1f1 | 32 | } |
| gustavatmel | 1:9c5af431a1f1 | 33 | |
| gustavatmel | 1:9c5af431a1f1 | 34 | virtual ssize_t write(const void *buffer, size_t size) |
| gustavatmel | 1:9c5af431a1f1 | 35 | { |
| gustavatmel | 1:9c5af431a1f1 | 36 | const unsigned char *buf = static_cast<const unsigned char *>(buffer); |
| gustavatmel | 1:9c5af431a1f1 | 37 | |
| gustavatmel | 1:9c5af431a1f1 | 38 | /* Send buffer one character at a time over the ITM SWO port */ |
| gustavatmel | 1:9c5af431a1f1 | 39 | for (size_t i = 0; i < size; i++) { |
| gustavatmel | 1:9c5af431a1f1 | 40 | mbed_itm_send(ITM_PORT_SWO, buf[i]); |
| gustavatmel | 1:9c5af431a1f1 | 41 | } |
| gustavatmel | 1:9c5af431a1f1 | 42 | return size; |
| gustavatmel | 1:9c5af431a1f1 | 43 | } |
| gustavatmel | 1:9c5af431a1f1 | 44 | |
| gustavatmel | 1:9c5af431a1f1 | 45 | virtual ssize_t read(void *buffer, size_t size) |
| gustavatmel | 1:9c5af431a1f1 | 46 | { |
| gustavatmel | 1:9c5af431a1f1 | 47 | /* Reading is not supported by this file handle */ |
| gustavatmel | 1:9c5af431a1f1 | 48 | return -EBADF; |
| gustavatmel | 1:9c5af431a1f1 | 49 | } |
| gustavatmel | 1:9c5af431a1f1 | 50 | |
| gustavatmel | 1:9c5af431a1f1 | 51 | virtual off_t seek(off_t offset, int whence = SEEK_SET) |
| gustavatmel | 1:9c5af431a1f1 | 52 | { |
| gustavatmel | 1:9c5af431a1f1 | 53 | /* Seeking is not support by this file handler */ |
| gustavatmel | 1:9c5af431a1f1 | 54 | return -ESPIPE; |
| gustavatmel | 1:9c5af431a1f1 | 55 | } |
| gustavatmel | 1:9c5af431a1f1 | 56 | |
| gustavatmel | 1:9c5af431a1f1 | 57 | virtual off_t size() |
| gustavatmel | 1:9c5af431a1f1 | 58 | { |
| gustavatmel | 1:9c5af431a1f1 | 59 | /* Size is not defined for this file handle */ |
| gustavatmel | 1:9c5af431a1f1 | 60 | return -EINVAL; |
| gustavatmel | 1:9c5af431a1f1 | 61 | } |
| gustavatmel | 1:9c5af431a1f1 | 62 | |
| gustavatmel | 1:9c5af431a1f1 | 63 | virtual int isatty() |
| gustavatmel | 1:9c5af431a1f1 | 64 | { |
| gustavatmel | 1:9c5af431a1f1 | 65 | /* File handle is used for terminal output */ |
| gustavatmel | 1:9c5af431a1f1 | 66 | return true; |
| gustavatmel | 1:9c5af431a1f1 | 67 | } |
| gustavatmel | 1:9c5af431a1f1 | 68 | |
| gustavatmel | 1:9c5af431a1f1 | 69 | virtual int close() |
| gustavatmel | 1:9c5af431a1f1 | 70 | { |
| gustavatmel | 1:9c5af431a1f1 | 71 | return 0; |
| gustavatmel | 1:9c5af431a1f1 | 72 | } |
| gustavatmel | 1:9c5af431a1f1 | 73 | }; |
| gustavatmel | 1:9c5af431a1f1 | 74 | |
| gustavatmel | 1:9c5af431a1f1 | 75 | } // namespace mbed |
| gustavatmel | 1:9c5af431a1f1 | 76 | |
| gustavatmel | 1:9c5af431a1f1 | 77 | #endif |
