init commit

This commit is contained in:
2026-03-30 13:45:38 +03:00
commit 0b982e5d4d
570 changed files with 280071 additions and 0 deletions

View File

@@ -0,0 +1,306 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Release Notes for STM32 timer server</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<link rel="stylesheet" href="_htmresc/mini-st.css" />
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
<link rel="icon" type="image/x-icon" href="_htmresc/favicon.png" />
</head>
<body>
<div class="row">
<div class="col-sm-12 col-lg-4">
<center>
<h1 id="release-notes-for-stm32-timer-server">Release Notes for <mark>STM32 timer server</mark></h1>
<p>Copyright © 2019 STMicroelectronics<br />
</p>
<a href="https://www.st.com" class="logo"><img src="_htmresc/st_logo_2020.png" alt="ST logo" /></a>
</center>
<h1 id="purpose">Purpose</h1>
<p>The source code delivered is an utility to help managing timer services within an embedded application.</p>
</div>
<section id="update-history" class="col-sm-12 col-lg-8">
<h1>Update History</h1>
<div class="collapse">
<input type="checkbox" id="collapse-section9" checked aria-hidden="true"> <label for="collapse-section9" aria-hidden="true">V1.3.0 / 27-October-2022</label>
<div>
<h2 id="main-changes">Main Changes</h2>
<h2 id="contents">Contents</h2>
<p><strong>Fixed bugs list</strong></p>
<table>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Ticket 137606 - [CodeSpell] Mistake in timer module</td>
</tr>
<tr class="even">
<td>Ticket 127700 - add UTIL_TIMER_GetTimerList function</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations">known limitations</h2>
<h2 id="development-toolchains-and-compilers">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards">Supported Devices and boards</h2>
<h2 id="backward-compatibility">backward compatibility</h2>
<h2 id="dependencies">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section9" aria-hidden="true"> <label for="collapse-section9" aria-hidden="true">V1.2.1 / 17-June-2022</label>
<div>
<h2 id="main-changes-1">Main Changes</h2>
<h2 id="contents-1">Contents</h2>
<p><strong>Fixed bugs list</strong></p>
<table>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Release note format update</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-1">known limitations</h2>
<h2 id="development-toolchains-and-compilers-1">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-1">Supported Devices and boards</h2>
<h2 id="backward-compatibility-1">backward compatibility</h2>
<h2 id="dependencies-1">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section8" aria-hidden="true"> <label for="collapse-section8" aria-hidden="true">V1.2.0 / 09-November-2021</label>
<div>
<h2 id="main-changes-2">Main Changes</h2>
<h2 id="contents-2">Contents</h2>
<p><strong>Fixed bugs list</strong></p>
<table>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Ticket 115234 - [Licensing] Update the way to declare licenses in Cube and X-CUBE components</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-2">known limitations</h2>
<h2 id="development-toolchains-and-compilers-2">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-2">Supported Devices and boards</h2>
<h2 id="backward-compatibility-2">backward compatibility</h2>
<h2 id="dependencies-2">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section7" aria-hidden="true"> <label for="collapse-section7" aria-hidden="true">V1.1.2 / 10-September-2020</label>
<div>
<h2 id="main-changes-3">Main Changes</h2>
<h3 id="release-v1.1.2">release V1.1.2</h3>
<h2 id="contents-3">Contents</h2>
<p><strong>Fixed bugs list</strong></p>
<table>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Ticket 86948 - CodeSpell : Correct some english words typo</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-3">known limitations</h2>
<h2 id="development-toolchains-and-compilers-3">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-3">Supported Devices and boards</h2>
<h2 id="backward-compatibility-3">backward compatibility</h2>
<h2 id="dependencies-3">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section6" aria-hidden="true"> <label for="collapse-section6" aria-hidden="true">V1.1.1 / 3-September-2020</label>
<div>
<h2 id="main-changes-4">Main Changes</h2>
<h3 id="release-v1.1.1">release V1.1.1</h3>
<h2 id="contents-4">Contents</h2>
<p><strong>Fixed bugs list</strong></p>
<table>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Ticket 89624 - Utilities Releases Notes Improvements - Link on openorg BSD-3-Clause</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-4">known limitations</h2>
<h2 id="development-toolchains-and-compilers-4">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-4">Supported Devices and boards</h2>
<h2 id="backward-compatibility-4">backward compatibility</h2>
<h2 id="dependencies-4">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section5" aria-hidden="true"> <label for="collapse-section5" aria-hidden="true">V1.1.0 / 29-June-2020</label>
<div>
<h2 id="main-changes-5">Main Changes</h2>
<h3 id="release-v1.1.0">release V1.1.0</h3>
<h2 id="contents-5">Contents</h2>
<p><strong>Fixed bugs list</strong></p>
<table>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Ticket 86948 - CodeSpell : Correct some english words typo</td>
</tr>
<tr class="even">
<td>Ticket 75887 - [UTILITIES] add TIMER_START_XXXXXX function with parameter Period + Type</td>
</tr>
<tr class="odd">
<td>MISRA update</td>
</tr>
<tr class="even">
<td>Doxygen tag update</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-5">known limitations</h2>
<h2 id="development-toolchains-and-compilers-5">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-5">Supported Devices and boards</h2>
<h2 id="backward-compatibility-5">backward compatibility</h2>
<h2 id="dependencies-5">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section4" aria-hidden="true"> <label for="collapse-section4" aria-hidden="true">V1.0.1 / 12-December-2019</label>
<div>
<h2 id="main-changes-6">Main Changes</h2>
<h3 id="release-v1.0.1">release V1.0.1</h3>
<h2 id="contents-6">Contents</h2>
<p><strong>Fixed bugs list</strong></p>
<table>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Release note correction</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-6">known limitations</h2>
<h2 id="development-toolchains-and-compilers-6">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-6">Supported Devices and boards</h2>
<h2 id="backward-compatibility-6">backward compatibility</h2>
<h2 id="dependencies-6">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section3" aria-hidden="true"> <label for="collapse-section3" aria-hidden="true">V1.0.0 / 08-October-2019</label>
<div>
<h2 id="main-changes-7">Main Changes</h2>
<h3 id="release-v1.0.0">release V1.0.0</h3>
<h2 id="contents-7">Contents</h2>
<p><strong>Fixed bugs list</strong></p>
<table>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>[Ticket 73263] insert default definition for the critical section</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-7">known limitations</h2>
<h2 id="development-toolchains-and-compilers-7">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-7">Supported Devices and boards</h2>
<h2 id="backward-compatibility-7">backward compatibility</h2>
<h2 id="dependencies-7">Dependencies</h2>
</div>
</div>
</section>
</div>
<footer class="sticky">
<div class="columns">
<div class="column" style="width:95%;">
</div><div class="column" style="width:5%;">
<p><abbr title="Based on template cx566953 version 2.1">Info</abbr></p>
</div>
</div>
</footer>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -0,0 +1,547 @@
/*!
* \file timer.c
*
* \brief Timer objects and scheduling management implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
* ______ _
* / _____) _ | |
* ( (____ _____ ____ _| |_ _____ ____| |__
* \____ \| ___ | (_ _) ___ |/ ___) _ \
* _____) ) ____| | | || |_| ____( (___| | | |
* (______/|_____)_|_|_| \__)_____)\____)_| |_|
* (C)2013-2017 Semtech
*
* \endcode
*
* \author Miguel Luis ( Semtech )
*
* \author Gregory Cristian ( Semtech )
*/
/******************************************************************************
* @file stm32_timer.c
* @author MCD Application Team
* @brief Time server utility
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32_timer.h"
/** @addtogroup TIMER_SERVER
* @{
*/
/* Private macro -----------------------------------------------------------*/
/**
* @defgroup TIMER_SERVER_private_macro TIMER_SERVER private macros
* @{
*/
/**
* @brief macro definition to initialize a critical section.
*
*/
#ifndef UTIL_TIMER_INIT_CRITICAL_SECTION
#define UTIL_TIMER_INIT_CRITICAL_SECTION( )
#endif
/**
* @brief macro definition to enter a critical section.
*
*/
#ifndef UTIL_TIMER_ENTER_CRITICAL_SECTION
#define UTIL_TIMER_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION( )
#endif
/**
* @brief macro definition to exit a critical section.
*
*/
#ifndef UTIL_TIMER_EXIT_CRITICAL_SECTION
#define UTIL_TIMER_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION( )
#endif
/**
* @}
*/
/* Private variables -----------------------------------------------------------*/
/**
* @defgroup TIMER_SERVER_private_varaible TIMER_SERVER private variable
* @{
*/
/**
* @brief Timers list head pointer
*
*/
static UTIL_TIMER_Object_t *TimerListHead = NULL;
/**
* @}
*/
/**
* @defgroup TIMER_SERVER_private_function TIMER_SERVER private function
* @{
*/
void TimerInsertNewHeadTimer( UTIL_TIMER_Object_t *TimerObject );
void TimerInsertTimer( UTIL_TIMER_Object_t *TimerObject );
void TimerSetTimeout( UTIL_TIMER_Object_t *TimerObject );
bool TimerExists( UTIL_TIMER_Object_t *TimerObject );
/**
* @}
*/
/* Functions Definition ------------------------------------------------------*/
/**
* @addtogroup TIMER_SERVER_exported_function
* @{
*/
UTIL_TIMER_Status_t UTIL_TIMER_Init(void)
{
UTIL_TIMER_INIT_CRITICAL_SECTION();
TimerListHead = NULL;
return UTIL_TimerDriver.InitTimer();
}
UTIL_TIMER_Status_t UTIL_TIMER_DeInit(void)
{
return UTIL_TimerDriver.DeInitTimer();
}
UTIL_TIMER_Status_t UTIL_TIMER_Create( UTIL_TIMER_Object_t *TimerObject, uint32_t PeriodValue, UTIL_TIMER_Mode_t Mode, void ( *Callback )( void *), void *Argument)
{
if((TimerObject != NULL) && (Callback != NULL))
{
TimerObject->Timestamp = 0U;
TimerObject->ReloadValue = UTIL_TimerDriver.ms2Tick(PeriodValue);
TimerObject->IsPending = 0U;
TimerObject->IsRunning = 0U;
TimerObject->IsReloadStopped = 0U;
TimerObject->Callback = Callback;
TimerObject->argument = Argument;
TimerObject->Mode = Mode;
TimerObject->Next = NULL;
return UTIL_TIMER_OK;
}
else
{
return UTIL_TIMER_INVALID_PARAM;
}
}
UTIL_TIMER_Status_t UTIL_TIMER_Start( UTIL_TIMER_Object_t *TimerObject)
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
uint32_t elapsedTime;
uint32_t minValue;
uint32_t ticks;
if(( TimerObject != NULL ) && ( TimerExists( TimerObject ) == false ) && (TimerObject->IsRunning == 0U))
{
UTIL_TIMER_ENTER_CRITICAL_SECTION();
ticks = TimerObject->ReloadValue;
minValue = UTIL_TimerDriver.GetMinimumTimeout( );
if( ticks < minValue )
{
ticks = minValue;
}
TimerObject->Timestamp = ticks;
TimerObject->IsPending = 0U;
TimerObject->IsRunning = 1U;
TimerObject->IsReloadStopped = 0U;
if( TimerListHead == NULL )
{
UTIL_TimerDriver.SetTimerContext();
TimerInsertNewHeadTimer( TimerObject ); /* insert a timeout at now+obj->Timestamp */
}
else
{
elapsedTime = UTIL_TimerDriver.GetTimerElapsedTime( );
TimerObject->Timestamp += elapsedTime;
if( TimerObject->Timestamp < TimerListHead->Timestamp )
{
TimerInsertNewHeadTimer( TimerObject);
}
else
{
TimerInsertTimer( TimerObject);
}
}
UTIL_TIMER_EXIT_CRITICAL_SECTION();
}
else
{
ret = UTIL_TIMER_INVALID_PARAM;
}
return ret;
}
UTIL_TIMER_Status_t UTIL_TIMER_StartWithPeriod( UTIL_TIMER_Object_t *TimerObject, uint32_t PeriodValue)
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
if(NULL == TimerObject)
{
ret = UTIL_TIMER_INVALID_PARAM;
}
else
{
TimerObject->ReloadValue = UTIL_TimerDriver.ms2Tick(PeriodValue);
if(TimerExists(TimerObject))
{
(void)UTIL_TIMER_Stop(TimerObject);
}
ret = UTIL_TIMER_Start(TimerObject);
}
return ret;
}
UTIL_TIMER_Status_t UTIL_TIMER_Stop( UTIL_TIMER_Object_t *TimerObject )
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
if (NULL != TimerObject)
{
UTIL_TIMER_ENTER_CRITICAL_SECTION();
UTIL_TIMER_Object_t* prev = TimerListHead;
UTIL_TIMER_Object_t* cur = TimerListHead;
TimerObject->IsReloadStopped = 1U;
/* List is empty or the Obj to stop does not exist */
if(NULL != TimerListHead)
{
TimerObject->IsRunning = 0U;
if( TimerListHead == TimerObject ) /* Stop the Head */
{
TimerListHead->IsPending = 0;
if( TimerListHead->Next != NULL )
{
TimerListHead = TimerListHead->Next;
TimerSetTimeout( TimerListHead );
}
else
{
UTIL_TimerDriver.StopTimerEvt( );
TimerListHead = NULL;
}
}
else /* Stop an object within the list */
{
while( cur != NULL )
{
if( cur == TimerObject )
{
if( cur->Next != NULL )
{
cur = cur->Next;
prev->Next = cur;
}
else
{
cur = NULL;
prev->Next = cur;
}
break;
}
else
{
prev = cur;
cur = cur->Next;
}
}
}
ret = UTIL_TIMER_OK;
}
UTIL_TIMER_EXIT_CRITICAL_SECTION();
}
else
{
ret = UTIL_TIMER_INVALID_PARAM;
}
return ret;
}
UTIL_TIMER_Status_t UTIL_TIMER_SetPeriod(UTIL_TIMER_Object_t *TimerObject, uint32_t NewPeriodValue)
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
if(NULL == TimerObject)
{
ret = UTIL_TIMER_INVALID_PARAM;
}
else
{
TimerObject->ReloadValue = UTIL_TimerDriver.ms2Tick(NewPeriodValue);
if(TimerExists(TimerObject))
{
(void)UTIL_TIMER_Stop(TimerObject);
ret = UTIL_TIMER_Start(TimerObject);
}
}
return ret;
}
UTIL_TIMER_Status_t UTIL_TIMER_SetReloadMode(UTIL_TIMER_Object_t *TimerObject, UTIL_TIMER_Mode_t ReloadMode)
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
if(NULL == TimerObject)
{
ret = UTIL_TIMER_INVALID_PARAM;
}
else
{
TimerObject->Mode = ReloadMode;
}
return ret;
}
UTIL_TIMER_Status_t UTIL_TIMER_GetRemainingTime(UTIL_TIMER_Object_t *TimerObject, uint32_t *ElapsedTime)
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
if(TimerExists(TimerObject))
{
uint32_t time = UTIL_TimerDriver.GetTimerElapsedTime();
if (TimerObject->Timestamp < time )
{
*ElapsedTime = 0;
}
else
{
*ElapsedTime = TimerObject->Timestamp - time;
}
}
else
{
ret = UTIL_TIMER_INVALID_PARAM;
}
return ret;
}
uint32_t UTIL_TIMER_IsRunning( UTIL_TIMER_Object_t *TimerObject )
{
if( TimerObject != NULL )
{
return TimerObject->IsRunning;
}
else
{
return 0;
}
}
uint32_t UTIL_TIMER_GetFirstRemainingTime(void)
{
uint32_t NextTimer = 0xFFFFFFFFU;
if(TimerListHead != NULL)
{
(void)UTIL_TIMER_GetRemainingTime(TimerListHead, &NextTimer);
}
return NextTimer;
}
void UTIL_TIMER_IRQ_Handler( void )
{
UTIL_TIMER_Object_t* cur;
uint32_t old, now, DeltaContext;
UTIL_TIMER_ENTER_CRITICAL_SECTION();
old = UTIL_TimerDriver.GetTimerContext( );
now = UTIL_TimerDriver.SetTimerContext( );
DeltaContext = now - old; /*intentional wrap around */
/* update timeStamp based upon new Time Reference*/
/* because delta context should never exceed 2^32*/
if ( TimerListHead != NULL )
{
cur = TimerListHead;
do {
if (cur->Timestamp > DeltaContext)
{
cur->Timestamp -= DeltaContext;
}
else
{
cur->Timestamp = 0;
}
cur = cur->Next;
} while(cur != NULL);
}
/* Execute expired timer and update the list */
while ((TimerListHead != NULL) && ((TimerListHead->Timestamp == 0U) || (TimerListHead->Timestamp < UTIL_TimerDriver.GetTimerElapsedTime( ))))
{
cur = TimerListHead;
TimerListHead = TimerListHead->Next;
cur->IsPending = 0;
cur->IsRunning = 0;
cur->Callback(cur->argument);
if(( cur->Mode == UTIL_TIMER_PERIODIC) && (cur->IsReloadStopped == 0U))
{
(void)UTIL_TIMER_Start(cur);
}
}
/* start the next TimerListHead if it exists and it is not pending*/
if(( TimerListHead != NULL ) && (TimerListHead->IsPending == 0U))
{
TimerSetTimeout( TimerListHead );
}
UTIL_TIMER_EXIT_CRITICAL_SECTION();
}
UTIL_TIMER_Time_t UTIL_TIMER_GetCurrentTime(void)
{
uint32_t now = UTIL_TimerDriver.GetTimerValue( );
return UTIL_TimerDriver.Tick2ms(now);
}
UTIL_TIMER_Time_t UTIL_TIMER_GetElapsedTime(UTIL_TIMER_Time_t past )
{
uint32_t nowInTicks = UTIL_TimerDriver.GetTimerValue( );
uint32_t pastInTicks = UTIL_TimerDriver.ms2Tick( past );
/* intentional wrap around. Works Ok if tick duation below 1ms */
return UTIL_TimerDriver.Tick2ms( nowInTicks- pastInTicks );
}
UTIL_TIMER_Object_t *UTIL_TIMER_GetTimerList(void)
{
return TimerListHead;
}
/**
* @}
*/
/**************************** Private functions *******************************/
/**
* @addtogroup TIMER_SERVER_private_function
*
* @{
*/
/**
* @brief Check if the Object to be added is not already in the list
*
* @param TimerObject Structure containing the timer object parameters
* @retval 1 (the object is already in the list) or 0
*/
bool TimerExists( UTIL_TIMER_Object_t *TimerObject )
{
UTIL_TIMER_Object_t* cur = TimerListHead;
while( cur != NULL )
{
if( cur == TimerObject )
{
return true;
}
cur = cur->Next;
}
return false;
}
/**
* @brief Sets a timeout with the duration "timestamp"
*
* @param TimerObject Structure containing the timer object parameters
*/
void TimerSetTimeout( UTIL_TIMER_Object_t *TimerObject )
{
uint32_t minTicks= UTIL_TimerDriver.GetMinimumTimeout( );
TimerObject->IsPending = 1;
/* In case deadline too soon */
if(TimerObject->Timestamp < (UTIL_TimerDriver.GetTimerElapsedTime( ) + minTicks) )
{
TimerObject->Timestamp = UTIL_TimerDriver.GetTimerElapsedTime( ) + minTicks;
}
UTIL_TimerDriver.StartTimerEvt( TimerObject->Timestamp );
}
/**
* @brief Adds a timer to the list.
*
* @remark The list is automatically sorted. The list head always contains the
* next timer to expire.
*
* @param TimerObject Structure containing the timer object parameters
*/
void TimerInsertTimer( UTIL_TIMER_Object_t *TimerObject)
{
UTIL_TIMER_Object_t* cur = TimerListHead;
UTIL_TIMER_Object_t* next = TimerListHead->Next;
while (cur->Next != NULL )
{
if( TimerObject->Timestamp > next->Timestamp )
{
cur = next;
next = next->Next;
}
else
{
cur->Next = TimerObject;
TimerObject->Next = next;
return;
}
}
cur->Next = TimerObject;
TimerObject->Next = NULL;
}
/**
* @brief Adds or replace the head timer of the list.
*
* @param TimerObject Structure containing the timer object parameters
*
* @remark The list is automatically sorted. The list head always contains the
* next timer to expire.
*/
void TimerInsertNewHeadTimer( UTIL_TIMER_Object_t *TimerObject )
{
UTIL_TIMER_Object_t* cur = TimerListHead;
if( cur != NULL )
{
cur->IsPending = 0;
}
TimerObject->Next = cur;
TimerListHead = TimerObject;
TimerSetTimeout( TimerListHead );
}
/**
* @}
*/
/**
* @}
*/

