Esempio n. 1
0
int main(void) {

    init();

    Serial.begin(9600);

    SetupPort();
    SetupTimer();

    /* repeat forever */
    while (1) {

        for (int thisNote = 0; thisNote < size; thisNote++)
            PlayNote(melody[thisNote],duration[thisNote],FULL_NOTE);

        delay(2000);
    }
    return 0;
}
Esempio n. 2
0
//_______________________________________________________________________
Boolean OpenLine (MtpDrvPtr data)
{
	SCCPtr scc = &data->scc;

	if (__OpenLine()) {
        if( data->powerMgr) PwMngON;
		
		SetData	(scc);	
		MidiParseInit (&scc->rcv, data->rTbl, data->s2t);
		MidiStreamInit (&scc->xmt, data->lTbl);
		scc->seq.last = (MidiEvPtr)&scc->seq.first;
		scc->refNum = data->refNum;

		LockedCall(SetupPort());
		scc->checkTask = MidiTask (CheckFifo, MidiGetTime()+100, data->refNum, (long)scc, 0, 0);
		scc->state = true;				
		return true;
	}
	return false;
}
void InitializeSystem(void* parameter, Uint16 followUpItemIndex)
{

	Uns interruptStatus;
	Uint16 i, j;
	double executionTime = 0;
	double genAvgTime = 0;
	double genMinTime = DBL_MAX;
	double genMaxTime = DBL_MIN;
	double avgTime[9] = {0,0,0,0,0,0,0,0,0};
	double minTime[9] = {DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX};
	double maxTime[9] = {DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN};
	Uint32 startTime = 0;
	Uint32 numSamples;
	struct Packet newPacket;

	// Allow the system to write to the system registers
	EALLOW;

	// Set up the heartbeat
	gpioCtrlRegisters.GPBDIR.bit.HEARTBEAT = 1;
	gpioDataRegisters.GPBDAT.bit.HEARTBEAT = 1;

	// Set up the seven segment display
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_A = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_A = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_B = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_B = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_C = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_C = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_D = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_D = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_E = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_E = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_F = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_F = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_G = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_G = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_DIGIT = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_DIGIT = 1;
	
	// Set up timer 0 for use with SPI related timings
	sysCtrlRegisters.HISPCP.all = 0;				// Set the HSPCLK to run at SYSCLK
	sysCtrlRegisters.LOSPCP.bit.LSPCLK = 0; 		// Set the LSPCLK to run at SYSCLK
	timer0Registers.TCR.bit.TSS = 1;				// Stop the timer
	timer0Registers.TPR.bit.TDDR = 0;				// Do not prescale the timer
	timer0Registers.PRD.all = 0xFFFFFFFF;			// Set the period register to it's largest possible value
	timer0Registers.TCR.bit.TIE = false;			// Disable timer interrupts
	timer0Registers.TCR.bit.FREE = 0;				// Set the timer to stop when a breakpoint occrs
	timer0Registers.TCR.bit.SOFT = 0;
	timer0Registers.TCR.bit.TRB = 1;				// Load the period register
	timer0Registers.TCR.bit.TSS = 0;				// Start the timer
	
	// Set up the global SPI-related settings
	IER |= 0x20;									// Enable CPU INT6
	
	// Disallow the system to write to the system registers
	EDIS;

	interruptStatus = HWI_disable();
	numSamples = 0;
	for(j = 0; j < 1000; j++)
	{
		
		InitializeGlobalVariables();

		globals.root.availableAddresses[0].address = 1;
		globals.root.availableAddresses[0].addressTaken = true;
		globals.root.availableAddresses[1].address = 2;
		globals.root.availableAddresses[1].addressTaken = true;
		globals.root.availableAddresses[2].address = 3;
		globals.root.availableAddresses[2].addressTaken = true;
		globals.root.availableAddresses[3].address = 4;
		globals.root.availableAddresses[3].addressTaken = true;
		globals.root.availableAddresses[4].address = 5;
		globals.root.availableAddresses[4].addressTaken = true;
		globals.root.availableAddresses[5].address = 6;
		globals.root.availableAddresses[5].addressTaken = true;
		globals.root.availableAddresses[6].address = 7;
		globals.root.availableAddresses[6].addressTaken = true;
		globals.root.availableAddresses[7].address = 8;
		globals.root.availableAddresses[7].addressTaken = true;	

		globals.protocol.globalNeighborInfo[1][PORTA].nodeAddress = 2;
		globals.protocol.globalNeighborInfo[1][PORTB].nodeAddress = 3;

		globals.protocol.globalNeighborInfo[2][PORTA].nodeAddress = 1;
		globals.protocol.globalNeighborInfo[2][PORTB].nodeAddress = 4;

		globals.protocol.globalNeighborInfo[3][PORTA].nodeAddress = 1;
		globals.protocol.globalNeighborInfo[3][PORTB].nodeAddress = 4;
		globals.protocol.globalNeighborInfo[3][PORTC].nodeAddress = 5;

		globals.protocol.globalNeighborInfo[4][PORTA].nodeAddress = 2;
		globals.protocol.globalNeighborInfo[4][PORTB].nodeAddress = 3;
		globals.protocol.globalNeighborInfo[4][PORTC].nodeAddress = 6;

		globals.protocol.globalNeighborInfo[5][PORTA].nodeAddress = 3;
		globals.protocol.globalNeighborInfo[5][PORTB].nodeAddress = 6;
		globals.protocol.globalNeighborInfo[5][PORTC].nodeAddress = 7;

		globals.protocol.globalNeighborInfo[6][PORTA].nodeAddress = 4;
		globals.protocol.globalNeighborInfo[6][PORTB].nodeAddress = 5;
		globals.protocol.globalNeighborInfo[6][PORTC].nodeAddress = 8;

		globals.protocol.globalNeighborInfo[7][PORTA].nodeAddress = 5;
		globals.protocol.globalNeighborInfo[7][PORTB].nodeAddress = 8;

		globals.protocol.globalNeighborInfo[8][PORTA].nodeAddress = 6;
		globals.protocol.globalNeighborInfo[8][PORTB].nodeAddress = 7;

		startTime = timer0Registers.TIM.all;
		GenerateRoutingTree();
		executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
		genAvgTime = (genAvgTime * numSamples) + executionTime;
		numSamples++;
		genAvgTime /= numSamples;
		if(executionTime < genMinTime)
			genMinTime = executionTime;
		else if(executionTime > genMaxTime)
			genMaxTime = executionTime;
	}

	for(i = 2; i <= 8; i++)
	{
		numSamples = 0;
		for(j = 0; j < 1000; j++)
		{
			startTime = timer0Registers.TIM.all;
			GenerateRoutingPath(1, i, &newPacket);
			executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
			avgTime[i] = (avgTime[i] * numSamples) + executionTime;
			numSamples++;
			avgTime[i] /= numSamples;
			if(executionTime < minTime[i])
				minTime[i] = executionTime;
			else if(executionTime > maxTime[i])
				maxTime[i] = executionTime;
		}
	}
	HWI_restore(interruptStatus);
	asm(" NOP");

	// Set the seed for the random number generator
	SetRandomSeed(0x175E);

	// Set up each individual port
	SetupPort(PORTA);
	SetupPort(PORTB);
	SetupPort(PORTC);
	SetupPort(PORTD);

	// Create the direct data cleanup follow-up item
	AddFollowUpItem(&CleanupDirectData,NULL,DIRECT_DATA_CLEANUP_RATE,true);

	// Create the neighbor check follow-up item
#if defined(IS_ROOT)

#if TEST != TEST_SPI
	globals.followUpMonitor.neighborFollowUpIndex = AddFollowUpItem(&NeighborFollowUp,NULL,NEIGHBOR_FOLLOW_UP_RATE,true);
#endif
	SetSevenSegmentDisplay(SEVENSEG_BLANK);
	globals.processing.sevenSegmentLowerDigit = globals.protocol.address;

#elif defined (IS_ROUTER)

#if TEST != TEST_SPI
	globals.followUpMonitor.neighborFollowUpIndex = AddFollowUpItem(&NeighborFollowUp,NULL,NEIGHBOR_FOLLOW_UP_RATE_WITHOUT_ADDRESS,true);
#endif
	SetSevenSegmentDisplay(SEVENSEG_BLANK);

	// Register the test service
	RegisterServiceProvider(TEST_SERVICE_TAG,TEST_SERVICE_TASK_PRIORITY,&TestServiceTask,&TestServiceSem);

#endif

	

	// Let the other threads know that initialization is finished
	SEM_post(&ProcessInboundFlitsSem);
	SEM_post(&TestServiceSem);
}
Esempio n. 4
0
MRESULT EXPENTRY fnwpClient(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
{
    RECTL   rcl;
    USHORT   Command;
    ULONG *pulPtr;

    switch(msg)
    {
    case WM_CREATE:
        stCell.cy = 12;
        stCell.cx = 8;
        hdcPs = WinOpenWindowDC(hwnd);

        /****************************************************************/
        /* Set the size and position of the frame window by making the  */
        /* client area width and height integral numbers of AVIO cell   */
        /* units.  Calculate the frame window values necessary to       */
        /* achieve this.                                                */
        /****************************************************************/

        rcl.yBottom = 0L;
        rcl.xLeft   = 0L;
        rcl.yTop    = 20 * stCell.cy;
        rcl.xRight  = 40 * stCell.cx;

        WinCalcFrameRect(WinQueryWindow(hwnd,QW_PARENT),&rcl,FALSE);

        WinSetWindowPos(WinQueryWindow(hwnd,QW_PARENT),
                        0,
                        7 * stCell.cx,
                        2 * stCell.cy,
                        (SHORT)(rcl.xRight - rcl.xLeft),
                        (SHORT)(rcl.yTop - rcl.yBottom),
                        SWP_MOVE | SWP_SIZE);

        WinPostMsg(hwnd,UM_INIT,0L,0L);
        break;
    case WM_ACTIVATE:
        if(LOUSHORT(LONGFROMMP(mp1)))
            WinSetFocus(HWND_DESKTOP,hwnd);
        break;
    case UM_INIT:
        if (szPortName[0] != 0)
            WinSetWindowText(hwndFrame,szPortName);
        else
            MenuItemEnable(hwndFrame,IDM_PROCESS,FALSE);
        WinShowWindow(hwndFrame,TRUE);
        WinQueryWindowRect(hwndClient,&rcl);
        ulWindowWidth = rcl.xRight;
        ulWindowHeight = rcl.yTop;
        ClearScreen();
        break;
    case WM_PAINT:
        Paint();
        break;
    case WM_SIZE:
        WndSize(hwnd,mp2);
        ClearScreen();
        return WinDefWindowProc(hwnd,msg,mp1,mp2);
    case WM_COMMAND:
        switch (SHORT1FROMMP(mp1))
        {
        case IDM_SELECT:
            if (WinDlgBox(HWND_DESKTOP,
                          hwnd,
                          (PFNWP)fnwpSelectPortDlg,
                          (USHORT)NULL,
                          PS_DLG,
                          NULL))
                WinSetWindowText(hwndFrame,szPortDesc);
            break;
        case IDM_RECOVER_USER_INI:
            RecoverProfile(HINI_USERPROFILE);
            break;
        case IDM_RECOVER_SYS_INI:
            RecoverProfile(HINI_SYSTEMPROFILE);
            break;
        case IDM_EXIT:
            WinPostMsg(hwnd,WM_QUIT,0L,0L);
            break;
        case IDM_SETUP:
            SetupPort();
            break;
        case IDM_REMOVE:
            RemovePort();
            break;
        case IDM_INSTALL:
            InstallPort();
            break;
        case IDM_INIT:
            InitializePort();
            break;
        case IDM_TERM:
            TerminatePort();
//          TerminatePort(szPortName);
            break;
        case IDM_QUERY:
            ulItemCount = QueryPort(achBuffer,4096);
            break;
        default:
            return WinDefWindowProc(hwnd,msg,mp1,mp2);
        }
        break;
    case WM_CLOSE:
        WinPostMsg(hwnd,WM_QUIT,0L,0L);  /* Cause termination     */
        break;
    default:
        return WinDefWindowProc(hwnd,msg,mp1,mp2);
    }
    return(FALSE);
}
Esempio n. 5
0
/*------------------------------------------------------------------------------------------------------------------
-- FUNCTION: Window_OnCommand
--
-- DATE: November 12, 2013
--
-- REVISIONS:
-- November 13, 2013 - Mat Siwoski: Completed implementation of the SendFile
-- November 13, 2013 - Mat Siwoski: Implementation of the Config option.
-- November 18, 2013 - Robin Hsieh: Added the enabling and disabling menu items.
-- November 25, 2013 - Vincent Lau: Added creation of the Transmit thread after successful file read operation
-- November 26, 2013 - Mat Siwoski: Added case for saving displayed text.
-- November 27, 2013 - Robin Hsieh: Tested ErrorCheck in the file being read in.
--
-- DESIGNER: Mat Siwoski
--
-- PROGRAMMER: Mat Siwoski
--
-- INTERFACE: void Window_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
--				HWND hwnd: Handle to the window
--				int id: The id of the selection.
--				HWND hwndCtl: Handle to the control.
--				UINT codeNotify: Int for the Notification
--
-- RETURNS: -
--
-- NOTES:
-- This function deals with the selection in the menu on the main window.
------------------------------------------------------------------------------------------------------------------*/
void Window_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) {
    static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ;

    switch(id) {
    case IDM_CONNECT:
        EnableMenuItem(GetMenu(hwnd), IDM_CONNECT, MF_DISABLED);
        EnableMenuItem(GetMenu(hwnd), IDM_DISCONNECT, MF_ENABLED);
        DrawMenuBar(hwnd);
        break;
    case IDM_SENDFILE:
        DWORD dwTransmitThreadID;
        if (FileOpenDlg(hwnd, szFileName, szTitleName)) {
            if (!FileRead(hwnd, szFileName)) { // error file could not be read
                OkMessage (hwnd, TEXT ("Could not read file %s!"),
                           szTitleName) ;
                szFileName[0]  = '\0' ;
                szTitleName[0] = '\0' ;
            }
            else // success file read
            {
                // Clean up thread
                TerminateThread(hTransmitThread, 0);
                CloseHandle(hTransmitThread);
                ReleaseSemaphore(hFileWaitSemaphore, 1, NULL);
                // create transmit thread for this file
                hTransmitThread = CreateThread(NULL, 0, TransmitThread, pszFileText, 0, &dwTransmitThreadID);
            }
        }
        break;
    case IDM_SAVEFILE:
        if (FileSaveDlg(hwnd, szFileName, szTitleName)) {
            if (!FileSave(hwnd, szFileName)) {
                OkMessage(hwnd, TEXT ("Could not write file %s"), szTitleName) ;
                break;
            }
        }
        break;
    case IDM_DISCONNECT:
        EnableMenuItem(GetMenu(hwnd), IDM_CONNECT, MF_ENABLED);
        EnableMenuItem(GetMenu(hwnd), IDM_DISCONNECT, MF_DISABLED);
        DrawMenuBar(hwnd);
        break;
    case IDM_CONFIG:
        DWORD dwReceiveThreadID;
        TerminateThread(hReceiveThread, 0);
        CloseHandle(hReceiveThread);
        if(SetupPort(lpszCommName)) {
            if (ConfPort(&MainWindow, lpszCommName)) {
                // Set Read flag true
                bWantToRead		= TRUE;
                hReceiveThread	= CreateThread(NULL, 0, ReceiveThread, &hEdit, 0, &dwReceiveThreadID);
                break;
            }
        }
        break;
    case IDM_ABOUT:
        DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ;
        break;
    case IDM_EXIT:
        Window_OnDestroy(hwnd);
        break;
    }
}