Use cfg instead appconfig in bertos modules. Reformat. Remove CVS logs.
[bertos.git] / bertos / cpu / arm / drv / pwm_test.c
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
30  * -->
31  *
32  *
33  * \brief Test for PWM driver (implementation)
34  *
35  * \version $Id$
36  *
37  * \author Daniele Basile <asterix@develer.com>
38  */
39
40 #include <cfg/macros.h>
41 #include <cfg/debug.h>
42
43 #include <cpu/types.h>
44 #include <cpu/irq.h>
45
46 #include <drv/pwm.h>
47 #include <drv/pwm_at91.h>
48 #include <drv/timer.h>
49 #include <drv/sysirq_at91.h>
50
51 #include <io/arm.h>
52
53 /*
54  * Esample of value for duty cycle"
55  *
56  * - 100% => 0xFFFFFFFF
57  * - 80%  => 0xCCCCCCCC
58  * - 75%  => 0xBFFFFFFF
59  * - 50%  => 0x7FFFFFFF
60  * - 25%  => 0x3FFFFFFF
61  * - 33%  => 0x55555555
62  * - 16%  => 0x2AAAAAAA
63  */
64
65 #define PWM_TEST_CH0                     0
66 #define PWM_TEST_CH0_FREQ            100UL // 100Hz
67 #define PWM_TEST_CH0_DUTY           0xBFFF // 80%
68
69 #define PWM_TEST_CH1                     1
70 #define PWM_TEST_CH1_FREQ           1000UL  // 1000Hz
71 #define PWM_TEST_CH1_DUTY           0xBFFF  // 75%
72
73 #define PWM_TEST_CH2                     2
74 #define PWM_TEST_CH2_FREQ          12356UL  // 12356Hz
75 #define PWM_TEST_CH2_DUTY           0x7FFF  // 50%
76
77 #define PWM_TEST_CH3                     3
78 #define PWM_TEST_CH3_FREQ         100000UL  // 100KHz
79 #define PWM_TEST_CH3_DUTY           0x5555  // 33%
80
81 #define PWM_TEST_CH_SET(index) \
82         do { \
83                         pwm_setFrequency(PWM_TEST_CH##index , PWM_TEST_CH##index##_FREQ); \
84                         pwm_setDuty(PWM_TEST_CH##index, PWM_TEST_CH##index##_DUTY); \
85                         pwm_enable(PWM_TEST_CH##index, true); \
86         } while (0)
87
88
89 /**
90  * Setup all needed to test PWM on AT91
91  *
92  */
93 int pwm_testSetup(void)
94 {
95         IRQ_ENABLE;
96         kdbg_init();
97         sysirq_init();
98         timer_init();
99
100         pwm_init();
101
102         return 0;
103 }
104
105
106 /**
107  * Test suit for genation of pwm waveform.
108  *
109  */
110 int pwm_testRun(void)
111 {
112
113         kputs("PWM test\n\n");
114
115         kputs("Init pwm..");
116         pwm_testSetup();
117         kputs("done.\n");
118
119         PWM_TEST_CH_SET(0);
120         kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH0, PWM_TEST_CH0_FREQ, PWM_TEST_CH0_DUTY);
121         PWM_TEST_CH_SET(1);
122         kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH1, PWM_TEST_CH1_FREQ, PWM_TEST_CH1_DUTY);
123         PWM_TEST_CH_SET(2);
124         kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH2, PWM_TEST_CH2_FREQ, PWM_TEST_CH2_DUTY);
125         PWM_TEST_CH_SET(3);
126         kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH3, PWM_TEST_CH3_FREQ, PWM_TEST_CH3_DUTY);
127
128         return 0;
129 }
130
131 /**
132  *
133  */
134 int pwm_testTearDown(void)
135 {
136         /*    */
137         return 0;
138 }
139
140 #ifdef _TEST
141
142 int main(void)
143 {
144         pwm_testRun();
145
146
147
148         kputs("Parto con il test!\n");
149         kprintf("PWM CURRENT ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH0, PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
150
151         for(;;)
152         {
153
154                 pwm_setDuty(0,0);
155                 timer_delay(5000);
156                 kprintf("TEST10 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
157
158
159                 pwm_setDuty(0,0x7FFF);
160                 timer_delay(5000);
161                 kprintf("TEST50 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
162
163
164                 pwm_setDuty(0,0x5555);
165                 timer_delay(5000);
166                 kprintf("TEST33 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
167
168
169                 pwm_setDuty(0,0xCCCC);
170                 timer_delay(5000);
171                 kprintf("TEST80 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
172                 kputs("--------\n");
173
174
175 //              kprintf("PWM test ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH0, PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
176 //              kprintf("PWM test ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH1, PWM_CMR1, PWM_CDTY1, PWM_CPRD1, PWM_CUPD1);
177 //              kprintf("PWM test ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH2, PWM_CMR2, PWM_CDTY2, PWM_CPRD2, PWM_CUPD2);
178 //              kprintf("PWM test ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH3, PWM_CMR3, PWM_CDTY3, PWM_CPRD3, PWM_CUPD3);
179         }
180
181 }
182 #endif
183
184