Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
critical.h
1
/*
2
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
*
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. Neither the name of the copyright holder nor the names of its
15
* contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29
* OF THE POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*---------------------------------------------------------------------------*/
32
/**
33
* \addtogroup sys
34
* @{
35
*
36
* \defgroup critical Critical sections
37
* @{
38
*
39
* Platform-independent functions for critical section entry and exit
40
*/
41
/*---------------------------------------------------------------------------*/
42
#ifndef CRITICAL_H_
43
#define CRITICAL_H_
44
/*---------------------------------------------------------------------------*/
45
#include "contiki.h"
46
#include "sys/memory-barrier.h"
47
#include "sys/int-master.h"
48
49
#include <stdint.h>
50
/*---------------------------------------------------------------------------*/
51
/**
52
* \brief Enter a critical section
53
* \return The status of the master interrupt before entering the critical
54
*
55
* This function will return the status of the master interrupt as it was
56
* before entering the critical section.
57
*
58
* The semantics of the return value are entirely platform-specific. The
59
* calling code should not try to determine whether the master interrupt was
60
* previously enabled/disabled by interpreting the return value of this
61
* function. The return value should only be used as an argument to
62
* critical_exit().
63
*/
64
static
inline
int_master_status_t
65
critical_enter
()
66
{
67
int_master_status_t
status =
int_master_read_and_disable
();
68
memory_barrier
();
69
return
status;
70
}
71
/*---------------------------------------------------------------------------*/
72
/**
73
* \brief Exit a critical section and restore the master interrupt
74
* \param status The new status of the master interrupt
75
*
76
* The semantics of \e status are platform-dependent. Normally, the argument
77
* provided to this function will be a value previously retrieved through a
78
* call to critical_enter().
79
*/
80
static
inline
void
81
critical_exit
(
int_master_status_t
status)
82
{
83
memory_barrier
();
84
int_master_status_set
(status);
85
}
86
/*---------------------------------------------------------------------------*/
87
#endif
/* CRITICAL_H_ */
88
/*---------------------------------------------------------------------------*/
89
/**
90
* @}
91
* @}
92
*/
int_master_status_set
void int_master_status_set(int_master_status_t status)
Set the status of the master interrupt.
Definition
int-master.c:68
int_master_read_and_disable
int_master_status_t int_master_read_and_disable(void)
Disable the master interrupt.
Definition
int-master.c:58
critical_exit
static void critical_exit(int_master_status_t status)
Exit a critical section and restore the master interrupt.
Definition
critical.h:81
critical_enter
static int_master_status_t critical_enter()
Enter a critical section.
Definition
critical.h:65
int_master_status_t
uint32_t int_master_status_t
Master interrupt state representation data type.
Definition
int-master.h:62
memory_barrier
#define memory_barrier()
Insert a memory barrier.
Definition
memory-barrier.h:59
os
sys
critical.h
Generated on
for Contiki-NG by
1.17.0