MCU driver/HAL for the Picocell Gateway concentrator board. The firmware implements either a USB CDC protocol or a UART protocol to bridge commands coming from host to the SX1308 SPI interface.

Committer:
dgabino
Date:
Wed Apr 11 14:42:47 2018 +0000
Revision:
0:c76361bd82e8
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dgabino 0:c76361bd82e8 1 /* mbed Microcontroller Library
dgabino 0:c76361bd82e8 2 * Copyright (c) 2006-2013 ARM Limited
dgabino 0:c76361bd82e8 3 *
dgabino 0:c76361bd82e8 4 * Licensed under the Apache License, Version 2.0 (the "License");
dgabino 0:c76361bd82e8 5 * you may not use this file except in compliance with the License.
dgabino 0:c76361bd82e8 6 * You may obtain a copy of the License at
dgabino 0:c76361bd82e8 7 *
dgabino 0:c76361bd82e8 8 * http://www.apache.org/licenses/LICENSE-2.0
dgabino 0:c76361bd82e8 9 *
dgabino 0:c76361bd82e8 10 * Unless required by applicable law or agreed to in writing, software
dgabino 0:c76361bd82e8 11 * distributed under the License is distributed on an "AS IS" BASIS,
dgabino 0:c76361bd82e8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dgabino 0:c76361bd82e8 13 * See the License for the specific language governing permissions and
dgabino 0:c76361bd82e8 14 * limitations under the License.
dgabino 0:c76361bd82e8 15 */
dgabino 0:c76361bd82e8 16 #ifndef MBED_FILEHANDLE_H
dgabino 0:c76361bd82e8 17 #define MBED_FILEHANDLE_H
dgabino 0:c76361bd82e8 18
dgabino 0:c76361bd82e8 19 typedef int FILEHANDLE;
dgabino 0:c76361bd82e8 20
dgabino 0:c76361bd82e8 21 #include <stdio.h>
dgabino 0:c76361bd82e8 22
dgabino 0:c76361bd82e8 23 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
dgabino 0:c76361bd82e8 24 typedef int ssize_t;
dgabino 0:c76361bd82e8 25 typedef long off_t;
dgabino 0:c76361bd82e8 26
dgabino 0:c76361bd82e8 27 #else
dgabino 0:c76361bd82e8 28 # include <sys/types.h>
dgabino 0:c76361bd82e8 29 #endif
dgabino 0:c76361bd82e8 30
dgabino 0:c76361bd82e8 31 namespace mbed {
dgabino 0:c76361bd82e8 32
dgabino 0:c76361bd82e8 33 /** An OO equivalent of the internal FILEHANDLE variable
dgabino 0:c76361bd82e8 34 * and associated _sys_* functions.
dgabino 0:c76361bd82e8 35 *
dgabino 0:c76361bd82e8 36 * FileHandle is an abstract class, needing at least sys_write and
dgabino 0:c76361bd82e8 37 * sys_read to be implmented for a simple interactive device.
dgabino 0:c76361bd82e8 38 *
dgabino 0:c76361bd82e8 39 * No one ever directly tals to/instanciates a FileHandle - it gets
dgabino 0:c76361bd82e8 40 * created by FileSystem, and wrapped up by stdio.
dgabino 0:c76361bd82e8 41 *
dgabino 0:c76361bd82e8 42 * @Note Synchronization level: Set by subclass
dgabino 0:c76361bd82e8 43 */
dgabino 0:c76361bd82e8 44 class FileHandle {
dgabino 0:c76361bd82e8 45
dgabino 0:c76361bd82e8 46 public:
dgabino 0:c76361bd82e8 47 /** Write the contents of a buffer to the file
dgabino 0:c76361bd82e8 48 *
dgabino 0:c76361bd82e8 49 * @param buffer the buffer to write from
dgabino 0:c76361bd82e8 50 * @param length the number of characters to write
dgabino 0:c76361bd82e8 51 *
dgabino 0:c76361bd82e8 52 * @returns
dgabino 0:c76361bd82e8 53 * The number of characters written (possibly 0) on success, -1 on error.
dgabino 0:c76361bd82e8 54 */
dgabino 0:c76361bd82e8 55 virtual ssize_t write(const void* buffer, size_t length) = 0;
dgabino 0:c76361bd82e8 56
dgabino 0:c76361bd82e8 57 /** Close the file
dgabino 0:c76361bd82e8 58 *
dgabino 0:c76361bd82e8 59 * @returns
dgabino 0:c76361bd82e8 60 * Zero on success, -1 on error.
dgabino 0:c76361bd82e8 61 */
dgabino 0:c76361bd82e8 62 virtual int close() = 0;
dgabino 0:c76361bd82e8 63
dgabino 0:c76361bd82e8 64 /** Function read
dgabino 0:c76361bd82e8 65 * Reads the contents of the file into a buffer
dgabino 0:c76361bd82e8 66 *
dgabino 0:c76361bd82e8 67 * @param buffer the buffer to read in to
dgabino 0:c76361bd82e8 68 * @param length the number of characters to read
dgabino 0:c76361bd82e8 69 *
dgabino 0:c76361bd82e8 70 * @returns
dgabino 0:c76361bd82e8 71 * The number of characters read (zero at end of file) on success, -1 on error.
dgabino 0:c76361bd82e8 72 */
dgabino 0:c76361bd82e8 73 virtual ssize_t read(void* buffer, size_t length) = 0;
dgabino 0:c76361bd82e8 74
dgabino 0:c76361bd82e8 75 /** Check if the handle is for a interactive terminal device.
dgabino 0:c76361bd82e8 76 * If so, line buffered behaviour is used by default
dgabino 0:c76361bd82e8 77 *
dgabino 0:c76361bd82e8 78 * @returns
dgabino 0:c76361bd82e8 79 * 1 if it is a terminal,
dgabino 0:c76361bd82e8 80 * 0 otherwise
dgabino 0:c76361bd82e8 81 */
dgabino 0:c76361bd82e8 82 virtual int isatty() = 0;
dgabino 0:c76361bd82e8 83
dgabino 0:c76361bd82e8 84 /** Move the file position to a given offset from a given location.
dgabino 0:c76361bd82e8 85 *
dgabino 0:c76361bd82e8 86 * @param offset The offset from whence to move to
dgabino 0:c76361bd82e8 87 * @param whence SEEK_SET for the start of the file, SEEK_CUR for the
dgabino 0:c76361bd82e8 88 * current file position, or SEEK_END for the end of the file.
dgabino 0:c76361bd82e8 89 *
dgabino 0:c76361bd82e8 90 * @returns
dgabino 0:c76361bd82e8 91 * new file position on success,
dgabino 0:c76361bd82e8 92 * -1 on failure or unsupported
dgabino 0:c76361bd82e8 93 */
dgabino 0:c76361bd82e8 94 virtual off_t lseek(off_t offset, int whence) = 0;
dgabino 0:c76361bd82e8 95
dgabino 0:c76361bd82e8 96 /** Flush any buffers associated with the FileHandle, ensuring it
dgabino 0:c76361bd82e8 97 * is up to date on disk
dgabino 0:c76361bd82e8 98 *
dgabino 0:c76361bd82e8 99 * @returns
dgabino 0:c76361bd82e8 100 * 0 on success or un-needed,
dgabino 0:c76361bd82e8 101 * -1 on error
dgabino 0:c76361bd82e8 102 */
dgabino 0:c76361bd82e8 103 virtual int fsync() = 0;
dgabino 0:c76361bd82e8 104
dgabino 0:c76361bd82e8 105 virtual off_t flen() {
dgabino 0:c76361bd82e8 106 lock();
dgabino 0:c76361bd82e8 107 /* remember our current position */
dgabino 0:c76361bd82e8 108 off_t pos = lseek(0, SEEK_CUR);
dgabino 0:c76361bd82e8 109 if(pos == -1) {
dgabino 0:c76361bd82e8 110 unlock();
dgabino 0:c76361bd82e8 111 return -1;
dgabino 0:c76361bd82e8 112 }
dgabino 0:c76361bd82e8 113 /* seek to the end to get the file length */
dgabino 0:c76361bd82e8 114 off_t res = lseek(0, SEEK_END);
dgabino 0:c76361bd82e8 115 /* return to our old position */
dgabino 0:c76361bd82e8 116 lseek(pos, SEEK_SET);
dgabino 0:c76361bd82e8 117 unlock();
dgabino 0:c76361bd82e8 118 return res;
dgabino 0:c76361bd82e8 119 }
dgabino 0:c76361bd82e8 120
dgabino 0:c76361bd82e8 121 virtual ~FileHandle();
dgabino 0:c76361bd82e8 122
dgabino 0:c76361bd82e8 123 protected:
dgabino 0:c76361bd82e8 124
dgabino 0:c76361bd82e8 125 /** Acquire exclusive access to this object.
dgabino 0:c76361bd82e8 126 */
dgabino 0:c76361bd82e8 127 virtual void lock() {
dgabino 0:c76361bd82e8 128 // Stub
dgabino 0:c76361bd82e8 129 }
dgabino 0:c76361bd82e8 130
dgabino 0:c76361bd82e8 131 /** Release exclusive access to this object.
dgabino 0:c76361bd82e8 132 */
dgabino 0:c76361bd82e8 133 virtual void unlock() {
dgabino 0:c76361bd82e8 134 // Stub
dgabino 0:c76361bd82e8 135 }
dgabino 0:c76361bd82e8 136 };
dgabino 0:c76361bd82e8 137
dgabino 0:c76361bd82e8 138 } // namespace mbed
dgabino 0:c76361bd82e8 139
dgabino 0:c76361bd82e8 140 #endif