Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "freertos/FreeRTOS.h"
- #include "esp_wifi.h"
- #include "esp_system.h"
- #include "esp_event.h"
- #include "esp_event_loop.h"
- #include "nvs_flash.h"
- #include "driver/gpio.h"
- esp_err_t event_handler(void *ctx, system_event_t *event) { return ESP_OK; }
- void loop(void *pvParameter);
- void toggle(void *pvParameter);
- #define TogglePin GPIO_NUM_23
- void app_main(void) {
- nvs_flash_init();
- tcpip_adapter_init();
- ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
- ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
- ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
- ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
- wifi_config_t sta_config = {
- .sta = {
- .ssid = "access_point_name",
- .password = "password",
- .bssid_set = false
- }
- };
- ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
- ESP_ERROR_CHECK( esp_wifi_start() );
- ESP_ERROR_CHECK( esp_wifi_connect() );
- gpio_pad_select_gpio(TogglePin);
- gpio_set_direction(TogglePin, GPIO_MODE_OUTPUT);
- xTaskCreatePinnedToCore(&toggle, "toggle", 4096, NULL, 1, NULL, 1);
- xTaskCreatePinnedToCore(&loop, "loop", 4096, NULL, 1, NULL, 0);
- }
- void loop(void *pvParameter) {
- printf("loop called\n");
- while (1) {
- vTaskDelay(500 / portTICK_PERIOD_MS);
- }
- }
- void toggle(void *pvParameter) {
- printf("toggle called.\n");
- portDISABLE_INTERRUPTS();
- while (1) {
- GPIO.out_w1ts |= (1 << TogglePin);
- __asm__ __volatile__("nop;nop;nop;nop;nop;nop;nop;"); // Bug workaround
- GPIO.out_w1tc |= (1 << TogglePin);
- __asm__ __volatile__("nop;nop;nop;nop;nop;nop;nop;");
- }
- // v doesn't seems to make any difference (as expected)
- /*while (1) {
- GPIO.out |= (1 << TogglePin);
- __asm__ __volatile__("nop;nop;nop;nop;nop;nop;nop;");
- GPIO.out &= ~(1 << TogglePin);
- __asm__ __volatile__("nop;nop;nop;nop;nop;nop;nop;");
- }*/
- portENABLE_INTERRUPTS();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement