Exemplo n.º 1
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      AppInit
 *
 *  DESCRIPTION
 *      This user application function is called after a power-on reset
 *      (including after a firmware panic), after a wakeup from Hibernate or
 *      Dormant sleep states, or after an HCI Reset has been requested.
 *
 *      NOTE: In the case of a power-on reset, this function is called
 *      after AppPowerOnReset().
 *
 *  PARAMETERS
 *      last_sleep_state [in]   Last sleep state
 *
 *  RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
void AppInit(sleep_state last_sleep_state)
{
    /* Initialise communications */
    DebugInit(1, uartRxDataCallback, NULL);

    DebugWriteString("Hello, world\r\n");
}
Exemplo n.º 2
0
// This should probably
// dump to a file or something in the future.  (or maybe send out sockets messages
// to a console)
void debug( char *sMessage, ... )
{
    //    MessageBox(NULL, "debug function start", "Debug message",MB_OK | MB_ICONINFORMATION);
    if( !bInitialized && !bAttemptedToConnectToDebugConsole )
    {
        //    MessageBox(NULL, "init", "Debug message",MB_OK | MB_ICONINFORMATION);
        DebugInit();
    }

    if( bInitialized )
    {
        va_list args;
        va_start( args, sMessage );
        //   MessageBox(NULL, "vsprintf", "Debug message",MB_OK | MB_ICONINFORMATION);
        vsprintf( SendBuffer1, sMessage, args );

        //    MessageBox(NULL, "sprintf", "Debug message",MB_OK | MB_ICONINFORMATION);
        sprintf( SendBuffer2, "<debug message=\"%.2047s\"/>\n", SendBuffer1 );

        //    MessageBox(NULL, "send", "Debug message",MB_OK | MB_ICONINFORMATION);
        int bytessent = send( DiagConsoleSocket, SendBuffer2, strlen( SendBuffer2 ), 0 );
        if( bytessent == SOCKET_ERROR )
        {
            bInitialized = false;
        }

        //    MessageBox(NULL, "debug function done", "Debug message",MB_OK | MB_ICONINFORMATION);
    }
}
Exemplo n.º 3
0
/* initialise everything */
void PicocInitialise(Picoc *pc, int StackSize)
{
	memset(pc, '\0', sizeof(*pc));
	PlatformInit(pc);
	BasicIOInit(pc);
	HeapInit(pc, StackSize);
	TableInit(pc);
	VariableInit(pc);
	LexInit(pc);
	TypeInit(pc);

#ifndef NO_HASH_INCLUDE
	IncludeInit(pc);
#endif

	LibraryInit(pc);

#ifdef BUILTIN_MINI_STDLIB
	LibraryAdd(pc, &pc->GlobalTable, "c library", &CLibrary[0]);
	CLibraryInit(pc);
#endif

	PlatformLibraryInit(pc);
	DebugInit(pc);
}
Exemplo n.º 4
0
void PlatInit(void)
{
	SetDebugPort(DEBUG_PORT);
	DebugInit();
	w25x64_init();
	SysTimeInit();
	ShellCmdInit();
	shell_cms_init();
	Signel_led_init();//ÐźŵƳõʼ»¯
}
Exemplo n.º 5
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      AppInit
 *
 *  DESCRIPTION
 *      This user application function is called after a power-on reset
 *      (including after a firmware panic), after a wakeup from Hibernate or
 *      Dormant sleep states, or after an HCI Reset has been requested.
 *
 *      NOTE: In the case of a power-on reset, this function is called
 *      after app_power_on_reset().
 *
 * PARAMETERS
 *      last_sleep_state [in]   Last sleep state
 *
 * RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
void AppInit(sleep_state last_sleep_state)
{
    /* Set sleep mode to never sleep */
    SleepModeChange(sleep_mode_never);

    /* Initialise communications (set Rx callback for every received byte) */
    DebugInit(1, uartRxDataCallback, NULL);

    /* Send usage information to UART */
    showHelp();
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
	DebugInit();
	
	ProcessEnvVars();

	ProcessCommandLine(argc, argv);
	
	DebugShutdown();
	
	return 0;
}
Exemplo n.º 7
0
//---------------------------------------------------------------------------
void SysInit(void)
{
	power_timer2_disable();
	power_adc_disable();
	power_twi_disable();
	power_usart0_disable();
	power_usart1_disable();

	OledInit();
	FrameInit();
	SndInit();
	EepInit();
	KeyInit();
	MathInit();
	RndInit();
	DebugInit();
}
Exemplo n.º 8
0
void UsartInit( void )
{

    sbi( UCSR0A, U2X0 );    // Double-speed
    sbi( UCSR0C, UCSZ01 );  // 8-bit
    sbi( UCSR0C, UCSZ00 );

    UBRR0L = 16;    // 115200

    sbi( UCSR0B, RXEN0 );   // Turn on Rx
    sbi( UCSR0B, TXEN0 );   // Turn on Tx


    sbi( UCSR0B, RXCIE0 );  // Enable Rx interrupts
#ifdef DEBUG
    DebugInit();
#endif

}
Exemplo n.º 9
0
VOID __cdecl BootMain(IN PCCH CmdLine)
{
    CmdLineParse(CmdLine);

    /* Debugger pre-initialization */
    DebugInit(FALSE);

    TRACE("BootMain() called.\n");

    MachInit(CmdLine);

    /* Check if the CPU is new enough */
    FrLdrCheckCpuCompatibility(); // FIXME: Should be done inside MachInit!

    /* UI pre-initialization */
    if (!UiInitialize(FALSE))
    {
        UiMessageBoxCritical("Unable to initialize UI.");
        goto Quit;
    }

    /* Initialize memory manager */
    if (!MmInitializeMemoryManager())
    {
        UiMessageBoxCritical("Unable to initialize memory manager.");
        goto Quit;
    }

    /* Initialize I/O subsystem */
    FsInit();

    RunLoader();

Quit:
    /* If we reach this point, something went wrong before, therefore reboot */
#if defined(__i386__) || defined(_M_AMD64)
    DiskStopFloppyMotor();
#endif
    Reboot();
}
Exemplo n.º 10
0
VOID BootMain(LPSTR CmdLine)
{
    CmdLineParse(CmdLine);

    MachInit(CmdLine);

    FsInit();

    DebugInit();

    TRACE("BootMain() called.\n");

    /* Check if the CPU is new enough */
    FrLdrCheckCpuCompatiblity();

    if (!UiInitialize(FALSE))
    {
        UiMessageBoxCritical("Unable to initialize UI.\n");
        goto quit;
    }

    if (!MmInitializeMemoryManager())
    {
        UiMessageBoxCritical("Unable to initialize memory manager");
        goto quit;
    }

#ifdef _M_IX86
	HalpInitializePciStubs();
	HalpInitBusHandler();
#endif
	RunLoader();

quit:
    /* If we reach this point, something went wrong before, therefore reboot */
    DiskStopFloppyMotor();
    Reboot();
}
Exemplo n.º 11
0
int main()
{
     __disable_irq();


    // ------------------------------------------------------------------ 
    // Desc: System Clk Config
    //
    //  HCLK = PCLK2 = SYSCLK = 72M 
    //  PCLK1 = 36M
    // ------------------------------------------------------------------ 
     SystemInit();
     // SysTick_Config(SystemCoreClock / 1000);

#if 0 
     // ------------------------------------------------------------------ 
     // Desc: CLK OUTPUT for measure
     // ------------------------------------------------------------------ 

     //PA8 alternate mode
     GPIO_InitTypeDef        GPIO_InitStructure;

     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
     GPIO_Init(GPIOA, &GPIO_InitStructure);

     GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_0);    

     RCC_MCOConfig(RCC_MCOSource_PLLCLK,RCC_MCOPrescaler_1);
     // while(1);
#endif


     // ------------------------------------------------------------------ 
     // Desc: Debug 
     // ------------------------------------------------------------------ 
     DebugInit();
     // d_printf("UART debug Init OK\r\n");

     // ------------------------------------------------------------------ 
     // Desc: ILX511 CLK ON
     // ------------------------------------------------------------------ 
#if 1
     {
         GPIO_InitTypeDef        GPIO_InitStructure;
         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
         GPIO_Init(GPIOB, &GPIO_InitStructure);
     }
#endif

#if 0
     ILX_Init();
     __enable_irq();
     ILX_CLKOn();
     delay_nms(50);//CCD power up

     ConvertOn();
#endif


#if 0

     d_printf("\r\n-------------------\r\n");
     {
         uint32_t i;
         for(i=32;i<2048+32;i++)
             d_printf("0x%04X ",data[i]);

     }
#endif


#if 0
    USBInit();
#endif

#if 0
    while (1)
    {
        if (bDeviceState == CONFIGURED)
        {
            CDC_Receive_DATA();
            if (Receive_length  != 0)
            {
                if (packet_sent == 1)
                    CDC_Send_DATA ((unsigned char*)Receive_Buffer,Receive_length);
                Receive_length = 0;
            }
        }
    }
#endif

     while(1);

    return 0;
}
Exemplo n.º 12
0
VOID RunLoader(VOID)
{
    ULONG_PTR SectionId;
    ULONG     OperatingSystemCount;
    OperatingSystemItem* OperatingSystemList;
    PCSTR*    OperatingSystemDisplayNames;
    ULONG     DefaultOperatingSystem;
    LONG      TimeOut;
    ULONG     SelectedOperatingSystem;
    ULONG     i;

    if (!MachInitializeBootDevices())
    {
        UiMessageBoxCritical("Error when detecting hardware.");
        return;
    }

#ifdef _M_IX86
    /* Load additional SCSI driver (if any) */
    if (LoadBootDeviceDriver() != ESUCCESS)
    {
        UiMessageBoxCritical("Unable to load additional boot device drivers.");
    }
#endif

    if (!IniFileInitialize())
    {
        UiMessageBoxCritical("Error initializing .ini file.");
        return;
    }

    /* Debugger main initialization */
    DebugInit(TRUE);

    if (!IniOpenSection("FreeLoader", &SectionId))
    {
        UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
        return;
    }

    TimeOut = GetTimeOut();

    /* UI main initialization */
    if (!UiInitialize(TRUE))
    {
        UiMessageBoxCritical("Unable to initialize UI.");
        return;
    }

    OperatingSystemList = InitOperatingSystemList(&OperatingSystemCount);
    if (!OperatingSystemList)
    {
        UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
        goto Reboot;
    }

    if (OperatingSystemCount == 0)
    {
        UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
        goto Reboot;
    }

    DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemList, OperatingSystemCount);

    /* Create list of display names */
    OperatingSystemDisplayNames = FrLdrTempAlloc(sizeof(PCSTR) * OperatingSystemCount, 'mNSO');
    if (!OperatingSystemDisplayNames)
        goto Reboot;

    for (i = 0; i < OperatingSystemCount; i++)
    {
        OperatingSystemDisplayNames[i] = OperatingSystemList[i].LoadIdentifier;
    }

    /* Find all the message box settings and run them */
    UiShowMessageBoxesInSection("FreeLoader");

    for (;;)
    {
        /* Redraw the backdrop */
        UiDrawBackdrop();

        /* Show the operating system list menu */
        if (!UiDisplayMenu("Please select the operating system to start:",
                           "For troubleshooting and advanced startup options for "
                               "ReactOS, press F8.",
                           TRUE,
                           OperatingSystemDisplayNames,
                           OperatingSystemCount,
                           DefaultOperatingSystem,
                           TimeOut,
                           &SelectedOperatingSystem,
                           FALSE,
                           MainBootMenuKeyPressFilter))
        {
            UiMessageBox("Press ENTER to reboot.");
            goto Reboot;
        }

        TimeOut = -1;

        /* Load the chosen operating system */
        LoadOperatingSystem(&OperatingSystemList[SelectedOperatingSystem]);
    }

