Ejemplo n.º 1
0
void matrix_scan_user(void) {
  //
  // Bit #            7     6     5     4     3     2     1     0
  // layer_state: [     |     |     | _xF | _xN | _xS | _xQ | _xW ]
  // usb_led      [     |     |     |kana |cmps |scrl |caps | num ]
  // PORTB:       [  NC |  10 |   9 |   8 |  14 |  16 |  15 |rxled]
  // PORTC:       [  NC |   5 |     |     |     |     |     |     ]
  // PORTD:       [   6 |  NC |txled|   4 | tx* | rx* | grn | p29 ]
  // PORTE:       [     |   7 |     |     |     |     |     |     ]
  // PORTF:       [  a0 |  a1 | red | blu |     |     |  NC |  NC ]
  //
  // PD0 is connected to the pairing switch and p29 on the wireless module.
  // PF0,PF1,PB7,PC7,PD6 are not broken out by the pro micro board. I don't understand why.
  // PB1-PB6,PD4,PD5,PD6,PF6,PF7 are not connected to the Mitosis receiver
  // board. Each may be connected to an LED by way of a resistor (4.7k to
  // match the others) for a total of 14 additional indicators.

  // A simple (but technically inaccurate) model of the momentary layer state:
  // Fn1 key makes _xS active; indicator = red
  // Fn2 key makes _xN active; indicator = blue
  // Both keys make _xF active; indicator = purple
  // Toggling QWERTY mode makes indicator include green, so (red/blue/purple becomes yellow/cyan/white)

  // negated because for ports 0=LED on.
  uint32_t portf_bits = ~(layer_state|layer_state<<1|(layer_state&0b100)<<3);
  setbits(PORTF, portf_bits, 0b00110000);
  setbits(PORTD, ~layer_state, 0b00000010);
}
Ejemplo n.º 2
0
void main(char args[]){

	//x = 1001101 (77)  y = 1000111  (71)
	//P = 5 N = 4
	//1[0011]01 in x
	//100[0111] in y
	//Want -> 1011101 (93)
	printf("%u\n", setbits(77, 5, 4, 71)); 
	
	//x = 10110 (22) y = 11111 (32)
	//P = 3 N = 1 
	//1[0]110  in x
	//1111[1] in y
	//Want -> 11110 (30)	
	printf("%u\n", setbits(22, 3, 1, 31));
	
	//x = 11 (3) y = 111100 (60)
	//P = 1 N = 2
	//[11] in x
	//1111[00] in y
	//Want -> 00 (0)
	printf("%u\n", setbits(3,1,2,60));
	
	//x = 1110 (14) y = 1101 (13)
	//P = 2 N = 2
	//1[11]0 in x
	//11[01] in y
	//Want -> 1010 (10)
	printf("%u\n", setbits(14,2,2,13));
}
Ejemplo n.º 3
0
void MemClrNoLog ( UINT32 addr,       //Memory Address
				   int total_byte,    //Number of Data to clear in Byte
				   UINT32 logaddr, 
				   int logbit                                        
				 )
{
	UINT32 result;
	int i,j=0;	

	for(i=0;i<total_byte;i=i+4)
	{
		set32(addr+(UINT32)i,0x0);
		result = read32(addr+(UINT32)i);
		if(result == 0x0)
		{ 
			j++; 
		}
		else
		{ 
			j=j; 
		}
	}
	if(j == total_byte/4)
	{
		setbits(logaddr, logbit, logbit, 1);
	}
	else
	{
		setbits(logaddr, logbit, logbit, 0);
	}

	return;
}
Ejemplo n.º 4
0
int main() {
  assert(setbits(0xff, 3, 4, 0xaa) == 0xfa);
  /* wrong input */
  assert(setbits(0xff, 0, 4, 0xaa) == 0xff);
  assert(setbits(0xff, 0, 1, 0xaa) == 0xfe);
  assert(setbits(0xff, 3, 0, 0xaa) == 0xff);
  return 0;
}
Ejemplo n.º 5
0
int main(int argc, char const* argv[])
{
  setbits(1, 0, 1, 1);
  setbits(1, 1, 2, 1);
  setbits(1, 2, 3, 1);
  setbits(1, 3, 4, 1);
  setbits(1, 4, 5, 1);
  return 0;
}
Ejemplo n.º 6
0
static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
{
	u16 tmp;
	int i = 0;

#if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
	do {
		r8a66597_write(r8a66597, SCKE, SYSCFG0);
		tmp = r8a66597_read(r8a66597, SYSCFG0);
		if (i++ > 1000) {
			printf("register access fail.\n");
			return -1;
		}
	} while ((tmp & SCKE) != SCKE);
	r8a66597_write(r8a66597, 0x04, 0x02);
#else
	do {
		r8a66597_write(r8a66597, USBE, SYSCFG0);
		tmp = r8a66597_read(r8a66597, SYSCFG0);
		if (i++ > 1000) {
			printf("register access fail.\n");
			return -1;
		}
	} while ((tmp & USBE) != USBE);
	r8a66597_bclr(r8a66597, USBE, SYSCFG0);
#if !defined(CONFIG_RZA_USB)
	r8a66597_mdfy(r8a66597, CONFIG_R8A66597_XTAL, XTAL, SYSCFG0);

	i = 0;
	r8a66597_bset(r8a66597, XCKE, SYSCFG0);
	do {
		udelay(1000);
		tmp = r8a66597_read(r8a66597, SYSCFG0);
		if (i++ > 500) {
			printf("register access fail.\n");
			return -1;
		}
	} while ((tmp & SCKE) != SCKE);
#else
	/*
	 * RZ/A Only:
	 * Bits XTAL(UCKSEL) and UPLLE in SYSCFG0 for USB0 controls both USB0
	 * and USB1, so we must always set the USB0 register
	 */
#if (CONFIG_R8A66597_XTAL == 1)
	setbits(le16, R8A66597_BASE0, XTAL);
#endif
	mdelay(1);
	setbits(le16, R8A66597_BASE0, UPLLE);
	mdelay(1);
	r8a66597_bset(r8a66597, SUSPM, SUSPMODE0);
#endif /* CONFIG_RZA_USB */
#endif	/* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */

	return 0;
}
Ejemplo n.º 7
0
Archivo: sms.c Proyecto: checko/sxx-ril
int encode_number(char *msg, char *no) {
	unsigned int i;
	int digit;
	
	setbits(msg, 0, 2, 0);
	setbits(msg, 2, 8, strlen(no));
	for(i=0;i<strlen(no);i++)
		setbits(msg,10+i*4, 4, encode_digit(no[i]));
	return (10+i*4+7)/8;
}
Ejemplo n.º 8
0
static int sh_sci_spi_probe(struct platform_device *dev)
{
	struct resource	*r;
	struct spi_master *master;
	struct sh_sci_spi *sp;
	int ret;

	master = spi_alloc_master(&dev->dev, sizeof(struct sh_sci_spi));
	if (master == NULL) {
		dev_err(&dev->dev, "failed to allocate spi master\n");
		ret = -ENOMEM;
		goto err0;
	}

	sp = spi_master_get_devdata(master);

	platform_set_drvdata(dev, sp);
	sp->info = dev->dev.platform_data;

	
	sp->bitbang.master = spi_master_get(master);
	sp->bitbang.master->bus_num = sp->info->bus_num;
	sp->bitbang.master->num_chipselect = sp->info->num_chipselect;
	sp->bitbang.chipselect = sh_sci_spi_chipselect;

	sp->bitbang.txrx_word[SPI_MODE_0] = sh_sci_spi_txrx_mode0;
	sp->bitbang.txrx_word[SPI_MODE_1] = sh_sci_spi_txrx_mode1;
	sp->bitbang.txrx_word[SPI_MODE_2] = sh_sci_spi_txrx_mode2;
	sp->bitbang.txrx_word[SPI_MODE_3] = sh_sci_spi_txrx_mode3;

	r = platform_get_resource(dev, IORESOURCE_MEM, 0);
	if (r == NULL) {
		ret = -ENOENT;
		goto err1;
	}
	sp->membase = ioremap(r->start, r->end - r->start + 1);
	if (!sp->membase) {
		ret = -ENXIO;
		goto err1;
	}
	sp->val = ioread8(SCSPTR(sp));
	setbits(sp, PIN_INIT, 1);

	ret = spi_bitbang_start(&sp->bitbang);
	if (!ret)
		return 0;

	setbits(sp, PIN_INIT, 0);
	iounmap(sp->membase);
 err1:
	spi_master_put(sp->bitbang.master);
 err0:
	return ret;
}
Ejemplo n.º 9
0
int main() {
  if (n % 2 == 0) {
    backtracking(setbits(n/2), 0, 0, 0, 0);
    std::cout << 2*count << " " << nodes << "\n";
  }
  else {
    backtracking(setbits(n/2), 0, 0, 0, 0);
    const count_t half = count; count = 0;
    backtracking(queen_t().set(n/2), 0, 0, 0, 0);
    std::cout << 2*half + count << " " << nodes << "\n";
  }
}
Ejemplo n.º 10
0
// initialize LCD after a short pause
//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
void LCD4Bit_mod::init() {
  // Configure pins as outputs
  setbits(CONTROL_DDR, CONTROL_EN | CONTROL_RS);
#ifdef USING_RW
  setbits(CONTROL_DDR, CONTROL_RW);
#endif
  setbits(DATA_DDR, DATA_PINS);

  delay(50);

  //The first 4 nibbles and timings are not in my DEM16217 SYH datasheet, but apparently are HD44780 standard...
  commandWriteNibble(0x03);
  delay(5);
  commandWriteNibble(0x03);
  delayMicroseconds(100);
  commandWriteNibble(0x03);
  delay(5);

  // needed by the LCDs controller
  //this being 2 sets up 4-bit mode.
  commandWriteNibble(0x02);
  commandWriteNibble(0x02);
  //todo: make configurable by the user of this library.
  //NFXX where
  //N = num lines (0=1 line or 1=2 lines).
  //F= format (number of dots (0=5x7 or 1=5x10)).
  //X=don't care

  uint8_t num_lines_ptn = g_num_lines - 1 << 3;
  uint8_t dot_format_ptn = 0x00;      //5x7 dots.  0x04 is 5x10

  commandWriteNibble(num_lines_ptn | dot_format_ptn);
  delayMicroseconds(60);

  //The rest of the init is not specific to 4-bit mode.
  //NOTE: we're writing full bytes now, not nibbles.

  // display control:
  // turn display on, cursor off, no blinking
  // 
  commandWrite(CMD_DISPLAY | CMD_DISPLAY_DISPLAY_ON/*0x0C*/);
  delayMicroseconds(60);

  //clear display
  commandWrite(CMD_CLEAR);
  delay(3);

  // entry mode set: 06
  // increment automatically, display shift, entire shift off

  commandWrite(0x06);
  delay(1);//TODO: remove unnecessary delays
}
Ejemplo n.º 11
0
Archivo: ex2-6.c Proyecto: imwally/knr
int main() {

    unsigned int x = 0x4a;   /* 01001010 (74) */
    unsigned int y = 0x3c;   /* 00111100 (60) */

    printf("x: %x\n", x);
    printf("y: %x\n", y);
    
    /* setbits(x, 4, 4, y):
     *
     * x = 0  1  0  0  1  0  1  0
     *     7  6  5  4  3  2  1  0
     *              ^--------^
     *
     * The 4 bits that begin at position 4 must be set to the
     * rightmost 4 bits of y.
     *
     * y = 0  0  1  1  1  1  0  0
     *                 ^--------^
     *
     * These 4 bits should replace the 4 in x.
     *
     * x = 0  1  0  1  1  0  0  0
     *              ^--------^
     *
     * In decimal this is 88.
     */

    printf("setbits(x, 4, 4, y) = %d\n", setbits(x, 4, 4, y));

}
//Note: it takes size and offset in units of byte
static inline int compute_ham_similarity_64(unsigned short* ref, unsigned short* circ_array, 
                                int size){
	
    const uint8_t*         	ref_c=(uint8_t*) ref;
    const uint8_t*         	circ_c=(uint8_t*) circ_array;
    register uint8x16_t     a,b;
    register uint8x16_t     c,d,temp;
    register uint16x8_t     acc;
    register uint           i=0,count=0;
	int 					j=0;
	int 					shift=size&0xF;
	for(i=0;i<=size-16; i+=16){
		j++;
		a=vld1q_u8(&ref_c[i]);
		b=vld1q_u8(&circ_c[i]);
		c=veorq_u8(a,b);
		acc=vaddq_u16(acc,vpaddlq_u8(vcntq_u8(c)));
	}	
	count=setbits(acc);
	a=vld1q_u8(&ref_c[i]);
	b=vld1q_u8(&circ_c[i]);
	c=veorq_u8(a,b);
	c=vcntq_u8(c);
	
	for(i=0;i<shift;i++){
		count=count+vgetq_lane_u8 (c,i);
	}
    return size*8-count;
}
Ejemplo n.º 13
0
/* encode type 1002: extended L1-only gps rtk observables --------------------*/
static int encode_type1002(rtcm_t *rtcm, int sync)
{
  int i, j;
  int code1, pr1, ppr1, lock1, amb, cnr1;

  /* encode header */
  i = encode_head(1002, rtcm, sync, rtcm->n);

  for (j = 0; j < rtcm->n; j++) {

    /* generate obs field data gps */
    gen_obs_gps(rtcm, &(rtcm->obs[j]), &code1, &pr1, &ppr1, &lock1, &amb,
                &cnr1);

    setbitu(rtcm->buff, i, 6, rtcm->obs[j].prn+1  ); i += 6;
    setbitu(rtcm->buff, i, 1, code1); i += 1;
    setbitu(rtcm->buff, i, 24, pr1  ); i += 24;
    setbits(rtcm->buff, i, 20, ppr1 ); i += 20;
    setbitu(rtcm->buff, i, 7, lock1); i += 7;
    setbitu(rtcm->buff, i, 8, amb  ); i += 8;
    setbitu(rtcm->buff, i, 8, cnr1 ); i += 8;
  }
  rtcm->nbit = i;
  return 1;
}
Ejemplo n.º 14
0
/** Encode an RTCMv3 message type 1002 (Extended L1-Only GPS RTK Observables)
 * Message type 1002 has length `64 + n_sat*74` bits. Returned message length
 * is rounded up to the nearest whole byte.
 *
 * \param buff A pointer to the RTCM data message buffer.
 * \param id Reference station ID (DF003).
 * \param t GPS time of epoch (DF004).
 * \param n_sat Number of GPS satellites included in the message (DF006).
 * \param nm Struct containing the observation.
 * \param sync Synchronous GNSS Flag (DF005).
 * \return The message length in bytes.
 */
