示例#1
0
文件: spi.c 项目: jFoster426/rpi3
unsigned int spi_transfer16(unsigned int data, unsigned char cs) {
	unsigned char l = data & 0xFF;
	unsigned char h = (data & 0xFF00) >> 8;
	put32(AUX_SPI0_CS, 0x000000B0 | cs);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 18)) {
			break;
		}
	}
	put8(AUX_SPI0_FIFO, h);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 16)) {
			break;
		}
	}
	h = get8(AUX_SPI0_FIFO);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 18)) {
			break;
		}
	}
	put8(AUX_SPI0_FIFO, l);
	while (1) {
		if (get32(AUX_SPI0_CS) & (1 << 16)) {
			break;
		}
	}
	l = get8(AUX_SPI0_FIFO);
	put32(AUX_SPI0_CS, 0x00000000 | cs);
	return (h << 8) | l;
}
/*
 * 0 - /dev/nul
 * 1 - binary
 * 2 - as assic 
*/
void dump(int size, int screen) {
  int i;
  if(screen == 0) {
    for(i=0; i<size; i++) {
      get8();
    }
  } else if(screen == 1) {
    for(i=0; i<size; i++) {
      if(i%16 == 0) {
	printf("%02x", get8());
      } else if(i%16 == 15) {
	printf(", %02x\n", get8());
      } else {
	printf(", %02x", get8());
      }
    }
    if(i%16 != 0) {
      printf("\n");
    }
  } else if(screen == 2) {
    for(i=0; i<size; i++) {
      printf("%c", get8());
    }
  }
}
示例#3
0
  void unpack(const uint8_t** pp, const uint8_t* pend) {
    const uint8_t* p = *pp;
    if(pend - p < 2)
      std::runtime_error("");

    service_type = get8(p);
    p += 1;
    size_t length = get8(p);
    p += 1;

    if(pend - p < length)
      std::runtime_error("");
    service_provider_name.assign(p, p+length);
    p += length;

    if(pend - p < 1)
      std::runtime_error("");
    length = get8(p);
    p += 1;

    if(pend - p < length)
      std::runtime_error("");
    service_name.assign(p, p+length);
    p += length;

    *pp = p;
  }
