本文整理汇总了C++中read_uint32函数 的典型用法代码示例。如果您正苦于以下问题:C++ read_uint32函数的具体用法?C++ read_uint32怎么用?C++ read_uint32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_uint32函数 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: read_uint64
uint64_t read_uint64(const uint8_t ** buffer) {
return (((uint64_t) read_uint32(buffer)) << 32) |
((uint64_t) read_uint32(buffer));
}
开发者ID:rolandvs, 项目名称:network_tester, 代码行数:4, 代码来源:ifc_struct_defs.c
示例2: dmg_open
/* Open dmg image */
int dmg_open(int fd, bdev_desc_t *bdev)
{
u32 count;
u32 max_compressed_size=1,max_sectors_per_chunk=1,i;
bdev->priv = malloc(sizeof(BDRVDMGState));
if(bdev->priv == NULL)
goto fail;
BDRVDMGState *s = DMG_PRIV(bdev);
CLEAR(*s);
off_t info_begin,info_end,last_in_offset,last_out_offset;
/* Init the bdev struct */
bdev->fd = fd;
bdev->read = &wrap_read;
bdev->real_read = &dmg_read;
bdev->write = NULL;
bdev->seek = &dmg_seek;
bdev->close = &dmg_close;
s->fd = fd;
/* RO */
bdev->flags &= ~BF_ENABLE_WRITE;
s->n_chunks = 0;
s->offsets = s->lengths = s->sectors = s->sectorcounts = 0;
/* read offset of info blocks */
if(lseek(s->fd,-0x1d8,SEEK_END)<0)
goto fail;
info_begin=read_off(s->fd);
if(info_begin==0)
goto fail;
if(lseek(s->fd,info_begin,SEEK_SET)<0)
goto fail;
if(read_uint32(s->fd)!=0x100)
goto fail;
if((count = read_uint32(s->fd))==0)
goto fail;
info_end = info_begin+count;
if(lseek(s->fd,0xf8,SEEK_CUR)<0)
goto fail;
/* read offsets */
last_in_offset = last_out_offset = 0;
while(lseek(s->fd,0,SEEK_CUR)<info_end) {
u32 type;
count = read_uint32(s->fd);
if(count==0)
goto fail;
type = read_uint32(s->fd);
if(type!=0x6d697368 || count<244)
lseek(s->fd,count-4,SEEK_CUR);
else {
int new_size, chunk_count;
if(lseek(s->fd,200,SEEK_CUR)<0)
goto fail;
chunk_count = (count-204)/40;
new_size = sizeof(u64) * (s->n_chunks + chunk_count);
s->types = realloc(s->types, new_size/2);
s->offsets = realloc(s->offsets, new_size);
s->lengths = realloc(s->lengths, new_size);
s->sectors = realloc(s->sectors, new_size);
s->sectorcounts = realloc(s->sectorcounts, new_size);
for(i=s->n_chunks;i<s->n_chunks+chunk_count;i++) {
s->types[i] = read_uint32(s->fd);
if(s->types[i]!=0x80000005 && s->types[i]!=1 && s->types[i]!=2) {
if(s->types[i]==0xffffffff) {
last_in_offset = s->offsets[i-1]+s->lengths[i-1];
last_out_offset = s->sectors[i-1]+s->sectorcounts[i-1];
}
chunk_count--;
i--;
if(lseek(s->fd,36,SEEK_CUR)<0)
goto fail;
continue;
}
read_uint32(s->fd);
s->sectors[i] = last_out_offset+read_off(s->fd);
s->sectorcounts[i] = read_off(s->fd);
s->offsets[i] = last_in_offset+read_off(s->fd);
s->lengths[i] = read_off(s->fd);
if(s->lengths[i]>max_compressed_size)
max_compressed_size = s->lengths[i];
if(s->sectorcounts[i]>max_sectors_per_chunk)
max_sectors_per_chunk = s->sectorcounts[i];
}
s->n_chunks+=chunk_count;
}
}
bdev->size = s->n_chunks * 512;
/* initialize zlib engine */
if(!(s->compressed_chunk=(char*)malloc(max_compressed_size+1)))
goto fail;
if(!(s->uncompressed_chunk=(char*)malloc(512*max_sectors_per_chunk)))
goto fail;
if(inflateInit(&s->zstream) != Z_OK)
//.........这里部分代码省略.........
开发者ID:threader, 项目名称:Mac-On-Linux, 代码行数:101, 代码来源:blk_dmg.c
示例3: read_ply_property
/* Reads a property of type 'prop_type' from 'data', and puts the
* result 'out'. Returns 0 upon success, a negative value otherwise */
static int read_ply_property(struct file_data *data, const int prop_type,
const int swap_bytes, void *out)
{
int c, rcode=0;
/* Just local pointers to copy the result from the 'read_[type]'
* functions into... */
t_int8 *tmp_int8;
t_uint8 *tmp_uint8;
t_int16 *tmp_int16;
t_uint16 *tmp_uint16;
t_int32 *tmp_int32;
t_uint32 *tmp_uint32;
float *tmp_float32;
double *tmp_float64;
switch(prop_type) {
case uint8:
c = getc(data);
if (c == EOF)
rcode = EOF;
else {
tmp_uint8 = out;
*tmp_uint8 = (t_uint8)c;
}
break;
case int8:
c = getc(data);
if (c == EOF)
rcode = EOF;
else {
tmp_int8= out;
*tmp_int8 = (t_int8)c;
}
break;
case uint16:
tmp_uint16 = out;
rcode = read_uint16(data, swap_bytes, tmp_uint16);
break;
case int16:
tmp_int16 = out;
rcode = read_int16(data, swap_bytes, tmp_int16);
break;
case uint32:
tmp_uint32 = out;
rcode = read_uint32(data, swap_bytes, tmp_uint32);
break;
case int32:
tmp_int32 = out;
rcode = read_int32(data, swap_bytes, tmp_int32);
break;
case float32:
tmp_float32 = out;
rcode = read_float32(data, swap_bytes, tmp_float32);
break;
case float64:
tmp_float64 = out;
rcode = read_float64(data, swap_bytes, tmp_float64);
break;
default:
rcode = MESH_CORRUPTED;
break;
}
return rcode;
}
开发者ID:BackupTheBerlios, 项目名称:mesh, 代码行数:67, 代码来源:model_in_ply.c
示例4: bmp_analyse_header
static bmp_result bmp_analyse_header(bmp_image *bmp, uint8_t *data) {
uint32_t header_size;
uint32_t i;
uint8_t j;
int32_t width, height;
uint8_t palette_size;
unsigned int flags = 0;
/* a variety of different bitmap headers can follow, depending
* on the BMP variant. A full description of the various headers
* can be found at
* http://msdn.microsoft.com/en-us/library/ms532301(VS.85).aspx
*/
header_size = read_uint32(data, 0);
if (bmp->buffer_size < (14 + header_size))
return BMP_INSUFFICIENT_DATA;
if (header_size == 12) {
/* the following header is for os/2 and windows 2.x and consists of:
*
* +0 UINT32 size of this header (in bytes)
* +4 INT16 image width (in pixels)
* +6 INT16 image height (in pixels)
* +8 UINT16 number of colour planes (always 1)
* +10 UINT16 number of bits per pixel
*/
width = read_int16(data, 4);
height = read_int16(data, 6);
if ((width <= 0) || (height == 0))
return BMP_DATA_ERROR;
if (height < 0) {
bmp->reversed = true;
height = -height;
}
/* ICOs only support 256*256 resolutions
* In the case of the ICO header, the height is actually the added
* height of XOR-Bitmap and AND-Bitmap (double the visible height)
* Technically we could remove this check and ICOs with bitmaps
* of any size could be processed; this is to conform to the spec.
*/
if (bmp->ico) {
if ((width > 256) || (height > 512)) {
return BMP_DATA_ERROR;
} else {
bmp->width = width;
bmp->height = height / 2;
}
} else {
bmp->width = width;
bmp->height = height;
}
if (read_uint16(data, 8) != 1)
return BMP_DATA_ERROR;
bmp->bpp = read_uint16(data, 10);
/**
* The bpp value should be in the range 1-32, but the only
* values considered legal are:
* RGB ENCODING: 1, 4, 8, 16, 24 and 32
*/
if ((bmp->bpp != 1) && (bmp->bpp != 4) &&
(bmp->bpp != 8) &&
(bmp->bpp != 16) &&
(bmp->bpp != 24) &&
(bmp->bpp != 32))
return BMP_DATA_ERROR;
bmp->colours = (1 << bmp->bpp);
palette_size = 3;
} else if (header_size < 40) {
return BMP_DATA_ERROR;
} else {
/* the following header is for windows 3.x and onwards. it is a
* minimum of 40 bytes and (as of Windows 95) a maximum of 108 bytes.
*
* +0 UINT32 size of this header (in bytes)
* +4 INT32 image width (in pixels)
* +8 INT32 image height (in pixels)
* +12 UINT16 number of colour planes (always 1)
* +14 UINT16 number of bits per pixel
* +16 UINT32 compression methods used
* +20 UINT32 size of bitmap (in bytes)
* +24 UINT32 horizontal resolution (in pixels per meter)
* +28 UINT32 vertical resolution (in pixels per meter)
* +32 UINT32 number of colours in the image
* +36 UINT32 number of important colours
* +40 UINT32 mask identifying bits of red component
* +44 UINT32 mask identifying bits of green component
* +48 UINT32 mask identifying bits of blue component
* +52 UINT32 mask identifying bits of alpha component
* +56 UINT32 color space type
* +60 UINT32 x coordinate of red endpoint
* +64 UINT32 y coordinate of red endpoint
* +68 UINT32 z coordinate of red endpoint
* +72 UINT32 x coordinate of green endpoint
* +76 UINT32 y coordinate of green endpoint
* +80 UINT32 z coordinate of green endpoint
* +84 UINT32 x coordinate of blue endpoint
* +88 UINT32 y coordinate of blue endpoint
* +92 UINT32 z coordinate of blue endpoint
* +96 UINT32 gamma red coordinate scale value
* +100 UINT32 gamma green coordinate scale value
* +104 UINT32 gamma blue coordinate scale value
//.........这里部分代码省略.........
开发者ID:solcer, 项目名称:bmp2fb, 代码行数:101, 代码来源:libnsbmp.c
示例5: slip_decode
/* state->src and state->src_size contain the freshly read bytes
we must accumulate any partial state between calls.
*/
int slip_decode(struct slip_decode_state *state)
{
switch(state->encapsulator) {
case SLIP_FORMAT_SLIP:
{
/*
Examine received bytes for end of packet marker.
The challenge is that we need to make sure that the packet encapsulation
is self-synchronising in the event that a data error occurs (including
failure to receive an arbitrary number of bytes).
*/
while(state->src_offset < state->src_size){
// clear the valid bit flag if we hit the end of the destination buffer
if (state->dst_offset >= sizeof state->dst)
state->state&=~DC_VALID;
if (state->state&DC_ESC){
// clear escape bit
state->state&=~DC_ESC;
switch(state->src[state->src_offset]) {
case SLIP_ESC_END: // escaped END byte
state->dst[state->dst_offset++]=SLIP_END;
break;
case SLIP_ESC_ESC: // escaped escape character
state->dst[state->dst_offset++]=SLIP_ESC;
break;
case SLIP_ESC_0a:
state->dst[state->dst_offset++]=SLIP_0a;
break;
case SLIP_ESC_0d:
state->dst[state->dst_offset++]=SLIP_0d;
break;
case SLIP_ESC_0f:
state->dst[state->dst_offset++]=SLIP_0f;
break;
case SLIP_ESC_1b:
state->dst[state->dst_offset++]=SLIP_1b;
break;
default: /* Unknown escape character. This is an error. */
if (config.debug.packetradio)
WARNF("Packet radio stream contained illegal escaped byte 0x%02x -- resetting parser.",state->src[state->src_offset]);
state->dst_offset=0;
// skip everything until the next SLIP_END
state->state=0;
}
}else{
// non-escape character
switch(state->src[state->src_offset]) {
case SLIP_ESC:
// set escape bit
state->state|=DC_ESC;
break;
case SLIP_END:
if (state->dst_offset>4){
uint32_t src_crc = read_uint32(state->dst + state->dst_offset -4);
uint32_t crc=Crc32_ComputeBuf( 0, state->dst, state->dst_offset -4);
if (src_crc != crc){
DEBUGF("Dropping frame due to CRC failure (%08x vs %08x)", src_crc, crc);
dump("frame", state->dst, state->dst_offset);
state->dst_offset=0;
state->state=0;
break;
}
// return once we've successfully parsed a valid packet that isn't empty
state->packet_length=state->dst_offset -4;
return 1;
}
// set the valid flag to begin parsing the next packet
state->state=DC_VALID;
break;
default:
if (state->state&DC_VALID)
state->dst[state->dst_offset++]=state->src[state->src_offset];
}
}
state->src_offset++;
}
return 0;
}
case SLIP_FORMAT_UPPER7:
{
if (config.debug.slip) {
if (state->rssi_len>=RSSI_TEXT_SIZE) state->rssi_len=RSSI_TEXT_SIZE-1;
state->rssi_text[state->rssi_len]=0;
DEBUGF("RX state=%d, rssi_len=%u, rssi_text='%s',src=%p, src_size=%u",
state->state,state->rssi_len,state->rssi_text,
state->src,state->src_size);
}
while(state->src_offset<state->src_size) {
if (upper7_decode(state,state->src[state->src_offset++])==1) {
if (config.debug.slip) {
dump("de-slipped packet",state->dst,state->packet_length);
}
// Check that CRC matches
//.........这里部分代码省略.........
开发者ID:petterreinholdtsen, 项目名称:serval-dna, 代码行数:101, 代码来源:slip.c
示例6: dmg_read_resource_fork
static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds,
uint64_t info_begin, uint64_t info_length)
{
BDRVDMGState *s = bs->opaque;
int ret;
uint32_t count, rsrc_data_offset;
uint8_t *buffer = NULL;
uint64_t info_end;
uint64_t offset;
/* read offset from begin of resource fork (info_begin) to resource data */
ret = read_uint32(bs, info_begin, &rsrc_data_offset);
if (ret < 0) {
goto fail;
} else if (rsrc_data_offset > info_length) {
ret = -EINVAL;
goto fail;
}
/* read length of resource data */
ret = read_uint32(bs, info_begin + 8, &count);
if (ret < 0) {
goto fail;
} else if (count == 0 || rsrc_data_offset + count > info_length) {
ret = -EINVAL;
goto fail;
}
/* begin of resource data (consisting of one or more resources) */
offset = info_begin + rsrc_data_offset;
/* end of resource data (there is possibly a following resource map
* which will be ignored). */
info_end = offset + count;
/* read offsets (mish blocks) from one or more resources in resource data */
while (offset < info_end) {
/* size of following resource */
ret = read_uint32(bs, offset, &count);
if (ret < 0) {
goto fail;
} else if (count == 0 || count > info_end - offset) {
ret = -EINVAL;
goto fail;
}
offset += 4;
buffer = g_realloc(buffer, count);
ret = bdrv_pread(bs->file, offset, buffer, count);
if (ret < 0) {
goto fail;
}
ret = dmg_read_mish_block(s, ds, buffer, count);
if (ret < 0) {
goto fail;
}
/* advance offset by size of resource */
offset += count;
}
ret = 0;
fail:
g_free(buffer);
return ret;
}
开发者ID:heiher, 项目名称:qemu, 代码行数:66, 代码来源:dmg.c
示例7:
void *read_pipe_(void* a)
{
*((int*)a) = read_uint32("outpipe");
}
开发者ID:madhavPdesai, 项目名称:ahir, 代码行数:4, 代码来源:testbench.c
示例8: pok_loader_load_partition
void pok_loader_load_partition (const uint32_t part_id, uint32_t *entry)
{
(void) part_id;
uint32_t part_entry;
uint32_t segments;
if(read_uint32(&part_entry) != sizeof(uint32_t))
{
#ifdef POK_NEEDS_ERROR_HANDLING
pok_partition_error (part_id, POK_ERROR_KIND_PARTITION_CONFIGURATION);
#else
#ifdef POK_NEEDS_DEBUG
#include <core/debug.h>
#include <stdio.h>
pok_fatal ("No partition entry\n");
#endif
#endif
}
if(read_uint32(&segments) != sizeof(uint32_t))
{
#ifdef POK_NEEDS_ERROR_HANDLING
pok_partition_error (part_id, POK_ERROR_KIND_PARTITION_CONFIGURATION);
#else
#ifdef POK_NEEDS_DEBUG
#include <core/debug.h>
#include <stdio.h>
pok_fatal ("No partition size\n");
#endif
#endif
}
#ifdef POK_NEEDS_DEBUG
printf("[DEBUG]\t [Reading partition %d] Entry address: %p\n", part_id, (void*)(part_entry));
printf("[DEBUG]\t [Reading partition %d] Segments number: %d\n", part_id, segments);
#endif
unsigned int segment = 0;
unsigned int part_size = 0;
while (segment < segments)
{
uint32_t segment_address;
uint32_t segment_size;
if (read_uint32(&segment_address) != sizeof(uint32_t))
{
#ifdef POK_NEEDS_ERROR_HANDLING
pok_partition_error (part_id, POK_ERROR_KIND_PARTITION_CONFIGURATION);
#else
#ifdef POK_NEEDS_DEBUG
#include <core/debug.h>
#include <stdio.h>
pok_fatal ("No segment address\n");
#endif
#endif
}
#ifdef POK_NEEDS_DEBUG
printf("[DEBUG]\t [Reading partition %d] Segment %d address: %p\n", part_id, segment, (void*)segment_address);
#endif
if (read_uint32(&segment_size) != sizeof(uint32_t))
{
#ifdef POK_NEEDS_ERROR_HANDLING
pok_partition_error (part_id, POK_ERROR_KIND_PARTITION_CONFIGURATION);
#else
#ifdef POK_NEEDS_DEBUG
#include <core/debug.h>
#include <stdio.h>
pok_fatal ("No segment size\n");
#endif
#endif
}
#ifdef POK_NEEDS_DEBUG
printf("[DEBUG]\t [Reading partition %d] Segment %d size: %d\n", part_id, segment, segment_size);
#endif
if (read_data(segment_size, (char*)(segment_address)) != segment_size) {
#ifdef POK_NEEDS_ERROR_HANDLING
pok_partition_error (part_id, POK_ERROR_KIND_PARTITION_CONFIGURATION);
#else
#ifdef POK_NEEDS_DEBUG
#include <core/debug.h>
#include <stdio.h>
printf("No segment data\n");
#endif
#endif
}
part_size = part_size + segment_size;
#ifdef POK_NEEDS_DEBUG
printf("[DEBUG]\t [Reading partition %d] Segment %d loaded\n", part_id, segment);
#endif
segment++;
}
*entry = (uint32_t) (part_entry);
}
开发者ID:t-crest, 项目名称:ospat, 代码行数:98, 代码来源:loader.c
示例9: ape_parseheader
int ape_parseheader(int fd, struct ape_ctx_t* ape_ctx)
{
int i,n;
/* TODO: Skip any leading junk such as id3v2 tags */
ape_ctx->junklength = 0;
lseek(fd,ape_ctx->junklength,SEEK_SET);
n = read(fd,&ape_ctx->magic,4);
if (n != 4) return -1;
if (memcmp(ape_ctx->magic,"MAC ",4)!=0)
{
return -1;
}
if (read_int16(fd,&ape_ctx->fileversion) < 0)
return -1;
if (ape_ctx->fileversion >= 3980)
{
if (read_int16(fd,&ape_ctx->padding1) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->descriptorlength) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->headerlength) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->seektablelength) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->wavheaderlength) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->audiodatalength) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->audiodatalength_high) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->wavtaillength) < 0)
return -1;
if (read(fd,&ape_ctx->md5,16) != 16)
return -1;
/* Skip any unknown bytes at the end of the descriptor. This is for future
compatibility */
if (ape_ctx->descriptorlength > 52)
lseek(fd,ape_ctx->descriptorlength - 52, SEEK_CUR);
/* Read header data */
if (read_uint16(fd,&ape_ctx->compressiontype) < 0)
return -1;
if (read_uint16(fd,&ape_ctx->formatflags) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->blocksperframe) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->finalframeblocks) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->totalframes) < 0)
return -1;
if (read_uint16(fd,&ape_ctx->bps) < 0)
return -1;
if (read_uint16(fd,&ape_ctx->channels) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->samplerate) < 0)
return -1;
} else {
ape_ctx->descriptorlength = 0;
ape_ctx->headerlength = 32;
if (read_uint16(fd,&ape_ctx->compressiontype) < 0)
return -1;
if (read_uint16(fd,&ape_ctx->formatflags) < 0)
return -1;
if (read_uint16(fd,&ape_ctx->channels) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->samplerate) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->wavheaderlength) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->wavtaillength) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->totalframes) < 0)
return -1;
if (read_uint32(fd,&ape_ctx->finalframeblocks) < 0)
return -1;
if (ape_ctx->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL)
{
lseek(fd, 4, SEEK_CUR); /* Skip the peak level */
ape_ctx->headerlength += 4;
}
if (ape_ctx->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS)
{
if (read_uint32(fd,&ape_ctx->seektablelength) < 0)
return -1;
ape_ctx->headerlength += 4;
ape_ctx->seektablelength *= sizeof(int32_t);
} else {
ape_ctx->seektablelength = ape_ctx->totalframes * sizeof(int32_t);
}
//.........这里部分代码省略.........
开发者ID:avs333, 项目名称:alsaplayer, 代码行数:101, 代码来源:parser.c
示例10: main
int main(int argc, char *argv[]) {
// set scpi lib debug level: 0 for no debug info, 10 for lots
const int scsi_verbose = 2;
char *dev_name;
switch (argc) {
case 1:
fputs(
"\nUsage: stlink-access-test /dev/sg0, sg1, ...\n"
"\n*** Notice: The stlink firmware violates the USB standard.\n"
"*** If you plug-in the discovery's stlink, wait a several\n"
"*** minutes to let the kernel driver swallow the broken device.\n"
"*** Watch:\ntail -f /var/log/messages\n"
"*** This command sequence can shorten the waiting time and fix some issues.\n"
"*** Unplug the stlink and execute once as root:\n"
"modprobe -r usb-storage && modprobe usb-storage quirks=483:3744:lrwsro\n\n",
stderr);
return EXIT_FAILURE;
case 2:
dev_name = argv[1];
break;
default:
return EXIT_FAILURE;
}
fputs("*** stlink access test ***\n", stderr);
fprintf(stderr, "Using sg_lib %s : scsi_pt %s\n", sg_lib_version(),
scsi_pt_version());
stlink_t *sl = stlink_quirk_open(dev_name, scsi_verbose);
if (sl == NULL)
return EXIT_FAILURE;
// we are in mass mode, go to swd
stlink_enter_swd_mode(sl);
stlink_current_mode(sl);
stlink_core_id(sl);
//----------------------------------------------------------------------
stlink_status(sl);
//stlink_force_debug(sl);
stlink_reset(sl);
stlink_status(sl);
#if 0
// core system control block
stlink_read_mem32(sl, 0xe000ed00, 4);
DD(sl, "cpu id base register: SCB_CPUID = got 0x%08x expect 0x411fc231", read_uint32(sl->q_buf, 0));
// no MPU
stlink_read_mem32(sl, 0xe000ed90, 4);
DD(sl, "mpu type register: MPU_TYPER = got 0x%08x expect 0x0", read_uint32(sl->q_buf, 0));
stlink_read_mem32(sl, 0xe000edf0, 4);
DD(sl, "DHCSR = 0x%08x", read_uint32(sl->q_buf, 0));
stlink_read_mem32(sl, 0x4001100c, 4);
DD(sl, "GPIOC_ODR = 0x%08x", read_uint32(sl->q_buf, 0));
#endif
#if 0
// happy new year 2011: let blink all the leds
// see "RM0041 Reference manual - STM32F100xx advanced ARM-based 32-bit MCUs"
#define GPIOC 0x40011000 // port C
#define GPIOC_CRH (GPIOC + 0x04) // port configuration register high
#define GPIOC_ODR (GPIOC + 0x0c) // port output data register
#define LED_BLUE (1<<8) // pin 8
#define LED_GREEN (1<<9) // pin 9
stlink_read_mem32(sl, GPIOC_CRH, 4);
uint32_t io_conf = read_uint32(sl->q_buf, 0);
DD(sl, "GPIOC_CRH = 0x%08x", io_conf);
// set: general purpose output push-pull, output mode, max speed 10 MHz.
write_uint32(sl->q_buf, 0x44444411);
stlink_write_mem32(sl, GPIOC_CRH, 4);
clear_buf(sl);
for (int i = 0; i < 100; i++) {
write_uint32(sl->q_buf, LED_BLUE | LED_GREEN);
stlink_write_mem32(sl, GPIOC_ODR, 4);
/* stlink_read_mem32(sl, 0x4001100c, 4); */
/* DD(sl, "GPIOC_ODR = 0x%08x", read_uint32(sl->q_buf, 0)); */
delay(100);
clear_buf(sl);
stlink_write_mem32(sl, GPIOC_ODR, 4); // PC lo
delay(100);
}
write_uint32(sl->q_buf, io_conf); // set old state
#endif
#if 0
// TODO rtfm: stlink doesn't have flash write routines
// writing to the flash area confuses the fw for the next read access
//stlink_read_mem32(sl, 0, 1024*6);
// flash 0x08000000 128kB
fputs("++++++++++ read a flash at 0x0800 0000\n", stderr);
stlink_read_mem32(sl, 0x08000000, 1024 * 6); //max 6kB
clear_buf(sl);
stlink_read_mem32(sl, 0x08000c00, 5);
stlink_read_mem32(sl, 0x08000c00, 4);
//.........这里部分代码省略.........
开发者ID:bikeNomad, 项目名称:stlink, 代码行数:101, 代码来源:test_sg.c
示例11: LOG_ERROR_RETURN
bool Indigo::detail::ZipFile::open(const char* filename)
{
static const OOBase::uint8_t END_OF_CDR[4] = { 0x50, 0x4b, 0x05, 0x06 };
static const OOBase::uint8_t CDR_HEADER[4] = { 0x50, 0x4b, 0x01, 0x02 };
int err = m_file.open(filename,false);
if (err)
LOG_ERROR_RETURN(("Failed to open file %s: %s",filename,OOBase::system_error_text(err)),false);
OOBase::uint64_t len = m_file.length();
if (len == OOBase::uint64_t(-1))
LOG_ERROR_RETURN(("Failed to get file length: %s",OOBase::system_error_text()),false);
// Step backwards looking for end of central directory record
OOBase::uint32_t cdr_size = 0;
OOBase::ScopedArrayPtr<OOBase::uint8_t,OOBase::ThreadLocalAllocator,256> buf;
for (OOBase::int64_t offset = len - 256;!cdr_size;)
{
if (offset < 0)
offset = 0;
OOBase::uint64_t p = m_file.seek(offset,OOBase::File::seek_begin);
if (p == OOBase::uint64_t(-1))
LOG_ERROR_RETURN(("Failed to get seek in file: %s",OOBase::system_error_text()),false);
size_t chunk_len = m_file.read(buf.get(),256);
if (chunk_len == size_t(-1))
LOG_ERROR_RETURN(("Failed to read file: %s",OOBase::system_error_text()),false);
// Scan forwards looking for signatures
for (OOBase::uint8_t* c = buf.get(); c < buf.get() + chunk_len - 4; ++c)
{
if (memcmp(c,END_OF_CDR,4) == 0)
{
OOBase::uint64_t eof_cdr = p + (c - buf.get());
if (len - eof_cdr >= 22 && m_file.seek(eof_cdr,OOBase::File::seek_begin) == eof_cdr)
{
m_file.read(buf.get(),22);
OOBase::uint16_t disk_no = read_uint16(buf,4);
OOBase::uint16_t cdr_disk_no = read_uint16(buf,6);
OOBase::uint16_t cdr_entries_disk = read_uint16(buf,8);
OOBase::uint16_t cdr_entries = read_uint16(buf,10);
OOBase::uint32_t cdr_size_i = read_uint32(buf,12);
OOBase::uint32_t cdr_offset = read_uint32(buf,16);
OOBase::uint16_t comments = read_uint16(buf,20);
if (cdr_size_i >= 46 && (eof_cdr + 22 + comments == len) &&
(disk_no == 0 && cdr_disk_no == 0 && cdr_entries_disk == cdr_entries) &&
(cdr_offset + cdr_size_i <= eof_cdr))
{
if (m_file.seek(cdr_offset,OOBase::File::seek_begin) == cdr_offset)
{
m_file.read(buf.get(),46);
if (memcmp(buf.get(),CDR_HEADER,4) == 0)
{
cdr_size = cdr_size_i;
break;
}
}
}
}
}
}
if (offset > 0)
offset -= 253;
else
break;
}
if (!cdr_size)
LOG_ERROR_RETURN(("Failed to find end of central dictionary in zip %s",filename),false);
// Now loop reading file entries
for (;;)
{
struct Info info = {0};
info.m_length = read_uint32(buf,24);
OOBase::uint16_t filename_len = read_uint16(buf,28);
OOBase::uint16_t extra_len = read_uint16(buf,30);
OOBase::uint16_t comments = read_uint16(buf,32);
OOBase::uint16_t disk_no = read_uint16(buf,34);
info.m_offset = read_uint32(buf,42);
if (disk_no != 0)
LOG_ERROR_RETURN(("Multi-disk zip file not supported: %s",filename),false);
if (filename_len == 0)
LOG_WARNING(("Ignoring empty filename in %s",filename));
else
{
if (!buf.resize(filename_len))
LOG_ERROR_RETURN(("Failed to resize buffer: %s",OOBase::system_error_text()),false);
if (m_file.read(buf.get(),filename_len) != filename_len)
LOG_ERROR_RETURN(("Failed to read file %s: %s",filename,OOBase::system_error_text()),false);
//.........这里部分代码省略.........
开发者ID:ricktaylor, 项目名称:indigo, 代码行数:101, 代码来源:ZipResource.cpp
示例12: filename
OOBase::SharedPtr<const char> Indigo::detail::ZipFile::load(const OOBase::String& prefix, const char* name)
{
OOBase::SharedPtr<const char> ret;
OOBase::String filename(prefix);
if (!filename.append(name))
LOG_ERROR_RETURN(("Failed to append string: %s",OOBase::system_error_text()),ret);
OOBase::Table<OOBase::String,Info>::iterator i=m_mapFiles.find(filename);
if (!i)
return ret;
// Read the local file header
if (m_file.seek(i->second.m_offset,OOBase::File::seek_begin) == OOBase::uint64_t(-1))
LOG_ERROR_RETURN(("Failed to get seek in file: %s",OOBase::system_error_text()),ret);
OOBase::uint8_t header[30];
if (m_file.read(header,30) != 30)
LOG_ERROR_RETURN(("Failed to read local file header header in zip"),ret);
static const OOBase::uint8_t LFR_HEADER[4] = { 0x50, 0x4b, 0x03, 0x04 };
if (memcmp(header,LFR_HEADER,4) != 0)
LOG_ERROR_RETURN(("Invalid local file header header in zip"),ret);
OOBase::uint16_t compression = read_uint16(header,8);
OOBase::uint32_t compressed_size = read_uint32(header,18);
size_t offset = 30 + read_uint16(header,26) + read_uint16(header,28);
OOBase::SharedPtr<const char> mapping = m_file.auto_map<const char>(false,i->second.m_offset + offset,compressed_size);
if (!mapping)
LOG_ERROR_RETURN(("Failed to map file content: %s",OOBase::system_error_text()),ret);
if (compression == 0)
{
ret = mapping;
}
else if (compression == 8)
{
void* p = OOBase::CrtAllocator::allocate(i->second.m_length,1);
if (!p)
LOG_ERROR_RETURN(("Failed to allocate: %s",OOBase::system_error_text()),ret);
if (stbi_zlib_decode_noheader_buffer(static_cast<char*>(p),(int)i->second.m_length,mapping.get(),(int)compressed_size) == -1)
{
LOG_ERROR(("Failed to inflate file: %s",stbi_failure_reason()));
OOBase::CrtAllocator::free(p);
}
else
{
ret = OOBase::const_pointer_cast<const char>(OOBase::make_shared<char>(static_cast<char*>(p)));
if (!ret)
{
LOG_ERROR(("Failed to allocate: %s",OOBase::system_error_text()));
OOBase::CrtAllocator::free(p);
}
}
}
else
LOG_ERROR(("Unsupported zip compression method: %u",compression));
return ret;
}
开发者ID:ricktaylor, 项目名称:indigo, 代码行数:61, 代码来源:ZipResource.cpp
示例13: process_input
/* Process the differences file in input stream, starting at offset 8 (the
header has already been read and verified), creating a new block reference
list. */
static void process_input(InputStream *is)
{
FILE *fp;
uint32_t S;
uint16_t C, A;
size_t num_blocks;
off_t offset;
BlockRef br;
uint8_t digest1[DS], digest2[DS];
fp = tmpfile();
if (fp == NULL)
{
fprintf(stderr, "Couldn't open temporary file!\n");
exit(EXIT_FAILURE);
}
offset = 8;
num_blocks = 0;
for (;;)
{
S = read_uint32(is);
C = read_uint16(is);
A = read_uint16(is);
offset += 8;
/* Check for end-of-instructions. */
if (S == 0xffffffffu && C == 0xffffu && A == 0xffffu) break;
if ( (C > 0x7fffu || A > 0x7fffu) || (C > 0xffffffffu - S) ||
(S == 0xffffffffu && C != 0) || (S != 0xffffffffu && C == 0) )
{
fprintf(stderr, "Invalid instruction in differences file!\n");
exit(EXIT_FAILURE);
}
while (C--)
{
if (last_blocks == NULL)
{
br.is = NULL;
br.offset = BS*S++;
}
else
{
if (S >= last_num_blocks)
{
fprintf(stderr, "Invalid block index in differences file!\n");
exit(EXIT_FAILURE);
}
br = last_blocks[S++];
}
if (fwrite(&br, sizeof(br), 1, fp) != 1)
{
fprintf(stderr, "Write to temporary file failed!\n");
exit(EXIT_FAILURE);
}
++num_blocks;
}
while (A--)
{
br.is = is;
br.offset = offset;
offset += BS;
if (fwrite(&br, sizeof(br), 1, fp) != 1)
{
fprintf(stderr, "Write to temporary file failed!\n");
exit(EXIT_FAILURE);
}
++num_blocks;
}
is->seek(is, offset);
}
/* Verify MD5 digests */
read_data(is, digest2, DS);
if (is->read(is, digest1, DS) == DS)
{
if (last_blocks == NULL)
{
orig_digest_known = true;
memcpy(orig_digest, digest1, DS);
}
else
if (memcmp(digest1, last_digest, DS) != 0)
{
fprintf(stderr, "Invalid sequence of differences files!\n");
exit(EXIT_FAILURE);
}
}
else
{
fprintf(stderr, "WARNING: differences file is missing original file "
"digest; patch integrity cannot be guaranteed.\n");
//.........这里部分代码省略.........
开发者ID:maksverver, 项目名称:tardiff, 代码行数:101, 代码来源:tardiffmerge.c
示例14: ape_parseheader
//int ape_parseheader(int fd, struct ape_parser_ctx_t* ape_ctx)
int ape_parseheader(FILE* fp, struct ape_parser_ctx_t* ape_ctx)
{
int i,n;
/* Skip any leading junk such as id3v2 tags */
memset(ape_ctx, 0, sizeof(struct ape_parser_ctx_t));
while (1) {
char sync[5];
if (4 != fread(sync, 1, 4, fp))
return -1;
sync[4] = 0;
if (strcmp(sync,"MAC ") == 0)
break;
else if (strcmp(sync + 1,"MAC") == 0) {
fseek(fp, -1, SEEK_CUR);
ape_ctx->junklength += 1;
}
else if (strcmp(sync + 2, "MA") == 0) {
fseek(fp, -2, SEEK_CUR);
ape_ctx->junklength += 2;
}
else if (sync[3]=='M') {
fseek(fp, -3, SEEK_CUR);
ape_ctx->junklength += 3;
}
else {
ape_ctx->junklength += 4;
}
}
fseek(fp, ape_ctx->junklength, SEEK_SET);
n = fread(&ape_ctx->magic,1, 4, fp);
if (n != 4) return -1;
if (memcmp(ape_ctx->magic,"MAC ",4)!=0)
{
return -1;
}
if (read_int16(fp,&ape_ctx->fileversion) < 0)
return -1;
if (ape_ctx->fileversion >= 3980)
{
if (read_int16(fp,&ape_ctx->padding1) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->descriptorlength) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->headerlength) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->seektablelength) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->wavheaderlength) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->audiodatalength) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->audiodatalength_high) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->wavtaillength) < 0)
return -1;
if (fread(&ape_ctx->md5,1, 16, fp) != 16)
return -1;
/* Skip any unknown bytes at the end of the descriptor. This is for future
compatibility */
if (ape_ctx->descriptorlength > 52)
fseek(fp, ape_ctx->descriptorlength - 52, SEEK_CUR);
/* Read header data */
if (read_uint16(fp,&ape_ctx->compressiontype) < 0)
return -1;
if (read_uint16(fp,&ape_ctx->formatflags) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->blocksperframe) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->finalframeblocks) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->totalframes) < 0)
return -1;
if (read_uint16(fp,&ape_ctx->bps) < 0)
return -1;
if (read_uint16(fp,&ape_ctx->channels) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->samplerate) < 0)
return -1;
} else {
ape_ctx->descriptorlength = 0;
ape_ctx->headerlength = 32;
if (read_uint16(fp,&ape_ctx->compressiontype) < 0)
return -1;
if (read_uint16(fp,&ape_ctx->formatflags) < 0)
return -1;
if (read_uint16(fp,&ape_ctx->channels) < 0)
return -1;
if (read_uint32(fp,&ape_ctx->samplerate) < 0)
return -1;
//.........这里部分代码省略.........
开发者ID:LuckJC, 项目名称:pro-mk, 代码行数:101, 代码来源:parser.c
示例15: main
int main ( int argc, char *argv[] )
{
stlink_t* sl;
unsigned int ra;
unsigned int rb;
unsigned int flen;
int ret;
if(argc<2)
{
printf(".bin file not specified\n");
return(1);
}
fp=fopen(argv[1],"rb");
if(fp==NULL)
{
printf("Error opening file [%s]\n",argv[1]);
return(1);
}
memset(pdata,0xFF,sizeof(pdata));
flen=fread(pdata,1,sizeof(pdata),fp);
flen+=3;
flen>>=2;
fclose(fp);
sl = stlink_open_usb(10);
if(sl==NULL)
{
printf("stlink_open_usb failed\n");
return(1);
}
printf("-- version\n");
stlink_version(sl);
printf("mode before doing anything: %d\n", stlink_current_mode(sl));
if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
printf("-- exit_dfu_mode\n");
stlink_exit_dfu_mode(sl);
}
printf("-- enter_swd_mode\n");
stlink_enter_swd_mode(sl);
printf("-- mode after entering swd mode: %d\n", stlink_current_mode(sl));
printf("-- chip id: %#x\n", sl->chip_id);
printf("-- core_id: %#x\n", sl->core_id);
cortex_m3_cpuid_t cpuid;
stlink_cpu_id(sl, &cpuid);
printf("cpuid:impl_id = %0#x, variant = %#x\n", cpuid.implementer_id, cpuid.variant);
printf("cpuid:part = %#x, rev = %#x\n", cpuid.part, cpuid.revision);
// printf("-- status\n");
//stlink_status(sl);
printf("-- reset\n");
stlink_reset(sl);
stlink_force_debug(sl);
// printf("-- status\n");
// stlink_status(sl);
#ifdef LOAD_RAM
printf("-- load\n");
for(ra=0;ra<flen;ra++)
{
write_uint32(sl->q_buf,pdata[ra]);
stlink_write_mem32(sl, 0x20000000+(ra<<2), 4);
}
for(ra=0;ra<8;ra++)
{
stlink_read_mem32(sl, 0x20000000+(ra<<2), 4);
rb=read_uint32(sl->q_buf,0);
printf("[0x%08X] 0x%08X 0x%08X\n",ra,rb,pdata[ra]);
}
printf("-- run\n");
stlink_write_reg(sl, 0x20020000, 13); /* pc register */
stlink_write_reg(sl, 0x20000000, 15); /* pc register */
stlink_run(sl);
ret =0;
#endif //LOAD_RAM
#ifdef LOAD_FLASH
ra=0;
rb=0;
ret=stlink_write_flash(sl,0x08000000,(unsigned char *)pdata,0x4000);
if(ret)
//.........这里部分代码省略.........
开发者ID:Qbicz, 项目名称:stm32f4d, 代码行数:101, 代码来源:stlink2.c
示例16: crf1mm_new
crf1mm_t* crf1mm_new(const char *filename)
{
FILE *fp = NULL;
uint8_t* p = NULL;
crf1mm_t *model = NULL;
header_t *header = NULL;
model = (crf1mm_t*)calloc(1, sizeof(crf1mm_t));
if (model == NULL) {
goto error_exit;
}
fp = fopen(filename, "rb");
if (fp == NULL) {
goto error_exit;
}
fseek(fp, 0, SEEK_END);
model->size = (uint32_t)ftell(fp);
fseek(fp, 0, SEEK_SET);
model->buffer = model->buffer_orig = (uint8_t*)malloc(model->size + 16);
while ((uint32_t)model->buffer % 16 != 0) {
++model->buffer;
}
fread(model->buffer, 1, model->size, fp);
fclose(fp);
/* Write the file header. */
header = (header_t*)calloc(1, sizeof(header_t));
p = model->buffer;
p += read_uint8_array(p, header->magic, sizeof(header->magic));
p += read_uint32(p, &header->size);
p += read_uint8_array(p, header->type, sizeof(header->type));
p += read_uint32(p, &header->version);
p += read_uint32(p, &header->num_features);
p += read_uint32(p, &header->num_labels);
p += read_uint32(p, &header->num_attrs);
p += read_uint32(p, &header->off_features);
p += read_uint32(p, &header->off_labels);
p += read_uint32(p, &header->off_attrs);
p += read_uint32(p, &header->off_labelrefs);
p += read_uint32(p, &header->off_attrrefs);
model->header = header;
model->labels = cqdb_reader(
model->buffer + header->off_labels,
model->size - header->off_labels
);
model->attrs = cqdb_reader(
model->buffer + header->off_attrs,
model->size - header->off_attrs
);
return model;
error_exit:
if (model != NULL) {
free(model);
}
if (fp != NULL) {
fclose(fp);
}
return NULL;
}
开发者ID:abhisheksingh12, 项目名称:773proj, 代码行数:68, 代码来源:crf1m_model.c
六六分期app的软件客服如何联系?不知道吗?加qq群【895510560】即可!标题:六六分期
阅读:19189| 2023-10-27
今天小编告诉大家如何处理win10系统火狐flash插件总是崩溃的问题,可能很多用户都不知
阅读:9988| 2022-11-06
今天小编告诉大家如何对win10系统删除桌面回收站图标进行设置,可能很多用户都不知道
阅读:8326| 2022-11-06
今天小编告诉大家如何对win10系统电脑设置节能降温的设置方法,想必大家都遇到过需要
阅读:8696| 2022-11-06
我们在使用xp系统的过程中,经常需要对xp系统无线网络安装向导设置进行设置,可能很多
阅读:8639| 2022-11-06
今天小编告诉大家如何处理win7系统玩cf老是与主机连接不稳定的问题,可能很多用户都不
阅读:9657| 2022-11-06
电脑对日常生活的重要性小编就不多说了,可是一旦碰到win7系统设置cf烟雾头的问题,很
阅读:8624| 2022-11-06
我们在日常使用电脑的时候,有的小伙伴们可能在打开应用的时候会遇见提示应用程序无法
阅读:7998| 2022-11-06
今天小编告诉大家如何对win7系统打开vcf文件进行设置,可能很多用户都不知道怎么对win
阅读:8656| 2022-11-06
今天小编告诉大家如何对win10系统s4开启USB调试模式进行设置,可能很多用户都不知道怎
阅读:7535| 2022-11-06
请发表评论