u16 rtcm3_encode_1002(u8 *buff, u16 id, gps_time_t t, u8 n_sat,
                      navigation_measurement_t *nm, u8 sync)
{
  rtcm3_write_header(buff, 1002, id, t, sync, n_sat, 0, 0);

  u16 bit = 64; /* Start at end of header. */

  u32 pr;
  s32 ppr;
  u8 amb, lock, cnr;

  for (u8 i=0; i<n_sat; i++) {
    gen_obs_gps(&nm[i], &amb, &pr, &ppr, &lock, &cnr);

    setbitu(buff, bit, 6, nm[i].sid.sat); bit += 6;
    /* TODO: set GPS code indicator if we ever support P(Y) code measurements. */
    setbitu(buff, bit, 1,  0);    bit += 1;
    setbitu(buff, bit, 24, pr);   bit += 24;
    setbits(buff, bit, 20, ppr);  bit += 20;
    setbitu(buff, bit, 7,  lock); bit += 7;
    setbitu(buff, bit, 8,  amb);  bit += 8;
    setbitu(buff, bit, 8,  cnr);  bit += 8;
  }

  /* Round number of bits up to nearest whole byte. */
  return (bit + 7) / 8;
}
Ejemplo n.º 15
0
Archivo: 06.c Proyecto: Liquifier/K-R
int main()
{
	printf("%d", setbits(255, 4, 3, 254));
	
	return 0;

}
Ejemplo n.º 16
0
int main(int argc, char *argv[])
{
  int x,p,n,y;
	
  if (argc != 5){
    printf("usage: x p n y\n");
    return 1;
  }

  x = atoi(argv[1]);
  p = atoi(argv[2]);
  n = atoi(argv[3]);
  y = atoi(argv[4]);

  printf("setbits with arguments x=%d, p=%d, n=%d, y=%d\n",x,p,n,y);
  printf("x before:\n");
  printBinary(x);
  printf("y before:\n");
  printBinary(y);

  x = setbits(x,p,n,y);
  printf("After set bits:\n");
  printBinary(x);
  return 0;
}
Ejemplo n.º 17
0
Archivo: 2-6.c Proyecto: eudisd/k-r
int main(void){
    int x = 2, y = 3;
    printbits("x", x);
    printbits("y", y);

    printbits("z", setbits(x, 3, 3, y));
}
int main(){

	unsigned int a, b;
	char* p, *q, *r, *s;

	a = 0xFF;
	b = 0x00;
	p = getbitstr(a);
	q = getbitstr(~0);
	r = getbitstr(b);

	printf("the ~0 is: %d\n", ~0);
	printf("the bit string of ~0 is %s.\n", q);
	printf("the bit string of a is %s.\n", p);
	// test
	printf("the bit string of b is %s.\n", r); 
	s = getbitstr(setbits(a, 6, 3, b));	
	printf("after setbits(a, 6, 3, b), bit string of a is: %s.\n", s);

	free((char*)p);
	free((char*)q);
	free((char*)r);
	free((char*)s);	
	p = NULL;
	q = NULL;
	r = NULL;
	s = NULL;
	return 0;
}
/* exercise2-6 - Write a function setbits(x,p,n,y) that returns x with
 * the n bits that begin at position p set to the rightmost n bits of y,
 * leaving the other bits unchanged. 
 * 
 * exercise2-6.c - prompts the user for values, applies 
 * setbits(x,p,n,y), and the prints the result.  Will not return an
 * error if given non-decimal-number input. 
 * 
 * NOTE: This implementation begs a more elegant solution. */
