mbed library sources. Supersedes mbed-src. RTC working even after reset

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 02 15:07:44 2016 +0100
Revision:
144:ef7eb2e8f9f7
Parent:
0:9b334a45a8ff
This updates the lib to the mbed lib v125

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_SPISLAVE_H
<> 144:ef7eb2e8f9f7 17 #define MBED_SPISLAVE_H
<> 144:ef7eb2e8f9f7 18
<> 144:ef7eb2e8f9f7 19 #include "platform.h"
<> 144:ef7eb2e8f9f7 20
<> 144:ef7eb2e8f9f7 21 #if DEVICE_SPISLAVE
<> 144:ef7eb2e8f9f7 22
<> 144:ef7eb2e8f9f7 23 #include "spi_api.h"
<> 144:ef7eb2e8f9f7 24
<> 144:ef7eb2e8f9f7 25 namespace mbed {
<> 144:ef7eb2e8f9f7 26
<> 144:ef7eb2e8f9f7 27 /** A SPI slave, used for communicating with a SPI Master device
<> 144:ef7eb2e8f9f7 28 *
<> 144:ef7eb2e8f9f7 29 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
<> 144:ef7eb2e8f9f7 30 *
<> 144:ef7eb2e8f9f7 31 * @Note Synchronization level: Not protected
<> 144:ef7eb2e8f9f7 32 *
<> 144:ef7eb2e8f9f7 33 * Example:
<> 144:ef7eb2e8f9f7 34 * @code
<> 144:ef7eb2e8f9f7 35 * // Reply to a SPI master as slave
<> 144:ef7eb2e8f9f7 36 *
<> 144:ef7eb2e8f9f7 37 * #include "mbed.h"
<> 144:ef7eb2e8f9f7 38 *
<> 144:ef7eb2e8f9f7 39 * SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
<> 144:ef7eb2e8f9f7 40 *
<> 144:ef7eb2e8f9f7 41 * int main() {
<> 144:ef7eb2e8f9f7 42 * device.reply(0x00); // Prime SPI with first reply
<> 144:ef7eb2e8f9f7 43 * while(1) {
<> 144:ef7eb2e8f9f7 44 * if(device.receive()) {
<> 144:ef7eb2e8f9f7 45 * int v = device.read(); // Read byte from master
<> 144:ef7eb2e8f9f7 46 * v = (v + 1) % 0x100; // Add one to it, modulo 256
<> 144:ef7eb2e8f9f7 47 * device.reply(v); // Make this the next reply
<> 144:ef7eb2e8f9f7 48 * }
<> 144:ef7eb2e8f9f7 49 * }
<> 144:ef7eb2e8f9f7 50 * }
<> 144:ef7eb2e8f9f7 51 * @endcode
<> 144:ef7eb2e8f9f7 52 */
<> 144:ef7eb2e8f9f7 53 class SPISlave {
<> 144:ef7eb2e8f9f7 54
<> 144:ef7eb2e8f9f7 55 public:
<> 144:ef7eb2e8f9f7 56
<> 144:ef7eb2e8f9f7 57 /** Create a SPI slave connected to the specified pins
<> 144:ef7eb2e8f9f7 58 *
<> 144:ef7eb2e8f9f7 59 * mosi or miso can be specfied as NC if not used
<> 144:ef7eb2e8f9f7 60 *
<> 144:ef7eb2e8f9f7 61 * @param mosi SPI Master Out, Slave In pin
<> 144:ef7eb2e8f9f7 62 * @param miso SPI Master In, Slave Out pin
<> 144:ef7eb2e8f9f7 63 * @param sclk SPI Clock pin
<> 144:ef7eb2e8f9f7 64 * @param ssel SPI chip select pin
<> 144:ef7eb2e8f9f7 65 */
<> 144:ef7eb2e8f9f7 66 SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel);
<> 144:ef7eb2e8f9f7 67
<> 144:ef7eb2e8f9f7 68 /** Configure the data transmission format
<> 144:ef7eb2e8f9f7 69 *
<> 144:ef7eb2e8f9f7 70 * @param bits Number of bits per SPI frame (4 - 16)
<> 144:ef7eb2e8f9f7 71 * @param mode Clock polarity and phase mode (0 - 3)
<> 144:ef7eb2e8f9f7 72 *
<> 144:ef7eb2e8f9f7 73 * @code
<> 144:ef7eb2e8f9f7 74 * mode | POL PHA
<> 144:ef7eb2e8f9f7 75 * -----+--------
<> 144:ef7eb2e8f9f7 76 * 0 | 0 0
<> 144:ef7eb2e8f9f7 77 * 1 | 0 1
<> 144:ef7eb2e8f9f7 78 * 2 | 1 0
<> 144:ef7eb2e8f9f7 79 * 3 | 1 1
<> 144:ef7eb2e8f9f7 80 * @endcode
<> 144:ef7eb2e8f9f7 81 */
<> 144:ef7eb2e8f9f7 82 void format(int bits, int mode = 0);
<> 144:ef7eb2e8f9f7 83
<> 144:ef7eb2e8f9f7 84 /** Set the spi bus clock frequency
<> 144:ef7eb2e8f9f7 85 *
<> 144:ef7eb2e8f9f7 86 * @param hz SCLK frequency in hz (default = 1MHz)
<> 144:ef7eb2e8f9f7 87 */
<> 144:ef7eb2e8f9f7 88 void frequency(int hz = 1000000);
<> 144:ef7eb2e8f9f7 89
<> 144:ef7eb2e8f9f7 90 /** Polls the SPI to see if data has been received
<> 144:ef7eb2e8f9f7 91 *
<> 144:ef7eb2e8f9f7 92 * @returns
<> 144:ef7eb2e8f9f7 93 * 0 if no data,
<> 144:ef7eb2e8f9f7 94 * 1 otherwise
<> 144:ef7eb2e8f9f7 95 */
<> 144:ef7eb2e8f9f7 96 int receive(void);
<> 144:ef7eb2e8f9f7 97
<> 144:ef7eb2e8f9f7 98 /** Retrieve data from receive buffer as slave
<> 144:ef7eb2e8f9f7 99 *
<> 144:ef7eb2e8f9f7 100 * @returns
<> 144:ef7eb2e8f9f7 101 * the data in the receive buffer
<> 144:ef7eb2e8f9f7 102 */
<> 144:ef7eb2e8f9f7 103 int read(void);
<> 144:ef7eb2e8f9f7 104
<> 144:ef7eb2e8f9f7 105 /** Fill the transmission buffer with the value to be written out
<> 144:ef7eb2e8f9f7 106 * as slave on the next received message from the master.
<> 144:ef7eb2e8f9f7 107 *
<> 144:ef7eb2e8f9f7 108 * @param value the data to be transmitted next
<> 144:ef7eb2e8f9f7 109 */
<> 144:ef7eb2e8f9f7 110 void reply(int value);
<> 144:ef7eb2e8f9f7 111
<> 144:ef7eb2e8f9f7 112 protected:
<> 144:ef7eb2e8f9f7 113 spi_t _spi;
<> 144:ef7eb2e8f9f7 114
<> 144:ef7eb2e8f9f7 115 int _bits;
<> 144:ef7eb2e8f9f7 116 int _mode;
<> 144:ef7eb2e8f9f7 117 int _hz;
<> 144:ef7eb2e8f9f7 118 };
<> 144:ef7eb2e8f9f7 119
<> 144:ef7eb2e8f9f7 120 } // namespace mbed
<> 144:ef7eb2e8f9f7 121
<> 144:ef7eb2e8f9f7 122 #endif
<> 144:ef7eb2e8f9f7 123
<> 144:ef7eb2e8f9f7 124 #endif