@@ -0,0 +1,22 | |||
|
1 | TEMPLATE = app | |
|
2 | ||
|
3 | DEFINES += CPUFREQ=40000000 | |
|
4 | ||
|
5 | LIBS += -ldac | |
|
6 | ||
|
7 | eval(UCMODEL = simulator) { | |
|
8 | BSP = SIMULATOR | |
|
9 | } | |
|
10 | eval(UCMODEL = stm32f4) { | |
|
11 | BSP = STM32F4Eval | |
|
12 | } | |
|
13 | ||
|
14 | SOURCES += \ | |
|
15 | main.c | |
|
16 | ||
|
17 | ||
|
18 | ||
|
19 | ||
|
20 | ||
|
21 | ||
|
22 |
@@ -0,0 +1,56 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the libuc, microcontroler library | |
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |
|
4 | -- | |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
|
6 | -- it under the terms of the GNU General Public License as published by | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
15 | -- You should have received a copy of the GNU General Public License | |
|
16 | -- along with this program; if not, write to the Free Software | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org | |
|
20 | -------------------------------------------------------------------------------*/ | |
|
21 | /** | |
|
22 | * This file is a simple example for the DAC library. | |
|
23 | * | |
|
24 | */ | |
|
25 | ||
|
26 | #include <stdio.h> | |
|
27 | #include <uhandle.h> | |
|
28 | #include <dac.h> | |
|
29 | #include <timer.h> | |
|
30 | #include <gpio.h> | |
|
31 | #include <math.h> | |
|
32 | int16_t __attribute__ ((aligned (4))) data[512]; | |
|
33 | int libuc_main() | |
|
34 | { | |
|
35 | /** | |
|
36 | Depending on the board the printf can be directed on one uart or LCD screen or | |
|
37 | any other stream device. | |
|
38 | */ | |
|
39 | printf("DAC example\n\r"); | |
|
40 | for(int i=0;i<512;i++) | |
|
41 | { | |
|
42 | data[i]=(int16_t)(2000.0*cos(i/10.0))+2000.0; | |
|
43 | } | |
|
44 | dacopen(PA4); | |
|
45 | dacsetconfig(timer8, 512, DAC1,DAC1_12bit_right_align , 100000,(void*)data); | |
|
46 | return 0; | |
|
47 | } | |
|
48 | ||
|
49 | ||
|
50 | ||
|
51 | ||
|
52 | ||
|
53 | ||
|
54 | ||
|
55 | ||
|
56 |
@@ -0,0 +1,18 | |||
|
1 | TEMPLATE = app | |
|
2 | ||
|
3 | eval(UCMODEL = simulator) { | |
|
4 | BSP = SIMULATOR | |
|
5 | } | |
|
6 | eval(UCMODEL = stm32f4) { | |
|
7 | BSP = STM32F4Eval | |
|
8 | } | |
|
9 | ||
|
10 | SOURCES += \ | |
|
11 | main.c | |
|
12 | ||
|
13 | ||
|
14 | ||
|
15 | ||
|
16 | ||
|
17 | ||
|
18 |
@@ -0,0 +1,45 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the libuc, microcontroler library | |
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |
|
4 | -- | |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
|
6 | -- it under the terms of the GNU General Public License as published by | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
15 | -- You should have received a copy of the GNU General Public License | |
|
16 | -- along with this program; if not, write to the Free Software | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org | |
|
20 | -------------------------------------------------------------------------------*/ | |
|
21 | /** | |
|
22 | * This file is a simple hello world example it should run on any supported | |
|
23 | * board/architecture couple. To change target board and architecture modify | |
|
24 | * the project file. The value BSP contains the board name, and UCMODEL contain | |
|
25 | * the target architecture. | |
|
26 | */ | |
|
27 | ||
|
28 | int libuc_main() | |
|
29 | { | |
|
30 | /** | |
|
31 | Depending on the board the printf can be directed on one uart or LCD screen or | |
|
32 | any other stream device. | |
|
33 | */ | |
|
34 | printf("hello world\n\r"); | |
|
35 | return 0; | |
|
36 | } | |
|
37 | ||
|
38 | ||
|
39 | ||
|
40 | ||
|
41 | ||
|
42 | ||
|
43 | ||
|
44 | ||
|
45 |
@@ -0,0 +1,65 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the libuc, microcontroler library | |
|
3 | -- Copyright (C) 2014, Kaveh Mohamadabadi | |
|
4 | -- | |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
|
6 | -- it under the terms of the GNU General Public License as published by | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
15 | -- You should have received a copy of the GNU General Public License | |
|
16 | -- along with this program; if not, write to the Free Software | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | ------------------------------------------------------------------------------- | |
|
19 | -- Author : Kaveh Mohamadabadi | |
|
20 | -- Mail : kaveh.mohamadabadi@gmail.com | |
|
21 | -------------------------------------------------------------------------------*/ | |
|
22 | /// \defgroup TIMER | |
|
23 | /*! \file timer.h | |
|
24 | \brief TIMER api. | |
|
25 | ||
|
26 | ||
|
27 | \ingroup TIMER | |
|
28 | ||
|
29 | */ | |
|
30 | #ifndef TIMER_H | |
|
31 | #define TIMER_H | |
|
32 | ||
|
33 | #include <stdint.h> | |
|
34 | #ifdef __cplusplus | |
|
35 | extern "C" { | |
|
36 | #endif | |
|
37 | ||
|
38 | ||
|
39 | #ifdef __cplusplus | |
|
40 | } | |
|
41 | #endif | |
|
42 | ||
|
43 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | |
|
44 | ||
|
45 | #define timer1 0 | |
|
46 | #define timer2 1 | |
|
47 | #define timer3 2 | |
|
48 | #define timer4 3 | |
|
49 | #define timer5 4 | |
|
50 | #define timer6 5 | |
|
51 | #define timer7 6 | |
|
52 | #define timer8 7 | |
|
53 | #define timer9 8 | |
|
54 | #define timer10 9 | |
|
55 | #define timer11 10 | |
|
56 | #define timer12 11 | |
|
57 | #define timer13 12 | |
|
58 | #define timer14 13 | |
|
59 | #define timer15 14 | |
|
60 | #define timer16 15 | |
|
61 | ||
|
62 | ||
|
63 | ||
|
64 | #endif | |
|
65 | #endif // TIMER_H |
@@ -0,0 +1,13 | |||
|
1 | TEMPLATE = lib | |
|
2 | CONFIG += libuc2lib | |
|
3 | ||
|
4 | SOURCES += timer.c | |
|
5 | ||
|
6 | ||
|
7 | UCMODEL=stm32f4 | |
|
8 | ||
|
9 | HEADERS += \ | |
|
10 | ../../../include/PERIPHERALS/timer.h | |
|
11 | ||
|
12 | ||
|
13 |
@@ -1,31 +1,21 | |||
|
1 | 1 | TEMPLATE = subdirs |
|
2 | 2 | CONFIG += ordered |
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | !isEmpty( UCMODEL ) { |
|
6 | 6 | contains( UCMODEL, stm32f4 ){ |
|
7 | 7 | SUBDIRS += \ |
|
8 |
|
|
|
9 | SOLAR_PSU_HELLO/hello.pro \ | |
|
10 |
|
|
|
11 | STM32F4IT \ | |
|
12 | M4StickV2 \ | |
|
13 | lcdHello \ | |
|
14 | BeagleSynthHello \ | |
|
15 | lcdTerminal \ | |
|
16 | BeagleSynthHelloSupMon \ | |
|
17 | TEST_CMSIS_FFT \ | |
|
18 | N25Q128_test \ | |
|
19 | ssd2119Tests | |
|
8 | helloWorld \ | |
|
9 | DAC \ | |
|
10 | PWM | |
|
20 | 11 | } |
|
21 | 12 | contains( UCMODEL, simulator ){ |
|
22 | 13 | SUBDIRS += \ |
|
23 | TEST_SIMULATOR \ | |
|
24 | 14 | helloWorld |
|
25 | 15 | } |
|
26 | 16 | } |
|
27 | 17 | |
|
28 | 18 | |
|
29 | 19 | |
|
30 | 20 | |
|
31 | 21 |
@@ -1,16 +1,19 | |||
|
1 | UCMODEL=simulator | |
|
2 | ||
|
3 | 1 |
|
|
4 | 2 | |
|
5 | BSP = SIMULATOR | |
|
6 | ||
|
3 | eval(UCMODEL = simulator) { | |
|
4 | BSP = SIMULATOR | |
|
5 | } | |
|
6 | eval(UCMODEL = stm32f4) { | |
|
7 | BSP = STM32F4Eval | |
|
8 | } | |
|
7 | 9 | |
|
8 | 10 | SOURCES += \ |
|
9 | 11 | main.c |
|
10 | 12 | |
|
11 | 13 | |
|
12 | 14 | |
|
13 | 15 | |
|
14 | 16 | |
|
15 | 17 | |
|
16 | 18 | |
|
19 |
@@ -1,45 +1,46 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2013, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org |
|
20 | 20 | -------------------------------------------------------------------------------*/ |
|
21 | 21 | /** |
|
22 | 22 | * This file is a simple hello world example it should run on any supported |
|
23 | 23 | * board/architecture couple. To change target board and architecture modify |
|
24 | 24 | * the project file. The value BSP contains the board name, and UCMODEL contain |
|
25 | 25 | * the target architecture. |
|
26 | 26 | */ |
|
27 | #include <stdio.h> | |
|
27 | 28 | |
|
28 | 29 | int libuc_main() |
|
29 | 30 | { |
|
30 | 31 | /** |
|
31 | 32 | Depending on the board the printf can be directed on one uart or LCD screen or |
|
32 | 33 | any other stream device. |
|
33 | 34 | */ |
|
34 | 35 | printf("hello world\n\r"); |
|
35 | 36 | return 0; |
|
36 | 37 | } |
|
37 | 38 | |
|
38 | 39 | |
|
39 | 40 | |
|
40 | 41 | |
|
41 | 42 | |
|
42 | 43 | |
|
43 | 44 | |
|
44 | 45 | |
|
45 | 46 |
@@ -1,33 +1,26 | |||
|
1 | 1 | #ifndef DAC_LIB_H |
|
2 | 2 | #define DAC_LIB_H |
|
3 | 3 | |
|
4 | 4 | #define DAC1_12bit_right_align 0x40007408 |
|
5 | 5 | #define DAC1_12bit_left_align 0x4000740C |
|
6 | 6 | #define DAC1_8bit_right_align 0x40007410 |
|
7 | 7 | #define DAC2_12bit_right_align 0x40007414 |
|
8 | 8 | #define DAC2_12bit_left_align 0x40007418 |
|
9 | 9 | #define DAC2_8bit_right_align 0x4000741C |
|
10 | 10 | #define DAC_Dual_12bit_right_align 0x40007420 |
|
11 | 11 | #define DAC_Dual_12bit_left_align 0x40007424 |
|
12 | 12 | #define DAC_Dual_8bit_right_align 0x40007428 |
|
13 | 13 | #define DAC_Dual_8bit_left_align 0x4000742C |
|
14 | 14 | |
|
15 | 15 | #define DAC1 0 |
|
16 | 16 | #define DAC2 1 |
|
17 | 17 | |
|
18 | #define timer2 1 | |
|
19 | #define timer3 2 | |
|
20 | #define timer4 3 | |
|
21 | #define timer5 4 | |
|
22 | #define timer6 5 | |
|
23 | #define timer7 6 | |
|
24 | #define timer8 7 | |
|
25 | 18 | |
|
26 | 19 | |
|
27 | 20 | extern int dacopen(uint32_t pin); |
|
28 |
extern int dacsetconfig(int timer, int buffer_size, int dac,uint32_t dac_type, uint32_t |
|
|
21 | extern int dacsetconfig(int timer, int buffer_size, int dac, uint32_t dac_type, uint32_t samplingFreq, void* data); | |
|
29 | 22 | |
|
30 | 23 | |
|
31 | 24 | |
|
32 | 25 | |
|
33 | 26 | #endif // DAC_LIB_H |
@@ -1,349 +1,346 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2014, Kaveh Mohamadabadi |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Kaveh Mohamadabadi |
|
20 | 20 | -- Mail : kaveh.mohamadabadi@gmail.com |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | /// \defgroup PWM |
|
23 | 23 | /*! \file pwm.h |
|
24 | 24 | \brief PWM api. |
|
25 | 25 | |
|
26 | 26 | The pwm api gives you a standard way to drive any pwm pin on any processor. |
|
27 | 27 | With this api you will be able to open and configure your PWM module, define the |
|
28 | 28 | associated pins when applicable and set the duty cycle and frequency. Note that depending |
|
29 | 29 | on the target architecture you can have soft or hard PWM. |
|
30 | 30 | |
|
31 | 31 | A simple example to configure and use PWM4_CH4 on STM32 discovery for example. |
|
32 | 32 | \code |
|
33 | 33 | // lets open PWM4_CH4 |
|
34 | 34 | //config : |
|
35 | 35 | // -TIMER = TIMER4 (PWM4=TIMER4) |
|
36 | 36 | // -PWM channel = 4 |
|
37 | 37 | // -PWM output = PD15 |
|
38 | 38 | // -PWM frequency = 1kHz |
|
39 | 39 | // -PWM duty cycle = 40.5% |
|
40 | 40 | pwmopen(PWM4_CH4,PD15); |
|
41 | 41 | int error = pwmsetconfig(PWM4_CH4,1000,40.5); |
|
42 | 42 | //check that everything is ok |
|
43 | 43 | if(error!=-1) //=> no error |
|
44 | 44 | { |
|
45 | 45 | //to change duty cycle to 15% for example: |
|
46 | 46 | pwmsetdutycycle(PWM4_CH4,15.0); |
|
47 | 47 | //you can also change the frequency: |
|
48 | 48 | pwmsetfrequency(PWM4_CH4,455000); |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | \endcode |
|
52 | 52 | \ingroup PWM |
|
53 | 53 | |
|
54 | 54 | */ |
|
55 | 55 | #ifndef PWM_H |
|
56 | 56 | #define PWM_H |
|
57 | 57 | |
|
58 | 58 | #include <stdint.h> |
|
59 | 59 | #ifdef __cplusplus |
|
60 | 60 | extern "C" { |
|
61 | 61 | #endif |
|
62 | 62 | /** |
|
63 | 63 | * @brief PWM open function |
|
64 | 64 | * |
|
65 | 65 | * This function opens the given PWM, it should turn it ON iff needed and enable it. |
|
66 | 66 | * @param PWM The PWM module and channel PWM1_CH6 for example |
|
67 | 67 | * @return The 0 on success or -1 if it fails. |
|
68 | 68 | * @ingroup PWM |
|
69 | 69 | */ |
|
70 | 70 | extern int pwmopen(int PWM,uint32_t pin); |
|
71 | 71 | extern int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle); |
|
72 | 72 | extern int pwmsetdutycycle(int PWM,float dutyCycle); |
|
73 | 73 | extern int pwmsetfrequency(int PWM,uint32_t freq); |
|
74 | 74 | |
|
75 | 75 | #ifdef __cplusplus |
|
76 | 76 | } |
|
77 | 77 | #endif |
|
78 | 78 | |
|
79 | 79 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
|
80 | #define UARTPARITYMASK 0x3 | |
|
81 | #define UARTBITSMASK 0xC | |
|
82 | #define UARTSTOPBITSMASK 0x70 | |
|
83 | 80 | |
|
84 | 81 | typedef enum |
|
85 | 82 | { |
|
86 | 83 | channel1 = 0, |
|
87 | 84 | channel2 = 1, |
|
88 | 85 | channel3 = 2, |
|
89 | 86 | channel4 = 3, |
|
90 | 87 | }channelx; |
|
91 | 88 | |
|
92 | 89 | #define PWM1_CH1 ((0 << 8) + 0 ) |
|
93 | 90 | #define PWM1_CH2 ((0 << 8) + 1 ) |
|
94 | 91 | #define PWM1_CH3 ((0 << 8) + 2 ) |
|
95 | 92 | #define PWM1_CH4 ((0 << 8) + 3 ) |
|
96 | 93 | #define PWM1_CH5 ((0 << 8) + 4 ) |
|
97 | 94 | #define PWM1_CH6 ((0 << 8) + 5 ) |
|
98 | 95 | #define PWM1_CH7 ((0 << 8) + 6 ) |
|
99 | 96 | #define PWM1_CH8 ((0 << 8) + 7 ) |
|
100 | 97 | #define PWM1_CH9 ((0 << 8) + 8 ) |
|
101 | 98 | #define PWM1_CH10 ((0 << 8) + 9 ) |
|
102 | 99 | #define PWM1_CH11 ((0 << 8) + 10 ) |
|
103 | 100 | #define PWM1_CH12 ((0 << 8) + 11 ) |
|
104 | 101 | #define PWM1_CH13 ((0 << 8) + 12 ) |
|
105 | 102 | #define PWM1_CH14 ((0 << 8) + 13 ) |
|
106 | 103 | #define PWM1_CH15 ((0 << 8) + 14 ) |
|
107 | 104 | #define PWM1_CH16 ((0 << 8) + 15 ) |
|
108 | 105 | #define PWM2_CH1 ((1 << 8) + 0 ) |
|
109 | 106 | #define PWM2_CH2 ((1 << 8) + 1 ) |
|
110 | 107 | #define PWM2_CH3 ((1 << 8) + 2 ) |
|
111 | 108 | #define PWM2_CH4 ((1 << 8) + 3 ) |
|
112 | 109 | #define PWM2_CH5 ((1 << 8) + 4 ) |
|
113 | 110 | #define PWM2_CH6 ((1 << 8) + 5 ) |
|
114 | 111 | #define PWM2_CH7 ((1 << 8) + 6 ) |
|
115 | 112 | #define PWM2_CH8 ((1 << 8) + 7 ) |
|
116 | 113 | #define PWM2_CH9 ((1 << 8) + 8 ) |
|
117 | 114 | #define PWM2_CH10 ((1 << 8) + 9 ) |
|
118 | 115 | #define PWM2_CH11 ((1 << 8) + 10 ) |
|
119 | 116 | #define PWM2_CH12 ((1 << 8) + 11 ) |
|
120 | 117 | #define PWM2_CH13 ((1 << 8) + 12 ) |
|
121 | 118 | #define PWM2_CH14 ((1 << 8) + 13 ) |
|
122 | 119 | #define PWM2_CH15 ((1 << 8) + 14 ) |
|
123 | 120 | #define PWM2_CH16 ((1 << 8) + 15 ) |
|
124 | 121 | #define PWM3_CH1 ((2 << 8) + 0 ) |
|
125 | 122 | #define PWM3_CH2 ((2 << 8) + 1 ) |
|
126 | 123 | #define PWM3_CH3 ((2 << 8) + 2 ) |
|
127 | 124 | #define PWM3_CH4 ((2 << 8) + 3 ) |
|
128 | 125 | #define PWM3_CH5 ((2 << 8) + 4 ) |
|
129 | 126 | #define PWM3_CH6 ((2 << 8) + 5 ) |
|
130 | 127 | #define PWM3_CH7 ((2 << 8) + 6 ) |
|
131 | 128 | #define PWM3_CH8 ((2 << 8) + 7 ) |
|
132 | 129 | #define PWM3_CH9 ((2 << 8) + 8 ) |
|
133 | 130 | #define PWM3_CH10 ((2 << 8) + 9 ) |
|
134 | 131 | #define PWM3_CH11 ((2 << 8) + 10 ) |
|
135 | 132 | #define PWM3_CH12 ((2 << 8) + 11 ) |
|
136 | 133 | #define PWM3_CH13 ((2 << 8) + 12 ) |
|
137 | 134 | #define PWM3_CH14 ((2 << 8) + 13 ) |
|
138 | 135 | #define PWM3_CH15 ((2 << 8) + 14 ) |
|
139 | 136 | #define PWM3_CH16 ((2 << 8) + 15 ) |
|
140 | 137 | #define PWM4_CH1 ((3 << 8) + 0 ) |
|
141 | 138 | #define PWM4_CH2 ((3 << 8) + 1 ) |
|
142 | 139 | #define PWM4_CH3 ((3 << 8) + 2 ) |
|
143 | 140 | #define PWM4_CH4 ((3 << 8) + 3 ) |
|
144 | 141 | #define PWM4_CH5 ((3 << 8) + 4 ) |
|
145 | 142 | #define PWM4_CH6 ((3 << 8) + 5 ) |
|
146 | 143 | #define PWM4_CH7 ((3 << 8) + 6 ) |
|
147 | 144 | #define PWM4_CH8 ((3 << 8) + 7 ) |
|
148 | 145 | #define PWM4_CH9 ((3 << 8) + 8 ) |
|
149 | 146 | #define PWM4_CH10 ((3 << 8) + 9 ) |
|
150 | 147 | #define PWM4_CH11 ((3 << 8) + 10 ) |
|
151 | 148 | #define PWM4_CH12 ((3 << 8) + 11 ) |
|
152 | 149 | #define PWM4_CH13 ((3 << 8) + 12 ) |
|
153 | 150 | #define PWM4_CH14 ((3 << 8) + 13 ) |
|
154 | 151 | #define PWM4_CH15 ((3 << 8) + 14 ) |
|
155 | 152 | #define PWM4_CH16 ((3 << 8) + 15 ) |
|
156 | 153 | #define PWM5_CH1 ((4 << 8) + 0 ) |
|
157 | 154 | #define PWM5_CH2 ((4 << 8) + 1 ) |
|
158 | 155 | #define PWM5_CH3 ((4 << 8) + 2 ) |
|
159 | 156 | #define PWM5_CH4 ((4 << 8) + 3 ) |
|
160 | 157 | #define PWM5_CH5 ((4 << 8) + 4 ) |
|
161 | 158 | #define PWM5_CH6 ((4 << 8) + 5 ) |
|
162 | 159 | #define PWM5_CH7 ((4 << 8) + 6 ) |
|
163 | 160 | #define PWM5_CH8 ((4 << 8) + 7 ) |
|
164 | 161 | #define PWM5_CH9 ((4 << 8) + 8 ) |
|
165 | 162 | #define PWM5_CH10 ((4 << 8) + 9 ) |
|
166 | 163 | #define PWM5_CH11 ((4 << 8) + 10 ) |
|
167 | 164 | #define PWM5_CH12 ((4 << 8) + 11 ) |
|
168 | 165 | #define PWM5_CH13 ((4 << 8) + 12 ) |
|
169 | 166 | #define PWM5_CH14 ((4 << 8) + 13 ) |
|
170 | 167 | #define PWM5_CH15 ((4 << 8) + 14 ) |
|
171 | 168 | #define PWM5_CH16 ((4 << 8) + 15 ) |
|
172 | 169 | #define PWM6_CH1 ((5 << 8) + 0 ) |
|
173 | 170 | #define PWM6_CH2 ((5 << 8) + 1 ) |
|
174 | 171 | #define PWM6_CH3 ((5 << 8) + 2 ) |
|
175 | 172 | #define PWM6_CH4 ((5 << 8) + 3 ) |
|
176 | 173 | #define PWM6_CH5 ((5 << 8) + 4 ) |
|
177 | 174 | #define PWM6_CH6 ((5 << 8) + 5 ) |
|
178 | 175 | #define PWM6_CH7 ((5 << 8) + 6 ) |
|
179 | 176 | #define PWM6_CH8 ((5 << 8) + 7 ) |
|
180 | 177 | #define PWM6_CH9 ((5 << 8) + 8 ) |
|
181 | 178 | #define PWM6_CH10 ((5 << 8) + 9 ) |
|
182 | 179 | #define PWM6_CH11 ((5 << 8) + 10 ) |
|
183 | 180 | #define PWM6_CH12 ((5 << 8) + 11 ) |
|
184 | 181 | #define PWM6_CH13 ((5 << 8) + 12 ) |
|
185 | 182 | #define PWM6_CH14 ((5 << 8) + 13 ) |
|
186 | 183 | #define PWM6_CH15 ((5 << 8) + 14 ) |
|
187 | 184 | #define PWM6_CH16 ((5 << 8) + 15 ) |
|
188 | 185 | #define PWM7_CH1 ((6 << 8) + 0 ) |
|
189 | 186 | #define PWM7_CH2 ((6 << 8) + 1 ) |
|
190 | 187 | #define PWM7_CH3 ((6 << 8) + 2 ) |
|
191 | 188 | #define PWM7_CH4 ((6 << 8) + 3 ) |
|
192 | 189 | #define PWM7_CH5 ((6 << 8) + 4 ) |
|
193 | 190 | #define PWM7_CH6 ((6 << 8) + 5 ) |
|
194 | 191 | #define PWM7_CH7 ((6 << 8) + 6 ) |
|
195 | 192 | #define PWM7_CH8 ((6 << 8) + 7 ) |
|
196 | 193 | #define PWM7_CH9 ((6 << 8) + 8 ) |
|
197 | 194 | #define PWM7_CH10 ((6 << 8) + 9 ) |
|
198 | 195 | #define PWM7_CH11 ((6 << 8) + 10 ) |
|
199 | 196 | #define PWM7_CH12 ((6 << 8) + 11 ) |
|
200 | 197 | #define PWM7_CH13 ((6 << 8) + 12 ) |
|
201 | 198 | #define PWM7_CH14 ((6 << 8) + 13 ) |
|
202 | 199 | #define PWM7_CH15 ((6 << 8) + 14 ) |
|
203 | 200 | #define PWM7_CH16 ((6 << 8) + 15 ) |
|
204 | 201 | #define PWM8_CH1 ((7 << 8) + 0 ) |
|
205 | 202 | #define PWM8_CH2 ((7 << 8) + 1 ) |
|
206 | 203 | #define PWM8_CH3 ((7 << 8) + 2 ) |
|
207 | 204 | #define PWM8_CH4 ((7 << 8) + 3 ) |
|
208 | 205 | #define PWM8_CH5 ((7 << 8) + 4 ) |
|
209 | 206 | #define PWM8_CH6 ((7 << 8) + 5 ) |
|
210 | 207 | #define PWM8_CH7 ((7 << 8) + 6 ) |
|
211 | 208 | #define PWM8_CH8 ((7 << 8) + 7 ) |
|
212 | 209 | #define PWM8_CH9 ((7 << 8) + 8 ) |
|
213 | 210 | #define PWM8_CH10 ((7 << 8) + 9 ) |
|
214 | 211 | #define PWM8_CH11 ((7 << 8) + 10 ) |
|
215 | 212 | #define PWM8_CH12 ((7 << 8) + 11 ) |
|
216 | 213 | #define PWM8_CH13 ((7 << 8) + 12 ) |
|
217 | 214 | #define PWM8_CH14 ((7 << 8) + 13 ) |
|
218 | 215 | #define PWM8_CH15 ((7 << 8) + 14 ) |
|
219 | 216 | #define PWM8_CH16 ((7 << 8) + 15 ) |
|
220 | 217 | #define PWM9_CH1 ((8 << 8) + 0 ) |
|
221 | 218 | #define PWM9_CH2 ((8 << 8) + 1 ) |
|
222 | 219 | #define PWM9_CH3 ((8 << 8) + 2 ) |
|
223 | 220 | #define PWM9_CH4 ((8 << 8) + 3 ) |
|
224 | 221 | #define PWM9_CH5 ((8 << 8) + 4 ) |
|
225 | 222 | #define PWM9_CH6 ((8 << 8) + 5 ) |
|
226 | 223 | #define PWM9_CH7 ((8 << 8) + 6 ) |
|
227 | 224 | #define PWM9_CH8 ((8 << 8) + 7 ) |
|
228 | 225 | #define PWM9_CH9 ((8 << 8) + 8 ) |
|
229 | 226 | #define PWM9_CH10 ((8 << 8) + 9 ) |
|
230 | 227 | #define PWM9_CH11 ((8 << 8) + 10 ) |
|
231 | 228 | #define PWM9_CH12 ((8 << 8) + 11 ) |
|
232 | 229 | #define PWM9_CH13 ((8 << 8) + 12 ) |
|
233 | 230 | #define PWM9_CH14 ((8 << 8) + 13 ) |
|
234 | 231 | #define PWM9_CH15 ((8 << 8) + 14 ) |
|
235 | 232 | #define PWM9_CH16 ((8 << 8) + 15 ) |
|
236 | 233 | #define PWM10_CH1 ((9 << 8) + 0 ) |
|
237 | 234 | #define PWM10_CH2 ((9 << 8) + 1 ) |
|
238 | 235 | #define PWM10_CH3 ((9 << 8) + 2 ) |
|
239 | 236 | #define PWM10_CH4 ((9 << 8) + 3 ) |
|
240 | 237 | #define PWM10_CH5 ((9 << 8) + 4 ) |
|
241 | 238 | #define PWM10_CH6 ((9 << 8) + 5 ) |
|
242 | 239 | #define PWM10_CH7 ((9 << 8) + 6 ) |
|
243 | 240 | #define PWM10_CH8 ((9 << 8) + 7 ) |
|
244 | 241 | #define PWM10_CH9 ((9 << 8) + 8 ) |
|
245 | 242 | #define PWM10_CH10 ((9 << 8) + 9 ) |
|
246 | 243 | #define PWM10_CH11 ((9 << 8) + 10 ) |
|
247 | 244 | #define PWM10_CH12 ((9 << 8) + 11 ) |
|
248 | 245 | #define PWM10_CH13 ((9 << 8) + 12 ) |
|
249 | 246 | #define PWM10_CH14 ((9 << 8) + 13 ) |
|
250 | 247 | #define PWM10_CH15 ((9 << 8) + 14 ) |
|
251 | 248 | #define PWM10_CH16 ((9 << 8) + 15 ) |
|
252 | 249 | #define PWM11_CH1 ((10 << 8) + 0 ) |
|
253 | 250 | #define PWM11_CH2 ((10 << 8) + 1 ) |
|
254 | 251 | #define PWM11_CH3 ((10 << 8) + 2 ) |
|
255 | 252 | #define PWM11_CH4 ((10 << 8) + 3 ) |
|
256 | 253 | #define PWM11_CH5 ((10 << 8) + 4 ) |
|
257 | 254 | #define PWM11_CH6 ((10 << 8) + 5 ) |
|
258 | 255 | #define PWM11_CH7 ((10 << 8) + 6 ) |
|
259 | 256 | #define PWM11_CH8 ((10 << 8) + 7 ) |
|
260 | 257 | #define PWM11_CH9 ((10 << 8) + 8 ) |
|
261 | 258 | #define PWM11_CH10 ((10 << 8) + 9 ) |
|
262 | 259 | #define PWM11_CH11 ((10 << 8) + 10 ) |
|
263 | 260 | #define PWM11_CH12 ((10 << 8) + 11 ) |
|
264 | 261 | #define PWM11_CH13 ((10 << 8) + 12 ) |
|
265 | 262 | #define PWM11_CH14 ((10 << 8) + 13 ) |
|
266 | 263 | #define PWM11_CH15 ((10 << 8) + 14 ) |
|
267 | 264 | #define PWM11_CH16 ((10 << 8) + 15 ) |
|
268 | 265 | #define PWM12_CH1 ((11 << 8) + 0 ) |
|
269 | 266 | #define PWM12_CH2 ((11 << 8) + 1 ) |
|
270 | 267 | #define PWM12_CH3 ((11 << 8) + 2 ) |
|
271 | 268 | #define PWM12_CH4 ((11 << 8) + 3 ) |
|
272 | 269 | #define PWM12_CH5 ((11 << 8) + 4 ) |
|
273 | 270 | #define PWM12_CH6 ((11 << 8) + 5 ) |
|
274 | 271 | #define PWM12_CH7 ((11 << 8) + 6 ) |
|
275 | 272 | #define PWM12_CH8 ((11 << 8) + 7 ) |
|
276 | 273 | #define PWM12_CH9 ((11 << 8) + 8 ) |
|
277 | 274 | #define PWM12_CH10 ((11 << 8) + 9 ) |
|
278 | 275 | #define PWM12_CH11 ((11 << 8) + 10 ) |
|
279 | 276 | #define PWM12_CH12 ((11 << 8) + 11 ) |
|
280 | 277 | #define PWM12_CH13 ((11 << 8) + 12 ) |
|
281 | 278 | #define PWM12_CH14 ((11 << 8) + 13 ) |
|
282 | 279 | #define PWM12_CH15 ((11 << 8) + 14 ) |
|
283 | 280 | #define PWM12_CH16 ((11 << 8) + 15 ) |
|
284 | 281 | #define PWM13_CH1 ((12 << 8) + 0 ) |
|
285 | 282 | #define PWM13_CH2 ((12 << 8) + 1 ) |
|
286 | 283 | #define PWM13_CH3 ((12 << 8) + 2 ) |
|
287 | 284 | #define PWM13_CH4 ((12 << 8) + 3 ) |
|
288 | 285 | #define PWM13_CH5 ((12 << 8) + 4 ) |
|
289 | 286 | #define PWM13_CH6 ((12 << 8) + 5 ) |
|
290 | 287 | #define PWM13_CH7 ((12 << 8) + 6 ) |
|
291 | 288 | #define PWM13_CH8 ((12 << 8) + 7 ) |
|
292 | 289 | #define PWM13_CH9 ((12 << 8) + 8 ) |
|
293 | 290 | #define PWM13_CH10 ((12 << 8) + 9 ) |
|
294 | 291 | #define PWM13_CH11 ((12 << 8) + 10 ) |
|
295 | 292 | #define PWM13_CH12 ((12 << 8) + 11 ) |
|
296 | 293 | #define PWM13_CH13 ((12 << 8) + 12 ) |
|
297 | 294 | #define PWM13_CH14 ((12 << 8) + 13 ) |
|
298 | 295 | #define PWM13_CH15 ((12 << 8) + 14 ) |
|
299 | 296 | #define PWM13_CH16 ((12 << 8) + 15 ) |
|
300 | 297 | #define PWM14_CH1 ((13 << 8) + 0 ) |
|
301 | 298 | #define PWM14_CH2 ((13 << 8) + 1 ) |
|
302 | 299 | #define PWM14_CH3 ((13 << 8) + 2 ) |
|
303 | 300 | #define PWM14_CH4 ((13 << 8) + 3 ) |
|
304 | 301 | #define PWM14_CH5 ((13 << 8) + 4 ) |
|
305 | 302 | #define PWM14_CH6 ((13 << 8) + 5 ) |
|
306 | 303 | #define PWM14_CH7 ((13 << 8) + 6 ) |
|
307 | 304 | #define PWM14_CH8 ((13 << 8) + 7 ) |
|
308 | 305 | #define PWM14_CH9 ((13 << 8) + 8 ) |
|
309 | 306 | #define PWM14_CH10 ((13 << 8) + 9 ) |
|
310 | 307 | #define PWM14_CH11 ((13 << 8) + 10 ) |
|
311 | 308 | #define PWM14_CH12 ((13 << 8) + 11 ) |
|
312 | 309 | #define PWM14_CH13 ((13 << 8) + 12 ) |
|
313 | 310 | #define PWM14_CH14 ((13 << 8) + 13 ) |
|
314 | 311 | #define PWM14_CH15 ((13 << 8) + 14 ) |
|
315 | 312 | #define PWM14_CH16 ((13 << 8) + 15 ) |
|
316 | 313 | #define PWM15_CH1 ((14 << 8) + 0 ) |
|
317 | 314 | #define PWM15_CH2 ((14 << 8) + 1 ) |
|
318 | 315 | #define PWM15_CH3 ((14 << 8) + 2 ) |
|
319 | 316 | #define PWM15_CH4 ((14 << 8) + 3 ) |
|
320 | 317 | #define PWM15_CH5 ((14 << 8) + 4 ) |
|
321 | 318 | #define PWM15_CH6 ((14 << 8) + 5 ) |
|
322 | 319 | #define PWM15_CH7 ((14 << 8) + 6 ) |
|
323 | 320 | #define PWM15_CH8 ((14 << 8) + 7 ) |
|
324 | 321 | #define PWM15_CH9 ((14 << 8) + 8 ) |
|
325 | 322 | #define PWM15_CH10 ((14 << 8) + 9 ) |
|
326 | 323 | #define PWM15_CH11 ((14 << 8) + 10 ) |
|
327 | 324 | #define PWM15_CH12 ((14 << 8) + 11 ) |
|
328 | 325 | #define PWM15_CH13 ((14 << 8) + 12 ) |
|
329 | 326 | #define PWM15_CH14 ((14 << 8) + 13 ) |
|
330 | 327 | #define PWM15_CH15 ((14 << 8) + 14 ) |
|
331 | 328 | #define PWM15_CH16 ((14 << 8) + 15 ) |
|
332 | 329 | #define PWM16_CH1 ((15 << 8) + 0 ) |
|
333 | 330 | #define PWM16_CH2 ((15 << 8) + 1 ) |
|
334 | 331 | #define PWM16_CH3 ((15 << 8) + 2 ) |
|
335 | 332 | #define PWM16_CH4 ((15 << 8) + 3 ) |
|
336 | 333 | #define PWM16_CH5 ((15 << 8) + 4 ) |
|
337 | 334 | #define PWM16_CH6 ((15 << 8) + 5 ) |
|
338 | 335 | #define PWM16_CH7 ((15 << 8) + 6 ) |
|
339 | 336 | #define PWM16_CH8 ((15 << 8) + 7 ) |
|
340 | 337 | #define PWM16_CH9 ((15 << 8) + 8 ) |
|
341 | 338 | #define PWM16_CH10 ((15 << 8) + 9 ) |
|
342 | 339 | #define PWM16_CH11 ((15 << 8) + 10 ) |
|
343 | 340 | #define PWM16_CH12 ((15 << 8) + 11 ) |
|
344 | 341 | #define PWM16_CH13 ((15 << 8) + 12 ) |
|
345 | 342 | #define PWM16_CH14 ((15 << 8) + 13 ) |
|
346 | 343 | #define PWM16_CH15 ((15 << 8) + 14 ) |
|
347 | 344 | #define PWM16_CH16 ((15 << 8) + 15 ) |
|
348 | 345 | #endif |
|
349 | 346 | #endif // PWM_H |
@@ -1,281 +1,282 | |||
|
1 | 1 | #include <stdlib.h> |
|
2 | 2 | #include <errno.h> |
|
3 | 3 | #include <string.h> |
|
4 | 4 | #include <sys/stat.h> |
|
5 | 5 | #include <sys/types.h> |
|
6 | 6 | #include <sys/times.h> |
|
7 | 7 | #include <streamdevices.h> |
|
8 | 8 | #include <string.h> |
|
9 | 9 | #include <stdio.h> |
|
10 | 10 | #include <gpio.h> |
|
11 | 11 | #include <uart.h> |
|
12 | 12 | #include <stdint.h> |
|
13 | 13 | #include <bsp.h> |
|
14 | #include <core.h> | |
|
14 | 15 | |
|
15 | 16 | #undef errno |
|
16 | 17 | |
|
17 | 18 | |
|
18 | 19 | #ifdef __cplusplus |
|
19 | 20 | extern "C" { |
|
20 | 21 | #endif |
|
21 | 22 | extern int errno; |
|
22 | 23 | extern int32_t __max_opened_files__; |
|
23 | 24 | extern streamdevice* __opnfiles__[]; |
|
24 | 25 | extern int32_t* __fs_root__; |
|
25 | 26 | extern int32_t __fs_root_size__; |
|
26 | 27 | |
|
27 | 28 | char *__env[1] = { 0 }; |
|
28 | 29 | char **environ = __env; |
|
29 | 30 | |
|
30 | 31 | int _exit() |
|
31 | 32 | { |
|
32 | 33 | while(1) |
|
33 | 34 | { |
|
34 | 35 | delay_100us(10000); |
|
35 | 36 | gpioset(LED2); |
|
36 | 37 | delay_100us(10000); |
|
37 | 38 | gpioclr(LED2); |
|
38 | 39 | } |
|
39 | 40 | } |
|
40 | 41 | |
|
41 | 42 | int _close(int file) |
|
42 | 43 | { |
|
43 | 44 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) |
|
44 | 45 | { |
|
45 | 46 | return __opnfiles__[file]->ops->close( __opnfiles__[file]); |
|
46 | 47 | } |
|
47 | 48 | return 0; |
|
48 | 49 | } |
|
49 | 50 | |
|
50 | 51 | |
|
51 | 52 | int _write(int file, char *ptr, int len) |
|
52 | 53 | { |
|
53 | 54 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) |
|
54 | 55 | { |
|
55 | 56 | if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len; |
|
56 | 57 | } |
|
57 | 58 | return len; |
|
58 | 59 | } |
|
59 | 60 | |
|
60 | 61 | int _execve(char *name, char **argv, char **env) { |
|
61 | 62 | errno = ENOMEM; |
|
62 | 63 | return -1; |
|
63 | 64 | } |
|
64 | 65 | |
|
65 | 66 | |
|
66 | 67 | int _fork(void) { |
|
67 | 68 | errno = EAGAIN; |
|
68 | 69 | return -1; |
|
69 | 70 | } |
|
70 | 71 | |
|
71 | 72 | int _fstat(int file, struct stat *st) { |
|
72 | 73 | st->st_mode = S_IFCHR; |
|
73 | 74 | return 0; |
|
74 | 75 | } |
|
75 | 76 | |
|
76 | 77 | |
|
77 | 78 | int _getpid(void) { |
|
78 | 79 | return 1; |
|
79 | 80 | } |
|
80 | 81 | |
|
81 | 82 | |
|
82 | 83 | int _isatty(int file) { |
|
83 | 84 | return 1; |
|
84 | 85 | } |
|
85 | 86 | |
|
86 | 87 | |
|
87 | 88 | int _kill(int pid, int sig) { |
|
88 | 89 | errno = EINVAL; |
|
89 | 90 | return -1; |
|
90 | 91 | } |
|
91 | 92 | |
|
92 | 93 | |
|
93 | 94 | int _link(char *old, char *_new) { |
|
94 | 95 | errno = EMLINK; |
|
95 | 96 | return -1; |
|
96 | 97 | } |
|
97 | 98 | |
|
98 | 99 | |
|
99 | 100 | int _lseek(int file, int ptr, int dir) { |
|
100 | 101 | return 0; |
|
101 | 102 | } |
|
102 | 103 | |
|
103 | 104 | #include <gpio.h> |
|
104 | 105 | |
|
105 | 106 | int _open(const char *name, int flags, int mode) |
|
106 | 107 | { |
|
107 | 108 | if(!strncmp("UART", name, 4) && ((name[4] & 0x30)==0x30)) |
|
108 | 109 | { |
|
109 | 110 | //uart_t* uart1 = malloc(sizeof(uart_t)); |
|
110 | 111 | streamdevice* fd1 = malloc(sizeof(streamdevice)); |
|
111 | 112 | uart_t uart=uartopen((name[4] & 0xF)-1); |
|
112 | 113 | if(uart!=-1); |
|
113 | 114 | { |
|
114 | 115 | uartmkstreamdev(uart,fd1); |
|
115 | 116 | int i=2; |
|
116 | 117 | while((i<__max_opened_files__) && (__opnfiles__[i]!=NULL))i++; |
|
117 | 118 | if(i!=__max_opened_files__) |
|
118 | 119 | { |
|
119 | 120 | __opnfiles__[i] = fd1; |
|
120 | 121 | return i; |
|
121 | 122 | } |
|
122 | 123 | else printf("Too much files opened\n\r"); |
|
123 | 124 | } |
|
124 | 125 | } |
|
125 | 126 | return -1; |
|
126 | 127 | } |
|
127 | 128 | |
|
128 | 129 | int _read(int file, char *ptr, int len) { |
|
129 | 130 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) |
|
130 | 131 | { |
|
131 | 132 | if(__opnfiles__[file]->ops->read(__opnfiles__[file],ptr,1,len)) return len; |
|
132 | 133 | } |
|
133 | 134 | return 0; |
|
134 | 135 | } |
|
135 | 136 | |
|
136 | 137 | |
|
137 | 138 | |
|
138 | 139 | caddr_t _sbrk(int incr) { |
|
139 | 140 | register char * stack_ptr __asm__ ("sp"); |
|
140 | 141 | extern char end; /* Defined by the linker */ |
|
141 | 142 | static char *heap_end; |
|
142 | 143 | char *prev_heap_end; |
|
143 | 144 | if (heap_end == 0) { |
|
144 | 145 | heap_end = &end; |
|
145 | 146 | } |
|
146 | 147 | prev_heap_end = heap_end; |
|
147 | 148 | if (heap_end + incr > stack_ptr) { |
|
148 | 149 | printf("Heap and stack collision\n"); |
|
149 | 150 | //abort (); |
|
150 | 151 | while(1) |
|
151 | 152 | { |
|
152 | 153 | delay_100us(10000); |
|
153 | 154 | gpioset(LED2); |
|
154 | 155 | delay_100us(10000); |
|
155 | 156 | gpioclr(LED2); |
|
156 | 157 | } |
|
157 | 158 | } |
|
158 | 159 | heap_end += incr; |
|
159 | 160 | return (caddr_t) prev_heap_end; |
|
160 | 161 | } |
|
161 | 162 | |
|
162 | 163 | |
|
163 | 164 | |
|
164 | 165 | int _stat(char *file, struct stat *st) { |
|
165 | 166 | st->st_mode = S_IFCHR; |
|
166 | 167 | return 0; |
|
167 | 168 | } |
|
168 | 169 | |
|
169 | 170 | |
|
170 | 171 | int _times(struct tms *buf) { |
|
171 | 172 | return -1; |
|
172 | 173 | } |
|
173 | 174 | |
|
174 | 175 | |
|
175 | 176 | int _unlink(char *name) { |
|
176 | 177 | errno = ENOENT; |
|
177 | 178 | return -1; |
|
178 | 179 | } |
|
179 | 180 | |
|
180 | 181 | int _wait(int *status) { |
|
181 | 182 | errno = ECHILD; |
|
182 | 183 | return -1; |
|
183 | 184 | } |
|
184 | 185 | |
|
185 | 186 | |
|
186 | 187 | int _read_r (struct _reent *r, int file, char * ptr, int len) |
|
187 | 188 | { |
|
188 | 189 | r = r; |
|
189 | 190 | file = file; |
|
190 | 191 | ptr = ptr; |
|
191 | 192 | len = len; |
|
192 | 193 | _read(file,ptr,len); |
|
193 | 194 | errno = EINVAL; |
|
194 | 195 | return -1; |
|
195 | 196 | } |
|
196 | 197 | |
|
197 | 198 | /***************************************************************************/ |
|
198 | 199 | |
|
199 | 200 | int _lseek_r (struct _reent *r, int file, int ptr, int dir) |
|
200 | 201 | { |
|
201 | 202 | r = r; |
|
202 | 203 | file = file; |
|
203 | 204 | ptr = ptr; |
|
204 | 205 | dir = dir; |
|
205 | 206 | |
|
206 | 207 | return 0; |
|
207 | 208 | } |
|
208 | 209 | |
|
209 | 210 | /***************************************************************************/ |
|
210 | 211 | |
|
211 | 212 | int _write_r (struct _reent *r, int file, char * ptr, int len) |
|
212 | 213 | { |
|
213 | 214 | return _write(file, ptr, len); |
|
214 | 215 | } |
|
215 | 216 | |
|
216 | 217 | /***************************************************************************/ |
|
217 | 218 | |
|
218 | 219 | int _close_r (struct _reent *r, int file) |
|
219 | 220 | { |
|
220 | 221 | return 0; |
|
221 | 222 | } |
|
222 | 223 | |
|
223 | 224 | /***************************************************************************/ |
|
224 | 225 | |
|
225 | 226 | caddr_t _sbrk_r (struct _reent *r, int incr) |
|
226 | 227 | { |
|
227 | 228 | register char * stack_ptr __asm__ ("sp"); |
|
228 | 229 | extern char end; /* Defined by the linker */ |
|
229 | 230 | static char *heap_end; |
|
230 | 231 | char *prev_heap_end; |
|
231 | 232 | if (heap_end == 0) { |
|
232 | 233 | heap_end = &end; |
|
233 | 234 | } |
|
234 | 235 | prev_heap_end = heap_end; |
|
235 | 236 | if (heap_end + incr > stack_ptr) { |
|
236 | 237 | printf( "Heap and stack collision\n"); |
|
237 | 238 | //abort (); |
|
238 | 239 | while(1) |
|
239 | 240 | { |
|
240 | 241 | delay_100us(10000); |
|
241 | 242 | gpioset(LED2); |
|
242 | 243 | delay_100us(10000); |
|
243 | 244 | gpioclr(LED2); |
|
244 | 245 | } |
|
245 | 246 | } |
|
246 | 247 | heap_end += incr; |
|
247 | 248 | return (caddr_t) prev_heap_end; |
|
248 | 249 | } |
|
249 | 250 | |
|
250 | 251 | /***************************************************************************/ |
|
251 | 252 | |
|
252 | 253 | int _fstat_r (struct _reent *r, int file, struct stat * st) |
|
253 | 254 | { |
|
254 | 255 | r = r; |
|
255 | 256 | file = file; |
|
256 | 257 | |
|
257 | 258 | memset (st, 0, sizeof (* st)); |
|
258 | 259 | st->st_mode = S_IFCHR; |
|
259 | 260 | return 0; |
|
260 | 261 | } |
|
261 | 262 | |
|
262 | 263 | /***************************************************************************/ |
|
263 | 264 | int _open_r(struct _reent *r,const char *name, int flags, int mode) |
|
264 | 265 | { |
|
265 | 266 | return _open(name, flags, mode); |
|
266 | 267 | } |
|
267 | 268 | |
|
268 | 269 | int _isatty_r(struct _reent *r, int fd) |
|
269 | 270 | { |
|
270 | 271 | r = r; |
|
271 | 272 | fd = fd; |
|
272 | 273 | |
|
273 | 274 | return 1; |
|
274 | 275 | } |
|
275 | 276 | |
|
276 | 277 | |
|
277 | 278 | #ifdef __cplusplus |
|
278 | 279 | } |
|
279 | 280 | #endif |
|
280 | 281 | |
|
281 | 282 |
@@ -1,127 +1,118 | |||
|
1 | 1 | #include <stdio.h> |
|
2 |
|
|
|
2 | #include <timer.h> | |
|
3 | 3 | #include <stm32f4xx_rcc.h> |
|
4 | 4 | #include <stm32f4xx_tim.h> |
|
5 | 5 | #include <stm32f4xx_dac.h> |
|
6 | 6 | #include <stm32f4xx_gpio.h> |
|
7 | 7 | #include <stm32f4xx_dma.h> |
|
8 | 8 | #include <stm32f4xx.h> |
|
9 | 9 | #include <gpio.h> |
|
10 | 10 | #include <stm32f4xx.h> |
|
11 | #include <dac.h> | |
|
11 | 12 | |
|
12 | 13 | |
|
13 | 14 | #define DAC_DHR12R2_ADDRESS 0x40007414 |
|
14 | 15 | #define DAC_DHR8R1_ADDRESS 0x40007410 |
|
15 | 16 | |
|
16 | #define DAC1_12bit_right_align 0x40007408 | |
|
17 | #define DAC1_12bit_left_align 0x4000740C | |
|
18 | #define DAC1_8bit_right_align 0x40007410 | |
|
19 | #define DAC2_12bit_right_align 0x40007414 | |
|
20 | #define DAC2_12bit_left_align 0x40007418 | |
|
21 | #define DAC2_8bit_right_align 0x4000741C | |
|
22 | #define DAC_Dual_12bit_right_align 0x40007420 | |
|
23 | #define DAC_Dual_12bit_left_align 0x40007424 | |
|
24 | #define DAC_Dual_8bit_right_align 0x40007428 | |
|
25 | #define DAC_Dual_8bit_left_align 0x4000742C | |
|
26 | ||
|
27 | ||
|
28 | 17 | |
|
29 | 18 | const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, |
|
30 | 19 | TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; |
|
31 | #define DAC1 0 | |
|
32 | #define DAC2 1 | |
|
33 | 20 | |
|
34 | #define timer2 1 | |
|
35 | #define timer3 2 | |
|
36 | #define timer4 3 | |
|
37 | #define timer5 4 | |
|
38 | #define timer6 5 | |
|
39 | #define timer7 6 | |
|
40 | #define timer8 7 | |
|
41 | 21 | |
|
42 | DAC_InitTypeDef DAC_InitStructure; | |
|
43 | 22 | |
|
44 | 23 | int dacopen(uint32_t pin) |
|
45 | 24 | { |
|
46 | 25 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
47 | 26 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
48 | 27 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 , ENABLE); |
|
49 | 28 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); |
|
50 | 29 | gpio_t DACOUT; |
|
51 | 30 | DACOUT = gpioopen(pin); |
|
52 | 31 | DACOUT |= gpioan | gpionopulltype; |
|
53 | 32 | gpiosetconfig(&DACOUT); |
|
54 | 33 | return 0; |
|
55 | 34 | } |
|
56 | 35 | |
|
57 |
int dacsetconfig(int timer, int buffer_size, int dac,uint32_t dac_type, uint32_t |
|
|
36 | int dacsetconfig(int timer, int buffer_size, int dac, uint32_t dac_type, uint32_t samplingFreq, void *data) | |
|
58 | 37 | { |
|
59 | TIM_TypeDef* tim = _timer_dev_table[timer]; | |
|
38 | #include <core.h> | |
|
39 | DAC_InitTypeDef DAC_InitStructure; | |
|
40 | TIM_TypeDef* tim = (TIM_TypeDef*)_timer_dev_table[timer]; | |
|
60 | 41 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
|
42 | DMA_InitTypeDef DMA_InitStructure; | |
|
61 | 43 | if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE); |
|
62 | 44 | if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); |
|
63 |
uint32_t timfreq = ( |
|
|
45 | uint32_t timfreq = getCpuFreq()/2; | |
|
46 | uint32_t period = timfreq/samplingFreq - 1; | |
|
47 | uint16_t PrescalerValue=0; | |
|
48 | while (period>=0x0FFFF) | |
|
49 | { | |
|
50 | PrescalerValue++; | |
|
51 | timfreq = getCpuFreq()/(2*(PrescalerValue+1)); | |
|
52 | period = (timfreq/samplingFreq) - 1; | |
|
53 | } | |
|
54 | printf("period = %d \n\r prescaler = %d \n\r",period,PrescalerValue); | |
|
64 | 55 | TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); |
|
65 |
TIM_TimeBaseStructure.TIM_Period = |
|
|
56 | TIM_TimeBaseStructure.TIM_Period = 10; | |
|
66 | 57 | TIM_TimeBaseStructure.TIM_Prescaler = 0; |
|
67 |
TIM_TimeBaseStructure.TIM_ClockDivision = |
|
|
58 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; | |
|
68 | 59 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
|
69 | 60 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); |
|
70 | 61 | TIM_SelectOutputTrigger(tim, TIM_TRGOSource_Update); |
|
62 | TIM_ARRPreloadConfig(tim, ENABLE); | |
|
71 | 63 | TIM_Cmd(tim, ENABLE); |
|
72 | 64 | |
|
73 | DMA_InitTypeDef DMA_InitStructure; | |
|
74 | 65 | if (timer == timer2)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; |
|
75 | 66 | if (timer == timer4)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T4_TRGO; |
|
76 | 67 | if (timer == timer5)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T5_TRGO; |
|
77 | 68 | if (timer == timer6)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; |
|
78 | 69 | if (timer == timer7)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T7_TRGO; |
|
79 | 70 | if (timer == timer8)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T8_TRGO; |
|
80 | 71 | DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; |
|
81 | 72 | DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; |
|
82 | 73 | if (dac == DAC1){ |
|
83 | 74 | DAC_Init(DAC_Channel_1, &DAC_InitStructure); |
|
84 | 75 | DMA_DeInit(DMA1_Stream5); |
|
85 | 76 | } |
|
86 | 77 | |
|
87 | 78 | if (dac == DAC2){ |
|
88 | 79 | DAC_Init(DAC_Channel_2, &DAC_InitStructure); |
|
89 | 80 | DMA_DeInit(DMA1_Stream6); |
|
90 | 81 | } |
|
91 | 82 | |
|
92 | 83 | DMA_InitStructure.DMA_Channel = DMA_Channel_7; |
|
93 | 84 | DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)dac_type; |
|
94 | 85 | DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)data; |
|
95 | 86 | DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; |
|
96 | 87 | DMA_InitStructure.DMA_BufferSize = buffer_size; |
|
97 | 88 | DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; |
|
98 | 89 | DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; |
|
99 | 90 | DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; |
|
100 | 91 | DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; |
|
101 | 92 | DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; |
|
102 | 93 | DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; |
|
103 | 94 | DMA_InitStructure.DMA_Priority = DMA_Priority_High; |
|
104 | 95 | DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; |
|
105 | 96 | DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; |
|
106 | 97 | DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; |
|
107 | 98 | DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; |
|
108 | 99 | |
|
109 | 100 | if (dac == DAC1){ |
|
110 | 101 | DMA_Init(DMA1_Stream5, &DMA_InitStructure); |
|
111 | 102 | DMA_Cmd(DMA1_Stream5, ENABLE); |
|
112 | 103 | DAC_DMACmd(DAC_Channel_1, ENABLE); |
|
113 | 104 | DAC_Cmd(DAC_Channel_1, ENABLE); |
|
114 | 105 | |
|
115 | 106 | } |
|
116 | 107 | if (dac == DAC2){ |
|
117 | 108 | DMA_Init(DMA1_Stream6, &DMA_InitStructure); |
|
118 | 109 | DMA_Cmd(DMA1_Stream6, ENABLE); |
|
119 | 110 | DAC_DMACmd(DAC_Channel_2, ENABLE); |
|
120 | 111 | DAC_Cmd(DAC_Channel_2, ENABLE); |
|
121 | 112 | |
|
122 | 113 | } |
|
123 | 114 | return 0; |
|
124 | 115 | |
|
125 | 116 | } |
|
126 | 117 | |
|
127 | 118 |
@@ -1,222 +1,208 | |||
|
1 | 1 | #include <pwm.h> |
|
2 | 2 | #include <stm32f4xx_tim.h> |
|
3 | 3 | #include <stm32f4xx_gpio.h> |
|
4 | 4 | #include <stm32f4xx_rcc.h> |
|
5 | 5 | #include <stm32f4xx_tim.h> |
|
6 | 6 | #include <core.h> |
|
7 | 7 | #include <gpio.h> |
|
8 | #include <timer.h> | |
|
9 | ||
|
8 | 10 | const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, |
|
9 | 11 | TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; |
|
10 | 12 | |
|
11 | #define timer1 0 | |
|
12 | #define timer2 1 | |
|
13 | #define timer3 2 | |
|
14 | #define timer4 3 | |
|
15 | #define timer5 4 | |
|
16 | #define timer6 5 | |
|
17 | #define timer7 6 | |
|
18 | #define timer8 7 | |
|
19 | #define timer9 8 | |
|
20 | #define timer10 9 | |
|
21 | #define timer11 10 | |
|
22 | #define timer12 11 | |
|
23 | #define timer13 12 | |
|
24 | #define timer14 13 | |
|
25 | #define timer15 14 | |
|
26 | #define timer16 15 | |
|
27 | 13 | |
|
28 | 14 | #define PWMGETTIMNUMBER(PWM) (((uint32_t)(PWM) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
29 | 15 | |
|
30 | 16 | int pwmopen(int PWM,uint32_t pin) |
|
31 | 17 | { |
|
32 | 18 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
33 | 19 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
34 | 20 | int timer = PWMGETTIMNUMBER(PWM); |
|
35 | 21 | gpio_t PWMOUT; |
|
36 | 22 | PWMOUT = gpioopen(pin); |
|
37 | 23 | PWMOUT |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
38 | 24 | gpiosetconfig(&PWMOUT); |
|
39 | 25 | uint8_t GPIO_AF = -1; |
|
40 | 26 | if(timer==timer1 || timer==timer2)GPIO_AF=1; |
|
41 | 27 | if(timer==timer3 || timer==timer4 || timer==timer5)GPIO_AF=2; |
|
42 | 28 | if(timer==timer8 || timer==timer9 || timer==timer10 || timer==timer11)GPIO_AF=3; |
|
43 | 29 | if(timer==timer12 || timer==timer13 || timer==timer14)GPIO_AF=9; |
|
44 | 30 | |
|
45 | 31 | if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE); |
|
46 | 32 | if(timer>=timer12 && timer <= timer14)RCC_APB1PeriphClockCmd((1<<(timer-5)), ENABLE); |
|
47 | 33 | if(timer==timer1)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); |
|
48 | 34 | if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); |
|
49 | 35 | if(timer==timer9)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE); |
|
50 | 36 | if(timer==timer10)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE); |
|
51 | 37 | if(timer==timer11)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE); |
|
52 | 38 | |
|
53 | 39 | if(GPIO_AF!=-1)GPIO_PinAFConfig(GPIOGETPORT(PWMOUT), (uint8_t)(PWMOUT & 0xF), GPIO_AF); |
|
54 | 40 | |
|
55 | 41 | return 0; |
|
56 | 42 | } |
|
57 | 43 | |
|
58 | 44 | int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle) |
|
59 | 45 | { |
|
60 | 46 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
|
61 | 47 | TIM_OCInitTypeDef TIM_OCInitStructure; |
|
62 | 48 | if(PWM==-1) return -1; |
|
63 | 49 | int timer = PWMGETTIMNUMBER(PWM); |
|
64 | 50 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
65 | 51 | uint32_t timfreq = getCpuFreq()/2; |
|
66 | 52 | uint32_t period = timfreq/freq - 1; |
|
67 | 53 | uint16_t PrescalerValue=0; |
|
68 | 54 | |
|
69 | 55 | while (period>=0x0FFFF) |
|
70 | 56 | { |
|
71 | 57 | PrescalerValue++; |
|
72 | 58 | timfreq = getCpuFreq()/(2*(PrescalerValue+1)); |
|
73 | 59 | period = (timfreq/freq) - 1; |
|
74 | 60 | } |
|
75 | 61 | |
|
76 | 62 | TIM_TimeBaseStructure.TIM_Period = period; |
|
77 | 63 | TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; |
|
78 | 64 | TIM_TimeBaseStructure.TIM_ClockDivision = 0; |
|
79 | 65 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
|
80 | 66 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); |
|
81 | 67 | |
|
82 | 68 | TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; |
|
83 | 69 | TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; |
|
84 | 70 | TIM_OCInitStructure.TIM_Pulse = (uint32_t)((period * dutyCycle)/100); |
|
85 | 71 | TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; |
|
86 | 72 | |
|
87 | 73 | switch (PWM&0x0FF) { |
|
88 | 74 | case 0: |
|
89 | 75 | TIM_OC1Init(tim, &TIM_OCInitStructure); |
|
90 | 76 | TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable); |
|
91 | 77 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
92 | 78 | TIM_Cmd(tim, ENABLE); |
|
93 | 79 | break; |
|
94 | 80 | case 1: |
|
95 | 81 | TIM_OC2Init(tim, &TIM_OCInitStructure); |
|
96 | 82 | TIM_OC2PreloadConfig(tim, TIM_OCPreload_Enable); |
|
97 | 83 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
98 | 84 | TIM_Cmd(tim, ENABLE); |
|
99 | 85 | break; |
|
100 | 86 | case 2: |
|
101 | 87 | TIM_OC3Init(tim, &TIM_OCInitStructure); |
|
102 | 88 | TIM_OC3PreloadConfig(tim, TIM_OCPreload_Enable); |
|
103 | 89 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
104 | 90 | TIM_Cmd(tim, ENABLE); |
|
105 | 91 | break; |
|
106 | 92 | case 3: |
|
107 | 93 | TIM_OC4Init(tim, &TIM_OCInitStructure); |
|
108 | 94 | TIM_OC4PreloadConfig(tim, TIM_OCPreload_Enable); |
|
109 | 95 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
110 | 96 | TIM_Cmd(tim, ENABLE); |
|
111 | 97 | break; |
|
112 | 98 | default: |
|
113 | 99 | return -1; |
|
114 | 100 | break; |
|
115 | 101 | } |
|
116 | 102 | return 0; |
|
117 | 103 | } |
|
118 | 104 | |
|
119 | 105 | |
|
120 | 106 | |
|
121 | 107 | |
|
122 | 108 | |
|
123 | 109 | int pwmsetdutycycle(int PWM,float dutyCycle) |
|
124 | 110 | { |
|
125 | 111 | if(PWM==-1) return -1; |
|
126 | 112 | int timer = PWMGETTIMNUMBER(PWM); |
|
127 | 113 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
128 | 114 | switch (PWM&0x0FF) { |
|
129 | 115 | case 0: |
|
130 | 116 | tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
131 | 117 | break; |
|
132 | 118 | case 1: |
|
133 | 119 | tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
134 | 120 | break; |
|
135 | 121 | case 2: |
|
136 | 122 | tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
137 | 123 | break; |
|
138 | 124 | case 3: |
|
139 | 125 | tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
140 | 126 | break; |
|
141 | 127 | default: |
|
142 | 128 | return -1; |
|
143 | 129 | break; |
|
144 | 130 | } |
|
145 | 131 | return 0; |
|
146 | 132 | } |
|
147 | 133 | |
|
148 | 134 | float pwmgetdutycycle(int PWM) |
|
149 | 135 | { |
|
150 | 136 | if(PWM==-1) return -1; |
|
151 | 137 | int timer = PWMGETTIMNUMBER(PWM); |
|
152 | 138 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
153 | 139 | switch (PWM&0x0FF) { |
|
154 | 140 | case 0: |
|
155 | 141 | return (float)((tim->CCR1*100)/tim->ARR); |
|
156 | 142 | break; |
|
157 | 143 | case 1: |
|
158 | 144 | return (float)((tim->CCR2*100)/tim->ARR); |
|
159 | 145 | break; |
|
160 | 146 | case 2: |
|
161 | 147 | return (float)((tim->CCR3*100)/tim->ARR); |
|
162 | 148 | break; |
|
163 | 149 | case 3: |
|
164 | 150 | return (float)((tim->CCR4*100)/tim->ARR); |
|
165 | 151 | break; |
|
166 | 152 | default: |
|
167 | 153 | return -1; |
|
168 | 154 | break; |
|
169 | 155 | } |
|
170 | 156 | return 0; |
|
171 | 157 | } |
|
172 | 158 | |
|
173 | 159 | |
|
174 | 160 | int pwmsetfrequency(int PWM,uint32_t freq) |
|
175 | 161 | { |
|
176 | 162 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
|
177 | 163 | if(PWM==-1) return -1; |
|
178 | 164 | int timer = PWMGETTIMNUMBER(PWM); |
|
179 | 165 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
180 | 166 | uint32_t timfreq = getCpuFreq()/2; |
|
181 | 167 | uint32_t period = timfreq/freq - 1; |
|
182 | 168 | uint16_t PrescalerValue=0; |
|
183 | 169 | float dutyCycle = pwmgetdutycycle(PWM); |
|
184 | 170 | while (period>=0x0FFFF) |
|
185 | 171 | { |
|
186 | 172 | PrescalerValue++; |
|
187 | 173 | timfreq = getCpuFreq()/(2*(PrescalerValue+1)); |
|
188 | 174 | period = (timfreq/freq) - 1; |
|
189 | 175 | } |
|
190 | 176 | |
|
191 | 177 | TIM_TimeBaseStructure.TIM_Period = period; |
|
192 | 178 | TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; |
|
193 | 179 | TIM_TimeBaseStructure.TIM_ClockDivision = 0; |
|
194 | 180 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
|
195 | 181 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); |
|
196 | 182 | |
|
197 | 183 | switch (PWM&0x0FF) { |
|
198 | 184 | case 0: |
|
199 | 185 | tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
200 | 186 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
201 | 187 | break; |
|
202 | 188 | case 1: |
|
203 | 189 | tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
204 | 190 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
205 | 191 | break; |
|
206 | 192 | case 2: |
|
207 | 193 | tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
208 | 194 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
209 | 195 | break; |
|
210 | 196 | case 3: |
|
211 | 197 | tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
212 | 198 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
213 | 199 | break; |
|
214 | 200 | default: |
|
215 | 201 | return -1; |
|
216 | 202 | break; |
|
217 | 203 | } |
|
218 | 204 | return 0; |
|
219 | 205 | } |
|
220 | 206 | |
|
221 | 207 | |
|
222 | 208 |
@@ -1,16 +1,17 | |||
|
1 | 1 | TEMPLATE = subdirs |
|
2 | 2 | CONFIG += ordered |
|
3 | 3 | |
|
4 | 4 | SUBDIRS = CORE/core.pro \ |
|
5 | 5 | CPU/cpu.pro \ |
|
6 | 6 | GPIO/gpio.pro \ |
|
7 | TIMER/timer.pro \ | |
|
7 | 8 | UART/uart.pro \ |
|
8 | 9 | SPI/spi.pro \ |
|
9 | 10 | I2C/i2c.pro \ |
|
10 | 11 | PWM/pwm.pro \ |
|
11 | 12 | DAC/dac.pro\ |
|
12 | 13 | SDCARD-SDIO/sdcard-sdio.pro |
|
13 | 14 | |
|
14 | 15 | |
|
15 | 16 | |
|
16 | 17 |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (509 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (566 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (808 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (509 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (1651 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (504 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (772 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (566 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now