int main()
{
	char numstring[MAXLINE];
	
	unsigned x, y;
	int p, n;
	
	//prompt user for x (number to transform)
	printf("enter a number to apply setbits(x, p, n, y) to: ");
	gets(numstring);
	x = (unsigned) atoi(numstring);
	
	//prompt user for p (position)
	printf("enter a number p corresponding to the position: ");
	gets(numstring);
	p = atoi(numstring);
	
	//prompt user for n (number of digits)
	printf("enter a number n corresponding to the number of digits: ");
	gets(numstring);
	n = atoi(numstring);
	
	//prompt user for y (transformant)
	printf("enter a number y to apply the righmost n bits from: ");
	gets(numstring);
	y = (unsigned) atoi(numstring);
	
	//print result
	printf("\nThe resulting transformation of x is: %u\n", setbits(x, p, n, y));
	
	return 0;
}
Ejemplo n.º 20
0
main(){
    int r= getbits(0xdddd,10,3);
    printf("%d\n",r);
    int r1= setbits(0xffff,10,8,0x4444);
    printf("%d  %d",r1,0xffff);

} 
Ejemplo n.º 21
0
int main(void)
{
	unsigned i;
	unsigned j;
	unsigned k;
	int p;
	int n;

	for(i = 0; i < 30000; i += 511)
	{
		for(j = 0; j < 1000; j += 37)
		{
			for(p = 0; p < 16; p++)
			{
				for(n = 1; n <= p + 1; n++)
				{
					k = setbits(i, p, n, j);
					printf("setbits(%u, %d, %d, %u) = %u\n", i, p, n, j, k);
				}
			}
		}
	}

	return 0;
}
main(){
  unsigned x= 15;
  unsigned y=10;
  int p=3;
  int n=2;

  printf("%d\n",setbits(x,p,n,y));
}
Ejemplo n.º 23
0
main()
{
	int i,x,p,y,n;
	printf("enter the values of x ,p ,y ,n\n");
	scanf("%d %d %d %d",&x,&p,&y,&n);
	i=setbits(x,p,y,n);
	printf("the result is %d\n",i);
}
Ejemplo n.º 24
0
int main() {

	int x, y, n, p;
	scanf("%d%d%d%d", &x, &p, &n, &y);
	int res = setbits(x, p, n, y);
	printf("%d\n", res);
	return 0;
}
Ejemplo n.º 25
0
main()
{
	unsigned x,y;
	int p,n;
	printf("enter the x,position,nbits,y");
	scanf("%u \t %d \t %d \t %u",&x ,&p,&n,&y);
	printf("resultand binary number is %u \n",setbits(x,p,n,y));
}
 int main()
	 
 {
 
    printf("%u\n", setbits(30, 2, 6, 100) );
    return 0;
    
 }
