Exemplo n.º 1
0
/* This is an entry point for the application.
   All application specific initialization is performed here. */
int main(void)
{
	int ret = 0;

	/* Initializes console on UART0 */
	ret = wmstdio_init(UART0_ID, 0);
	if (ret == -WM_FAIL) {
		wmprintf("Failed to initialize console on uart0\r\n");
		return -1;
	}

	wmprintf(" LED demo application started\r\n");
	wmprintf(" This application demonstrates the"
		 " use of blinking led\r\n");

	gpio_led = (board_led_2()).gpio;

	wmprintf(" LED Pin : %d\r\n", gpio_led);

	configure_gpios();
	while (1) {
		gpio_led_on();
		os_thread_sleep(os_msec_to_ticks(1000));
		gpio_led_off();
		os_thread_sleep(os_msec_to_ticks(1000));
	}
	return 0;
}
Exemplo n.º 2
0
/* Write data from SSP master after every 100msec */
static void ssp_master_write(os_thread_arg_t data)
{
	int len, i, j;

	wmprintf("SSP Writer Application Started\r\n");

	i = 0;
	while (1) {
		i++;
		/* Write random number of random bytes */
		len = rand() % BUF_LEN;
		for (j = 0; j < len; j++)
			write_data[j] = rand();

		/* Write data on SSP bus */
		len = ssp_drv_write(ssp, write_data, NULL, len, 0);
		wmprintf("Write iteration %d: data_len = %d\n\r", i, len);

		for (j = 0; j < len ; j++) {
			if ((j % 16) == 0)
				wmprintf("\n\r");
			wmprintf("%02x ", write_data[j]);
		}
		if (len)
			wmprintf("\n\r\n\r");

		os_thread_sleep(os_msec_to_ticks(100));
	}
}
Exemplo n.º 3
0
void
mc_usb_fin()
{
	usb_exit++;
	os_thread_sleep(os_msec_to_ticks(USB_READ_TIMEOUT));	/* wait for the thread to termiante */
	/* no API to deactivate USB! at least the thread has to be stopped... */
}
Exemplo n.º 4
0
int
mc_usb_init()
{
	if (usb_device_system_init(USB_CDC) != WM_SUCCESS) {
		int i;
		wmprintf("usb_stdio_init failed\r\n");
		for (i = 0; i < MC_MAX_LED_PINS; i++)
			GPIO_WritePinOutput(mc_conf.led_pins[i], GPIO_IO_HIGH);
		GPIO_WritePinOutput(mc_conf.led_pins[0], GPIO_IO_LOW);	/* red */
		os_thread_sleep(5000);
		return -1;
	}
	os_thread_sleep(1000);
	mc_thread_create(usb_thread_main, NULL, -1);	/* create a thread for USB input */
	return 0;
}
Exemplo n.º 5
0
int
mc_usb_write(void *buf, size_t n)
{
	unsigned long t, d;
	uint8_t *p;
	int ret = -1;

	if (n > USB_BUF_SIZE)
		goto bail;
	if (!USBActive())
		goto bail;
	t = os_ticks_get();
	d = t < usb_last_tick ? ~0UL - usb_last_tick + t : t - usb_last_tick;
	if (d >= USB_TIMEOUT_TICKS) {
		usb_buf_ptr = 0;
		usb_last_tick = os_ticks_get();
	}
	if (usb_buf_ptr + n > USB_BUF_SIZE) {
		usb_buf_ptr = 0;
		if (d < USB_TIMEOUT_TICKS)
			os_thread_sleep(USB_TIMEOUT_TICKS);
		usb_last_tick = os_ticks_get();
	}
	p = &usb_buf[usb_buf_ptr];
	memcpy(p, buf, n);
	if (usb_drv_write(p, n) != (int)n)
		goto bail;
	usb_buf_ptr += n;
	ret = 0;
bail:
	return ret;
}
Exemplo n.º 6
0
/***********************************************************//**
Removes a secondary index entry if possible. */
UNIV_INLINE
void
row_purge_remove_sec_if_poss(
    /*=========================*/
    purge_node_t*	node,	/*!< in: row purge node */
    dict_index_t*	index,	/*!< in: index */
    dtuple_t*	entry)	/*!< in: index entry */
{
    ibool	success;
    ulint	n_tries		= 0;

    /*	fputs("Purge: Removing secondary record\n", stderr); */

    if (row_purge_remove_sec_if_poss_leaf(node, index, entry)) {

        return;
    }
retry:
    success = row_purge_remove_sec_if_poss_tree(node, index, entry);
    /* The delete operation may fail if we have little
    file space left: TODO: easiest to crash the database
    and restart with more file space */

    if (!success && n_tries < BTR_CUR_RETRY_DELETE_N_TIMES) {

        n_tries++;

        os_thread_sleep(BTR_CUR_RETRY_SLEEP_TIME);

        goto retry;
    }

    ut_a(success);
}
Exemplo n.º 7
0
/***********************************************************//**
Removes a clustered index record if it has not been modified after the delete
marking. */
static
void
row_purge_remove_clust_if_poss(
    /*===========================*/
    purge_node_t*	node)	/*!< in: row purge node */
{
    ibool	success;
    ulint	n_tries	= 0;

    /*	fputs("Purge: Removing clustered record\n", stderr); */

    success = row_purge_remove_clust_if_poss_low(node, BTR_MODIFY_LEAF);
    if (success) {

        return;
    }
retry:
    success = row_purge_remove_clust_if_poss_low(node, BTR_MODIFY_TREE);
    /* The delete operation may fail if we have little
    file space left: TODO: easiest to crash the database
    and restart with more file space */

    if (!success && n_tries < BTR_CUR_RETRY_DELETE_N_TIMES) {
        n_tries++;

        os_thread_sleep(BTR_CUR_RETRY_SLEEP_TIME);

        goto retry;
    }

    ut_a(success);
}
Exemplo n.º 8
0
/*******************************************************************//**
Rollback a transaction used in MySQL.
@return	error code or DB_SUCCESS */
UNIV_INTERN
int
trx_general_rollback_for_mysql(
/*===========================*/
	trx_t*		trx,	/*!< in: transaction handle */
	trx_savept_t*	savept)	/*!< in: pointer to savepoint undo number, if
				partial rollback requested, or NULL for
				complete rollback */
{
	mem_heap_t*	heap;
	que_thr_t*	thr;
	roll_node_t*	roll_node;

	/* Tell Innobase server that there might be work for
	utility threads: */

	srv_active_wake_master_thread();

	trx_start_if_not_started(trx);

	heap = mem_heap_create(512);

	roll_node = roll_node_create(heap);

	if (savept) {
		roll_node->partial = TRUE;
		roll_node->savept = *savept;
	}

	trx->error_state = DB_SUCCESS;

	thr = pars_complete_graph_for_exec(roll_node, trx, heap);

	ut_a(thr == que_fork_start_command(que_node_get_parent(thr)));
	que_run_threads(thr);

	mutex_enter(&kernel_mutex);

	while (trx->que_state != TRX_QUE_RUNNING) {

		mutex_exit(&kernel_mutex);

		os_thread_sleep(100000);

		mutex_enter(&kernel_mutex);
	}

	mutex_exit(&kernel_mutex);

	mem_heap_free(heap);

	ut_a(trx->error_state == DB_SUCCESS);

	/* Tell Innobase server that there might be work for
	utility threads: */

	srv_active_wake_master_thread();

	return((int) trx->error_state);
}
static void dhcp_cli(int argc, char **argv)
{
	void *intrfc_handle = NULL;
	int wait_for_sec = WAIT_FOR_UAP_START;

	if (argc >= 3 && string_equal(argv[2], "start")) {
		if (!strncmp(argv[1], "mlan0", 5))
			intrfc_handle = net_get_mlan_handle();
		else if (!strncmp(argv[1], "uap0", 4)) {
			while(wait_for_sec) {
				wait_for_sec--;
				if (!is_uap_started()) {
					if (wait_for_sec == 0) {
						dhcp_e("unable"
						" to start DHCP server. Retry"
						" after uAP is started");
						return;
					}
				} else
					break;
				os_thread_sleep(os_msec_to_ticks(1000));
			}
			intrfc_handle = net_get_uap_handle();
		}

		if (dhcp_server_start(intrfc_handle))
			dhcp_e("unable to "
				       "start DHCP server");
	} else if (argc >= 3 && string_equal(argv[2], "stop"))
		dhcp_server_stop();
	else {
		wmprintf("Usage: %s %s\r\n", DHCPS_COMMAND, DHCPS_HELP);
		wmprintf("Error: invalid argument\r\n");
	}
}
void check_ultrasonic_sensor(void)
{
	while(1) {
		ultrasonic_sensor_input_scan(&event_ultrasonic_sensor);
		os_thread_sleep(1000);
	}
}
Exemplo n.º 11
0
/**********************************************************//**
Returns system time.
Upon successful completion, the value 0 is returned; otherwise the
value -1 is returned and the global variable errno is set to indicate the
error.
@return	0 on success, -1 otherwise */
UNIV_INTERN
int
ut_usectime(
/*========*/
	ulint*	sec,	/*!< out: seconds since the Epoch */
	ulint*	ms)	/*!< out: microseconds since the Epoch+*sec */
{
	struct timeval	tv;
	int		ret;
	int		errno_gettimeofday;
	int		i;

	for (i = 0; i < 10; i++) {

		ret = ut_gettimeofday(&tv, NULL);

		if (ret == -1) {
			errno_gettimeofday = errno;
			ut_print_timestamp(stderr);
			fprintf(stderr, "  InnoDB: gettimeofday(): %s\n",
				strerror(errno_gettimeofday));
			os_thread_sleep(100000);  /* 0.1 sec */
			errno = errno_gettimeofday;
		} else {
			break;
		}
	}

	if (ret != -1) {
		*sec = (ulint) tv.tv_sec;
		*ms  = (ulint) tv.tv_usec;
	}

	return(ret);
}
Exemplo n.º 12
0
static int
i2c_write_bytes(wm_i2c *i2c, int reg, uint8_t *data, int datasize)
{
	int retry = 60;
	int i;

	do {
		if (reg >= 0) {
			if (!i2c_write_byte(i2c, reg))
				return false;
		}
		for (i = 0; i < datasize; i++)
			if (!i2c_write_byte(i2c, data[i]))
				return false;
		
		if (!(i2c->reg->RAW_INTR_STAT.WORDVAL & 0x40 /* TX ABRT */))
			break;
		os_thread_sleep(os_msec_to_ticks(10));
#if I2C_VERBOSE > 1
		mc_log_debug("I2C: xmit aborted [%d]: cause = 0x%x.\n", retry, i2c_get_abort_cause(i2c));
#endif
		i2c_clear_abort(i2c);
		
	} while (--retry >= 0);
#if I2C_VERBOSE
	if (retry < 0)
		mc_log_debug("I2C: xmit aborted!\n");
#endif
	return (retry >= 0);
}
Exemplo n.º 13
0
static void __write_to_lcd(mdev_t *dev, const char *line1, const char *line2)
{
	mdev_t *i2c_dev;
	int temp;

	memset(lcd_buff, 0, sizeof(lcd_buff));

	os_thread_sleep(os_msec_to_ticks(35));
	i2c_dev = i2c_drv_open(dev->private_data,
			I2C_SLAVEADR(I2C_LCD_ADDR >> 1));
	if (i2c_dev == NULL) {
		lcd_d("I2C driver init is required before open");
		return;
	}

	lcd_buff[0] = LCD_CMD_CONFIG_MODE;

	/* Set DDRAM Address to line 1
	 * Bits: 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0
	 * AC6-0: The address to be written to:
	 * 00H: line 1
	 * 40H: line 2
	 */
	lcd_buff[1] = 0x80;
	lcd_buff[2] = 0x06;	/* Entry mode as mentioned above */
	os_thread_sleep(os_msec_to_ticks(35));
	temp = os_enter_critical_section();
	i2c_drv_write(i2c_dev, (uint8_t *) lcd_buff, 2);
	os_exit_critical_section(temp);

	/* Write data */
	lcd_buff[0] = LCD_CMD_DATA_MODE;

	if (line1)
		write_line1(lcd_buff, line1);

	if (line2)
		write_line2(lcd_buff, line2);

	os_thread_sleep(os_msec_to_ticks(35));
	temp = os_enter_critical_section();
	i2c_drv_write(i2c_dev, (uint8_t *) lcd_buff, end_of_line2(lcd_buff));
	os_exit_critical_section(temp);
	i2c_drv_close(i2c_dev);
}
Exemplo n.º 14
0
void
buf_read_ibuf_merge_pages(
/*======================*/
	ibool	sync,		/* in: TRUE if the caller wants this function
				to wait for the highest address page to get
				read in, before this function returns */
	ulint*	space_ids,	/* in: array of space ids */
	ib_longlong* space_versions,/* in: the spaces must have this version
				number (timestamp), otherwise we discard the
				read; we use this to cancel reads if
				DISCARD + IMPORT may have changed the
				tablespace size */
	ulint*	page_nos,	/* in: array of page numbers to read, with the
				highest page number the last in the array */
	ulint	n_stored)	/* in: number of page numbers in the array */
{
	ulint	err;
	ulint	i;

	ut_ad(!ibuf_inside());
#ifdef UNIV_IBUF_DEBUG
	ut_a(n_stored < UNIV_PAGE_SIZE);
#endif
	while (buf_pool->n_pend_reads
	       > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
		os_thread_sleep(500000);
	}

	for (i = 0; i < n_stored; i++) {
		buf_read_page_low(&err,
				  (i + 1 == n_stored) && sync,
				  BUF_READ_ANY_PAGE,
				  space_ids[i], space_versions[i],
				  page_nos[i]);

		if (err == DB_TABLESPACE_DELETED) {
			/* We have deleted or are deleting the single-table
			tablespace: remove the entries for that page */

			ibuf_merge_or_delete_for_page(NULL, space_ids[i],
						      page_nos[i], FALSE);
		}
	}

	os_aio_simulated_wake_handler_threads();

	/* Flush pages from the end of the LRU list if necessary */
	buf_flush_free_margin();

#ifdef UNIV_DEBUG
	if (buf_debug_prints) {
		fprintf(stderr,
			"Ibuf merge read-ahead space %lu pages %lu\n",
			(ulong) space_ids[0], (ulong) n_stored);
	}
#endif /* UNIV_DEBUG */
}
Exemplo n.º 15
0
void
ut_dbg_stop_thread(
/*===============*/
	const char*	file,
	ulint		line)
{
	fprintf(stderr, "InnoDB: Thread %lu stopped in file %s line %lu\n",
		os_thread_pf(os_thread_get_curr_id()), file, line);
	os_thread_sleep(1000000000);
}
Exemplo n.º 16
0
/* This is the main event handler for this project. The application framework
 * calls this function in response to the various events in the system.
 */
