Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
libatomic.c File Reference
#include <stdint.h>

Go to the source code of this file.

Macros

#define ACQ_LOCK()
 Disables interrupts and saves the interrupt enable flag in a register.
 
#define REL_LOCK()   __asm volatile(" msr PRIMASK, %0\n " : : "r"(_pastlock));
 Restores the interrupte enable flag from a register.
 

Functions

uint8_t __atomic_fetch_add_1 (uint8_t *ptr, uint8_t val, int memorder)
 __atomic_fetch_add_1
 
uint16_t __atomic_fetch_sub_2 (uint16_t *ptr, uint16_t val, int memorder)
 __atomic_fetch_sub_2
 
uint8_t __atomic_fetch_or_1 (uint8_t *ptr, uint8_t val, int memorder)
 __atomic_fetch_or_1
 
uint32_t __atomic_fetch_or_4 (uint32_t *ptr, uint32_t val, int memorder)
 __atomic_fetch_or_4
 
uint8_t __atomic_fetch_and_1 (uint8_t *ptr, uint8_t val, int memorder)
 __atomic_fetch_and_1
 
uint32_t __atomic_fetch_and_4 (uint32_t *ptr, uint32_t val, int memorder)
 __atomic_fetch_and_4
 
uint8_t __atomic_exchange_1 (uint8_t *ptr, uint8_t val, int memorder)
 __atomic_exchange_1
 
_Bool __atomic_compare_exchange_1 (uint8_t *ptr, uint8_t *exp, uint8_t desired, _Bool weak, int success_memorder, int failure_memorder)
 __atomic_compare_exchange_1
 
_Bool __atomic_compare_exchange_4 (uint32_t *ptr, uint32_t *exp, uint32_t desired, _Bool weak, int success_memorder, int failure_memorder)
 __atomic_compare_exchange_4
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

A partial implementation of libatomic for Cortex-M0 for the necessary operations in OpenMRN.

Author
Balazs Racz
Date
30 Dec 2019

Definition in file libatomic.c.

Macro Definition Documentation

◆ ACQ_LOCK

#define ACQ_LOCK ( )
Value:
int _pastlock; \
__asm volatile(" mrs %0, PRIMASK \n cpsid i\n" : "=r"(_pastlock));

Disables interrupts and saves the interrupt enable flag in a register.

Definition at line 70 of file libatomic.c.

◆ REL_LOCK

#define REL_LOCK ( )    __asm volatile(" msr PRIMASK, %0\n " : : "r"(_pastlock));

Restores the interrupte enable flag from a register.

Definition at line 75 of file libatomic.c.

Function Documentation

◆ __atomic_compare_exchange_1()

_Bool __atomic_compare_exchange_1 ( uint8_t *  ptr,
uint8_t *  exp,
uint8_t  desired,
_Bool  weak,
int  success_memorder,
int  failure_memorder 
)

__atomic_compare_exchange_1

This function is needed for GCC-generated code.

This built-in function implements an atomic compare and exchange operation. This compares the contents of *ptr with the contents of *exp. If equal, the operation is a read-modify-write operation that writes desired into *ptr. If they are not equal, the operation is a read and the current contents of *ptr are written into *expected.

If desired is written into *ptr then true is returned.

Definition at line 180 of file libatomic.c.

◆ __atomic_compare_exchange_4()

_Bool __atomic_compare_exchange_4 ( uint32_t *  ptr,
uint32_t *  exp,
uint32_t  desired,
_Bool  weak,
int  success_memorder,
int  failure_memorder 
)

__atomic_compare_exchange_4

This function is needed for GCC-generated code.

Definition at line 199 of file libatomic.c.

◆ __atomic_exchange_1()

uint8_t __atomic_exchange_1 ( uint8_t *  ptr,
uint8_t  val,
int  memorder 
)

__atomic_exchange_1

This function is needed for GCC-generated code.

Definition at line 160 of file libatomic.c.

◆ __atomic_fetch_add_1()

uint8_t __atomic_fetch_add_1 ( uint8_t *  ptr,
uint8_t  val,
int  memorder 
)

__atomic_fetch_add_1

This function is needed for GCC-generated code.

Definition at line 88 of file libatomic.c.

◆ __atomic_fetch_and_1()

uint8_t __atomic_fetch_and_1 ( uint8_t *  ptr,
uint8_t  val,
int  memorder 
)

__atomic_fetch_and_1

This function is needed for GCC-generated code.

Definition at line 136 of file libatomic.c.

◆ __atomic_fetch_and_4()

uint32_t __atomic_fetch_and_4 ( uint32_t *  ptr,
uint32_t  val,
int  memorder 
)

__atomic_fetch_and_4

This function is needed for GCC-generated code.

Definition at line 148 of file libatomic.c.

◆ __atomic_fetch_or_1()

uint8_t __atomic_fetch_or_1 ( uint8_t *  ptr,
uint8_t  val,
int  memorder 
)

__atomic_fetch_or_1

This function is needed for GCC-generated code.

Definition at line 112 of file libatomic.c.

◆ __atomic_fetch_or_4()

uint32_t __atomic_fetch_or_4 ( uint32_t *  ptr,
uint32_t  val,
int  memorder 
)

__atomic_fetch_or_4

This function is needed for GCC-generated code.

Definition at line 124 of file libatomic.c.

◆ __atomic_fetch_sub_2()

uint16_t __atomic_fetch_sub_2 ( uint16_t *  ptr,
uint16_t  val,
int  memorder 
)

__atomic_fetch_sub_2

This function is needed for GCC-generated code.

Definition at line 100 of file libatomic.c.