Issue 2 move folders and use deep path include file names to prevent collisions (#4)

* moving folders and files and adjust server demo build

* Fix Makefile for apps/server on Linux

* fix unit test source file folders

* fix datetime convert UTC functions. Add Code::Blocks project for datetime testing

* added some ignore extensions

* disable parallel make option

* fix build for abort, dcc, and epics apps

* fix build for dcc, epics, error, and getevent apps.

* Fixed building of all apps

* fix the ipv4 to ipv6 router app build

* Change indent style from Google to Webkit

* make pretty to re-format style

* removed common Makefile since we already had one and two was too many

* remove scripts from root folder that are no longer maintained or used

* remove mercurial EOL and ignore files for git repo

* remove .vscodeconfig files from repo

* tweak clang-format style

* clang-format src and apps with tweaked style

* added clang-tidy to fix readability if braces in src

* result of make tidy for src and apps

* fix clang-tidy mangling

* Added code::blocks project for BACnet server simulation

* added code::blocks linux project for WhoIs app

* update text files for EOL

* fix EOL in some files

* fixed make win32 apps for older gcc

* Removed Borland C++ Makefile in apps. Unable to maintain support for Borland C++ compiler.

* created codeblocks project for apps/epics for Windows

* fixing ports/xplained to work with new data structure.

* fix ports/xplained example for Atmel Studio compile

* fix ports/stm32f10x example for gcc Makefile compile

* fix ports/stm32f10x example for IAR EWARM compile

* fix ports/xplained timer callback

* fix ports/bdk_atxx_mspt build with subdirs

* fix ports/bdk_atxx_mspt build with subdirs

* updated git ignore for IAR build artifacts

* updated gitignore for non-tracked files and folders

* fixed bdk-atxx4-mstp port for Rowley Crossworks project file

* fixed bdk-atxx4-mstp port for GCC AVR Makefile

* fixed atmega168 port for IAR AVR and GCC AVR Makefile

* fixed at91sam7s port for IAR ARM and GCC ARM Makefile

* removed unmaintainable DOS, RTOS32, and atmega8 ports.  Updated rx62n (untested).

* changed arm7 to uip port
This commit is contained in:
Steve Karg
2019-12-13 15:19:10 -06:00
committed by GitHub
parent 8a38dbe2cf
commit d50c190957
912 changed files with 36206 additions and 52502 deletions
+6 -6
View File
@@ -28,12 +28,12 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
#include "config.h"
#include "ai.h"
#include "handlers.h"
#include "bacnet/bacdef.h"
#include "bacnet/bacdcode.h"
#include "bacnet/bacenum.h"
#include "bacnet/config.h"
#include "bacnet/basic/object/ai.h"
#include "bacnet/basic/services.h"
#ifndef MAX_ANALOG_INPUTS
#define MAX_ANALOG_INPUTS 2
+28 -28
View File
@@ -32,19 +32,19 @@
#include "led.h"
#include "adc-hdw.h"
/* BACnet Stack includes */
#include "datalink.h"
#include "npdu.h"
#include "handlers.h"
#include "client.h"
#include "txbuf.h"
#include "dcc.h"
#include "iam.h"
#include "timer.h"
#include "tsm.h"
#include "ringbuf.h"
#include "bacnet/npdu.h"
#include "bacnet/dcc.h"
#include "bacnet/iam.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/sys/mstimer.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/sys/ringbuf.h"
/* BACnet objects */
#include "device.h"
#include "ai.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/object/ai.h"
/* me */
#include "bacnet.h"
@@ -63,16 +63,16 @@ static RING_BUFFER Receive_Queue;
/* Device ID to track changes */
static uint32_t Device_ID = 0xFFFFFFFF;
/* timer for device communications control */
static struct itimer DCC_Timer;
static struct mstimer DCC_Timer;
#define DCC_CYCLE_SECONDS 1
/* timer for COV */
static struct itimer COV_Timer;
static struct mstimer COV_Timer;
#define COV_CYCLE_SECONDS 1
/* timer for TSM */
static struct itimer TSM_Timer;
static struct mstimer TSM_Timer;
#define TSM_CYCLE_SECONDS 1
/* timer for Reinit */
static struct itimer Reinit_Timer;
static struct mstimer Reinit_Timer;
/* buffer for incoming packets */
static uint8_t PDUBuffer[MAX_MPDU];
@@ -88,14 +88,14 @@ static void reinit_task(void)
state = Device_Reinitialized_State();
if (state == BACNET_REINIT_IDLE) {
/* set timer to never expire */
timer_interval_infinity(&Reinit_Timer);
} else if (timer_interval_active(&Reinit_Timer)) {
if (timer_interval_expired(&Reinit_Timer)) {
mstimer_set(&Reinit_Timer, 0);
} else if (mstimer_interval(&Reinit_Timer) > 0) {
if (mstimer_expired(&Reinit_Timer)) {
/* reset MCU via watchdog timeout */
wdt_reset_mcu();
}
} else {
timer_interval_start_seconds(&Reinit_Timer, 3);
mstimer_set(&Reinit_Timer, 3000);
}
}
@@ -164,14 +164,14 @@ void bacnet_task(void)
Send_I_Am(&Handler_Transmit_Buffer[0]);
}
/* handle the timers */
if (timer_interval_expired(&DCC_Timer)) {
timer_interval_reset(&DCC_Timer);
if (mstimer_expired(&DCC_Timer)) {
mstimer_reset(&DCC_Timer);
dcc_timer_seconds(DCC_CYCLE_SECONDS);
led_on_interval(LED_DEBUG,500);
}
if (timer_interval_expired(&TSM_Timer)) {
timer_interval_reset(&TSM_Timer);
tsm_timer_milliseconds(timer_interval(&TSM_Timer));
if (mstimer_expired(&TSM_Timer)) {
mstimer_reset(&TSM_Timer);
tsm_timer_milliseconds(mstimer_interval(&TSM_Timer));
}
reinit_task();
bacnet_test_task();
@@ -221,11 +221,11 @@ void bacnet_init(void)
apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control);
/* start the cyclic 1 second timer for DCC */
timer_interval_start_seconds(&DCC_Timer, DCC_CYCLE_SECONDS);
mstimer_set(&DCC_Timer, DCC_CYCLE_SECONDS*1000);
/* start the cyclic 1 second timer for COV */
timer_interval_start_seconds(&COV_Timer, COV_CYCLE_SECONDS);
mstimer_set(&COV_Timer, COV_CYCLE_SECONDS*1000);
/* start the cyclic 1 second timer for TSM */
timer_interval_start_seconds(&TSM_Timer, TSM_CYCLE_SECONDS);
mstimer_set(&TSM_Timer, TSM_CYCLE_SECONDS*1000);
for (i = 0; i < MAX_ANALOG_INPUTS; i++) {
Analog_Input_Units_Set(
Analog_Input_Index_To_Instance(i),
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -26,11 +26,11 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacstr.h"
#include "bacnet/bacdef.h"
#include "bacnet/bacdcode.h"
#include "bacnet/bacstr.h"
#include "nvmdata.h"
#include "device.h"
#include "bacnet/basic/object/device.h"
#include "bname.h"
/*************************************************************************
+1 -1
View File
@@ -25,7 +25,7 @@
#define BACNET_NAME_H
#include <stdint.h>
#include "bacstr.h"
#include "bacnet/bacstr.h"
#ifdef __cplusplus
extern "C" {
+11 -11
View File
@@ -26,23 +26,23 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacstr.h"
#include "bacenum.h"
#include "apdu.h"
#include "dcc.h"
#include "datalink.h"
#include "bacnet/bacdef.h"
#include "bacnet/bacdcode.h"
#include "bacnet/bacstr.h"
#include "bacnet/bacenum.h"
#include "bacnet/apdu.h"
#include "bacnet/dcc.h"
#include "bacnet/datalink/datalink.h"
#include "rs485.h"
#include "version.h"
#include "bacnet/version.h"
#include "nvmdata.h"
#include "handlers.h"
#include "bacnet/basic/services.h"
#include "bname.h"
#include "stack.h"
#include "nvmdata.h"
/* objects */
#include "device.h"
#include "ai.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/object/ai.h"
/* forward prototype */
int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA * rpdata);
+10 -10
View File
@@ -36,17 +36,17 @@
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "bacdef.h"
#include "dlmstp.h"
#include "mstpdef.h"
#include "bacnet/bacdef.h"
#include "bacnet/datalink/dlmstp.h"
#include "bacnet/datalink/mstpdef.h"
#include "rs485.h"
#include "crc.h"
#include "npdu.h"
#include "bits.h"
#include "bytes.h"
#include "bacaddr.h"
#include "ringbuf.h"
#include "timer.h"
#include "bacnet/datalink/crc.h"
#include "bacnet/npdu.h"
#include "bacnet/bits.h"
#include "bacnet/bytes.h"
#include "bacnet/bacaddr.h"
#include "bacnet/basic/sys/ringbuf.h"
#include "bacnet/basic/sys/mstimer.h"
/* This file has been customized for use with small microprocessors */
/* Assumptions:
+1 -1
View File
@@ -24,7 +24,7 @@
#include <stdint.h>
#include "board.h"
#include "ioport.h"
#include "timer.h"
#include "bacnet/basic/sys/mstimer.h"
#include "led.h"
#ifdef CONF_BOARD_ENABLE_RS485_XPLAINED
+6 -4
View File
@@ -5,13 +5,15 @@
*
*/
#include <asf.h>
#include "timer.h"
#include "bacnet/basic/sys/mstimer.h"
#include "rs485.h"
#include "led.h"
#include "adc-hdw.h"
#include "dlmstp.h"
#include "bacnet/datalink/dlmstp.h"
#include "bacnet.h"
static struct mstimer_callback_data_t BACnet_Callback;
/**
* \brief Main function.
*
@@ -23,7 +25,7 @@ int main(void)
sysclk_init();
board_init();
pmic_init();
timer_init();
mstimer_init();
rs485_init();
led_init();
adc_init();
@@ -41,7 +43,7 @@ int main(void)
rs485_baud_rate_set(38400);
bacnet_init();
/* run forever - timed tasks */
timer_callback(bacnet_task_timed, 5);
mstimer_callback(&BACnet_Callback, bacnet_task_timed, 5);
for (;;) {
bacnet_task();
led_task();
@@ -33,52 +33,34 @@
#include <stdbool.h>
#include <stddef.h>
#include "tc.h"
#include "timer.h"
#include "bacnet/basic/sys/mstimer.h"
/* define which timer counter we are using */
#define MY_TIMER TCE0
/* number of callbacks supported */
#ifndef TIMER_CALLBACK_MAX
#define TIMER_CALLBACK_MAX 8
#endif
/* counter for the base timer */
static volatile uint32_t Millisecond_Counter;
/* callback data structure */
struct timer_data_t {
volatile uint32_t interval;
volatile uint32_t milliseconds;
timer_callback_function callback;
};
static volatile struct timer_data_t Callback_Data[TIMER_CALLBACK_MAX];
/* callback data head of list */
static volatile struct mstimer_callback_data_t *Callback_Head;
/**
* Handles the interrupt from the timer
*/
static void my_callback(void)
{
uint32_t now, t, interval, i;
struct mstimer_callback_data_t *cb;
Millisecond_Counter++;
now = Millisecond_Counter;
for (i = 0; i < TIMER_CALLBACK_MAX; i++) {
/* check for callback */
if (Callback_Data[i].callback) {
t = Callback_Data[i].milliseconds;
if (now >= t) {
Callback_Data[i].callback();
interval = Callback_Data[i].interval;
if (interval) {
Callback_Data[i].milliseconds = now + interval;
} else {
/* disable any one-shot timers */
Callback_Data[i].callback = NULL;
}
}
cb = (struct mstimer_callback_data_t *)Callback_Head;
while (cb) {
if (mstimer_expired(&cb->timer)) {
cb->callback();
if (mstimer_interval(&cb->timer) > 0) {
mstimer_reset(&cb->timer);
}
}
}
cb = cb->next;
}
}
/**
@@ -86,7 +68,7 @@ static void my_callback(void)
*
* @return the current milliseconds count
*/
uint32_t timer_milliseconds(void)
unsigned long mstimer_now(void)
{
uint32_t timer_value; /* return value */
@@ -100,71 +82,44 @@ uint32_t timer_milliseconds(void)
/**
* Configures and enables a repeating callback function
*
* @param new_cb - pointer to #mstimer_callback_data_t
* @param callback - pointer to a #timer_callback_function function
* @param milliseconds - how often to call the function
*
* @return true if successfully added and enabled
*/
bool timer_callback(
timer_callback_function callback,
uint32_t milliseconds)
void mstimer_callback(
struct mstimer_callback_data_t *new_cb,
mstimer_callback_function callback,
unsigned long milliseconds)
{
bool status = false;
uint32_t now, i;
struct mstimer_callback_data_t *cb;
tc_set_overflow_interrupt_level(&MY_TIMER, TC_INT_LVL_OFF);
now = Millisecond_Counter;
for (i = 0; i < TIMER_CALLBACK_MAX; i++) {
if (Callback_Data[i].callback == NULL) {
Callback_Data[i].interval = milliseconds;
/* set the first expiration time */
Callback_Data[i].milliseconds = now + milliseconds;
Callback_Data[i].callback = callback;
status = true;
break;
if (new_cb) {
new_cb->callback = callback;
mstimer_set(&new_cb->timer, milliseconds);
}
if (Callback_Head) {
cb = (struct mstimer_callback_data_t *)Callback_Head;
while (cb) {
if (!cb->next) {
cb->next = new_cb;
break;
} else {
cb = cb->next;
}
}
}
} else {
Callback_Head = new_cb;
}
tc_set_overflow_interrupt_level(&MY_TIMER, TC_INT_LVL_LO);
return status;
}
/**
* Configures and enables a one-shot callback function
*
* @param callback - pointer to a #timer_callback_function function
* @param milliseconds - how long to wait before calling the function
*
* @return true if successfully added and enabled
*/
bool timer_callback_oneshot(
timer_callback_function callback,
uint32_t milliseconds)
{
bool status = false;
uint32_t now, i;
tc_set_overflow_interrupt_level(&MY_TIMER, TC_INT_LVL_OFF);
now = Millisecond_Counter;
for (i = 0; i < TIMER_CALLBACK_MAX; i++) {
if (Callback_Data[i].callback == NULL) {
/* set the first expiration time */
Callback_Data[i].milliseconds = now + milliseconds;
Callback_Data[i].interval = 0;
Callback_Data[i].callback = callback;
status = true;
break;
}
}
tc_set_overflow_interrupt_level(&MY_TIMER, TC_INT_LVL_LO);
return status;
}
/**
* Timer setup for 1 millisecond timer
*/
void timer_init(void)
void mstimer_init(void)
{
unsigned long period;
+2 -2
View File
@@ -8,8 +8,8 @@
#include <stdint.h>
#include <stdbool.h>
#include "nvmdata.h"
#include "dlmstp.h"
#include "device.h"
#include "bacnet/datalink/dlmstp.h"
#include "bacnet/basic/object/device.h"
/**
* Initializes the non-volatile memory module
+10 -10
View File
@@ -33,10 +33,10 @@
#include "usart.h"
#include "ioport.h"
#include "sysclk.h"
#include "fifo.h"
#include "timer.h"
#include "bacnet/basic/sys/fifo.h"
#include "bacnet/basic/sys/mstimer.h"
#include "led.h"
#include "mstpdef.h"
#include "bacnet/datalink/mstpdef.h"
/* me! */
#include "rs485.h"
@@ -69,7 +69,7 @@ static FIFO_BUFFER Transmit_Queue;
/* baud rate of the UART interface */
static uint32_t Baud_Rate;
/* timer for measuring line silence */
static struct etimer Silence_Timer;
static struct mstimer Silence_Timer;
/* flag to track RTS status */
static volatile bool RTS_Status;
@@ -78,7 +78,7 @@ static volatile bool RTS_Status;
*/
void rs485_silence_reset(void)
{
timer_elapsed_start(&Silence_Timer);
mstimer_set(&Silence_Timer, 0);
}
/**
@@ -90,7 +90,7 @@ void rs485_silence_reset(void)
*/
bool rs485_silence_elapsed(uint32_t interval)
{
return timer_elapsed_milliseconds(&Silence_Timer, interval);
return (mstimer_remaining(&Silence_Timer) > interval);
}
/**
@@ -154,7 +154,7 @@ static uint16_t rs485_turnaround_time(void)
*/
bool rs485_turnaround_elapsed(void)
{
return timer_elapsed_milliseconds(&Silence_Timer, rs485_turnaround_time());
return (mstimer_remaining(&Silence_Timer) > rs485_turnaround_time());
}
/**
@@ -222,7 +222,7 @@ bool rs485_bytes_send(uint8_t * buffer,
status = FIFO_Add(&Transmit_Queue, buffer, nbytes);
if (start_required && status) {
rs485_rts_enable(true);
timer_elapsed_start(&Silence_Timer);
rs485_silence_reset();
ch = FIFO_Get(&Transmit_Queue);
usart_clear_tx_complete(&RS485_USART);
usart_set_tx_interrupt_level(&RS485_USART, USART_INT_LVL_LO);
@@ -322,12 +322,12 @@ void rs485_init(void)
FIFO_Init(&Transmit_Queue, &Transmit_Queue_Data[0],
(unsigned) sizeof(Transmit_Queue_Data));
/* initialize the silence timer */
timer_elapsed_start(&Silence_Timer);
rs485_silence_reset();
/* configure the TX pin */
ioport_configure_pin(RS485_TXD,
IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
/* configure the RX pin */
ioport_configure_pin(RS485_RXD,
ioport_configure_pin(RS485_RXD,
IOPORT_DIR_INPUT);
/* configure the RTS pins */
ioport_configure_pin(RS485_RE,
-338
View File
@@ -1,338 +0,0 @@
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "timer.h"
/* interval and elapsed millisecond timer */
/* interval not to exceed 49.7 days */
/* minimum interval of 1ms may be 0 to 1ms */
/*************************************************************************
* Description: Start a timer from now.
* Returns: elapsed milliseconds since last set
* Notes: none
**************************************************************************/
uint32_t timer_interval_start(struct itimer *t, uint32_t interval)
{
uint32_t now = 0;
uint32_t elapsed = 0;
now = timer_milliseconds();
elapsed = now - t->start;
t->start = now;
t->interval = interval;
return elapsed;
}
/*************************************************************************
* Description: Start a timer from now.
* Returns: elapsed seconds since last set
* Notes: none
**************************************************************************/
uint32_t timer_interval_start_seconds(struct itimer *t, uint32_t interval)
{
uint32_t elapsed = 0;
interval *= 1000L;
elapsed = timer_interval_start(t, interval);
elapsed /= 1000L;
return elapsed;
}
/*************************************************************************
* Description: Start a timer from now.
* Returns: elapsed minutes since last set
* Notes: none
**************************************************************************/
uint32_t timer_interval_start_minutes(struct itimer *t, uint32_t interval)
{
uint32_t elapsed = 0;
interval *= 60L;
interval *= 1000L;
elapsed = timer_interval_start(t, interval);
elapsed /= 1000L;
elapsed /= 60L;
return elapsed;
}
/*************************************************************************
* Description: Change the timer interval without restart
* Returns: previous interval value
* Notes: none
**************************************************************************/
uint32_t timer_interval_adjust(struct itimer *t, uint32_t interval)
{
uint32_t previous_interval = t->interval;
t->interval = interval;
return previous_interval;
}
/*************************************************************************
* Description: Reset the timer with the same interval
* Returns: none
* Notes: none
**************************************************************************/
void timer_interval_reset(struct itimer *t)
{
t->start += t->interval;
}
/*************************************************************************
* Description: Restart the timer from now, syncing on existing interval
* Returns: elapsed milliseconds since last reset
* Notes: none
**************************************************************************/
uint32_t timer_interval_resync(struct itimer *t)
{
uint32_t elapsed;
uint32_t intervals;
uint32_t gap;
uint32_t now;
now = timer_milliseconds();
elapsed = now - t->start;
if ((t->interval != TIMER_INTERVAL_MAX) && (t->interval != 0)) {
if (elapsed >= t->interval) {
/* catch up to now */
intervals = elapsed / t->interval;
gap = intervals * t->interval;
t->start += gap;
}
}
return elapsed;
}
/*************************************************************************
* Description: Restart the timer from now
* Returns: elapsed milliseconds since last set
* Notes: none
**************************************************************************/
uint32_t timer_interval_restart(struct itimer *t)
{
uint32_t now;
uint32_t elapsed;
now = timer_milliseconds();
elapsed = now - t->start;
t->start = now;
return elapsed;
}
/*************************************************************************
* Description: Reset the timer with the zero interval - always expired
* Returns: none
* Notes: none
**************************************************************************/
void timer_interval_none(struct itimer *t)
{
t->interval = 0;
}
/*************************************************************************
* Description: Reset the timer with the max interval - never expires
* Returns: none
* Notes: none
**************************************************************************/
void timer_interval_infinity(struct itimer *t)
{
t->interval = TIMER_INTERVAL_MAX;
}
/*************************************************************************
* Description: Determines if the timer has an active interval
* Returns: true if active
* Notes: none
**************************************************************************/
bool timer_interval_active(struct itimer *t)
{
return ((t->interval != TIMER_INTERVAL_MAX) && (t->interval != 0));
}
/*************************************************************************
* Description: Check to see if the time interval has elapsed
* Returns: true if expired
* Notes: Setting the interval to max never expires, to zero always expires
**************************************************************************/
bool timer_interval_expired(struct itimer *t)
{
uint32_t elapsed = 0;
bool status = false;
uint32_t now;
if (t->interval == 0) {
status = true;
} else if (t->interval == TIMER_INTERVAL_MAX) {
status = false;
} else {
now = timer_milliseconds();
elapsed = now - t->start;
if (elapsed >= t->interval) {
status = true;
}
}
return status;
}
/*************************************************************************
* Description: Return the elapsed time
* Returns: number of milliseconds elapsed
* Notes: none
**************************************************************************/
uint32_t timer_interval_elapsed(struct itimer *t)
{
uint32_t now;
uint32_t elapsed;
now = timer_milliseconds();
elapsed = now - t->start;
return elapsed;
}
/*************************************************************************
* Description: Return the interval time
* Returns: number of milliseconds for which the interval is set
* Notes: none
**************************************************************************/
uint32_t timer_interval(struct itimer *t)
{
return t->interval;
}
/*************************************************************************
* Description: Return the interval time
* Returns: number of seconds for which the interval is set
* Notes: none
**************************************************************************/
uint32_t timer_interval_seconds(struct itimer *t)
{
return (t->interval/1000);
}
/* Elapsed Timer */
/*************************************************************************
* Description: Restart the timer from now
* Returns: elapsed milliseconds since last set
* Notes: none
**************************************************************************/
uint32_t timer_elapsed_start_offset(struct etimer *t, uint32_t offset)
{
uint32_t now;
uint32_t elapsed;
now = timer_milliseconds();
elapsed = now - t->start;
if (offset) {
t->start = now + offset;
} else {
t->start = now;
}
return elapsed;
}
/*************************************************************************
* Description: Start a timer from now.
* Returns: elapsed milliseconds since last set
* Notes: none
**************************************************************************/
uint32_t timer_elapsed_start(struct etimer *t)
{
return timer_elapsed_start_offset(t, 0);
}
/*************************************************************************
* Description: Return the elapsed time
* Returns: true if interval has elapsed
* Notes: none
**************************************************************************/
bool timer_elapsed_milliseconds(struct etimer *t, uint32_t interval)
{
bool status = false;
uint32_t delta;
delta = timer_milliseconds() - t->start;
if (delta >= interval) {
status = true;
}
return status;
}
/*************************************************************************
* Description: Return the elapsed time
* Returns: true if interval has elapsed
* Notes: none
**************************************************************************/
bool timer_elapsed_seconds(struct etimer *t, uint32_t interval)
{
/* convert to seconds */
interval *= 1000L;
return timer_elapsed_milliseconds(t, interval);
}
/*************************************************************************
* Description: Return the elapsed time
* Returns: true if interval has elapsed
* Notes: none
**************************************************************************/
bool timer_elapsed_minutes(struct etimer *t, uint32_t interval)
{
/* convert to seconds */
interval *= 1000L;
/* convert to minutes */
interval *= 60L;
return timer_elapsed_milliseconds(t, interval);
}
/*************************************************************************
* Description: Return the elapsed time
* Returns: number of milliseconds elapsed
* Notes: none
**************************************************************************/
uint32_t timer_elapsed_time(struct etimer *t)
{
uint32_t now;
uint32_t elapsed;
now = timer_milliseconds();
elapsed = now - t->start;
return elapsed;
}
-96
View File
@@ -1,96 +0,0 @@
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************/
#ifndef TIMER_H
#define TIMER_H
#include <stdbool.h>
#include <stdint.h>
/* interval and elapsed millisecond timer */
/* interval not to exceed 49.7 days */
#define TIMER_INTERVAL_MAX UINT32_MAX
/* structure for elapsed timer */
struct etimer {
uint32_t start;
};
/* structure for interval timer */
struct itimer {
uint32_t start;
uint32_t interval;
};
typedef void (*timer_callback_function) (void);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* -- Interval Timer library -- */
/* defined in generic timer module */
uint32_t timer_interval_start(struct itimer *t, uint32_t interval);
uint32_t timer_interval_start_seconds(struct itimer *t, uint32_t interval);
uint32_t timer_interval_start_minutes(struct itimer *t, uint32_t interval);
/* adjust interval without restarting */
uint32_t timer_interval_adjust(struct itimer *t, uint32_t interval);
/* adds interval to start - good for cyclic timers */
void timer_interval_reset(struct itimer *t);
/* sets interval to zero - always expired */
void timer_interval_none(struct itimer *t);
/* sets interval to max - never expires */
void timer_interval_infinity(struct itimer *t);
/* syncs the start time to the next interval */
uint32_t timer_interval_resync(struct itimer *t);
/* restarts the interval timer */
uint32_t timer_interval_restart(struct itimer *t);
bool timer_interval_expired(struct itimer *t);
uint32_t timer_interval(struct itimer *t);
bool timer_interval_active(struct itimer *t);
uint32_t timer_interval_seconds(struct itimer *t);
uint32_t timer_interval_elapsed(struct itimer *t);
/* -- Elapsed Timer library - lower RAM usage or alternate functional usage -- */
uint32_t timer_elapsed_start(struct etimer *t);
uint32_t timer_elapsed_start_offset(struct etimer *t, uint32_t offset);
bool timer_elapsed_milliseconds(struct etimer *t, uint32_t interval);
bool timer_elapsed_seconds(struct etimer *t, uint32_t interval);
bool timer_elapsed_minutes(struct etimer *t, uint32_t interval);
uint32_t timer_elapsed_time(struct etimer *t);
/* define these functions in hardware specific timer module */
void timer_init(void);
/* Raw API is used only by the elapsed and interval timer library.
Do not use it directly in your code. */
uint32_t timer_milliseconds(void);
bool timer_callback(
timer_callback_function callback,
uint32_t milliseconds);
bool timer_callback_oneshot(
timer_callback_function callback,
uint32_t milliseconds);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif