Нужна помощь Мигание светодиодом по команде UART

Meinframe

New member
Подскажите. Я пытаюсь соединить пример работы по UART (http://41j.com/blog/2015/01/esp8266-serial-uart0-txrx/) и пример мигания светодиодом "Blinky" из esp_iot_sdk_v0.9.5_15_01_23.zip (https://github.com/esp8266/esp8266-wiki/tree/master/sdk).

Проблема в изменении, как мне кажется, флага по UART. Так как я проверял, что задача мигания выполняется и не выполняется при начальном значении флага 1 или 0 соответственно. Вопрос что я делаю не так? куда копать?
Код:
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_interface.h"
#include "user_config.h"
#include "uart.h"

#include "c_types.h"
#include "espconn.h"
#include "mem.h"

#define user_procTaskPrio        0
#define user_procTaskPrio1       1
#define user_procTaskQueueLen    2
os_event_t    user_procTaskQueue[user_procTaskQueueLen];
static void user_procTask(os_event_t *events);
int UART_ENABLE_BLINK = 1;

static void loop(os_event_t *events);

LOCAL os_timer_t network_timer;

static volatile os_timer_t some_timer;

//Do nothing function
static void ICACHE_FLASH_ATTR
user_procTask(os_event_t *events)
{
    os_delay_us(10);
}

void some_timerfunc(void *arg)
{
    if(UART_ENABLE_BLINK == 1)
    {
            //Do blinky stuff
        if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2)
        {
        //Set GPIO2 to LOW
        gpio_output_set(0, BIT2, BIT2, 0);
        }
        else
        {
        //Set GPIO2 to HIGH
        gpio_output_set(BIT2, 0, BIT2, 0);
        }
    }
    else if(UART_ENABLE_BLINK == 0)
    {
        //Set GPIO2 to LOW
        gpio_output_set(0, BIT2, BIT2, 0);
    }

    system_os_post(user_procTaskPrio1, 0, 0 );

}

/* Доступные функции SDK Espressif */
//PROVIDE ( UartConnCheck = 0x40003230 );
//PROVIDE ( UartConnectProc = 0x400037a0 );
//PROVIDE ( UartDwnLdProc = 0x40003368 );
//PROVIDE ( UartGetCmdLn = 0x40003ef4 );
//PROVIDE ( UartRegReadProc = 0x4000381c );
//PROVIDE ( UartRegWriteProc = 0x400037ac );
//PROVIDE ( UartRxString = 0x40003c30 );
//PROVIDE ( Uart_Init = 0x40003a14 );
//PROVIDE ( ets_install_uart_printf = 0x40002438 );
//PROVIDE ( ets_uart_printf = 0x40002544 );
//PROVIDE ( uartAttach = 0x4000383c );
//PROVIDE ( uart_baudrate_detect = 0x40003924 );
//PROVIDE ( uart_buff_switch = 0x400038a4 );
//PROVIDE ( uart_div_modify = 0x400039d8 );
//PROVIDE ( uart_rx_intr_handler = 0x40003bbc );
//PROVIDE ( uart_rx_one_char = 0x40003b8c );
//PROVIDE ( uart_rx_one_char_block = 0x40003b64 );
//PROVIDE ( uart_rx_readbuff = 0x40003ec8 );
//PROVIDE ( uart_tx_one_char = 0x40003b30 );
//PROVIDE ( UartDev = 0x3fffde10 );

void ICACHE_FLASH_ATTR wifi_config_ap();

int debug(char *text) {
}

//Main code function
static void ICACHE_FLASH_ATTR loop(os_event_t *events) {

  int c = uart0_rx_one_char();

  if(c == 5)
  {
      UART_ENABLE_BLINK = 1;
  }
  else if(c == 6)
  {
      UART_ENABLE_BLINK = 0;
  }

  os_delay_us(100);
  system_os_post(user_procTaskPrio, 0, 0 );
}

void ICACHE_FLASH_ATTR network_wait_for_ip() {

  struct ip_info ipconfig;
  os_timer_disarm(&network_timer);
  wifi_get_ip_info(STATION_IF, &ipconfig);
  if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) {
    char page_buffer[40];
    os_sprintf(page_buffer,"myIP: %d.%d.%d.%d",IP2STR(&ipconfig.ip));
    debug(page_buffer);
    //safecast_send_nema("$BNRDD,1010,2015-01-06T17:31:15Z,0,0,128,V,3537.2633,N,13938.0270,E,37.70,A,9,11160");
  } else {
    char page_buffer[40];
    os_sprintf(page_buffer,"network retry, status: %d",wifi_station_get_connect_status());
    if(wifi_station_get_connect_status() == 3) wifi_station_connect();
    debug(page_buffer);
    os_timer_setfn(&network_timer, (os_timer_func_t *)network_wait_for_ip, NULL);
    os_timer_arm(&network_timer, 2000, 0);
  }
}

void ICACHE_FLASH_ATTR network_init() {
  debug("init network 1");
  os_timer_disarm(&network_timer);
  os_timer_setfn(&network_timer, (os_timer_func_t *)network_wait_for_ip, NULL);
  os_timer_arm(&network_timer, 2000, 0);
  debug("init network 2");
}

void ICACHE_FLASH_ATTR wifi_config_station() {
    // Wifi configuration
    char ssid[32] = SSID;
    char password[64] = SSID_PASSWORD;

    struct station_config stationConf;

    //Set station mode
    wifi_set_opmode( 0x1 );

    //Set ap settings
    stationConf.bssid_set = 0;
    os_memcpy(&stationConf.ssid, ssid, 32);
    os_memcpy(&stationConf.password, password, 64);

    wifi_station_set_config(&stationConf);
    debug("init wifi");
    debug(ssid);
    debug(password);
}

//Init function
void ICACHE_FLASH_ATTR user_init() {

    // Initialize the GPIO subsystem.
    gpio_init();

    // Set UART Speed (default appears to be rather odd 77KBPS)
    uart_init(BIT_RATE_9600,BIT_RATE_9600);

    // check GPIO setting (for config mode selection)
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
    PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO0_U);

    //Set GPIO2 to output mode
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

    //Set GPIO2 low
    gpio_output_set(0, BIT2, BIT2, 0);

    //Disarm timer
    os_timer_disarm(&some_timer);

    //Setup timer
    os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);

    //Arm the timer
    //&some_timer is the pointer
    //500 is the fire time in ms
    //0 for once and 1 for repeating
    os_timer_arm(&some_timer, 500, 1);

    wifi_config_station();

    //Start os task
    system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
    system_os_post(user_procTaskPrio, 0, 0 );
    system_os_task(user_procTask, user_procTaskPrio1,user_procTaskQueue, user_procTaskQueueLen);
    system_os_post(user_procTaskPrio1, 0, 0 );
    network_init();
}
 
Сверху Снизу