PICSimLab - Programmable IC Simulator Laboratory 0.9.3
PICSimLab - API
Loading...
Searching...
No Matches
picsimlab6_vspio.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2026 Luis Claudio GambĂ´a Lopes <lcgamboa@yahoo.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 For e-mail suggestions : lcgamboa@yahoo.com
24 ######################################################################## */
25
26#ifndef CPWINDOW6VSPIO
27#define CPWINDOW6VSPIO
28
29static const char blink_code[] =
30 "/*\n"
31 " Simple example to blinking an LED using Platformio IDE.\n"
32 " To upload to PICSimLab:\n"
33 " 1- Check if PICSimLab is running;\n"
34 " 2- Use Ctrl+Alt+U in VS code.\n"
35 " To debug the code:\n"
36 " 1- Toggle the PICSimLab Debug button;\n"
37 " 2- Use Ctrl+Shift+D followed by F5 in VS code.\n"
38 "*/\n\n"
39 "#include <Arduino.h>\n"
40 "\n"
41 "#define LED_PIN %s\n"
42 "\n"
43 "void setup()\n"
44 "{\n"
45 " pinMode(LED_PIN, OUTPUT);\n"
46 "}\n"
47 "\n"
48 "void loop()\n"
49 "{\n"
50 " digitalWrite(LED_PIN, HIGH);\n"
51 " delay(500);\n"
52 " digitalWrite(LED_PIN, LOW);\n"
53 " delay(500);\n"
54 "}\n"
55 "\n";
56
57static const char blink_RTOS_code[] =
58 "/*\n"
59 " Simple example to blinking an LED using Platformio IDE.\n"
60 " To upload to PICSimLab:\n"
61 " 1- Check if PICSimLab is running;\n"
62 " 2- Use Ctrl+Alt+U in VS code.\n"
63 " To debug the code:\n"
64 " 1- Toggle the PICSimLab Debug button;\n"
65 " 2- Use Ctrl+Shift+D followed by F5 in VS code.\n"
66 "*/\n"
67 "\n"
68 "#include <Arduino.h>\n"
69 "%s"
70 "\n"
71 "#define LED_PIN %s\n"
72 "\n"
73 "void TaskBlink(void *pvParameters)\n"
74 "{\n"
75 " pinMode(LED_PIN, OUTPUT);\n"
76 " while (1)\n"
77 " {\n"
78 " digitalWrite(LED_PIN, HIGH);\n"
79 " vTaskDelay(500 / portTICK_PERIOD_MS);\n"
80 " digitalWrite(LED_PIN, LOW);\n"
81 " vTaskDelay(500 / portTICK_PERIOD_MS);\n"
82 " }\n"
83 "}\n"
84 "\n"
85 "void setup()\n"
86 "{\n"
87 " xTaskCreate(TaskBlink, \"Blink\", configMINIMAL_STACK_SIZE, NULL, 2, NULL);\n%s"
88 "}\n"
89 "\n"
90 "void loop()\n"
91 "{\n"
92 "}\n"
93 "\n";
94
95static const char blink_idf_code[] =
96 "/*\n"
97 " Simple example to blinking an LED using Platformio IDE.\n"
98 " To upload to PICSimLab:\n"
99 " 1- Check if PICSimLab is running;\n"
100 " 2- Use Ctrl+Alt+U in VS code.\n"
101 " To debug the code:\n"
102 " 1- Toggle the PICSimLab Debug button;\n"
103 " 2- Use Ctrl+Shift+D followed by F5 in VS code.\n"
104 "*/\n\n"
105 "#include <stdio.h>\n"
106 "#include \"freertos/FreeRTOS.h\"\n"
107 "#include \"driver/gpio.h\"\n"
108 "\n"
109 "#define LED_PIN %s\n"
110 "\n"
111 "void app_main(void)\n"
112 "{\n"
113 " gpio_reset_pin(LED_PIN);\n"
114 " gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);\n"
115 "\n"
116 " while (1)\n"
117 " {\n"
118 " gpio_set_level(LED_PIN, 1);\n"
119 " vTaskDelay(500 / portTICK_PERIOD_MS);\n"
120 " gpio_set_level(LED_PIN, 0);\n"
121 " vTaskDelay(500 / portTICK_PERIOD_MS);\n"
122 " }\n"
123 "}\n"
124 "\n";
125
126static const char blink_cmsis_code[] =
127 "/*\n"
128 " Simple example to blinking an LED using Platformio IDE.\n"
129 " To upload to PICSimLab:\n"
130 " 1- Check if PICSimLab is running;\n"
131 " 2- Use Ctrl+Alt+U in VS code.\n"
132 " To debug the code:\n"
133 " 1- Toggle the PICSimLab Debug button;\n"
134 " 2- Use Ctrl+Shift+D followed by F5 in VS code.\n"
135 "*/\n"
136 "#include \"stm32f1xx.h\"\n"
137 "\n"
138 "static volatile uint32_t msTicks = 0;\n"
139 "\n"
140 "#define PC12 GPIO_ODR_ODR12\n"
141 "#define PC13 GPIO_ODR_ODR13\n"
142 "\n"
143 "#define LED_PIN %s\n"
144 "\n"
145 "void SysTick_Handler(void)\n"
146 "{\n"
147 " if (msTicks != 0)\n"
148 " {\n"
149 " msTicks--;\n"
150 " }\n"
151 "}\n"
152 "\n"
153 "void delay_ms(uint32_t ms)\n"
154 "{\n"
155 " msTicks = ms;\n"
156 " while (msTicks != 0)\n"
157 " ;\n"
158 "}\n"
159 "\n"
160 "void SetClock72MHz(void)\n"
161 "{\n"
162 " RCC->CR = 0;\n"
163 " RCC->CFGR |= RCC_CFGR_PLLMULL9;\n"
164 " RCC->CFGR |= (1 << 16);\n"
165 " RCC->CFGR |= RCC_CFGR_PPRE1_DIV2;\n"
166 " RCC->CFGR |= RCC_CFGR_SW_PLL;\n"
167 " RCC->CFGR |= RCC_CFGR_MCOSEL_PLL_DIV2;\n"
168 " RCC->CR |= RCC_CR_HSEON;\n"
169 " RCC->CR |= RCC_CR_PLLON;\n"
170 "}\n"
171 "\n"
172 "int main(void)\n"
173 "{\n"
174 " SetClock72MHz();\n"
175 " SystemCoreClockUpdate();\n"
176 " SysTick_Config(SystemCoreClock / 1000);\n"
177 "\n"
178 " RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;\n"
179 "\n"
180 "#if LED_PIN == PC12 \n"
181 " GPIOC->CRH &= ~(GPIO_CRH_MODE12 | GPIO_CRH_CNF12);\n"
182 " GPIOC->CRH |= GPIO_CRH_MODE12_1;\n"
183 "#else //PC13\n"
184 " GPIOC->CRH &= ~(GPIO_CRH_MODE13 | GPIO_CRH_CNF13);\n"
185 " GPIOC->CRH |= GPIO_CRH_MODE13_1;\n"
186 "#endif \n"
187 "\n"
188 " while (1)\n"
189 " {\n"
190 " GPIOC->ODR |= LED_PIN;\n"
191 " delay_ms(500);\n"
192 " GPIOC->ODR &= ~LED_PIN;\n"
193 " delay_ms(500);\n"
194 " }\n"
195 "}\n"
196 "\n";
197
198static const char blink_c51_code[] =
199 "/*\n"
200 " Simple example to blinking an LED using Platformio IDE.\n"
201 " To upload to PICSimLab:\n"
202 " 1- Check if PICSimLab is running;\n"
203 " 2- Use Ctrl+Alt+U in VS code.\n"
204 "*/\n"
205 "\n"
206 "#include <mcs51/8051.h>\n"
207 "\n"
208 "#define LED_PIN %s\n"
209 "\n"
210 "void delay_ms_1(int m)\n"
211 "{\n"
212 " int i, j;\n"
213 " for (i = 0; i < m; i++)\n"
214 " for (j = 0; j < 114; j++)\n"
215 " ;\n"
216 "}\n"
217 "\n"
218 "void main()\n"
219 "{\n"
220 " while (1)\n"
221 " {\n"
222 " LED_PIN = 1;\n"
223 " delay_ms_1(500);\n"
224 " LED_PIN = 0;\n"
225 " delay_ms_1(500);\n"
226 " }\n"
227 "}\n"
228 "\n";
229
230static const char platformio_ini[] =
231 "; PlatformIO Project Configuration File\n"
232 ";\n"
233 "; Build options: build flags, source filter\n"
234 "; Upload options: custom upload port, speed and extra flags\n"
235 "; Library options: dependencies, extra library storages\n"
236 "; Advanced options: extra scripting\n"
237 ";\n"
238 "; Please visit documentation for the other options and examples\n"
239 "; https://docs.platformio.org/page/projectconf.html\n"
240 "\n"
241 "[platformio]\n"
242 "default_envs = PICSimLab\n"
243 "\n"
244 "[env:%s]\n"
245 "platform = %s\n"
246 "board = %s\n"
247 "framework = %s\n"
248 "%s\n"
249 "[env:PICSimLab]\n"
250 "extends = env:%s\n"
251 "extra_scripts = pre:python/install_python_deps.py\n"
252 "test_framework = custom\n"
253 "test_build_src = yes\n"
254 "upload_protocol = custom\n"
255 "upload_command = $PYTHONEXE python/picsimlab_tool.py \"$BUILD_DIR/firmware.%s\"\n";
256
257static const char platformio_ini_dbg[] =
258 "debug_tool = custom\n"
259 "debug_port = localhost:1234\n"
260 "debug_init_break = tbreak %s\n"
261 "debug_init_cmds =\n"
262 " define pio_reset_halt_target\n%s"
263 " end\n"
264 " define pio_reset_run_target\n%s"
265 " end\n"
266 " target extended-remote $DEBUG_PORT\n"
267 " $LOAD_CMDS\n"
268 " pio_reset_halt_target\n"
269 " $INIT_BREAK\n"
270 "\n";
271
272static const char blink_test[] =
273 "from platformio.public import TestCase, TestCaseSource, TestStatus, UnityTestRunner\n"
274 "\n"
275 "from PICSimLab_rcontrol import PICSimLab_rcontrol\n"
276 "\n"
277 "import time,re\n"
278 "\n"
279 "class CustomTestRunner(UnityTestRunner):\n"
280 " def stage_testing(self):\n"
281 " print(\"Blink time measure test started ....\")\n"
282 " time.sleep(3)\n"
283 " try: \n"
284 " with PICSimLab_rcontrol(5000) as rc: \n"
285 " #rc.debug=1\n"
286 " rc.cmd_oscshow()\n"
287 " oscopen= rc.get_cmd_response().split()[0]\n"
288 " rc.cmd_oscshow(1)\n"
289 " rc.cmd_oscrdcfg()\n"
290 " osccfg= re.findall(r'(\\d+):\"([^\"]*)\"', rc.get_cmd_response())\n"
291 " rc.cmd_oscwrcfg(0, \"osc_cfg,100,100,0:500.000000,0.000000,1,1,2.500000,3,2,9,7,8\")\n"
292 " rc.cmd_oscwrcfg(1, \"osc_ch1,0,0,0:2.000000,0.000000,1,#FF0000,0,%s\")\n"
293 " rc.cmd_oscwrcfg(2, \"osc_ch2,0,0,0:2.000000,-6.000000,0,#00FF00,0,0\")\n"
294 " cnt = 0\n"
295 " while cnt < 5:\n"
296 " time.sleep(0.1)\n"
297 " cnt = cnt + 0.1\n"
298 " rc.cmd_oscmeasures(1)\n"
299 " val = rc.get_cmd_response()\n"
300 " fcyc = float((val.split('\\n')[9]).split()[1])\n"
301 " if fcyc > 900 :\n"
302 " break\n"
303 " time.sleep(5)\n"
304 " rc.cmd_oscmeasures(1)\n"
305 " val= rc.get_cmd_response()\n"
306 " rc.cmd_oscwrcfg(osccfg[0][0], osccfg[0][1])\n"
307 " rc.cmd_oscwrcfg(osccfg[1][0], osccfg[1][1])\n"
308 " rc.cmd_oscwrcfg(osccfg[2][0], osccfg[2][1])\n"
309 " rc.cmd_oscshow(oscopen)\n"
310 " pcyc=float((val.split('\\n')[7]).split()[1]) \n"
311 " ncyc=float((val.split('\\n')[8]).split()[1]) \n"
312 "\n"
313 " print(f\"Positive cycle: {pcyc} ms\")\n"
314 " print(f\"Negative cycle: {ncyc} ms\")\n"
315 "\n"
316 " if pcyc > 490 and pcyc < 510: \n"
317 " self.test_suite.add_case(\n"
318 " TestCase(name=\"Positive cycle\", status=TestStatus.PASSED))\n"
319 " else : \n"
320 " self.test_suite.add_case(\n"
321 " TestCase(name=\"Positive cycle\", \n"
322 " status=TestStatus.FAILED,\n"
323 " message=f\"Expected 500 ms Was {pcyc} ms\",\n"
324 " stdout=f\"Positive cycle: FAIL: Expected 500 ms Was {pcyc} ms\"\n"
325 " ))\n"
326 " \n"
327 " if ncyc > 490 and ncyc < 510: \n"
328 " self.test_suite.add_case(TestCase(name=\"Negative cycle\", status=TestStatus.PASSED))\n"
329 " else : \n"
330 " self.test_suite.add_case(\n"
331 " TestCase(name=\"Negative cycle\", \n"
332 " status=TestStatus.FAILED,\n"
333 " message=f\"Expected 500 ms Was {ncyc} ms\",\n"
334 " stdout=f\"Negative cycle: FAIL: Expected 500 ms Was {ncyc} ms\"\n"
335 " )) \n"
336 "\n"
337 " except ConnectionError as e:\n"
338 " print(e)\n"
339 " return -1 \n"
340 " \n"
341 "\n"
342 "\n";
343
344#endif /*#CPWINDOW6VSPIO*/