int common_event_handler(int event, void *data)
{
    int ret;
    static bool is_cloud_started;
    switch (event) {
    case AF_EVT_WLAN_INIT_DONE:
        ret = psm_cli_init();
        if (ret != WM_SUCCESS)
            wmprintf("Error: psm_cli_init failed\r\n");
        int i = (int) data;

        if (i == APP_NETWORK_NOT_PROVISIONED) {
            wmprintf("\r\nPlease provision the device "
                     "and then reboot it:\r\n\r\n");
            wmprintf("psm-set network ssid <ssid>\r\n");
            wmprintf("psm-set network security <security_type>"
                     "\r\n");
            wmprintf("    where: security_type: 0 if open,"
                     " 3 if wpa, 4 if wpa2\r\n");
            wmprintf("psm-set network passphrase <passphrase>"
                     " [valid only for WPA and WPA2 security]\r\n");
            wmprintf("psm-set network configured 1\r\n");
            wmprintf("pm-reboot\r\n\r\n");
        } else
            app_sta_start();

        break;
    case AF_EVT_NORMAL_CONNECTED:
        set_device_time();
        if (!is_cloud_started) {
            configure_gpios();
            os_thread_sleep(2000);
            ret = os_thread_create(
                      /* thread handle */
                      &app_thread,
                      /* thread name */
                      "evrythng_demo_thread",
                      /* entry function */
                      evrythng_task,
                      /* argument */
                      0,
                      /* stack */
                      &app_stack,
                      /* priority - medium low */
                      OS_PRIO_3);
            is_cloud_started = true;
        }
        break;
    default:
        break;
    }

    return 0;
}
Exemplo n.º 17
0
void miio_app_test_thread(void* arg)
{
    /*if(STATE_OK == sell_ready()){
     LOG_INFO("==================\r\n");
     LOG_INFO(" OK. Sell ready. \r\n");
     LOG_INFO("==================\r\n");
     }*/

    while (1) {
        os_thread_sleep(os_msec_to_ticks(500));
    }
}
Exemplo n.º 18
0
/*************************************************************//**
Stop a thread after assertion failure. */
UNIV_INTERN
void
ut_dbg_stop_thread(
/*===============*/
	const char*	file,
	ulint		line)
{
#ifndef UNIV_HOTBACKUP
	fprintf(stderr, "InnoDB: Thread %lu stopped in file %s line %lu\n",
		os_thread_pf(os_thread_get_curr_id()), file, line);
	os_thread_sleep(1000000000);
#endif /* !UNIV_HOTBACKUP */
}
Exemplo n.º 19
0
int report_ap_info_change_event()
{
#define JS_BUF_LEN (128)

   char *js_buf = malloc(JS_BUF_LEN);
   if(!js_buf) {
       LOG_ERROR("no enough mem to report event\r\n");
       
       //clear flags
       clear_ap_info_change_flag();
       return -1;
   }

   int n = snprintf_safe(js_buf,JS_BUF_LEN,"{\"method\":\"event.router_changed\",\"params\":");
   
   if(ap_info_change == ANY_ONE) {
       n += snprintf_safe(js_buf+n,JS_BUF_LEN - n,"\"ssid or passwd changed\"}");
   } else {
       n += snprintf_safe(js_buf+n,JS_BUF_LEN-n,"\""); 

       if(is_ssid_changed()) {
           n += snprintf_safe(js_buf+n,JS_BUF_LEN -n,"ssid changed ");
       }

       if(is_passwd_changed()) {
           n += snprintf_safe(js_buf+n,JS_BUF_LEN-n,"passwd changed");
       }
   
       n += snprintf_safe(js_buf+n,JS_BUF_LEN-n,"\"}");
   }

   LOG_DEBUG("report :len is %d %s \r\n",n,js_buf);

   //clear flags
   clear_ap_info_change_flag();
   
   report_success = false;
   int retry_count = 3;

   while(!report_success && retry_count > 0) {
       ot_api_method(js_buf,n,report_ack, NULL);
       retry_count --; 

       //it's diffcult to query ot status, so just wait
       os_thread_sleep(3000);
   }

   free(js_buf);

   return 0;
}
Exemplo n.º 20
0
void miio_app_thread(void* arg)
{
    static bool has_sync_time = false;
    g_mum = mum_create();

//*****************************button init*******************************/
    os_timer_create(&g_reset_prov_timer, "reset-prov-timer", os_msec_to_ticks(4000), reset_prov, NULL,
            OS_TIMER_ONE_SHOT, OS_TIMER_NO_ACTIVATE);

    button_frame_work_init();
    register_button_callback(0, button_1_press_handle);

    if (WM_SUCCESS != os_semaphore_create(&btn_pressed_sem, "btn_pressed_sem")) {
        LOG_ERROR("btn_pressed_sem creation failed\r\n");
    }
    else if (WM_SUCCESS != os_semaphore_get(&btn_pressed_sem, OS_WAIT_FOREVER)) {
        LOG_ERROR("first get btn_pressed_sem failed.\r\n");
    }
//******************************button init end*******************************************/

    local_timer_init();//add by [email protected]

    miio_led_on();
    LOG_INFO("miio_app_thread while loop start.\r\n");

#ifdef MIIO_COMMANDS_DEBUG
    while(!ot_api_is_online())api_os_tick_sleep(100);
    uart_wifi_debug_init();
#endif
    while (1) {
        if (WM_SUCCESS == os_semaphore_get(&btn_pressed_sem, OS_NO_WAIT)) {
                mum_set_property(g_mum,"button_pressed","\"wifi_rst\"");
        }

        if(has_sync_time)//only after sync time, we start check timer
            check_schedule_and_set_timer();
        else if(otn_is_online())
            has_sync_time = true;

        os_thread_sleep(os_msec_to_ticks(PERIOD_CHECK_BUTTON));
    }

    local_timer_deinit();//add by [email protected]

//*****************************button deinit*******************************/
    mum_destroy(&g_mum);
    os_timer_delete(&g_reset_prov_timer);
    os_semaphore_delete(&btn_pressed_sem);
//******************************button deinit end*******************************************/
}
bool CO2_dataRecieve(void)
{
    uint8_t data[9];
    int i, len, sz;

    /* transmit command data */
    os_mutex_get(&co2uart_mutex, OS_WAIT_FOREVER);
    uart_drv_write(uart2_dev, cmd_get_sensor, 9); //sizeof(cmd_get_sensor));
    os_mutex_put(&co2uart_mutex);

    os_thread_sleep(10); /* delay of 10 milisecs */

    /* begin reveiceing data */
    for(i = 0; i < 9; i++) {
        len = 0;
        while(len++ < 100) { /* Ready each byte until it is received, timeout 100msec*/
            sz = uart_drv_read(uart2_dev, &data[i], 1);
            if (sz == 1) {
                /* If a bute is read then store and move to next */
                break;
            } else
                os_thread_sleep(1); /* delay of 1 milisecs */
        }
    }

    if((i != 9) || (1 + (0xFF ^ (uint8_t)(data[1] + data[2] + data[3]
                                          + data[4] + data[5] + data[6] + data[7]))) != data[8]) {
        wmprintf("Received Data Checksum Error\r\n");
        return false;
    }

    CO2PPM = (int)data[2] * 256 + (int)data[3];
    temperature = (int)data[4] - 40;

    wmprintf("Tempr: %d, CORPPM: %d\r\n", temperature, CO2PPM);
    return true;
}
Exemplo n.º 22
0
static int
i2c_wait_tx_fifo(wm_i2c *i2c)
{
	int tcnt;
	uint32_t toticks = os_msec_to_ticks(10);

	/* sending the stop sequence by emptying the TX FIFO */
	for (tcnt = 10; !(i2c->reg->STATUS.WORDVAL & 0x04 /* TFE */) && --tcnt >= 0;)
		os_thread_sleep(toticks);
#if I2C_VERBOSE
	if (tcnt < 0)
		mc_log_debug("I2C: TX FIFO can't be empty! STATUS = 0x%x\n", i2c->reg->STATUS.WORDVAL);
#endif
	return tcnt >= 0;
}
Exemplo n.º 23
0
/** Synchronous wait for an master command to be finished...
 * The calling thread blocks (sleeps)
 */
