示例#1
0
文件: main.c 项目: nqd/cc3200
//****************************************************************************
//
//! Main function
//!
//! \param none
//!
//! This function
//!    1. Invokes the SLHost task
//!    2. Invokes the GetNTPTimeTask
//!
//! \return None.
//
//****************************************************************************
void main()
{
    long lRetVal = -1;

    //
    // Initialize Board configurations
    //
    BoardInit();

    //
    // Enable and configure DMA
    //
    UDMAInit();

    //
    // Pinmux for UART
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Display Application Banner
    //
    DisplayBanner(APP_NAME);

    //
    // Start the SimpleLink Host
    //
    lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

    //
    // Start the GetNTPTime task
    //
    lRetVal = osi_TaskCreate(GetNTPTimeTask,
                    (const signed char *)"Get NTP Time",
                    OSI_STACK_SIZE,
                    NULL,
                    1,
                    NULL );

    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

    //
    // Start the task scheduler
    //
    osi_start();
}
示例#2
0
文件: main.cpp 项目: hangc2/wif
//****************************************************************************
//							MAIN FUNCTION
//****************************************************************************
int main()
{
    long lRetVal = -1;
    //
    // Board Initialization
    //
    BoardInit();

    //
    // Enable and configure DMA
    //
    UDMAInit();
    //
    // Pinmux for UART
    //
    PinMuxConfig();
    //
    // Configuring UART
    //
    InitTerm();
    //
    // Display Application Banner
    //
    DisplayBanner(APP_NAME);
    //
    // Start the SimpleLink Host
    //
    lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }
    //
    // Start the Receiving file
    //

    lRetVal = osi_TaskCreate(cmd_dispatcher,
                    (const signed char *)"TFTP",
                    OSI_STACK_SIZE,
                    NULL,
                    1,
                    NULL );
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

    //
    // Start the task scheduler
    //
    osi_start();
    return 0;
}
示例#3
0
/*@Function============================================================
@Desc: ChooseColor():	Countdown zum Waehlen der Farbe 

@Ret: void
@Int:
* $Function----------------------------------------------------------*/
void
ChooseColor (void)
{
  int countdown = 100;  /* duration in 1/10 seconds given for color choosing */
  int ColorChosen = FALSE;
  char count_text[80];
  
  Uint32 prev_count_tick, count_tick_len;

  count_tick_len = 100; 	/* countdown in 1/10 second steps */

  prev_count_tick = SDL_GetTicks ();

  ResetMouseWheel ();  // forget about previous wheel events

  while (!ColorChosen)
    {
      if (RightPressedR() || WheelDownPressed())
	{
	  if (YourColor != VIOLETT) MoveMenuPositionSound();
	  YourColor = VIOLETT;
	  OpponentColor = GELB;
	}
      if (LeftPressedR() || WheelUpPressed())
	{
	  if (YourColor != GELB) MoveMenuPositionSound();
	  YourColor = GELB;
	  OpponentColor = VIOLETT;
	}

      if (FirePressedR())
	{
	  ColorChosen = TRUE;
	}

      /* wait for next countdown tick */
      if ( SDL_GetTicks() >= prev_count_tick + count_tick_len )
	{ 
	  prev_count_tick += count_tick_len; /* set for next tick */
	  countdown--;		/* Count down */
	  sprintf (count_text, "Color-%d", countdown);

	  DisplayBanner (count_text, NULL , 0);
	  ShowPlayground ();
	}


      if (countdown == 0)
	ColorChosen = TRUE;

    } /* while(!ColorChosen) */

  return;

} /* ChooseColor() */
示例#4
0
//****************************************************************************
//							MAIN FUNCTION
//****************************************************************************
void main() {
	
	//
	// Board Initialization
	//
	BoardInit();

	//
	// Pinmux for UART
	//
	PinMuxConfig();

#ifndef NOTERM
	//
	// Configuring UART
	//
	InitTerm();
	
    //
    // Display Application Banner
    //
    DisplayBanner(APP_NAME);
#endif

    //
    // Enable and configure DMA
    //
    UDMAInit();

    //
    // Start the SimpleLink Host
    //
    VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    //
    // Start the HttpServer Task
    //
    //

    osi_TaskCreate(HttpServerAppTask,
                    "WebSocketApp",
                        OSI_STACK_SIZE,
                        NULL,
                        HTTP_SERVER_APP_TASK_PRIORITY,
                        NULL );

    UART_PRINT("HttpServerApp Initialized \n\r");

    //
    // Start the task scheduler
    //
    osi_start();

	return;
}
示例#5
0
//*****************************************************************************
//
//! Main 
//!
//! \param  none
//!
//! This function
//!    1. Invokes the SLHost task
//!    2. Invokes the MqttClient
//!
//! \return None
//!
//*****************************************************************************
void main()
{ 
    long lRetVal = -1;
    //
    // Initialize the board configurations
    //
    BoardInit();

    //
    // Pinmux for UART
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Display Application Banner
    //
    DisplayBanner("MQTT_Client");

    //
    // Start the SimpleLink Host
    //
    lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

    //
    // Start the MQTT Client task
    //
    osi_MsgQCreate(&g_PBQueue,"PBQueue",sizeof(event_msg),10);
    lRetVal = osi_TaskCreate(MqttClient,
                            (const signed char *)"Mqtt Client App",
                            OSI_STACK_SIZE, NULL, 2, NULL );

    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }
    //
    // Start the task scheduler
    //
    osi_start();
}
示例#6
0
void ConnectionManager::HandleBannerData(int respType)
{
    QString responseStr(GetResponse());

    if(respType == EContinue)
        dataResponseStr += responseStr;
    else
        dataResponseStr = responseStr;

    {
        Parser bannerTokenRecognize(dataResponseStr, BANNER_TOKEN_SEP);
        int bannerToken = bannerTokenRecognize.GetResponseValue(Parser::ELeft).toInt();

        if(bannerToken != BANNER_DATA)
            return;
    }

    Parser bannerRecognize(dataResponseStr);

    if(bannerRecognize.GetKeyValue(STATUS_KEY) != SUCCESS_VAL)
    {
        //handle an error here
        qWarning(ERROR_WARNING);
        return;
    }

    int type = EUnknown;
    QString dataStr = NULL;
    QString typeStr (bannerRecognize.GetKeyValue(TYPE_KEY));

    if(bannerRecognize.IsCompleteDataReceived())
    {
        if(typeStr != NULL)
        {
            type = typeStr.toInt();

            if (type == EText)
                dataStr = bannerRecognize.GetKeyValue(TEXT_KEY);

            if (type == EImage)
                dataStr = bannerRecognize.GetKeyValue(CONTENT_BASE64_KEY);
        }

        actionCounter = ERedirect;
    }
    else
        type = EContinue;

    DisplayBanner(type, dataStr);
}
示例#7
0
//****************************************************************************
//
//! Main function invoking the sleep and deepsleep functionality
//!
//! \param none
//! 
//! This function  
//!    1. Invokes the API that implements Sleep followed by wakeup using WDT
//!    2. Invokes the API that implements DeepSleep followed by wakeup 
//!       using WDT
//!    3. Invokes the API that implements Sleep followed by wakeup using GPT
//!    4. Invokes the API that implements DeepSleep followed by wakeup 
//!       using GPT
//!
//! \return None.
//
//****************************************************************************
void main()
{
    //
    // Initialize the MCU
    //
    BoardInit();
    
    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();
    
    //
    // Initialze the UART
    //
    InitTerm();

    DisplayBanner(APP_NAME);
    
    DBG_PRINT("SLEEP_DEEPSLEEP: Test Begin\n\r");
    
    //
    // Sleep followed by wakeup using WDT
    //
    PerformPRCMSleepWDTWakeup();
    
    //
    // DeepSleep followed by wakeup using WDT
    //
    PerformPRCMDeepSleepWDTWakeup();
    
    //
    // Sleep followed by wakeup using GPT
    //
    PerformPRCMSleepGPTWakeup();
    
    //
    // DeepSleep followed by wakeup using GPT
    //
    PerformPRCMDeepSleepGPTWakeup();
    
    DBG_PRINT("SLEEP_DEEPSLEEP: Test Complete\n\r");

    //
    // Done. Loop here
    //
    while(1);
}
示例#8
0
//*****************************************************************************
//                            MAIN FUNCTION
//*****************************************************************************
void main() {
	//
	// Board Initialization
	//
	BoardInit();

	//
	// configure the GPIO pins for LEDs,UART
	//
	PinMuxConfig();

	//
	// Configure the UART
	//
#ifndef NOTERM
	InitTerm();
#endif  //NOTERM
	//
	// Display Application Banner
	//
	DisplayBanner(APPLICATION_NAME);

	//
	// Configure all 3 LEDs
	//
	GPIO_IF_LedConfigure(LED1 | LED2 | LED3);

	// switch off all LEDs
	GPIO_IF_LedOff(MCU_ALL_LED_IND);

	FileTest();

	/*//
	 // Start the SimpleLink Host
	 //
	 VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);

	 //
	 // Start the WlanStationMode task
	 //
	 osi_TaskCreate( WlanStationMode, (const signed char*)"Wlan Station Task",
	 OSI_STACK_SIZE, NULL, 1, NULL );
	 //
	 // Start the task scheduler
	 //
	 osi_start();*/
}
示例#9
0
文件: acc.c 项目: Edward850/acc
int main(int argc, char **argv)
{
	int i;

	ArgCount = argc;
	ArgVector = argv;
	DisplayBanner();
	Init();
	TK_OpenSource(acs_SourceFileName);
	PC_OpenObject(ObjectFileName, DEFAULT_OBJECT_SIZE, 0);
	PA_Parse();
	PC_CloseObject();
	TK_CloseSource();

	MS_Message(MSG_NORMAL, "\n\"%s\":\n  %d line%s (%d included)\n",
		acs_SourceFileName, tk_Line, tk_Line == 1 ? "" : "s",
		tk_IncludedLines);
	MS_Message(MSG_NORMAL, "  %d function%s\n  %d script%s\n",
		pc_FunctionCount, pc_FunctionCount == 1 ? "" : "s",
		pa_ScriptCount, pa_ScriptCount == 1 ? "" : "s");
	for (i = 0; pa_TypedScriptCounts[i].TypeName; i++)
	{
		if (pa_TypedScriptCounts[i].TypeCount > 0)
		{
			MS_Message(MSG_NORMAL, "%5d %s\n",
				pa_TypedScriptCounts[i].TypeCount,
				pa_TypedScriptCounts[i].TypeName);
		}
	}
	MS_Message(MSG_NORMAL, "  %d global variable%s\n"
						   "  %d world variable%s\n"
						   "  %d map variable%s\n"
						   "  %d global array%s\n"
						   "  %d world array%s\n",
		pa_GlobalVarCount, pa_GlobalVarCount == 1 ? "" : "s",
		pa_WorldVarCount, pa_WorldVarCount == 1 ? "" : "s",
		pa_MapVarCount, pa_MapVarCount == 1 ? "" : "s",
		pa_GlobalArrayCount, pa_GlobalArrayCount == 1 ? "" : "s",
		pa_WorldArrayCount, pa_WorldArrayCount == 1 ? "" : "s"
		);
	MS_Message(MSG_NORMAL, "  object \"%s\": %d bytes\n",
		ObjectFileName, pc_Address);
	ERR_RemoveErrorFile();
	return 0;
}
示例#10
0
//****************************************************************************
//							MAIN FUNCTION
//****************************************************************************
void main()
{
    char cMode = 0;

    //
    // Board Initialization
    //
    BoardInit();

    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
#ifndef NOTERM
    InitTerm();
#endif  //NOTERM
    //
    // Display banner
    //
    DisplayBanner(APP_NAME);

    //
    // staring simplelink
    //
    cMode = sl_Start(NULL,NULL,NULL);

    //
    // Display current mode and ssid name(for AP mode)
    //
    DisplayCurrentConfig(cMode);

    //
    // Configure the networking mode and ssid name(for AP mode)
    //
    ConfigureMode(cMode);

    UART_PRINT("Please restart the device \n\r");
    sl_Stop(SL_STOP_TIMEOUT);
    LOOP_FOREVER(line_number);

}
示例#11
0
文件: main.c 项目: dlugaz/All
int main()
{
    long lRetVal = -1;

    //
    // Board Initialization
    //
    BoardInit();

    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Display banner
    //
    DisplayBanner(APP_NAME);

    InitializeAppVariables();

    lRetVal = ServerFileDownload();

    if(lRetVal < 0)
    {
        UART_PRINT("Server file download failed\n\r");
        LOOP_FOREVER();
    }
    else
    {
        UART_PRINT("Downloading File Completed\n\r");
    }
    UART_PRINT("\nThank you\r\n");
    // Stop the CC3200 device
    lRetVal = sl_Stop(SL_STOP_TIMEOUT);
    
    LOOP_FOREVER();
}
示例#12
0
//****************************************************************************
//
//! Main function
//!
//! \param none
//!
//! This function
//!    1. Invokes the Loader Task
//!
//! \return None.
//
//****************************************************************************
void main()
{
    BoardInit();
    PinMuxConfig();

    InitTerm();

    DisplayBanner(APPLICATION_NAME);

    // Start the SimpleLink Host 
    VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);

    // Start the Loader task 
    osi_TaskCreate(Loader, (const signed char*)"Loader Task", \
                                OSI_STACK_SIZE, NULL, 1, NULL );

    // Start the task scheduler 
    osi_start();
}
示例#13
0
//*****************************************************************************
//                            MAIN FUNCTION
//*****************************************************************************
void main()
{
    //
    // Board Initialization
    //
    BoardInit();
    
    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();
    
#ifndef NOTERM
    //
    // Configuring UART
    //
    InitTerm();
#endif

    //
    // Display banner
    //
    DisplayBanner(APP_NAME);
    
    //
    // Start the SimpleLink Host
    //
    VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    
    //
    // Start the WlanAPMode task
    //
    osi_TaskCreate( WlanAPMode,
                            (const signed char*)"wireless LAN in AP mode",
                            OSI_STACK_SIZE, NULL, 1, NULL );
    
    //
    // Start the task scheduler
    //
    osi_start();
}
示例#14
0
文件: main.c 项目: nqngo22/CC3200_LED
//****************************************************************************
//
//! Main function
//!
//! \param none
//! 
//! This function  
//!    1. Invokes the LEDBlinkyTask
//!
//! \return None.
//
//****************************************************************************
int
main()
{
    //
    // Initialize Board configurations
    //
    BoardInit();
    
    //
    // Power on the corresponding GPIO port B for 9,10,11.
    // Set up the GPIO lines to mode 0 (GPIO)
    //
    PinMuxConfig();

	#ifndef NOTERM
		//
		// Configuring UART
		//
		InitTerm();
	#endif

	DisplayBanner("Lab 0");
    Message("\t\t****************************************************\n\r");
    Message("\t\t\t        CC3200 UART Echo Usage        \n\r");
    Message("\t\t To get to state 3, the user must press and hold SW2  \n\r");
    Message("\t\t then press SW3 without releasing SW2   \n\r");
    Message("\t\t and then release SW2 while continuing to press SW3\n\r");
    Message("\n\n\n\r");

    GPIO_IF_LedConfigure(LED1|LED2|LED3);

    GPIO_IF_LedOff(MCU_ALL_LED_IND);
    
    //
    // Start the LEDBlinkyRoutine
    //
    LEDBlinkyRoutine();
    return 0;
}
示例#15
0
//*****************************************************************************
//
//! Main function handling the interrupt example
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************
void
main()
{
    //
    // Initialize board configurations
    BoardInit();
    PinMuxConfig();
    
    //
    // Configuring UART
    //
    InitTerm();

    //
    // Display Banner
    //
    DisplayBanner(APP_NAME);
    
    //
    // Do Interrupt Test
    //
    DoInterruptTest();
    while(1);
}
示例#16
0
文件: main.c 项目: robbie-cao/cc3200
//****************************************************************************
//                            MAIN FUNCTION
//****************************************************************************
void main()
{
    long   lRetVal = -1;

    //
    // Board Initilization
    //
    BoardInit();
    
    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();

    PinConfigSet(PIN_58,PIN_STRENGTH_2MA|PIN_STRENGTH_4MA,PIN_TYPE_STD_PD);

    // Initialize Global Variables
    InitializeAppVariables();
    
    //
    // UART Init
    //
    InitTerm();
    
    DisplayBanner(APP_NAME);

    //
    // LED Init
    //
    GPIO_IF_LedConfigure(LED1);
      
    //Turn Off the LEDs
    GPIO_IF_LedOff(MCU_RED_LED_GPIO);
       
    //
    // I2C Init
    //
    lRetVal = I2C_IF_Open(I2C_MASTER_MODE_FST);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }    

    //Init Temprature Sensor
    lRetVal = TMP006DrvOpen();
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }    

    //Init Accelerometer Sensor
    lRetVal = BMA222Open();
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }    
    
    //
    // Simplelinkspawntask
    //
    lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }    
    
    //
    // Create OOB Task
    //
    lRetVal = osi_TaskCreate(OOBTask, (signed char*)"OOBTask", \
                                OSI_STACK_SIZE, NULL, \
                                OOB_TASK_PRIORITY, NULL );
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }    

    //
    // Start OS Scheduler
    //
    osi_start();

    while (1)
    {

    }

}
示例#17
0
//****************************************************************************
//
//! Task function implementing the TCP server and showcasing the  
//! deepsleep functionality
//!
//! \param none
//! 
//! This function  
//!    1. Creates a TCP socket and binds to it
//!    2. Listens on the socket
//!    3. Accepts a client connection
//!    4. Receives a packet on the socket
//!    5. Closes the socket
//!
//! \return None.
//
//****************************************************************************
void TCPServerTask(void *pvParameters)
{
    int iSocketDesc, iClientFD;
    struct sockaddr_in sClientAddr;
    int iRecvLen;
    unsigned int iClientAddrLen = sizeof(sClientAddr);
    unsigned char aucRecvBuffer[MAX_BUF];

    DisplayBanner(APPLICATION_NAME);

    DBG_PRINT("DEEPSLEEP: Test Begin\n\r");

    //
    // GPIO Configuration
    //
    GPIO_IF_LedConfigure(LED1|LED3);

    GPIO_IF_LedOff(MCU_RED_LED_GPIO);
    GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);	

    //
    // Start the driver
    //
    Network_IF_InitDriver(ROLE_STA);

    GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);
    LedTimerConfigNStart();

    // Initialize AP security params
    SecurityParams.Key = SECURITY_KEY;
    SecurityParams.KeyLen = strlen(SECURITY_KEY);
    SecurityParams.Type = SECURITY_TYPE;

    //
    // Connect to the Access Point
    //
    Network_IF_ConnectAP(SSID_NAME,SecurityParams);

    LedTimerDeinitStop();

    //
    // Switch ON RED LED to indicate that Device acquired an IP
    //
    GPIO_IF_LedOn(MCU_IP_ALLOC_IND);

    //
    // Create and Bind TCP server socket
    //
    iSocketDesc = CreateTCPServerSocket(APP_TCP_PORT);
    if(iSocketDesc < 0)
    {
        DBG_PRINT("DEEPSLEEP: Socket create failed\n");
        goto end;
    }
    DBG_PRINT("DEEPSLEEP: Socket created\n\r");
    DBG_PRINT("DEEPSLEEP: Listening on Socket...\n\r");

    //
    // Start Listening on the socket
    //
    if( listen(iSocketDesc, 5) != 0)
    {
        DBG_PRINT("DEEPSLEEP: Listen failed\n\r");
        goto end;
    }

    while(FOREVER)
    {
        //
        // Accept new client connections (Here just one)
        //
        DBG_PRINT("DEEPSLEEP: Waiting for client.......\n\r");
        iClientFD = accept(iSocketDesc, 
                       (struct sockaddr*)&sClientAddr, 
                       &iClientAddrLen);
        DBG_PRINT("DEEPSLEEP: Connected to client [0x%x] \n\r", 
                           htonl(sClientAddr.sin_addr.s_addr));

        do
        {
            //
            // Receive on the socket
            //
            iRecvLen = recv(iClientFD,aucRecvBuffer,MAX_BUF,0);

            if(iRecvLen > 0)
            {
                DBG_PRINT("DEEPSLEEP: received %d bytes\n\r", iRecvLen);
                DBG_PRINT("DEEPSLEEP: received message : %s\n\r", aucRecvBuffer);
            }
        }while(iRecvLen > 0);

        //
        // Close the client descriptor
        //
        close(iClientFD);
    }

    //
    // Close the socket. Commented as not expected to reach here
    //
    //close(iSocketDesc);

