Beispiel #1
0
int time_diff(struct time *res, const struct time *t1, const struct time *t2)
{
	const int cmp = time_cmp(t1, t2);
	if (cmp >= 0) {
		_time_diff(res, t1, t2);
	}
	else {
		_time_diff(res, t2, t1);
	}
	return cmp;
}
Beispiel #2
0
void _io_pccardflexbus_wait
   (
      /* [IN] The info for this slot */
      IO_PCCARDFLEXBUS_STRUCT_PTR  info_ptr,

      /* [IN] The time to wait in ms */
      uint_32                    wait_ms
   )
{ /* Body */
   TIME_STRUCT   now, diff;
   uint_32       diff_ms = 0;

   while (diff_ms < wait_ms) {
      _time_get_elapsed(&now);
      _time_diff(&info_ptr->START_TIME, &now, &diff);
      diff_ms = diff.MILLISECONDS + diff.SECONDS * 1000;
   } /* Endwhile */
      
} /* Endbody */
Beispiel #3
0
/*TASK*-------------------------------------------------------------------
*
* Task Name : main_task
* Comments  :
*
*END*----------------------------------------------------------------------*/
void main_task
   (
      uint_32 dummy
   )
{
    MQX_FILE_PTR           qspifd;
    int_32 ret = 0, i, byte_write, byte_read;
    uint_8_ptr data;
    uint_8 test_data[512];
    TIME_STRUCT start_time, end_time, diff_time;

    printf ("\n-------------- QSPI driver example --------------\n\n");
    printf ("This example application demonstrates usage of QSPI driver.\n");

    /* Open the QSPI driver */
    qspifd = fopen (TEST_CHANNEL, NULL);
    if (qspifd == NULL) {
        printf ("Error opening QSPI driver!\n");
        _time_delay (200L);
        _task_block ();
    }

    /* erase all */
    printf("\n\n************************************************************************\n");
    printf("Erase the first flash chip, for S25FL128S/256S, it might take 30s/60s....\n");
    printf("************************************************************************\n");
    _time_get(&start_time);

    memory_chip_erase(qspifd, FLASH_BASE_ADR);

    _time_get(&end_time);
    _time_diff(&start_time, &end_time, &diff_time);
    printf("\nErase whole flash %ld sec, %ld millisec\n", diff_time.SECONDS, diff_time.MILLISECONDS);
    printf("Finish erase all flash\n");

    printf("\n\n*****************************************\n");
    printf("*** Function Test <memory_read_data> ****\n");
    printf("*****************************************\n");
    printf("From Flash %08x: first 20 btyes\n", TEST_BUFFER1);
    byte_read = memory_read_data(qspifd, TEST_BUFFER1, 20, test_data);
    if (byte_read < 0) {
        printf("memory_read_data failed!\n");
        return;
    }

    for (i = 0; i < 20; i++) {
        printf("0x%02x ", test_data[i]);
    }

    printf("\n\n*****************************************\n");
    printf("*** Function Test <memory_read_byte> ****\n");
    printf("*****************************************\n");
    printf("From Flash %08x: first 20 bytes\n", TEST_BUFFER1);
    for (i = 0; i < 20; i++) {
        printf("0x%02x ", memory_read_byte(qspifd, TEST_BUFFER1 + i));
    }
    printf("\n");

    printf("\n\n*****************************************\n");
    printf("*** Function Test <memory_write_data> ***\n");
    printf("*****************************************\n");
    data = (uint_8_ptr)_mem_alloc_zero(TEST_BUF_SIZE1);
    if (data == NULL) {
        printf("fail to allocate write buffer\n");
        fclose(qspifd);
        return;
    }
    for (i = 0; i < TEST_BUF_SIZE1; i++) {
        data[i] = i % 256;
    }

    _time_get(&start_time);

    byte_write = memory_write_data (qspifd, TEST_BUFFER1, TEST_BUF_SIZE1, data);
    if (byte_write < 0) {
        printf("memory_write_data failed!\n");
        return;
    }

    _time_get(&end_time);
    _time_diff(&start_time, &end_time, &diff_time);
    printf("\ndata = %d, Time spends on Flash write is %ld sec, %ld millisec, rate = %ld kbps\n",
        byte_write, diff_time.SECONDS, diff_time.MILLISECONDS,
        (byte_write)/(diff_time.SECONDS * 1000 + diff_time.MILLISECONDS));

    printf("\n\n*****************************************\n");
    printf("***** Time Test <memory_read_data> ******\n");
    printf("*****************************************\n");
    for (i = 0; i < TEST_BUF_SIZE1; i++) {
        data[i] = 255;
    }

    _time_get(&start_time);

    byte_read = memory_read_data (qspifd, TEST_BUFFER1, TEST_BUF_SIZE1, data);
    if (byte_read < 0) {
        printf("memory_read_data failed!\n");
        return;
    }

    _time_get(&end_time);
    _time_diff(&start_time, &end_time, &diff_time);
    printf("\ndata = %d, Time spends on Flash read is %ld sec, %ld millisec, rate = %ld kbps\n\n",
        byte_write, diff_time.SECONDS, diff_time.MILLISECONDS,
        (byte_write)/(diff_time.SECONDS * 1000 + diff_time.MILLISECONDS));

    printf("memory_read_data read data from %08x: first 20 bytes \n", TEST_BUFFER1);
    for(i = 0; i < 20; i++) {
        printf ("0x%02x ", data[i]);
    }
    printf("\n");

    printf("\n\n*****************************************\n");
    printf("**** Compare Test <memory_read_byte> ****\n");
    printf("*****************************************\n");
    printf("memory_read_byte from %08x: first 20 bytes \n", TEST_BUFFER1);
    for (i = 0; i < 20; i++) {
        printf("0x%02x ", memory_read_byte(qspifd, TEST_BUFFER1 + i));
    }
    printf("\n");

    /* Close the SPI */
    _mem_free(data);
    ret = (uint_32)fclose (qspifd);
    if (ret) {
        printf ("Error closing QSPI, returned: 0x%08x\n", ret);
    }

    printf ("\n-------------- End of example --------------\n\n");

}