TMasterCmdResult TMasterCmd_WaitFor( TMasterCmdReq * me )
{
   /* Zur Zeit einfach polling...*/
   /* Wenn kein Scheduling stattfindet, dann nicht mehr warten */
   while( !me->isResultValid && TSchedule_IsScheduling() )
   {
      #ifdef YASDI_NO_THREADS
      TSchedule_MainExecute();
      #endif
   
      os_thread_sleep( YASDI_SCHEDULER_DELAY_TIME );
   }

   return me->Result;
}
Exemplo n.º 24
0
static void
usb_thread_main(void *args)
{
	uint8_t c;
	uint8_t buf[MAX_MSG_LEN], *bp = buf, *bend = buf + sizeof(buf);
	uint8_t crnl[2] = {'\r', '\n'};		/* usb can't transfer data in the .ro section?? */
	uint8_t bs[3] = {'\b', ' ', '\b'};
#define CTRL(c)	(c - 'A' + 1)
#define ISPRINT(c)	((c) >= 0x20 && (c) < 0x7f)

	while (!usb_exit) {
		int ret = usb2Read(&c, 1, USB_READ_TIMEOUT, USB_ENDPOINT);
		if (ret <= 0) {
			if (ret != CONIO_TIMEOUT)
				os_thread_sleep(os_msec_to_ticks(1000));
			continue;
		}
		if (c == '\n' || c == '\r') {
			if (bp < bend)
				*bp = '\0';
			else
				*(bp - 1) = '\0';
			usb_drv_write(crnl, 2);
			mc_event_thread_call(usb_callback, buf, 0);
			bp = buf;
		}
		else if (c == '\b' || c == '\x7f') {
			if (bp > buf) {
				--bp;
				usb_drv_write(bs, 3);
			}
		}
		else if (c == CTRL('U')) {
			while (bp > buf) {
				--bp;
				usb_drv_write(bs, 3);
			}
		}
		else {
			if (bp < bend) {
				*bp = c;
				usb_drv_write(bp, 1);
				bp++;
			}
		}
	}
}
Exemplo n.º 25
0
/*****************************************************************//**
Advises the os to give up remainder of the thread's time slice. */
UNIV_INTERN
void
os_thread_yield(void)
/*=================*/
{
#if defined(__WIN__)
	SwitchToThread();
#elif (defined(HAVE_SCHED_YIELD) && defined(HAVE_SCHED_H))
	sched_yield();
#elif defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
	pthread_yield();
#elif defined(HAVE_PTHREAD_YIELD_ONE_ARG)
	pthread_yield(0);
#else
	os_thread_sleep(0);
#endif
}
Exemplo n.º 26
0
/**
 * All application specific initializations are performed here.
 */