示例#4
0
static uint16_t get16be(struct buffer *input)
{
	uint16_t ret;
	ret = get8(input)<<8;
	ret |= get8(input);
	return ret;
}
示例#5
0
文件: mpegts.c 项目: Haaaaaank/avbin
static int parse_section_header(SectionHeader *h,
                                const uint8_t **pp, const uint8_t *p_end)
{
    int val;

    val = get8(pp, p_end);
    if (val < 0)
        return -1;
    h->tid = val;
    *pp += 2;
    val = get16(pp, p_end);
    if (val < 0)
        return -1;
    h->id = val;
    val = get8(pp, p_end);
    if (val < 0)
        return -1;
    h->version = (val >> 1) & 0x1f;
    val = get8(pp, p_end);
    if (val < 0)
        return -1;
    h->sec_num = val;
    val = get8(pp, p_end);
    if (val < 0)
        return -1;
    h->last_sec_num = val;
    return 0;
}
示例#6
0
CARD16 StreamCopyPaste::GetBuffer::get16() {
	if (transferRec.bytesWritten == transferRec.bytesRead) {
		logger.error("bytesWritten == bytesRead");
		ERROR();
	}
	CARD16 b1 = get8();
	CARD16 b2 = get8();
	return (b2 << 8) | (b1 << 0);
}
示例#7
0
int
get16(void)
{
	int i;
	
	i = get8();
	i |= get8() << 8;
	return i;
}
示例#8
0
文件: decode_ref.c 项目: caox/otp
int ei_decode_ref(const char *buf, int *index, erlang_ref *p)
{
  const char *s = buf + *index;
  const char *s0 = s;
  int count, i;
  
  switch (get8(s)) {
    case ERL_REFERENCE_EXT:

      /* nodename */
      if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1;
  
      /* now the numbers: num (4), creation (1) */
      if (p) {
	  p->n[0] = get32be(s);
	  p->len = 1;
	  p->creation = get8(s) & 0x03;
      }
      else s += 5;
  
      *index += s-s0;
  
      return 0;
      break;
      
    case ERL_NEW_REFERENCE_EXT:
      /* first the integer count */
      count = get16be(s);
      if (p) p->len = count;

      /* then the nodename */
      if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1;

      /* creation */
      if (p) {
	  p->creation = get8(s) & 0x03;
      }
      else s += 1;

      /* finally the id integers */
      if (p) {
	for (i = 0; (i<count) && (i<3); i++) {
	  p->n[i] = get32be(s);
	}
      }
      else s += 4 * count;
  
      *index += s-s0;
  
      return 0;
      break;
      
    default:
      return -1;
  }
}
void get_ether(struct EthernetHeader* ehead) {
  int i;
  for(i=0; i<6; i++) {
    ehead->dest[i] = get8();
  }
  for(i=0; i<6; i++) {
    ehead->src[i] = get8();
  }
  ehead->length_type = get16();
}
void get_tcp(struct TCPHeader* tcphead) {
  tcphead->src = get16();
  tcphead->dest = get16();
  tcphead->seqnum = get32();
  tcphead->acknum = get32();
  tcphead->byte0 = get8();
  tcphead->byte1 = get8();
  tcphead->winsize = get16();
  tcphead->checksum = get16();
  tcphead->urgpoint = get16();
}
示例#11
0
int
get32(void)
{
	int i;
	
	i = get8();
	i |= get8() << 8;
	i |= get8() << 16;
	i |= get8() << 24;
	return i;
}
示例#12
0
static int bmp_test(stbi *s)
{
   int sz;
   if (get8(s) != 'B') return 0;
   if (get8(s) != 'M') return 0;
   get32le(s); 
   get16le(s); 
   get16le(s); 
   get32le(s); 
   sz = get32le(s);
   if (sz == 12 || sz == 40 || sz == 56 || sz == 108) return 1;
   return 0;
}
示例#13
0
void es_eventState(sdl_data *sd, int len, char *bp) 
{
   Uint8 type, res;
   int sendlen, state;
   char *start;
    
   type  = get8(bp);
   state = get8(bp);

   res = SDL_EventState(type, state);
   bp = start = sdl_get_temp_buff(sd, 1);
   put8(bp, res);
   sendlen = bp - start;
   sdl_send(sd, sendlen);
}
示例#14
0
void describe4(uint8_t *p, size_t nbytes, const char *dev)
{
   char fromaddr[INET_ADDRSTRLEN];
   char toaddr[INET_ADDRSTRLEN];
   int headerlen = 4*(p[HLEN_OFFSET]&0x0f);
   int proto = p[PROTO_OFFSET];
   inet_ntop(AF_INET, p+SRC_OFFSET4, fromaddr, sizeof(fromaddr));
   inet_ntop(AF_INET, p+DST_OFFSET4, toaddr, sizeof(toaddr));
   uint8_t *phdr = p+headerlen;
   if (proto == PROTO_TCP) {
      // Should do this for IPv6 as well
      uint16_t srcport = ntohs(get16(phdr+0));
      uint16_t dstport = ntohs(get16(phdr+2));
      uint16_t flags = 0x0f & get8(phdr+13);
      char flagstring[16];
      snprintf(flagstring, sizeof(flagstring),
               "%s%s%s%s",
               (flags&1)?"F":"",
               (flags&2)?"S":"", 
               (flags&4)?"R":"",
               (flags&8)?"P":"");
      printf("dev=%s src=%s:%hu dst=%s:%hu len=%zu proto=%d flags=%s\n", 
             dev, fromaddr, srcport, toaddr, dstport, nbytes, proto, flagstring);
   } else if (proto == PROTO_UDP) {
      uint16_t srcport = ntohs(get16(phdr+0));
      uint16_t dstport = ntohs(get16(phdr+2));
      printf("proto=4 dev=%s src=%s:%hu dst=%s:%hu len=%zu proto=%d\n",
             dev, fromaddr, srcport, toaddr, dstport, nbytes, proto);
   } else {
      printf("proto=4 dev=%s src=%s dst=%s len=%zu proto=%d\n",
             dev, fromaddr, toaddr, nbytes, proto);
   }
}
示例#15
0
文件: main.c 项目: 8l/go-learn
int
sample(Map *map)
{
	int i;
	static int n;

	n++;
	if(registers) {
		for(i = 0; i < sizeof ureg; i+=8) {
			if(get8(map, (uvlong)i, &((uvlong*)&ureg)[i/8]) < 0)
				goto bad;
		}
	} else {
		// we need only two registers
		if(get8(map, offsetof(struct Ureg, ip), (uvlong*)&ureg.ip) < 0)
			goto bad;
		if(get8(map, offsetof(struct Ureg, sp), (uvlong*)&ureg.sp) < 0)
			goto bad;
	}
	return 1;
bad:
	if(n == 1)
		fprint(2, "prof: can't read registers: %r\n");
	return 0;
}
示例#16
0
/* c non-zero -> erlang "true" atom, otherwise "false" */
int ei_decode_boolean(const char *buf, int *index, int *p)
{
  const char *s = buf + *index;
  const char *s0 = s;
  int len;
  int t;

  if (get8(s) != ERL_ATOM_EXT) return -1;

  len = get16be(s);

  switch (len) {
  case 4:
    /* typecast makes ansi happy */
    if (strncmp((char*)s,"true",4)) return -1;
    t = 1;
    break;

  case 5:
    if (strncmp((char*)s,"false",5)) return -1;
    t = 0;
    break;
    
  default:
    return -1;
  }
  
  s += len;
  if (p) *p = t;
  *index += s-s0;

  return 0; 
}
示例#17
0
void es_pauseAudio(sdl_data *sd, int len, char *buff)
{
    char *bp;
    int pause;
    bp = buff;
    pause = get8(bp);
    SDL_PauseAudio(pause);
}
示例#18
0
void
main()
{
	U_LONG key[2], plain[2], cipher[2], answer[2];
	int i;
	int test;
	int fail;

	for(test=0;!feof(stdin);test++){
		get8(key);
		do_setkey(key);
		printf(" K: "); put8(key);

		get8(plain);
		printf(" P: "); put8(plain);

		get8(answer);
		printf(" C: "); put8(answer);


		for(i=0;i<2;i++)
			cipher[i] = plain[i];
		do_crypt(cipher, 0);

		for(i=0;i<2;i++)
			if(cipher[i] != answer[i])
				break;
		fail = 0;
		if(i != 2){
			printf(" Encrypt FAIL");
			fail++;
		}
		do_crypt(cipher, 1);
		for(i=0;i<2;i++)
			if(cipher[i] != plain[i])
				break;
		if(i != 2){
			printf(" Decrypt FAIL");
			fail++;
		}
		if(fail == 0)
			printf(" OK");
		printf("\n");
	}
}
示例#19
0
void es_openAudio(sdl_data *sd, int len, char *buff)
{
   int sendlen;
   char *bp, *start;
   int ff;
   SDL_AudioSpec desired, obtained, *obptr;
   bp = buff;
   ff = get8(bp);
   desired.freq     = get32be(bp);
   desired.format   = get16be(bp);
   desired.channels = get8(bp);
   desired.samples  = get16be(bp);
   desired.padding  = get16be(bp);
   desired.callback = myaudiomixer;

   /* Init the global data structures */
   wave.sound = NULL;
   wave.soundpos = 0;
   wave.soundlen = 0;

   if(ff == 1)  /* Force the requested format */
      obptr = NULL;
   else 
      obptr = &obtained;
   
   bp = start = sdl_getbuff(sd, 16);
   if( SDL_OpenAudio(&desired, obptr) < 0 ) {
      fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());		
   } else {
      if(ff == 1) 
	  obptr = &desired;
       put32be(bp, obptr->freq);
       put16be(bp, obptr->format);
       put8(bp, obptr->channels);
       put8(bp, obptr->silence);
       put16be(bp, obptr->samples);
       put16be(bp, obptr->padding);
       put32be(bp, obptr->size);
       wave.silence = obptr->silence;
   } 
  
   sendlen = (int) (bp - start);
   sdl_send(sd, sendlen);
}
示例#20
0
int ei_get_type_internal(const char *buf, const int *index,
			 int *type, int *len)
{
  const char *s = buf + *index;

  *type = get8(s);
  
  switch (*type) {
  case ERL_SMALL_TUPLE_EXT:
    *len = get8(s);
    break;
    
  case ERL_ATOM_EXT:
  case ERL_STRING_EXT:
    *len = get16be(s);
    break;

  case ERL_FLOAT_EXT:
  case NEW_FLOAT_EXT:
    *type = ERL_FLOAT_EXT;
    break;

  case ERL_LARGE_TUPLE_EXT:
  case ERL_LIST_EXT:
  case ERL_BINARY_EXT:
    *len = get32be(s);
    break;
    
  case ERL_SMALL_BIG_EXT:
    *len = get8(s); /* #digit_bytes */
    break;

  case ERL_LARGE_BIG_EXT:
    *len = get32be(s); /* #digit_bytes */
    break;

  default:
    *len = 0;
    break;
  }

  /* leave index unchanged */
  return 0;
}
示例#21
0
int ei_decode_intlist(const char *buf, int *index, long *a, int *count)
{
  const unsigned char *s = (const unsigned char *)(buf + *index);
  const unsigned char *s0 = s;
  int idx;
  int len;
  int i;

  switch (get8(s)) {
  case ERL_STRING_EXT:
    len = get16be(s);

    /* transfer and cast chars one at a time into array */
    if (a) {
      for (i=0; i<len; i++) {
	a[i] = (long)(s[i]);
      }
    }
    if (count) *count = len;
    s += len;
    break;

  case ERL_LIST_EXT:
    len = get32be(s);
    idx = 0;
    
    if (a) {
      for (i=0; i<len; i++) {
	if (ei_decode_long((char*)s,&idx,a+i) < 0) {
	  if (count) *count = i;
	  return -1;
	}
      }
    }
    else {
      for (i=0; i<len; i++) {
	if (ei_decode_long((char*)s,&idx,NULL) < 0) {
	  if (count) *count = i;
	  return -1;
	}
      }
    }

    if (count) *count = len;
    s += idx;
    break;

  default:
    return -1;
  }


  *index += s-s0; 

  return 0; 
}
示例#22
0
static int recv_challenge_reply (int fd, 
				 unsigned our_challenge,
				 char cookie[], 
				 unsigned *her_challenge,
				 unsigned ms)
{
    char dbuf[DEFBUF_SIZ];
    char *buf = dbuf;
    int is_static = 1;
    int buflen = DEFBUF_SIZ;
    int rlen;
    char *s;
    char tag;
    char her_digest[16], expected_digest[16];
    
    erl_errno = EIO;		/* Default */

    if ((rlen = read_2byte_package(fd, &buf, &buflen, &is_static, ms)) != 21) {
	EI_TRACE_ERR1("recv_challenge_reply",
		      "<- RECV_CHALLENGE_REPLY socket read failed (%d)",rlen);
	goto error;
    }
    
    s = buf;
    if ((tag = get8(s)) != 'r') {
	EI_TRACE_ERR2("recv_challenge_reply",
		      "<- RECV_CHALLENGE_REPLY incorrect tag, "
		      "expected 'r' got '%c' (%u)",tag,tag);
	goto error;
    }
    *her_challenge = get32be(s);
    memcpy(her_digest, s, 16);
    gen_digest(our_challenge, cookie, (unsigned char*)expected_digest);
    if (memcmp(her_digest, expected_digest, 16)) {
	EI_TRACE_ERR0("recv_challenge_reply",
		      "<- RECV_CHALLENGE_REPLY authorization failure");
	goto error;
    }
    if (!is_static)
	free(buf);

   
    if (ei_tracelevel >= 3) {
	char buffer[33];	
        EI_TRACE_CONN2("recv_challenge_reply",
		   "<- RECV_CHALLENGE_REPLY (ok) challenge = %u, digest = %s",
		   *her_challenge,hex(her_digest,buffer));
    }
    erl_errno = 0;
    return 0;
    
error:
    if (!is_static)
	free(buf);
    return -1;
}
示例#23
0
int ei_decode_port(const char *buf, int *index, erlang_port *p)
{
  const char *s = buf + *index;
  const char *s0 = s;
  
  if (get8(s) != ERL_PORT_EXT) return -1;

  /* first the nodename */
  if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1;
  
  /* now the numbers: num (4), creation (1) */
  if (p) {
    p->id = get32be(s) & 0x0fffffff /* 28 bits */;
    p->creation = get8(s) & 0x03;
  }
  else s += 5;
  
  *index += s-s0;
  
  return 0;
}
示例#24
0
void es_convertAudio(sdl_data *sd, int len, char *buff)
{
   char *bp, *start;
   void *mptr;
   Uint16 oformat, nformat;
   Uint8  ochannels, nchannels;
   int    ofreq, nfreq, osize, nsize;
   SDL_AudioCVT  wav_cvt;
   int sendlen;

   bp = buff;
   oformat = get16be(bp);
   ochannels = get8(bp);
   ofreq = get32be(bp);
   nformat = get16be(bp);
   nchannels = get8(bp);
   nfreq = get32be(bp);
   POPGLPTR(mptr, bp);
   osize = get32be(bp);

   bp = start = sdl_getbuff(sd, 12);
   
   /* Build AudioCVT */
   if(SDL_BuildAudioCVT(&wav_cvt,oformat, ochannels, ofreq,
			nformat, nchannels, nfreq) >= 0) {      
      /* Setup for conversion */
      nsize = osize*wav_cvt.len_mult;      
      wav_cvt.buf=(Uint8 *)malloc(nsize);
      if(wav_cvt.buf != NULL) {
	 wav_cvt.len=osize;
	 memcpy(wav_cvt.buf, mptr, osize);
	 if (SDL_ConvertAudio(&wav_cvt) >= 0) {
	   PUSHGLPTR(wav_cvt.buf, bp);
	   put32be(bp, nsize);	 	
	 }
      }
   }   
   sendlen = (int) (bp - start);
   sdl_send(sd, sendlen);
}
示例#25
0
BYTE CHD61102::cmd_read(qint16 cmd)
{


    BYTE value = get8((info.Xadr * 0x40) + (info.Yadr==0 ? 63 : info.Yadr - 1) );
    AddLog(LOG_TEMP,tr("HD61102 READ CMD : x=%1   Y=%2  v=%3").arg(info.Xadr).arg(info.Yadr).arg(value,2,16,QChar('0')));
    (info.Yadr)++;
    if (info.Yadr == 64) {
        info.Yadr=0;
    }

//    if (pPC->fp_log) fprintf(pPC->fp_log,"LCD Read:%02x\n",value);
    return value;
}
示例#26
0
void es_joystick_opened(sdl_data *sd, int len,char *buff)
{
   int sendlen;
   char *bp, *start;
   int index, bool;
   
   bp = buff;
   index = get8(bp);
   bp = start = sdl_get_temp_buff(sd, 1);
   bool = SDL_JoystickOpened(index);
   put8(bp, bool);
   sendlen = bp - start;
   sdl_send(sd, sendlen);
}
示例#27
0
void es_enableUNICODE(sdl_data *sd, int len,char *buff)
{
   int sendlen;
   char *bp, *start;
   Uint8 enable;

   bp = buff;
   enable = get8(bp);
   bp = start = sdl_get_temp_buff(sd, 1);
   enable = SDL_EnableUNICODE(enable);
   put8(bp, enable);
   sendlen = bp - start;
   sdl_send(sd, sendlen);
}
示例#28
0
void es_joystick_getAxis(sdl_data *sd, int len,char *buff)
{
   int sendlen;
   char *bp, *start;
   SDL_Joystick *joy;
   int state, axis;
   bp = buff;
   POPGLPTR(joy, bp);
   axis = get8(bp);
   bp = start = sdl_get_temp_buff(sd, 4);
   state = SDL_JoystickGetAxis(joy, axis);
   put32be(bp, state);
   sendlen = bp - start;
   sdl_send(sd, sendlen);
}
示例#29
0
void es_joystick_getButton(sdl_data *sd, int len,char *buff)
{
   int sendlen;
   char *bp, *start;
   SDL_Joystick *joy;
   int state;
   Uint8 button;
   bp = buff;
   POPGLPTR(joy, bp);
   button = get8(bp);
   bp = start = sdl_get_temp_buff(sd, 1);
   state = SDL_JoystickGetButton(joy, button);
   put8(bp,state);
   sendlen = bp - start;
   sdl_send(sd, sendlen);
}
示例#30
0
void es_joystick_open(sdl_data *sd, int len,char *buff)
{
   int sendlen;
   char *bp, *start;
   SDL_Joystick *joy;
   int index;
   
   bp = buff;
   index = get8(bp);
   bp = start = sdl_get_temp_buff(sd, 8);
   if((joy = SDL_JoystickOpen(index)) != NULL) {
      PUSHGLPTR(joy, bp);
   }
   sendlen = bp - start;
   sdl_send(sd, sendlen);
}