Refactor BeRTOS to be in his own directory.
[bertos.git] / bertos / 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 <cpu/types.h>
41 #include <cpu/irq.h>
42
43 #include <drv/pwm.h>
44 #include <drv/pwm_at91.h>
45
46 #include <cfg/macros.h>
47 #include <cfg/debug.h>
48
49 /*
50  * Esample of value for duty cycle"
51  *
52  * - 100% => 0xFFFFFFFF
53  * - 80%  => 0xCCCCCCCC
54  * - 75%  => 0xBFFFFFFF
55  * - 50%  => 0x7FFFFFFF
56  * - 25%  => 0x3FFFFFFF
57  * - 33%  => 0x55555555
58  * - 16%  => 0x2AAAAAAA
59  */
60
61 #define PWM_TEST_CH0                     0
62 #define PWM_TEST_CH0_FREQ            100UL // 100Hz
63 #define PWM_TEST_CH0_DUTY           0xCCCC // 80%
64
65 #define PWM_TEST_CH1                     1
66 #define PWM_TEST_CH1_FREQ           1000UL  // 1000Hz
67 #define PWM_TEST_CH1_DUTY           0xBFFF  // 75%
68
69 #define PWM_TEST_CH2                     2
70 #define PWM_TEST_CH2_FREQ            12356  // 12356Hz
71 #define PWM_TEST_CH2_DUTY           0x7FFF  // 50%
72
73 #define PWM_TEST_CH3                     3
74 #define PWM_TEST_CH3_FREQ         100000UL  // 100KHz
75 #define PWM_TEST_CH3_DUTY           0x5555  // 33%
76
77 #define PWM_TEST_CH_SET(index) \
78         do { \
79                         pwm_setFrequency(PWM_TEST_CH##index , PWM_TEST_CH##index##_FREQ); \
80                         pwm_setDuty(PWM_TEST_CH##index, PWM_TEST_CH##index##_DUTY); \
81                         pwm_enable(PWM_TEST_CH##index, true); \
82         } while (0)
83
84 /**
85  * Test suit for genation of pwm waveform.
86  *
87  */
88 void pwm_test(void)
89 {
90
91         pwm_init();
92         kputs("Init pwm..\n");
93
94         PWM_TEST_CH_SET(0);
95         kprintf("Set pwm ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH0, PWM_TEST_CH0_FREQ, PWM_TEST_CH0_DUTY);
96         PWM_TEST_CH_SET(1);
97         kprintf("Set pwm ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH1, PWM_TEST_CH1_FREQ, PWM_TEST_CH1_DUTY);
98         PWM_TEST_CH_SET(2);
99         kprintf("Set pwm ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH2, PWM_TEST_CH2_FREQ, PWM_TEST_CH2_DUTY);
100         PWM_TEST_CH_SET(3);
101         kprintf("Set pwm ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH3, PWM_TEST_CH3_FREQ, PWM_TEST_CH3_DUTY);
102 }
103
104
105
106
107
108