blob: d96d42e8ff762e4dbeb31b404f2aaec8f116eae8 (
plain)
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
|
/*
* linux/drivers/power/fg/fg_math.c
*
* TI Fuel Gauge driver for Linux
*
* Copyright (C) 2008-2009 Texas Instruments, Inc.
* Author: Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <linux/types.h>
#include "fg_math.h"
/* IIR Filter */
short filter(short y, short x, short a)
{
int l;
l = (int) a * y;
l += (int) (256 - a) * x;
l /= 256;
return (short) l;
}
/* Returns diviation between 'size' array members */
unsigned short diff_array(short *arr, unsigned char size)
{
unsigned char i;
unsigned int diff = 0;
for (i = 0; i < size-1; i++)
diff += abs(arr[i] - arr[i+1]);
if (diff > MAX_UNSIGNED_INT)
diff = MAX_UNSIGNED_INT;
return (unsigned short) diff;
}
|