コード例 #1
0
ファイル: main.c プロジェクト: gstroe/Arm
/**
 *  \brief getting-started Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main(void)
{
	uint32_t id_offset = 0;
	uint32_t fifo_entries;
	uint32_t button_state = BUTTON_PUSHED;
	uint32_t button_state2 = BUTTON_NOT_PUSHED;
	uint32_t can_mode = CAN_STANDARD;

	/* Disable watchdog */
	WDT_Disable(WDT);

	/* Output example information */
	printf("\n\r-- Controller Area Network (CAN) Example %s --\n\r",
			SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r\n\r", __DATE__, __TIME__);
	printf("-- LED0 toggles on CAN message reception\n\r");
	printf("-- LED1 toggles on CAN message transmission\n\r");
	printf("-- CAN message transmission stopped while SW0 is pushed\n\r");
	printf("-- SW1 pushes alternate between standard CAN and CAN-FD\n\r");

	SCB_EnableICache();
	SCB_EnableDCache();

	/* Configure systick for 1 ms. */
	TimeTick_Configure();

	/* Configure Board LED's */
	LED_Configure(0);
#if 2 == LED_NUM
	LED_Configure(1);
#endif

	/* Configure Timer/Counter for 250msec Tick */
	_ConfigureTc();

	/* Configure Board Push-buttons */
	// SW1 is a ERASE system function, switch it to port function
	MATRIX->CCFG_SYSIO |= (1u << 12);
	/* have to disable the pull down on PB12 for SW1 before the pull up can be
		enabled */
	PIOB->PIO_PPDDR = 1 << 12;
	PIO_Configure(pushbutton, PIO_LISTSIZE(pushbutton));
	/* Adjust pio denounce filter parameters, uses 10 Hz filter. */
	PIO_SetDebounceFilter(&pushbutton[0], 10);
#if 2 == BUTTON_NUM
	PIO_SetDebounceFilter(&pushbutton[1], 10000);
#endif

	SystemCoreClockUpdate();

	MCAN_Init(&mcan1Config);

	MCAN_InitFdBitRateSwitchEnable(&mcan1Config);
	MCAN_InitTxQueue(&mcan1Config);
	MCAN_InitLoopback(&mcan1Config);  // remove to disable loop back mode
	MCAN_Enable(&mcan1Config);

	MCAN_IEnableMessageStoredToRxDedBuffer(&mcan1Config, CAN_INTR_LINE_1);

	txMailbox0 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_0,
			MSG_ID_0, CAN_STD_ID, CAN_DLC_1);
	txMailbox1 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_1,
			MSG_ID_1, CAN_EXT_ID, CAN_DLC_8);
	MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_0, FILTER_0, MSG_ID_0,
			CAN_STD_ID);
	MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_1, FILTER_0, MSG_ID_1,
			CAN_EXT_ID);
	MCAN_ConfigRxClassicFilter(&mcan1Config, CAN_FIFO_0, FILTER_1, MSG_ID_2,
			CAN_STD_ID, MSG_ID_2_MASK);

	while (1) {
		 if (tick) {
			tick = 0;
			if (PIO_Get(&pushbutton[0]) == BUTTON_NOT_PUSHED) {
				if (button_state2 == BUTTON_NOT_PUSHED) {
					/* periodically transmit messages while SW0 is not pushed */
					// send standard ID from a dedicated buffer
					*txMailbox0 = MSG_ID_0_DATA1;  // write data into CAN mailbox
					MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_0);  // send data
					txdCntr++;
					// send extended ID from a dedicated buffer
					*txMailbox1 = MSG_ID_1_DATA1_4;  // write data into CAN mailbox
					*(txMailbox1 + 1) = MSG_ID_1_DATA5_8; // write data into CAN mailbox
					MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_1); // send the data
					txdCntr++;
					// send from Tx Queue
					MCAN_AddToTxFifoQ(&mcan1Config, MSG_ID_2 + id_offset, CAN_STD_ID,
							CAN_DLC_1, &txData[0]);
					txdCntr++;
					// increment the offset so we send different ID's within the
					// range defined by the mask
					id_offset = (id_offset + 1) & (uint32_t) ~MSG_ID_2_MASK;
					// update data being sent for next time
					txData[0]++;
					button_state2 = BUTTON_NOT_PUSHED;
				}
			} else {
				if (button_state2 == BUTTON_NOT_PUSHED)
					button_state2 = BUTTON_PUSHED;
				else
					button_state2 = BUTTON_NOT_PUSHED;
			}
		}
		/* poll for TX'd message complete */
		 if (MCAN_IsTxComplete(&mcan1Config)) {
			MCAN_ClearTxComplete(&mcan1Config);
			if (MCAN_IsBufferTxd(&mcan1Config, TX_BUFFER_0)) {
		#if 2 == LED_NUM
				LED_Toggle(1);
		#endif
			}
		}
		/* Poll for new CAN messages in RX FIFO */
		do {
			fifo_entries = MCAN_GetRxFifoBuffer(&mcan1Config, CAN_FIFO_0,
					(Mailbox64Type *) &rxMailbox2);
			if (fifo_entries > 0) rxdCntr++;
		} while (fifo_entries > 1);

		/* SW1 used to alternate between standard CAN and CAN-FD operation */
