saramonteiro commented on a change in pull request #2628: URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555259328
########## File path: drivers/efuse/efuse.c ########## @@ -0,0 +1,377 @@ +/**************************************************************************** + * drivers/efuse/efuse.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> +#include <stdint.h> +#include <stdbool.h> +#include <string.h> +#include <fcntl.h> +#include <assert.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/fs/fs.h> +#include <nuttx/irq.h> +#include <nuttx/kmalloc.h> +#include <nuttx/power/pm.h> +#include <nuttx/semaphore.h> +#include <nuttx/efuse/efuse.h> + +#ifdef CONFIG_EFUSE + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/* This structure describes the state of the upper half driver */ + +struct efuse_upperhalf_s +{ + sem_t exclsem; /* Supports mutual exclusion */ + FAR char *path; /* Registration path */ + + /* The contained lower-half driver */ + + FAR struct efuse_lowerhalf_s *lower; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int efuse_open(FAR struct file *filep); +static int efuse_close(FAR struct file *filep); +static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int efuse_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_efuseops = +{ + efuse_open, /* open */ + efuse_close, /* close */ + efuse_read, /* read */ + efuse_write, /* write */ + NULL, /* seek */ + efuse_ioctl, /* ioctl */ + NULL /* poll */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: efuse_open + * + * Description: + * This function is called whenever the efuse timer device is opened. + * + ****************************************************************************/ + +static int efuse_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: efuse_close + * + * Description: + * This function is called when the efuse timer device is closed. + * + ****************************************************************************/ + +static int efuse_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: efuse_read + * + * Description: + * A dummy read method. This is provided only to satisfy the VFS layer. + * + ****************************************************************************/ + +static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + /* Return zero -- usually meaning end-of-file */ + + return 0; +} + +/**************************************************************************** + * Name: efuse_write + * + * Description: + * A dummy write method. This is provided only to satisfy the VFS layer. + * + ****************************************************************************/ + +static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return 0; +} + +/**************************************************************************** + * Name: efuse_ioctl + * + * Description: + * The standard ioctl method. This is where ALL of the efuse timer + * work is done. + * + ****************************************************************************/ + +static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct efuse_upperhalf_s *upper; + FAR struct efuse_lowerhalf_s *lower; + int ret; + + minfo("cmd: %d arg: %ld\n", cmd, arg); + upper = inode->i_private; + DEBUGASSERT(upper != NULL); + lower = upper->lower; + DEBUGASSERT(lower != NULL); + + /* Get exclusive access to the device structures */ + + ret = nxsem_wait(&upper->exclsem); + if (ret < 0) + { + return ret; + } + + /* Handle built-in ioctl commands */ + + switch (cmd) + { + /* cmd: EFUSEIOC_READ_FIELD_BIT + * Description: Read a single bit efuse + * Argument: Return variable + */ Review comment: ```suggestion /* cmd: EFUSEIOC_READ_FIELD * Description: Read a field * Argument: A pointer to a struct efuse_param. * Where the field is an array. * Each item in the array is a pointer to an efuse_desc_t variable. * An efuse_desc_t variable contains an offset to a field or subfield and its size in bits. * The size param is a redundancy, and it is the sum of all subfields sizes from * from efuse_desc_t in bits. * The data is a pointer to a pre-allocated space where the driver will load * the data read from efuse. */ ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org