Contiki 3.x
port2.c
1 /*
2 Copyright (c) 2012, Philippe Retornaz
3 Copyright (c) 2012, EPFL STI IMT LSRO1 -- Mobots group
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 1. Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14 3. The name of the author may not be used to endorse or promote
15  products derived from this software without specific prior
16  written permission.
17 
18 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #include "cc253x.h"
32 #include "port2.h"
33 
34 struct cc253x_p2_handler *handlers = NULL;
35 
36 void
37 cc253x_p2_register_handler(struct cc253x_p2_handler *h)
38 {
39  uint8_t flags;
40 
41  if(!h) {
42  return;
43  }
44 
45  cc253x_p2_irq_disable(flags);
46 
47  h->next = handlers;
48  handlers = h;
49 
50  cc253x_p2_irq_enable(flags);
51 }
52 
53 void
54 cc253x_p2_unregister_handler(struct cc253x_p2_handler *remove)
55 {
56  uint8_t flags;
57  struct cc253x_p2_handler *h = handlers;
58 
59  // Protect against dumb users
60  if(!h || !remove) {
61  return;
62  }
63 
64  cc253x_p2_irq_disable(flags);
65 
66  if(h == remove) {
67  // First element in the list
68  handlers = h->next;
69  } else {
70  while(h->next) {
71  if(h->next == remove) {
72  h->next = h->next->next;
73  break;
74  }
75  h = h->next;
76  }
77  }
78 
79  cc253x_p2_irq_enable(flags);
80 }
#define NULL
The null pointer.
Definitions for TI/Chipcon cc2530, cc2531 and cc2533 SFR registers.