1 /**
2  * \file
3  *
4  * \brief Critical sections related functionality implementation.
5  *
6  * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
7  *
8  * \asf_license_start
9  *
10  * \page License
11  *
12  * Subject to your compliance with these terms, you may use Microchip
13  * software and any derivatives exclusively with Microchip products.
14  * It is your responsibility to comply with third party license terms applicable
15  * to your use of third party software (including open source software) that
16  * may accompany Microchip software.
17  *
18  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
19  * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
20  * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
21  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
22  * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
23  * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
24  * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
25  * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
26  * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
27  * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
28  * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
29  *
30  * \asf_license_stop
31  *
32  */
33 
34 #include "hal_atomic.h"
35 
36 /**
37  * \brief Driver version
38  */
39 #define DRIVER_VERSION 0x00000001u
40 
41 /**
42  * \brief Disable interrupts, enter critical section
43  */
atomic_enter_critical(hal_atomic_t volatile * atomic)44 void atomic_enter_critical(hal_atomic_t volatile *atomic)
45 {
46 	*atomic = __get_PRIMASK();
47 	__disable_irq();
48 	__DMB();
49 }
50 
51 /**
52  * \brief Exit atomic section
53  */
atomic_leave_critical(hal_atomic_t volatile * atomic)54 void atomic_leave_critical(hal_atomic_t volatile *atomic)
55 {
56 	__DMB();
57 	__set_PRIMASK(*atomic);
58 }
59 
60 /**
61  * \brief Retrieve the current driver version
62  */
atomic_get_version(void)63 uint32_t atomic_get_version(void)
64 {
65 	return DRIVER_VERSION;
66 }
67