added prescaler for 16 bit pwm in LPC1347 target

Fork of mbed-dev by mbed official

Committer:
JojoS
Date:
Sat Sep 10 15:32:04 2016 +0000
Revision:
147:ba84b7dc41a7
Parent:
144:ef7eb2e8f9f7
added prescaler for 16 bit timers (solution as in LPC11xx), default prescaler 31 for max 28 ms period time

Who changed what in which revision?

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