示例#1
0
uint_8 
CmtSpiSdCard::WriteBlock( const uint32 *src, uint32 block ) {
  CCHLOCK(mSpi,CMTE_FAIL);
  mSpi->Select(); /* clear SPI SSEL */
  block <<= mSdFactor; // sector <<= 9;
  /* block size has been set in mmc_init() */
  MMCCmd[0] = 0x58;
  MMCCmd[1] = block >> 24;
  MMCCmd[2] = block >> 16;
  MMCCmd[3] = block >> 8;
  MMCCmd[4] = block;

  /* checksum is no longer required but we always send 0xFF */
  MMCCmd[5] = 0xFF;
  mSpi->WriteBlock( MMCCmd, MMC_CMD_SIZE, mBreak );
  /* if mmc_response returns 1 then we failed to get a 0x00 response */
  if( Response( mSpi, 0x00 ) != CMTE_OK ) {
    mSpi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(mSpi);
    return CMTE_SD_WRITE_BLOCK_TIMEOUT;
    }

  /* Set bit 0 to 0 which indicates the beginning of the data block */
  MMCCmd[0] = 0xfe;
  mSpi->Transfer( MMCCmd, 0, 1, mBreak );
  //MMCCmd[0] = 0xFE;
  //cmtSpiWriteBlock( CMT_SD->mSpi, MMCCmd, 1 );

  /* send data, pattern as 0x00,0x01,0x02,0x03,0x04,0x05 ...*/
  mSpi->WriteBlock( src, MMC_DATA_SIZE, mBreak );

  /* Send dummy checksum */
  /* when the last check sum is sent, the response should come back
  immediately. So, check the SPI FIFO MISO and make sure the status
  return 0xX5, the bit 3 through 0 should be 0x05 */
  MMCCmd[0] = 0xFF;
  MMCCmd[1] = 0xFF;
  mSpi->WriteBlock( MMCCmd, 2, mBreak );
  MMCCmd[0] = 0;
  mSpi->Transfer( MMCCmd, MMCCmd, 1, mBreak );
  if( (MMCCmd[0] & 0x0F) != 0x05 ) {
    mSpi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(mSpi);
    return CMTE_SD_WRITE_BLOCK_FAIL;
    }
  /* if the status is already zero, the write hasn't finished
  yet and card is busy */

  if( WaitForWriteFinish() != CMTE_OK ) {
    mSpi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(mSpi);
    return CMTE_SD_WRITE_BLOCK_FAIL;
    }
  mSpi->UnSelect(); /* set SPI SSEL */
  MMCCmd[0] = 0xff;
  mSpi->WriteBlock( MMCCmd, 1, mBreak );
  CUNLOCK(mSpi);
  return fnIsConnect();
  }
static void
lookup_callback(isc_task_t *task, isc_event_t *ev) {
	client_t *client;

	client = ev->ev_arg;
	INSIST(client->find == ev->ev_sender);

	printf("NAME %s:\n\tTask %p got event %p type %08x from %p, client %p\n\terr4: %s  err6: %s\n",
	       client->target,
	       task, ev, ev->ev_type, client->find, client,
	       isc_result_totext(client->find->result_v4),
	       isc_result_totext(client->find->result_v6));

	isc_event_free(&ev);
	ev = NULL;

	CLOCK();

	dns_adb_dumpfind(client->find, stderr);
	dns_adb_destroyfind(&client->find);

	ISC_LIST_UNLINK(clients, client, link);
	free_client(&client);

	CUNLOCK();
}
示例#3
0
uint_8 
CmtSpiSdCard::ReadBlock( uint32 *dest, uint32 block ) {
  uint_16 Checksum;
  CCHLOCK(mSpi,CMTE_FAIL);
  mSpi->Select(); /* clear SPI SSEL */
  block <<= mSdFactor; // sector <<= 9;
  MMCCmd[0] = 0x51;
  MMCCmd[1] = block >> 24;
  MMCCmd[2] = block >> 16;
  MMCCmd[3] = block >> 8;
  MMCCmd[4] = block;

  /* checksum is no longer required but we always send 0xFF */
  MMCCmd[5] = 0xFF;
  mSpi->WriteBlock( MMCCmd, MMC_CMD_SIZE, mBreak );
  /* if mmc_response returns 1 then we failed to get a 0x00 response */
  if( Response( mSpi, 0x00 ) != CMTE_OK ) {
    mSpi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(mSpi);
    return CMTE_SD_READ_BLOCK_TIMEOUT;
    }
  /* wait for data token */
  if( Response( mSpi, 0xFE ) != CMTE_OK ) {
    mSpi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(mSpi);
    return CMTE_SD_BLOCK_DATA_TOKEN_MISSING;
    }
  /* Get the block of data based on the length */
  memset( dest, 0xff, MMC_DATA_SIZE );
  mSpi->ReadBlock( dest, MMC_DATA_SIZE, mBreak );
  /* CRC bytes that are not needed */
  Checksum = 0xffff;
  mSpi->Transfer( &Checksum, &Checksum, 2, mBreak );
  mSpi->UnSelect(); /* set SPI SSEL */
  Checksum = 0xffff;
  mSpi->WriteBlock( &Checksum, 1, mBreak );
  CUNLOCK(mSpi);
  if( mBreak && mBreak->IsSignaled() ) return CMTE_BREAK;
  return fnIsConnect();
  }
