Statistics: Posted by FrenkR — Thu Jan 01, 2015 4:16 am
Code:
// GPIO interrupt handler:store local data and start task
static void iw_GPIO_handler(int8_t key)
{
GPIOState * _gpioState = (GPIOState *)os_zalloc(sizeof(GPIOState));
os_printf("heap size %d\n", system_get_free_heap_size());
uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
uint32_t rtc_now = system_get_rtc_time();
_gpioState->GPIOState = gpio_status;
_gpioState->RtcTime = rtc_now;
// activate task
if (system_os_post(user_procTaskPrio, 0, (uint32_t)_gpioState) == false) {
os_free(_gpioState);
}
// if you uncomment following line, "memalloc assert" error will be removed
//os_free(_gpioState);
// clear pending interrupts
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
}
Statistics: Posted by jackon — Wed Dec 31, 2014 11:05 am
Code:
#include "osapi.h"
#include "user_interface.h"
#include "driver/uart.h"
#include "user_config.h"
#include "eagle_soc.h"
#include "ets_sys.h"
#include "gpio.h"
#include "mem.h"
static volatile os_timer_t tmrSstart;
os_event_t user_procTaskQueue[user_procTaskQueueLen];
//Main code function
static void ICACHE_FLASH_ATTR
loop(os_event_t *events)
{
os_printf("Task sig=%u, par=%u!\r\n",events->sig, events->par);
GPIOState * _gpioState = (GPIOState *)(events->par);
// if os_free() is uncommented in iw_GPIO_handler routine, you must comment this line.
os_free(_gpioState);
os_printf("Task executed and memory disposed!\r\n");
}
static void ICACHE_FLASH_ATTR
startTask(void *arg){
system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen);
}
// GPIO interrupt handler:store local data and start task
static void ICACHE_FLASH_ATTR
iw_GPIO_handler(int8_t key){
GPIOState * _gpioState = (GPIOState *)os_zalloc(sizeof(GPIOState));
uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
uint32_t rtc_now = system_get_rtc_time();
_gpioState->GPIOState = gpio_status;
_gpioState->RtcTime = rtc_now;
// activate task
system_os_post(user_procTaskPrio, 0, (uint32_t)_gpioState);
// if you uncomment following line, "memalloc assert" error will be removed
//os_free(_gpioState);
// clear pending interrupts
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
}
//Init function
void ICACHE_FLASH_ATTR
user_init()
{
uart_init(BIT_RATE_115200, BIT_RATE_115200);
os_delay_us(1000);
uart0_sendStr("Start!\r\n");
//Start os task
system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen);
// set interrupt routine
// start first run with timer(otherwise doesn't work?)
ETS_GPIO_INTR_DISABLE();
// GPIO12 interrupt handler
ETS_GPIO_INTR_ATTACH(iw_GPIO_handler, 12);
// pin 13 setup
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); // select pin to GPIO 13 mode
GPIO_DIS_OUTPUT(13); // set pin to "input" mode
PIN_PULLDWN_DIS(PERIPHS_IO_MUX_MTCK_U); // disable pullodwn
PIN_PULLUP_EN(PERIPHS_IO_MUX_MTCK_U); // pull - up pin
// interrupt on GPIO 13
gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_LOLEVEL); // Interrupt on any GPIO13 edge
// Enable gpio interrupts
ETS_GPIO_INTR_ENABLE();
}
Statistics: Posted by FrenkR — Tue Dec 30, 2014 7:13 am
Statistics: Posted by FrenkR — Sat Dec 27, 2014 9:52 pm