Пример #1
0
static void
wait_interrupt(struct lis2dw12_int * interrupt, uint8_t int_num)
{
    bool wait;

    OS_ENTER_CRITICAL(interrupt->lock);

    /* Check if we did not missed interrupt */
    if (hal_gpio_read(interrupt->ints[int_num].host_pin) ==
                                            interrupt->ints[int_num].active) {
        OS_EXIT_CRITICAL(interrupt->lock);
        return;
    }

    if (interrupt->active) {
        interrupt->active = false;
        wait = false;
    } else {
        interrupt->asleep = true;
        wait = true;
    }
    OS_EXIT_CRITICAL(interrupt->lock);

    if (wait) {
        os_error_t error;

        error = os_sem_pend(&interrupt->wait, -1);
        assert(error == OS_OK);
    }
}
Пример #2
0
static void 
sem_test_1_task1_handler(void *arg)
{
    os_error_t err;
    struct os_task *t;
    int i;;

    for (i = 0; i < 3; i++) {
        t = os_sched_get_current_task();
        TEST_ASSERT(t->t_func == sem_test_1_task1_handler);


        err = os_sem_pend(&g_sem1, 0);
        TEST_ASSERT(err == OS_OK);

        /* Sleep to let other tasks run */
        os_time_delay(100);

        /* Release the semaphore */
        err = os_sem_release(&g_sem1);
        TEST_ASSERT(err == OS_OK);

        /* Sleep to let other tasks run */
        os_time_delay(100);
    }

    os_test_restart();
}
Пример #3
0
static void _display_task( void*arg )
{
	Bsize_t 	page = 0;
	int     	start_n = 2,end_n= 19;
	DL_flag_t 	dl_flag;
	float 		XBdata[6][52];
	GLOBAL_MEMCLR(XBdata,sizeof(float)*6*52);
	_WINpaint();
	while(1)
	{
		if ( os_task_delete_req( SELF_PRO ) == OS_TASK_DEL_REQ )
		{
			os_task_delete( SELF_PRO );   			
		}
		if(os_sem_pend(_sem,APP_100_MS*5) == OS_NO_ERR )
		{
		    page       = _GR_CURpage;
			start_n    = 2+17*page;
			end_n      = start_n+17; 
			_XBtimes_view(start_n,end_n);
			os_driver_ioctl(g_DL_dev,MEASURE_CMD_XBDATA_GET,XBdata);
			_XBview(start_n,end_n,XBdata);
		}
		app_global_DLflag_obtain(&dl_flag);
		if(dl_flag.DL_XB_is_new)
		{
			os_driver_ioctl(g_DL_dev,MEASURE_CMD_XBDATA_GET,XBdata);
			_XBview(start_n,end_n,XBdata);
		}
	}
}
Пример #4
0
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);
    }
}
Пример #5
0
/********************************************************************
 * @创建人 :揭成
 * @功能 :WAVE模块显示任务
 * @输入 :NONE
 *@输出  :NONE
********************************************************************/
static void _GRdisplay_task( void*arg )
{
	Bsize_t 	page 	= 0;
	BOOL    	Is_sort = 0;
	int     	start_n = 2,end_n = 19;
	hwin_t* 	checkbox,*phaseR;
	DL_flag_t 	dl_flag;
	GLOBAL_MEMCLR(_GR_XBdata,sizeof(float)*6*52);
	app_XBmod_window_create();
	phaseR   = GET_DOBJ(2);
	_phaseR  = phaseR;
	checkbox = GUI_childobj_obtian(GUI_KEY_SELECT_WAY,WIDGET_CHECK_BOX,GET_DOBJ(2));
	GUI_radio_select(phaseR,0);
	while(1)
	{
		if ( os_task_delete_req( SELF_PRO ) == OS_TASK_DEL_REQ )
		{
			os_task_delete( SELF_PRO );   			
		}
		if(os_sem_pend(_GR_sem,APP_100_MS*5) == OS_NO_ERR )
		{
		    page       = _GR_CURpage;
			_GR_CURxb_pos = GUI_radio_curmember_obtain(phaseR)*2;
            Is_sort    = GUI_checkbox_state_obtain(checkbox);
			start_n    = 2+17*page;
			end_n      = start_n+17; 
			app_XBmod_ruler_clean();
			os_driver_ioctl(g_DL_dev,MEASURE_CMD_XBDATA_GET,_GR_XBdata);
			_GRXBview(start_n,end_n,Is_sort);
			GUI_window_hwin_req(GET_DOBJ(2));
			GUI_set_Bgcolor(GUI_GetwinBgcor());
			GUI_set_Fgcolor(C_GUI_WHITE);
			GUI_SetFront(&GUI_HZK16_EXTASCII);
		    GUI_string_display_At(2,10,"第");
		    GUI_int_display(page+1);
		    GUI_string_display("页");
			GUI_window_hwin_release(GET_DOBJ(2));	
		}
		app_global_DLflag_obtain(&dl_flag);
		if(dl_flag.DL_XB_is_new)
		{
			os_driver_ioctl(g_DL_dev,MEASURE_CMD_XBDATA_GET,_GR_XBdata);
	        _GRXBview(start_n,end_n,Is_sort);
		}

	}
}
Пример #6
0
static void
sem_test_pend_release_loop(int delay, int timeout, int itvl)
{
    os_error_t err;

    os_time_delay(delay);

    while (1) {
        err = os_sem_pend(&g_sem1, timeout);
        TEST_ASSERT(err == OS_OK);

        err = os_sem_release(&g_sem1);
        TEST_ASSERT(err == OS_OK);

        os_time_delay(itvl);
    }
}
Пример #7
0
void
task2_handler(void *arg)
{
    struct os_task *t;

    while (1) {
        /* just for debug; task 2 should be the running task */
        t = os_sched_get_current_task();
        assert(t->t_func == task2_handler);

        /* Increment # of times we went through task loop */
        ++g_task2_loops;

        /* Wait for semaphore from ISR */
        os_sem_pend(&g_test_sem, OS_TIMEOUT_NEVER);
    }
}
Пример #8
0
u32_t
sys_arch_sem_wait(sys_sem_t *sem, u32_t timo)
{
    u32_t now;

    if (timo == 0) {
        timo = OS_WAIT_FOREVER;
    } else {
        if (os_time_ms_to_ticks(timo, &timo)) {
            timo = OS_WAIT_FOREVER - 1;
        }
    }
    now = os_time_get();
    if (os_sem_pend(sem, timo) == OS_TIMEOUT) {
        return SYS_ARCH_TIMEOUT;
    }
    return (now - os_time_get()) * 1000 / OS_TICKS_PER_SEC;
}
Пример #9
0
/********************************************************************
 * @创建人:揭成
 * @功能 : 蜂鸣任务主体,等待蜂鸣实践的到来
 *
 * @输入 :p_arg 任务参数
 *
 *@输出  :NONE
********************************************************************/
static void app_global_buz_task( void *p_arg )
{
	msleep( TYPE_DELAY );
	while ( 1 )
	{
		if ( os_task_delete_req( SELF_PRO ) == OS_TASK_DEL_REQ )/*判断是否有删除请求*/
		{
			os_task_delete( SELF_PRO );   			      		/*收到删除请求,删除自身任务*/
		}
		if ( os_sem_pend( m_buz_sem, 0) == OS_NO_ERR )			/*等待信号*/
		{
			os_lock( m_buz_lock );
			while ( m_buz_ctl_buf.ctl_times > 0 )  				/*判断响应次数*/
			{
	    		BUZ_ON();
				msleep( m_buz_ctl_buf.alarm_time );				/*等待响应节拍*/
				BUZ_OFF();
				msleep( m_buz_ctl_buf.stop_time ); 				/*等待关时间节拍*/
				m_buz_ctl_buf.ctl_times--;		   				/*响应次数减*/
			}
			os_unlock( m_buz_lock );
		}
	}
}
Пример #10
0
/**
 * sem test basic 
 *  
 * Basic semaphore tests
 * 
 * @return int 
 */