View File

@@ -0,0 +1,303 @@
/*!
* \file timer.h
*
* \brief Timer objects and scheduling management implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
* ______ _
* / _____) _ | |
* ( (____ _____ ____ _| |_ _____ ____| |__
* \____ \| ___ | (_ _) ___ |/ ___) _ \
* _____) ) ____| | | || |_| ____( (___| | | |
* (______/|_____)_|_|_| \__)_____)\____)_| |_|
* (C)2013-2017 Semtech
*
* \endcode
*
* \author Miguel Luis ( Semtech )
*
* \author Gregory Cristian ( Semtech )
*/
/******************************************************************************
* @file stm32_timer.h
* @author MCD Application Team
* @brief This is the header of the timer server driver
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef UTIL_TIME_SERVER_H__
#define UTIL_TIME_SERVER_H__
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup TIMER_SERVER timer server
* @{
*/
/* Includes ------------------------------------------------------------------*/
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <cmsis_compiler.h>
#include "utilities_conf.h"
/* Exported types ------------------------------------------------------------*/
/** @defgroup TIMER_SERVER_exported_TypeDef TIMER_SERVER exported Typedef
* @{
*/
/**
* @brief Timer mode
*/
typedef enum {
UTIL_TIMER_ONESHOT = 0, /*!<One-shot timer. */
UTIL_TIMER_PERIODIC = 1 /*!<Periodic timer. */
} UTIL_TIMER_Mode_t;
/**
* @brief Timer status
*/
typedef enum {
UTIL_TIMER_OK = 0, /*!<Operation terminated successfully.*/
UTIL_TIMER_INVALID_PARAM = 1, /*!<Invalid Parameter. */
UTIL_TIMER_HW_ERROR = 2, /*!<Hardware Error. */
UTIL_TIMER_UNKNOWN_ERROR = 3 /*!<Unknown Error. */
} UTIL_TIMER_Status_t;
/**
* @brief Timer object description
*/
typedef struct TimerEvent_s
{
uint32_t Timestamp; /*!<Expiring timer value in ticks from TimerContext */
uint32_t ReloadValue; /*!<Reload Value when Timer is restarted */
uint8_t IsPending; /*!<Is the timer waiting for an event */
uint8_t IsRunning; /*!<Is the timer running */
uint8_t IsReloadStopped; /*!<Is the reload stopped */
UTIL_TIMER_Mode_t Mode; /*!<Timer type : one-shot/continuous */
void ( *Callback )( void *); /*!<callback function */
void *argument; /*!<callback argument */
struct TimerEvent_s *Next; /*!<Pointer to the next Timer object. */
} UTIL_TIMER_Object_t;
/**
* @brief Timer driver definition
*/
typedef struct
{
UTIL_TIMER_Status_t (* InitTimer )( void ); /*!< Initialisation of the low layer timer */
UTIL_TIMER_Status_t (* DeInitTimer )( void ); /*!< Un-Initialisation of the low layer timer */
UTIL_TIMER_Status_t (* StartTimerEvt )( uint32_t timeout ); /*!< Start the low layer timer */
UTIL_TIMER_Status_t (* StopTimerEvt )( void); /*!< Stop the low layer timer */
uint32_t (* SetTimerContext)( void ); /*!< Set the timer context */
uint32_t (* GetTimerContext)( void ); /*!< Get the timer context */
uint32_t (* GetTimerElapsedTime)( void ); /*!< Get elapsed time */
uint32_t (* GetTimerValue)( void ); /*!< Get timer value */
uint32_t (* GetMinimumTimeout)( void ); /*!< Get Minimum timeout */
uint32_t (* ms2Tick)( uint32_t timeMicroSec ); /*!< convert ms to tick */
uint32_t (* Tick2ms)( uint32_t tick ); /*!< convert tick into ms */
} UTIL_TIMER_Driver_s;
/**
* @brief Timer value on 32 bits
*/
typedef uint32_t UTIL_TIMER_Time_t;
/**
* @}
*/
/* Exported variables ------------------------------------------------------------*/
/** @defgroup TIMER_SERVER_exported_Variable TIMER_SERVER exported Variable
* @{
*/
/**
* @brief low layer interface to handle timing execution
*
* @remark This structure is defined and initialized in the specific platform
* timer implementation
*/
extern const UTIL_TIMER_Driver_s UTIL_TimerDriver;
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/** @defgroup TIMER_SERVER_exported_function TIMER_SERVER exported function
* @{
*/
/**
* @brief Initialize the timer server
*
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_Init(void);
/**
* @brief Un-Initialize the timer server
*
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_DeInit(void);
/**
* @brief Create the timer object
*
* @remark TimerSetValue function must be called before starting the timer.
* this function initializes timestamp and reload value at 0.
*
* @param TimerObject Structure containing the timer object parameters
* @param PeriodValue Period value of the timer in ms
* @param Mode @ref UTIL_TIMER_Mode_t
* @param Callback Function callback called at the end of the timeout
* @param Argument argument for the callback function
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_Create( UTIL_TIMER_Object_t *TimerObject, uint32_t PeriodValue, UTIL_TIMER_Mode_t Mode, void ( *Callback )( void *) , void *Argument);
/**
* @brief Start and adds the timer object to the list of timer events
*
* @param TimerObject Structure containing the timer object parameters
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_Start( UTIL_TIMER_Object_t *TimerObject );
/**
* @brief Start and adds the timer object to the list of timer events
*
* @param TimerObject Structure containing the timer object parameters
* @param PeriodValue period value of the timer
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_StartWithPeriod( UTIL_TIMER_Object_t *TimerObject, uint32_t PeriodValue);
/**
* @brief Stop and removes the timer object from the list of timer events
*
* @param TimerObject Structure containing the timer object parameters
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_Stop( UTIL_TIMER_Object_t *TimerObject );
/**
* @brief update the period and start the timer
*
* @param TimerObject Structure containing the timer object parameters
* @param NewPeriodValue new period value of the timer
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_SetPeriod(UTIL_TIMER_Object_t *TimerObject, uint32_t NewPeriodValue);
/**
* @brief update the period and start the timer
*
* @param TimerObject Structure containing the timer object parameters
* @param ReloadMode new reload mode @ref UTIL_TIMER_Mode_t
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_SetReloadMode(UTIL_TIMER_Object_t *TimerObject, UTIL_TIMER_Mode_t ReloadMode);
/**
* @brief get the remaining time before timer expiration
* *
* @param TimerObject Structure containing the timer object parameters
* @param Time time before expiration in ms
* @retval Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t UTIL_TIMER_GetRemainingTime(UTIL_TIMER_Object_t *TimerObject, uint32_t *Time);
/**
* @brief return timer state
*
* @param TimerObject Structure containing the timer object parameters
* @retval boolean value is returned 0 = false and 1 = true
*/
uint32_t UTIL_TIMER_IsRunning( UTIL_TIMER_Object_t *TimerObject );
/**
* @brief return the remaining time of the first timer in the chain list
*
* @retval return the time in ms, the value 0xFFFFFFFF means no timer running
*/
uint32_t UTIL_TIMER_GetFirstRemainingTime(void);
/**
* @brief return the current time
*
* @retval time value
*/
UTIL_TIMER_Time_t UTIL_TIMER_GetCurrentTime(void);
/**
* @brief return the elapsed time
*
* @param past a value returned by the function UTIL_TIMER_GetCurrentTime
* @retval elapsed time value
*/
UTIL_TIMER_Time_t UTIL_TIMER_GetElapsedTime(UTIL_TIMER_Time_t past );
/**
* @brief return the list of the current timer
*
* @retval pointer on @ref UTIL_TIMER_Object_t
*
* @Note : the use of this function is dangerous and must be done with precaution, the risks are:
* 1 - an update of this data structure may affect the operation of timer server
* 2 - data structure is moving according the events, so read must be under critical section
*/
UTIL_TIMER_Object_t *UTIL_TIMER_GetTimerList(void);
/**
* @brief Timer IRQ event handler
*
* @note Head Timer Object is automatically removed from the List
*
* @note e.g. it is not needed to stop it
*/
void UTIL_TIMER_IRQ_Handler( void );
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* UTIL_TIME_SERVER_H__*/