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 <cpu/types.h>
44 #include <drv/pwm_at91.h>
45 #include <drv/timer.h>
46 #include <drv/sysirq_at91.h>
48 #include <cfg/macros.h>
49 #include <cfg/debug.h>
52 #warning FIXME: This test is target specific, refactor it to be generic for all target!
58 * Esample of value for duty cycle"
60 * - 100% => 0xFFFFFFFF
69 #define PWM_TEST_CH0 0
70 #define PWM_TEST_CH0_FREQ 100UL // 100Hz
71 #define PWM_TEST_CH0_DUTY 0xBFFF // 80%
73 #define PWM_TEST_CH1 1
74 #define PWM_TEST_CH1_FREQ 1000UL // 1000Hz
75 #define PWM_TEST_CH1_DUTY 0xBFFF // 75%
77 #define PWM_TEST_CH2 2
78 #define PWM_TEST_CH2_FREQ 12356UL // 12356Hz
79 #define PWM_TEST_CH2_DUTY 0x7FFF // 50%
81 #define PWM_TEST_CH3 3
82 #define PWM_TEST_CH3_FREQ 100000UL // 100KHz
83 #define PWM_TEST_CH3_DUTY 0x5555 // 33%
85 #define PWM_TEST_CH_SET(index) \
87 pwm_setFrequency(PWM_TEST_CH##index , PWM_TEST_CH##index##_FREQ); \
88 pwm_setDuty(PWM_TEST_CH##index, PWM_TEST_CH##index##_DUTY); \
89 pwm_enable(PWM_TEST_CH##index, true); \
93 * Test suit for genation of pwm waveform.
99 kputs("PWM test\n\n");
107 kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH0, PWM_TEST_CH0_FREQ, PWM_TEST_CH0_DUTY);
109 kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH1, PWM_TEST_CH1_FREQ, PWM_TEST_CH1_DUTY);
111 kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH2, PWM_TEST_CH2_FREQ, PWM_TEST_CH2_DUTY);
113 kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH3, PWM_TEST_CH3_FREQ, PWM_TEST_CH3_DUTY);
127 kputs("Parto con il test!\n");
128 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);
135 kprintf("TEST10 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
138 pwm_setDuty(0,0x7FFF);
140 kprintf("TEST50 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
143 pwm_setDuty(0,0x5555);
145 kprintf("TEST33 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
148 pwm_setDuty(0,0xCCCC);
150 kprintf("TEST80 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
154 // 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);
155 // 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);
156 // 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);
157 // 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);