Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
aziz111
Date:
Fri Mar 08 17:15:02 2019 +0000
Revision:
5:569a4894abc1
Parent:
3:78f223d34f36
Final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ethaderu 3:78f223d34f36 1 /* mbed Microcontroller Library
ethaderu 3:78f223d34f36 2 * Copyright (c) 2015 ARM Limited
ethaderu 3:78f223d34f36 3 *
ethaderu 3:78f223d34f36 4 * Licensed under the Apache License, Version 2.0 (the "License");
ethaderu 3:78f223d34f36 5 * you may not use this file except in compliance with the License.
ethaderu 3:78f223d34f36 6 * You may obtain a copy of the License at
ethaderu 3:78f223d34f36 7 *
ethaderu 3:78f223d34f36 8 * http://www.apache.org/licenses/LICENSE-2.0
ethaderu 3:78f223d34f36 9 *
ethaderu 3:78f223d34f36 10 * Unless required by applicable law or agreed to in writing, software
ethaderu 3:78f223d34f36 11 * distributed under the License is distributed on an "AS IS" BASIS,
ethaderu 3:78f223d34f36 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ethaderu 3:78f223d34f36 13 * See the License for the specific language governing permissions and
ethaderu 3:78f223d34f36 14 * limitations under the License.
ethaderu 3:78f223d34f36 15 */
ethaderu 3:78f223d34f36 16 #ifndef MBED_TICKER_API_H
ethaderu 3:78f223d34f36 17 #define MBED_TICKER_API_H
ethaderu 3:78f223d34f36 18
ethaderu 3:78f223d34f36 19 #include "device.h"
ethaderu 3:78f223d34f36 20
ethaderu 3:78f223d34f36 21 typedef uint32_t timestamp_t;
ethaderu 3:78f223d34f36 22
ethaderu 3:78f223d34f36 23 /** Ticker's event structure
ethaderu 3:78f223d34f36 24 */
ethaderu 3:78f223d34f36 25 typedef struct ticker_event_s {
ethaderu 3:78f223d34f36 26 timestamp_t timestamp; /**< Event's timestamp */
ethaderu 3:78f223d34f36 27 uint32_t id; /**< TimerEvent object */
ethaderu 3:78f223d34f36 28 struct ticker_event_s *next; /**< Next event in the queue */
ethaderu 3:78f223d34f36 29 } ticker_event_t;
ethaderu 3:78f223d34f36 30
ethaderu 3:78f223d34f36 31 typedef void (*ticker_event_handler)(uint32_t id);
ethaderu 3:78f223d34f36 32
ethaderu 3:78f223d34f36 33 /** Ticker's interface structure - required API for a ticker
ethaderu 3:78f223d34f36 34 */
ethaderu 3:78f223d34f36 35 typedef struct {
ethaderu 3:78f223d34f36 36 void (*init)(void); /**< Init function */
ethaderu 3:78f223d34f36 37 uint32_t (*read)(void); /**< Read function */
ethaderu 3:78f223d34f36 38 void (*disable_interrupt)(void); /**< Disable interrupt function */
ethaderu 3:78f223d34f36 39 void (*clear_interrupt)(void); /**< Clear interrupt function */
ethaderu 3:78f223d34f36 40 void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */
ethaderu 3:78f223d34f36 41 } ticker_interface_t;
ethaderu 3:78f223d34f36 42
ethaderu 3:78f223d34f36 43 /** Tickers events queue structure
ethaderu 3:78f223d34f36 44 */
ethaderu 3:78f223d34f36 45 typedef struct {
ethaderu 3:78f223d34f36 46 ticker_event_handler event_handler; /**< Event handler */
ethaderu 3:78f223d34f36 47 ticker_event_t *head; /**< A pointer to head */
ethaderu 3:78f223d34f36 48 } ticker_event_queue_t;
ethaderu 3:78f223d34f36 49
ethaderu 3:78f223d34f36 50 /** Tickers data structure
ethaderu 3:78f223d34f36 51 */
ethaderu 3:78f223d34f36 52 typedef struct {
ethaderu 3:78f223d34f36 53 const ticker_interface_t *interface; /**< Ticker's interface */
ethaderu 3:78f223d34f36 54 ticker_event_queue_t *queue; /**< Ticker's events queue */
ethaderu 3:78f223d34f36 55 } ticker_data_t;
ethaderu 3:78f223d34f36 56
ethaderu 3:78f223d34f36 57 #ifdef __cplusplus
ethaderu 3:78f223d34f36 58 extern "C" {
ethaderu 3:78f223d34f36 59 #endif
ethaderu 3:78f223d34f36 60
ethaderu 3:78f223d34f36 61 /** Initialize a ticker and sets the event handler
ethaderu 3:78f223d34f36 62 *
ethaderu 3:78f223d34f36 63 * @param data The ticker's data
ethaderu 3:78f223d34f36 64 * @param handler A handler to be set
ethaderu 3:78f223d34f36 65 */
ethaderu 3:78f223d34f36 66 void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler);
ethaderu 3:78f223d34f36 67
ethaderu 3:78f223d34f36 68 /** Irq handler which goes through the events to trigger events in the past.
ethaderu 3:78f223d34f36 69 *
ethaderu 3:78f223d34f36 70 * @param data The ticker's data
ethaderu 3:78f223d34f36 71 */
ethaderu 3:78f223d34f36 72 void ticker_irq_handler(const ticker_data_t *const data);
ethaderu 3:78f223d34f36 73
ethaderu 3:78f223d34f36 74 /** Remove an event from the queue
ethaderu 3:78f223d34f36 75 *
ethaderu 3:78f223d34f36 76 * @param data The ticker's data
ethaderu 3:78f223d34f36 77 * @param obj The event's queue to be removed
ethaderu 3:78f223d34f36 78 */
ethaderu 3:78f223d34f36 79 void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj);
ethaderu 3:78f223d34f36 80
ethaderu 3:78f223d34f36 81 /** Insert an event from the queue
ethaderu 3:78f223d34f36 82 *
ethaderu 3:78f223d34f36 83 * @param data The ticker's data
ethaderu 3:78f223d34f36 84 * @param obj The event's queue to be removed
ethaderu 3:78f223d34f36 85 * @param timestamp The event's timestamp
ethaderu 3:78f223d34f36 86 * @param id The event object
ethaderu 3:78f223d34f36 87 */
ethaderu 3:78f223d34f36 88 void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id);
ethaderu 3:78f223d34f36 89
ethaderu 3:78f223d34f36 90 /** Read the current ticker's timestamp
ethaderu 3:78f223d34f36 91 *
ethaderu 3:78f223d34f36 92 * @param data The ticker's data
ethaderu 3:78f223d34f36 93 * @return The current timestamp
ethaderu 3:78f223d34f36 94 */
ethaderu 3:78f223d34f36 95 timestamp_t ticker_read(const ticker_data_t *const data);
ethaderu 3:78f223d34f36 96
ethaderu 3:78f223d34f36 97 /** Read the next event's timestamp
ethaderu 3:78f223d34f36 98 *
ethaderu 3:78f223d34f36 99 * @param data The ticker's data
ethaderu 3:78f223d34f36 100 * @return 1 if timestamp is pending event, 0 if there's no event pending
ethaderu 3:78f223d34f36 101 */
ethaderu 3:78f223d34f36 102 int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp);
ethaderu 3:78f223d34f36 103
ethaderu 3:78f223d34f36 104 #ifdef __cplusplus
ethaderu 3:78f223d34f36 105 }
ethaderu 3:78f223d34f36 106 #endif
ethaderu 3:78f223d34f36 107
ethaderu 3:78f223d34f36 108 #endif