#if 2 == BUTTON_NUM
		if (PIO_Get(&pushbutton[1]) == BUTTON_NOT_PUSHED) {
#else
		if (1) {
#endif
			 button_state = BUTTON_NOT_PUSHED;
		} else {
			if (button_state == BUTTON_NOT_PUSHED ) {
				// Switch on a NOT PUSHED to PUSHED edge
				button_state = BUTTON_PUSHED;
				if (can_mode == CAN_STANDARD) {
					can_mode = CAN_FD;
					MCAN_RequestFdBitRateSwitch( &mcan1Config );
				} else {
					can_mode = CAN_STANDARD;
					MCAN_RequestIso11898_1( &mcan1Config );
				}
			}
		}
#ifdef POLLKEYBOARD
	/* poll for keyboard entry */
	if (DBG_IsRxReady()) {
		keyboard = DBG_GetChar();
		if (((char) keyboard == 'L' ) || ( (char) keyboard == 'l')) {
			if (loopback == 1) {
				MCAN_LoopbackOff(&mcan1Config);
				loopback = 0;
			} else {
				MCAN_LoopbackOn(&mcan1Config);
				loopback = 1;
			}
		}
	}
#endif
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: gstroe/Arm
/**
 *  \brief usart-hw-handshaking Application entry point..
 *
 *  Configures USART in hardware handshaking mode and
 *  Timer Counter 0 to generate an interrupt every second. Then, start the first
 *  transfer on the USART and wait in an endless loop.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main( void )
{
	char pbaud_time[8];
	uint32_t BytesRead, BytesToRead, baudrate, timeout, TxBytesLeft;
	uint8_t AppBufferRollOver = 0;
	uint8_t *pTxBuff;

	/* Disable watchdog*/
	WDT_Disable(WDT);

	printf("-- USART Hardware Handshaking Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	/* Enable I and D cache */
	SCB_EnableICache();
	SCB_EnableDCache();

	/* Configure USART pins*/
	PIO_Configure(pins, PIO_LISTSIZE(pins));

	/* Configure systick for 1 ms. */
	TimeTick_Configure();

	NVIC_SetPriority(XDMAC_IRQn , XDMA_NVIC_PRIO);


	printf("\n\rEnter required baudrate:");
	gets(pbaud_time);
	baudrate = (atoi(pbaud_time)) ? (atoi(pbaud_time)): 921600;
	printf("\n\rEnter required timeout (in microsec):");
	gets(pbaud_time);

	timeout = atoi(pbaud_time);
	if (timeout > 1000) {
		timeout /= 1000;
		timeout = ((timeout * baudrate) / 1000);
	} else {
		timeout = (timeout * baudrate) / 1000000;
	}
	timeout = (timeout) ? ((timeout > MAX_RX_TIMEOUT) ? MAX_RX_TIMEOUT : timeout) \
		: MAX_RX_TIMEOUT;
	printf("\n\r");
	/* Configure USART */
	_ConfigureUsart(baudrate, timeout);
	printf("\n\r");

	/*Enable Rx channel of USART */
	USARTD_EnableRxChannels(&Usartd, &UsartRx);

#ifdef FULL_DUPLEX
	/*Enable Tx channel of USART */
	USARTD_EnableTxChannels(&Usartd, &UsartTx);
#endif

	/* Start receiving data and start timer*/
	USARTD_RcvData(&Usartd);

	/*Initialize Ring buffer */
	pUsartBuffer = (RignBuffer_t *)malloc(sizeof(RignBuffer_t));
	_initCircularBuffer(pUsartBuffer);

	pTxBuff = &FirstAppBuff[0];

	TxBytesLeft = 0;

#ifdef USE_MD5_CHECK
	md5_init(&pms);
#endif //USE_MD5_CHECK

#ifdef FULL_DUPLEX
	printf( "\n\r-I- USART is in Full Duplex mode \n\r");
#else
	printf( "\n\r-I- USART is in Half Duplex mode \n\r");
#endif
	printf( "\n\r-I- Please send a file to serial port (USART0) \n\r");
	BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer

	while (1) {
#ifdef USE_MD5_CHECK
		if (DBG_IsRxReady()) {
			ch = DBG_GetChar();
			if (ch == 'm') {
				uint8_t i;
				md5_finish(&pms, md5);
				printf("\r\nmd5:");
				for (i = 0; i < sizeof(md5);i++)
					printf("%.2x",md5[i]);
				printf("\r\n");
				md5_init(&pms);
				TotalbytesReceived = 0;
			}
		}
#endif
		/* Check Application buffer (100 KB)overflow */
		if (((PingPongBufferFlag == 0) &&
			(pTxBuff+BytesToRead) >= &FirstAppBuff[APP_BUFFER]) ||
			(( PingPongBufferFlag == 1) && (pTxBuff+BytesToRead) >=
			&SecondAppBuff[APP_BUFFER])) {
			AppBufferRollOver = 1;
			// Roll over and start copying to the beginning of Application buffer to avoid errors
			if (PingPongBufferFlag)
				BytesToRead = (&SecondAppBuff[APP_BUFFER] - pTxBuff);
			else
				BytesToRead = (&FirstAppBuff[APP_BUFFER] - pTxBuff);
			memory_barrier();
		}
		/* Read ring buffer */
		BytesRead = RingBufferRead(pUsartBuffer, pTxBuff, BytesToRead);
		memory_sync();
		TxBytesLeft += BytesRead;       // number of bytes to send via USART Tx

#ifdef USE_MD5_CHECK
		if (BytesRead > 0)
			md5_append(&pms,pTxBuff,BytesRead);
#endif

		/* check if one of the application buffer is full and ready to send */
		if (AppBufferRollOver && (TxBytesLeft == APP_BUFFER)) {
			AppBufferRollOver = 0;
			TxBytesLeft = 0;
			BytesRead = 0;
			BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
			while (!UsartTx.dmaProgress);
			if (PingPongBufferFlag) {
				PingPongBufferFlag = 0;
				pTxBuff = &FirstAppBuff[0];
			} else {
				PingPongBufferFlag = 1;
				pTxBuff = &SecondAppBuff[0];
			}
			memory_sync();
#ifdef FULL_DUPLEX
			USARTD_SendData(&Usartd);
#endif
		}
		/* otherwise keep storing in same application buffer from Rx DMA's ring
			buffer */
		else {
			BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
			pTxBuff += BytesRead;

#ifdef FULL_DUPLEX
			/* Check for Tx timeout, if there is timeout then send the bytes left
				(less than 100 KB) in application buffer */
			if ((GetDelayInTicks(TimeOutTimer, GetTicks()) == USART_TX_TIMEOUT)
				&& TxBytesLeft) {
				// wait for any eventual USART Tx in progress
				while (!UsartTx.dmaProgress);
				FlushTxBuffer(TxBytesLeft);
				TimeOutTimer = GetTicks();
				PingPongBufferFlag = 0;
				TxBytesLeft = 0;
				BytesRead = 0;
				BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
				pTxBuff = &FirstAppBuff[0];
				_UpdateTxConfig((uint32_t)&FirstAppBuff[0], APP_BUFFER);
				TRACE_INFO_WP(" TX Tiemout \n\r");
			}
#endif
		}
	}
}
コード例 #3
0
ファイル: main.c プロジェクト: gstroe/Arm
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	uint8_t isUsbConnected = 0;
	/* Disable watchdog */
	WDT_Disable(WDT);


	SCB_EnableICache();
	SCB_EnableDCache();

	/* Output example information */
	printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	/* Initialize PIO interrupts */
	PIO_InitializeInterrupts(0);

	/* Interrupt priority */
	NVIC_SetPriority(USBHS_IRQn, 2);

	/* Configure DMA driver */
	_ConfigureDma();

	/* Configure USART */
	_ConfigureUsart();
	_UsartDmaRxSetup();

	/* Initialize OTG clocks */
	_ConfigureUotghs();

	/* CDC serial driver initialization */
	CDCDSerialDriver_Initialize(&cdcdSerialDriverDescriptors);

	/* Help information */
	_DebugHelp();

	// Start USB stack to authorize VBus monitoring
	USBD_Connect();

	/* Driver loop */
	while (1) {
		/* Device is not configured */
		if (USBD_GetState() < USBD_STATE_CONFIGURED) {
			if (isUsbConnected) {
				isUsbConnected = 0;
				isCdcSerialON  = 0;
			}
		} else if (isUsbConnected == 0)
			isUsbConnected = 1;

		/* Serial port ON/OFF */
		if (CDCDSerialDriver_GetControlLineState() & CDCControlLineState_DTR) {
			if (!isCdcSerialON) {
				isCdcSerialON = 1;

				/* Start receiving data on the USART */
				_UsartDmaRx();
				USART_EnableIt(BASE_USART, US_CSR_FRAME | US_CSR_OVRE | US_IER_TIMEOUT);
				USART_EnableRecvTimeOut(BASE_USART, USART_TIMEOUT);
				/* Start receiving data on the USB */
				CDCDSerialDriver_Read(usbBuffer,
									  DATAPACKETSIZE,
									  (TransferCallback) _UsbDataReceived,
									  0);
			}
		} else if (isCdcSerialON)
			isCdcSerialON = 0;

		if (DBG_IsRxReady()) {
			uint8_t key = DBG_GetChar();

			/* ESC: CDC Echo ON/OFF */
			if (key == 27) {
				printf("** CDC Echo %s\n\r",
					   isCdcEchoON ? "OFF" : "ON");
				isCdcEchoON = !isCdcEchoON;
			}
			/* 't': Test CDC writing  */
			else if (key == 't')
				_SendText();
			else {
				printf("Alive\n\r");

				while (CDCDSerialDriver_Write((char *)"Alive\n\r", 8, 0, 0)
					   != USBD_STATUS_SUCCESS);

				_DebugHelp();
			}
		}
	}
}
コード例 #4
0
ファイル: main.c プロジェクト: gstroe/Arm
/**
 * Monitor keyboard buttons & Update key status in HID driver
 */
