NanoStack lib for Cortex-M4
Dependents: mbedEndpointNetwork mbedEndpointNetworkMJK
Fork of Nanostack_lib by
inc/event_os/system_event.h@11:1b7aaf37a131, 2014-06-25 (annotated)
- Committer:
- jusu_81
- Date:
- Wed Jun 25 21:05:58 2014 +0000
- Revision:
- 11:1b7aaf37a131
- Parent:
- 4:c449bead5cf3
- Child:
- 12:acef6f596835
Added C++ & C Extern C sectors to hedaer files.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mika Karjalainen |
4:c449bead5cf3 | 1 | #ifndef _SYSTEM_EVENT_H_ |
Mika Karjalainen |
4:c449bead5cf3 | 2 | #define _SYSTEM_EVENT_H_ |
Mika Karjalainen |
4:c449bead5cf3 | 3 | /* |
Mika Karjalainen |
4:c449bead5cf3 | 4 | * Copyright ARM Ltd 2014 |
Mika Karjalainen |
4:c449bead5cf3 | 5 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 6 | |
Mika Karjalainen |
4:c449bead5cf3 | 7 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 8 | * \file system_event.h |
Mika Karjalainen |
4:c449bead5cf3 | 9 | * \brief Library Event and Timer API. |
Mika Karjalainen |
4:c449bead5cf3 | 10 | * |
Mika Karjalainen |
4:c449bead5cf3 | 11 | * \section Libary-Event-API Library Event API |
Mika Karjalainen |
4:c449bead5cf3 | 12 | * - event_dispatch(), NanoStack 2.x event dispatcher loop call |
Mika Karjalainen |
4:c449bead5cf3 | 13 | * - arm_ns_event_send(), Event send function |
Mika Karjalainen |
4:c449bead5cf3 | 14 | * |
Mika Karjalainen |
4:c449bead5cf3 | 15 | * \section Global-Interrupts-API Global Interrupts API |
Mika Karjalainen |
4:c449bead5cf3 | 16 | * - lib_enter_critical(), Disable Interrupt |
Mika Karjalainen |
4:c449bead5cf3 | 17 | * - lib_exit_critical(), Enable Interrupt |
Mika Karjalainen |
4:c449bead5cf3 | 18 | * Application can handle global interrupts by using next two macros. |
Mika Karjalainen |
4:c449bead5cf3 | 19 | * These are mandatory if interrupt uses event_send() function. |
Mika Karjalainen |
4:c449bead5cf3 | 20 | * |
Mika Karjalainen |
4:c449bead5cf3 | 21 | * \section Library-Timer-API Library Timer API |
Mika Karjalainen |
4:c449bead5cf3 | 22 | * - timer_sys_event(), Used to allocate timer events |
Mika Karjalainen |
4:c449bead5cf3 | 23 | * - timer_sys_event_cancel(), Used to cancel allocated timer events |
Mika Karjalainen |
4:c449bead5cf3 | 24 | * |
Mika Karjalainen |
4:c449bead5cf3 | 25 | * If the application needs any timers it can allocate one with timer_sys_event() function. |
Mika Karjalainen |
4:c449bead5cf3 | 26 | * After the needed timers are allocated system timer event occurs. |
Mika Karjalainen |
4:c449bead5cf3 | 27 | * |
Mika Karjalainen |
4:c449bead5cf3 | 28 | * Note: Library supports 6 concurrent timers for the application layer use. Quite often the application can multiplex a single timer for multiple purposes. |
Mika Karjalainen |
4:c449bead5cf3 | 29 | * Library timer API is not mandatory to be used if own timer drivers are desired. |
Mika Karjalainen |
4:c449bead5cf3 | 30 | * |
Mika Karjalainen |
4:c449bead5cf3 | 31 | * \section Events-intro Events introduction |
Mika Karjalainen |
4:c449bead5cf3 | 32 | * |
Mika Karjalainen |
4:c449bead5cf3 | 33 | * NanoStack2.0 Library works in event-based scheduling model. This chapter describes the event functionality on the application level. |
Mika Karjalainen |
4:c449bead5cf3 | 34 | * All events are handled in tasklet_main() function and therefore the main.c file must contain this function. The main event senders are SYSTEM, SYSTEM_TIMER, TL_DNSSD, APP_SPESIFIC_EVENT and EV_NETWORK. See below for example of a tasklet_main(). |
Mika Karjalainen |
4:c449bead5cf3 | 35 | * |
Mika Karjalainen |
4:c449bead5cf3 | 36 | *@code |
Mika Karjalainen |
4:c449bead5cf3 | 37 | void tasklet_main(event_t *event) |
Mika Karjalainen |
4:c449bead5cf3 | 38 | { |
Mika Karjalainen |
4:c449bead5cf3 | 39 | switch(event->sender) |
Mika Karjalainen |
4:c449bead5cf3 | 40 | { |
Mika Karjalainen |
4:c449bead5cf3 | 41 | |
Mika Karjalainen |
4:c449bead5cf3 | 42 | case SYSTEM: |
Mika Karjalainen |
4:c449bead5cf3 | 43 | if (event->event == EV_INIT) |
Mika Karjalainen |
4:c449bead5cf3 | 44 | { |
Mika Karjalainen |
4:c449bead5cf3 | 45 | //Initializes application layer tasklet |
Mika Karjalainen |
4:c449bead5cf3 | 46 | main_initilize(); |
Mika Karjalainen |
4:c449bead5cf3 | 47 | //... |
Mika Karjalainen |
4:c449bead5cf3 | 48 | } |
Mika Karjalainen |
4:c449bead5cf3 | 49 | else if (event->event == EV_DEBUG) |
Mika Karjalainen |
4:c449bead5cf3 | 50 | { |
Mika Karjalainen |
4:c449bead5cf3 | 51 | //Events from debug interface are handled here. |
Mika Karjalainen |
4:c449bead5cf3 | 52 | int16_t u_data = debug_get(); |
Mika Karjalainen |
4:c449bead5cf3 | 53 | if(u_data != -1) |
Mika Karjalainen |
4:c449bead5cf3 | 54 | { |
Mika Karjalainen |
4:c449bead5cf3 | 55 | ... |
Mika Karjalainen |
4:c449bead5cf3 | 56 | } |
Mika Karjalainen |
4:c449bead5cf3 | 57 | } |
Mika Karjalainen |
4:c449bead5cf3 | 58 | break; |
Mika Karjalainen |
4:c449bead5cf3 | 59 | |
Mika Karjalainen |
4:c449bead5cf3 | 60 | case EV_NETWORK: |
Mika Karjalainen |
4:c449bead5cf3 | 61 | //Network Event state event handler |
Mika Karjalainen |
4:c449bead5cf3 | 62 | app_parse_network_event(event->event); |
Mika Karjalainen |
4:c449bead5cf3 | 63 | break; |
Mika Karjalainen |
4:c449bead5cf3 | 64 | |
Mika Karjalainen |
4:c449bead5cf3 | 65 | case SYSTEM_TIMER: |
Mika Karjalainen |
4:c449bead5cf3 | 66 | //SYSTEM_TIMER events are handled here |
Mika Karjalainen |
4:c449bead5cf3 | 67 | timer_sys_event_cancel(event->event); |
Mika Karjalainen |
4:c449bead5cf3 | 68 | switch(event->event) |
Mika Karjalainen |
4:c449bead5cf3 | 69 | { |
Mika Karjalainen |
4:c449bead5cf3 | 70 | } |
Mika Karjalainen |
4:c449bead5cf3 | 71 | break; |
Mika Karjalainen |
4:c449bead5cf3 | 72 | |
Mika Karjalainen |
4:c449bead5cf3 | 73 | case APP_SPESIFIC_EVENT: |
Mika Karjalainen |
4:c449bead5cf3 | 74 | //Applications own event type |
Mika Karjalainen |
4:c449bead5cf3 | 75 | break; |
Mika Karjalainen |
4:c449bead5cf3 | 76 | |
Mika Karjalainen |
4:c449bead5cf3 | 77 | default: |
Mika Karjalainen |
4:c449bead5cf3 | 78 | break; |
Mika Karjalainen |
4:c449bead5cf3 | 79 | } |
Mika Karjalainen |
4:c449bead5cf3 | 80 | } |
Mika Karjalainen |
4:c449bead5cf3 | 81 | |
Mika Karjalainen |
4:c449bead5cf3 | 82 | *@endcode |
Mika Karjalainen |
4:c449bead5cf3 | 83 | * |
Mika Karjalainen |
4:c449bead5cf3 | 84 | * \subsection ev_init EV_INIT event type |
Mika Karjalainen |
4:c449bead5cf3 | 85 | * |
Mika Karjalainen |
4:c449bead5cf3 | 86 | * This is received only once after startup per tasklet. Typically when event has been received application will set MAC scan channel list, |
Mika Karjalainen |
4:c449bead5cf3 | 87 | * open sockets, set certificate Chain, configure Multicast Parameter, load last session form NVM etc. |
Mika Karjalainen |
4:c449bead5cf3 | 88 | * Also the protocol module stack bootstrap is started here. This can also be done elsewhere if necessary. |
Mika Karjalainen |
4:c449bead5cf3 | 89 | * |
Mika Karjalainen |
4:c449bead5cf3 | 90 | * NOTE: main_initialize() function call is mandatory here. See below for an example code of EV_INIT handling: |
Mika Karjalainen |
4:c449bead5cf3 | 91 | * @code |
jusu_81 | 11:1b7aaf37a131 | 92 | #include �zip_certificates.h� // ZIP test certificates |
Mika Karjalainen |
4:c449bead5cf3 | 93 | static PL_LARGE int8_t app_udp_socket = 0; //UDP socket variable |
Mika Karjalainen |
4:c449bead5cf3 | 94 | static PL_LARGE int8_t app_tcp_socket = 0; //TCP server socket variable |
Mika Karjalainen |
4:c449bead5cf3 | 95 | static PL_LARGE int8_t app_tcp_socket_client = 0; //TCP client socket variable |
Mika Karjalainen |
4:c449bead5cf3 | 96 | static PL_LARGE int8_t app_raw_socket = 0; //RAW socket variable for ICMP communications |
Mika Karjalainen |
4:c449bead5cf3 | 97 | static PL_LARGE certificate_info_entry_t certificate_chain_entry; // Certificate Chain entry |
Mika Karjalainen |
4:c449bead5cf3 | 98 | |
Mika Karjalainen |
4:c449bead5cf3 | 99 | void main_initilize(void) |
Mika Karjalainen |
4:c449bead5cf3 | 100 | { |
Mika Karjalainen |
4:c449bead5cf3 | 101 | //Initializes tasklet allocation. This has to be executed here. |
Mika Karjalainen |
4:c449bead5cf3 | 102 | main_initialize(); |
Mika Karjalainen |
4:c449bead5cf3 | 103 | //Generate CertiChain for length 3 |
Mika Karjalainen |
4:c449bead5cf3 | 104 | certificate_chain_entry.certificate_owner = SEC_CERTIFICATE_ZIP; |
Mika Karjalainen |
4:c449bead5cf3 | 105 | certificate_chain_entry.chain_length = 4; |
Mika Karjalainen |
4:c449bead5cf3 | 106 | //Set Root |
Mika Karjalainen |
4:c449bead5cf3 | 107 | certificate_chain_entry.certi_chain[0] = root_certificate; |
Mika Karjalainen |
4:c449bead5cf3 | 108 | certificate_chain_entry.certi_len[0] = sizeof(root_certificate); |
Mika Karjalainen |
4:c449bead5cf3 | 109 | certificate_chain_entry.key_chain[0] = rootpk; |
Mika Karjalainen |
4:c449bead5cf3 | 110 | //Set MICA |
Mika Karjalainen |
4:c449bead5cf3 | 111 | certificate_chain_entry.certi_chain[1] = mca_certi; |
Mika Karjalainen |
4:c449bead5cf3 | 112 | certificate_chain_entry.certi_len[1] = sizeof(mca_certi); |
Mika Karjalainen |
4:c449bead5cf3 | 113 | certificate_chain_entry.key_chain[1] = mca_pv; |
Mika Karjalainen |
4:c449bead5cf3 | 114 | // Set MCA |
Mika Karjalainen |
4:c449bead5cf3 | 115 | certificate_chain_entry.certi_chain[2] = mica_certi; |
Mika Karjalainen |
4:c449bead5cf3 | 116 | certificate_chain_entry.certi_len[2] = sizeof(mica_certi); |
Mika Karjalainen |
4:c449bead5cf3 | 117 | certificate_chain_entry.key_chain[2] = mica_pv; |
Mika Karjalainen |
4:c449bead5cf3 | 118 | //Set Dev |
Mika Karjalainen |
4:c449bead5cf3 | 119 | certificate_chain_entry.certi_chain[3] = dev_certi; |
Mika Karjalainen |
4:c449bead5cf3 | 120 | certificate_chain_entry.certi_len[3] = sizeof(dev_certi); |
Mika Karjalainen |
4:c449bead5cf3 | 121 | certificate_chain_entry.key_chain[3] = dev_pv; |
Mika Karjalainen |
4:c449bead5cf3 | 122 | |
Mika Karjalainen |
4:c449bead5cf3 | 123 | //Set chain list |
Mika Karjalainen |
4:c449bead5cf3 | 124 | sec_certificate_list_update(&certificate_cahin_entry); |
Mika Karjalainen |
4:c449bead5cf3 | 125 | |
Mika Karjalainen |
4:c449bead5cf3 | 126 | //Open UDP Socket to Port 64771 |
Mika Karjalainen |
4:c449bead5cf3 | 127 | app_udp_socket = socket_open(SOCKET_UDP, 64771, mainreceive_udp); |
Mika Karjalainen |
4:c449bead5cf3 | 128 | |
Mika Karjalainen |
4:c449bead5cf3 | 129 | //Open TCP Socket to Port 80 & 81 |
Mika Karjalainen |
4:c449bead5cf3 | 130 | app_tcp_socket = socket_open(SOCKET_TCP,80, mainreceive_tcp_server); |
Mika Karjalainen |
4:c449bead5cf3 | 131 | app_tcp_socket_client = socket_open(SOCKET_TCP,81, mainreceive_tcp_client); |
Mika Karjalainen |
4:c449bead5cf3 | 132 | |
Mika Karjalainen |
4:c449bead5cf3 | 133 | //Open ICMP RAW socket |
Mika Karjalainen |
4:c449bead5cf3 | 134 | app_raw_socket = socket_open(SOCKET_ICMP,0xffff, mainreceive_raw); |
Mika Karjalainen |
4:c449bead5cf3 | 135 | |
Mika Karjalainen |
4:c449bead5cf3 | 136 | // Set one TCP socket to listen state, Cipher mode parameter is unused when |
Mika Karjalainen |
4:c449bead5cf3 | 137 | //Socket Type is PROTOCOL_UDP or PROTOCOL_TCP |
Mika Karjalainen |
4:c449bead5cf3 | 138 | socket_listen(app_tcp_socket); |
Mika Karjalainen |
4:c449bead5cf3 | 139 | multicast_set_parameters(10,0,20,3,75 ); |
Mika Karjalainen |
4:c449bead5cf3 | 140 | if(nwk_nvm_load_nvm_data_to_stack() == 0) |
Mika Karjalainen |
4:c449bead5cf3 | 141 | { |
Mika Karjalainen |
4:c449bead5cf3 | 142 | debug("NVM session Load and NWKID filter enabled\r\n"); |
Mika Karjalainen |
4:c449bead5cf3 | 143 | nwk_id_filter_enabled = 1; |
Mika Karjalainen |
4:c449bead5cf3 | 144 | if(nwk_nvm_get_network_role(&net_start_operating_mode, &pana_suite) == 0) |
Mika Karjalainen |
4:c449bead5cf3 | 145 | { |
Mika Karjalainen |
4:c449bead5cf3 | 146 | int8_t retval; |
Mika Karjalainen |
4:c449bead5cf3 | 147 | debug("Start After Reset\r\n"); |
Mika Karjalainen |
4:c449bead5cf3 | 148 | if(nwk_nvm_get_network_id(network_id_filter) == 0) |
Mika Karjalainen |
4:c449bead5cf3 | 149 | { |
Mika Karjalainen |
4:c449bead5cf3 | 150 | retval = net_zip_start(channel_list, 0xffff,network_id_filter,net_start_operating_mode, pana_suite ); |
Mika Karjalainen |
4:c449bead5cf3 | 151 | } |
Mika Karjalainen |
4:c449bead5cf3 | 152 | else |
Mika Karjalainen |
4:c449bead5cf3 | 153 | { |
Mika Karjalainen |
4:c449bead5cf3 | 154 | network_id_filter[0] = 't'; |
Mika Karjalainen |
4:c449bead5cf3 | 155 | retval = net_zip_start(channel_list, 0xffff,0,net_start_operating_mode, pana_suite ); |
Mika Karjalainen |
4:c449bead5cf3 | 156 | } |
Mika Karjalainen |
4:c449bead5cf3 | 157 | if(retval != 0) |
Mika Karjalainen |
4:c449bead5cf3 | 158 | { |
Mika Karjalainen |
4:c449bead5cf3 | 159 | debug_int(retval); |
Mika Karjalainen |
4:c449bead5cf3 | 160 | debug("Start Fail code\r\n"); |
Mika Karjalainen |
4:c449bead5cf3 | 161 | } |
Mika Karjalainen |
4:c449bead5cf3 | 162 | else |
Mika Karjalainen |
4:c449bead5cf3 | 163 | { |
Mika Karjalainen |
4:c449bead5cf3 | 164 | debug("ZigBeeIP Bootstrap started\r\n"); |
Mika Karjalainen |
4:c449bead5cf3 | 165 | } |
Mika Karjalainen |
4:c449bead5cf3 | 166 | } |
Mika Karjalainen |
4:c449bead5cf3 | 167 | |
Mika Karjalainen |
4:c449bead5cf3 | 168 | } |
Mika Karjalainen |
4:c449bead5cf3 | 169 | else |
Mika Karjalainen |
4:c449bead5cf3 | 170 | { |
Mika Karjalainen |
4:c449bead5cf3 | 171 | //Set NanoStack 2.0 in Router mode, Chan channels 11-16, PAN-IDfilter 0xffff and PANA TLS chiphersuite PSK |
Mika Karjalainen |
4:c449bead5cf3 | 172 | net_zip_start(0x07fff800, 0xffff,0, NW_INFRA_ROUTER, SEC_SOCKET_CHIPHERSUITE_PSK); |
Mika Karjalainen |
4:c449bead5cf3 | 173 | } |
Mika Karjalainen |
4:c449bead5cf3 | 174 | } |
Mika Karjalainen |
4:c449bead5cf3 | 175 | |
Mika Karjalainen |
4:c449bead5cf3 | 176 | * @endcode |
Mika Karjalainen |
4:c449bead5cf3 | 177 | * |
Mika Karjalainen |
4:c449bead5cf3 | 178 | * \subsection net-event Network event |
Mika Karjalainen |
4:c449bead5cf3 | 179 | * |
Mika Karjalainen |
4:c449bead5cf3 | 180 | * Network events are enabled after stack has been started with net_start() function call or after indicated network failure status. |
Mika Karjalainen |
4:c449bead5cf3 | 181 | * The stack uses these events to inform the application of the network connection status. |
Mika Karjalainen |
4:c449bead5cf3 | 182 | * |
Mika Karjalainen |
4:c449bead5cf3 | 183 | * | Event Type | Value | Description | |
Mika Karjalainen |
4:c449bead5cf3 | 184 | * | :-----------------------: | :---: | :-----------------------------------------------: | |
Mika Karjalainen |
4:c449bead5cf3 | 185 | * | NET_READY | 0 | Connection to access point is ready | |
Mika Karjalainen |
4:c449bead5cf3 | 186 | * | NET_NO_BEACON | 1 | No Coordinator available | |
Mika Karjalainen |
4:c449bead5cf3 | 187 | * | NET_NO_ND_ROUTER | 2 | No ND Router available | |
Mika Karjalainen |
4:c449bead5cf3 | 188 | * | NET_NO_PANA_SERVER | 3 | No Response for Pana PCI | |
Mika Karjalainen |
4:c449bead5cf3 | 189 | * | NET_PANA_SERVER_AUTH_FAIL | 4 | Pana authentication process fail | |
Mika Karjalainen |
4:c449bead5cf3 | 190 | * | NET_BORDER_ROUTER_LOST | 5 | Connection to Border Router lost | |
Mika Karjalainen |
4:c449bead5cf3 | 191 | * | NET_PARENT_POLL_FAIL | 6 | Host poll to parent have been failed direct 3 time| |
Mika Karjalainen |
4:c449bead5cf3 | 192 | * |
Mika Karjalainen |
4:c449bead5cf3 | 193 | * Application should start stack again scanning all 16 channels again when receiving NET_PARENT_POLL_FAIL. |
Mika Karjalainen |
4:c449bead5cf3 | 194 | * When NET_NO_BEACON, NET_NO_ND_ROUTER, NET_NO_PANA-SERVER or NET_PANA_SERVER_AUTH_FAIL event occur the stack will enter IDLE state automatically. |
Mika Karjalainen |
4:c449bead5cf3 | 195 | * In case of NET_BORDER_ROUTER_LOST event stack starts scanning automatically for new network and application must wait for the result before attempting to transmit data. |
Mika Karjalainen |
4:c449bead5cf3 | 196 | * |
Mika Karjalainen |
4:c449bead5cf3 | 197 | * \subsection app-specific_event Application Specific Event Send |
Mika Karjalainen |
4:c449bead5cf3 | 198 | * |
Mika Karjalainen |
4:c449bead5cf3 | 199 | * This chapter describes how application can send events to itself. This is useful if application wants for example to receive a signal from an interrupt or in other case. |
Mika Karjalainen |
4:c449bead5cf3 | 200 | * Event structure sender has to be APP_SPESIFIC_EVENT. |
Mika Karjalainen |
4:c449bead5cf3 | 201 | * |
Mika Karjalainen |
4:c449bead5cf3 | 202 | * See below for a simple example that only initializes Debug interface and Port A.7 GPIO to interrupt. Interrupt handler then sends event to application. |
Mika Karjalainen |
4:c449bead5cf3 | 203 | * @code |
Mika Karjalainen |
4:c449bead5cf3 | 204 | |
Mika Karjalainen |
4:c449bead5cf3 | 205 | |
Mika Karjalainen |
4:c449bead5cf3 | 206 | #include "socket_api.h" |
Mika Karjalainen |
4:c449bead5cf3 | 207 | #include "net.h" |
Mika Karjalainen |
4:c449bead5cf3 | 208 | #include "system_event.h" |
Mika Karjalainen |
4:c449bead5cf3 | 209 | #include "string.h" |
Mika Karjalainen |
4:c449bead5cf3 | 210 | #include "ns_debug.h" |
Mika Karjalainen |
4:c449bead5cf3 | 211 | #define S1_BUTTON 0xFF |
Mika Karjalainen |
4:c449bead5cf3 | 212 | |
Mika Karjalainen |
4:c449bead5cf3 | 213 | void s1_init(void); |
Mika Karjalainen |
4:c449bead5cf3 | 214 | //Initializes interrupt gpio settings in Port A.7. |
Mika Karjalainen |
4:c449bead5cf3 | 215 | void s1_init(void) |
Mika Karjalainen |
4:c449bead5cf3 | 216 | { |
Mika Karjalainen |
4:c449bead5cf3 | 217 | GPIO_PACFGH &= ~PA7_CFG; //init portA.7 as input |
Mika Karjalainen |
4:c449bead5cf3 | 218 | GPIO_PACFGH |= 0x8000; |
Mika Karjalainen |
4:c449bead5cf3 | 219 | GPIO_PAOUT |= PA7; //pull-up portA.7 |
Mika Karjalainen |
4:c449bead5cf3 | 220 | GPIO_IRQDSEL = 0x07; |
Mika Karjalainen |
4:c449bead5cf3 | 221 | GPIO_INTCFGD |= 0x140; |
Mika Karjalainen |
4:c449bead5cf3 | 222 | INT_GPIOFLAG |= INT_IRQDFLAG; |
Mika Karjalainen |
4:c449bead5cf3 | 223 | INT_CFGSET |= INT_IRQD; |
Mika Karjalainen |
4:c449bead5cf3 | 224 | } |
Mika Karjalainen |
4:c449bead5cf3 | 225 | |
Mika Karjalainen |
4:c449bead5cf3 | 226 | //GPIO IRQD Handler. |
Mika Karjalainen |
4:c449bead5cf3 | 227 | //Sends event to the tasklet_main when button S1 in Port A.7 is pushed. |
Mika Karjalainen |
4:c449bead5cf3 | 228 | |
Mika Karjalainen |
4:c449bead5cf3 | 229 | void halIrqDIsr(void) |
Mika Karjalainen |
4:c449bead5cf3 | 230 | { |
Mika Karjalainen |
4:c449bead5cf3 | 231 | INT_GPIOFLAG |= INT_IRQDFLAG; |
Mika Karjalainen |
4:c449bead5cf3 | 232 | // Example of sending event to the application. |
Mika Karjalainen |
4:c449bead5cf3 | 233 | // event.event is user defined event. |
Mika Karjalainen |
4:c449bead5cf3 | 234 | // In this application S1_BUTTON event is sent when IRQD interrupt occurs |
Mika Karjalainen |
4:c449bead5cf3 | 235 | event_t event; |
Mika Karjalainen |
4:c449bead5cf3 | 236 | event.sender = APP_SPESIFIC_EVENT; |
Mika Karjalainen |
4:c449bead5cf3 | 237 | event.receiver = TL_MAIN; |
Mika Karjalainen |
4:c449bead5cf3 | 238 | event.event = S1_BUTTON; |
Mika Karjalainen |
4:c449bead5cf3 | 239 | arm_ns_event_send(&event); |
Mika Karjalainen |
4:c449bead5cf3 | 240 | } |
Mika Karjalainen |
4:c449bead5cf3 | 241 | |
Mika Karjalainen |
4:c449bead5cf3 | 242 | |
Mika Karjalainen |
4:c449bead5cf3 | 243 | |
Mika Karjalainen |
4:c449bead5cf3 | 244 | void tasklet_main(event_t *event) |
Mika Karjalainen |
4:c449bead5cf3 | 245 | { |
Mika Karjalainen |
4:c449bead5cf3 | 246 | switch(event->sender) |
Mika Karjalainen |
4:c449bead5cf3 | 247 | { |
Mika Karjalainen |
4:c449bead5cf3 | 248 | case SYSTEM: |
Mika Karjalainen |
4:c449bead5cf3 | 249 | if (event->event == EV_INIT) |
Mika Karjalainen |
4:c449bead5cf3 | 250 | { |
Mika Karjalainen |
4:c449bead5cf3 | 251 | //Inits debugs and Port A.7 GPIO pin interrupt |
Mika Karjalainen |
4:c449bead5cf3 | 252 | debug_init(230400); |
Mika Karjalainen |
4:c449bead5cf3 | 253 | s1_init(); |
Mika Karjalainen |
4:c449bead5cf3 | 254 | } |
Mika Karjalainen |
4:c449bead5cf3 | 255 | break; |
Mika Karjalainen |
4:c449bead5cf3 | 256 | case APP_SPESIFIC_EVENT: |
Mika Karjalainen |
4:c449bead5cf3 | 257 | //Application own event type |
Mika Karjalainen |
4:c449bead5cf3 | 258 | if(event->event == S1_BUTTON) |
Mika Karjalainen |
4:c449bead5cf3 | 259 | { |
Mika Karjalainen |
4:c449bead5cf3 | 260 | debug("S1 button pressed\r\n"); |
Mika Karjalainen |
4:c449bead5cf3 | 261 | } |
Mika Karjalainen |
4:c449bead5cf3 | 262 | break; |
Mika Karjalainen |
4:c449bead5cf3 | 263 | default: |
Mika Karjalainen |
4:c449bead5cf3 | 264 | break; |
Mika Karjalainen |
4:c449bead5cf3 | 265 | } |
Mika Karjalainen |
4:c449bead5cf3 | 266 | } |
Mika Karjalainen |
4:c449bead5cf3 | 267 | |
Mika Karjalainen |
4:c449bead5cf3 | 268 | * @endcode |
Mika Karjalainen |
4:c449bead5cf3 | 269 | * |
Mika Karjalainen |
4:c449bead5cf3 | 270 | */ |
jusu_81 | 11:1b7aaf37a131 | 271 | #ifdef __cplusplus |
jusu_81 | 11:1b7aaf37a131 | 272 | extern "C" { |
jusu_81 | 11:1b7aaf37a131 | 273 | #endif |
Mika Karjalainen |
4:c449bead5cf3 | 274 | #include "pl_types.h" |
Mika Karjalainen |
4:c449bead5cf3 | 275 | |
Mika Karjalainen |
4:c449bead5cf3 | 276 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 277 | * \enum error_t |
Mika Karjalainen |
4:c449bead5cf3 | 278 | * \brief System generic error. |
Mika Karjalainen |
4:c449bead5cf3 | 279 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 280 | typedef enum error_t |
Mika Karjalainen |
4:c449bead5cf3 | 281 | { |
Mika Karjalainen |
4:c449bead5cf3 | 282 | eOK = 0, /*!< no error */ |
Mika Karjalainen |
4:c449bead5cf3 | 283 | eFALSE = 1, /*!< no result */ |
Mika Karjalainen |
4:c449bead5cf3 | 284 | eBUSY = 2, /*!< resource busy */ |
Mika Karjalainen |
4:c449bead5cf3 | 285 | eSYSTEM /*!< error code readable in sys_error */ |
Mika Karjalainen |
4:c449bead5cf3 | 286 | }error_t; |
Mika Karjalainen |
4:c449bead5cf3 | 287 | #include "tasklet_api.h" |
Mika Karjalainen |
4:c449bead5cf3 | 288 | |
Mika Karjalainen |
4:c449bead5cf3 | 289 | typedef enum arm_nwk_interface_status_type_e |
Mika Karjalainen |
4:c449bead5cf3 | 290 | { |
Mika Karjalainen |
4:c449bead5cf3 | 291 | ARM_NWK_BOOTSTRAP_READY = 0, /**< Interface configured Bootstrap is ready*/ |
Mika Karjalainen |
4:c449bead5cf3 | 292 | ARM_NWK_RPL_INSTANCE_FLOODING_READY, /**< RPL instance have been flooded */ |
Mika Karjalainen |
4:c449bead5cf3 | 293 | ARM_NWK_SET_DOWN_COMPLETE, /**< Interface DOWN command successfully */ |
Mika Karjalainen |
4:c449bead5cf3 | 294 | ARM_NWK_NWK_SCAN_FAIL, /**< Interface have not detect any valid network*/ |
Mika Karjalainen |
4:c449bead5cf3 | 295 | ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL, /*!*< IP address allocation fail(ND, DHCPv4 or DHCPv6 */ |
Mika Karjalainen |
4:c449bead5cf3 | 296 | ARM_NWK_DUPLICATE_ADDRESS_DETECTED, /*!*< User specific GP16 was not valid */ |
Mika Karjalainen |
4:c449bead5cf3 | 297 | ARM_NWK_AUHTENTICATION_START_FAIL, /**< No valid Authentication server detected behind access point */ |
Mika Karjalainen |
4:c449bead5cf3 | 298 | ARM_NWK_AUHTENTICATION_FAIL, /**< Network authentication fail by Handshake */ |
Mika Karjalainen |
4:c449bead5cf3 | 299 | ARM_NWK_NWK_CONNECTION_DOWN, /*!*< No connection between Access point or Default Router */ |
Mika Karjalainen |
4:c449bead5cf3 | 300 | ARM_NWK_NWK_PARENT_POLL_FAIL, /*!*< Sleepy host poll fail 3 time */ |
Mika Karjalainen |
4:c449bead5cf3 | 301 | ARM_NWK_PHY_CONNECTION_DOWN, /*!*< Interface PHY cable off or serial port interface not respond anymore */ |
Mika Karjalainen |
4:c449bead5cf3 | 302 | } arm_nwk_interface_status_type_e; |
Mika Karjalainen |
4:c449bead5cf3 | 303 | |
Mika Karjalainen |
4:c449bead5cf3 | 304 | typedef enum arm_library_event_type_e |
Mika Karjalainen |
4:c449bead5cf3 | 305 | { |
Mika Karjalainen |
4:c449bead5cf3 | 306 | ARM_LIB_TASKLET_INIT_EVENT = 0, /**< Tasklet Init come always when generate tasklet*/ |
Mika Karjalainen |
4:c449bead5cf3 | 307 | ARM_LIB_NWK_INTERFACE_EVENT = 1, /**< Interface Bootstrap or state update event */ |
Mika Karjalainen |
4:c449bead5cf3 | 308 | ARM_LIB_SYSTEM_TIMER_EVENT = 2, /*!*< System Timer event */ |
Mika Karjalainen |
4:c449bead5cf3 | 309 | } arm_library_event_type_e; |
Mika Karjalainen |
4:c449bead5cf3 | 310 | |
Mika Karjalainen |
4:c449bead5cf3 | 311 | |
Mika Karjalainen |
4:c449bead5cf3 | 312 | typedef struct arm_event_s |
Mika Karjalainen |
4:c449bead5cf3 | 313 | { |
Mika Karjalainen |
4:c449bead5cf3 | 314 | int8_t receiver; /**< Event handler Tasklet ID */ |
Mika Karjalainen |
4:c449bead5cf3 | 315 | int8_t sender; /**< Event sender Tasklet ID */ |
Mika Karjalainen |
4:c449bead5cf3 | 316 | uint8_t event_type; /**< This will be typecast arm_library_event_type_e */ |
Mika Karjalainen |
4:c449bead5cf3 | 317 | uint8_t event_id; /**< Timer ID, NWK interface ID or application specific ID */ |
Mika Karjalainen |
4:c449bead5cf3 | 318 | void *data_ptr; /**< Application could share data pointer tasklet to tasklet */ |
Mika Karjalainen |
4:c449bead5cf3 | 319 | void (*cb_fptr)(uint8_t); /**< Application could share data pointer tasklet to tasklet */ |
Mika Karjalainen |
4:c449bead5cf3 | 320 | uint32_t event_data; |
Mika Karjalainen |
4:c449bead5cf3 | 321 | } arm_event_s; |
Mika Karjalainen |
4:c449bead5cf3 | 322 | |
Mika Karjalainen |
4:c449bead5cf3 | 323 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 324 | * \brief NanoStack 2.x event dispatcher loop call. |
Mika Karjalainen |
4:c449bead5cf3 | 325 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 326 | extern NEAR_FUNC void event_dispatch(void); |
Mika Karjalainen |
4:c449bead5cf3 | 327 | |
Mika Karjalainen |
4:c449bead5cf3 | 328 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 329 | * \brief A function to allocate a sapplication tasklet. |
Mika Karjalainen |
4:c449bead5cf3 | 330 | * |
Mika Karjalainen |
4:c449bead5cf3 | 331 | * \param tasklet_func_ptr pointer to event handler |
Mika Karjalainen |
4:c449bead5cf3 | 332 | * |
Mika Karjalainen |
4:c449bead5cf3 | 333 | * \return eOK event allocated |
Mika Karjalainen |
4:c449bead5cf3 | 334 | * \return eFAIL event reserved |
Mika Karjalainen |
4:c449bead5cf3 | 335 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 336 | extern int8_t arm_ns_tasklet_create(void (*tasklet_func_ptr)(arm_event_s*)); |
Mika Karjalainen |
4:c449bead5cf3 | 337 | |
Mika Karjalainen |
4:c449bead5cf3 | 338 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 339 | * \brief A function to send an event. |
Mika Karjalainen |
4:c449bead5cf3 | 340 | * |
Mika Karjalainen |
4:c449bead5cf3 | 341 | * \param event a pointer to an event to send. |
Mika Karjalainen |
4:c449bead5cf3 | 342 | * \return eOK |
Mika Karjalainen |
4:c449bead5cf3 | 343 | * \return eFALSE invalid tasklet ID |
Mika Karjalainen |
4:c449bead5cf3 | 344 | * \return eBUSY event queue full |
Mika Karjalainen |
4:c449bead5cf3 | 345 | * |
Mika Karjalainen |
4:c449bead5cf3 | 346 | * |
Mika Karjalainen |
4:c449bead5cf3 | 347 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 348 | extern int8_t arm_ns_event_send(arm_event_s *event); |
Mika Karjalainen |
4:c449bead5cf3 | 349 | |
Mika Karjalainen |
4:c449bead5cf3 | 350 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 351 | * \brief A function to request a software timer from NanoStack. |
Mika Karjalainen |
4:c449bead5cf3 | 352 | * |
Mika Karjalainen |
4:c449bead5cf3 | 353 | * \param snmessage is a timer ID to send. |
Mika Karjalainen |
4:c449bead5cf3 | 354 | * \param time is time in milliseconds when the requested event is to trigger. |
Mika Karjalainen |
4:c449bead5cf3 | 355 | * |
Mika Karjalainen |
4:c449bead5cf3 | 356 | * \return 0 on success. |
Mika Karjalainen |
4:c449bead5cf3 | 357 | * \return -1 on failure. |
Mika Karjalainen |
4:c449bead5cf3 | 358 | * |
Mika Karjalainen |
4:c449bead5cf3 | 359 | * After allocated time period NanoStack2.0 will send event of which sender SYSTEM_TIMER (event->sender) |
Mika Karjalainen |
4:c449bead5cf3 | 360 | * and event->event is indicating allocated timer identification. |
Mika Karjalainen |
4:c449bead5cf3 | 361 | * |
Mika Karjalainen |
4:c449bead5cf3 | 362 | * */ |
Mika Karjalainen |
4:c449bead5cf3 | 363 | extern int8_t timer_sys_event(uint8_t snmessage, uint32_t time); |
Mika Karjalainen |
4:c449bead5cf3 | 364 | |
Mika Karjalainen |
4:c449bead5cf3 | 365 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 366 | * \brief A function to cancel a timer that has been requested. |
Mika Karjalainen |
4:c449bead5cf3 | 367 | * \param snmessage is a timer ID to cancel. |
Mika Karjalainen |
4:c449bead5cf3 | 368 | * \return 0 on success. |
Mika Karjalainen |
4:c449bead5cf3 | 369 | * \return -1 on failure or in case if timer is not found. |
Mika Karjalainen |
4:c449bead5cf3 | 370 | * |
Mika Karjalainen |
4:c449bead5cf3 | 371 | * */ |
Mika Karjalainen |
4:c449bead5cf3 | 372 | extern int8_t timer_sys_event_cancel(uint8_t snmessage); |
Mika Karjalainen |
4:c449bead5cf3 | 373 | |
Mika Karjalainen |
4:c449bead5cf3 | 374 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 375 | * \brief A function to enter into a mode where global interrupts are disabled. |
Mika Karjalainen |
4:c449bead5cf3 | 376 | * |
Mika Karjalainen |
4:c449bead5cf3 | 377 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 378 | extern void lib_enter_critical(void); |
Mika Karjalainen |
4:c449bead5cf3 | 379 | |
Mika Karjalainen |
4:c449bead5cf3 | 380 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 381 | * \brief A function to enter into a mode where global interrupts are enabled. |
Mika Karjalainen |
4:c449bead5cf3 | 382 | * |
Mika Karjalainen |
4:c449bead5cf3 | 383 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 384 | extern void lib_exit_critical(void); |
jusu_81 | 11:1b7aaf37a131 | 385 | #ifdef __cplusplus |
jusu_81 | 11:1b7aaf37a131 | 386 | } |
jusu_81 | 11:1b7aaf37a131 | 387 | #endif |
Mika Karjalainen |
4:c449bead5cf3 | 388 | #endif /*_SYSTEM_EVENT_H_*/ |