static void task1_handler(void *arg) { struct os_task *t; /* Set the led pin for the E407 devboard */ g_led_pin = LED_BLINK_PIN; hal_gpio_init_out(g_led_pin, 1); console_printf("\nSensors Test App\n"); while (1) { t = os_sched_get_current_task(); assert(t->t_func == task1_handler); ++g_task1_loops; /* Wait one second */ os_time_delay(OS_TICKS_PER_SEC * MYNEWT_VAL(SENSOR_OIC_OBS_RATE)); /* Toggle the LED */ (void)hal_gpio_toggle(g_led_pin); /* Release semaphore to task 2 */ os_sem_release(&g_test_sem); } }
void task1_handler(void *arg) { struct os_task *t; /* Set the led pin for the E407 devboard */ g_led_pin = LED_BLINK_PIN; hal_gpio_init_out(g_led_pin, 1); while (1) { t = os_sched_get_current_task(); assert(t->t_func == task1_handler); ++g_task1_loops; /* Wait one second */ os_time_delay(1000); /* Toggle the LED */ hal_gpio_toggle(g_led_pin); /* Release semaphore to task 2 */ os_sem_release(&g_test_sem); } }
void task1_handler(void *arg) { int rc; /* Set the led pin for the E407 devboard */ g_led_pin = LED_BLINK_PIN; hal_gpio_init_out(g_led_pin, 1); spi_cb_arg = &spi_cb_obj; sblinky_spi_cfg(SPI_SLAVE_ID); hal_spi_enable(SPI_SLAVE_ID); /* Make the default character 0x77 */ hal_spi_slave_set_def_tx_val(SPI_SLAVE_ID, 0x77); /* * Fill buffer with 0x77 for first transfer. This should be a 0xdeadbeef * transfer from master to start things off */ memset(g_spi_tx_buf, 0x77, 32); rc = hal_spi_txrx_noblock(SPI_SLAVE_ID, g_spi_tx_buf, g_spi_rx_buf, 32); while (1) { /* Wait for semaphore from ISR */ os_sem_pend(&g_test_sem, OS_TIMEOUT_NEVER); if (g_spi_xfr_num == 0) { /* Since we dont know what master will send, we fill 0x88 */ memset(g_spi_tx_buf, 0x88, 32); rc = hal_spi_txrx_noblock(SPI_SLAVE_ID, g_spi_tx_buf, g_spi_rx_buf, 32); assert(rc == 0); } else { /* transmit back what we just received */ memcpy(prev_buf, g_spi_tx_buf, 32); memset(g_spi_tx_buf, 0xaa, 32); memcpy(g_spi_tx_buf, g_spi_rx_buf, spi_cb_obj.txlen); rc = hal_spi_txrx_noblock(SPI_SLAVE_ID, g_spi_tx_buf, g_spi_rx_buf, 32); assert(rc == 0); } ++g_spi_xfr_num; /* Toggle the LED */ hal_gpio_toggle(g_led_pin); } }
/** * Main bletest function. Called by the task timer every 50 msecs. * */ void bletest_execute(void) { /* Toggle LED at set rate */ if ((int32_t)(os_time_get() - g_bletest_next_led_time) >= 0) { hal_gpio_toggle(LED_BLINK_PIN); g_bletest_next_led_time = os_time_get() + g_bletest_led_rate; } #if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER) bletest_execute_advertiser(); #endif #if (BLETEST_CFG_ROLE == BLETEST_ROLE_SCANNER) bletest_execute_scanner(); #endif #if (BLETEST_CFG_ROLE == BLETEST_ROLE_INITIATOR) bletest_execute_initiator(); #endif }
void task1_handler(void *arg) { struct os_task *t; int prev_pin_state, curr_pin_state; struct image_version ver; /* Set the led pin for the E407 devboard */ g_led_pin = LED_BLINK_PIN; hal_gpio_init_out(g_led_pin, 1); if (imgr_my_version(&ver) == 0) { console_printf("\nSlinky_OIC %u.%u.%u.%u\n", ver.iv_major, ver.iv_minor, ver.iv_revision, (unsigned int)ver.iv_build_num); } else { console_printf("\nSlinky\n"); } while (1) { t = os_sched_get_current_task(); assert(t->t_func == task1_handler); ++g_task1_loops; /* Wait one second */ os_time_delay(OS_TICKS_PER_SEC); /* Toggle the LED */ prev_pin_state = hal_gpio_read(g_led_pin); curr_pin_state = hal_gpio_toggle(g_led_pin); LOG_INFO(&my_log, LOG_MODULE_DEFAULT, "GPIO toggle from %u to %u", prev_pin_state, curr_pin_state); STATS_INC(g_stats_gpio_toggle, toggles); /* Release semaphore to task 2 */ os_sem_release(&g_test_sem); } }
void task1_handler(void *arg) { int i; int rc; uint16_t rxval; uint8_t last_val; uint8_t spi_nb_cntr; uint8_t spi_b_cntr; /* Set the led pin for the E407 devboard */ g_led_pin = LED_BLINK_PIN; hal_gpio_init_out(g_led_pin, 1); /* Use SS pin for testing */ hal_gpio_init_out(SPI_SS_PIN, 1); sblinky_spi_cfg(0); hal_spi_set_txrx_cb(0, NULL, NULL); hal_spi_enable(0); /* * Send some bytes in a non-blocking manner to SPI using tx val. The * slave should send back 0x77. */ g_spi_tx_buf[0] = 0xde; g_spi_tx_buf[1] = 0xad; g_spi_tx_buf[2] = 0xbe; g_spi_tx_buf[3] = 0xef; hal_gpio_write(SPI_SS_PIN, 0); for (i = 0; i < 4; ++i) { rxval = hal_spi_tx_val(0, g_spi_tx_buf[i]); assert(rxval == 0x77); g_spi_rx_buf[i] = (uint8_t)rxval; } hal_gpio_write(SPI_SS_PIN, 1); ++g_spi_xfr_num; /* Set up the callback to use when non-blocking API used */ hal_spi_disable(0); spi_cb_arg = &spi_cb_obj; spi_cb_obj.txlen = 32; hal_spi_set_txrx_cb(0, sblinky_spi_irqm_handler, spi_cb_arg); hal_spi_enable(0); spi_nb_cntr = 0; spi_b_cntr = 0; while (1) { /* Wait one second */ os_time_delay(OS_TICKS_PER_SEC); /* Toggle the LED */ hal_gpio_toggle(g_led_pin); /* Get random length to send */ g_last_tx_len = spi_cb_obj.txlen; spi_cb_obj.txlen = (rand() & 0x1F) + 1; memcpy(g_spi_last_tx_buf, g_spi_tx_buf, g_last_tx_len); last_val = g_spi_last_tx_buf[g_last_tx_len - 1]; for (i= 0; i < spi_cb_obj.txlen; ++i) { g_spi_tx_buf[i] = (uint8_t)(last_val + i); } if (g_spi_xfr_num & 1) { /* Send non-blocking */ ++spi_nb_cntr; assert(hal_gpio_read(SPI_SS_PIN) == 1); hal_gpio_write(SPI_SS_PIN, 0); #if 0 if (spi_nb_cntr == 7) { g_spi_null_rx = 1; rc = hal_spi_txrx_noblock(0, g_spi_tx_buf, NULL, 32); } else { g_spi_null_rx = 0; rc = hal_spi_txrx_noblock(0, g_spi_tx_buf, g_spi_rx_buf, 32); } assert(!rc); #else g_spi_null_rx = 0; rc = hal_spi_txrx_noblock(0, g_spi_tx_buf, g_spi_rx_buf, spi_cb_obj.txlen); assert(!rc); console_printf("a transmitted: "); for (i = 0; i < spi_cb_obj.txlen; i++) { console_printf("%2x ", g_spi_tx_buf[i]); } console_printf("\n"); console_printf("received: "); for (i = 0; i < spi_cb_obj.txlen; i++) { console_printf("%2x ", g_spi_rx_buf[i]); } console_printf("\n"); #endif } else { /* Send blocking */ ++spi_b_cntr; assert(hal_gpio_read(SPI_SS_PIN) == 1); hal_gpio_write(SPI_SS_PIN, 0); #if 0 if (spi_b_cntr == 7) { g_spi_null_rx = 1; rc = hal_spi_txrx(0, g_spi_tx_buf, NULL, 32); spi_b_cntr = 0; } else { g_spi_null_rx = 0; rc = hal_spi_txrx(0, g_spi_tx_buf, g_spi_rx_buf, 32); } assert(!rc); hal_gpio_write(SPI_SS_PIN, 1); spitest_validate_last(spi_cb_obj.txlen); #else rc = hal_spi_txrx(0, g_spi_tx_buf, g_spi_rx_buf, spi_cb_obj.txlen); assert(!rc); hal_gpio_write(SPI_SS_PIN, 1); console_printf("b transmitted: "); for (i = 0; i < spi_cb_obj.txlen; i++) { console_printf("%2x ", g_spi_tx_buf[i]); } console_printf("\n"); console_printf("received: "); for (i = 0; i < spi_cb_obj.txlen; i++) { console_printf("%2x ", g_spi_rx_buf[i]); } console_printf("\n"); spitest_validate_last(spi_cb_obj.txlen); ++g_spi_xfr_num; #endif } } }