int main(void)
{
	int i = 0;

	/* Initialize wmstdio console */
	wmstdio_init(UART0_ID, 0);
	wmprintf("SSP Display Application Started\r\n");

	display_init();

	while (1) {
		change_display_data(colors[i++ % no_colors]);
		display_update(frame_buf);
		os_thread_sleep(2000);
	}

	return 0;
}
Exemplo n.º 27
0
static void report_reset_event()
{
#define JS_BUF_LEN (64)

   char *js_buf = malloc(JS_BUF_LEN);
   if(!js_buf) {
       return;
   }

   int n = snprintf_safe(js_buf,JS_BUF_LEN,"{\"method\":\"event.dev_is_reset\",\"params\":\"\"}");

   LOG_DEBUG("report :len is %d %s \r\n",n,js_buf);

   ot_api_method(js_buf,n, NULL, NULL);

   //make sure the report is send out before reboot, but do not assure reach the server
   os_thread_sleep(100);

   free(js_buf);
}
Exemplo n.º 28
0
/*******************************************************************
Removes a secondary index entry from the index if found. Tries first
optimistic, then pessimistic descent down the tree. */
static
ulint
row_undo_ins_remove_sec(
/*====================*/
				/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
	dict_index_t*	index,	/* in: index */
	dtuple_t*	entry,	/* in: index entry to insert */
	que_thr_t*	thr)	/* in: query thread */
{
	ulint	err;
	ulint	n_tries	= 0;
	
	/* Try first optimistic descent to the B-tree */

	err = row_undo_ins_remove_sec_low(BTR_MODIFY_LEAF, index, entry, thr);
								
	if (err == DB_SUCCESS) {

		return(err);
	}

	/* Try then pessimistic descent to the B-tree */
retry:
	err = row_undo_ins_remove_sec_low(BTR_MODIFY_TREE, index, entry, thr);

	/* The delete operation may fail if we have little
	file space left: TODO: easiest to crash the database
	and restart with more file space */

	if (err != DB_SUCCESS && n_tries < BTR_CUR_RETRY_DELETE_N_TIMES) {

		n_tries++;

		os_thread_sleep(BTR_CUR_RETRY_SLEEP_TIME);
			
		goto retry;
	}

	return(err);
}
Exemplo n.º 29
0
/* Function to read Integer portion of gas value */
float getGasSensorData(void)
{
        int avgdata=0;

	if (adc_dev == NULL)
		return -1;

	adc_dev = adc_drv_open(ADC0_ID, GASSEN_ADCCH);

#ifdef ADC_DMA
	adc_drv_get_samples(adc_dev, buffer, samples);
        for (i=0;i<samples;++i) {
		avgdata+=buffer[i];
	}
        avgdata/=samples;
#else
        for (i=0;i<ITERATIONS;++i) {
		avgdata += adc_drv_result(adc_dev);
		os_thread_sleep(5);
        }
        avgdata/=ITERATIONS;
#endif

	adc_drv_close(adc_dev);

	/* Convert ADC Value to the milivolts, Ref: io_demo/adc sample app */
	result = ((float)avgdata / BIT_RESOLUTION_FACTOR)
		* VMAX_IN_mV
		* ((float)1/(float)(config.adcGainSel != 0 ?
				config.adcGainSel : 0.5));

	dbg("ADC val=%d, milivolts %d.%d\r\n",
			avgdata,
			wm_int_part_of(result),
			wm_frac_part_of(result, 2));

	return result;
}
Exemplo n.º 30
0
/***************************************************************
Removes a secondary index entry if possible. */
UNIV_INLINE
void
row_purge_remove_sec_if_poss(
/*=========================*/
	purge_node_t*	node,	/* in: row purge node */
	que_thr_t*	thr,	/* in: query thread */
	dict_index_t*	index,	/* in: index */
	dtuple_t*	entry)	/* in: index entry */
{
	ibool	success;
	ulint	n_tries		= 0;
	
/*	printf("Purge: Removing secondary record\n"); */

	success = row_purge_remove_sec_if_poss_low(node, thr, index, entry,
							BTR_MODIFY_LEAF);
	if (success) {

		return;
	}
retry:
	success = row_purge_remove_sec_if_poss_low(node, thr, index, entry,
							BTR_MODIFY_TREE);
	/* The delete operation may fail if we have little
	file space left: TODO: easiest to crash the database
	and restart with more file space */

	if (!success && n_tries < BTR_CUR_RETRY_DELETE_N_TIMES) {
				
		n_tries++;

		os_thread_sleep(BTR_CUR_RETRY_SLEEP_TIME);
							
		goto retry;
	}

	ut_a(success);
}