コード例 #1
0
ファイル: flash_pmc29f002.c プロジェクト: amuntner/rx5usb
void flash_eraseBlocks(unsigned long addr, unsigned long size)
{
	unsigned long i;
	
	if(addr==0 && size==131072)
	{
		size=8192;
	}
		
	for (i=0;i<size;i+=8192)
	{
		flash_command(0x80);
		
		SET_ADDR(0x555);
		SET_DATA(0xaa);
		flash_toggleWrite();

		SET_ADDR(0x2aa);
		SET_DATA(0x55);
		flash_toggleWrite();

		SET_ADDR(addr+i);
		SET_DATA(0x30);
		flash_toggleWrite();
	
		while(flash_getData()!=0xff);
	}
}
コード例 #2
0
ファイル: flash_pmc29f002.c プロジェクト: amuntner/rx5usb
static void flash_command(unsigned char cmd)
{
	SET_ADDR(0x555);
	SET_DATA(0xaa);
	flash_toggleWrite();

	SET_ADDR(0x2aa);
	SET_DATA(0x55);
	flash_toggleWrite();

	SET_ADDR(0x555);
	SET_DATA(cmd);
	flash_toggleWrite();
}
コード例 #3
0
ファイル: epmd_cli.c プロジェクト: 0x00evil/otp
static int conn_to_epmd(EpmdVars *g)
{
    struct EPMD_SOCKADDR_IN address;
    int connect_sock;
    
    connect_sock = socket(FAMILY, SOCK_STREAM, 0);
    if (connect_sock<0)
	goto error;

    { /* store port number in unsigned short */
      unsigned short sport = g->port;
      SET_ADDR(address, EPMD_ADDR_LOOPBACK, sport);
    }

    if (connect(connect_sock, (struct sockaddr*)&address, sizeof address) < 0) 
	goto error;
    return connect_sock;

 error:
    if (!g->silent) {
	fprintf(stderr, "epmd: Cannot connect to local epmd\n");
    }
    epmd_cleanup_exit(g,1);
    return -1;
}
コード例 #4
0
ファイル: pinctrl-mtk-common.c プロジェクト: coderkan/linux
static void mtk_pconf_set_ies_smt(struct mtk_pinctrl *pctl, unsigned pin,
                                  int value, enum pin_config_param param)
{
    unsigned int reg_addr, offset;
    unsigned int bit;
    int ret;

    /*
     * Due to some pins are irregular, their input enable and smt
     * control register are discontinuous, but they are mapping together.
     * So we need this special handle.
     */
    if (pctl->devdata->spec_ies_smt_set) {
        ret = pctl->devdata->spec_ies_smt_set(mtk_get_regmap(pctl, pin),
                                              pin, pctl->devdata->port_align, value);
        if (!ret)
            return;
    }

    bit = BIT(pin & 0xf);

    if (param == PIN_CONFIG_INPUT_ENABLE)
        offset = pctl->devdata->ies_offset;
    else
        offset = pctl->devdata->smt_offset;

    if (value)
        reg_addr = SET_ADDR(mtk_get_port(pctl, pin) + offset, pctl);
    else
        reg_addr = CLR_ADDR(mtk_get_port(pctl, pin) + offset, pctl);

    regmap_write(mtk_get_regmap(pctl, pin), reg_addr, bit);
}
コード例 #5
0
ファイル: pinctrl-mtk-common.c プロジェクト: coderkan/linux
static int mtk_pconf_set_pull_select(struct mtk_pinctrl *pctl,
                                     unsigned int pin, bool enable, bool isup, unsigned int arg)
{
    unsigned int bit;
    unsigned int reg_pullen, reg_pullsel;
    int ret;

    /* Some pins' pull setting are very different,
     * they have separate pull up/down bit, R0 and R1
     * resistor bit, so we need this special handle.
     */
    if (pctl->devdata->spec_pull_set) {
        ret = pctl->devdata->spec_pull_set(mtk_get_regmap(pctl, pin),
                                           pin, pctl->devdata->port_align, isup, arg);
        if (!ret)
            return 0;
    }

    /* For generic pull config, default arg value should be 0 or 1. */
    if (arg != 0 && arg != 1) {
        dev_err(pctl->dev, "invalid pull-up argument %d on pin %d .\n",
                arg, pin);
        return -EINVAL;
    }

    bit = BIT(pin & 0xf);
    if (enable)
        reg_pullen = SET_ADDR(mtk_get_port(pctl, pin) +
                              pctl->devdata->pullen_offset, pctl);
    else
        reg_pullen = CLR_ADDR(mtk_get_port(pctl, pin) +
                              pctl->devdata->pullen_offset, pctl);

    if (isup)
        reg_pullsel = SET_ADDR(mtk_get_port(pctl, pin) +
                               pctl->devdata->pullsel_offset, pctl);
    else
        reg_pullsel = CLR_ADDR(mtk_get_port(pctl, pin) +
                               pctl->devdata->pullsel_offset, pctl);

    regmap_write(mtk_get_regmap(pctl, pin), reg_pullen, bit);
    regmap_write(mtk_get_regmap(pctl, pin), reg_pullsel, bit);
    return 0;
}
コード例 #6
0
ファイル: flash_pmc29f002.c プロジェクト: amuntner/rx5usb
void flash_programByte(unsigned long addr, unsigned char byte)
{
	flash_command(0xa0);
	
	SET_ADDR(addr);
	SET_DATA(byte);
	flash_toggleWrite();

	while(flash_getData()!=byte);
}
コード例 #7
0
ファイル: flash_pmc29f002.c プロジェクト: amuntner/rx5usb
char flash_checkId(void)
{
	unsigned char mfg,dev;
	
	flash_command(0x90);
	
	SET_ADDR(0);
	
	mfg=flash_getData();
	print("mfg ");
	phex(mfg);
	print(" dev ");

	SET_ADDR(1);

	dev=flash_getData();
	phex(dev);
	print("\n");

	flash_command(0xf0);
	
	return (mfg==0x9d) && (dev==0x1d || dev==0x2d);
}
コード例 #8
0
ファイル: msxbus.c プロジェクト: meesokim/msxslot
 void msxwriteio(unsigned short  addr, unsigned char byte)
 {
	 GPIO_SET = MSX_CS | MSX_MIO;
	 GPIO_CLR = MSX_MA0 | MSX_MODE;
	 SET_ADDR(addr);
	 GPIO_SET = MSX_RW;
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_CS;
	 SET_DATA(byte);	 
	 GPIO_SET = MSX_MA0;
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_CS | MSX_MODE;
	 return;
 }
