STM32 V5 source code
guowenxue
2018-02-04 785deec23b4cb1e7c4c4d81eb808f195adb1d98a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/****************************************************************************
*   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;
}