You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Device-specific extensions | No | No | Possible using derived types
38
39
Newline conversion | Yes (enabled with JSON) | No | No
39
40
Error indications | EOF, ferror, set errno | Return -1, set errno | Return negative error code
@@ -51,9 +52,13 @@ Calls are provided to attach already-opened lower levels to the higher levels:
51
52
-`FILE *fdopen(int fd, const char *mode)` bind a POSIX file descriptor to a stdio FILE.
52
53
-`FILE *fdopen(FileHandle *fh, const char *mode)` bind a FileHandle to a stdio FILE.
53
54
55
+
The only call provided to map from higher level to lower-level is:
56
+
57
+
-`FileHandle *mbed_file_handle(int fd)` obtain the FileHandle for a POSIX file descriptor
58
+
54
59
The standard POSIX function `int fileno(FILE *stream)` may be available to map from `FILE` to file descriptor, depending on the toolchain and C library in use - it is not usable in fully portable Mbed OS code.
55
60
56
-
As it is not possible to map from higher levels to lower levels, if code needs to access the lower levels, use a lower-level open call, so the lower-level handle is known. Then, bind that to the higher level..
61
+
As it is not possible to map from `FILE`to lower levels, if code needs to access the lower levels, rather than use `fopen`, use a lower-level open call then `fdopen`to create the `FILE`.
57
62
58
63
The POSIX file descriptors for the console are available as `STDIN_FILENO`, `STDOUT_FILENO` and `STDERR_FILENO`, permitting operations such as `fsync(STDERR_FILENO)`, which would for example drain `UARTSerial`s output buffer.
59
64
@@ -112,6 +117,14 @@ Important notes on sigio:
112
117
113
118
Ordinary files do not generate sigio callbacks because they are always readable and writable.
114
119
120
+
#### Suspending a device
121
+
122
+
Having a device open via a `FileHandle` may cost power, especially if open for input. For example, for `UARTSerial` to be able to receive data, the system must not enter deep sleep, so deep sleep will be prevented while the `UARTSerial` is active.
123
+
124
+
To permit power saving, the device can be closed or destroyed, or you can indicate that you do not currently require input or output by calling `FileHandle::enable_input` or `FileHandle::enable_output`. Disabling input or output effectively suspends the device in that direction, which can permit power saving.
125
+
126
+
This is particularly useful when an application does not require console input - it can indicate this by calling `mbed_file_handle(STDIN_FILENO)->enable_input(false)` once at the start of the program. This will permit deep sleep when `platform.stdio-buffered-serial` is set to true.
127
+
115
128
#### Stream-derived FileHandles
116
129
117
130
`Stream` is a legacy class that provides an abstract interface for streams similar to the `FileHandle` class. The difference is that the `Stream` API is built around the `getc` and `putc` set of functions, whereas `FileHandle` is built around `read` and `write`. This makes implementations simpler but limits what is possible with the API. Because of this, implementing the `FileHandle` API directly is suggested API for new device drivers.
Copy file name to clipboardExpand all lines: docs/api/platform/PowerManagement.md
+9-1Lines changed: 9 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,15 @@ These Mbed OS drivers can lock the deep sleep:
38
38
-`SPI`.
39
39
-`I2C`.
40
40
-`CAN`.
41
-
-`SerialBase`.
41
+
-`SerialBase` (and hence `Serial` and `UARTSerial`)
42
+
43
+
#### Console versus deep sleep
44
+
45
+
By default, on entry to `main`, the deep sleep lock will not be held, so deep sleep will be possible until a driver or other code locks it.
46
+
47
+
However, if `platform.stdio-buffered-serial` is set to true, then `UARTSerial` installs an interrupt handler to receive serial data for `stdin`. This will block deep sleep. To permit deep sleep, input must be suspended (permanently or temporarily). Making the call `mbed_file_handle(STDIN_FILENO)->enable_input(false)` from the application gives the console driver, whatever it is, permission to stop reception. If `UARTSerial` is providing `stdin`, this removes the receive interrupt handler and releases the deep sleep lock.
48
+
49
+
For more information see [`FileHandle`](filehandle.html).
0 commit comments