static void HIDDKeyboardProcessKeys(void)
{
	uint32_t i;
	uint8_t pressedKeys[NUM_KEYS];
	uint8_t pressedKeysSize = 0;
	uint8_t releasedKeys[NUM_KEYS];
	uint8_t releasedKeysSize = 0;

	/* Monitor buttons */
#ifdef NO_PUSHBUTTON

	if (DBG_IsRxReady()) {
		uint8_t key = DBG_GetChar();

		switch (key) {
		case '1': case '2':
			i = key - '1';

			if (keyStatus[i]) {
				/* Key press simulation */
				TRACE_INFO("Key %u pressed\n\r", (unsigned int)i);
				keyStatus[i] = 0;
				pressedKeys[pressedKeysSize] = keyCodes[i];
				pressedKeysSize ++;
				HIDDKeyboard_RemoteWakeUp();
			} else {
				/* Key release simulation */
				TRACE_INFO("Key %u released\n\r", (unsigned int)i);
				keyStatus[i] = 1;
				releasedKeys[releasedKeysSize] = keyCodes[i];
				releasedKeysSize++;
			}

			break;

		default: DBG_PutChar(key);
		}
	}

#else

	for (i = 0; i < PIO_LISTSIZE(pinsPushButtons); i++) {
		/* Check if button state has changed */
		uint8_t isButtonPressed = PIO_Get(&(pinsPushButtons[i]));

		if (isButtonPressed != keyStatus[i]) {
			/* Update button state */
			if (!isButtonPressed)   {
				/* Key has been pressed */
				TRACE_INFO("Key %u has been pressed\n\r", i);
				keyStatus[i] = 0;
				pressedKeys[pressedKeysSize] = keyCodes[i];
				pressedKeysSize++;
				HIDDKeyboard_RemoteWakeUp();
			} else {
				/* Key has been released */
				TRACE_INFO("Key %u has been released\n\r", i);
				keyStatus[i] = 1;
				releasedKeys[releasedKeysSize] = keyCodes[i];
				releasedKeysSize++;
			}
		}
	}

#endif

	/* Update key status in the HID driver if necessary */
	if ((pressedKeysSize != 0) || (releasedKeysSize != 0)) {
		uint8_t status;

		do {
			status = HIDDKeyboard_ChangeKeys(pressedKeys,
											 pressedKeysSize,
											 releasedKeys,
											 releasedKeysSize);
		} while (status != USBD_STATUS_SUCCESS);
	}
}
コード例 #5
0
ファイル: main.c プロジェクト: BlueSkyGjj/SAMV71_softpack
/**
 * Disk test
 * \param iMci Controller number.
 * \param clr  Do block clear.
 * \param wr   Do block write.
 * \param rd   Do block read.
 */
