Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "test_env.h"
00002 
00003 /* Timer/Match Register    Pinout Options
00004 
00005 CT16B0/MR0  p5 (P0_9)
00006 CT16B0/MR1  p6 (P0_8)
00007 CT16B0/MR2  p34 (P1_15)
00008 
00009 CT16B1/MR0  p36 (P0_21)
00010 CT16B1/MR1  p20 (P0_22) and p14 (P1_23)
00011 
00012 CT32B0/MR0  p25 (P1_24)
00013 CT32B0/MR1  p26 (P1_25) and USBTX (P0_19)
00014 CT32B0/MR2  p10 (P1_26)
00015  */
00016 
00017 float value = 0.75;
00018 
00019 int main() {
00020 #if defined(TARGET_FF_ARDUINO)
00021     PwmOut pwm(D9);
00022     int period_ms = 10;
00023 
00024     pwm.period_ms(period_ms);
00025     pwm.write(value);
00026 
00027     float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
00028     printf("PWM period = %dms with duty cycle: %d%%\n", period_ms, (int) (result * 100));
00029 
00030     notify_completion(result == value ? true : false);
00031 #elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC2460)
00032     PwmOut pwm_p25(p25);
00033     PwmOut pwm_p26(p26);
00034 
00035     pwm_p25.write(0.75);
00036     pwm_p26.write(0.50);
00037 
00038     printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
00039     printf("Initialize PWM on pin 26 with duty cycle: %.2f\n", pwm_p26.read());
00040 
00041 #elif defined(TARGET_LPC1114)
00042     PwmOut pwm_dp24(dp24); // P0_1
00043     PwmOut pwm_dp18(dp18); // P1_9
00044 
00045     pwm_dp24.write(0.75);
00046     pwm_dp18.write(0.50);
00047 
00048     printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_dp24.read());
00049     printf("Initialize PWM on pin 18 with duty cycle: %.2f\n", pwm_dp18.read());
00050 
00051 #elif defined(TARGET_LPC1347)
00052     PwmOut pwm_1(P0_18);
00053     PwmOut pwm_2(P0_9);
00054 
00055     pwm_1.write(0.75);
00056     pwm_2.write(0.50);
00057 
00058     printf("Initialize PWM on P0_18 with duty cycle: %.2f\n", pwm_1.read());
00059     printf("Initialize PWM on P0_9 with duty cycle: %.2f\n", pwm_2.read());
00060 
00061 #elif defined(TARGET_NRF51822)
00062     PwmOut pwm_p24(p24);
00063     PwmOut pwm_p25(p25);
00064 
00065     pwm_p24.write(0.75);
00066     pwm_p25.write(0.50);
00067 
00068     printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_p24.read());
00069     printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
00070 
00071 #elif defined(TARGET_DISCO_F100RB)
00072     PwmOut pwm_1(PB_3);
00073     PwmOut pwm_2(PB_4);
00074 
00075     pwm_1.write(0.75);
00076     pwm_2.write(0.50);
00077 
00078     printf("Initialize PWM on pin PB_3 with duty cycle: %.2f\n", pwm_1.read());
00079     printf("Initialize PWM on pin PB_4 with duty cycle: %.2f\n", pwm_2.read());
00080 #elif defined(TARGET_DISCO_F051R8)
00081     PwmOut pwm_1(PA_7);
00082     PwmOut pwm_2(PC_7);
00083 
00084     pwm_1.write(0.75);
00085     pwm_2.write(0.50);
00086 
00087     printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
00088     printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
00089 #elif defined(TARGET_DISCO_F303VC)
00090     PwmOut pwm_1(PA_8);
00091     PwmOut pwm_2(PA_9);
00092 
00093     pwm_1.write(0.75);
00094     pwm_2.write(0.50);
00095 
00096     printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
00097     printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
00098 #elif defined(TARGET_MAXWSNENV)
00099     PwmOut pwm_1(TP2);
00100     PwmOut pwm_2(TP4);
00101 
00102     pwm_1.write(0.75);
00103     pwm_2.write(0.50);
00104 
00105     printf("Initialize PWM on pin TP2 with duty cycle: %.2f\n", pwm_1.read());
00106     printf("Initialize PWM on pin TP4 with duty cycle: %.2f\n", pwm_2.read());
00107 #elif defined(TARGET_DISCO_F407VG)
00108     PwmOut pwm_1(PD_12);
00109     PwmOut pwm_2(PD_13);
00110 
00111     pwm_1.write(value);
00112     pwm_2.write(0.50);
00113 
00114     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
00115 
00116     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
00117     printf("Initialize PWM on pin PD_13 with duty cycle: %.2f\n", pwm_2.read());
00118 
00119     notify_completion(result == value ? true : false);
00120 #elif defined(TARGET_DISCO_F429ZI) || defined(TARGET_NUCLEO_F429ZI)
00121     PwmOut pwm_1(PA_0);
00122 
00123     pwm_1.write(value);
00124 
00125     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
00126 
00127     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
00128 
00129     notify_completion(result == value ? true : false);
00130 #elif defined(TARGET_MTS_MDOT_F405RG)
00131     PwmOut pwm_1(PA_0);
00132 
00133     pwm_1.write(value);
00134 
00135     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
00136 
00137     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
00138 
00139     notify_completion(result == value ? true : false);
00140 #elif defined(TARGET_MTS_DRAGONFLY_F411RE)
00141     PwmOut pwm_1(PA_0);
00142 
00143     pwm_1.write(value);
00144 
00145     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
00146 
00147     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
00148 
00149     notify_completion(result == value ? true : false);
00150 #elif defined(TARGET_MTS_MDOT_F411RE)
00151     PwmOut pwm_1(PA_0);
00152 
00153     pwm_1.write(value);
00154 
00155     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
00156 
00157     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
00158 
00159     notify_completion(result == value ? true : false);
00160 #elif defined(TARGET_UBLOX_EVK_ODIN_W2)
00161     PwmOut pwm_1(PA_0);
00162 
00163     pwm_1.write(value);
00164 
00165     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
00166 
00167     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
00168 
00169     notify_completion(result == value ? true : false);
00170 #elif defined(TARGET_MAX32600MBED)
00171     PwmOut pwm_1(P1_2);
00172     PwmOut pwm_2(P1_3);
00173 
00174     pwm_1.write(0.75);
00175     pwm_2.write(0.50);
00176 
00177     printf("Initialize PWM on pin P1.2 with duty cycle: %.2f\n", pwm_1.read());
00178     printf("Initialize PWM on pin P1.3 with duty cycle: %.2f\n", pwm_2.read());
00179 #elif defined(TARGET_SAMR21G18A) || defined(TARGET_SAMD21J18A) || defined(TARGET_SAMD21G18A) || defined(TARGET_SAML21J18A)
00180     PwmOut pwm(LED1);
00181 
00182     pwm.period_ms(1000);
00183     pwm.write(value);
00184 
00185     float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
00186     printf("Initialize PWM on pin LED1 with duty cycle: %.2f\n", result);
00187 
00188     notify_completion(result == value ? true : false);
00189 #elif defined(TARGET_SAMG55J19)
00190     PwmOut pwm(PA00);  /*LED Doesnt support PWM for G55 XPro*/
00191 
00192     pwm.period_ms(1000);
00193     pwm.write(value);
00194 
00195     float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
00196     printf("Initialize PWM on pin PA01 with duty cycle: %.2f\n", result);
00197 
00198     notify_completion(result == value ? true : false);
00199 #else
00200 #error [NOT_SUPPORTED] This test is not supported on this target.
00201 #endif
00202 
00203     notify_completion(true);
00204 }