/****************************************************************************
|
* Copyright: (C)2014 Î人ÁèÔÆÇ¶ÈëʽʵÑéÊÒ www.emblinux.com
|
* Author: GuoWenxue<guowenxue@gmail.com> QQ: 281143292
|
* Description: ·Ü¶·STM32v5¿ª·¢°åcontiki²Ù×÷ϵͳʱÖÓº¯Êý£¬Ö÷ÒªÊÇsystick
|
* ÖжϷþÎñ´¦Àí³ÌÐò¡£
|
*
|
* ChangeLog:
|
* °æ±¾ºÅ ÈÕÆÚ ×÷Õß ËµÃ÷
|
* V1.0.0 2014.08.25 GuoWenxue ·¢²¼¸Ã°æ±¾
|
****************************************************************************/
|
|
#include "stm32f10x.h"
|
#include "stm32f10x_it.h"
|
|
#include <sys/clock.h>
|
#include <sys/cc.h>
|
#include <sys/etimer.h>
|
#include <stdio.h>
|
|
static volatile clock_time_t current_clock = 0; /* Total current running clocks */
|
static volatile unsigned long current_seconds = 0; /* Current running seconds */
|
static unsigned int second_countdown = CLOCK_SECOND;
|
|
void SysTick_Handler(void)
|
{
|
current_clock++;
|
|
/* timerlist²»Îª¿ÕÇÒ»¹Ã»ÓÐetimerµ½ÆÚ£¬ÔòÖ´ÐÐetimer_request_poll */
|
if(etimer_pending() && etimer_next_expiration_time() <= current_clock)
|
{
|
/* ÈÃetimer_process¸ü¿ìµØÔٴλñµÃÖ´ÐÐ */
|
etimer_request_poll();
|
}
|
|
if (--second_countdown == 0) {
|
current_seconds++;
|
second_countdown = CLOCK_SECOND;
|
}
|
|
//printf("Current seconds:%lu Current Clocks: %u\n", current_seconds, current_clock);
|
}
|
|
void clock_init()
|
{
|
if (SysTick_Config(SystemCoreClock / CLOCK_SECOND))
|
{
|
while(1);
|
}
|
}
|
|
clock_time_t clock_time(void)
|
{
|
return current_clock;
|
}
|
|
unsigned long clock_seconds(void)
|
{
|
return current_seconds;
|
}
|