end:
    DBG_PRINT("DEEPSLEEP: Test Complete\n\r");
    //
    // Loop here
    //
    while(1);
}
示例#18
0
文件: main.c 项目: gale320/cc3200
//*****************************************************************************
//
//! main - populate the parameters from predefines Test Vector or User
//!
//! \param None
//!
//! \return None
//
//*****************************************************************************
void
main()
{
    unsigned int uiConfig,uiHashLength,uiDataLength;
    unsigned char *puiKey1,*puiData,*puiResult;
    unsigned int u8count;
#ifndef USER_INPUT
    unsigned char *puiTempExpResult;
#endif
    //
    // Initialize board configurations
    BoardInit();
    //
    // Configuring UART for Receiving input and displaying output
    // 1. PinMux setting
    // 2. Initialize UART
    // 3. Displaying Banner
    //
    PinMuxConfig();
    InitTerm();
    DisplayBanner(APP_NAME);

    //
    // Enable the module .
    //
    MAP_PRCMPeripheralClkEnable(PRCM_DTHE, PRCM_RUN_MODE_CLK);
    //
    // Enable interrupts.
    //
    MAP_SHAMD5IntRegister(SHAMD5_BASE, SHAMD5IntHandler);

#ifdef USER_INPUT
    while(FOREVER)
    {
        //
        // Read values either from User or from Vector based on macro USER_INPUT
        // defined or not
        //

        //
        // Read the values from the user over uart and Populate the variables
        //
        puiData=ReadFromUser(&uiConfig,&uiHashLength,&puiKey1,&uiDataLength,
                             &puiResult);
        if(puiData==NULL)
        {
            continue;
        }
#else
    //
    // Load Default values
    //
    UART_PRINT("Running Keyed Hashing HMAC_MD5\n\r\n\r");
    UART_PRINT("loading default values\n\r\n\r");
    uiHMAC=1;
    puiData= LoadDefaultValues(SHAMD5_ALGO_HMAC_MD5,&uiConfig,&uiHashLength,
                               &puiKey1,&uiDataLength,&puiResult);
    UART_PRINT("Data Length (in Bytes) %d\n\r\n\r",uiDataLength);
#endif

        //
        // Generate Hash Value
        //
        UART_PRINT("\n\rHashing in Progress... \n\r");
        GenerateHash(uiConfig,puiKey1,puiData,puiResult,uiDataLength);
        UART_PRINT("Hash Value is generated\n\r");
        //
        // Display/Verify Result
        //

#ifdef USER_INPUT
        //
        // Display Hash Value Generated
        //
        UART_PRINT("\n\r The Hash Value in Hex is: 0x%02x",*puiResult);
        for(u8count=0; u8count<(uiHashLength/4); u8count++)
        {
            UART_PRINT("%02x",*(puiResult+u8count));
        }
        UART_PRINT("\n\r");
    } //end while(FOREVER)
#else
        //
        // Comapre Hash Generated and expected values from predefined vector
        //
        UART_PRINT("Hash Length (in Bytes) %d\n\r\n\r",uiHashLength);
        UART_PRINT("\n\r Computed Hash Value in Hex is: ");
        for(u8count=0; u8count<uiHashLength; u8count++)
        {
            UART_PRINT("%02x",*(puiResult+u8count));
        }
        UART_PRINT("\n\r");

        puiTempExpResult = (unsigned char *)g_psHMACShaMD5TestVectors.puiExpectedHash;

        UART_PRINT("\n\r Expected Hash Value in Hex is: ");
        for(u8count=0; u8count<uiHashLength; u8count++)
        {
            UART_PRINT("%02x",*(puiTempExpResult+u8count));
        }
        UART_PRINT("\n\r");

        if(memcmp(puiResult,g_psHMACShaMD5TestVectors.puiExpectedHash,uiHashLength)==0)
        {
            UART_PRINT("\n\r Hashing verified successfully");
        }
        else
        {
            UART_PRINT("\n\r Error in Hashing computation");
        }
        while(FOREVER);
#endif


}
示例#19
0
//*****************************************************************************
//
//! Main function handling the I2C example
//!
//! \param  None
//!
//! \return None
//! 
//*****************************************************************************
void main()
{
    int iRetVal;
    char acCmdStore[512];
    
    //
    // Initialize board configurations
    //
    BoardInit();
    
    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();
    
    //
    // Configuring UART
    //
    InitTerm();
    
    //
    // I2C Init
    //
    I2C_IF_Open(I2C_MASTER_MODE_FST);
    
    //
    // Display the banner followed by the usage description
    //
    DisplayBanner(APP_NAME);
    DisplayUsage();

    while(FOREVER)
    {
      //
      // Provide a prompt for the user to enter a command
      //
      DisplayPrompt();
      
      //
      // Get the user command line
      //
      iRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));

      if(iRetVal < 0)
      {
          //
          // Error in parsing the command as length is exceeded.
          //
          UART_PRINT("Command length exceeded 512 bytes \n\r");
          DisplayUsage();
      }
      else if(iRetVal == 0)
      {
          //
          // No input. Just an enter pressed probably. Display a prompt.
          //
      }
      else
      {
          //
          // Parse the user command and try to process it.
          //
          iRetVal = ParseNProcessCmd(acCmdStore);
          if(iRetVal < 0)
          {
              UART_PRINT("Error in processing command\n\r");
              DisplayUsage();
          }
      }
    }
}
示例#20
0
int PSPSaveDialog::Update()
{
	switch (status) {
	case SCE_UTILITY_STATUS_FINISHED:
		status = SCE_UTILITY_STATUS_SHUTDOWN;
		break;
	default:
		break;
	}

	if (status != SCE_UTILITY_STATUS_RUNNING)
		return SCE_ERROR_UTILITY_INVALID_STATUS;

	if (!param.GetPspParam()) {
		status = SCE_UTILITY_STATUS_SHUTDOWN;
		return 0;
	}

	// The struct may have been updated by the game.  This happens in "Where Is My Heart?"
	// Check if it has changed, reload it.
	// TODO: Cut down on preloading?  This rebuilds the list from scratch.
	int size = Memory::Read_U32(requestAddr);
	if (memcmp(Memory::GetPointer(requestAddr), &originalRequest, size) != 0) {
		memset(&request, 0, sizeof(request));
		Memory::Memcpy(&request, requestAddr, size);
		Memory::Memcpy(&originalRequest, requestAddr, size);
		param.SetPspParam(&request);
	}

	buttons = __CtrlPeekButtons();
	UpdateFade();

	okButtonImg = I_CIRCLE;
	cancelButtonImg = I_CROSS;
	okButtonFlag = CTRL_CIRCLE;
	cancelButtonFlag = CTRL_CROSS;
	if (param.GetPspParam()->common.buttonSwap == 1) {
		okButtonImg = I_CROSS;
		cancelButtonImg = I_CIRCLE;
		okButtonFlag = CTRL_CROSS;
		cancelButtonFlag = CTRL_CIRCLE;
	}

	I18NCategory *d = GetI18NCategory("Dialog");

	switch (display)
	{
		case DS_SAVE_LIST_CHOICE:
			StartDraw();

			DisplaySaveList();
			DisplaySaveDataInfo1();

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				// Save exist, ask user confirm
				if (param.GetFileInfo(currentSelectedSave).size > 0) {
					yesnoChoice = 0;
					display = DS_SAVE_CONFIRM_OVERWRITE;
				} else {
					display = DS_SAVE_SAVING;
					if (param.Save(param.GetPspParam(), GetSelectedSaveDirName())) {
						param.SetPspParam(param.GetPspParam()); // Optim : Just Update modified save
						display = DS_SAVE_DONE;
					} else
						display = DS_SAVE_LIST_CHOICE; // This will probably need error message ?
				}
			}
			EndDraw();
		break;
		case DS_SAVE_CONFIRM:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(d->T("Confirm Save", "Do you want to save this data?"), true);

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				display = DS_SAVE_SAVING;
				if (param.Save(param.GetPspParam(), GetSelectedSaveDirName())) {
					param.SetPspParam(param.GetPspParam()); // Optim : Just Update modified save
					display = DS_SAVE_DONE;
				} else {
					// TODO: This should probably show an error message?
					StartFade(false);
				}
			}

			EndDraw();
		break;
		case DS_SAVE_CONFIRM_OVERWRITE:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(d->T("Confirm Overwrite","Do you want to overwrite the data?"), true);

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
				if (param.GetPspParam()->mode != SCE_UTILITY_SAVEDATA_TYPE_SAVE)
					display = DS_SAVE_LIST_CHOICE;
				else {
					param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
					StartFade(false);
				}
			} else if (IsButtonPressed(okButtonFlag)) {
				display = DS_SAVE_SAVING;
				if (param.Save(param.GetPspParam(), GetSelectedSaveDirName())) {
					param.SetPspParam(param.GetPspParam()); // Optim : Just Update modified save
					display = DS_SAVE_DONE;
				} else {
					// TODO: This should probably show an error message?
					if (param.GetPspParam()->mode != SCE_UTILITY_SAVEDATA_TYPE_SAVE)
						display = DS_SAVE_LIST_CHOICE;
					else
						StartFade(false);
				}
			}

			EndDraw();
		break;
		case DS_SAVE_SAVING:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(d->T("Saving","Saving\nPlease Wait..."));

			DisplayBanner(DB_SAVE);

			EndDraw();
		break;
		case DS_SAVE_DONE:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(d->T("Save completed"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
				// Set the save to use for autosave and autoload
				param.SetSelectedSave(param.GetFileInfo(currentSelectedSave).idx);
				StartFade(false);
			}

			EndDraw();
		break;

		case DS_LOAD_LIST_CHOICE:
			StartDraw();
			
			DisplaySaveList();
			DisplaySaveDataInfo1();

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				display = DS_LOAD_LOADING;
				if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave))
					display = DS_LOAD_DONE;
			}

			EndDraw();
		break;
		case DS_LOAD_CONFIRM:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(d->T("ConfirmLoad", "Load this data?"), true);

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				display = DS_LOAD_LOADING;
				if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave))
					display = DS_LOAD_DONE;
				else {
					param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
					StartFade(false);
				}
			}

			EndDraw();
		break;
		case DS_LOAD_LOADING:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(d->T("Loading","Loading\nPlease Wait..."));

			DisplayBanner(DB_LOAD);

			EndDraw();
		break;
		case DS_LOAD_DONE:
			StartDraw();
			
			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(d->T("Load completed"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
				// Set the save to use for autosave and autoload
				param.SetSelectedSave(param.GetFileInfo(currentSelectedSave).idx);
				StartFade(false);
			}

			EndDraw();
		break;
		case DS_LOAD_NODATA:
			StartDraw();

			DisplayMessage(d->T("There is no data"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
				StartFade(false);
			}

			EndDraw();
		break;

		case DS_DELETE_LIST_CHOICE:
			StartDraw();
			
			DisplaySaveList();
			DisplaySaveDataInfo1();

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				yesnoChoice = 0;
				display = DS_DELETE_CONFIRM;
			}

			EndDraw();
		break;
		case DS_DELETE_CONFIRM:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(d->T("DeleteConfirm", 
						"This save data will be deleted.\nAre you sure you want to continue?"), 
						true);

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag))
				display = DS_DELETE_LIST_CHOICE;
			else if (IsButtonPressed(okButtonFlag)) {
				if (yesnoChoice == 0)
					display = DS_DELETE_LIST_CHOICE;
				else {
					display = DS_DELETE_DELETING;
					if (param.Delete(param.GetPspParam(),currentSelectedSave)) {
						param.SetPspParam(param.GetPspParam()); // Optim : Just Update modified save
						display = DS_DELETE_DONE;
					} else 		
						display = DS_DELETE_LIST_CHOICE; // This will probably need error message ?
				}
			}

			EndDraw();
		break;
		case DS_DELETE_DELETING:
			StartDraw();

			DisplayMessage(d->T("Deleting","Deleting\nPlease Wait..."));

			DisplayBanner(DB_DELETE);

			EndDraw();
		break;
		case DS_DELETE_DONE:
			StartDraw();
			
			DisplayMessage(d->T("Delete completed"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag)) {
				if (param.GetFilenameCount() == 0)
					display = DS_DELETE_NODATA;
				else
					display = DS_DELETE_LIST_CHOICE;
			}

			EndDraw();
		break;
		case DS_DELETE_NODATA:
			StartDraw();
			
			DisplayMessage(d->T("There is no data"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
				StartFade(false);
			}

			EndDraw();
		break;

		case DS_NONE: // For action which display nothing
		{
			switch ((SceUtilitySavedataType)(u32)param.GetPspParam()->mode)
			{
				case SCE_UTILITY_SAVEDATA_TYPE_LOAD: // Only load and exit
				case SCE_UTILITY_SAVEDATA_TYPE_AUTOLOAD:
					if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave))
						param.GetPspParam()->common.result = 0;
					else
						param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				case SCE_UTILITY_SAVEDATA_TYPE_SAVE: // Only save and exit
				case SCE_UTILITY_SAVEDATA_TYPE_AUTOSAVE:
					if (param.Save(param.GetPspParam(), GetSelectedSaveDirName()))
						param.GetPspParam()->common.result = 0;
					else
						param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_SAVE_MS_NOSPACE;
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				case SCE_UTILITY_SAVEDATA_TYPE_SIZES:
					param.GetPspParam()->common.result = param.GetSizes(param.GetPspParam());
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				case SCE_UTILITY_SAVEDATA_TYPE_LIST:
					param.GetList(param.GetPspParam());
					param.GetPspParam()->common.result = 0;
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				case SCE_UTILITY_SAVEDATA_TYPE_FILES:
					param.GetPspParam()->common.result = param.GetFilesList(param.GetPspParam());
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				case SCE_UTILITY_SAVEDATA_TYPE_GETSIZE:
					{
						bool result = param.GetSize(param.GetPspParam());
						// TODO: According to JPCSP, should test/verify this part but seems edge casey.
						if (MemoryStick_State() != PSP_MEMORYSTICK_STATE_DRIVER_READY)
							param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_MEMSTICK;
						else if (result)
							param.GetPspParam()->common.result = 0;
						else
							param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
						status = SCE_UTILITY_STATUS_FINISHED;
					}
				break;
				case SCE_UTILITY_SAVEDATA_TYPE_DELETEDATA:
					// TODO: This should probably actually delete something.
					// For now, always say it couldn't be deleted.
					WARN_LOG(SCEUTILITY, "FAKE sceUtilitySavedata DELETEDATA: %s", param.GetPspParam()->saveName);
					param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_STATUS;
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				//case SCE_UTILITY_SAVEDATA_TYPE_AUTODELETE:
				case SCE_UTILITY_SAVEDATA_TYPE_SINGLEDELETE:
					if (param.Delete(param.GetPspParam(), param.GetSelectedSave()))
						param.GetPspParam()->common.result = 0;
					else
						param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				// TODO: Should reset the directory's other files.
				case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATA:
				case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE:
					if (param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE))
						param.GetPspParam()->common.result = 0;
					else
						param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATA:
				case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE:
					if (param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE))
						param.GetPspParam()->common.result = 0;
					else
						param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				case SCE_UTILITY_SAVEDATA_TYPE_READDATA:
				case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE:
					if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave, param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE))
						param.GetPspParam()->common.result = 0;
					else
						param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA; // not sure if correct code
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
				default:
					status = SCE_UTILITY_STATUS_FINISHED;
				break;
			}
		}
		break;
		default:
			status = SCE_UTILITY_STATUS_FINISHED;
		break;
	}

	lastButtons = buttons;

	if (status == SCE_UTILITY_STATUS_FINISHED)
		Memory::Memcpy(requestAddr, &request, request.common.size);
	
	return 0;
}
示例#21
0
//****************************************************************************
//                            MAIN FUNCTION
//****************************************************************************
void main()
{
    long retVal = -1;
    unsigned long ulResetCause;
    unsigned long ulDestinationIP;

    //
    // Board Initialization
    //
    BoardInit();

    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Initialize WDT
    //
    WDT_IF_Init(NULL,80000000 * 10);

    //
    // Get the reset cause
    //
    ulResetCause = PRCMSysResetCauseGet();

    //
    // If watchdog triggered reset request hibernate
    // to clean boot the system
    //
    if( ulResetCause == PRCM_WDT_RESET )
    {
        HIBEntrePreamble();
        MAP_PRCMOCRRegisterWrite(0,1);
        MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR);
        MAP_PRCMHibernateIntervalSet(330);
        MAP_PRCMHibernateEnter();
    }

    //
    // uDMA Initialization
    //
    UDMAInit();

    //
    // Display banner
    //
    DisplayBanner(APPLICATION_NAME);

    if( ulResetCause == PRCM_HIB_EXIT &&  (MAP_PRCMOCRRegisterRead(0) & 1) == 1 )
    {
        UART_PRINT("Reset Cause        : Watchdog Reset\n\r");
    }
    else
    {
        UART_PRINT("Reset Cause        : Power On\n\r");

        //
        // Initialize the variables.
        //
        InitializeAppVariables();

        //
        // Following function configure the device to default state by cleaning
        // the persistent settings stored in NVMEM (viz. connection profiles &
        // policies, power policy etc)
        //
        // Applications may choose to skip this step if the developer is sure
        // that the device is in its desired state at start of applicaton
        //
        // Note that all profiles and persistent settings that were done on the
        // device will be lost
        //
        retVal = ConfigureSimpleLinkToDefaultState();

        if(retVal < 0)
        {
            if (DEVICE_NOT_IN_STATION_MODE == retVal)
                UART_PRINT("Failed to configure the device in its default"
                            " state \n\r");

            LOOP_FOREVER();
        }
    }

    //
    // Set destination IP
    //
    ulDestinationIP = IP_ADDR;

    //
    // Asumption is that the device is configured in station mode already
    // and it is in its default state
    //
    retVal = sl_Start(0, 0, 0);

    //
    // Acknowledge the watchdog so that it doesn't resets
    //
    WatchdogAck();

    if (retVal < 0 || retVal != ROLE_STA)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    //
    //Connecting to WLAN AP
    //
    retVal = WlanConnect();

    //
    // Acknowledge the watchdog so that it doesn't resets
    //
    WatchdogAck();

    if(retVal < 0)
    {
        UART_PRINT("Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Connected to AP    : %s \n\r",SSID_NAME);

    UART_PRINT("Device IP          : %d.%d.%d.%d\n\r\n\r",
                SL_IPV4_BYTE(g_ulIpAddr,3),
                SL_IPV4_BYTE(g_ulIpAddr,2),
                SL_IPV4_BYTE(g_ulIpAddr,1),
                SL_IPV4_BYTE(g_ulIpAddr,0));


    UART_PRINT("\nStarting UDP Client\n\n\r");

    UART_PRINT("Source IP          : %d.%d.%d.%d\n\r"
                 "Destination IP     : %d.%d.%d.%d\n\r"
                 "PORT               : %d\n\r",
                 SL_IPV4_BYTE(g_ulIpAddr,3),
                 SL_IPV4_BYTE(g_ulIpAddr,2),
                 SL_IPV4_BYTE(g_ulIpAddr,1),
                 SL_IPV4_BYTE(g_ulIpAddr,0),
                 SL_IPV4_BYTE(ulDestinationIP,3),
                 SL_IPV4_BYTE(ulDestinationIP,2),
                 SL_IPV4_BYTE(ulDestinationIP,1),
                 SL_IPV4_BYTE(ulDestinationIP,0),
                 g_uiPortNum);


    //
    // Acknowledge the watchdog so that it doesn't resets
    //
    WatchdogAck();

    //
    // Send packets
    //
    BsdUdpClient(PORT_NUM,ulDestinationIP);


    //
    // power off the network processor
    //
    sl_Stop(SL_STOP_TIMEOUT);
    while (1)
    {
        _SlNonOsMainLoopTask();
    }
}
示例#22
0
//*****************************************************************************
//
//! \brief Task Created by main fucntion.This task starts simpleink, set NWP
//!        power policy, connects to an AP. Give Signal to the other task about
//!        the connection.wait for the message form the interrupt handlers and
//!        the other task. Accordingly print the wake up cause from the low
//!        power modes.
//!
//! \param pvParameters is a general void pointer (not used here).
//!
//! \return none
//
//*****************************************************************************
void TimerGPIOTask(void *pvParameters)
{
    cc_hndl tTimerHndl = NULL; 
    cc_hndl tGPIOHndl = NULL;
    unsigned char ucQueueMsg = 0;
    unsigned char ucSyncMsg = 0;
    int iRetVal = 0;
    //
    // Displays the Application Banner
    //
    DisplayBanner();
    
    //
    // creating the queue for signalling about connection events
    //
    iRetVal = osi_MsgQCreate(&g_tConnection, NULL, sizeof( unsigned char ), 3);
    if (iRetVal < 0)
    {
        UART_PRINT("unable to create the msg queue\n\r");
        LOOP_FOREVER();
    }
    
    //
    // starting the simplelink
    //
    iRetVal = sl_Start(NULL, NULL, NULL);
    if (iRetVal < 0)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    //
    // Swtich to STA mode if device is not
    //
    SwitchToStaMode(iRetVal);
    
    //
    // Set the power management policy of NWP
    //
    iRetVal = sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0);
    if (iRetVal < 0)
    {
        UART_PRINT("unable to configure network power policy\n\r");
        LOOP_FOREVER();
    }

    //
    // connecting to the Access Point
    //
    if(-1 == WlanConnect())
    {
        sl_Stop(SL_STOP_TIMEOUT);
        UART_PRINT("Connection to AP failed\n\r");
    }
    else
    {
        UART_PRINT("Connected to AP\n\r");
        //
        //signal the other task about the sl start and connection to the AP
        //
        iRetVal = osi_MsgQWrite(&g_tConnectionFlag, &ucSyncMsg,
                                OSI_WAIT_FOREVER);
        if (iRetVal < 0)
        {
            UART_PRINT("unable to create the msg queue\n\r");
            LOOP_FOREVER();
        }
    }
    
    //
    // Queue management related configurations
    //
    iRetVal = osi_MsgQCreate(&g_tWkupSignalQueue, NULL,
                             sizeof( unsigned char ), 10);
    if (iRetVal < 0)
    {
        UART_PRINT("unable to create the msg queue\n\r");
        LOOP_FOREVER();
    }

    //
    // setting Timer as one of the wakeup source
    //
    tTimerHndl = SetTimerAsWkUp();
    
    //
    // setting some GPIO as one of the wakeup source
    //
    tGPIOHndl = SetGPIOAsWkUp();
    
    /* handles, if required, can be used to stop the timer, but not used here*/
    UNUSED(tTimerHndl);
    UNUSED(tGPIOHndl);
    //
    // setting Apps power policy
    //
    lp3p0_setup_power_policy(POWER_POLICY_STANDBY);
    
    while(FOREVER)
    {
        //
        // waits for the message from the various interrupt handlers(GPIO,
        // Timer) and the UDPServerTask.
        //
        osi_MsgQRead(&g_tWkupSignalQueue, &ucQueueMsg, OSI_WAIT_FOREVER);
        switch(ucQueueMsg){
        case 1:
            UART_PRINT("timer\n\r");
            break;
        case 2:
            UART_PRINT("GPIO\n\r");
            break;
        case 3:
            UART_PRINT("host irq\n\r");
            break;
        default:
            UART_PRINT("invalid msg\n\r");
            break;
        }
    }
}
示例#23
0
//*****************************************************************************
//
//! main - calls Crypt function after populating either from pre- defined vector 
//! or from User
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************
void 
main()
{
    unsigned long  uiAdcInputPin;  
    unsigned int  uiChannel;
    unsigned int  uiIndex=0;
    unsigned long ulSample;      

    //
    // Initialize Board configurations
    //
    BoardInit();

    //
    // Configuring UART for Receiving input and displaying output
    // 1. PinMux setting
    // 2. Initialize UART
    // 3. Displaying Banner
    //
    PinMuxConfig();
    InitTerm();
    DisplayBanner(APP_NAME);

    while(FOREVER)
    {
        //
        // Initialize Array index for multiple execution
        //
        uiIndex=0;
      
        //
        // Read inputs from user
        //
        if(!ReadFromUser(&uiAdcInputPin))
        {
          UART_PRINT("\n\rInvalid Input. Please try again. HAHAHAHAHAHAHAHAHA\n\r");
          continue;
        }

#ifdef CC3200_ES_1_2_1
        //
        // Enable ADC clocks.###IMPORTANT###Need to be removed for PG 1.32
        //
        HWREG(GPRCM_BASE + GPRCM_O_ADC_CLK_CONFIG) = 0x00000043;
        HWREG(ADC_BASE + ADC_O_ADC_CTRL) = 0x00000004;
        HWREG(ADC_BASE + ADC_O_ADC_SPARE0) = 0x00000100;
        HWREG(ADC_BASE + ADC_O_ADC_SPARE1) = 0x0355AA00;
#endif
        //
        // Pinmux for the selected ADC input pin
        //
        MAP_PinTypeADC(uiAdcInputPin,PIN_MODE_255);

        //
        // Convert pin number to channel number
        //
        switch(uiAdcInputPin)
        {
            case PIN_58:
                uiChannel = ADC_CH_1;
                break;
            case PIN_59:
                uiChannel = ADC_CH_2;
                break;
            case PIN_60:
                uiChannel = ADC_CH_3;
                break;
            default:
                break;
        }

        //
        // Configure ADC timer which is used to timestamp the ADC data samples
        //
        MAP_ADCTimerConfig(ADC_BASE,2^17);

        //
        // Enable ADC timer which is used to timestamp the ADC data samples
        //
        MAP_ADCTimerEnable(ADC_BASE);

        //
        // Enable ADC module
        //
        MAP_ADCEnable(ADC_BASE);

        //
        // Enable ADC channel
        //

        MAP_ADCChannelEnable(ADC_BASE, uiChannel);

        while(uiIndex < NO_OF_SAMPLES + 4)
        {
            if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel))
            {
                ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel);
                pulAdcSamples[uiIndex++] = ulSample;
            }


        }

        MAP_ADCChannelDisable(ADC_BASE, uiChannel);

        uiIndex = 0;

        //UART_PRINT("\n\rTotal no of 32 bit ADC data printed :4096 \n\r");
        //UART_PRINT("\n\rADC data format:\n\r");
        //UART_PRINT("\n\rbits[13:2] : ADC sample\n\r");
        //UART_PRINT("\n\rbits[31:14]: Time stamp of ADC sample \n\r");

        //
        // Print out ADC samples
        //

        while(uiIndex < NO_OF_SAMPLES)
        {
            UART_PRINT("\n\rVoltage is %f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.4)/4096);
            uiIndex++;
        }


        //UART_PRINT("\n\rVoltage is %f\n\r",((pulAdcSamples[4] >> 2 ) & 0x0FFF)*1.4/4096);
        UART_PRINT("\n\r");

    }

}
示例#24
0
文件: main.c 项目: oter/BSPTools
int main()
{
    long lRetVal = -1;

    //
    // Initialize Board configurations
    //
    BoardInit();

    //
    // Pinmuxing for GPIO,UART
    //
    PinMuxConfig();

    //
    // configure LEDs
    //
    GPIO_IF_LedConfigure(LED1|LED2|LED3);

    GPIO_IF_LedOff(MCU_ALL_LED_IND);

    #ifndef NOTERM  
    //
    // Configuring UART
    //
    InitTerm();
    #endif
    //
    // Display Welcome Message
    //
    DisplayBanner(APP_NAME);

    // Generate Menu Output for Application
    OutputMenu();

    // Initialize AP security params
    SecurityParams.Key = (signed char *)SECURITY_KEY;
    SecurityParams.KeyLen = strlen(SECURITY_KEY);
    SecurityParams.Type = SECURITY_TYPE;
    uiUartCmd=0;

    //
    // Simplelinkspawntask
    //
    lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    if(lRetVal < 0)
    {
    ERR_PRINT(lRetVal);
    LOOP_FOREVER();
    }

    lRetVal = osi_MsgQCreate(&g_PBQueue,"PBQueue",sizeof(tPushButtonMsg),1);
    if(lRetVal < 0)
    {
    ERR_PRINT(lRetVal);
    LOOP_FOREVER();
    }

    lRetVal = osi_TaskCreate(PushButtonHandler, \
                            (signed char*)"PushButtonHandler", \
                            OSI_STACK_SIZE , NULL, \
                            TASK_PRIORITY+2, &g_PushButtonTask );
    if(lRetVal < 0)
    {
    ERR_PRINT(lRetVal);
    LOOP_FOREVER();
    }

    lRetVal = osi_TaskCreate(SimpleEmail, (signed char*)"SimpleEmail", \
                                OSI_STACK_SIZE, \
                                NULL, TASK_PRIORITY+1, NULL );
    if(lRetVal < 0)
    {
    ERR_PRINT(lRetVal);
    LOOP_FOREVER();
    }

    osi_start();

    while(1)
    {

    }

}
//****************************************************************************
//                            MAIN FUNCTION
//****************************************************************************
void main()
{
    long lRetVal = 0;
    char data[BUF_SIZE];
    char sent_data[BUF_SIZE];
    unsigned char highByte, lowByte;
    int i;

    unsigned long tempStartTimeStamp, tempStopTimeStamp;

    memset(sent_data, 0, 10);
    // Board Initialization
    BoardInit();

    // Configure the pinmux settings for the peripherals exercised
    PinMuxConfig();

    // Initialize the PWM outputs on the board
    InitServos();

    // Initialize the sensor ADC
    InitSensorADC();

    // Configuring UART
    InitTerm();

    // Display banner
    DisplayBanner(APPLICATION_NAME);

    // Connect to WIFI using default info
    //WlanConnect(NULL, NULL, NULL);
    WlanConnect("Nagui's Network", "SL_SEC_TYPE_WPA", "19520605");

    // Setup the TCP Server Socket
    BsdTcpServerSetup(PORT_NUM);

    // Recieve Data
    while (lRetVal >= 0)
    {
    	lRetVal = BsdTcpServerReceive(data);

		//SysTickPeriodSet(800000000);				// test
		//SysTickEnable();						// test
    	Timer_IF_Init(PRCM_TIMERA0, TIMERA0_BASE, TIMER_CFG_PERIODIC, TIMER_A, 0);
    	Timer_IF_Start(TIMERA0_BASE, TIMER_A, MILLISECONDS_TO_TICKS(2000));
		//tempStartTimeStamp = SysTickValueGet();		// test
    	tempStartTimeStamp = Timer_IF_GetCount(TIMERA0_BASE, TIMER_A);

    	for (i = 0; i<NUM_SERVOS; i++)
    	{
    		MoveServo((unsigned char)data[i], (enum Servo_Joint_Type)i);
    		UART_PRINT("%d", (unsigned int) data[i]);
    	}

    	for (i = 0; i< NUM_SENSORS; i++)
    	{
        	//UnsignedShort_to_UnsignedChar(GetSensorReading((enum Fingertip_Sensor_Type)i), &highByte, &lowByte);
    		UnsignedShort_to_UnsignedChar(GetSensorReading(SENSOR_FINGER_INDEX), &highByte, &lowByte);
        	sent_data[i*2] = (char)highByte;
        	sent_data[i*2+1] = (char)lowByte;
    	}
    	//tempStopTimeStamp = SysTickValueGet();					// test
    	tempStopTimeStamp = Timer_IF_GetCount(TIMERA0_BASE, TIMER_A);
    	lRetVal = BsdTcpServerSend(sent_data, 10);
    	UART_PRINT("timestamp start: %lu\n\r", tempStartTimeStamp);	//test
    	UART_PRINT("timestamp stop: %lu\n\r", tempStopTimeStamp);	//test
    	UART_PRINT("Sent 10 bytes to client.\n\r");

    }
    UART_PRINT("Exiting Application ...\n\r");

    // power of the Network processor
    lRetVal = sl_Stop(SL_STOP_TIMEOUT);

}
示例#26
0
int PSPSaveDialog::Update(int animSpeed)
{
	if (GetStatus() != SCE_UTILITY_STATUS_RUNNING)
		return SCE_ERROR_UTILITY_INVALID_STATUS;

	if (!param.GetPspParam()) {
		ChangeStatusShutdown(SAVEDATA_SHUTDOWN_DELAY_US);
		return 0;
	}

	if (pendingStatus != SCE_UTILITY_STATUS_RUNNING) {
		// We're actually done, we're just waiting to tell the game that.
		return 0;
	}

	// The struct may have been updated by the game.  This happens in "Where Is My Heart?"
	// Check if it has changed, reload it.
	// TODO: Cut down on preloading?  This rebuilds the list from scratch.
	int size = Memory::Read_U32(requestAddr);
	if (memcmp(Memory::GetPointer(requestAddr), &originalRequest, size) != 0) {
		memset(&request, 0, sizeof(request));
		Memory::Memcpy(&request, requestAddr, size);
		Memory::Memcpy(&originalRequest, requestAddr, size);
		lock_guard guard(paramLock);
		param.SetPspParam(&request);
	}

	UpdateButtons();
	UpdateFade(animSpeed);

	okButtonImg = I_CIRCLE;
	cancelButtonImg = I_CROSS;
	okButtonFlag = CTRL_CIRCLE;
	cancelButtonFlag = CTRL_CROSS;
	if (param.GetPspParam()->common.buttonSwap == 1) {
		okButtonImg = I_CROSS;
		cancelButtonImg = I_CIRCLE;
		okButtonFlag = CTRL_CROSS;
		cancelButtonFlag = CTRL_CIRCLE;
	}

	I18NCategory *di = GetI18NCategory("Dialog");

	switch (display)
	{
		case DS_SAVE_LIST_CHOICE:
			StartDraw();

			DisplaySaveList();
			DisplaySaveDataInfo1();

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				// Save exist, ask user confirm
				if (param.GetFileInfo(currentSelectedSave).size > 0) {
					yesnoChoice = 0;
					display = DS_SAVE_CONFIRM_OVERWRITE;
				} else {
					display = DS_SAVE_SAVING;
					StartIOThread();
				}
			}
			EndDraw();
		break;
		case DS_SAVE_CONFIRM:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("Confirm Save", "Do you want to save this data?"), true);

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				display = DS_SAVE_SAVING;
				StartIOThread();
			}

			EndDraw();
		break;
		case DS_SAVE_CONFIRM_OVERWRITE:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("Confirm Overwrite","Do you want to overwrite the data?"), true);

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
				if (param.GetPspParam()->mode != SCE_UTILITY_SAVEDATA_TYPE_SAVE)
					display = DS_SAVE_LIST_CHOICE;
				else {
					param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
					StartFade(false);
				}
			} else if (IsButtonPressed(okButtonFlag)) {
				display = DS_SAVE_SAVING;
				StartIOThread();
			}

			EndDraw();
		break;
		case DS_SAVE_SAVING:
			if (ioThreadStatus != SAVEIO_PENDING) {
				JoinIOThread();
			}

			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("Saving","Saving\nPlease Wait..."));

			DisplayBanner(DB_SAVE);

			EndDraw();
		break;
		case DS_SAVE_FAILED:
			JoinIOThread();
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("SavingFailed", "Unable to save data."));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag)) {
				// Go back to the list so they can try again.
				if (param.GetPspParam()->mode != SCE_UTILITY_SAVEDATA_TYPE_SAVE) {
					display = DS_SAVE_LIST_CHOICE;
				} else {
					param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
					StartFade(false);
				}
			}

			EndDraw();
		break;
		case DS_SAVE_DONE:
			if (ioThread) {
				JoinIOThread();
				param.SetPspParam(param.GetPspParam());
			}
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("Save completed"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_SAVE);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
				// Set the save to use for autosave and autoload
				param.SetSelectedSave(param.GetFileInfo(currentSelectedSave).idx);
				StartFade(false);
			}

			EndDraw();
		break;

		case DS_LOAD_LIST_CHOICE:
			StartDraw();
			
			DisplaySaveList();
			DisplaySaveDataInfo1();

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				display = DS_LOAD_LOADING;
				StartIOThread();
			}

			EndDraw();
		break;
		case DS_LOAD_CONFIRM:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("ConfirmLoad", "Load this data?"), true);

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				display = DS_LOAD_LOADING;
				StartIOThread();
			}

			EndDraw();
		break;
		case DS_LOAD_LOADING:
			if (ioThreadStatus != SAVEIO_PENDING) {
				JoinIOThread();
			}

			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("Loading","Loading\nPlease Wait..."));

			DisplayBanner(DB_LOAD);

			EndDraw();
		break;
		case DS_LOAD_FAILED:
			JoinIOThread();
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("LoadingFailed", "Unable to load data."));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			if (IsButtonPressed(cancelButtonFlag)) {
				// Go back to the list so they can try again.
				if (param.GetPspParam()->mode != SCE_UTILITY_SAVEDATA_TYPE_LOAD) {
					display = DS_LOAD_LIST_CHOICE;
				} else {
					param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
					StartFade(false);
				}
			}

			EndDraw();
		break;
		case DS_LOAD_DONE:
			JoinIOThread();
			StartDraw();
			
			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("Load completed"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			// Allow OK to be pressed as well to confirm the save.
			// The PSP only allows cancel, but that's generally not great UX.
			// Allowing this here makes it quicker for most users to get into the actual game.
			if (IsButtonPressed(cancelButtonFlag) || IsButtonPressed(okButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
				// Set the save to use for autosave and autoload
				param.SetSelectedSave(param.GetFileInfo(currentSelectedSave).idx);
				StartFade(false);
			}

			EndDraw();
		break;
		case DS_LOAD_NODATA:
			StartDraw();

			DisplayMessage(di->T("There is no data"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_LOAD);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
				StartFade(false);
			}

			EndDraw();
		break;

		case DS_DELETE_LIST_CHOICE:
			StartDraw();
			
			DisplaySaveList();
			DisplaySaveDataInfo1();

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
				StartFade(false);
			} else if (IsButtonPressed(okButtonFlag)) {
				yesnoChoice = 0;
				display = DS_DELETE_CONFIRM;
			}

			EndDraw();
		break;
		case DS_DELETE_CONFIRM:
			StartDraw();

			DisplaySaveIcon();
			DisplaySaveDataInfo2();

			DisplayMessage(di->T("DeleteConfirm", 
						"This save data will be deleted.\nAre you sure you want to continue?"), 
						true);

			DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag))
				display = DS_DELETE_LIST_CHOICE;
			else if (IsButtonPressed(okButtonFlag)) {
				if (yesnoChoice == 0)
					display = DS_DELETE_LIST_CHOICE;
				else {
					display = DS_DELETE_DELETING;
					StartIOThread();
				}
			}

			EndDraw();
		break;
		case DS_DELETE_DELETING:
			if (ioThreadStatus != SAVEIO_PENDING) {
				JoinIOThread();
			}

			StartDraw();

			DisplayMessage(di->T("Deleting","Deleting\nPlease Wait..."));

			DisplayBanner(DB_DELETE);

			EndDraw();
		break;
		case DS_DELETE_FAILED:
			JoinIOThread();
			StartDraw();

			DisplayMessage(di->T("DeleteFailed", "Unable to delete data."));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag)) {
				display = DS_DELETE_LIST_CHOICE;
			}

			EndDraw();
		break;
		case DS_DELETE_DONE:
			if (ioThread) {
				JoinIOThread();
				param.SetPspParam(param.GetPspParam());
			}
			StartDraw();
			
			DisplayMessage(di->T("Delete completed"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag)) {
				if (param.GetFilenameCount() == 0)
					display = DS_DELETE_NODATA;
				else
					display = DS_DELETE_LIST_CHOICE;
			}

			EndDraw();
		break;
		case DS_DELETE_NODATA:
			StartDraw();
			
			DisplayMessage(di->T("There is no data"));

			DisplayButtons(DS_BUTTON_CANCEL);
			DisplayBanner(DB_DELETE);

			if (IsButtonPressed(cancelButtonFlag)) {
				param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
				StartFade(false);
			}

			EndDraw();
		break;

		case DS_NONE: // For action which display nothing
			switch (ioThreadStatus) {
			case SAVEIO_NONE:
				StartIOThread();
				break;
			case SAVEIO_PENDING:
			case SAVEIO_DONE:
				// To make sure there aren't any timing variations, we sync the next frame.
				JoinIOThread();
				ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0);
				break;
			}
		break;

		default:
			ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0);
		break;
	}

	if (status == SCE_UTILITY_STATUS_FINISHED || pendingStatus == SCE_UTILITY_STATUS_FINISHED)
		Memory::Memcpy(requestAddr, &request, request.common.size);
	
	return 0;
}
示例#27
0
/*-----------------------------------------------------------------
 * @Desc: the acutal Takeover game-playing is done here
 *
 *
 *-----------------------------------------------------------------*/