コード例 #9
0
ファイル: msxbus.c プロジェクト: meesokim/msxslot
 int msxreadio(unsigned short  addr)
 {
	 unsigned char byte;
	 GPIO_SET = MSX_CS | MSX_RESET | MSX_MIO;
	 GPIO_CLR = MSX_MA0 | MSX_MODE | MSX_M1;
	 SET_ADDR(addr);
	 GPIO_CLR = MSX_RW;
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_MA0;
	 setDataIn();	 
	 while(!GET_GPIO(MREADY_PIN));
	 GET_DATA(byte);	 
	 GPIO_SET = MSX_CS | MSX_MODE;
	 return byte;	 
 }
コード例 #10
0
ファイル: pinctrl-mtk-common.c プロジェクト: coderkan/linux
static void mtk_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{
    unsigned int reg_addr;
    unsigned int bit;
    struct mtk_pinctrl *pctl = dev_get_drvdata(chip->dev);

    reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dout_offset;
    bit = BIT(offset & 0xf);

    if (value)
        reg_addr = SET_ADDR(reg_addr, pctl);
    else
        reg_addr = CLR_ADDR(reg_addr, pctl);

    regmap_write(mtk_get_regmap(pctl, offset), reg_addr, bit);
}
コード例 #11
0
ファイル: msxbus.c プロジェクト: meesokim/msxslot
int msxread(int slot, unsigned short addr)
 {
	 unsigned char byte, b1;
	 int i;
	 GPIO_CLR = MSX_MA0 | MSX_MODE;
	 GPIO_SET = MSX_CS | MSX_RESET | MSX_M1 | (slot !=2 ? MSX_SLTSL : 0);
	 SET_ADDR(addr);
	 GPIO_CLR = MSX_RW | MSX_MIO | (slot == 2 ? MSX_SLTSL : 0);
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_MA0;
	 setDataIn();
//	 while(!GET_GPIO(MREADY_PIN));
	 GET_DATA(byte);
	 GPIO_SET = MSX_CS | MSX_MODE;
	 return byte;	 
 }
コード例 #12
0
ファイル: msxbus.c プロジェクト: meesokim/msxslot
 void msxwrite(int slot, unsigned short  addr, unsigned char byte)
 {
	 int i = 0;
	 GPIO_CLR = MSX_MA0 | MSX_MODE;
	 GPIO_SET = MSX_CS | MSX_RESET | MSX_M1 | (slot != 2 ? MSX_SLTSL : 0);
	 SET_ADDR(addr);
	 GPIO_SET = MSX_RW;
	 GPIO_CLR = MSX_CS | MSX_MIO | (slot == 2 ? MSX_SLTSL : 0);
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_CS;
	 SET_DATA(byte);	
	 GPIO_SET = MSX_MA0;
	 GPIO_CLR = MSX_CS;
	 while(!GET_GPIO(MREADY_PIN));
	 GPIO_SET = MSX_CS | MSX_MODE;
	 return;
 }