static void 
sem_test_basic_handler(void *arg)
{
    struct os_task *t;
    struct os_sem *sem;
    os_error_t err;

    sem = &g_sem1;
    t = os_sched_get_current_task();

    /* Test some error cases */
    TEST_ASSERT(os_sem_init(NULL, 1)    == OS_INVALID_PARM);
    TEST_ASSERT(os_sem_delete(NULL)     == OS_INVALID_PARM);
    TEST_ASSERT(os_sem_release(NULL)    == OS_INVALID_PARM);
    TEST_ASSERT(os_sem_pend(NULL, 1)    == OS_INVALID_PARM);

    /* Get the semaphore */
    err = os_sem_pend(sem, 0);
    TEST_ASSERT(err == 0,
                "Did not get free semaphore immediately (err=%d)", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after getting semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u", sem_test_sem_to_s(sem), t, t->t_prio);

    /* Get the semaphore again; should fail */
    err = os_sem_pend(sem, 0);
    TEST_ASSERT(err == OS_TIMEOUT,
                "Did not time out waiting for semaphore (err=%d)", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after getting semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                t->t_prio);

    /* Release semaphore */
    err = os_sem_release(sem);
    TEST_ASSERT(err == 0,
                "Could not release semaphore I own (err=%d)", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 1 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after releasing semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                t->t_prio);

    /* Release it again */
    err = os_sem_release(sem);
    TEST_ASSERT(err == 0,
                "Could not release semaphore again (err=%d)\n", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 2 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after releasing semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                t->t_prio);

    /* "Delete" it */
    err = os_sem_delete(sem);
    TEST_ASSERT(err == 0,
                "Could not delete semaphore (err=%d)", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after deleting semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                t->t_prio);

    os_test_restart();
}