jerpelea commented on code in PR #7248: URL: https://github.com/apache/incubator-nuttx/pull/7248#discussion_r994186888
########## drivers/modem/alt1250/alt1250.c: ########## @@ -0,0 +1,1279 @@ +/**************************************************************************** + * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h> +#include <nuttx/fs/fs.h> +#include <poll.h> +#include <errno.h> +#include <nuttx/wireless/lte/lte_ioctl.h> +#include <nuttx/modem/alt1250.h> +#include <assert.h> + +#include "altcom_pkt.h" +#include "altcom_hdlr.h" +#include "altmdm.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define WRITE_OK 0 +#define WRITE_NG 1 + +#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev) + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods. */ + +static int alt1250_open(FAR struct file *filep); +static int alt1250_close(FAR struct file *filep); +static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer, + size_t len); +static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +static int alt1250_poll(FAR struct file *filep, struct pollfd *fds, + bool setup); + +parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t); +compose_handler_t alt1250_additional_composehdlr(uint32_t, + FAR uint8_t *, size_t); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This the vtable that supports the character driver interface. */ + +static const struct file_operations g_alt1250fops = +{ + alt1250_open, /* open */ + alt1250_close, /* close */ + alt1250_read, /* read */ + 0, /* write */ + 0, /* seek */ + alt1250_ioctl, /* ioctl */ + alt1250_poll, /* poll */ +}; +static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX]; +static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX]; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: add_list + ****************************************************************************/ + +static void add_list(FAR struct alt_queue_s *head, + FAR struct alt_container_s *list) +{ + FAR struct alt_container_s *next; + + nxsem_wait_uninterruptible(&head->lock); + + while (list != NULL) + { + next = (FAR struct alt_container_s *)sq_next(&list->node); + + sq_next(&list->node) = NULL; + sq_addlast(&list->node, &head->queue); + + list = next; + } + + nxsem_post(&head->lock); +} + +/**************************************************************************** + * Name: remove_list_all + ****************************************************************************/ + +static FAR struct alt_container_s *remove_list_all( + FAR struct alt_queue_s *head) +{ + FAR struct alt_container_s *list; + + nxsem_wait_uninterruptible(&head->lock); + + list = (FAR struct alt_container_s *)sq_peek(&head->queue); + sq_init(&head->queue); + + nxsem_post(&head->lock); + + return list; +} + +/**************************************************************************** + * Name: remove_list + ****************************************************************************/ + +static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head, + uint16_t cmdid, uint16_t transid) +{ + FAR struct alt_container_s *list; + + nxsem_wait_uninterruptible(&head->lock); + + list = (FAR struct alt_container_s *)sq_peek(&head->queue); + while (list != NULL) + { + if ((list->altcid == cmdid) && (list->alttid == transid)) + { + sq_rem(&list->node, &head->queue); + sq_next(&list->node) = NULL; + break; + } + + list = (FAR struct alt_container_s *)sq_next(&list->node); + } + + nxsem_post(&head->lock); + + return list; +} + +/**************************************************************************** + * Name: set_senddisable + ****************************************************************************/ + +static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable) +{ + nxsem_wait_uninterruptible(&dev->senddisablelock); + + dev->senddisable = disable; + + nxsem_post(&dev->senddisablelock); +} + +/**************************************************************************** + * Name: is_senddisable + ****************************************************************************/ + +static bool is_senddisable(FAR struct alt1250_dev_s *dev) +{ + bool disable; + + nxsem_wait_uninterruptible(&dev->senddisablelock); + + disable = dev->senddisable; + + nxsem_post(&dev->senddisablelock); + + return disable; +} + +/**************************************************************************** + * Name: read_evtbitmap + ****************************************************************************/ + +static ssize_t read_data(FAR struct alt1250_dev_s *dev, + FAR struct alt_readdata_s *rdata) +{ + int idx; + + nxsem_wait_uninterruptible(&dev->evtmaplock); + + /* change status to NOT WRITABLE */ + + for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++) + { + if (dev->evtbitmap & (1ULL << idx)) + { + if (dev->evtbuff->ninst >= idx) + { + FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx]; + + nxsem_wait_uninterruptible(&inst->stat_lock); + + inst->stat = ALTEVTBUF_ST_NOTWRITABLE; + + nxsem_post(&inst->stat_lock); + } + } + } + + rdata->evtbitmap = dev->evtbitmap; + rdata->head = remove_list_all(&dev->replylist); + + if (dev->evtbitmap & ALT1250_EVTBIT_RESET) + { + /* Resume sending because daemon has been notified of the reset + * reliably. + */ + + set_senddisable(dev, false); + } + + dev->evtbitmap = 0ULL; + + nxsem_post(&dev->evtmaplock); + + return sizeof(struct alt_readdata_s); +} + +/**************************************************************************** + * Name: write_evtbitmap + ****************************************************************************/ + +static void write_evtbitmap(FAR struct alt1250_dev_s *dev, + uint64_t bitmap) +{ + nxsem_wait_uninterruptible(&dev->evtmaplock); + + dev->evtbitmap |= bitmap; + + if (dev->evtbitmap & ALT1250_EVTBIT_RESET) Review Comment: quirk -- 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. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org