static void DiskTest(uint8_t iMci,
        uint8_t clr,
        uint8_t wr,
        uint8_t rd)
{
    sSdCard *pSd = &sdDrv[iMci];
    uint8_t error = 0;
    uint32_t i, errcnt = 0;
    uint32_t multiBlock, block, splitMulti;

    DumpSeperator();
    printf("-!- Test code: 1.clr, 2.wr, 3.rd\n\r");

    /* Perform tests on each block */
    multiBlock = 0;
    for (block = TEST_BLOCK_START;
            block < TEST_BLOCK_END;
            block += multiBlock) {

        /* Perform different single or multiple bloc operations */
        if (multiBlock >= 16)   multiBlock <<= 1;
        else                    multiBlock ++;
        if (multiBlock > NB_MULTI_BLOCKS)
            multiBlock = 1;

        /* Multi-block adjustment */
        if (block + multiBlock > TEST_BLOCK_END) {
            multiBlock = TEST_BLOCK_END - block;
        }

        /* ** Perform single block or multi block transfer */
        printf("\r-I- Testing block [%6u - %6u] ...", (unsigned int)block, (unsigned int)(block + multiBlock -1));

        if (clr) {
            /* - Clear the block */
            memset(pBuffer, 0, SDMMC_BLOCK_SIZE * multiBlock);
            for (i=0; i < SDMMC_BLOCK_SIZE * multiBlock; i++) {
                if (pBuffer[i] != 0) {
                    /* Fatal error */
                    printf("\n\r-F- Data @ %u for write : 0x00 <> 0x%02x\n\r", (unsigned int)i, pBuffer[i]);
                    return;
                }
            }
            error = MMCT_WriteFun(pSd, block, multiBlock, pBuffer);
            if (error) {
                printf("\n\r-E- 1. Write block (%d) #%u\n\r", error, (unsigned int)block);
                if(MaxErrorBreak(0)) return;
                /* Skip following test */
                continue;
            }
            /* - Read back the data to check the write operation */
            memset(pBuffer, 0xFF, SDMMC_BLOCK_SIZE * multiBlock);
            error = MMCT_ReadFun(pSd, block, multiBlock, pBuffer);
            if (error) {
                printf("\n\r-E- 1. Read block (%d) #%u\n\r", error, (unsigned int)block);
                if(MaxErrorBreak(0)) return;
                /* Skip following test */
                continue;
            }
            for (i=0; i < SDMMC_BLOCK_SIZE * multiBlock; i++) {
                if (pBuffer[i] != 0) {
                    printf("\n\r-E- 1. B%u.D[%u] : 0 <> 0x%02X\n\r", (unsigned int)block, (unsigned int)i, (int)pBuffer[i]);
                    if(MaxErrorBreak(0)) return;
                    /* Only find first verify error. */
                    break;
                }
            }
        }

        if (wr) {
            /* - Write a checker board pattern on the block */
            for (i=0; i < SDMMC_BLOCK_SIZE * multiBlock; i++) {
                if ((i & 1) == 0)  pBuffer[i] = (i & 0x55);
                else               pBuffer[i] = (i & 0xAA);
            }
            for (i = 0; i < multiBlock; ) {
                splitMulti = ((multiBlock - i) > NB_SPLIT_MULTI) ?
                    NB_SPLIT_MULTI : (multiBlock - i);
                error = MMCT_WriteFun(pSd,
                        block + i,
                        splitMulti,
                        &pBuffer[i * SDMMC_BLOCK_SIZE]);
                if (error) break;
                i += splitMulti;
            }
            if (error)
            {
                printf("\n\r-E- 2. Write block #%u(%u+%u): %d\n\r",  (unsigned int)(block+i), (unsigned int)block, (unsigned int)i, error);
                if(MaxErrorBreak(0)) return;
                /* Skip Following Test */
                continue;
            }
        }

        if (rd) {
            /* - Read back the data to check the write operation */
            memset(pBuffer, 0, SDMMC_BLOCK_SIZE * multiBlock);
            for (i = 0; i < multiBlock; ) {
                splitMulti = ((multiBlock - i) > NB_SPLIT_MULTI) ?
                    NB_SPLIT_MULTI : (multiBlock - i);
                error = MMCT_ReadFun(pSd,
                        block + i,
                        splitMulti,
                        &pBuffer[i * SDMMC_BLOCK_SIZE]);
                if (error) break;
                i += splitMulti;
            }
            if (error)
            {
                printf("\n\r-E- 2. Read block #%u(%u+%u): %d\n\r", (unsigned int)(block + i), (unsigned int)block, (unsigned int)i, error);
                if(MaxErrorBreak(0)) return;
                /* Skip Following Test */
                continue;
            }
            errcnt = 0;
            for (i=0; i < SDMMC_BLOCK_SIZE * multiBlock; i++) {

                if (!(((i & 1) == 0) && (pBuffer[i] == (i & 0x55))) &&
                        !(((i & 1) != 0) && (pBuffer[i] == (i & 0xAA))) ) {
                    uint32_t j, js;
                    printf("\n\r-E- 2.%d. Data @ %u (0x%x)\n\r", (int)errcnt, (unsigned int)i, (unsigned int)i);
                    printf("  -Src:");
                    js = (i > 8) ? (i - 8) : 0;
                    for (j = js; j < i + 8; j ++)
                        printf(" %02x", (unsigned int)(((j & 1)!= 0) ? (j & 0xAA):(j & 0x55)));
                    printf("\n\r  -Dat:");
                    for (j = js; j < i + 8; j ++)
                        printf("%c%02x", (i == j) ? '!' : ' ', pBuffer[j]);
                    printf("\n\r");
                    if(MaxErrorBreak(0)) return;
                    // Only find first 3 verify error.
                    if (errcnt ++ >= 3)
                        break;
                }
            }
        }

        if (DBG_IsRxReady()) {
            switch(DBG_GetChar()) {
                /* Skip 100M */
                case 'k':
                    block += TEST_BLOCK_SKIP;
                    if (block > TEST_BLOCK_END) {
                        block -= 5 + multiBlock;
                    }
                    printf("\n\r");
                    break;
                    /* Cancel */
                case 'c':
                    return;
            }
        }
    }

    printf("All block tested!\n\r");
}
コード例 #6
0
ファイル: main.c プロジェクト: BlueSkyGjj/SAMV71_softpack
/**
 *  \brief hsmci_multimedia_card Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
    uint8_t connected = 0;

    /* Disable watchdog */
    WDT_Disable( WDT ) ;
    
    SCB_EnableICache();        
    SCB_EnableDCache();
    TimeTick_Configure();

    /* Output example information*/
    printf("-- MultiMedia Card Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
    bMciID = 0;
    /* Initialize PIO pins */
    _ConfigurePIOs();

    /* Initialize drivers */
    _ConfigureDrivers();


    /* Card insert detection loop */
    for(;;) {

        if (CardIsConnected(bMciID)) {
            if (connected == 0) {
                connected = 1;
                /* Delay before card initialize */
                Wait(300);
                /* Do card test */
                CardInit(bMciID);
                DumpMenu();
            }
        }
        else if (connected) {
            connected = 0;
            printf("** Card Disconnected\n\r");
        }


        if (DBG_IsRxReady()) 
        {
            uint8_t key = DBG_GetChar();
            switch(key) 
            {
                /* Change performance test block size */
                case 'c':
                case 'C': 
                    {   
                        if (performanceMultiBlock >= NB_MULTI_BLOCKS)
                            performanceMultiBlock = 1;
                        else
                            performanceMultiBlock <<= 1;
                        printf("-!- Performance Multi set to %d\n\r", (int)performanceMultiBlock);
                    }
                    break;
                /* Show help information */
                default:
                    if (!connected) 
                    {
                        DumpMenu();
                    }
                    else 
                    {
                        switch(key){
                            /* Dump block contents */
                            case 'd':
                            case 'D':
                                BlockDump(bMciID);  
                                break;
                            /* Initialize the card again */
                            case 'I':  
                            case 'i':    
                                CardInit(bMciID);   
                                break;
                            /* Run test on whole disk */
                            case 't':
                            case 'T':
                                if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDIO)
                                    SdioTest(bMciID);
                                if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDMMC)
                                    DiskTest(bMciID, 1, 1, 1);
                                printf("\n\r");  
                                break;
                            /* Run performance test */
                            case 'P':
                            case 'p':
                                if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDIO)
                                    SdioPerformanceTest(bMciID);
                                if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDMMC)
                                    DiskPerformanceTest(bMciID, 1, 1, 0);
                                printf("\n\r");
                                break;
                            /* Read/Verify ONLY test */
                            case 'r': 
                            case 'R':
                                DiskTest(bMciID, 0, 0, 1);
                                printf("\n\r");
                                break;
                            /* Read/Verify ONLY performance test */
                            case 'V':
                            case 'v':
                                DiskPerformanceTest(bMciID, 0, 1, 1);
                                printf("\n\r");
                                break;
                            /* Show help information */
                            default:   
                                DumpMenu();
                        }
                    }
                    break;
            }
        }
    }
}