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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*++
Copyright (c) 2010 WonderMedia Technologies, Inc.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details. You
should have received a copy of the GNU General Public License along with this
program. If not, see http://www.gnu.org/licenses/>.
WonderMedia Technologies, Inc.
4F, 531, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
--*/
#include <common.h>
#include "vpp.h"
static WMT_OST_REG *pWMTOST;
#ifndef NULL
#define NULL 0
#endif
int wmt_write_ostc(void)
{
unsigned int sw_counter = 30000;
while( pWMTOST->ostas & 0x10 ) {
if ( --sw_counter == 0 ) { // Need to be considered
printf("Count Write Active Busy\n");
return -1;
}
}
return 0;
}
int wmt_init_ost(void)
{
//printf("wmt_init_ostimer\n");
if (pWMTOST == NULL)
pWMTOST = (WMT_OST_REG *)0xd8130100;
if (pWMTOST->ostctrl&0x01)
return 0;
pWMTOST->ostctrl = 0;
pWMTOST->ostwe = 0;
if (wmt_write_ostc())
return -1;
pWMTOST->ostct = 0;
pWMTOST->ostctrl = 1;
return 0;
}
int wmt_read_ostc(int *val)
{
unsigned int sw_counter = 300000;
if (pWMTOST == NULL) {
if (wmt_init_ost())
return -1;
}
if ( (pWMTOST->ostctrl & 0x02 ) == 0 )
pWMTOST->ostctrl |= 0x02;
// Check OS Timer Count Value is Valid
while ( (pWMTOST->ostas & 0x20) == 0x20 ) {
if ( --sw_counter == 0 ) { // Need to be considered
printf("Read Count Request Fail\n");
break;
}
}
//*val = (int)pWMTOST->ostct; //Charles
*val = (int)pWMTOST->ostct/3;
return 0;
}
int wmt_delayus(int us)
{
int count = 100;
int before,after;
//us = us*3;
if (wmt_read_ostc(&before))
return -1;
while(1) {
while(--count);
if (wmt_read_ostc(&after))
return -1;
if ((after - before) >= us) {
//printf("request = %d , result = %d\n",us,(after - before));
break;
}
count = 100;
}
return 0;
}
|