void
PlayGame (void)
{
  int countdown = 100;   /* lenght of Game in 1/10 seconds */
  char count_text[80];
  int FinishTakeover = FALSE;
  int row;

  Uint32 prev_count_tick, count_tick_len;  /* tick vars for count-down */
  Uint32 prev_move_tick, move_tick_len;    /* tick vars for motion */
  Uint32 last_movekey_time, wait_move_ticks = 110;    /* number of ticks to wait before "key-repeat" */

  int up, down, set; 
  int up_counter, down_counter; 
  int wheel_up, wheel_down;

  count_tick_len = 100;   /* countdown in 1/10 second steps */
  move_tick_len  = 60;    /* allow motion at this tick-speed in ms */
  
  up = down = set = FALSE;
  up_counter = down_counter = 0;
  wheel_up = wheel_down = 0;

  prev_count_tick = prev_move_tick = SDL_GetTicks (); /* start tick clock */
  
  ResetMouseWheel ();  // forget about previous wheel events

  CountdownSound();
  while (!FinishTakeover)
    {
      cur_time = SDL_GetTicks ();
      
      /* 
       * here we register if there have been key-press events in the
       * "waiting period" between move-ticks :
       */
      if ( !up && UpPressed () )
	{
	  up = TRUE;
	  last_movekey_time = SDL_GetTicks();
	}
      if (!down && DownPressed() )
	{
	  down = TRUE;
	  last_movekey_time = SDL_GetTicks();
	}

      set  = set  || (SpacePressed() || MouseLeftPressed());

      if (WheelUpPressed()) wheel_up ++;
      if (WheelDownPressed()) wheel_down ++;

      /* allow for a WIN-key that give immedate victory */
      if ( KeyIsPressedR ('w') && CtrlPressed() && AltPressed() )
	{
	  LeaderColor = YourColor;   /* simple as that */
	  return;  /* leave now, to avoid changing of LeaderColor! */
	} 
	
      if ( cur_time > prev_count_tick + count_tick_len ) /* time to count 1 down */
	{
	  prev_count_tick += count_tick_len;  /* set for next countdown tick */
	  countdown--;
	  sprintf (count_text, "Finish-%d", countdown);
	  DisplayBanner (count_text, NULL , 0 );

	  if (countdown && (countdown%10 == 0) ) CountdownSound();
	  if (countdown == 0)
	    {
	      EndCountdownSound();
	      FinishTakeover = TRUE;
	    }

	  AnimateCurrents ();  /* do some animation on the active cables */

	} /* if (countdown_tick has occurred) */


      /* time for movement */
      if ( cur_time > prev_move_tick + move_tick_len )  
	{
	  prev_move_tick += move_tick_len; /* set for next motion tick */
	  EnemyMovements ();

	  if (wheel_up || (up && (SDL_GetTicks() - last_movekey_time > wait_move_ticks)))
	    {
	      CapsuleCurRow[YourColor]--;
	      if (CapsuleCurRow[YourColor] < 1)
		CapsuleCurRow[YourColor] = NUM_LINES;
	
	      if (!UpPressed()) up = FALSE;  
	      if (wheel_up) wheel_up --;
	    }
	  if (wheel_down || (down && (SDL_GetTicks() - last_movekey_time > wait_move_ticks)))
	    {
	      CapsuleCurRow[YourColor]++;
	      if (CapsuleCurRow[YourColor] > NUM_LINES)
		CapsuleCurRow[YourColor] = 1;

	      if (!DownPressed()) down = FALSE;
	      if (wheel_down) wheel_down --;
	    }    

	  if ( set && (NumCapsules[YOU] > 0))
	    {
	      set = FALSE;
	      row = CapsuleCurRow[YourColor] - 1;
	      if ((row >= 0) &&
		  (ToPlayground[YourColor][0][row] != KABELENDE) &&
		  (ActivationMap[YourColor][0][row] == INACTIVE))
		{
		  NumCapsules[YOU]--;
		  CapsuleCurRow[YourColor] = 0;
		  ToPlayground[YourColor][0][row] = VERSTAERKER;
		  ActivationMap[YourColor][0][row] = ACTIVE1;
		  CapsuleCountdown[YourColor][0][row] = CAPSULE_COUNTDOWN * 2;

		  Takeover_Set_Capsule_Sound ();
		}	/* if (row > 0 && ... ) */
	    } /* if ( set ) */

	  ProcessCapsules ();	/* count down the lifetime of the capsules */

	  ProcessPlayground ();
	  ProcessPlayground ();
	  ProcessPlayground ();
	  ProcessPlayground ();	/* this has to be done several times to be sure */

	  ProcessDisplayColumn ();

	} /* if (motion_tick has occurred) */

      ShowPlayground ();

    }	/* while !FinishTakeover */

  /* Schluss- Countdown */
  countdown = CAPSULE_COUNTDOWN;

  while (countdown--)
    {
      while ( SDL_GetTicks() < prev_count_tick + count_tick_len ) ;
      prev_count_tick += count_tick_len;
      ProcessCapsules ();	/* count down the lifetime of the capsules */
      ProcessCapsules ();	/* do it twice this time to be faster */
      AnimateCurrents ();
      ProcessPlayground ();
      ProcessPlayground ();
      ProcessPlayground ();
      ProcessPlayground ();	/* this has to be done several times to be sure */
      ProcessDisplayColumn ();
      ShowPlayground ();

    }	/* while (countdown) */

    return;

} /* PlayGame() */
示例#28
0
/*-----------------------------------------------------------------
 * @Desc: play takeover-game against a druid 
 *
 * @Ret: TRUE/FALSE:  user has won/lost
 *
 *-----------------------------------------------------------------*/