Ejemplo n.º 27
0
static void aout_addreloclist(struct list *rlst,unsigned long raddr,
                              unsigned long rindex,unsigned long rinfo,int be)
/* add new relocation_info to .text or .data reloc-list */
{
  struct RelocNode *rn = mymalloc(sizeof(struct RelocNode));

  setval(be,rn->r.r_address,4,raddr);
  setbits(be,rn->r.r_info,32,RELB_symbolnum,RELS_symbolnum,rindex);
  setbits(be,rn->r.r_info,32,RELB_reloc,RELS_reloc,rinfo);
  addtail(rlst,&rn->n);

  if (isPIC && !readbits(be,rn->r.r_info,32,RSTDB_pcrel,1)
      && !readbits(be,rn->r.r_info,32,RSTDB_baserel,1)) {
    /* the relocation is probably absolute, so it is no PIC anymore */
    isPIC = 0;
  }
}
Ejemplo n.º 28
0
main()
{
	unsigned x=255;
	unsigned y=13;
	x=setbits(x,4,4,y);
	printf("%d\n",x);

}
Ejemplo n.º 29
0
//pulse the Enable pin high (for a microsecond).
//This clocks whatever command or data is in DB4~7 into the LCD controller.
void LCD4Bit_mod::pulseEnablePin(){
  //clrbits(CONTROL_PORT, CONTROL_EN); //digitalWrite(Enable,LOW);
  //delayMicroseconds(1);
  // send a pulse to enable
  setbits(CONTROL_PORT, CONTROL_EN); //digitalWrite(Enable,HIGH);
  delayMicroseconds(1); // enable pulse must be >450ns
  clrbits(CONTROL_PORT, CONTROL_EN); //digitalWrite(Enable,LOW);
  //delayMicroseconds(40); // commands need > 37us to settle
}
Ejemplo n.º 30
0
  void init()
  {
    mColor = Color(0xFF,0xFF,0xFF);
    mLevel = 4;
    mCounter = 0;
    updatePrescalers();

    setbits(LED_DDR, LED_PINS); // output
  }