コード例 #13
0
ファイル: pinctrl-mtk-common.c プロジェクト: infidel/linux
static int mtk_pconf_set_ies_smt(struct mtk_pinctrl *pctl, unsigned pin,
		int value, enum pin_config_param arg)
{
	unsigned int reg_addr, offset;
	unsigned int bit;

	/**
	 * Due to some soc are not support ies/smt config, add this special
	 * control to handle it.
	 */
	if (!pctl->devdata->spec_ies_smt_set &&
		pctl->devdata->ies_offset == MTK_PINCTRL_NOT_SUPPORT &&
			arg == PIN_CONFIG_INPUT_ENABLE)
		return -EINVAL;

	if (!pctl->devdata->spec_ies_smt_set &&
		pctl->devdata->smt_offset == MTK_PINCTRL_NOT_SUPPORT &&
			arg == PIN_CONFIG_INPUT_SCHMITT_ENABLE)
		return -EINVAL;

	/*
	 * Due to some pins are irregular, their input enable and smt
	 * control register are discontinuous, so we need this special handle.
	 */
	if (pctl->devdata->spec_ies_smt_set) {
		return pctl->devdata->spec_ies_smt_set(mtk_get_regmap(pctl, pin),
			pin, pctl->devdata->port_align, value, arg);
	}

	bit = BIT(pin & 0xf);

	if (arg == PIN_CONFIG_INPUT_ENABLE)
		offset = pctl->devdata->ies_offset;
	else
		offset = pctl->devdata->smt_offset;

	if (value)
		reg_addr = SET_ADDR(mtk_get_port(pctl, pin) + offset, pctl);
	else
		reg_addr = CLR_ADDR(mtk_get_port(pctl, pin) + offset, pctl);

	regmap_write(mtk_get_regmap(pctl, pin), reg_addr, bit);
	return 0;
}
コード例 #14
0
ファイル: pinctrl-mtk-common.c プロジェクト: coderkan/linux
static int mtk_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
                                      struct pinctrl_gpio_range *range, unsigned offset,
                                      bool input)
{
    unsigned int reg_addr;
    unsigned int bit;
    struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);

    reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset;
    bit = BIT(offset & 0xf);

    if (input)
        /* Different SoC has different alignment offset. */
        reg_addr = CLR_ADDR(reg_addr, pctl);
    else
        reg_addr = SET_ADDR(reg_addr, pctl);

    regmap_write(mtk_get_regmap(pctl, offset), reg_addr, bit);
    return 0;
}
コード例 #15
0
ファイル: rom16.c プロジェクト: Ced2911/picflashrom
uint8_t rom_read_16(uint8_t * out, uint32_t addr, uint8_t _len) {
    uint8_t p = 0;
    uint8_t * buf = out;
    
    WE_H;
    TRISA = 0x00;

    for (p = 0; p < 0x20; p++, addr++) {
        SET_ADDR(addr);
        // Read data
        CSL;
        TRISA = 0xFF;
        TRISD = 0xFF;
        *buf++ = PORTD;
        *buf++ = PORTA;
        CSH;
    }
    
    return ROM_OK;
}
コード例 #16
0
ファイル: rom16.c プロジェクト: Ced2911/picflashrom
uint8_t rom_identify_16(uint8_t * in) {    
    // Start write
    TRISA = 0x00;
    TRISD = 0x00;

    // Send command
    write_16_cmd(0x5555, 0xAA);
    write_16_cmd(0xAAAA, 0x55);
    write_16_cmd(0x5555, 0x90);

    SET_ADDR(0);
        
    // Start read
    TRISA = 0xFF;
    TRISD = 0xFF;

    // Read id
    GEN_READ16(0, in[0], in[1]);
    GEN_READ16(1, in[2], in[3]);
    GEN_READ16(2, in[4], in[5]);
    GEN_READ16(3, in[6], in[7]);
 
    return ROM_OK;
}
コード例 #17
0
ファイル: epmd_srv.c プロジェクト: RJ/otp
void run(EpmdVars *g)
{
  struct EPMD_SOCKADDR_IN iserv_addr[MAX_LISTEN_SOCKETS];
  int listensock[MAX_LISTEN_SOCKETS];
  int num_sockets;
  int i;
  int opt;
  unsigned short sport = g->port;

  node_init(g);
  g->conn = conn_init(g);

#ifdef HAVE_SYSTEMD_DAEMON
  if (g->is_systemd)
    {
      int n;
      
      dbg_printf(g,2,"try to obtain sockets from systemd");

      n = sd_listen_fds(0);
      if (n < 0)
        {
          dbg_perror(g,"cannot obtain sockets from systemd");
          epmd_cleanup_exit(g,1);
        }
      else if (n == 0)
        {
          dbg_tty_printf(g,0,"systemd provides no sockets");
          epmd_cleanup_exit(g,1);
      }
      else if (n > MAX_LISTEN_SOCKETS)
      {
          dbg_tty_printf(g,0,"cannot listen on more than %d IP addresses", MAX_LISTEN_SOCKETS);
          epmd_cleanup_exit(g,1);
      } 
      num_sockets = n;
      for (i = 0; i < num_sockets; i++)
        {
          g->listenfd[i] = listensock[i] = SD_LISTEN_FDS_START + i;
        }
    }
  else
    {
#endif /* HAVE_SYSTEMD_DAEMON */

  dbg_printf(g,2,"try to initiate listening port %d", g->port);

  if (g->addresses != NULL && /* String contains non-separator characters if: */
      g->addresses[strspn(g->addresses," ,")] != '\000')
    {
      char *tmp;
      char *token;
      int loopback_ok = 0;

      if ((tmp = (char *)malloc(strlen(g->addresses) + 1)) == NULL)
	{
	  dbg_perror(g,"cannot allocate memory");
	  epmd_cleanup_exit(g,1);
	}
      strcpy(tmp,g->addresses);

      for(token = strtok(tmp,", "), num_sockets = 0;
	  token != NULL;
	  token = strtok(NULL,", "), num_sockets++)
	{
	  struct EPMD_IN_ADDR addr;
#ifdef HAVE_INET_PTON
	  int ret;

	  if ((ret = inet_pton(FAMILY,token,&addr)) == -1)
	    {
	      dbg_perror(g,"cannot convert IP address to network format");
	      epmd_cleanup_exit(g,1);
	    }
	  else if (ret == 0)
#elif !defined(EPMD6)
	  if ((addr.EPMD_S_ADDR = inet_addr(token)) == INADDR_NONE)
#endif
	    {
	      dbg_tty_printf(g,0,"cannot parse IP address \"%s\"",token);
	      epmd_cleanup_exit(g,1);
	    }

	  if (IS_ADDR_LOOPBACK(addr))
	    loopback_ok = 1;

	  if (num_sockets - loopback_ok == MAX_LISTEN_SOCKETS - 1)
	    {
	      dbg_tty_printf(g,0,"cannot listen on more than %d IP addresses",
			     MAX_LISTEN_SOCKETS);
	      epmd_cleanup_exit(g,1);
	    }

	  SET_ADDR(iserv_addr[num_sockets],addr.EPMD_S_ADDR,sport);
	}

      free(tmp);

      if (!loopback_ok)
	{
	  SET_ADDR(iserv_addr[num_sockets],EPMD_ADDR_LOOPBACK,sport);
	  num_sockets++;
	}
    }
  else
    {
      SET_ADDR(iserv_addr[0],EPMD_ADDR_ANY,sport);
      num_sockets = 1;
    }
#ifdef HAVE_SYSTEMD_DAEMON
    }
#endif /* HAVE_SYSTEMD_DAEMON */

#if !defined(__WIN32__)
  /* We ignore the SIGPIPE signal that is raised when we call write
     twice on a socket closed by the other end. */
  signal(SIGPIPE, SIG_IGN);
#endif

  /*
   * Initialize number of active file descriptors.
   * Stdin, stdout, and stderr are still open.
   */
  g->active_conn = 3 + num_sockets;
  g->max_conn -= num_sockets;

  FD_ZERO(&g->orig_read_mask);
  g->select_fd_top = 0;

#ifdef HAVE_SYSTEMD_DAEMON
  if (g->is_systemd)
      for (i = 0; i < num_sockets; i++)
          select_fd_set(g, listensock[i]);
  else
    {
#endif /* HAVE_SYSTEMD_DAEMON */
  for (i = 0; i < num_sockets; i++)
    {
      if ((listensock[i] = socket(FAMILY,SOCK_STREAM,0)) < 0)
	{
	  dbg_perror(g,"error opening stream socket");
	  epmd_cleanup_exit(g,1);
	}
      g->listenfd[i] = listensock[i];
  
      /*
       * Note that we must not enable the SO_REUSEADDR on Windows,
       * because addresses will be reused even if they are still in use.
       */
  
#if !defined(__WIN32__)
      opt = 1;
      if (setsockopt(listensock[i],SOL_SOCKET,SO_REUSEADDR,(char* ) &opt,
		     sizeof(opt)) <0)
	{
	  dbg_perror(g,"can't set sockopt");
	  epmd_cleanup_exit(g,1);
	}
#endif
  
      /* In rare cases select returns because there is someone
	 to accept but the request is withdrawn before the
	 accept function is called. We set the listen socket
	 to be non blocking to prevent us from being hanging
	 in accept() waiting for the next request. */
#if (defined(__WIN32__) || defined(NO_FCNTL))
      opt = 1;
      /* Gives warning in VxWorks */
      if (ioctl(listensock[i], FIONBIO, &opt) != 0)
#else
      opt = fcntl(listensock[i], F_GETFL, 0);
      if (fcntl(listensock[i], F_SETFL, opt | O_NONBLOCK) == -1)
#endif /* __WIN32__ || VXWORKS */
	dbg_perror(g,"failed to set non-blocking mode of listening socket %d",
		   listensock[i]);

      if (bind(listensock[i], (struct sockaddr*) &iserv_addr[i],
	  sizeof(iserv_addr[i])) < 0)
	{
	  if (errno == EADDRINUSE)
	    {
	      dbg_tty_printf(g,1,"there is already a epmd running at port %d",
			     g->port);
	      epmd_cleanup_exit(g,0);
	    }
	  else
	    {
	      dbg_perror(g,"failed to bind socket");
	      epmd_cleanup_exit(g,1);
	    }
	}

      if(listen(listensock[i], SOMAXCONN) < 0) {
          dbg_perror(g,"failed to listen on socket");
          epmd_cleanup_exit(g,1);
      }
      select_fd_set(g, listensock[i]);
    }
#ifdef HAVE_SYSTEMD_DAEMON
    }
    sd_notifyf(0, "READY=1\n"
                  "STATUS=Processing port mapping requests...\n"
                  "MAINPID=%lu", (unsigned long) getpid());
#endif /* HAVE_SYSTEMD_DAEMON */

  dbg_tty_printf(g,2,"entering the main select() loop");

 select_again:
  while(1)
    {
      fd_set read_mask = g->orig_read_mask;
      struct timeval timeout;
      int ret;

      /* If we are idle we time out now and then to enable the code
	 below to close connections that are old and probably
	 hanging. Make sure that select will return often enough. */

      timeout.tv_sec = (g->packet_timeout < IDLE_TIMEOUT) ? 1 : IDLE_TIMEOUT;
      timeout.tv_usec = 0;

      if ((ret = select(g->select_fd_top,
			&read_mask, (fd_set *)0,(fd_set *)0,&timeout)) < 0) {
	dbg_perror(g,"error in select ");
        switch (errno) {
          case EAGAIN:
          case EINTR:
            break;
          default:
            epmd_cleanup_exit(g,1);
        }
      }
      else {
	time_t now;
	if (ret == 0) {
	  FD_ZERO(&read_mask);
	}
	if (g->delay_accept) {		/* Test of busy server */
	  sleep(g->delay_accept);
	}

	for (i = 0; i < num_sockets; i++)
	  if (FD_ISSET(listensock[i],&read_mask)) {
	    if (do_accept(g, listensock[i]) && g->active_conn < g->max_conn) {
	      /*
	       * The accept() succeeded, and we have at least one file
	       * descriptor still free, which means that another accept()
	       * could succeed. Go do do another select(), in case there
	       * are more incoming connections waiting to be accepted.
	       */
	      goto select_again;
	    }
	  }
	  
	/* Check all open streams marked by select for data or a
	   close.  We also close all open sockets except ALIVE
	   with no activity for a long period */

	now = current_time(g);
	for (i = 0; i < g->max_conn; i++) {
	  if (g->conn[i].open == EPMD_TRUE) {
	    if (FD_ISSET(g->conn[i].fd,&read_mask))
	      do_read(g,&g->conn[i]);
	    else if ((g->conn[i].keep == EPMD_FALSE) &&
		     ((g->conn[i].mod_time + g->packet_timeout) < now)) {
	      dbg_tty_printf(g,1,"closing because timed out on receive");
	      epmd_conn_close(g,&g->conn[i]);
	    }
	  }
	}
      }
    }
}
コード例 #18
0
ファイル: flash_pmc29f002.c プロジェクト: amuntner/rx5usb
unsigned char flash_getByte(unsigned long addr)
{
	SET_ADDR(addr);
	return flash_getData();
}