From 1702ce6ce430a66bb7af51644b91b7c196e719d9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 29 Jun 2022 11:03:02 +0300 Subject: =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D1=8E=20=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B9=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B9.=20=D0=9F=D1=80=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=BC=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=81=D0=B8=D0=B8=20NixieClock=5Fv2.=20=D0=A0=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82,=20=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D1=8B=20=D1=82=D0=B8=D0=BA=D0=B0=D1=8E=D1=82.=20=D0=95=D1=81?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D0=B0?= =?UTF-8?q?,=20=D1=87=D1=82=D0=BE=20=D1=81=D0=BA=D0=B0=D1=87=D0=B5=D1=82?= =?UTF-8?q?=20=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=81=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=80=D0=BD=D0=B0=D1=8F=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BA=D0=B0=20(=D0=BE=D0=BD=D0=B0=20=D0=B2=20=D0=B4=D1=80?= =?UTF-8?q?=D1=83=D0=B3=D0=BE=D0=BC=20=D0=BA=D0=B0=D0=BD=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?).=20=D0=9F=D0=BE=D1=8D=D1=82=D0=BE=D0=BC=D1=83=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=B5=20=D1=81=D0=BE=D0=B1=D0=B8=D1=80=D0=B0?= =?UTF-8?q?=D1=8E=D1=81=D1=8C=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B0=D0=BD=D1=82=D0=B8=D0=B4=D1=80=D0=B5=D0=B1=D0=B5=D0=B7?= =?UTF-8?q?=D0=B3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Libraries/TouchSense/stmCriticalSection.c | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Libraries/TouchSense/stmCriticalSection.c (limited to 'Libraries/TouchSense/stmCriticalSection.c') diff --git a/Libraries/TouchSense/stmCriticalSection.c b/Libraries/TouchSense/stmCriticalSection.c new file mode 100644 index 0000000..9b763f4 --- /dev/null +++ b/Libraries/TouchSense/stmCriticalSection.c @@ -0,0 +1,59 @@ +/******************** (C) COPYRIGHT 2014 STMicroelectronics ******************** +* File Name : stmCriticalSection.c +* Author : MCD Tools Development +* Version : V1.0 +* Date : 21/02/2013 +* Description : This file provides a mechanism for STMStudio host/target +* synchronization. Based on a critical section, using few +* target resources (in term of code and RAM), but +* potentially impacting the application runtime (possible +* waiting loop when enterring the critical section). +******************************************************************************** +* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +/* Implementation of Peterson's algorithm for mutual exclusive access to + data, between the STMStudio host and the target processor. + The use of the critical section ensures the coherence of a set of data: it is + not possible for the STMStudio host to read data while the target is in the + critical section. + The target should enter the critical section (waiting loop possible, if the + STMStudio host is being reading) before modifying data that are identified as + critical ones. Then leave the critical section in order to allow the + STMStudio host to read them. + The host also enters the critical section before each reading, and leaves it + afterwards. + Note that it is not mandatory for the target to protect all spied variables + into the critical section; and that the synchronization might generate + relatively long waiting loops on the target side. As a result the critical + section should be used only for word-variables or group of variables for + which the coherence is important. +*/ + +#include "stmCriticalSection.h" + +#define TARGET_LOCK_ID 0 // Do not modify - shared with STMStudio host software +#define HOST_LOCK_ID 1 // Do not modify - shared with STMStudio host software + +typedef struct petersons_t { + volatile unsigned char flag[2]; // Do not modify - shared with STMStudio host software + volatile unsigned char turn; // Do not modify - shared with STMStudio host software +} petersons_t; + +// stm_studio_lock symbol used by the STMStudio host software for synchronization +petersons_t stm_studio_lock = { { 0, 0 }, TARGET_LOCK_ID }; // Do not modify - shared with STMStudio host software + +void enterLock (void) { + stm_studio_lock.flag[TARGET_LOCK_ID] = 1; + stm_studio_lock.turn = HOST_LOCK_ID; + while (stm_studio_lock.flag[HOST_LOCK_ID] && (stm_studio_lock.turn == HOST_LOCK_ID)) {} +} + +void exitLock (void) { + stm_studio_lock.flag[TARGET_LOCK_ID] = 0; +} -- cgit v1.2.3