OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_STR71x_IAR/] [Library/] [wdg.c] - Blame information for rev 577

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 577 jeremybenn
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
2
* File Name          : WDG.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 10/24/2003
5
* Description        : This file provides all the WDG software functions
6
********************************************************************************
7
* History:
8
*  30/11/2004 : V2.0
9
*  14/07/2004 : V1.3
10
*  01/01/2004 : V1.2
11
*******************************************************************************
12
 THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
13
 CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
14
 AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
15
 OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
16
 OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
17
 CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18
*******************************************************************************/
19
 
20
#include "wdg.h"
21
 
22
#ifndef abs
23
        #define abs(x) ((x)>0 ? (x) : -(x))
24
#endif
25
 
26
/*******************************************************************************
27
* Function Name  : FindFactors
28
* Description    : Search for the best (a,b) values that fit n = a*b
29
*                  with the following constraints: 1<=a<=256, 1<=b<=65536
30
* Input 1        : n: the number to decompose
31
* Input/Output 2 : a: a pointer to the first factor
32
* Input/Output 3 : b: a pointer to the second factor
33
* Return         : None
34
*******************************************************************************/
35
static void FindFactors(unsigned long n, unsigned int *a, unsigned long *b)
36
{
37
        unsigned long b0;
38
        unsigned int a0;
39
        long err, err_min=n;
40
 
41
        *a = a0 = ((n-1)/65536ul) + 1;
42
        *b = b0 = n / *a;
43
 
44
        for (; *a <= 256; (*a)++)
45
        {
46
                *b = n / *a;
47
                err = (long)*a * (long)*b - (long)n;
48
                if (abs(err) > (*a / 2))
49
                {
50
                        (*b)++;
51
                        err = (long)*a * (long)*b - (long)n;
52
                }
53
                if (abs(err) < abs(err_min))
54
                {
55
                        err_min = err;
56
                        a0 = *a;
57
                        b0 = *b;
58
                        if (err == 0) break;
59
                }
60
        }
61
 
62
        *a = a0;
63
        *b = b0;
64
}
65
 
66
/*******************************************************************************
67
* Function Name  : WDG_PeriodValueConfig
68
* Description    : Set the prescaler and counter reload value
69
* Input          : Amount of time (us) needed
70
* Return         : None
71
*******************************************************************************/
72
void WDG_PeriodValueConfig ( u32 Time )
73
{
74
        unsigned int a;
75
        unsigned long n, b;
76
 
77
        n = Time * (RCCU_FrequencyValue(RCCU_PCLK) / 1000000);
78
        FindFactors(n, &a, &b);
79
    WDG->PR = a - 1;
80
    WDG->VR = b - 1;
81
}
82
 
83
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.