Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MrBedfordVan 0:b9164b348919 1 /* mbed Microcontroller Library
MrBedfordVan 0:b9164b348919 2 * Copyright (c) 2006-2013 ARM Limited
MrBedfordVan 0:b9164b348919 3 *
MrBedfordVan 0:b9164b348919 4 * Licensed under the Apache License, Version 2.0 (the "License");
MrBedfordVan 0:b9164b348919 5 * you may not use this file except in compliance with the License.
MrBedfordVan 0:b9164b348919 6 * You may obtain a copy of the License at
MrBedfordVan 0:b9164b348919 7 *
MrBedfordVan 0:b9164b348919 8 * http://www.apache.org/licenses/LICENSE-2.0
MrBedfordVan 0:b9164b348919 9 *
MrBedfordVan 0:b9164b348919 10 * Unless required by applicable law or agreed to in writing, software
MrBedfordVan 0:b9164b348919 11 * distributed under the License is distributed on an "AS IS" BASIS,
MrBedfordVan 0:b9164b348919 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MrBedfordVan 0:b9164b348919 13 * See the License for the specific language governing permissions and
MrBedfordVan 0:b9164b348919 14 * limitations under the License.
MrBedfordVan 0:b9164b348919 15 */
MrBedfordVan 0:b9164b348919 16
MrBedfordVan 0:b9164b348919 17 #include <time.h>
MrBedfordVan 0:b9164b348919 18
MrBedfordVan 0:b9164b348919 19 #ifdef __cplusplus
MrBedfordVan 0:b9164b348919 20 extern "C" {
MrBedfordVan 0:b9164b348919 21 #endif
MrBedfordVan 0:b9164b348919 22
MrBedfordVan 0:b9164b348919 23 /** Implementation of the C time.h functions
MrBedfordVan 0:b9164b348919 24 *
MrBedfordVan 0:b9164b348919 25 * Provides mechanisms to set and read the current time, based
MrBedfordVan 0:b9164b348919 26 * on the microcontroller Real-Time Clock (RTC), plus some
MrBedfordVan 0:b9164b348919 27 * standard C manipulation and formating functions.
MrBedfordVan 0:b9164b348919 28 *
MrBedfordVan 0:b9164b348919 29 * Example:
MrBedfordVan 0:b9164b348919 30 * @code
MrBedfordVan 0:b9164b348919 31 * #include "mbed.h"
MrBedfordVan 0:b9164b348919 32 *
MrBedfordVan 0:b9164b348919 33 * int main() {
MrBedfordVan 0:b9164b348919 34 * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
MrBedfordVan 0:b9164b348919 35 *
MrBedfordVan 0:b9164b348919 36 * while(1) {
MrBedfordVan 0:b9164b348919 37 * time_t seconds = time(NULL);
MrBedfordVan 0:b9164b348919 38 *
MrBedfordVan 0:b9164b348919 39 * printf("Time as seconds since January 1, 1970 = %d\n", seconds);
MrBedfordVan 0:b9164b348919 40 *
MrBedfordVan 0:b9164b348919 41 * printf("Time as a basic string = %s", ctime(&seconds));
MrBedfordVan 0:b9164b348919 42 *
MrBedfordVan 0:b9164b348919 43 * char buffer[32];
MrBedfordVan 0:b9164b348919 44 * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
MrBedfordVan 0:b9164b348919 45 * printf("Time as a custom formatted string = %s", buffer);
MrBedfordVan 0:b9164b348919 46 *
MrBedfordVan 0:b9164b348919 47 * wait(1);
MrBedfordVan 0:b9164b348919 48 * }
MrBedfordVan 0:b9164b348919 49 * }
MrBedfordVan 0:b9164b348919 50 * @endcode
MrBedfordVan 0:b9164b348919 51 */
MrBedfordVan 0:b9164b348919 52
MrBedfordVan 0:b9164b348919 53 /** Set the current time
MrBedfordVan 0:b9164b348919 54 *
MrBedfordVan 0:b9164b348919 55 * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
MrBedfordVan 0:b9164b348919 56 * to the time represented by the number of seconds since January 1, 1970
MrBedfordVan 0:b9164b348919 57 * (the UNIX timestamp).
MrBedfordVan 0:b9164b348919 58 *
MrBedfordVan 0:b9164b348919 59 * @param t Number of seconds since January 1, 1970 (the UNIX timestamp)
MrBedfordVan 0:b9164b348919 60 *
MrBedfordVan 0:b9164b348919 61 * Example:
MrBedfordVan 0:b9164b348919 62 * @code
MrBedfordVan 0:b9164b348919 63 * #include "mbed.h"
MrBedfordVan 0:b9164b348919 64 *
MrBedfordVan 0:b9164b348919 65 * int main() {
MrBedfordVan 0:b9164b348919 66 * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
MrBedfordVan 0:b9164b348919 67 * }
MrBedfordVan 0:b9164b348919 68 * @endcode
MrBedfordVan 0:b9164b348919 69 */
MrBedfordVan 0:b9164b348919 70 void set_time(time_t t);
MrBedfordVan 0:b9164b348919 71
MrBedfordVan 0:b9164b348919 72 /** Attach an external RTC to be used for the C time functions
MrBedfordVan 0:b9164b348919 73 *
MrBedfordVan 0:b9164b348919 74 * Do not call this function from an interrupt while an RTC read/write operation may be occurring
MrBedfordVan 0:b9164b348919 75 *
MrBedfordVan 0:b9164b348919 76 * @param read_rtc pointer to function which returns current UNIX timestamp
MrBedfordVan 0:b9164b348919 77 * @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL
MrBedfordVan 0:b9164b348919 78 * @param init_rtc pointer to funtion which initializes RTC, can be NULL
MrBedfordVan 0:b9164b348919 79 * @param isenabled_rtc pointer to function wich returns if the rtc is enabled, can be NULL
MrBedfordVan 0:b9164b348919 80 */
MrBedfordVan 0:b9164b348919 81 void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void));
MrBedfordVan 0:b9164b348919 82
MrBedfordVan 0:b9164b348919 83 #ifdef __cplusplus
MrBedfordVan 0:b9164b348919 84 }
MrBedfordVan 0:b9164b348919 85 #endif