clock.h
来自「MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis」· C头文件 代码 · 共 162 行
H
162 行
// This file is part of MANTIS OS, Operating System// See http://mantis.cs.colorado.edu///// Copyright (C) 2003,2004,2005 University of Colorado, Boulder//// This program is free software; you can redistribute it and/or// modify it under the terms of the mos license (see file LICENSE)/* Project Mantis File: clock.c Author: Jeff Rose Date: 4/20/04 A set of typical clock and timer based services for the MOS system.*//** @file clock.h * @brief An alarm timer implementation for the avr. * * @author Original Author: Jeff Rose * @author Heavily Modified and debugged: Brian, Cyrus, Charles, Adam * @date Created: 04/20/2004 * @date Modified: 05/25/2004*/#ifndef __CLOCK_H__#define __CLOCK_H__#include "mos.h"#include <inttypes.h>/** @brief A standard time struct */typedef struct mos_time_{ /** @brief Seconds */ uint32_t sec; /** @brief Microseconds */ uint32_t usec;} mos_time_t;typedef void (*alarm_func)(void *user_data);/** @brief A structure to hold an alarm * * An alarm is attached to a hardware timer, along with * a callback function which is called when the alarm triggers. * Alarms are stored in a linked list, with the relative number * of ticks between each node in the list. * * NOTE: The callback function will be executed in an interrrupt * context. */#ifdef PLATFORM_LINUXtypedef struct mos_alarm_{ alarm_func func; mos_time_t time; void *data; struct mos_alarm_ *next;} mos_alarm_t;#elsetypedef struct mos_alarm_{ /** @brief Callback function to call on alarm trigger */ alarm_func func; /** @brief Data parameter to pass to callback function */ void *data; /** @brief Number of ticks until alarm triggers */ uint32_t ticks; /** @brief Next alarm */ struct mos_alarm_ *next;} mos_alarm_t;#endif#if !defined(PLATFORM_LINUX) && !defined(PLATFORM_TELOSB)/** @brief ticks per second *//** @brief microseconds per tick */#ifdef CLOCK_SPEED_7_37#define TICKS_PER_SEC 28800#define USECS_PER_TICK 35#else# ifdef CLOCK_SPEED_3_68#define TICKS_PER_SEC 14400#define USECS_PER_TICK 69# else# ifdef CLOCK_SPEED_4_0#define TICKS_PER_SEC 14400#define USECS_PER_TICK 69# else# error "Timeslice not defined for clock. (msched.c)"# endif#endif#endif#endif/** @brief Initialize the clock. * * Set the interrupt mode, set the prescaler. */void clock_init();/** @brief Delay function in microseconds. * * @param usec Microseconds to delay */void mos_udelay(uint16_t usec);/** @brief Delay function in milliseconds. * * @param msec Milliseconds to delay */ void mos_mdelay(uint16_t msec);/** @brief Inserts a new alarm at the given secs and usecs from the current time. * * Accounts for inserting the new alarm into the alarm list in order and adjusting the relative times of the alarm list as it is called. * @param new New alarm to be inserted * @param secs Relative time in secs * @param usecs Relative time in microseconds */int8_t mos_alarm(mos_alarm_t *new, uint32_t secs, uint32_t usecs);/** @brief Inserts a new alarm at the given number of ticks from the current time. * * Accounts for inserting the new alarm into the alarm list in order and adjusting the relative times of the alarm list as it is called. * Use this if you want to avoid conversion math. * @param new New alarm to be inserted * @param ticks Relative time in ticks */int8_t mos_alarm_ticks(mos_alarm_t *new, uint32_t ticks);/** @brief Remove an alarm from the list * * @param alarm Alarm to remove * @return */boolean mos_remove_alarm(mos_alarm_t *alarm);/** @brief Set the current real world time. * * @param tv New time to apply */int8_t mos_set_time(mos_time_t *tv);/**@brief Get the current real world time. * * @param tv Stores real world time */int8_t mos_get_time(mos_time_t *tv);/** @brief Convenience function for printing an alarm list. */void print_clock_list (void);#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?