libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
sync.h
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2012 Fergus Noble <fergusnoble@gmail.com>
5 *
6 * This library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBOPENCM3_CM3_SYNC_H
21#define LIBOPENCM3_CM3_SYNC_H
22
23#include "common.h"
24
26
27void __dmb(void);
28
29/* Implements synchronisation primitives as discussed in the ARM document
30 * DHT0008A (ID081709) "ARM Synchronization Primitives" and the ARM v7-M
31 * Architecture Reference Manual.
32*/
33
34/* --- Exclusive load and store instructions ------------------------------- */
35
36/* Those are defined only on CM3 or CM4 */
37#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
38
39uint32_t __ldrex(volatile uint32_t *addr);
40uint32_t __strex(uint32_t val, volatile uint32_t *addr);
41
42/* --- Convenience functions ----------------------------------------------- */
43
44/* Here we implement some simple synchronisation primitives. */
45
46typedef uint32_t mutex_t;
47
48#define MUTEX_UNLOCKED 0
49#define MUTEX_LOCKED 1
50
51void mutex_lock(mutex_t *m);
52uint32_t mutex_trylock(mutex_t *m);
53void mutex_unlock(mutex_t *m);
54
55#endif
56
58
59#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
uint32_t mutex_trylock(mutex_t *m)
Definition: sync.c:52
void mutex_lock(mutex_t *m)
Definition: sync.c:46
uint32_t __strex(uint32_t val, volatile uint32_t *addr)
Definition: sync.c:38
uint32_t __ldrex(volatile uint32_t *addr)
Definition: sync.c:31
uint32_t mutex_t
Definition: sync.h:46
void __dmb(void)
Definition: sync.c:23
void mutex_unlock(mutex_t *m)
Definition: sync.c:70