示例#1
0
文件: key.c 项目: postgetme/crco
static void PushKeyTask (void* pdata)
{
	INT8U err;

	while (1)
	{
		OSSemPend (os_sem_push, PUSH_TIME, &err);
		if (err == OS_TIMEOUT)
		{	
			key_hook (TYPE_KEY_PUSH<<24 | change);
			OSQPost (os_q_key_msg, (void*)(TYPE_KEY_PUSH<<24 | change));
		#if KEY_CONTINUOUS_PUSH_EN == 1
			while (1)	
			{
				key_hook (TYPE_KEY_DOWN<<24 | change);
			    OSQPost (os_q_key_msg, (void*)(TYPE_KEY_PUSH<<24 | change));
				OSTimeDly (PUSH_EXECUTE_INTERVAL);
				if (OSSemAccept(os_sem_push))
				{
					OSSemPost (os_sem_push);
					break;
				}
			}
		#else
			OSTaskDel (KEY_PUSH_TASK_PRIO);
		#endif
		}
		else
		{
			OSTaskDel (KEY_PUSH_TASK_PRIO);
		}
	}
}
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_SemaWait
 * Description   : This function checks the semaphore's counting value, if it is
 * positive, decreases it and returns kStatus_OSA_Success, otherwise, timeout
 * will be used for wait. The parameter timeout indicates how long should wait
 * in milliseconds. Pass OSA_WAIT_FOREVER to wait indefinitely, pass 0 will
 * return kStatus_OSA_Timeout immediately if semaphore is not positive.
 * This function returns kStatus_OSA_Success if the semaphore is received, returns
 * kStatus_OSA_Timeout if the semaphore is not received within the specified
 * 'timeout', returns kStatus_OSA_Error if any errors occur during waiting.
 *
 *END**************************************************************************/
