NanoStack lib for Cortex-M4

Dependents:   mbedEndpointNetwork mbedEndpointNetworkMJK

Fork of Nanostack_lib by Sensinode

Committer:
sscaglia
Date:
Tue Jul 15 02:52:09 2014 +0000
Revision:
14:b486fa9e70a7
Parent:
12:acef6f596835
Initial version

Who changed what in which revision?

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