static int dvfs_open(FAR struct file *filep, FAR const char *relpath,
                    int oflags, mode_t mode)
{
  FAR struct dvfs_file_s *priv;

  finfo("Open '%s'\n", relpath);

  /* "dvfs" is the only acceptable value for the relpath */

  if (strcmp(relpath, "dvfs") != 0)
    {
      ferr("ERROR: relpath is '%s'\n", relpath);
      return -ENOENT;
    }

  /* Allocate a container to hold the task and attribute selection */

  priv = (FAR struct dvfs_file_s *)kmm_zalloc(sizeof(struct dvfs_file_s));
  if (!priv)
    {
      ferr("ERROR: Failed to allocate file attributes\n");
      return -ENOMEM;
    }

  /* Save the index as the open-specific state in filep->f_priv */

  filep->f_priv = (FAR void *)priv;
  return OK;
}
int sig_notification(pid_t pid, FAR struct sigevent *event)
{
  FAR struct sig_notify_s *notify;
  DEBUGASSERT(event != NULL && event->sigev_notify_function != NULL);
  int ret;

  /* Allocate a structure to hold the notification information */

  notify = kmm_zalloc(sizeof(struct sig_notify_s));
  if (notify == NULL)
    {
      return -ENOMEM;
    }

  /* Initialize the notification information */

#ifdef CONFIG_CAN_PASS_STRUCTS
  notify->nt_value = event->sigev_value;
#else
  notify->nt_value.sival_ptr = event->sigev_value.sival_ptr;
#endif
  notify->nt_func = event->sigev_notify_function;

  /* Then queue the work */

  ret = work_queue(NTWORK, &notify->nt_work, sig_ntworker, notify, 0);
  if (ret < 0)
    {
      kmm_free(notify);
    }

  return ret;
}
Exemple #3
0
static int skel_opendir(FAR const char *relpath, FAR struct fs_dirent_s *dir)
{
  FAR struct skel_level1_s *level1;

  fvdbg("relpath: \"%s\"\n", relpath ? relpath : "NULL");
  DEBUGASSERT(relpath && dir && !dir->u.procfs);

  /* The path refers to the 1st level sbdirectory.  Allocate the level1
   * dirent structure.
   */

  level1 = (FAR struct skel_level1_s *)
     kmm_zalloc(sizeof(struct skel_level1_s));

  if (!level1)
    {
      fdbg("ERROR: Failed to allocate the level1 directory structure\n");
      return -ENOMEM;
    }

  /* TODO:  Initialze context specific data */


  /* Initialze base structure components */

  level1->base.level    = 1;
  level1->base.nentries = 0;
  level1->base.index    = 0;

  dir->u.procfs = (FAR void *) level1;
  return OK;
}
Exemple #4
0
static int djoy_open(FAR struct file *filep)
{
  FAR struct inode *inode;
  FAR struct djoy_upperhalf_s *priv;
  FAR const struct djoy_lowerhalf_s *lower;
  FAR struct djoy_open_s *opriv;
#ifndef CONFIG_DISABLE_POLL
  djoy_buttonset_t supported;
#endif
  int ret;

  DEBUGASSERT(filep && filep->f_inode);
  inode = filep->f_inode;
  DEBUGASSERT(inode->i_private);
  priv = (FAR struct djoy_upperhalf_s *)inode->i_private;

  /* Get exclusive access to the driver structure */

  ret = djoy_takesem(&priv->du_exclsem);
  if (ret < 0)
    {
      ierr("ERROR: djoy_takesem failed: %d\n", ret);
      return ret;
    }

  /* Allocate a new open structure */

  opriv = (FAR struct djoy_open_s *)kmm_zalloc(sizeof(struct djoy_open_s));
  if (!opriv)
    {
      ierr("ERROR: Failled to allocate open structure\n");
      ret = -ENOMEM;
      goto errout_with_sem;
    }

  /* Initialize the open structure */

#ifndef CONFIG_DISABLE_POLL
  lower = priv->du_lower;
  DEBUGASSERT(lower && lower->dl_supported);
  supported = lower->dl_supported(lower);

  opriv->do_pollevents.dp_press   = supported;
  opriv->do_pollevents.dp_release = supported;
#endif

  /* Attach the open structure to the device */

  opriv->do_flink = priv->du_open;
  priv->du_open = opriv;

  /* Attach the open structure to the file structure */

  filep->f_priv = (FAR void *)opriv;
  ret = OK;

errout_with_sem:
  djoy_givesem(&priv->du_exclsem);
  return ret;
}
Exemple #5
0
int ramlog_register(FAR const char *devpath, FAR char *buffer, size_t buflen)
{
  FAR struct ramlog_dev_s *priv;
  int ret = -ENOMEM;

  /* Sanity checking */

  DEBUGASSERT(devpath && buffer && buflen > 1);

  /* Allocate a RAM logging device structure */

  priv = (struct ramlog_dev_s *)kmm_zalloc(sizeof(struct ramlog_dev_s));
  if (priv)
    {
      /* Initialize the non-zero values in the RAM logging device structure */

      sem_init(&priv->rl_exclsem, 0, 1);
#ifndef CONFIG_RAMLOG_NONBLOCKING
      sem_init(&priv->rl_waitsem, 0, 0);
#endif
      priv->rl_bufsize = buflen;
      priv->rl_buffer  = buffer;

      /* Register the character driver */

      ret = register_driver(devpath, &g_ramlogfops, 0666, priv);
      if (ret < 0)
        {
          kmm_free(priv);
        }
    }

  return ret;
}
Exemple #6
0
int svc_send_event(enum svc_event event, void *parameter0, void *parameter1, void *parameter2) {
    llvdbg("event: %s (%d), %p %p %p\n",
         svc_event_to_string(event), event,
         parameter0,
         parameter1,
         parameter2);

    struct svc_work *svc_work = (struct svc_work *)kmm_zalloc(sizeof(*svc_work));
    if (!svc_work) {
        lldbg("ERROR: failed to alloc work: errno=%d\n", get_errno());
        return -1;
    }

    svc_work->svc = &g_svc;
    svc_work->event = event;
    svc_work->parameter0 = parameter0;
    svc_work->parameter1 = parameter1;
    svc_work->parameter2 = parameter2;

    int ret = work_queue(HPWORK, &svc_work->work, svc_work_callback, svc_work, 0 /* delay */);
    if (ret) {
        lldbg("ERROR: failed to queue work: errno=%d\n", get_errno());
        return ret;
    }

    return ret;
}
Exemple #7
0
static int ccm_dup(FAR const struct file *oldp, FAR struct file *newp)
{
  FAR struct ccm_file_s *oldpriv;
  FAR struct ccm_file_s *newpriv;

  fvdbg("Dup %p->%p\n", oldp, newp);

  /* Recover our private data from the old struct file instance */

  oldpriv = (FAR struct ccm_file_s *)oldp->f_priv;
  DEBUGASSERT(oldpriv);

  /* Allocate a new container to hold the task and attribute selection */

  newpriv = (FAR struct ccm_file_s *)kmm_zalloc(sizeof(struct ccm_file_s));
  if (!newpriv)
    {
      fdbg("ERROR: Failed to allocate file attributes\n");
      return -ENOMEM;
    }

  /* The copy the file attributes from the old attributes to the new */

  memcpy(newpriv, oldpriv, sizeof(struct ccm_file_s));

  /* Save the new attributes in the new file structure */

  newp->f_priv = (FAR void *)newpriv;
  return OK;
}
Exemple #8
0
int pwm_register(FAR const char *path, FAR struct pwm_lowerhalf_s *dev)
{
  FAR struct pwm_upperhalf_s *upper;

  /* Allocate the upper-half data structure */

  upper = (FAR struct pwm_upperhalf_s *)kmm_zalloc(sizeof(struct pwm_upperhalf_s));
  if (!upper)
    {
      pwmdbg("Allocation failed\n");
      return -ENOMEM;
    }

  /* Initialize the PWM device structure (it was already zeroed by kmm_zalloc()) */

  sem_init(&upper->exclsem, 0, 1);
#ifdef CONFIG_PWM_PULSECOUNT
  sem_init(&upper->waitsem, 0, 0);
#endif
  upper->dev = dev;

  /* Register the PWM device */

  pwmvdbg("Registering %s\n", path);
  return register_driver(path, &g_pwmops, 0666, upper);
}
Exemple #9
0
int pwm_register(FAR const char *path, FAR struct pwm_lowerhalf_s *dev)
{
  FAR struct pwm_upperhalf_s *upper;

  /* Allocate the upper-half data structure */

  upper = (FAR struct pwm_upperhalf_s *)kmm_zalloc(sizeof(struct pwm_upperhalf_s));
  if (!upper)
    {
      pwmerr("Allocation failed\n");
      return -ENOMEM;
    }

  /* Initialize the PWM device structure (it was already zeroed by kmm_zalloc()) */

  sem_init(&upper->exclsem, 0, 1);
#ifdef CONFIG_PWM_PULSECOUNT
  sem_init(&upper->waitsem, 0, 0);

  /* The wait semaphore is used for signaling and, hence, should not have priority
   * inheritance enabled.
   */

  sem_setprotocol(&upper->waitsem, SEM_PRIO_NONE);
#endif

  upper->dev = dev;

  /* Register the PWM device */

  pwminfo("Registering %s\n", path);
  return register_driver(path, &g_pwmops, 0666, upper);
}
Exemple #10
0
static int skel_open(FAR struct file *filep, FAR const char *relpath, int oflags, mode_t mode)
{
	FAR struct skel_file_s *priv;

	fvdbg("Open '%s'\n", relpath);

	/* PROCFS is read-only.  Any attempt to open with any kind of write
	 * access is not permitted.
	 *
	 * REVISIT:  Write-able proc files could be quite useful.
	 */

	if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) && (skel_procfsoperations.write == NULL)) {
		fdbg("ERROR: Only O_RDONLY supported\n");
		return -EACCES;
	}

	/* Allocate a container to hold the task and attribute selection */

	priv = (FAR struct skel_file_s *)kmm_zalloc(sizeof(struct skel_file_s));
	if (!priv) {
		fdbg("ERROR: Failed to allocate file attributes\n");
		return -ENOMEM;
	}

	/* TODO: Initialize the context specific data here */

	/* Save the index as the open-specific state in filep->f_priv */

	filep->f_priv = (FAR void *)priv;
	return OK;
}
Exemple #11
0
static int mtd_open(FAR struct file *filep, FAR const char *relpath,
                    int oflags, mode_t mode)
{
    FAR struct mtd_file_s *attr;

    fvdbg("Open '%s'\n", relpath);

    /* PROCFS is read-only.  Any attempt to open with any kind of write
     * access is not permitted.
     *
     * REVISIT:  Write-able proc files could be quite useful.
     */

    if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)
    {
        fdbg("ERROR: Only O_RDONLY supported\n");
        return -EACCES;
    }

    /* Allocate a context structure */

    attr = (FAR struct mtd_file_s *)kmm_zalloc(sizeof(struct mtd_file_s));
    if (!attr)
    {
        fdbg("ERROR: Failed to allocate file attributes\n");
        return -ENOMEM;
    }

    attr->pnextmtd = g_pfirstmtd;

    /* Save the context as the open-specific state in filep->f_priv */

    filep->f_priv = (FAR void *)attr;
    return OK;
}
Exemple #12
0
FAR struct local_conn_s *local_alloc(void)
{
  FAR struct local_conn_s *conn =
    (FAR struct local_conn_s *)kmm_zalloc(sizeof(struct local_conn_s));

  if (conn)
    {
      /* Initialize non-zero elements the new connection structure */

      conn->lc_infd  = -1;
      conn->lc_outfd = -1;

#ifdef CONFIG_NET_LOCAL_STREAM
      /* This semaphore is used for signaling and, hence, should not have
       * priority inheritance enabled.
       */

      sem_init(&conn->lc_waitsem, 0, 0);
      sem_setprotocol(&conn->lc_waitsem, SEM_PRIO_NONE);

#ifdef HAVE_LOCAL_POLL
      memset(conn->lc_accept_fds, 0, sizeof(conn->lc_accept_fds));
#endif
#endif
    }

  return conn;
}
Exemple #13
0
FAR struct battery_charger_dev_s *bq2425x_initialize(FAR struct i2c_dev_s *i2c,
                            uint8_t addr, uint32_t frequency)
{
  FAR struct bq2425x_dev_s *priv;
  int ret;

  /* Initialize the BQ2425x device structure */

  priv = (FAR struct bq2425x_dev_s *)kmm_zalloc(sizeof(struct bq2425x_dev_s));
  if (priv)
    {
      /* Initialize the BQ2425x device structure */

      sem_init(&priv->batsem, 0, 1);
      priv->ops       = &g_bq2425xops;
      priv->i2c       = i2c;
      priv->addr      = addr;
      priv->frequency = frequency;

      /* Set the I2C frequency (ignoring the returned, actual frequency) */

      (void)I2C_SETFREQUENCY(i2c, priv->frequency);

      /* Reset the BQ2425x */

      ret = bq2425x_reset(priv);
      if (ret < 0)
        {
          batdbg("Failed to reset the BQ2425x: %d\n", ret);
          kmm_free(priv);
          return NULL;
        }

      /* Disable watchdog otherwise BQ2425x returns to StandAlone mode */

      ret = bq2425x_watchdog(priv, false);
      if (ret < 0)
        {
          batdbg("Failed to disable BQ2425x watchdog: %d\n", ret);
          kmm_free(priv);
          return NULL;
        }

      /* Define that our power supply can offer 2000mA to the charger */

      ret = bq2425x_powersupply(priv, 2000);
      if (ret < 0)
        {
          batdbg("Failed to set BQ2425x power supply current: %d\n", ret);
          kmm_free(priv);
          return NULL;
        }
    }

  return (FAR struct battery_charger_dev_s *)priv;
}
Exemple #14
0
FAR void *watchdog_register(FAR const char *path,
                            FAR struct watchdog_lowerhalf_s *lower)
{
  FAR struct watchdog_upperhalf_s *upper;
  int ret;

  DEBUGASSERT(path && lower);
  wdvdbg("Entry: path=%s\n", path);

  /* Allocate the upper-half data structure */

  upper = (FAR struct watchdog_upperhalf_s *)
    kmm_zalloc(sizeof(struct watchdog_upperhalf_s));
  if (!upper)
    {
      wddbg("Upper half allocation failed\n");
      goto errout;
    }

  /* Initialize the watchdog timer device structure (it was already zeroed
   * by kmm_zalloc()).
   */

  sem_init(&upper->exclsem, 0, 1);
  upper->lower = lower;

  /* Copy the registration path */

  upper->path = strdup(path);
  if (!upper->path)
    {
      wddbg("Path allocation failed\n");
      goto errout_with_upper;
    }

  /* Register the watchdog timer device */

  ret = register_driver(path, &g_wdogops, 0666, upper);
  if (ret < 0)
    {
      wddbg("register_driver failed: %d\n", ret);
      goto errout_with_path;
    }

  return (FAR void *)upper;

errout_with_path:
  kmm_free(upper->path);

errout_with_upper:
  sem_destroy(&upper->exclsem);
  kmm_free(upper);

errout:
  return NULL;
}
static inline FAR struct gran_s *
gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran,
                       uint8_t log2align)
{
  FAR struct gran_s *priv;
  uintptr_t          heapend;
  uintptr_t          alignedstart;
  unsigned int       mask;
  unsigned int       alignedsize;
  unsigned int       ngranules;

  /* Check parameters if debug is on.  Note the size of a granule is
   * limited to 2**31 bytes and that the size of the granule must be greater
   * than or equal to the alignment size.
   */

  DEBUGASSERT(heapstart && heapsize > 0 &&
              log2gran > 0 && log2gran < 32 &&
              log2gran >= log2align);

  /* Get the aligned start of the heap */

  mask         = (1 << log2align) - 1;
  alignedstart = ((uintptr_t)heapstart + mask) & ~mask;

  /* Determine the number of granules */

  mask         = (1 << log2gran) - 1;
  heapend      = (uintptr_t)heapstart + heapsize;
  alignedsize  = (heapend - alignedstart) & ~mask;
  ngranules    = alignedsize >> log2gran;

  /* Allocate the information structure with a granule table of the
   * correct size.
   */

  priv = (FAR struct gran_s *)kmm_zalloc(SIZEOF_GRAN_S(ngranules));
  if (priv)
    {
      /* Initialize non-zero elements of the granules heap info structure */

      priv->log2gran  = log2gran;
      priv->ngranules = ngranules;
      priv->heapstart = alignedstart;

      /* Initialize mutual exclusion support */

#ifndef CONFIG_GRAN_INTR
      sem_init(&priv->exclsem, 0, 1);
#endif
    }

  return priv;
}
Exemple #16
0
int mod_load(FAR struct mod_loadinfo_s *loadinfo)
{
  int ret;

  svdbg("loadinfo: %p\n", loadinfo);
  DEBUGASSERT(loadinfo && loadinfo->filfd >= 0);

  /* Load section headers into memory */

  ret = mod_loadshdrs(loadinfo);
  if (ret < 0)
    {
      sdbg("ERROR: mod_loadshdrs failed: %d\n", ret);
      goto errout_with_buffers;
    }

  /* Determine total size to allocate */

  mod_elfsize(loadinfo);

  /* Allocate (and zero) memory for the ELF file. */

  /* Allocate memory to hold the ELF image */

  loadinfo->textalloc = (uintptr_t)kmm_zalloc(loadinfo->textsize + loadinfo->datasize);
  if (!loadinfo->textalloc)
    {
      sdbg("ERROR: Failed to allocate memory for the module\n");
      ret = -ENOMEM;
      goto errout_with_buffers;
    }

  loadinfo->datastart = loadinfo->textalloc + loadinfo->textsize;

  /* Load ELF section data into memory */

  ret = mod_loadfile(loadinfo);
  if (ret < 0)
    {
      sdbg("ERROR: mod_loadfile failed: %d\n", ret);
      goto errout_with_buffers;
    }

  return OK;

  /* Error exits */

errout_with_buffers:
  mod_unload(loadinfo);
  return ret;
}
Exemple #17
0
int romdisk_register(int minor, FAR const uint8_t *buffer, uint32_t nsectors,
                     uint16_t sectsize)
#endif
{
  struct rd_struct_s *dev;
  char devname[16];
  int ret = -ENOMEM;

  finfo("buffer: %p nsectors: %d sectsize: %d\n", buffer, nsectors, sectsize);

  /* Sanity check */

#ifdef CONFIG_DEBUG_FEATURES
  if (minor < 0 || minor > 255 || !buffer || !nsectors || !sectsize)
    {
      return -EINVAL;
    }
#endif

  /* Allocate a ramdisk device structure */

  dev = (struct rd_struct_s *)kmm_zalloc(sizeof(struct rd_struct_s));
  if (dev)
    {
      /* Initialize the ramdisk device structure */

      dev->rd_nsectors     = nsectors;     /* Number of sectors on device */
      dev->rd_sectsize     = sectsize;     /* The size of one sector */
      dev->rd_buffer       = buffer;       /* RAM disk backup memory */

#ifdef CONFIG_FS_WRITABLE
      dev->rd_flags        = rdflags & RDFLAG_USER;
#endif

      /* Create a ramdisk device name */

      snprintf(devname, 16, "/dev/ram%d", minor);

      /* Inode private data is a reference to the ramdisk device structure */

      ret = register_blockdriver(devname, &g_bops, 0, dev);
      if (ret < 0)
        {
          ferr("register_blockdriver failed: %d\n", -ret);
          kmm_free(dev);
        }
    }

  return ret;
}
Exemple #18
0
int btn_register(FAR const char *devname,
                 FAR const struct btn_lowerhalf_s *lower)

{
  FAR struct btn_upperhalf_s *priv;
  int ret;

  DEBUGASSERT(devname && lower);

  /* Allocate a new button driver instance */

  priv = (FAR struct btn_upperhalf_s *)
    kmm_zalloc(sizeof(struct btn_upperhalf_s));

  if (!priv)
    {
      ierr("ERROR: Failed to allocate device structure\n");
      return -ENOMEM;
    }

  /* Make sure that all button interrupts are disabled */

  DEBUGASSERT(lower->bl_enable);
  lower->bl_enable(lower, 0, 0, NULL, NULL);

  /* Initialize the new button driver instance */

  priv->bu_lower = lower;
  nxsem_init(&priv->bu_exclsem, 0, 1);

  DEBUGASSERT(lower->bl_buttons);
  priv->bu_sample = lower->bl_buttons(lower);

  /* And register the button driver */

  ret = register_driver(devname, &btn_fops, 0666, priv);
  if (ret < 0)
    {
      ierr("ERROR: register_driver failed: %d\n", ret);
      goto errout_with_priv;
    }

  return OK;

errout_with_priv:
  nxsem_destroy(&priv->bu_exclsem);
  kmm_free(priv);
  return ret;
}
Exemple #19
0
DMA_HANDLE lc823450_dmachannel(int ch)
{
  struct lc823450_dmach_s *dmach = NULL;

  /* Get exclusive access to the GPDMA state structure */

  dmach = (struct lc823450_dmach_s *)
           kmm_zalloc(sizeof(struct lc823450_dmach_s));

  if (dmach)
    {
      dmach->chn = ch;
    }

  return (DMA_HANDLE)dmach;
}
Exemple #20
0
static int zc_open(FAR struct file *filep)
{
  FAR struct inode                *inode;
  FAR struct zc_upperhalf_s       *priv;
  FAR const struct zc_lowerhalf_s *lower;
  FAR struct zc_open_s            *opriv;
  int ret;

  DEBUGASSERT(filep && filep->f_inode);
  inode = filep->f_inode;
  DEBUGASSERT(inode->i_private);
  priv = (FAR struct zc_upperhalf_s *)inode->i_private;

  /* Get exclusive access to the driver structure */

  ret = sem_wait(&priv->exclsem);
  if (ret < 0)
    {
      snvdbg("ERROR: sem_wait failed: %d\n", ret);
      return ret;
    }

  /* Allocate a new open structure */

  opriv = (FAR struct zc_open_s *)kmm_zalloc(sizeof(struct zc_open_s));
  if (!opriv)
    {
      snvdbg("ERROR: Failled to allocate open structure\n");
      ret = -ENOMEM;
      goto errout_with_sem;
    }

  /* Attach the open structure to the device */

  opriv->do_flink = priv->zu_open;
  priv->zu_open = opriv;

  /* Attach the open structure to the file structure */

  filep->f_priv = (FAR void *)opriv;
  ret = OK;

errout_with_sem:
  sem_post(&priv->exclsem);
  return ret;
}
Exemple #21
0
int gpio_lower_half(FAR struct ioexpander_dev_s *ioe, unsigned int pin,
                    enum gpio_pintype_e pintype, int minor)
{
  FAR struct gplh_dev_s *priv;
  FAR struct gpio_dev_s *gpio;
  int ret;

  DEBUGASSERT(ioe != NULL && pin < CONFIG_IOEXPANDER_NPINS &&
              (unsigned int)pintype < GPIO_NPINTYPES);

#ifndef CONFIG_IOEXPANDER_INT_ENABLE
  /* If there is no I/O expander interrupt support, then we cannot handle
   * interrupting pin types.
   */

  DEBUGASSERT(pintype != GPIO_INTERRUPT_PIN);
#endif

  /* Allocate an new instance of the GPIO lower half driver */

  priv = (FAR struct gplh_dev_s *)kmm_zalloc(sizeof(struct gplh_dev_s));
  if (priv == NULL)
    {
      gpioerr("ERROR: Failed to allocate driver state\n");
      return -ENOMEM;
    }

  /* Initialize the non-zero elements of the newly allocated instance */

  priv->pin        = (uint8_t)pin;
  priv->ioe        = ioe;
  gpio             = &priv->gpio;
  gpio->gp_pintype = (uint8_t)pintype;
  gpio->gp_ops     = &g_gplh_ops;

  /* Register the GPIO driver */

  ret = gpio_pin_register(gpio, minor);
  if (ret < 0)
    {
      gpioerr("ERROR: gpio_pin_register() failed: %d\n", ret);
      kmm_free(priv);
    }

  return ret;
}
Exemple #22
0
int djoy_register(FAR const char *devname,
                  FAR const struct djoy_lowerhalf_s *lower)

{
  FAR struct djoy_upperhalf_s *priv;
  int ret;

  DEBUGASSERT(devname && lower);

  /* Allocate a new djoystick driver instance */

  priv = (FAR struct djoy_upperhalf_s *)
    kmm_zalloc(sizeof(struct djoy_upperhalf_s));

  if (!priv)
    {
      ierr("ERROR: Failed to allocate device structure\n");
      return -ENOMEM;
    }

  /* Make sure that all djoystick interrupts are disabled */

  DEBUGASSERT(lower->dl_enable);
  lower->dl_enable(lower, 0, 0, NULL, NULL);

  /* Initialize the new djoystick driver instance */

  priv->du_lower = lower;
  sem_init(&priv->du_exclsem, 0, 1);

  DEBUGASSERT(lower->dl_sample);
  priv->du_sample = lower->dl_sample(lower);

  /* And register the djoystick driver */

  ret = register_driver(devname, &djoy_fops, 0666, priv);
  if (ret < 0)
    {
      ierr("ERROR: register_driver failed: %d\n", ret);
      sem_destroy(&priv->du_exclsem);
      kmm_free(priv);
    }

  return ret;
}
Exemple #23
0
int i2c_register(FAR struct i2c_master_s *i2c, int bus)
{
  FAR struct i2c_driver_s *priv;
  char devname[DEVNAME_FMTLEN];
  int ret;

  /* Sanity check */

  DEBUGASSERT(i2c != NULL && (unsigned)bus < 1000);

  /* Allocate a I2C character device structure */

  priv = (FAR struct i2c_driver_s *)kmm_zalloc(sizeof(struct i2c_driver_s));
  if (priv)
    {
      /* Initialize the I2C character device structure */

      priv->i2c = i2c;
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
      sem_init(&priv->exclsem, 0, 1);
#endif

      /* Create the character device name */

      snprintf(devname, DEVNAME_FMTLEN, DEVNAME_FMT, bus);
      ret = register_driver(devname, &i2cdrvr_fops, 0666, priv);
      if (ret < 0)
        {
          /* Free the device structure if we failed to create the character
           * device.
           */

          kmm_free(priv);
        }

      /* Return the result of the registration */

      return OK;
    }


  return -ENOMEM;
}
Exemple #24
0
int rtc_initialize(int minor, FAR struct rtc_lowerhalf_s *lower)
{
	FAR struct rtc_upperhalf_s *upper;
	char devpath[16];
	int ret;

	DEBUGASSERT(lower && lower->ops && minor >= 0 && minor < 1000);

	/* Allocate an upper half container structure */

	upper = (FAR struct rtc_upperhalf_s *)kmm_zalloc(
					sizeof(struct rtc_upperhalf_s));
	if (!upper) {
		return -ENOMEM;
	}

	/* Initialize the upper half container */

	upper->lower = lower;     /* Contain lower half driver */

#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
	upper->crefs = 0;         /* No open references */
	upper->unlinked = false;  /* Driver is not  unlinked */
#endif

	/*
	 * Create the driver name.  There is space for the a minor number
	 * up to 6 characters
	 */

	snprintf(devpath, 16, "/dev/rtc%d", minor);

	/* And, finally, register the new RTC driver */

	ret = register_driver(devpath, &rtc_fops, 0666, upper);
	if (ret < 0) {
		kmm_free(upper);
		return ret;
	}

	return OK;
}
Exemple #25
0
FAR void* ubxmdm_register(FAR const char *path,
                          FAR struct ubxmdm_lower *lower)
{
  FAR struct ubxmdm_upper *upper;
  int ret;

  DEBUGASSERT(path && lower);

  upper = (FAR struct ubxmdm_upper*)
    kmm_zalloc(sizeof(struct ubxmdm_upper));
  if (!upper)
    {
      m_err("ERROR: Upper half allocation failed\n");
      goto errout;
    }

  upper->lower = lower;
  upper->path = strdup(path);
  if (!upper->path)
    {
      m_err("ERROR: Path allocation failed\n");
      goto errout_with_upper;
    }

  ret = register_driver(path, &ubxmdm_fops, 0666, upper);
  if (ret < 0)
    {
      m_err("ERROR: register_driver failed: %d\n", ret);
      goto errout_with_path;
    }

  return (FAR void*) upper;

errout_with_path:
  kmm_free(upper->path);

errout_with_upper:
  kmm_free(upper);

errout:
  return NULL;
}
Exemple #26
0
static int ccm_open(FAR struct file *filep, FAR const char *relpath,
                      int oflags, mode_t mode)
{
  FAR struct ccm_file_s *priv;

  fvdbg("Open '%s'\n", relpath);

  /* PROCFS is read-only.  Any attempt to open with any kind of write
   * access is not permitted.
   *
   * REVISIT:  Write-able proc files could be quite useful.
   */

  if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)
    {
      fdbg("ERROR: Only O_RDONLY supported\n");
      return -EACCES;
    }

  /* "cpuload" is the only acceptable value for the relpath */

  if (strcmp(relpath, "ccm") != 0)
    {
      fdbg("ERROR: relpath is '%s'\n", relpath);
      return -ENOENT;
    }

  /* Allocate a container to hold the task and attribute selection */

  priv = (FAR struct ccm_file_s *)kmm_zalloc(sizeof(struct ccm_file_s));
  if (!priv)
    {
      fdbg("ERROR: Failed to allocate file attributes\n");
      return -ENOMEM;
    }

  /* Save the index as the open-specific state in filep->f_priv */

  filep->f_priv = (FAR void *)priv;
  return OK;
}
Exemple #27
0
int i2schar_register(FAR struct i2s_dev_s *i2s, int minor)
{
  FAR struct i2schar_dev_s *priv;
  char devname[DEVNAME_FMTLEN];
  int ret;

  /* Sanity check */

  DEBUGASSERT(i2s != NULL && (unsigned)minor < 1000);

  /* Allocate a I2S character device structure */

  priv = (FAR struct i2schar_dev_s *)kmm_zalloc(sizeof(struct i2schar_dev_s));
  if (priv)
    {
      /* Initialize the I2S character device structure */

      priv->i2s = i2s;
      sem_init(&priv->exclsem, 0, 1);

      /* Create the character device name */

      snprintf(devname, DEVNAME_FMTLEN, DEVNAME_FMT, minor);
      ret = register_driver(devname, &i2schar_fops, 0666, priv);
      if (ret < 0)
        {
          /* Free the device structure if we failed to create the character
           * device.
           */

          kmm_free(priv);
        }

      /* Return the result of the registration */

      return OK;
    }


  return -ENOMEM;
}
Exemple #28
0
struct scsc_mx *scsc_mx_create(struct scsc_mif_abs *mif)
{
	struct scsc_mx *mx;

	mx = kmm_zalloc(sizeof(*mx));
	if (!mx) {
		return NULL;
	}

	mx->mif_abs = mif;

	mifintrbit_init(&mx->intr, mif);

	mifmboxman_init(&mx->mbox);
	panicmon_init(&mx->panicmon, mx);
	suspendmon_init(&mx->suspendmon, mx);
	mxman_init(&mx->mxman, mx);
	srvman_init(&mx->srvman, mx);
	SLSI_INFO_NODEV("Hurray Maxwell is here with %p\n", mx);
	return mx;
}
Exemple #29
0
int zc_register(FAR const char *devname, FAR struct zc_lowerhalf_s *lower)
{
  FAR struct zc_upperhalf_s *priv;
  int ret;

  DEBUGASSERT(devname && lower);

  /* Allocate a new zero cross driver instance */

  priv = (FAR struct zc_upperhalf_s *)
    kmm_zalloc(sizeof(struct zc_upperhalf_s));

  if (!priv)
    {
      snvdbg("ERROR: Failed to allocate device structure\n");
      return -ENOMEM;
    }

  /* Make sure that zero cross interrupt is disabled */

  DEBUGASSERT(lower->zc_enable);
  lower->zc_enable(lower, NULL, NULL);

  /* Initialize the new zero cross driver instance */

  priv->lower = lower;
  sem_init(&priv->exclsem, 0, 1);

  /* And register the zero cross driver */

  ret = register_driver(devname, &g_zcops, 0666, priv);
  if (ret < 0)
    {
      snvdbg("ERROR: register_driver failed: %d\n", ret);
      sem_destroy(&priv->exclsem);
      kmm_free(priv);
    }

  return ret;
}
Exemple #30
0
int qe_register(FAR const char *devpath, FAR struct qe_lowerhalf_s *lower)
{
  FAR struct qe_upperhalf_s *upper;

  /* Allocate the upper-half data structure */

  upper = (FAR struct qe_upperhalf_s *)kmm_zalloc(sizeof(struct qe_upperhalf_s));
  if (!upper)
    {
      snerr("ERROR: Allocation failed\n");
      return -ENOMEM;
    }

  /* Initialize the PWM device structure (it was already zeroed by kmm_zalloc()) */

  sem_init(&upper->exclsem, 0, 1);
  upper->lower = lower;

  /* Register the PWM device */

  sninfo("Registering %s\n", devpath);
  return register_driver(devpath, &g_qeops, 0666, upper);
}