void ProtocolTest1() { #if defined(IS_ROUTER) #if PROFILE_TEST_SERVICE == true double executionTime; Uint32 startTime; #endif struct Packet newPacket; Uint16 x[100], i, j; for(i = 0; i < 100; i++) x[i] = i; TSK_sleep(3000); if(gpioDataRegisters.GPBDAT.bit.SWITCH1) { for(i = 0; i < 100; i++) { for(j = 0; j < 50; j++) { InitializePacket(&newPacket, PACKET_ID_UNDEFINED); // Create the data transfer packet newPacket.a.communicationType = COMM_TYPE_UNICAST; newPacket.transmissionInfo.destination = ROOT_ADDRESS; newPacket.b.command = COMMAND_DATA_TRANSFER; newPacket.b.packetSequenceStep = SEQUENCE_DATA_TRANSFER_REQUEST_TRANSFER; // Set the data newPacket.dataBuffer = x; newPacket.dataBufferInfo.dataBufferLength = 100; #if PROFILE_TEST_SERVICE == true startTime = timer0Registers.TIM.all; #endif SendDataPacket(&newPacket); while(globals.statistics.packet.numDataTransfersSucceeded + globals.statistics.packet.numDataTransfersExpired + globals.statistics.packet.numDataTransfersFailed < globals.statistics.packet.numDataTransfersSetup); #if PROFILE_TEST_SERVICE == true executionTime = TimeDifference(startTime, timer0Registers.TIM.all); globals.statistics.profiling.avgTestServiceTime = (globals.statistics.profiling.avgTestServiceTime * globals.statistics.profiling.numTestServiceSamples) + executionTime; globals.statistics.profiling.numTestServiceSamples++; globals.statistics.profiling.avgTestServiceTime /= globals.statistics.profiling.numTestServiceSamples; if(executionTime < globals.statistics.profiling.minTestServiceTime) globals.statistics.profiling.minTestServiceTime = executionTime; else if(executionTime > globals.statistics.profiling.maxTestServiceTime) globals.statistics.profiling.maxTestServiceTime = executionTime; #endif } SetSevenSegmentDisplay(i); } } #endif }
void SPITest() { #if defined(IS_ROUTER) Uint16 flit[NUM_CHARACTERS_IN_FLIT] = { 0xCA5F, 0xCA5F, 0xCA5F, 0xCA5F, 0xCA5F, 0xCA5F, 0xCA5F, 0xCA5F, 0xCA5F }; Uint32 numTransmitsInGroup, numGroups = 0, numTransmits = 0; TSK_sleep(2000); while(numTransmits < 500000) { numTransmitsInGroup = 0; while(numTransmitsInGroup < 5000) { if(gpioDataRegisters.GPBDAT.bit.SWITCH1) { while(globals.processing.outboundFlitQueFull[PORTA]); EnqueOutboundFlit(flit,PORTA); } if(gpioDataRegisters.GPBDAT.bit.SWITCH2) { while(globals.processing.outboundFlitQueFull[PORTB]); EnqueOutboundFlit(flit,PORTB); } if(gpioDataRegisters.GPADAT.bit.SWITCH3) { while(globals.processing.outboundFlitQueFull[PORTC]); EnqueOutboundFlit(flit,PORTC); } if(gpioDataRegisters.GPADAT.bit.SWITCH4) { while(globals.processing.outboundFlitQueFull[PORTD]); EnqueOutboundFlit(flit,PORTD); } numTransmits++; numTransmitsInGroup++; } numGroups++; SetSevenSegmentDisplay(numGroups); } SEM_pend(&TestServiceSem,SYS_FOREVER); #endif }
HRESULT CMyDevice::IndicateDeviceReady( VOID ) /*++ Routine Description: This method lights the period on the device's seven-segment display to indicate that the driver's PrepareHardware method has completed. Arguments: None Return Value: Status --*/ { SEVEN_SEGMENT display = {0}; BAR_GRAPH_STATE barGraph = {0}; HRESULT hr = S_OK; if (SUCCEEDED(hr)) { display.Segments |= 0xf7; hr = SetSevenSegmentDisplay(&display); } if (SUCCEEDED(hr)) { barGraph.BarsAsUChar = BARGRAPH_LED_ALL_OFF; hr = SetBarGraphDisplay(&barGraph); } return hr; }
HRESULT CMyDevice::IndicateDeviceReady( VOID ) /*++ Routine Description: This method lights the period on the device's seven-segment display to indicate that the driver's PrepareHardware method has completed. Arguments: None Return Value: Status --*/ { SEVEN_SEGMENT display = {0}; HRESULT hr; // // First read the contents of the seven segment display. // hr = GetSevenSegmentDisplay(&display); if (SUCCEEDED(hr)) { display.Segments |= 0x08; hr = SetSevenSegmentDisplay(&display); } return hr; }
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); }