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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.