osa_status_t OSA_SemaWait(semaphore_t *pSem, uint32_t timeout)
{
    INT8U err;

    /* If timeout is 0, try to get the semaphore. */
    if (!timeout)
    {
        if (OSSemAccept(*pSem) > 0)
        {
            return kStatus_OSA_Success;
        }
        else
        {
            return kStatus_OSA_Timeout;
        }
    }

    /* If timeout is not 0, convert it to tickes. */
    timeout = wait_timeout_msec_to_tick(timeout);

    OSSemPend(*pSem, timeout, &err);

    if (OS_ERR_NONE == err)
    {
        return kStatus_OSA_Success;
    }
    else if (OS_ERR_TIMEOUT == err)
    {
        return kStatus_OSA_Timeout;
    }
    else
    {
        return kStatus_OSA_Error;
    }
}
示例#3
0
void led0Task(void *pdata)
{
    LED_Init();
    INT16U cnt = 0;
    while(1)
    {
        cnt = OSSemAccept(pkey);//等待 返回值表示该事件可用的资源
        if(cnt > 0)
        {
            CLOSE_LED0();
            OSTimeDlyHMSM(0,0,5,0);
        }//按键按下 LED熄灭5秒
        //但是由于每次使用OSSemPost(pkey)发送 信号量加1
        //而使用OSSemPend()等待到 然后使用一次 信号量减1
        //所以利用OSSemAccept()获取到信号量的时候 pkey已经变成0了
        //(两个任务等待同一个信号量 不一定哪个先等到,跟优先级无关)
        //所以led并不会熄灭
        //解决办法是把beep等待的OSSemPend()删去 不让它等待该信号量

        OPEN_LED0();
        //Delay(100000);
        //OSTimeDly(500);
        OSTimeDlyHMSM(0,0,0,500);
        CLOSE_LED0();
        //Delay(100000);
        //OSTimeDly(500);
        OSTimeDlyHMSM(0,0,0,500);//好用但是效率低 其实还是调用OSTimeDly()
    }
}
示例#4
0
CPU_BOOLEAN  SerialOS_SemTryLock (void  *psem)
{
    INT16U  cnt;


    cnt = OSSemAccept((OS_EVENT *)psem);
    if (cnt == 0) {
        return (DEF_FAIL);
    } else {
        return (DEF_OK);
    }
}
/*********************************************************************************************************
** Function name:           zySemAccept
** Descriptions:            无等待获得信号量
** input parameters:        ulSem: zySemCreate返回值
** output parameters:       none
** Returned value:          >=0:   信号量当前值
**                          负数:  错误,绝对值参考zy_if.h
** Created by:              Chenmingji
** Created Date:            2009-07-23
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
*********************************************************************************************************/
INT32S zySemAccept (unsigned long ulSem)
{
#if OS_ARG_CHK_EN == 0    
    /*
     *  参数检查
     */
    if (ulSem == 0) {
        return -ZY_PARAMETER_ERR;
    }
#endif                                                                  /*  OS_ARG_CHK_EN               */

    return OSSemAccept((OS_EVENT *)ulSem);
}
示例#6
0
void
LOCKNET_CHECK(struct queue * q)
{

   /* Don't start checking until the net is up */
   if(!iniche_net_ready)
      return;

#ifdef INCLUDE_TCP
#ifndef MINI_TCP
   /* On uCOS/Nichestack/TCP builds, check the mbuf free queue is locked
    * by the NET_RESID semaphore. If it's not we panic().
    */
   if(q == &mfreeq)
   {
      /* A non-zero from OSSemAccept() means the semaphore was NOT locked */
      if (OSSemAccept(resid_semaphore[NET_RESID]) != 0)
      {
         panic("locknet_check1");
      }
   }
#endif /* not MINI_TCP */
#endif /* INCLUDE_TCP */

   /* quick return if it's not one of the other sensitive queues */
   if((q != &rcvdq) &&
      (q != &bigfreeq) &&
      (q != &lilfreeq))
   {
      return;
   }

   /* Since the Nios2 build uses interrupt disabling to protect these
    * queues, we just need to check the Interrupt state. We use look at
    * the irq_level to get the current interrupt state, if interrupts
    * were not then we are going to panic().
    */

   if(irq_level != 1)    /* Get current interupt state */
   {
      panic("locknet_check2");
   }
   return;
}
示例#7
0
/*
*********************************************************************************************************
*                                             App_TaskMEMS()
*
* Description : This task monitors the state of the push buttons and passes messages to AppTaskUserIF()
*
* Argument(s) : p_arg   is the argument passed to 'App_TaskMEMS()' by 'OSTaskCreateExt()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Note(s)     : none.
*********************************************************************************************************
*/
void  App_TaskMEMS (void *p_arg)
{
    INT8U err, FRH, FRM, FRL;
    INT16U i;


    (void)p_arg;

    while (DEF_TRUE) {
        while(OSSemAccept(g_sem_mems));

        mems_read_instant_flow();

        OSSemPend(g_sem_mems, OS_TICKS_PER_SEC, &err);

        if(OS_ERR_NONE == err)
        {
            LED_MEMS_ON();

            if(MEMS_FRAME_OK == MEMS_AnalysisFrame((INT8U *)&mems_frame_recv, &mems_frame_stat))
            {
                switch(mems_frame_stat.cmd)
                {
                case MEMS_READ_INSTANT_FLOW_CMD:
                    FRH = mems_frame_recv.data[0];
                    FRM = mems_frame_recv.data[1];
                    FRL = mems_frame_recv.data[2];

                    g_mems_para.instant_flow = (INT32U)FRH * 65536 + (INT32U)FRM * 256 + (INT32U)FRL;

                    g_mems_para.buf[g_mems_para.index++] = g_mems_para.instant_flow;

                    if(MAX_FLOW_NUM == g_mems_para.index)
                    {
                        g_mems_para.index = 0;

                        g_mems_para.sum = 0;

                        for(i = 0; i < MAX_FLOW_NUM; i++)
                        {
                            g_mems_para.sum += g_mems_para.buf[i];
                        }

                        g_mems_para.average_flow = g_mems_para.sum / MAX_FLOW_NUM;

                        g_mems_para.cal_flow = g_mems_para.average_flow; //Á÷Á¿Ð£×¼

                        if((0 != g_mems_para.cal_flow) && (abs((int)g_mems_para.cal_flow - (int)g_mems_para.target_flow) < g_mem_para.mems_debounce_threshold))
                        {
                            g_mems_para.inside_count++;

                            if(g_mems_para.inside_count >= 2)
                            {
                                g_mems_para.inside_count = 0;
                                g_mems_para.outside_count = 5;

                                g_mems_para.disp_flow = g_mems_para.target_flow;
                                g_mems_para.disp_flow_int_part = g_mems_para.disp_flow / 1000;
                                g_mems_para.disp_flow_dec_part = (g_mems_para.disp_flow - (g_mems_para.disp_flow_int_part * 1000)) / 100;
                            }

                            break;
                        }
                        else
                        {
                            g_mems_para.inside_count = 0;
                        }

                        if(g_mems_para.outside_count)
                        {
                            g_mems_para.outside_count--;
                        }
                        else
                        {
                            g_mems_para.disp_flow = g_mems_para.cal_flow + 50;
                            g_mems_para.disp_flow_int_part = g_mems_para.disp_flow / 1000;
                            g_mems_para.disp_flow_dec_part = (g_mems_para.disp_flow - (g_mems_para.disp_flow_int_part * 1000)) / 100;
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
        else
        {
            LED_MEMS_OFF();
        }
    }
}
示例#8
0
文件: main.cpp 项目: Quang2695/ECE492
/* Checks for fingerprint */
void task1(void* pdata) {
	INT8U err;
	bool firstBuffer = true;
	while (true) {
		//Init sensor
		ZFMComm fingerprintSensor;
		fingerprintSensor.init(SERIAL_NAME);
		//Continue while we have no error
		while (!fingerprintSensor.hasError()) {
			OSTimeDlyHMSM(0, 0, 1, 0);
			printf("Checking for fingerprint\n");
			LCD::writeToLCD("Checking for", "fingerprint");
			//Check if the web server is pending on a fingerprint
			bool sendToMailbox = OSSemAccept(fingerprintSem) > 0;
			while (!fingerprintSensor.scanFinger()
					|| !fingerprintSensor.storeImage(getBufferNum(firstBuffer))) {
				//Sleep for a second and try again
				OSTimeDlyHMSM(0, 0, 1, 0);
				if (!sendToMailbox) {
					sendToMailbox = OSSemAccept(fingerprintSem) > 0;
				}
			}
			printf("Fingerprint acquired, looking for fingerprint ID\n");
			LCD::writeToLCD("Print found", "Looking for ID");
			int fid = fingerprintSensor.findFingerprint(getBufferNum(firstBuffer));
			printf("Fingerprint id:%d\n", fid);

			stringstream sStream;
			sStream << fid;
			LCD::writeToLCD("Print ID: ", sStream.str());


			if (sendToMailbox) {
				//Swap Fingerprint Buffer used in case we enroll next
				firstBuffer = !firstBuffer;
				if(m_enrollNow){
					Database dbAccess;
					fid = dbAccess.findNextID(USER_PRINTS);
					fingerprintSensor.storeFingerprint(fid);
					m_enrollNow = false;
				}
				//We need to wait for the mailbox to empty before we do anything
				while (true) {
					OS_MBOX_DATA mboxData;
					OSMboxQuery(fingerprintMailbox, &mboxData);
					if (mboxData.OSMsg == NULL) {
						//We can add data to the mailbox now
						break;
					}
					OSTimeDlyHMSM(0, 0, 1, 0);
				}
				err = OSMboxPost(fingerprintMailbox, &fid);
				if (err != OS_NO_ERR) {
					printf("Error sending message to fingerprint mailbox");
				}
				//Restart loop
				continue;
			}

			//Check if fingerprint is allowed access and unlock door
			//After this point, we fall through to the error if (uriString.compare(0, 7,
			{
				Database dbAccess;
				if(dbAccess.checkAccess(fid)){
					//Success, unlock door!
					char * ledBase = (char*) GREEN_LEDS_BASE;
					for (int i = 0; i < GREEN_LEDS_DATA_WIDTH; i++){
						*ledBase = 1 << i;
						OSTimeDlyHMSM(0, 0, 0, 100);
					}
					*ledBase = 0;
					printf("Open up!!!\n\n");
					printf("Unlocking\n");
					LCD::writeToLCD("Unlocking", "");
					Solenoid::unlock();
					continue;
				}
			}

			//Fallthrough error case. Notify owner!
			printf("Failed to verify print!\n\n");
			LCD::writeToLCD("Print not", "verified");
			{
				Audio sound(databaseSemaphore);
				for (int i = 0; i < 3; i++){
					sound.play();
				}
			}
		}
	}
}