Reboot:
    UiUnInitialize("Rebooting...");
    return;
}
    ;  they are included in dcc.xref
#pragma endasm

////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
//
//>  Name:          Project_Startup          
//
//   Type:          Function
//
//   Description:   A main entry point called by the kernel
//
//   Inputs:        none
//
//   Outputs:       none
//
//   Notes:         none
//<
////////////////////////////////////////////////////////////////////////////////
//int jCurrLimEntry=1;
void Project_Startup(void)
{
    //BOOL bDone;
    WORD i;
    //WORD j;
    //DWORD wTime;
    //WORD wCount = 5000;
    //RETCODE retCode;
    
    USHORT  usStatus;
    BOOL bLowPowerUsbStickyBitReadResult = FALSE;

    //bDone = FALSE;
    
    // Startup
    // Run debug initialization
    (DebugInit()== SUCCESS);

    // Let's start with a clean system
    SystemShutdown();

    #pragma asm

        extern  FTimeInit
        jsr     FTimeInit
    
    #pragma endasm
    
// In order to free up P memory space, we're doing the same trick as above for
// some other initialization functions.
    {
        unsigned int ClearSize = (unsigned int)(&_lc_u_y_MMC_bssclear_end-&_lc_u_y_MMC_bssclear_start);

        unsigned int CopySize = (unsigned int)(&_lc_u_y_OVLY_copy_end-&_lc_u_y_OVLY_copy_start);
        
        CopyCodeIntoBootmanagerArea((_Y WORD *)&_lc_u_y_OVLY_copy_start, 
                                    (_P WORD * _P)&_lc_u_p_OVLY_start, CopySize);
        
        // In either case(MMC or NAND only), clear the bss section.
        ClearMemory((_Y WORD *)&_lc_u_y_MMC_bssclear_start, ClearSize);
    }
Exemplo n.º 14
0
int main(int argc, char **argv)
{
	CUNICODE_STRING us;
	THREAD *initial_thread = NULL;
	const char *exename;


	ParseOptions( argc, argv );

	if (optind == argc)
	{
		// default to starting smss.exe
		exename = "\\??\\c:\\winnt\\system32\\smss.exe";
	}
	else
	{
		exename = argv[optind];
	}

	// Read debug channels options
	DebugInit();

	// the skas3 patch is deprecated...
	if (0) InitSkas();

	// pass our path so thread tracing can find the client stub
	InitTt( argv[0] );
	if (!pCreateAddressSpace)
		Die("no way to manage address spaces found\n");

	if (!TraceIsEnabled("core"))
	{
		// enable backtraces
		signal(SIGSEGV, SegvHandler);
		signal(SIGABRT, AbortHandler);
	}

	if (RegistryIndex >= 0)
	{
		TRACE("created registry: %s\n",registry_list[RegistryIndex].name);
		Registry = registry_list[RegistryIndex].create();
	}
	else
	{
		TRACE("created registry: xml\n");
		Registry = REGISTRY_XML::Create();
	}

	// quick sanity test
	ALLOCATION_BITMAP::Test();

	// initialize boottime
	SYSTEM_TIME_OF_DAY_INFORMATION dummy;
	GetSystemTimeOfDay( dummy );

	FIBER::FibersInit();
	InitRoot();
	CreateDirectoryObject( (PWSTR) L"\\" );
	CreateDirectoryObject( (PWSTR) L"\\??" );
	CUNICODE_STRING link_name, link_target;
	link_name.Set( L"\\DosDevices" );
	link_target.Copy( L"\\??" );
	CreateSymlink( link_name, link_target );
	CreateDirectoryObject( (PWSTR) L"\\Device" );
	CreateDirectoryObject( (PWSTR) L"\\Device\\MailSlot" );
	CreateDirectoryObject( (PWSTR) L"\\Security" );
	//create_directory_object( (PWSTR) L"\\DosDevices" );
	CreateDirectoryObject( (PWSTR) L"\\BaseNamedObjects" );
	CreateSyncEvent( (PWSTR) L"\\Security\\LSA_AUTHENTICATION_INITIALIZED" );
	CreateSyncEvent( (PWSTR) L"\\SeLsaInitEvent" );
	InitRandom();
	InitPipeDevice();
	// XP
	CreateDirectoryObject( (PWSTR) L"\\KernelObjects" );
	CreateSyncEvent( (PWSTR) L"\\KernelObjects\\CritSecOutOfMemoryEvent" );
	InitDrives();
	InitNtDLL();
	CreateKThread();

	us.Copy( exename );

	int r = CreateInitialProcess( &initial_thread, us );
	if (r < STATUS_SUCCESS)
		Die("create_initial_process() failed (%08x)\n", r);

	// run the main loop
	Schedule();

	NtGdiFini();
	r = initial_thread->Process->ExitStatus;
	//fprintf(stderr, "process exited (%08x)\n", r);
	Release( initial_thread );

	ShutdownKThread();
	DoCleanup();

	FreeRoot();
	FIBER::FibersFinish();
	FreeNtDLL();

	return r;
}
Exemplo n.º 15
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
    PF_CONSOLE_INIT_ALL()

    // Set global handle
    gHInst = hInst;

    CCmdParser cmdParser(s_cmdLineArgs, arrsize(s_cmdLineArgs));
    cmdParser.Parse();

    bool doIntroDialogs = true;
#ifndef PLASMA_EXTERNAL_RELEASE
    if (cmdParser.IsSpecified(kArgSkipLoginDialog))
        doIntroDialogs = false;
    if (cmdParser.IsSpecified(kArgLocalData))
    {
        gDataServerLocal = true;
        gSkipPreload = true;
    }
    if (cmdParser.IsSpecified(kArgSkipPreload))
        gSkipPreload = true;
#endif

    plFileName serverIni = "server.ini";
    if (cmdParser.IsSpecified(kArgServerIni))
        serverIni = plString::FromWchar(cmdParser.GetString(kArgServerIni));

    // check to see if we were launched from the patcher
    bool eventExists = false;
    // we check to see if the event exists that the patcher should have created
    HANDLE hPatcherEvent = CreateEventW(nil, TRUE, FALSE, L"UruPatcherEvent");
    if (hPatcherEvent != NULL)
    {
        // successfully created it, check to see if it was already created
        if (GetLastError() == ERROR_ALREADY_EXISTS)
        {
            // it already existed, so the patcher is waiting, signal it so the patcher can die
            SetEvent(hPatcherEvent);
            eventExists = true;
        }
    }

#ifdef PLASMA_EXTERNAL_RELEASE
    // if the client was started directly, run the patcher, and shutdown
    STARTUPINFOW si;
    PROCESS_INFORMATION pi; 
    memset(&si, 0, sizeof(si));
    memset(&pi, 0, sizeof(pi));
    si.cb = sizeof(si);

    const char** addrs;
    
    if (!eventExists) // if it is missing, assume patcher wasn't launched
    {
        plStringStream cmdLine;

        GetAuthSrvHostnames(&addrs);
        if (strlen(addrs[0]))
            cmdLine << " /AuthSrv=" << addrs[0];

        GetFileSrvHostnames(&addrs);
        if (strlen(addrs[0]))
            cmdLine << " /FileSrv=" << addrs[0];

        GetGateKeeperSrvHostnames(&addrs);
        if (strlen(addrs[0]))
            cmdLine << " /GateKeeperSrv=" << addrs[0];

        if(!CreateProcessW(s_patcherExeName, (LPWSTR)cmdLine.GetString().ToUtf16().GetData(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
        {
            hsMessageBox("Failed to launch patcher", "Error", hsMessageBoxNormal);
        }
        CloseHandle( pi.hThread );
        CloseHandle( pi.hProcess );
        return PARABLE_NORMAL_EXIT;
    }
#endif

    // Load an optional general.ini
    plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini");
    FILE *generalini = plFileSystem::Open(gipath, "rb");
    if (generalini)
    {
        fclose(generalini);
        pfConsoleEngine tempConsole;
        tempConsole.ExecuteFile(gipath);
    }

#ifdef PLASMA_EXTERNAL_RELEASE
    // If another instance is running, exit.  We'll automatically release our
    // lock on the mutex when our process exits
    HANDLE hOneInstance = CreateMutex(nil, FALSE, "UruExplorer");
    if (WaitForSingleObject(hOneInstance,0) != WAIT_OBJECT_0)
    {
        switch (plLocalization::GetLanguage())
        {
            case plLocalization::kFrench:
                hsMessageBox("Une autre copie d'URU est déjà en cours d'exécution", "Erreur", hsMessageBoxNormal);
                break;
            case plLocalization::kGerman:
                hsMessageBox("URU wird bereits in einer anderen Instanz ausgeführt", "Fehler", hsMessageBoxNormal);
                break;
            case plLocalization::kSpanish:
                hsMessageBox("En estos momentos se está ejecutando otra copia de URU", "Error", hsMessageBoxNormal);
                break;
            case plLocalization::kItalian:
                hsMessageBox("Un'altra copia di URU è già aperta", "Errore", hsMessageBoxNormal);
                break;
            // default is English
            default:
                hsMessageBox("Another copy of URU is already running", "Error", hsMessageBoxNormal);
                break;
        }
        return PARABLE_NORMAL_EXIT;
    }
#endif

    FILE *serverIniFile = plFileSystem::Open(serverIni, "rb");
    if (serverIniFile)
    {
        fclose(serverIniFile);
        pfConsoleEngine tempConsole;
        tempConsole.ExecuteFile(serverIni);
    }
    else
    {
        hsMessageBox("No server.ini file found.  Please check your URU installation.", "Error", hsMessageBoxNormal);
        return PARABLE_NORMAL_EXIT;
    }

    NetCliAuthAutoReconnectEnable(false);

    NetCommSetReadIniAccountInfo(!doIntroDialogs);
    InitNetClientComm();

    curl_global_init(CURL_GLOBAL_ALL);

    bool                needExit = false;
    LoginDialogParam    loginParam;
    memset(&loginParam, 0, sizeof(loginParam));
    LoadUserPass(&loginParam);

    if (!doIntroDialogs && loginParam.remember) {
        ENetError auth;

        NetCommSetAccountUsernamePassword(loginParam.username, loginParam.namePassHash);
        bool cancelled = AuthenticateNetClientComm(&auth, NULL);

        if (IS_NET_ERROR(auth) || cancelled) {
            doIntroDialogs = true;

            loginParam.authError = auth;

            if (cancelled)
            {
                NetCommDisconnect();
            }
        }
    }

    if (doIntroDialogs) {
        needExit = ::DialogBoxParam( hInst, MAKEINTRESOURCE( IDD_URULOGIN_MAIN ), NULL, UruLoginDialogProc, (LPARAM)&loginParam ) <= 0;
    }

    if (doIntroDialogs && !needExit) {
        HINSTANCE hRichEdDll = LoadLibrary("RICHED20.DLL");
        INT_PTR val = ::DialogBoxParam( hInst, MAKEINTRESOURCE( IDD_URULOGIN_EULA ), NULL, UruTOSDialogProc, (LPARAM)hInst);
        FreeLibrary(hRichEdDll);
        if (val <= 0) {
            DWORD error = GetLastError();
            needExit = true;
        }
    }

    curl_global_cleanup();

    if (needExit) {
        DeInitNetClientComm();
        return PARABLE_NORMAL_EXIT;
    }

    NetCliAuthAutoReconnectEnable(true);

    // VERY VERY FIRST--throw up our splash screen
    HWND splashDialog = ::CreateDialog( hInst, MAKEINTRESOURCE( IDD_LOADING ), NULL, SplashDialogProc );

    // Install our unhandled exception filter for trapping all those nasty crashes in release build
#ifndef HS_DEBUGGING
    LPTOP_LEVEL_EXCEPTION_FILTER oldFilter;
    oldFilter = SetUnhandledExceptionFilter( plCustomUnhandledExceptionFilter );
#endif

    //
    // Set up to log errors by using hsDebugMessage
    //
    DebugInit();
    DebugMsgF("Plasma 2.0.%i.%i - %s", PLASMA2_MAJOR_VERSION, PLASMA2_MINOR_VERSION, plProduct::ProductString().c_str());

    for (;;) {
        // Create Window
        if (!WinInit(hInst, nCmdShow) || gClient->GetDone())
            break;

        // Done with our splash now
        ::DestroyWindow( splashDialog );

        if (!gClient)
            break;

        // Show the main window
        ShowWindow(gClient->GetWindowHandle(), SW_SHOW);
            
        // Be really REALLY forceful about being in the front
        BringWindowToTop( gClient->GetWindowHandle() );

        // Update the window
        UpdateWindow(gClient->GetWindowHandle());

        // 
        // Init Application here
        //
        if( !gClient->StartInit() )
            break;
        
        // I want it on top! I mean it!
        BringWindowToTop( gClient->GetWindowHandle() );

        // initialize dinput here:
        if (gClient && gClient->GetInputManager())
            gClient->GetInputManager()->InitDInput(hInst, (HWND)gClient->GetWindowHandle());
        
        // Seriously!
        BringWindowToTop( gClient->GetWindowHandle() );
        
        //
        // Main loop
        //
        MSG msg;
        do
        {   
            gClient->MainLoop();

            if( gClient->GetDone() )
                break;

            // Look for a message
            while (PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ))
            {
                // Handle the message
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
        } while (WM_QUIT != msg.message);

        break;
    }

    //
    // Cleanup
    //
    if (gClient)
    {
        gClient->Shutdown(); // shuts down PhysX for us
        gClient = nil;
    }
    hsAssert(hsgResMgr::ResMgr()->RefCnt()==1, "resMgr has too many refs, expect mem leaks");
    hsgResMgr::Shutdown();  // deletes fResMgr
    DeInitNetClientComm();

    // Uninstall our unhandled exception filter, if we installed one
#ifndef HS_DEBUGGING
    SetUnhandledExceptionFilter( oldFilter );
#endif

    // Exit WinMain and terminate the app....
    return PARABLE_NORMAL_EXIT;
}
Exemplo n.º 16
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      AppInit
 *
 *  DESCRIPTION
 *      This user application function is called after a power-on reset
 *      (including after a firmware panic), after a wakeup from Hibernate or
 *      Dormant sleep states, or after an HCI Reset has been requested.
 *
 *      NOTE: In the case of a power-on reset, this function is called
 *      after app_power_on_reset().
 *
 *  PARAMETERS
 *      last_sleep_state [in]   Last sleep state
 *
 *  RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
void AppInit(sleep_state last_sleep_state)
{
    /* Length octet for first transaction */
    uint16 len = 0U;

    /* Initialise communications */
    DebugInit(1, NULL, NULL);

    /* Set up the queue containing data to be sent to the SPI Master. The queue
     * is read by the SPI Slave library and the data transferred over to the Tx
     * area of the shared RAM when an interrupt from the PIO controller is
     * received. The application can queue data at any time.
     */
    OQSetFill(&(g_spi_data.tx_q), FALSE, 0U);
    OQCreate(g_spi_data.data_tx, MAX_TRANSACTION_SIZE, OQDataMode_packed,
            &(g_spi_data.tx_q));

    /* Set up the queue containing data received from the SPI Master. Data is
     * transferred from the Rx area of the shared memory and added to the queue
     * by the SPI Slave library when it receives an interrupt from the PIO
     * controller. The application may read data from the queue at any time,
     * but in order to prevent the buffer from overflowing and corrupting the
     * incoming data the queue should be read as soon as possible after the data
     * status callback is received.
     */
    OQSetFill(&(g_spi_data.rx_q), FALSE, 0U);
    OQCreate(g_spi_data.data_rx, MAX_TRANSACTION_SIZE, OQDataMode_packed,
            &(g_spi_data.rx_q));

    /* Only enter shallow sleep mode, because the PIO controller needs to run at
     * 16MHz in order to operate the SPI bus at ~1MHz */
    SleepModeChange(sleep_mode_shallow);

    /* Keep awake when WAKE pin is low */
    SleepWakePinEnable(wakepin_mode_low_level);

    /* Queue the length octet for the first transfer */
    OQQueueData(&(g_spi_data.tx_q), &len, 1U);

    /* Initialise the SPI Slave, and fill the Tx area of the shared RAM with the
     * general response octet, which will be sent in tha absence of any data in
     * the queue.
     */
    SpiSlaveInit(PIO_CTRLR_CODE_ADDR, spiSlaveSSELStatusCallback,
            &(g_spi_data.tx_q), &(g_spi_data.rx_q), GENERAL_RESP);

    /* Configure the SPI Slave data callback to occur when the length octet for
     * the next transaction is received. */
    SpiSlaveConfigDataStatusCallback(spiSlaveDataCallback, 1U);

    /* Set the pull-up for the SSEL pin */
    PioSetPullModes(PIO_BIT_MASK(SPI_SLAVE_PIO_SSEL), pio_mode_weak_pull_up);

    /* Set the pull-up for MOSI pin */
    PioSetPullModes(PIO_BIT_MASK(SPI_SLAVE_PIO_MOSI), pio_mode_weak_pull_up);

    /* Set the pull-up/pull-down for SCLK pin, depending on the SPI Mode */
    PioSetPullModes(PIO_BIT_MASK(SPI_SLAVE_PIO_SCLK), PIO_CTRLR_SCLK_PULL_MODE);

    /* Start the SPI slave */
    SpiSlaveStart();

    /* Set state to indicate we're ready to receive the length octet for the
     * next transaction */
    g_spi_data.state = state_waiting_for_len;

    DebugWriteString("\r\nSPI Slave test application, stores previous data sent"
            " from SPI Master and returns the data in the subsequent "
            "transactions\r\n");

    DebugWriteString("Transaction format: \r\n");

    DebugWriteString("<LEN> <delay (at least 60us)> <DATA>\r\n");

    DebugWriteString("Ready to receive data\r\n");
} /* AppInit */
Exemplo n.º 17
0
//--------------------------------------------------------------------------
// Module:
//  main
//
///   This function is the main program. It provides initialization of hardware
///   and software components and software. The main loop  portion handles
///   only the Debug task.
///
//--------------------------------------------------------------------------
void main (void)
{
    UINT_16 temp = 0;

	/* Disable all C167 interrupts */
    DISABLE_ALL_INTERRUPTS();

	/* Don't allow any interrupt processing to occur */
    SetMvbReady (FALSE);
    SetStartupSuccessful (FALSE);

    /* Release MVB IPACK hardware */
    ReleaseIpackHw();

    /* Configure Push-Pull digital IOs at P7 to Digital Outputs */
    DO_Init (0xFF);

	/* Initialize the HiDAC outputs */
    InitP8ForDigOuts();
    InitDigitalOutputs();
    InitAnalogOutputs();

	/* Toggle VDrive and CPU watchdogs */
    ToggleVDriveWatchdog();
    ToggleCPUWatchdog();

    /* Set the state of the HIDAC LEDs */
    HIDAC_TEST_LED_ON();
    HIDAC_FAIL_LED_OFF();

    /* Enable SSMR1, SSMR2, VDrive & +5V to Hex LED Display */
    DO_WriteBank (DIGOUT_BANK2, 0x00FF);

	/* Initialize the software to detect a 15 volt failure */
    Init15VoltFailDetect();
    /* This call initializes the 10 ms Timer ISR 
*/
	InitTimer0();
    InitTimer1 ();
	InitTimer7 ();

	ENABLE_ALL_INTERRUPTS();

	/* Allow the VDrive watchdog to toggle and wait some timer before 
	   trying to drive display */
    SetVdriveDisable (FALSE);
	TM_Wait (250);


    /* Display the stored CRC checksum for approximately 1 second at startup */
    DisplayCRConHexLED();

    /* Perform the RAM Test. */
    if (!VerifyRAM())
    {
        HIDAC_FAIL_LED_ON();
        UpdateHidacError (RAM_FAILURE);
    }

	if (!HidacErrorExists())
	{
		/* Perform the ROM Test. */
		if (!VerifyCRCAtStart())
		{
			HIDAC_FAIL_LED_ON();
			UpdateHidacError (ROM_FAILURE);
		}
	}

    /* Init the RS-232 */
    InitSerialCommunications();

    /* Init the analog inputs */
    InitAnalogInputs();

    /* Init the PWM input hardware */
    PwmInInit();

    /* Init the MVB IPACK interface */
    InitMVBIpack();

	/* DAS This call to InitPwmOutputs needs to be after InitMVBIpack. After Sweden made an
	  an upgrade to the IPACK CPLD to rev 2, for some reason, initializing PWM1 prior to initializing 
	  the IPACK causes the IPACK not to initialize properly. Didn't have time to investigate ????? */
	InitPwmOutputs();

	if (!HidacErrorExists())
	{
	    /* stop here if +/- 15VDC supply is low */
		if (Get15VoltBad())
		{
			HexLEDUpdate (0x15);
			HIDAC_FAIL_LED_ON();
			UpdateHidacError (BAD_15V);
		}
	}

#ifdef BURN_IN
	if (!HidacErrorExists())
	{
		BurnInCode();
	}
	else
	{
		while (1);
	}
    ////////////////////////////////////////////////////////////////
    // Code never gets past here if Burn-In code enabled
    // Infinite while (FOREVER) in BurnInCode() or if error detected
    ////////////////////////////////////////////////////////////////
#endif


    HIDAC_TEST_LED_OFF();

    SetStartupSuccessful (TRUE);

	// Setting the argument to FALSE indicates that the baseline CPU loading has
	// already been performed and that the CPU load check, that can be performed via
	// the serial port, will report the CPU loading as a percentage. Setting to TRUE
	// should only be done when capturing the CPU baseline loading and should be returned
	// to FALSE for normal operation
    DebugInit (FALSE);

    if (!HidacErrorExists())
    {
        HexLEDUpdate (0x00);
    }

    /* This is the background loop */
    while (1)
    {
		// Used to measure CPU loading
		DebugUpdateLoadCounter();
        
		/* Code that executes in the main while forever loop. All RealTime critical
			application code is interrupt driven */
        DebugService();

    }

}
Exemplo n.º 18
0
void debug_parse(char *cmd_line)
{
	int params;
	unsigned int temp1,temp2,temp3,temp4;
	unsigned short tempword;
	unsigned char tempbyte;

	while (*cmd_line == ' ') cmd_line++;

	switch (toupper(*cmd_line++))
	{
	case '?':
		DebugPrint("\r\n Compile Date: %s, Time: %s",__DATE__,__TIME__);
		break;
	case 'A':  // assemble
		break;
	case 'B':
		break;
	case 'C':  // compare
		break;
	case 'D':  // dump
		params = sscanf(cmd_line,"%X %X",&temp2,&temp3);
		switch (params) {
		case 0:
			case EOF:
			dump_end = dump_beg + 127;
			do_dump();
			break;
		case 1:
			dump_beg = temp2;
			dump_end = dump_beg + 127;
			do_dump();
			break;
		case 2:
			if (temp3<temp2) temp3=temp2;
			dump_beg = temp2;
			dump_end = temp3;
			do_dump();
			break;
		}
		break;
	case 'E':  // read unsigned int
		if (sscanf(cmd_line,"%X",&temp1)==1)
			debug_port = (unsigned char*)(temp1&0xFFFFFFFC);
		temp2 = *(unsigned int*)debug_port;
		DebugPrint("\r\n %08X -> %08X",(int)debug_port,temp2);
//		debug_port += sizeof(int);
		break;
	case 'F':  // fill
		params = sscanf(cmd_line,"%X %X %X",&temp2,&temp3,&temp4);
		switch (params) {
		case 3:
			dump_end = temp3;
			for (old_dump_beg=temp2;old_dump_beg<=dump_end;old_dump_beg++)
			{
//				pokeb(dump_seg,old_dump_beg,temp4);
			}
			break;
		default:
			{
				DebugSend(" ?? \r\n");
			}
			break;
		}
		break;
	case 'G':  // go
		DebugInit();
		break;
	case 'H':  // hex
		break;
	case 'I':  // read byte
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			debug_port = (unsigned char*)temp1;
			tempbyte = *(unsigned char*)debug_port;
			DebugPrint("\r\n %08X -> %02X",(int)debug_port,tempbyte);
			debug_port += sizeof(tempbyte);
		}
		break;
	case 'J':  // read word
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			debug_port = (unsigned char*)(temp1&0xFFFFFFFE);
		}
		tempword = *(unsigned short*)debug_port;
		DebugPrint("\r\n %08X -> %04X",(int)debug_port,tempword);
		break;
	case 'K':
		break;
	case 'L':  // load
		break;
	case 'M':  // write unsigned int
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)(temp1&0xFFFFFFFC);
			DebugPrint("\r\n %08X <- %08X",(int)debug_port,temp2);
			*(unsigned int*)debug_port = temp2;
			debug_port += sizeof(int);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'N':  // name
		break;
	case 'O':  // output byte
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)temp1;
			tempbyte = temp2;
			DebugPrint("\r\n %08X <- %02X",(int)debug_port,tempbyte);
			*debug_port = tempbyte;
			debug_port += sizeof(tempbyte);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'P':  // proceed
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'Q':  // quit
		DebugSend("\r\nYou can't quit now!");
		break;
	case 'R':  // register
		break;
	case 'S':  // search
		if (sscanf(cmd_line,"%X",&temp2)==1)
		{
		}
		break;
	case 'T':  // Test
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
			bTest = !bTest;
			if (bTest)
			{
				ResetTimer(BLINK_TIMER);
				StartTimer(BLINK_TIMER, 500);
				DebugSend("\r\n LED Blink Started.");
			}
			else
			{
				DebugSend("\r\n LED Blink Stopped.");
			}
		}
		break;
	case 'U':
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:	//U5
				break;
			case 6:	//U6
				break;
			case 7:	//U7
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'W':  // write word
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)(temp1&0xFFFFFFFE);
			tempword = temp2;
			DebugPrint("\r\n %08X <- %04X",(int)debug_port,tempword);
			*(unsigned short*)debug_port = tempword;
			debug_port += sizeof(tempword);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'X':
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'Y':
		temp4 = sscanf(cmd_line,"%X %X",&temp1,&temp2);
		if (temp4>=1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'Z':
		if (sscanf(cmd_line,"%i %i",&temp1,&temp2)==2)
		{
		}
		else
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	default:
		;
	}
}
Exemplo n.º 19
0
void debug_parse(char *cmd_line)
{
	int params, result;
	unsigned int temp1,temp2,temp3,temp4;
	unsigned short tempword;
	unsigned char tempbyte;

	while (*cmd_line == ' ') cmd_line++;

	switch (toupper(*cmd_line++))
	{
	case '?':
		DebugPrint("\r\n Compile Date: %s, Time: %s",__DATE__,__TIME__);
		break;
	case 'A':  // assemble
		break;
	case 'B':
		break;
	case 'C':  // compare
		break;
	case 'D':  // dump
		params = sscanf(cmd_line,"%X %X",&temp2,&temp3);
		switch (params) {
		case 0:
			case EOF:
			dump_end = dump_beg + 127;
			do_dump();
			break;
		case 1:
			dump_beg = temp2;
			dump_end = dump_beg + 127;
			do_dump();
			break;
		case 2:
			if (temp3<temp2) temp3=temp2;
			dump_beg = temp2;
			dump_end = temp3;
			do_dump();
			break;
		}
		break;
	case 'E':  // read unsigned int
		if (sscanf(cmd_line,"%X",&temp1)==1)
			debug_port = (unsigned char*)(temp1&0xFFFFFFFC);
		temp2 = *(unsigned int*)debug_port;
		DebugPrint("\r\n %08X -> %08X",(int)debug_port,temp2);
//		debug_port += sizeof(int);
		break;
	case 'F':  // fill
		params = sscanf(cmd_line,"%X %X %X",&temp2,&temp3,&temp4);
		switch (params) {
		case 3:
			dump_end = temp3;
			for (old_dump_beg=temp2;old_dump_beg<=dump_end;old_dump_beg++)
			{
//				pokeb(dump_seg,old_dump_beg,temp4);
			}
			break;
		default:
			{
				DebugSend(" ?? \r\n");
			}
			break;
		}
		break;
	case 'G':  // go
		DebugInit();
		break;
	case 'H':  // hex
		break;
	case 'I':  // read byte
		break;
	case 'J':  // read word
		break;
	case 'K':
		break;
	case 'L':  // load
		break;
	case 'M':  // write unsigned int
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)(temp1&0xFFFFFFFC);
			DebugPrint("\r\n %08X <- %08X",(int)debug_port,temp2);
			*(unsigned int*)debug_port = temp2;
			debug_port += sizeof(int);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'N':  // name
		break;
	case 'O':  // output byte
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)temp1;
			tempbyte = temp2;
			DebugPrint("\r\n %08X <- %02X",(int)debug_port,tempbyte);
			*debug_port = tempbyte;
			debug_port += sizeof(tempbyte);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'P':  // proceed
		if (sscanf(cmd_line,"%d",&temp1)==1)
		{
			gain_Ap = temp1;
		}
		DebugPrint("\r\n gain_Ap = %5.1f",gain_Ap);
		break;
	case 'Q':  // quit
		if (sscanf(cmd_line,"%d",&temp1)==1)
		{
			gain_Ai = temp1;
		}
		DebugPrint("\r\n gain_Ai = %5.1f",gain_Ai);
		break;
	case 'R':  // register
		if (sscanf(cmd_line,"%d",&temp1)==1)
		{
			gain_Ad = temp1;
		}
		DebugPrint("\r\n gain_Ad = %5.1f",gain_Ad);
		break;
	case 'S':  // search
		if (sscanf(cmd_line,"%X",&temp2)==1)
		{
		}
		break;
	case 'T':  // Test
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				#ifdef	_MPU6050_H_			
				result = MPU6050_Setup();
				if (result==STATUS_OK)
				{
					DebugPrint("\r\n MPU6050 Init Success!");
				}
				else
				{
					DebugPrint("\r\n MPU6050 Init Fail. Error = %i", result);
				}
				#endif
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
			bTest = !bTest;
			if (bTest)
			{
				DebugPrint("\r\n Test ON!");
				ResetTimer(DEBUG_TIMER);
				StartTimer(DEBUG_TIMER,50);
			}
			else
			{
				DebugPrint("\r\n Test OFF!");
			}
		}
		break;
	case 'U':
		if (sscanf(cmd_line,"%d %d",&temp1,&temp2)==2)
		{
			DebugPrint("\r\n L298_set_speed(%d,%d)", temp1, temp2);
			L298_set_speed(temp1,temp2);
		}
		else
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:	//U5
				break;
			case 6:	//U6
				break;
			case 7:	//U7
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'W':  // write word
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)(temp1&0xFFFFFFFE);
			tempword = temp2;
			DebugPrint("\r\n %08X <- %04X",(int)debug_port,tempword);
			*(unsigned short*)debug_port = tempword;
			debug_port += sizeof(tempword);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'X':
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'Y':
		temp4 = sscanf(cmd_line,"%X %X",&temp1,&temp2);
		if (temp4>=1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'Z':
		debug_main_Z(cmd_line);
		break;
	default:
		;
	}
}
Exemplo n.º 20
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      AppInit
 *
 *  DESCRIPTION
 *      This user application function is called after a power-on reset
 *      (including after a firmware panic), after a wakeup from Hibernate or
 *      Dormant sleep states, or after an HCI Reset has been requested.
 *
 *      NOTE: In the case of a power-on reset, this function is called
 *      after AppPowerOnReset().
 *
 * PARAMETERS
 *      last_sleep_state [in]   Last sleep state
 *
 * RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
