1 | /*
|
2 | * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
3 | *
|
4 | * SPDX-License-Identifier: Unlicense OR CC0-1.0
|
5 | */
|
6 |
|
7 | #include <stdint.h>
|
8 | #include "esp_log.h"
|
9 | #include "freertos/FreeRTOS.h"
|
10 | #include "freertos/task.h"
|
11 | #include "driver/gpio.h"
|
12 | #include "sdkconfig.h"
|
13 |
|
14 | static const char *TAG = "example";
|
15 |
|
16 | #define OUT_PORT 9
|
17 |
|
18 | static volatile int cpu1Cnt=0;
|
19 |
|
20 | /*------------------------------------------------------------------------*\
|
21 | \*------------------------------------------------------------------------*/
|
22 | void IRAM_ATTR task_cpu1(void *dummy)
|
23 | {
|
24 | // first config the outputs
|
25 | gpio_config_t io_conf = {};
|
26 | //disable interrupt
|
27 | io_conf.intr_type = GPIO_INTR_DISABLE;
|
28 | //set as output mode
|
29 | io_conf.mode = GPIO_MODE_OUTPUT;
|
30 | //bit mask of the pins that you want to set,e.g.GPIO18/19
|
31 | io_conf.pin_bit_mask = (1<<OUT_PORT);
|
32 | //disable pull-down mode
|
33 | io_conf.pull_down_en = 0;
|
34 | //disable pull-up mode
|
35 | io_conf.pull_up_en = 0;
|
36 | //configure GPIO with the given settings
|
37 | gpio_config(&io_conf);
|
38 |
|
39 | // now disable interrupts for CPU1
|
40 | portDISABLE_INTERRUPTS();
|
41 | // never enable it again, so Taskscheduler will not steal cycles
|
42 | // DMA will steal them nevertheless
|
43 | // if you uncomment it, you will see interrutions of about 10 us every RTOS tick
|
44 |
|
45 | #if 1 // slow version, generates about 1 MHz at fCPU = 160 MHz on ESP32-S3
|
46 | while(1)
|
47 | {
|
48 | gpio_set_level(OUT_PORT, 0);
|
49 | cpu1Cnt ++;
|
50 | gpio_set_level(OUT_PORT, 1);
|
51 | }
|
52 | #else // fast Version with direct access to the GPIO register
|
53 | // generates about 8 MHz square at fCPU = 160 MHz on esp32-s3
|
54 | // register addresses are valid only for esp32-s3
|
55 | volatile uint32_t * pGPIOw1tc = (uint32_t *)0x6000400c;
|
56 | volatile uint32_t * pGPIOw1ts = (uint32_t *)0x60004008;
|
57 | volatile uint32_t * pGPIOin = (uint32_t *)0x6000403c;
|
58 | while(1)
|
59 | {
|
60 | *pGPIOw1tc = (1 << OUT_PORT); // clear Port
|
61 | *pGPIOw1ts = (1 << OUT_PORT); // set Port
|
62 | }
|
63 | #endif
|
64 | }
|
65 |
|
66 | /*------------------------------------------------------------------------*\
|
67 | \*------------------------------------------------------------------------*/
|
68 | void tuwas(void)
|
69 | {
|
70 | volatile int i,k,jj=0;
|
71 | for(k=0;k<10000;k++)
|
72 | {
|
73 | for(i=0;i<1000;i++) jj+= k+i;
|
74 | }
|
75 | }
|
76 |
|
77 | /*------------------------------------------------------------------------*\
|
78 | \*------------------------------------------------------------------------*/
|
79 | void app_main(void)
|
80 | {
|
81 | ESP_LOGI(TAG, "Start CPU1");
|
82 | xTaskCreatePinnedToCore(task_cpu1, "tskCpu1", 2048, NULL, 10, NULL, 1);
|
83 |
|
84 | int Cnt=0;
|
85 | while (1)
|
86 | {
|
87 | ESP_LOGI(TAG,"Cnt = %d, cpu1Cnt = %d",Cnt,cpu1Cnt);
|
88 | Cnt++;
|
89 | tuwas();
|
90 | }
|
91 | }
|