PIR grove sensor that sends the sensed data to Thingspeak.com through the wifi module ESP 8266

Dependencies:   mbed

Committer:
skrawool
Date:
Mon Dec 05 16:39:27 2016 +0000
Revision:
0:3954a906acc2
PIR grove sensor that sends the sensed data to thingspeak through the wifi module ESP 8266

Who changed what in which revision?

UserRevisionLine numberNew contents of line
skrawool 0:3954a906acc2 1 /* mbed Microcontroller Library
skrawool 0:3954a906acc2 2 * Copyright (c) 2016 ARM Limited
skrawool 0:3954a906acc2 3 *
skrawool 0:3954a906acc2 4 * Licensed under the Apache License, Version 2.0 (the "License");
skrawool 0:3954a906acc2 5 * you may not use this file except in compliance with the License.
skrawool 0:3954a906acc2 6 * You may obtain a copy of the License at
skrawool 0:3954a906acc2 7 *
skrawool 0:3954a906acc2 8 * http://www.apache.org/licenses/LICENSE-2.0
skrawool 0:3954a906acc2 9 *
skrawool 0:3954a906acc2 10 * Unless required by applicable law or agreed to in writing, software
skrawool 0:3954a906acc2 11 * distributed under the License is distributed on an "AS IS" BASIS,
skrawool 0:3954a906acc2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skrawool 0:3954a906acc2 13 * See the License for the specific language governing permissions and
skrawool 0:3954a906acc2 14 * limitations under the License.
skrawool 0:3954a906acc2 15 */
skrawool 0:3954a906acc2 16
skrawool 0:3954a906acc2 17 #ifndef MBED_EMAC_API_H
skrawool 0:3954a906acc2 18 #define MBED_EMAC_API_H
skrawool 0:3954a906acc2 19
skrawool 0:3954a906acc2 20 #if DEVICE_EMAC
skrawool 0:3954a906acc2 21
skrawool 0:3954a906acc2 22 #include <stdbool.h>
skrawool 0:3954a906acc2 23 #include "emac_stack_mem.h"
skrawool 0:3954a906acc2 24
skrawool 0:3954a906acc2 25 typedef struct emac_interface emac_interface_t;
skrawool 0:3954a906acc2 26
skrawool 0:3954a906acc2 27 /**
skrawool 0:3954a906acc2 28 * EmacInterface
skrawool 0:3954a906acc2 29 *
skrawool 0:3954a906acc2 30 * This interface should be used to abstract low level access to networking hardware
skrawool 0:3954a906acc2 31 */
skrawool 0:3954a906acc2 32
skrawool 0:3954a906acc2 33 /**
skrawool 0:3954a906acc2 34 * Callback to be register with Emac interface and to be called fore received packets
skrawool 0:3954a906acc2 35 *
skrawool 0:3954a906acc2 36 * @param data Arbitrary user data (IP stack)
skrawool 0:3954a906acc2 37 * @param buf Received data
skrawool 0:3954a906acc2 38 */
skrawool 0:3954a906acc2 39 typedef void (*emac_link_input_fn)(void *data, emac_stack_mem_chain_t *buf);
skrawool 0:3954a906acc2 40
skrawool 0:3954a906acc2 41 /**
skrawool 0:3954a906acc2 42 * Callback to be register with Emac interface and to be called for link status changes
skrawool 0:3954a906acc2 43 *
skrawool 0:3954a906acc2 44 * @param data Arbitrary user data (IP stack)
skrawool 0:3954a906acc2 45 * @param up Link status
skrawool 0:3954a906acc2 46 */
skrawool 0:3954a906acc2 47 typedef void (*emac_link_state_change_fn)(void *data, bool up);
skrawool 0:3954a906acc2 48
skrawool 0:3954a906acc2 49 /**
skrawool 0:3954a906acc2 50 * Return maximum transmission unit
skrawool 0:3954a906acc2 51 *
skrawool 0:3954a906acc2 52 * @param emac Emac interface
skrawool 0:3954a906acc2 53 * @return MTU in bytes
skrawool 0:3954a906acc2 54 */
skrawool 0:3954a906acc2 55 typedef uint32_t (*emac_get_mtu_size_fn)(emac_interface_t *emac);
skrawool 0:3954a906acc2 56
skrawool 0:3954a906acc2 57 /**
skrawool 0:3954a906acc2 58 * Return interface name
skrawool 0:3954a906acc2 59 *
skrawool 0:3954a906acc2 60 * @param emac Emac interface
skrawool 0:3954a906acc2 61 * @param name Pointer to where the name should be written
skrawool 0:3954a906acc2 62 * @param size Maximum number of character to copy
skrawool 0:3954a906acc2 63 */
skrawool 0:3954a906acc2 64 typedef void (*emac_get_ifname_fn)(emac_interface_t *emac, char *name, uint8_t size);
skrawool 0:3954a906acc2 65
skrawool 0:3954a906acc2 66 /**
skrawool 0:3954a906acc2 67 * Returns size of the underlying interface HW address size
skrawool 0:3954a906acc2 68 *
skrawool 0:3954a906acc2 69 * @param emac Emac interface
skrawool 0:3954a906acc2 70 * @return HW address size in bytes
skrawool 0:3954a906acc2 71 */
skrawool 0:3954a906acc2 72 typedef uint8_t (*emac_get_hwaddr_size_fn)(emac_interface_t *emac);
skrawool 0:3954a906acc2 73
skrawool 0:3954a906acc2 74 /**
skrawool 0:3954a906acc2 75 * Return interface hw address
skrawool 0:3954a906acc2 76 *
skrawool 0:3954a906acc2 77 * Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size
skrawool 0:3954a906acc2 78 *
skrawool 0:3954a906acc2 79 * @param emac Emac interface
skrawool 0:3954a906acc2 80 * @param addr HW address for underlying interface
skrawool 0:3954a906acc2 81 */
skrawool 0:3954a906acc2 82 typedef void (*emac_get_hwaddr_fn)(emac_interface_t *emac, uint8_t *addr);
skrawool 0:3954a906acc2 83
skrawool 0:3954a906acc2 84 /**
skrawool 0:3954a906acc2 85 * Set HW address for interface
skrawool 0:3954a906acc2 86 *
skrawool 0:3954a906acc2 87 * Provided address has to be of correct size, see @a get_hwaddr_size
skrawool 0:3954a906acc2 88 *
skrawool 0:3954a906acc2 89 * @param emac Emac interface
skrawool 0:3954a906acc2 90 * @param addr Address to be set
skrawool 0:3954a906acc2 91 */
skrawool 0:3954a906acc2 92 typedef void (*emac_set_hwaddr_fn)(emac_interface_t *emac, uint8_t *addr);
skrawool 0:3954a906acc2 93
skrawool 0:3954a906acc2 94 /**
skrawool 0:3954a906acc2 95 * Sends the packet over the link
skrawool 0:3954a906acc2 96 *
skrawool 0:3954a906acc2 97 * That can not be called from an interrupt context.
skrawool 0:3954a906acc2 98 *
skrawool 0:3954a906acc2 99 * @param emac Emac interface
skrawool 0:3954a906acc2 100 * @param buf Packet to be send
skrawool 0:3954a906acc2 101 * @return True if the packet was send successfully, False otherwise
skrawool 0:3954a906acc2 102 */
skrawool 0:3954a906acc2 103 typedef bool (*emac_link_out_fn)(emac_interface_t *emac, emac_stack_mem_t *buf);
skrawool 0:3954a906acc2 104
skrawool 0:3954a906acc2 105 /**
skrawool 0:3954a906acc2 106 * Initializes the HW
skrawool 0:3954a906acc2 107 *
skrawool 0:3954a906acc2 108 * @return True on success, False in case of an error.
skrawool 0:3954a906acc2 109 */
skrawool 0:3954a906acc2 110 typedef bool (*emac_power_up_fn)(emac_interface_t *emac);
skrawool 0:3954a906acc2 111
skrawool 0:3954a906acc2 112 /**
skrawool 0:3954a906acc2 113 * Deinitializes the HW
skrawool 0:3954a906acc2 114 *
skrawool 0:3954a906acc2 115 * @param emac Emac interface
skrawool 0:3954a906acc2 116 */
skrawool 0:3954a906acc2 117 typedef void (*emac_power_down_fn)(emac_interface_t *emac);
skrawool 0:3954a906acc2 118
skrawool 0:3954a906acc2 119 /**
skrawool 0:3954a906acc2 120 * Sets a callback that needs to be called for packets received for that interface
skrawool 0:3954a906acc2 121 *
skrawool 0:3954a906acc2 122 * @param emac Emac interface
skrawool 0:3954a906acc2 123 * @param input_cb Function to be register as a callback
skrawool 0:3954a906acc2 124 * @param data Arbitrary user data to be passed to the callback
skrawool 0:3954a906acc2 125 */
skrawool 0:3954a906acc2 126 typedef void (*emac_set_link_input_cb_fn)(emac_interface_t *emac, emac_link_input_fn input_cb, void *data);
skrawool 0:3954a906acc2 127
skrawool 0:3954a906acc2 128 /**
skrawool 0:3954a906acc2 129 * Sets a callback that needs to be called on link status changes for given interface
skrawool 0:3954a906acc2 130 *
skrawool 0:3954a906acc2 131 * @param emac Emac interface
skrawool 0:3954a906acc2 132 * @param state_cb Function to be register as a callback
skrawool 0:3954a906acc2 133 * @param data Arbitrary user data to be passed to the callback
skrawool 0:3954a906acc2 134 */
skrawool 0:3954a906acc2 135 typedef void (*emac_set_link_state_cb_fn)(emac_interface_t *emac, emac_link_state_change_fn state_cb, void *data);
skrawool 0:3954a906acc2 136
skrawool 0:3954a906acc2 137 typedef struct emac_interface_ops {
skrawool 0:3954a906acc2 138 emac_get_mtu_size_fn get_mtu_size;
skrawool 0:3954a906acc2 139 emac_get_ifname_fn get_ifname;
skrawool 0:3954a906acc2 140 emac_get_hwaddr_size_fn get_hwaddr_size;
skrawool 0:3954a906acc2 141 emac_get_hwaddr_fn get_hwaddr;
skrawool 0:3954a906acc2 142 emac_set_hwaddr_fn set_hwaddr;
skrawool 0:3954a906acc2 143 emac_link_out_fn link_out;
skrawool 0:3954a906acc2 144 emac_power_up_fn power_up;
skrawool 0:3954a906acc2 145 emac_power_down_fn power_down;
skrawool 0:3954a906acc2 146 emac_set_link_input_cb_fn set_link_input_cb;
skrawool 0:3954a906acc2 147 emac_set_link_state_cb_fn set_link_state_cb;
skrawool 0:3954a906acc2 148 } emac_interface_ops_t;
skrawool 0:3954a906acc2 149
skrawool 0:3954a906acc2 150 typedef struct emac_interface {
skrawool 0:3954a906acc2 151 const emac_interface_ops_t ops;
skrawool 0:3954a906acc2 152 void *hw;
skrawool 0:3954a906acc2 153 } emac_interface_t;
skrawool 0:3954a906acc2 154
skrawool 0:3954a906acc2 155 #else
skrawool 0:3954a906acc2 156
skrawool 0:3954a906acc2 157 typedef void *emac_interface_t;
skrawool 0:3954a906acc2 158
skrawool 0:3954a906acc2 159 #endif /* DEVICE_EMAC */
skrawool 0:3954a906acc2 160 #endif /* MBED_EMAC_API_H */