void AppInit(sleep_state last_sleep_state)
{
    /* Initialise UART communications */
    DebugInit(1, NULL, NULL);

    DebugWriteString("Configuring PWM Modes\r\n");

    /* Configure the output PIO on which the slow flashing LED signal is
     * generated */
    PioSetDir(PIO_LED, PIO_DIR_OUTPUT);

    /* SLOW FLASHING WITH PWM:
     * Configure PWM 0 to have the following characteristics
     * DULL LED Light is generated by having pulses of 0ms ON and
     *      6ms OFF (~0% duty cycle)
     * BRIGHT LED Light is generated by having pulses of 6ms ON and
     *      0ms OFF (~100% duty cycle)
     * Dullest and Brightest level are held for ~1s
     *
     * The brightness level ramps for ~1s when going from dullest to
     * brightest and vice-versa */
    if (PioConfigPWM(0, pio_pwm_mode_push_pull,
                     /* Pulse timings for the dullest part of the sequence:
                      * dullest part of the sequence has the pulse off for the whole
                      * period, in effect the line stays low for the duration for which
                      * the dullest part of the sequence lasts. */
                     0,          /* ON time for the pulse is 0us */
                     255,        /* OFF time for the pulse is (255 * 30)us */
                     62,         /* Dullest part of the sequence lasts for
                            ( 62 * 16 )ms before ramping up to the brightest
                            part of the sequence */

                     /* Pulse timings for the brightest part of the sequence:
                      * brightest part of the sequence has the pulse ON for the whole
                      * period, in effect the line stays high for the duration for which
                      * the brightest part of the sequence lasts. */
                     255,        /* ON time for the pulse is (255 * 30)us */
                     0,          /* OFF time for the pulse is 0us */
                     62,         /* Brightest part of the sequence lasts for
                            ( 62 * 16 )ms before ramping down to the dullest
                            part of the sequence */

                     /* Ramping between dullest and brightest parts of the sequence
                      * This parameter determines the duration for which the ramping
                      * lasts when going from dullest to the brightest (and vice-versa).
                      *
                      * The total duration for which the ramping lasts is determined by
                      * multiplying this value with one less than the difference between
                      * the on_time or off_time of the two states, whichever is bigger;
                      * in the units of 30us
                      * */
                     132         /* Ramping lasts for ((255-1) * 132 * 30)us */
                    ))
    {
        DebugWriteString("PWM0 was set to ramp between brightest and dullest "
                         "levels\r\n");

        /* Connect PWM0 output to LED */
        PioSetMode(PIO_LED, pio_mode_pwm0);

        /* Enable the PWM0 */
        PioEnablePWM(0, TRUE);
    }
    else
    {
        DebugWriteString("PWM0 couldn't be configured\r\n");
    }

    /* Set both outputs to have strong internal pull ups */
    PioSetPullModes((1UL << PIO_MOTOR) | (1UL << PIO_LED),
                    pio_mode_strong_pull_up);

    /* Configure motor PIO to be output */
    PioSetDir(PIO_MOTOR, PIO_DIR_OUTPUT);

    /* Connect PWM1 output to motor PIO */
    PioSetMode(PIO_MOTOR, pio_mode_pwm1);

    /* Initialise timers */
    TimerInit(MAX_APP_TIMERS, app_timers);

    /* Call the function (with a dummy timer ID to start with) to configure
     * the PWM1 with initial duty cycle and start a timer. When the timer
     * expires the same function gets called again and the duty cycle for
     * PWM1 gets updated. It takes care of restarting the timer and ensuring
     * that duty cycle alternates between 0% and 100% back and forth. */
    dutyCycleTask(TIMER_INVALID);

    /* Enable the PWM1 */
    PioEnablePWM(1, TRUE);
}