int
Takeover (int enemynum)
{
  int row;
  int FinishTakeover = FALSE;
  static int RejectEnergy = 0;	/* your energy if you're rejected */
  char *message;
  SDL_Rect buf;
  Uint32 now;

  /* Prevent distortion of framerate by the delay coming from 
   * the time spend in the menu.
   */
  Activate_Conservative_Frame_Computation ();

  // release fire keys
  SpacePressedR();
  MouseLeftPressedR();

  // Takeover game always uses Classic User_Rect:
  Copy_Rect (User_Rect, buf);
  Copy_Rect (Classic_User_Rect, User_Rect);

  DisplayBanner (NULL, NULL,  BANNER_FORCE_UPDATE );
  
  Fill_Rect (User_Rect, to_bg_color);

  Me.status = MOBILE; /* the new status _after_ the takeover game */

  SDL_ShowCursor (SDL_DISABLE); // no mouse-cursor in takeover game!

  show_droid_info ( Me.type, -1 , 0);
  show_droid_portrait (Cons_Droid_Rect, Me.type, DROID_ROTATION_TIME, UPDATE);
  while (!FirePressedR())
    show_droid_portrait (Cons_Droid_Rect, Me.type, DROID_ROTATION_TIME, 0);

  show_droid_info ( AllEnemys[enemynum].type, -2 ,0);
  show_droid_portrait (Cons_Droid_Rect,  AllEnemys[enemynum].type, DROID_ROTATION_TIME, UPDATE);
  while (!FirePressedR())
    show_droid_portrait (Cons_Droid_Rect,  AllEnemys[enemynum].type, DROID_ROTATION_TIME, 0);

  SDL_BlitSurface (takeover_bg_pic, NULL, ne_screen, NULL);
  DisplayBanner (NULL, NULL,  BANNER_FORCE_UPDATE );

  while (!FinishTakeover)
    {
      /* Init Color-column and Capsule-Number for each opponenet and your color */
      for (row = 0; row < NUM_LINES; row++)
	{
	  DisplayColumn[row] = (row % 2);
	  CapsuleCountdown[GELB][0][row] = -1;
	  CapsuleCountdown[VIOLETT][0][row] = -1;
	}			/* for row */

      YourColor = GELB;
      OpponentColor = VIOLETT;

      CapsuleCurRow[GELB] = 0;
      CapsuleCurRow[VIOLETT] = 0;
      
      DroidNum = enemynum;
      OpponentType = AllEnemys[enemynum].type;
      NumCapsules[YOU] = 3 + ClassOfDruid (Me.type);
      NumCapsules[ENEMY] = 4 + ClassOfDruid (OpponentType);

      InventPlayground ();

      ShowPlayground ();

      ChooseColor ();

      PlayGame ();

      /* Ausgang beurteilen und returnen */
      if (InvincibleMode || (LeaderColor == YourColor))
	{
	  Takeover_Game_Won_Sound ();
	  if (Me.type == DRUID001)
	    {
	      RejectEnergy = Me.energy;
	      PreTakeEnergy = Me.energy;
	    }

	  // We provide some security agains too high energy/health values gained
	  // by very rapid successions of successful takeover attempts
	  if (Me.energy > Druidmap[DRUID001].maxenergy) Me.energy = Druidmap[DRUID001].maxenergy;
	  if (Me.health > Druidmap[DRUID001].maxenergy) Me.health = Druidmap[DRUID001].maxenergy;

	  // We allow to gain the current energy/full health that was still in the 
	  // other droid, since all previous damage must be due to fighting damage,
	  // and this is exactly the sort of damage can usually be cured in refreshes.
	  Me.energy += AllEnemys[enemynum].energy;
	  Me.health += Druidmap[OpponentType].maxenergy;

	  Me.type = AllEnemys[enemynum].type;

	  RealScore += Druidmap[OpponentType].score;

	  DeathCount += OpponentType * OpponentType;   // quadratic "importance", max=529

	  AllEnemys[enemynum].status = OUT; // removed droid silently (no blast!)

	  if (LeaderColor != YourColor)	/* only won because of InvincibleMode */
	    message = "You cheat";
	  else				/* won the proper way */
	    message = "Complete";

	  FinishTakeover = TRUE;
	}				/* LeaderColor == YourColor */
      else if (LeaderColor == OpponentColor)
	{
	  // you lost, but enemy is killed too --> blast it!
	  AllEnemys[enemynum].energy = -1.0;  /* to be sure */

	  Takeover_Game_Lost_Sound ();
	  if (Me.type != DRUID001)
	    {
	      message = "Rejected";
	      Me.type = DRUID001;
	      Me.energy = RejectEnergy;
	    }
	  else
	    {
	      message = "Burnt Out";
	      Me.energy = 0;
	    }
	  FinishTakeover = TRUE;
	}			/* LeadColor == OpponentColor */
      else
	{
	  Takeover_Game_Deadlock_Sound ();
	  message = "Deadlock";
	}			/* LeadColor == REMIS */

      DisplayBanner (message, NULL , 0 );	
      ShowPlayground ();
      now = SDL_GetTicks();
      while ((!FirePressedR()) && (SDL_GetTicks() - now < SHOW_WAIT) ) SDL_Delay(1);

    }	/* while !FinishTakeover */

  // restore User_Rect
  Copy_Rect (buf, User_Rect);

  ClearGraphMem();
  SDL_Flip(ne_screen);

  if (LeaderColor == YourColor)
    return TRUE;
  else
    return FALSE;

} /* Takeover() */
示例#29
0
//*****************************************************************************
//
//! Main  Function
//
//*****************************************************************************
int main()
{

    //
    // Initialize Board configurations
    //
    BoardInit();

    //
    // Pinmux for UART
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Display Application Banner
    //
    DisplayBanner(APP_NAME);

    //
    // Enable pull down
    //
    MAP_PinConfigSet(PIN_05,PIN_TYPE_STD_PD,PIN_STRENGTH_6MA);


    //
    // Register timer interrupt hander
    //
    MAP_TimerIntRegister(TIMERA2_BASE,TIMER_A,TimerIntHandler);

    //
    // Configure the timer in edge count mode
    //
    MAP_TimerConfigure(TIMERA2_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME));

    //
    // Set the detection edge
    //
    MAP_TimerControlEvent(TIMERA2_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);

    //
    // Set the reload value
    //
    MAP_TimerLoadSet(TIMERA2_BASE,TIMER_A,0xffff);


    //
    // Enable capture event interrupt
    //
    MAP_TimerIntEnable(TIMERA2_BASE,TIMER_CAPA_EVENT);

    //
    // Enable Timer
    //
    MAP_TimerEnable(TIMERA2_BASE,TIMER_A);


    while(1)
    {
        //
        // Report the calculate frequency
        //
        Report("Frequency : %d Hz\n\n\r",g_ulFreq);

        //
        // Delay loop
        //
        MAP_UtilsDelay(80000000/5);
    }
}
示例#30
0
int main()
{

    unsigned char ucP2PParam[4];
    long lRetVal = -1;

    //
    // Initialize Board configurations
    //
    BoardInit();
    
    //
    // Pinmuxing for GPIO, UART
    //
    PinMuxConfig();
    
    //
    // configure LEDs
    //
    GPIO_IF_LedConfigure(LED1|LED2|LED3);
    
    // off all LEDs
    GPIO_IF_LedOff(MCU_ALL_LED_IND);
    
#ifndef NOTERM
    //
    // Configuring UART
    //
    InitTerm();
#endif

    
    //
    // Display the Application Banner
    //
    DisplayBanner(APP_NAME);

    UART_PRINT("Scan Wi-FI direct device in your handheld device\n\r");

    // Initializing the CC3200 device
    lRetVal = StartDeviceInP2P();
    if(lRetVal < 0)
    {
    	LOOP_FOREVER(__LINE__);
    }

    // Set any p2p option (SL_CONNECTION_POLICY(0,0,0,any_p2p,0)) to connect to
    // first available p2p device
    sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL,0);

    // Set the negotiation role (SL_P2P_ROLE_NEGOTIATE).
    // CC3200 will negotiate with remote device GO/client mode.
    // Other valid options are:
    //             - SL_P2P_ROLE_GROUP_OWNER
    //             - SL_P2P_ROLE_CLIENT
    sl_WlanPolicySet(SL_POLICY_P2P, SL_P2P_POLICY(SL_P2P_ROLE_NEGOTIATE,
            SL_P2P_NEG_INITIATOR_ACTIVE),NULL,0);


    // Set P2P Device name
    sl_NetAppSet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN,
            strlen(P2P_DEVICE_NAME), (unsigned char *)P2P_DEVICE_NAME);

    // Set P2P device type
    sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_DEV_TYPE,
            strlen(P2P_CONFIG_VALUE), (unsigned char*)P2P_CONFIG_VALUE);

    // setting P2P channel parameters
    ucP2PParam[0] = LISENING_CHANNEL;
    ucP2PParam[1] = REGULATORY_CLASS;
    ucP2PParam[2] = OPERATING_CHANNEL;
    ucP2PParam[3] = REGULATORY_CLASS;

    // Set P2P Device listen and open channel valid channels are 1/6/11
    sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_CHANNEL_N_REGS,
                sizeof(ucP2PParam), ucP2PParam);

    // Restart as P2P device
    sl_Stop(SL_STOP_TIMEOUT);
    lRetVal = sl_Start(NULL,NULL,NULL);

    if(lRetVal < 0 || lRetVal != ROLE_P2P)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER(__LINE__);
    }
    else
    {
        UART_PRINT("Connect to %s \n\r",P2P_DEVICE_NAME);
    }
    
    /* Connect to configure P2P device */
    lRetVal = WlanConnect();

    if(lRetVal == 0)
    {
        GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
    }
    else
    {
        UART_PRINT("Reset the device and try again\n\r");
        LOOP_FOREVER(__LINE__);
    }

    DisplayIP();
    UART_PRINT("Send TCP packets from your handheld device to CC3200's IP\n\r");
    
    /*After calling this function, you can start sending data to CC3200 IP
    * address on PORT_NUM */
    if(!(IS_CONNECT_FAILED(g_ulStatus)))
        BsdTcpServer(PORT_NUM);

    UART_PRINT("Received TCP packets successfully \n\r");
    
    // revert Device into STA mode and power off Network Processor
    sl_WlanSetMode(ROLE_STA);
    sl_Stop(SL_STOP_TIMEOUT);
    UART_PRINT("Test passed, exiting application... \n\r");
    while(1)
    {
        _SlNonOsMainLoopTask();
    }
}