示例#4
0
uint_8
CmtFatFileFinder::FindNext( CMT_FILE_ATTR *lpFileAttr ) {
  FatDirEntry1x *ptr;
  int32 res = CMTE_FAIL;
  //if( mFat == 0 ) return 0;
  char longName[CMT_MAX_PATH];
  longName[0] = 0;
  CLOCK(mFat);
  while(1) {
    ptr = mFat->GetNextFileEntry( &mFinder );
    if( ptr == 0 ) break; //Ничего не найдено
    if( ptr->CheckLongName( longName ) ) continue;
    //Найден очередной элемент директория
    if( ptr->PatternName( longName, mPattern, mFinderFlag ) ) {
      //Подходит
      ptr->FillAttr( longName, lpFileAttr );
      res = CMTE_OK;
      break;
      }
    longName[0] = 0;
    }
  CUNLOCK(mFat);
  return res;
  }
int
main(int argc, char **argv) {
	isc_result_t result;
	isc_logdestination_t destination;

	UNUSED(argc);
	UNUSED(argv);

	dns_result_register();
	result = isc_app_start();
	check_result(result, "isc_app_start()");

	isc_stdtime_get(&now);

	result = isc_mutex_init(&client_lock);
	check_result(result, "isc_mutex_init(&client_lock)");
	ISC_LIST_INIT(clients);

	/*
	 * EVERYTHING needs a memory context.
	 */
	RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);

	cmp = NULL;
	RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp)
		      == ISC_R_SUCCESS);
	isc_mempool_setname(cmp, "adb test clients");

	result = isc_entropy_create(mctx, &ectx);
	check_result(result, "isc_entropy_create()");
	result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
	check_result(result, "isc_hash_create()");

	result = isc_log_create(mctx, &lctx, &lcfg);
	check_result(result, "isc_log_create()");
	isc_log_setcontext(lctx);
	dns_log_init(lctx);
	dns_log_setcontext(lctx);

	/*
	 * Create and install the default channel.
	 */
	destination.file.stream = stderr;
	destination.file.name = NULL;
	destination.file.versions = ISC_LOG_ROLLNEVER;
	destination.file.maximum_size = 0;
	result = isc_log_createchannel(lcfg, "_default",
				       ISC_LOG_TOFILEDESC,
				       ISC_LOG_DYNAMIC,
				       &destination, ISC_LOG_PRINTTIME);
	check_result(result, "isc_log_createchannel()");
	result = isc_log_usechannel(lcfg, "_default", NULL, NULL);
	check_result(result, "isc_log_usechannel()");

	/*
	 * Set the initial debug level.
	 */
	isc_log_setdebuglevel(lctx, 2);

	create_managers();

	t1 = NULL;
	result = isc_task_create(taskmgr, 0, &t1);
	check_result(result, "isc_task_create t1");
	t2 = NULL;
	result = isc_task_create(taskmgr, 0, &t2);
	check_result(result, "isc_task_create t2");

	printf("task 1 = %p\n", t1);
	printf("task 2 = %p\n", t2);

	create_view();

	adb = view->adb;

	/*
	 * Lock the entire client list here.  This will cause all events
	 * for found names to block as well.
	 */
	CLOCK();
	lookup("f.root-servers.net.");		/* Should be in hints */
	lookup("www.iengines.com");		/* should fetch */
	lookup("www.isc.org");			/* should fetch */
	lookup("www.flame.org");		/* should fetch */
	lookup("kechara.flame.org.");		/* should fetch */
	lookup("moghedien.flame.org.");		/* should fetch */
	lookup("mailrelay.flame.org.");		/* should fetch */
	lookup("ipv4v6.flame.org.");		/* should fetch */
	lookup("nonexistant.flame.org.");	/* should fail to be found */
	lookup("foobar.badns.flame.org.");	/* should fail utterly (NS) */
	lookup("i.root-servers.net.");		/* Should be in hints */
	lookup("www.firstcard.com.");
	lookup("dns04.flame.org.");
	CUNLOCK();

	sleep(10);

	dns_adb_dump(adb, stderr);

	sleep(10);

	CLOCK();
	lookup("f.root-servers.net.");		/* Should be in hints */
	lookup("www.iengines.com");		/* should fetch */
	lookup("www.isc.org");			/* should fetch */
	lookup("www.flame.org");		/* should fetch */
	lookup("kechara.flame.org.");		/* should fetch */
	lookup("moghedien.flame.org.");		/* should fetch */
	lookup("mailrelay.flame.org.");		/* should fetch */
	lookup("ipv4v6.flame.org.");		/* should fetch */
	lookup("nonexistant.flame.org.");	/* should fail to be found */
	lookup("foobar.badns.flame.org.");	/* should fail utterly (NS) */
	lookup("i.root-servers.net.");		/* Should be in hints */
	CUNLOCK();

	sleep(20);

	dns_adb_dump(adb, stderr);

	isc_task_detach(&t1);
	isc_task_detach(&t2);

	isc_mem_stats(mctx, stdout);
	dns_adb_dump(adb, stderr);

	isc_app_run();

	dns_adb_dump(adb, stderr);

	dns_view_detach(&view);
	adb = NULL;

	fprintf(stderr, "Destroying socket manager\n");
	isc_socketmgr_destroy(&socketmgr);
	fprintf(stderr, "Destroying timer manager\n");
	isc_timermgr_destroy(&timermgr);

	fprintf(stderr, "Destroying task manager\n");
	isc_taskmgr_destroy(&taskmgr);

	isc_log_destroy(&lctx);

	isc_hash_destroy();
	isc_entropy_detach(&ectx);

	isc_mempool_destroy(&cmp);
	isc_mem_stats(mctx, stdout);
	isc_mem_destroy(&mctx);

	isc_app_finish();

	return (0);
}
示例#6
0
CmtSpiSdCard* 
CmtSpiSdCard::CreateCard( CmtSpiPipeBase *spi, CmtSdIsConnect isConnect ) {
  if( isConnect() != CMTE_OK ) return 0; //Карта не подключена
  CCHLOCK(spi,0);  //SPI не доступно
  uint32 i;
  uint8 MMCCmd[16];
  uint8 dummi[2];

  spi->UnSelect(); /* set SPI SSEL */
  /* initialise the MMC card into SPI mode by sending 80 clks on */
  /* Use MMCRDData as a temporary buffer for SPI_Send() */
  for(i=0; i<10; i++) {
    MMCCmd[i] = 0xFF;
    }
  spi->WriteBlock( MMCCmd, 10, 0 );
  spi->Select(); /* clear SPI SSEL */

  /* send CMD0(RESET or GO_IDLE_STATE) command, all the arguments
  are 0x00 for the reset command, precalculated checksum */
  MMCCmd[0] = 0x40;
  MMCCmd[1] = 0x00;
  MMCCmd[2] = 0x00;
  MMCCmd[3] = 0x00;
  MMCCmd[4] = 0x00;
  MMCCmd[5] = 0x95;
  spi->WriteBlock( MMCCmd, MMC_CMD_SIZE, 0 );

  /* if = 1 then there was a timeout waiting for 0x01 from the MMC */
  if( Response(spi,0x01) != CMTE_OK ) {
//strcpy( (char*)gpsGeo, "            A" );
    spi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(spi);
    return 0;
    }
//strcpy( (char*)gpsGeo, "            U" );

  /* Send some dummy clocks after GO_IDLE_STATE */
  spi->UnSelect(); /* set SPI SSEL */
  MMCCmd[0] = 0xff;
  spi->WriteBlock( MMCCmd, 1, 0 );

  spi->Select(); /* clear SPI SSEL */

  /* must keep sending command until zero response ia back. */
  i = MAX_TIMEOUT;
  do {
    /* send mmc CMD1(SEND_OP_COND) to bring out of idle state */
    /* all the arguments are 0x00 for command one */
    MMCCmd[0] = 0x41;
    MMCCmd[1] = 0x00;
    MMCCmd[2] = 0x00;
    MMCCmd[3] = 0x00;
    MMCCmd[4] = 0x00;
    /* checksum is no longer required but we always send 0xFF */
    MMCCmd[5] = 0xFF;
    spi->WriteBlock( MMCCmd, MMC_CMD_SIZE, 0 );
    i--;
    } while ( (Response(spi,0x00) != CMTE_OK) && (i>0) );

  /* timeout waiting for 0x00 from the MMC */
  if ( i == 0 ) {
    //MMCStatus = OP_COND_TIMEOUT;
//strcpy( (char*)gpsGeo, "            B" );
    spi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(spi);
    return 0;
    }

  /* Send some dummy clocks after SEND_OP_COND */
  spi->UnSelect(); /* set SPI SSEL */
  MMCCmd[0] = 0xff;
  spi->WriteBlock( MMCCmd, 1, 0 );

  //Команда чтения CSD
  spi->Select(); /* clear SPI SSEL */

  /* send CMD9(SEND_CSD) command */
  MMCCmd[0] = 0x49;
  MMCCmd[1] = 0x00;
  MMCCmd[2] = 0x00;
  MMCCmd[3] = 0x00;
  MMCCmd[4] = 0x00;
  MMCCmd[5] = 0xFF;
  spi->WriteBlock( MMCCmd, MMC_CMD_SIZE, 0 );

  /* if = 1 then there was a timeout waiting for 0x01 from the MMC */
  if( Response(spi,0x00) != CMTE_OK ) {
//strcpy( (char*)gpsGeo, "            D" );
    spi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(spi);
    return 0;
    }
  
  /* wait for data token */
  if( Response( spi, 0xFE ) != CMTE_OK ) {
//strcpy( (char*)gpsGeo, "            E" );
    spi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(spi);
    return 0;
    }

  for(i=0; i<16; i++) {
    MMCCmd[i] = 0xff;
    }
  /* Get the block of data based on the length */
  
  spi->ReadBlock( MMCCmd, 16, 0 );
  /* CRC bytes that are not needed */
  dummi[0] = 0xff;
  dummi[1] = 0xff;
  spi->WriteBlock( dummi, 2, 0 );
//GPIO_SetBits( GPIOA, MBIT3 );
  spi->UnSelect(); /* set SPI SSEL */
  dummi[0] = 0;
  spi->WriteBlock( dummi, 1, 0 );

  //Анализ размера карты (определение количества блоков)
  uint32 blockCount; //Количество блоков по 512 байт
  int factor;
  //Регистр CSD MSB битами вперед
  //Биты  127-120  119-112 111-104  103-96  95-88  87-80  79-72  71-64  63-56  55-48  47-40  39-32  31-24  23-16  15-8  7-0
  //Байты    0        1       2        3      4      5      6      7      8      9      10     11     12     13     14   15
  if( (MMCCmd[0] & 0xc0) == 0 ) {
    //SD 1.0
    uint32 c_size;
    c_size = MMCCmd[6] & 0x3; //[73:62]
    c_size <<= 8;
    c_size += MMCCmd[7];
    c_size <<= 2;
    c_size += (MMCCmd[8] >> 6) & 0x3;
    
    uint32 c_size_mult; 
    c_size_mult = MMCCmd[9] & 0x3; //[49:47]
    c_size_mult <<= 1;
    c_size_mult += (MMCCmd[10] >> 7) & 1;
    
    uint32 read_bl_len;
    read_bl_len = MMCCmd[5] & 0xf; //[83:80]
    
    read_bl_len -= 9; //Перейти к блокам
    
    blockCount = (c_size + 1) * (1 << (c_size_mult + 2)) * (1 << read_bl_len);
    factor = 9;
    }