static void
low_level_init(struct netif *pstNetif)
{
    UBYTE		__ubOldPrio;
    UBYTE		__ubErr;
    pstNetif->hwaddr_len = NETIF_MAX_HWADDR_LEN;
//0x00,0x19,0x21,0xcb,0x60,0x0b
    //* 设置MAC地址
    pstNetif->hwaddr[0] = 0x00;
    pstNetif->hwaddr[1] = 0x10;
    pstNetif->hwaddr[2] = 0x20;
    pstNetif->hwaddr[3] = 0xc0;
    pstNetif->hwaddr[4] = 0x60;
    pstNetif->hwaddr[5] = 0x0b;

    pstNetif->mtu = 1500;

    pstNetif->flags = NETIF_FLAG_BROADCAST;


    //* 初始化EMAC。EMACInit()函数包含查询状态位代码,并且这些查询代码并没有使用OSTimeDly()等函数主动释放
    //* CPU使用权。如果网线在当时并没有接触良好,则这个过程需要相当长的时间。为了避免阻塞其它低优先级任务的
    //* 正常运行,我们使用了uCOS提供的任务管理函数,先将其所在任务的优先级降低,等初始化完成之后再恢复其优
    //* 先级。
    __ubOldPrio = OSTCBCur->OSTCBPrio;
    __ubErr = OSTaskChangePrio(OS_PRIO_SELF, OS_TASK_IDLE_PRIO-3);
    /*	实际的网卡初始化程序 纯粹的网卡初始化 不涉及到协议栈的初始化	*/
    //*这个函数是调用的MAC层函数,MAC层也有一个任务,是负责处理发送和接受的链路数据的,最为底层,优先级最高的任务
    EMACInit();
    if(__ubErr == OS_NO_ERR)
        OSTaskChangePrio(OS_PRIO_SELF, __ubOldPrio);

    OSTaskCreate(ethernetif_input, pstNetif, &T_ETHERNETIF_INPUT_STK[T_ETHERNETIF_INPUT_STKSIZE-1], 9);
}
Ejemplo n.º 2
0
/*
*********************************************************************************************************
*                                              test1_4
*********************************************************************************************************
*/
unsigned char test1_4(void){

	unsigned char exit_err=0;

        /* The value chould be changed for your system */
	TASK_T1_PRIORITY=20;
	TASK_T2_PRIORITY=22;

	STTBX_Print(("\nTEST 1.4 Started...\n"));
	STTBX_Print((TEST1_4_STRING));

	STTBX_Print(("\n 1.4.1 Creating task T1 Pri=%d...",TASK_T1_PRIORITY));
	exit_err = print_debug_task_create(OSTaskCreate(test1_4_T1, (void *)&test1_4_T1Stk, &test1_4_T1Stk[TASK_STK_SIZE - 1], TASK_T1_PRIORITY),OS_NO_ERR);

	if(exit_err)
		return(exit_err);

	STTBX_Print(("\n 1.4.2 Creating task T2 Pri=%d...",TASK_T2_PRIORITY));
	exit_err = print_debug_task_create(OSTaskCreate(test1_4_T2, (void *)&test1_4_T2Stk, &test1_4_T2Stk[TASK_STK_SIZE - 1], TASK_T2_PRIORITY),OS_NO_ERR);

	if(exit_err)
		return(exit_err);

	STTBX_Print(("\n 1.4.3 Change T1 priority from %d to 22...",TASK_T1_PRIORITY));
	exit_err = print_debug_task_change_priority(OSTaskChangePrio(TASK_T1_PRIORITY,TASK_T2_PRIORITY),OS_PRIO_EXIST);

	if(exit_err)
		return(exit_err);

	STTBX_Print(("\n 1.4.4 Change T1 priority from %d to 254...",TASK_T1_PRIORITY));
	exit_err = print_debug_task_change_priority(OSTaskChangePrio(TASK_T1_PRIORITY,254),OS_NO_ERR);

	if(exit_err)
		return(exit_err);

	STTBX_Print(("\n 1.4.5 Change priority from %d to 12...",11));
	exit_err = print_debug_task_change_priority(OSTaskChangePrio(11,12),OS_PRIO_ERR);

	if(exit_err)
		return(exit_err);

	STTBX_Print(("\n 1.4.6 Delete T1..."));
	exit_err = print_debug_task_delete(OSTaskDel(254),OS_NO_ERR);

	if(exit_err)
		return(exit_err);

	STTBX_Print(("\n 1.4.7 Delete T2..."));
	exit_err = print_debug_task_delete(OSTaskDel(TASK_T2_PRIORITY),OS_NO_ERR);

	if(exit_err)
		return(exit_err);

	return(FALSE);

}
Ejemplo n.º 3
0
/*
* This function allows you to change the priority of a task dynamically
*/
extern  status_t taskPrioritySet
    (
    uint8_t tid,                  /* task ID */
    uint8_t newPriority           /* new priority */
    )
{
    return OSTaskChangePrio(tid, newPriority);
}
Ejemplo n.º 4
0
INT8U  CTask::ChangePrio(INT8U nNewPrio)
{
	INT8U	nOldPrio = m_nPrio;
	
	OSTaskChangePrio(m_nPrio, nNewPrio);
	m_nPrio = nNewPrio;
	
	return nOldPrio;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_TaskSetPriority
 * Description   : This function sets task's priority by task handler.
 *
 *END**************************************************************************/
osa_status_t OSA_TaskSetPriority(task_handler_t handler, uint16_t priority)
{
    if (OS_ERR_NONE == OSTaskChangePrio(handler->OSTCBPrio, PRIORITY_OSA_TO_RTOS(priority)))
    {
        return kStatus_OSA_Success;
    }
    else
    {
        return kStatus_OSA_Error;
    }
}
Ejemplo n.º 6
0
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_TaskSetPriority
 * Description   : This function sets task's priority by task handler.
 *
 *END**************************************************************************/
osa_status_t OSA_TaskSetPriority(task_handler_t handler, uint16_t priority)
{
    OS_ERR err;

    OSTaskChangePrio(handler, PRIORITY_OSA_TO_RTOS(priority), &err);

    if (OS_ERR_NONE == err)
    {
        return kStatus_OSA_Success;
    }
    else
    {
        return kStatus_OSA_Error;
    }
}
Ejemplo n.º 7
0
void beepTask(void *pdata)
{
	int i = 0;
	BEEP_Init();
	while(1)
	{
		OPEN_BEEP();
		//Delay(100000);//实际上是空语句 可以把这个时间让给优先级低的执行
		OSTimeDly(500);
		CLOSE_BEEP();
		//Delay(100000);
		OSTimeDly(500);//这个时候CPU可以去执行别的事情 可以执行多任务
		i++;
		if(i>=3)
		{
			OSTaskChangePrio(BEEP_TASK_PRIO,12);
			OSTaskDel(12);
			//先把蜂鸣器任务优先级改为12 然后删除第12优先级的任务 	
		}
	}	
}
Ejemplo n.º 8
0
void
usrAppInit(void)
{
    printf("In usr usrAppInit\n");
//    task_leds_start();
    int i = 0;
    uint32_t cnt = 0;
    uint32_t heart_5[5];
    uint32_t heart;
    uint32_t max;
    uint32_t min;
    uint32_t total;
    adc_init();

    OSTaskChangePrio(0, 7);

    uint32_t ad;
    uint32_t pre_ad = get_v();
    pre_tick = tickGet();
    while (1)
    {
        ad = get_v();
        if ((pre_ad < 570) && (ad >= 570))
        {
//            printf("%d pre_ad:%d ad:%d", i++, pre_ad, ad);
            heart_tick = tickGet();
            pre_tick = heart_tick - pre_tick;
            heart = (1200000 / pre_tick);
            if (heart > 35*10 && heart < 180*10)
            {
                memmove(&heart_5[0], &heart_5[1], 4*sizeof(uint32_t));
                heart_5[4] = heart;
                if (cnt < 5)
                {
                    cnt++;
                }
                else
                {
                    total = max = min = heart_5[0];
                    for(int i = 1; i < 5; i++)
                    {
                        total += heart_5[i];

                        if (heart_5[i] > max)
                        {
                            max = heart_5[i];
                        }
                        if (heart_5[i] < min)
                        {
                            min = heart_5[i];
                        }
                    }
                    heart = (total - max - min) / 3;

                    printf("心率:%d.%d\n", heart / 10,  heart % 10);//pre_tick
                }
            }

            pre_tick = heart_tick;
            sys_gpio_write(IO_LED2, E_LED_ON);
        }
        else if ((ad < 570) && (pre_ad >= 570))
        {
            sys_gpio_write(IO_LED2, E_LED_OFF);
        }

        pre_ad = ad;
        taskDelay(2);
    }
}
Ejemplo n.º 9
0
CODEC_START_STATUS video_encode_fast_switch_stop_and_start(MEDIA_SOURCE src)
{
#if AVI_ENCODE_FAST_SWITCH_EN == 1	
	INT32S nRet;
	AviEncPacker_t *pNewAviEncPacker, *pOldAviEncPacker;
	
	/* set video codec*/
	if(src.Format.VideoFormat == MJPEG) {
    	pAviEncVidPara->video_format = C_MJPG_FORMAT;
#if	MPEG4_ENCODE_ENABLE == 1 
    } else if(src.Format.VideoFormat == MPEG4) {
		pAviEncVidPara->video_format = C_XVID_FORMAT;
#endif	
	} else {
		goto AVI_PACKER_FAIL;
	}
	
	/* set avi packer workmem */
	if(pAviEncPara->AviPackerCur == pAviEncPacker0) {
    	pOldAviEncPacker = pAviEncPacker0;
    	pNewAviEncPacker = pAviEncPacker1;
    } else {
    	pOldAviEncPacker = pAviEncPacker1;
    	pNewAviEncPacker = pAviEncPacker0;
    }

	/* set source type */
	if(src.type == SOURCE_TYPE_FS) {
    	if(src.type_ID.FileHandle < 0) {        
        	goto AVI_PACKER_FAIL;
    	}
    	
    	pAviEncPara->source_type = SOURCE_TYPE_FS;
    	nRet = avi_encode_set_file_handle_and_caculate_free_size(pNewAviEncPacker, src.type_ID.FileHandle);	
    } else if(src.type == SOURCE_TYPE_USER_DEFINE) {
    	pAviEncPara->source_type = SOURCE_TYPE_USER_DEFINE;
    	nRet = avi_encode_set_file_handle_and_caculate_free_size(pNewAviEncPacker, 0x7FFF);
    } else { 
        goto AVI_PACKER_FAIL;
  	}
  	
   	if(nRet < 0) {
    	goto AVI_PACKER_FAIL;
    }
       
    /* stop current avi encode */
  	nRet = avi_enc_stop();
	if(nRet < 0) {
		goto AVI_PACKER_FAIL;
	}
	
    /* change current avi packer priority */
    OSTaskChangePrio(pOldAviEncPacker->task_prio, AVI_PACKER_PRIORITY); 
    
    /* start new avi packer */ 
    nRet = avi_enc_packer_start(pNewAviEncPacker);
    if(nRet < 0) {
    	goto AVI_PACKER_FAIL;
    }
        
	/* start new avi packer workmen */
	avi_encode_set_curworkmem((void *)pNewAviEncPacker);  
   	nRet = avi_enc_start();
  	if(nRet < 0) {
  		goto AVI_PACKER_FAIL;
    }
    
    /* stop old avi packer */
    nRet = avi_enc_packer_stop(pOldAviEncPacker);
    if(nRet < 0) {
    	goto AVI_PACKER_FAIL;		
    }
    
    return START_OK;
    
AVI_PACKER_FAIL:
	avi_enc_stop();
	avi_enc_packer_stop(pNewAviEncPacker);
	avi_enc_packer_stop(pOldAviEncPacker);
#endif
	return CODEC_START_STATUS_ERROR_MAX;
}
Ejemplo n.º 10
0
ADI_OSAL_STATUS adi_osal_ThreadSetPrio(ADI_OSAL_THREAD_HANDLE const hThread, ADI_OSAL_PRIORITY nNewPriority)
{
    INT8U           nNewPrio;
    INT8U           nOldPrio;
    INT8U           nRetValue;
    ADI_OSAL_STATUS eRetStatus;
#pragma diag(push)
#pragma diag(suppress:misra_rule_11_4 : "typecasting is necessary to convert the handle type into a useful type")
    ADI_OSAL_THREAD_INFO_PTR hThreadNode = (ADI_OSAL_THREAD_INFO_PTR) hThread;
#pragma diag(pop)


#ifdef OSAL_DEBUG
    if (CALLED_FROM_AN_ISR)
    {
        return (ADI_OSAL_CALLER_ERROR);
    }
#endif /* OSAL_DEBUG */

#ifdef OSAL_DEBUG
        /* check validity of the handle */
        if ((hThreadNode==NULL) || (hThread==ADI_OSAL_INVALID_THREAD))
        {
            return (ADI_OSAL_BAD_HANDLE);
        }
        if ((hThreadNode->pThreadLocalStorageBuffer==NULL) ||
            (hThreadNode->nThreadPrio < ADI_OSAL_UCOS_BASE_PRIO) )
        {
            return (ADI_OSAL_BAD_HANDLE);
        }
#endif

    nOldPrio = (INT8U) hThreadNode->nThreadPrio;
    nNewPrio = (INT8U) (nNewPriority + ADI_OSAL_UCOS_BASE_PRIO);

    if ((nNewPrio <  (INT8U) ADI_OSAL_UCOS_BASE_PRIO))
    {
        return(ADI_OSAL_BAD_PRIORITY);
    }

    PAUSE_PROFILING();
    nRetValue= OSTaskChangePrio(nOldPrio, nNewPrio);
    RESUME_PROFILING();
    switch (nRetValue)
    {
        case  OS_ERR_NONE:
            /* update local structure */
            hThreadNode->nThreadPrio = nNewPrio;
            eRetStatus = ADI_OSAL_SUCCESS;
            break;

        case OS_ERR_PRIO_EXIST:
            eRetStatus = ADI_OSAL_PRIORITY_IN_USE;
            break;
#ifdef OSAL_DEBUG
        case OS_ERR_PRIO_INVALID:
            eRetStatus = ADI_OSAL_BAD_PRIORITY;
            break;
        case OS_ERR_PRIO:
            eRetStatus = ADI_OSAL_BAD_HANDLE;
            break;
#endif /* OSAL_DEBUG */
        default :
            eRetStatus = ADI_OSAL_FAILED;
            break;
    }
    return(eRetStatus);
}
Ejemplo n.º 11
0
Archivo: app.c Proyecto: Liyuxiang/Test
static	void	App_TaskStart(void *p_arg)
{
	volatile  uint32_t status;
	int8u bufp[7] = {0xc4,0x01,0x01,0x00,0x00,0x00,0x55};
	uint8_t *ptr;
	uint8_t err;
	
	(void) p_arg;

	
	//系统滴答安装
	OS_CPU_SysTickInit();   

	//初始化信号量
	app_eventcreate();

	//初始化其他任务
	app_taskcreate();
	


	//初始化基础硬件
	BSP_Init();
	
	dw1000_init();

{
	dwtconf temp;
	temp.config.chan = 3;
	temp.config.prf = DWT_PRF_16M;
	
	temp.config.txPreambLength = DWT_PLEN_256;
	temp.config.rxPAC = DWT_PAC16;
	
	temp.config.rxCode = 5;
	temp.config.txCode = 5;
	temp.config.nsSFD = 1;
	
	temp.config.dataRate = DWT_BR_850K;
	temp.config.smartPowerEn = 0;
	
	temp.config.phrMode = 0;
	
	temp.mode = LOCA_LISTENER;
	dw1000_config(&temp);

}
dwt_rxenable(0);

	  USBD_Init(&USB_OTG_dev,
            USB_OTG_FS_CORE_ID, 
            &USR_desc, 
            &USBD_CDC_cb, 
            &USR_cb);
//dw1000_intenable();
	//发送log
	//Shell_SendDatas(strlen(logstr), logstr);

	//改变自己优先级 变为工作指示灯
	//OSTaskDel(OS_PRIO_SELF);
	OSTaskChangePrio(OS_PRIO_SELF, OS_LOWEST_PRIO - 4);
	
	while(TURE)
	{
	//	OSTimeDlyHMSM(0, 0, 0, 10);
		//dwt_writetxdata(127,msg,0);
		//dwt_writetxfctrl(127,0);
		//dwt_starttx(DWT_START_TX_IMMEDIATE);
	//	bufp[1] ++;
		//status = dwt_read32bitreg(SYS_STATUS_ID);


		ptr = OSQPend(qmsg, 0, &err);
		if (err == OS_ERR_NONE)
		{
		VCP_fops.pIf_DataTx(ptr+1, ptr[0]);

		free(ptr);
		}
	}
}