Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "test_env.h" 00002 00003 #if !DEVICE_PORTIN 00004 #error [NOT_SUPPORTED] PortIn is not supported 00005 #endif 00006 00007 #if !DEVICE_PORTOUT 00008 #error [NOT_SUPPORTED] PortOut is not supported 00009 #endif 00010 00011 #if defined(TARGET_K64F) || defined(TARGET_KL05Z) 00012 #define P1_1 (1 << 16) 00013 #define P1_2 (1 << 17) 00014 #define PORT_1 PortC 00015 00016 #define P2_1 (1 << 2) 00017 #define P2_2 (1 << 3) 00018 #define PORT_2 PortC 00019 00020 #elif defined(TARGET_K66F) 00021 #define P1_1 (1 << 3) 00022 #define P1_2 (1 << 4) 00023 #define PORT_1 PortC 00024 00025 #define P2_1 (1 << 5) 00026 #define P2_2 (1 << 2) 00027 #define PORT_2 PortC 00028 00029 #elif defined(TARGET_LPC11U24) 00030 #define P1_1 (1 << 9) // p0.9 00031 #define P1_2 (1 << 8) // p0.8 00032 #define PORT_1 Port0 00033 00034 #define P2_1 (1 << 24) // p1.24 00035 #define P2_2 (1 << 25) // p1.25 00036 #define PORT_2 Port1 00037 00038 #elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368) 00039 #define P1_1 (1 << 9) // p0.9 -> p5 00040 #define P1_2 (1 << 8) // p0.8 -> p6 00041 #define PORT_1 Port0 00042 00043 #define P2_1 (1 << 1) // p2.1 -> p25 00044 #define P2_2 (1 << 0) // p2.0 -> p26 00045 #define PORT_2 Port2 00046 00047 #elif defined(TARGET_LPC4088) 00048 #define P1_1 (1 << 7) // p0.7 -> p13 00049 #define P1_2 (1 << 6) // p0.6 -> p14 00050 #define PORT_1 Port0 00051 00052 #define P2_1 (1 << 2) // p1.2 -> p30 00053 #define P2_2 (1 << 3) // p1.3 -> p29 00054 #define PORT_2 Port1 00055 00056 #elif defined(TARGET_LPC1114) 00057 #define P1_1 (1 << 9) // p0.9 00058 #define P1_2 (1 << 8) // p0.8 00059 #define PORT_1 Port0 00060 00061 #define P2_1 (1 << 1) // p1.1 00062 #define P2_2 (1 << 0) // p1.0 00063 #define PORT_2 Port1 00064 00065 #elif defined(TARGET_KL25Z) 00066 #define P1_1 (1 << 4) // PTA4 00067 #define P1_2 (1 << 5) // PTA5 00068 #define PORT_1 PortA 00069 00070 #define P2_1 (1 << 5) // PTC5 00071 #define P2_2 (1 << 6) // PTC6 00072 #define PORT_2 PortC 00073 00074 #elif defined(TARGET_nRF51822) 00075 #define P1_1 (1 << 4) // p4 00076 #define P1_2 (1 << 5) // p5 00077 #define PORT_1 Port0 00078 00079 #define P2_1 (1 << 24) // p24 00080 #define P2_2 (1 << 25) // p25 00081 #define PORT_2 Port0 00082 00083 #elif defined(TARGET_MAXWSNENV) 00084 #define P1_1 (1 << 0) 00085 #define P1_2 (1 << 1) 00086 #define PORT_1 Port0 00087 00088 #define P2_1 (1 << 0) 00089 #define P2_2 (1 << 1) 00090 #define PORT_2 Port1 00091 00092 #elif defined(TARGET_MAX32600MBED) 00093 #define P1_1 (1 << 0) // P1_0 00094 #define P1_2 (1 << 1) // P1_1 00095 #define PORT_1 Port1 00096 00097 #define P2_1 (1 << 7) // P4_7 00098 #define P2_2 (1 << 6) // P4_6 00099 #define PORT_2 Port4 00100 00101 #elif defined(TARGET_DISCO_F469NI) 00102 00103 #define P1_1 (1 << 2) // PC_2 00104 #define P1_2 (1 << 3) // PC_3 00105 #define PORT_1 PortC 00106 00107 #define P2_1 (1 << 1) // PA_1 00108 #define P2_2 (1 << 2) // PA_2 00109 #define PORT_2 PortA 00110 00111 #elif defined(TARGET_NUCLEO_F030R8) || \ 00112 defined(TARGET_NUCLEO_F070RB) || \ 00113 defined(TARGET_NUCLEO_F072RB) || \ 00114 defined(TARGET_NUCLEO_F091RC) || \ 00115 defined(TARGET_NUCLEO_F103RB) || \ 00116 defined(TARGET_NUCLEO_F302R8) || \ 00117 defined(TARGET_NUCLEO_F303RE) || \ 00118 defined(TARGET_NUCLEO_F334R8) || \ 00119 defined(TARGET_NUCLEO_F401RE) || \ 00120 defined(TARGET_NUCLEO_F410RB) || \ 00121 defined(TARGET_NUCLEO_F411RE) || \ 00122 defined(TARGET_NUCLEO_L053R8) || \ 00123 defined(TARGET_NUCLEO_L073RZ) || \ 00124 defined(TARGET_NUCLEO_L476RG) || \ 00125 defined(TARGET_NUCLEO_F446RE) || \ 00126 defined(TARGET_NUCLEO_L152RE) 00127 #define P1_1 (1 << 3) // PB_3 (D3) 00128 #define P1_2 (1 << 10) // PB_10 (D6) 00129 #define PORT_1 PortB 00130 00131 #define P2_1 (1 << 10) // PA_10 (D2) 00132 #define P2_2 (1 << 8) // PA_8 (D7) 00133 #define PORT_2 PortA 00134 00135 #elif defined(TARGET_NUCLEO_F767ZI) || \ 00136 defined(TARGET_NUCLEO_F303ZE) || \ 00137 defined(TARGET_NUCLEO_F207ZG) || \ 00138 defined(TARGET_NUCLEO_F746ZG) 00139 #define P1_1 (1 << 13) // PE_13 (D3) 00140 #define P1_2 (1 << 11) // PE_11 (D5) 00141 #define PORT_1 PortE 00142 00143 #define P2_1 (1 << 15) // PF_15 (D2) 00144 #define P2_2 (1 << 14) // PF_14 (D4) 00145 #define PORT_2 PortF 00146 00147 #elif defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32GG_STK3700) || defined(TARGET_EFM32WG_STK3800) 00148 #define P1_1 (1 << 0) // PD0 00149 #define P1_2 (1 << 1) // PD1 00150 #define PORT_1 PortD 00151 00152 #define P2_1 (1 << 3) // PC3 00153 #define P2_2 (1 << 4) // PC4 00154 #define PORT_2 PortC 00155 00156 #elif defined(TARGET_EFM32ZG_STK3200) 00157 #define P1_1 (1 << 7) // PD7 00158 #define P1_2 (1 << 6) // PD6 00159 #define PORT_1 PortD 00160 00161 #define P2_1 (1 << 1) // PC1 00162 #define P2_2 (1 << 2) // PC2 00163 #define PORT_2 PortC 00164 00165 #elif defined(TARGET_EFM32HG_STK3400) 00166 #define P1_1 (1 << 10) // PE10 00167 #define P1_2 (1 << 11) // PE11 00168 #define PORT_1 PortE 00169 00170 #define P2_1 (1 << 1) // PC1 00171 #define P2_2 (1 << 2) // PC2 00172 #define PORT_2 PortC 00173 00174 #elif defined(TARGET_EFM32PG_STK3401) 00175 #define P1_1 (1 << 6) // PC6 00176 #define P1_2 (1 << 7) // PC7 00177 #define PORT_1 PortC 00178 00179 #define P2_1 (1 << 3) // PA3 00180 #define P2_2 (1 << 4) // PA4 00181 #define PORT_2 PortA 00182 00183 #elif defined(TARGET_SAMR21G18A) || defined(TARGET_SAMD21J18A) 00184 #define P1_1 (1 << 6) /*PA06*/ 00185 #define P1_2 (1 << 7) /*PA07*/ 00186 #define PORT_1 PortA 00187 00188 #define P2_1 (1 << 2) /*PB02*/ 00189 #define P2_2 (1 << 3) /*PB03*/ 00190 #define PORT_2 PortB 00191 00192 #elif defined(TARGET_SAMD21G18A) 00193 #define P1_1 (1 << 2) /*PA02*/ 00194 #define P1_2 (1 << 3) /*PA03*/ 00195 #define PORT_1 PortA 00196 00197 #define P2_1 (1 << 2) /*PB02*/ 00198 #define P2_2 (1 << 3) /*PB03*/ 00199 #define PORT_2 PortB 00200 00201 #elif defined(TARGET_SAML21J18A) 00202 #define P1_1 (1 << 4) /*PA04*/ 00203 #define P1_2 (1 << 5) /*PA05*/ 00204 #define PORT_1 PortA 00205 00206 #define P2_1 (1 << 0) /*PB00*/ 00207 #define P2_2 (1 << 1) /*PB01*/ 00208 #define PORT_2 PortB 00209 00210 #elif defined(TARGET_SAMG55J19) 00211 #define P1_1 (1 << 17) /*PA17*/ 00212 #define P1_2 (1 << 18) /*PA18*/ 00213 #define PORT_1 PortA 00214 00215 #define P2_1 (1 << 10) /*PB10*/ 00216 #define P2_2 (1 << 11) /*PB11*/ 00217 #define PORT_2 PortB 00218 00219 #elif defined(TARGET_VK_RZ_A1H) 00220 #define P1_1 (1 << 2) /*P3_2*/ 00221 #define P1_2 (1 << 7) /*P3_7*/ 00222 #define PORT_1 Port3 00223 00224 #define P2_1 (1 << 6) /*P5_6*/ 00225 #define P2_2 (1 << 1) /*P5_1*/ 00226 #define PORT_2 Port5 00227 00228 #else 00229 #error [NOT_SUPPORTED] This test is not defined on this target 00230 #endif 00231 00232 #define MASK_1 (P1_1 | P1_2) 00233 #define MASK_2 (P2_1 | P2_2) 00234 00235 PortOut port_out(PORT_1, MASK_1); 00236 PortIn port_in (PORT_2, MASK_2); 00237 00238 int main() { 00239 MBED_HOSTTEST_TIMEOUT(20); 00240 MBED_HOSTTEST_SELECT(default_auto); 00241 MBED_HOSTTEST_DESCRIPTION(PortOut PortIn); 00242 MBED_HOSTTEST_START("MBED_A10"); 00243 00244 port_out = MASK_1; 00245 wait(0.1); 00246 int value = port_in.read(); 00247 if (value != MASK_2) { 00248 printf("[Test high] expected (0x%x) received (0x%x)\n", MASK_2, value); 00249 notify_completion(false); 00250 } 00251 00252 port_out = 0; 00253 wait(0.1); 00254 value = port_in.read(); 00255 if (value != 0) { 00256 printf("[Test low] expected (0x%x) received (0x%x)\n", 0, value); 00257 notify_completion(false); 00258 } 00259 00260 notify_completion(true); 00261 }
Generated on Sun Jul 17 2022 08:25:26 by
1.7.2