4 * This file is part of BeRTOS.
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.
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.
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
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.
29 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
33 * \brief Test for PWM driver (implementation)
37 * \author Daniele Basile <asterix@develer.com>
40 #include <cfg/macros.h>
41 #include <cfg/debug.h>
43 #include <cpu/types.h>
47 #include <drv/pwm_at91.h>
48 #include <drv/timer.h>
49 #include <drv/sysirq_at91.h>
54 * Esample of value for duty cycle"
56 * - 100% => 0xFFFFFFFF
65 #define PWM_TEST_CH0 0
66 #define PWM_TEST_CH0_FREQ 100UL // 100Hz
67 #define PWM_TEST_CH0_DUTY 0xBFFF // 80%
69 #define PWM_TEST_CH1 1
70 #define PWM_TEST_CH1_FREQ 1000UL // 1000Hz
71 #define PWM_TEST_CH1_DUTY 0xBFFF // 75%
73 #define PWM_TEST_CH2 2
74 #define PWM_TEST_CH2_FREQ 12356UL // 12356Hz
75 #define PWM_TEST_CH2_DUTY 0x7FFF // 50%
77 #define PWM_TEST_CH3 3
78 #define PWM_TEST_CH3_FREQ 100000UL // 100KHz
79 #define PWM_TEST_CH3_DUTY 0x5555 // 33%
81 #define PWM_TEST_CH_SET(index) \
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); \
90 * Setup all needed to test PWM on AT91
93 int pwm_testSetup(void)
107 * Test suit for genation of pwm waveform.
110 int pwm_testRun(void)
113 kputs("PWM test\n\n");
120 kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH0, PWM_TEST_CH0_FREQ, PWM_TEST_CH0_DUTY);
122 kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH1, PWM_TEST_CH1_FREQ, PWM_TEST_CH1_DUTY);
124 kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH2, PWM_TEST_CH2_FREQ, PWM_TEST_CH2_DUTY);
126 kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH3, PWM_TEST_CH3_FREQ, PWM_TEST_CH3_DUTY);
134 int pwm_testTearDown(void)
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);
156 kprintf("TEST10 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
159 pwm_setDuty(0,0x7FFF);
161 kprintf("TEST50 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
164 pwm_setDuty(0,0x5555);
166 kprintf("TEST33 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
169 pwm_setDuty(0,0xCCCC);
171 kprintf("TEST80 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
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);