コード例 #1
0
ファイル: main.c プロジェクト: godzivan/nuc123-fdsemu
int main()
{
	CLEAR_WRITE();
	SET_STOPMOTOR();
	CLEAR_SCANMEDIA();
	CLEAR_MEDIASET();
	CLEAR_READY();
	
	//setup led and button gpio
    GPIO_SetMode(LED_G_PORT, LED_G_PIN, GPIO_PMD_OUTPUT);
    GPIO_SetMode(LED_R_PORT, LED_R_PIN, GPIO_PMD_OUTPUT);
    GPIO_SetMode(SWITCH_PORT, SWITCH_PIN, GPIO_PMD_INPUT);
    GPIO_SetMode(IRDATA_PORT, IRDATA_PIN, GPIO_PMD_INPUT);
	LED_GREEN(0);
	LED_RED(1);

	detect_board_version();

    /* Unlock protected registers */
    SYS_UnlockReg();

    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    UART0_Init();
	SPI_Init();

	TIMER_Open(TIMER0, TIMER_CONTINUOUS_MODE, 6000000);
	TIMER_Open(TIMER1, TIMER_PERIODIC_MODE, TRANSFER_RATE * 2);
	TIMER_Open(TIMER3, TIMER_PERIODIC_MODE, TRANSFER_RATE * 2);
	TIMER_EnableInt(TIMER1);
	TIMER_EnableInt(TIMER3);

	/* Open USB controller */
    USBD_Open(&gsInfo, HID_ClassRequest, NULL);

    /* Init Endpoint configuration for HID */
    HID_Init();

    /* Start USB device */
    USBD_Start();

    /* Enable USB device interrupt */
    NVIC_EnableIRQ(USBD_IRQn);

	LED_GREEN(1);
	LED_RED(0);
    printf("\n\nnuc123-fdsemu v%d.%02d build %d started.  Compiled on "__DATE__" at "__TIME__"\n",version / 100,version % 100,BUILDNUM);
    printf("--CPU @ %0.3f MHz\n", (double)SystemCoreClock / 1000000.0f);
    printf("--SPI0 @ %0.3f MHz\n", (double)SPI_GetBusClock(SPI0) / 1000000.0f);
    printf("--SPI1 @ %0.3f MHz\n", (double)SPI_GetBusClock(SPI1) / 1000000.0f);
    printf("--Detected board version: %d (config = %d %d %d)\n", boardver,PA12,PA13,PA14);
	
	NVIC_SetPriority(USBD_IRQn,2);
	NVIC_SetPriority(TMR1_IRQn,1);
	NVIC_SetPriority(TMR2_IRQn,0);
	NVIC_SetPriority(TMR3_IRQn,0);
	NVIC_SetPriority(GPAB_IRQn,0);
	NVIC_SetPriority(EINT0_IRQn,0);

	flash_init();
	sram_init();

	fds_init();

	print_block_info(0);
	while(1) {
		if(havepacket) {
			havepacket = 0;
//			process_send_feature(epdata,64);
		}
		console_tick();
		fds_tick();
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: wjw890912/Power-measurement
int main(void)
{
    uint32_t u32DataCount, u32TestCount, u32Err;

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART to 115200-8n1 for print message */
    UART_Open(UART0, 115200);

    /* Configure SPI0 as a master, MSB first, 32-bit transaction, SPI Mode-0 timing, clock is 2MHz */
    SPI_Open(SPI0, SPI_MASTER, SPI_MODE_0, 32, 2000000);

    /* Enable the automatic hardware slave select function. Select the SPI0_SS0 pin and configure as low-active. */
    SPI_EnableAutoSS(SPI0, SPI_SS0, SPI_SS_ACTIVE_LOW);

    /* Configure SPI1 as a slave, MSB first, 32-bit transaction, SPI Mode-0 timing, clock is 4Mhz */
    SPI_Open(SPI1, SPI_SLAVE, SPI_MODE_0, 32, 4000000);

    /* Configure SPI1 as a low level active device. */
    SPI_SET_SS0_LOW(SPI1);

    printf("\n\n");
    printf("+----------------------------------------------------------------------+\n");
    printf("|                       SPI Driver Sample Code                         |\n");
    printf("+----------------------------------------------------------------------+\n");
    printf("\n");

    printf("Configure SPI0 as a master and SPI1 as a slave.\n");
    printf("Data width of a transaction: 32\n");
    printf("SPI clock rate: %d Hz\n", SPI_GetBusClock(SPI0));
    printf("The I/O connection for SPI0/SPI1 loopback:\n");
    printf("    SPI0_SS  (PE.4) <--> SPI1_SS(PC.12)\n    SPI0_CLK(PE.5)  <--> SPI1_CLK(PD.1)\n");
    printf("    SPI0_MISO(PE.2) <--> SPI1_MISO(PD.0)\n    SPI0_MOSI(PE.3) <--> SPI1_MOSI(PC.15)\n\n");
    printf("Please connect SPI0 with SPI1, and press any key to start transmission ...");
    getchar();
    printf("\n");

    printf("\nSPI0/1 Loopback test ");

    /* Enable the SPI1 unit transfer interrupt. */
    SPI_EnableInt(SPI1, SPI_UNITIEN_MASK);
    NVIC_EnableIRQ(SPI1_IRQn);
    SPI_TRIGGER(SPI1);

    u32Err = 0;
    for(u32TestCount=0; u32TestCount<10000; u32TestCount++) {
        /* set the source data and clear the destination buffer */
        for(u32DataCount=0; u32DataCount<TEST_COUNT; u32DataCount++) {
            g_au32SourceData[u32DataCount] = u32DataCount;
            g_au32DestinationData[u32DataCount] = 0;
        }

        u32DataCount=0;
        SPI1_INT_Flag = 0;

        if((u32TestCount&0x1FF) == 0) {
            putchar('.');
        }

        SPI_TRIGGER(SPI0);
        /* write the first data of source buffer to Tx register of SPI0. And start transmission. */
        SPI_WRITE_TX(SPI0, g_au32SourceData[0]);

        while(1) {
            if(SPI1_INT_Flag==1) {
                SPI1_INT_Flag = 0;

                if(u32DataCount<(TEST_COUNT-1)) {
                    /* Read the previous retrieved data and trigger next transfer. */
                    g_au32DestinationData[u32DataCount] = SPI_READ_RX(SPI1);
                    u32DataCount++;
                    /* Write data to SPI0 Tx buffer and trigger the transfer */
                    SPI_WRITE_TX(SPI0, g_au32SourceData[u32DataCount]);
                } else {
                    /* Just read the previous retrieved data but trigger next transfer, because this is the last transfer. */
                    g_au32DestinationData[u32DataCount] = SPI_READ_RX(SPI1);
                    break;
                }
            }
        }

        /*  Check the received data */
        for(u32DataCount=0; u32DataCount<TEST_COUNT; u32DataCount++) {
            if(g_au32DestinationData[u32DataCount]!=g_au32SourceData[u32DataCount])
                u32Err = 1;
        }

        if(u32Err)
            break;
    }
    /* Disable the SPI1 unit transfer interrupt. */
    SPI_DisableInt(SPI1, SPI_UNITIEN_MASK);
    NVIC_DisableIRQ(SPI1_IRQn);

    if(u32Err)
        printf(" [FAIL]\n\n");
    else
        printf(" [PASS]\n\n");


    printf("\n\nExit SPI driver sample code.\n");

    while(1);
}