Beispiel #1
0
/******************************************************************************
  Function:
    void APP_Tasks ( void )

  Remarks:
    See prototype in app.h.
 */
void APP_Tasks ( void )
{
   /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            break;
        }

        /* The running state. Get value from the queue and output character
         * if necessary */
        case APP_STATE_OUTPUT:
        {
            //stopEverything();
            //Receive Information from the Queue
#ifdef MACRO_DEBUG
debugChar(0x03);
#endif 
            //Number of elapsed ms.
            unsigned int ms;
            BaseType_t received = xQueueReceive(appData.local_q , &ms, portMAX_DELAY);
            //If not received, stop and turn on LED.
            if(received == pdFALSE)
            {
                stopEverything();
            }
            
            //Read a value from the xQueue every 10ms
            unsigned char sensorRead;
            BaseType_t sensorReceived;

            sensorReceived = xQueueReceive(appData.sensor1_q , &sensorRead, portMAX_DELAY);
            //debugChar(sensorRead);

#ifdef MACRO_DEBUG
debugChar(0x04);
#endif
            //If not received, stop and turn on LED.
            if(sensorReceived == pdFALSE)
            {
                stopEverything();
            }

            //Once the Task runs once, restart the ISR to read values
            PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_ADC_1);
            
            //SendUSARTMsgToMsgQ("My name is Andrew");
            
            break;
        }
        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }  
}
Beispiel #2
0
void app1SendSensorValToSensorQ(unsigned char sensorValue)
{
#ifdef MACRO_DEBUG
    debugChar(0x01);
#endif 
    //debugChar(sensorValue);
    xQueueSendFromISR( appData.sensor1_q, &sensorValue,
                                   NULL );
#ifdef MACRO_DEBUG
    debugChar(0x02);
#endif
}
Beispiel #3
0
void MESSAGING_TASK_Tasks ( void )
{
    /* Check the application's current state. */
    switch ( msg_taskData.state )
    {
        /* Application's initial state. */
        case MESSAGING_TASK_STATE_INIT:
        {
            break;
        }

        /* TODO: implement your application state machine.*/
        case MESSAGING_TASK_STATE_RUN:
        {
            //stopEverything();
#ifdef MACRO_DEBUG
      debugChar(0x07);      
#endif
            unsigned char temp;
            xQueueReceive(msg_taskData.receiveMsg_q, &temp, portMAX_DELAY);
#ifdef MACRO_DEBUG
      debugBuffer(0x08,5);      
#endif
            //SendUSARTByteToMsgQ(temp);  
        }
        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }
}
Beispiel #4
0
void MESSAGING_TASK_Initialize ( void )
{
    /* Place the App state machine in its initial state. */
    msg_taskData.state = MESSAGING_TASK_STATE_INIT;
    
    /* TODO: Initialize your application's state machine and other
     * parameters.
     */
    msg_taskData.sendMsg_q = xQueueCreate(50, sizeof(unsigned char));
    if(msg_taskData.sendMsg_q == 0)
    {
        stopEverything();
    }
    msg_taskData.receiveMsg_q = xQueueCreate(50, sizeof(unsigned char));
    if(msg_taskData.sendMsg_q == 0)
    {
        stopEverything();
    }
    //stopEverything();
    /* Initialization is done, allow the state machine to continue */
    msg_taskData.state = MESSAGING_TASK_STATE_RUN;
    
#ifdef MACRO_DEBUG
      debugChar(0x09);      
#endif
      //stopEverything();
}
void APP_WIFLY_Tasks ( void )
{
	while(1)
	{
//		debugChar(0x22);
//		app_wifly_sendmsg(2,"TEST");
		//check if queue exists
		if(appData.theQueue != 0)	
		{
			//receive a message and store into rxMessage ... block 5 ticks if empty queue
			if(xQueuePeek(appData.theQueue, &(appData.rxChar), portMAX_DELAY ))
			{
				xQueueReceive(appData.theQueue, &(appData.rxChar), portMAX_DELAY );
				//received messageQ message will tell use the state which will be used
				//##appData.state = appData.rxMessage.type;
				appData.state = 2;
				
				//run the state according to the message's state
				switch ( appData.state )
				{
					/* Application's initial state. */
					case APP_STATE_INIT:	//0
						break;

					case APP_STATE_READ:	//1
					{
						debugU("Read");
						debugChar(0x0F);
						app_wifly_UartRx();
						appData.state = 0;
						app_wifly_sendmsg(2,appData.rxBuffer);
						appData.rxMessage.type = 0;
						appData.rxMessage.string = "";
						break;
					}

					case APP_STATE_WRITE:	//2
					{
						debugU("Write");
						debugChar(0xF0);
						app_wifly_UartTxChar(appData.rxChar);
						appData.state = 0;
						appData.rxMessage.type = 0;
						appData.rxMessage.string = "";
						//appData.rxChar = ' ';
						break;
					}
					case APP_STATE_RECEIVE:	//3
					{
						debugU("Receiving");
						debugChar(appData.rxBufferIndex);
						if(appData.rxBufferIndex < appData.rxBufferSize)	//if we are within buffer bounds, copy char
							appData.rxBuffer[appData.rxBufferIndex] = appData.rxMessage.string[0];
						appData.rxBufferIndex++;
						appData.state = 0;
						appData.rxMessage.type = 0;
						appData.rxMessage.string = "";
						break;
					}

					/* The default state should never be executed. */
					default:
					{
						/* TODO: Handle error in application's state machine. */
						break;
					}
				}//end of case
			}//end of receive message
		}//end of check message queue != 0
		else	//attempt to create the queue again if it doesn't exist
		{
			//something terrible happens normally so have it exit rather than recreate
			debugChar(0xFF);
			//run exit interrupt to OS... or forever loop message
			return;
			//appData.theQueue = xQueueCreate(10, sizeof(APP_STATES));
		}
	}//end of while(1)
}