xiaoxiang781216 commented on code in PR #7554: URL: https://github.com/apache/incubator-nuttx/pull/7554#discussion_r1016433554
########## include/nuttx/drivers/drivers.h: ########## @@ -227,6 +227,16 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, void lwlconsole_init(void); +/**************************************************************************** + * Name: rtt_console_register + * + * Description: + * Register /dev/console + * + ****************************************************************************/ + +void rtt_console_register(void); Review Comment: let's add a new api to support general channel ########## drivers/segger/console_rtt.c: ########## @@ -0,0 +1,127 @@ +/**************************************************************************** + * drivers/segger/console_rtt.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 <unistd.h> +#include <debug.h> +#include <nuttx/fs/fs.h> + +#include <SEGGER_RTT.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, + size_t buflen); +static ssize_t rtt_write(FAR struct file *filep, + FAR const char *buffer, + size_t buflen); + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_rttops = +{ + NULL, /* open */ + NULL, /* close */ + rtt_read, /* read */ + rtt_write, /* write */ + NULL, /* seek */ + NULL, /* ioctl */ + NULL /* poll */ +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL /* unlink */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtt_read + ****************************************************************************/ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, size_t buflen) +{ + ssize_t res = 0; + + res += SEGGER_RTT_Read(0, buffer + res, buflen); + while(res != buflen) + { + usleep(1000); Review Comment: let's configurable ########## drivers/segger/console_rtt.c: ########## @@ -0,0 +1,127 @@ +/**************************************************************************** + * drivers/segger/console_rtt.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 <unistd.h> +#include <debug.h> +#include <nuttx/fs/fs.h> + +#include <SEGGER_RTT.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static ssize_t rtt_read(FAR struct file *filep, Review Comment: add prefix serial_? ########## drivers/segger/Kconfig: ########## @@ -3,6 +3,14 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +config RTT_CONSOLE Review Comment: ```suggestion config CONSOLE_RTT ``` move after line 72 ########## drivers/segger/console_rtt.c: ########## @@ -0,0 +1,127 @@ +/**************************************************************************** + * drivers/segger/console_rtt.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 <unistd.h> +#include <debug.h> +#include <nuttx/fs/fs.h> + +#include <SEGGER_RTT.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, + size_t buflen); +static ssize_t rtt_write(FAR struct file *filep, + FAR const char *buffer, + size_t buflen); + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_rttops = +{ + NULL, /* open */ + NULL, /* close */ + rtt_read, /* read */ + rtt_write, /* write */ + NULL, /* seek */ + NULL, /* ioctl */ + NULL /* poll */ +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL /* unlink */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtt_read + ****************************************************************************/ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, size_t buflen) +{ + ssize_t res = 0; + + res += SEGGER_RTT_Read(0, buffer + res, buflen); + while(res != buflen) + { + usleep(1000); Review Comment: nxsig_usleep ########## drivers/segger/console_rtt.c: ########## @@ -0,0 +1,127 @@ +/**************************************************************************** + * drivers/segger/console_rtt.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 <unistd.h> +#include <debug.h> +#include <nuttx/fs/fs.h> + +#include <SEGGER_RTT.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, + size_t buflen); +static ssize_t rtt_write(FAR struct file *filep, + FAR const char *buffer, + size_t buflen); + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_rttops = +{ + NULL, /* open */ + NULL, /* close */ + rtt_read, /* read */ + rtt_write, /* write */ + NULL, /* seek */ + NULL, /* ioctl */ + NULL /* poll */ +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL /* unlink */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtt_read + ****************************************************************************/ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, size_t buflen) +{ + ssize_t res = 0; + + res += SEGGER_RTT_Read(0, buffer + res, buflen); + while(res != buflen) + { + usleep(1000); + res += SEGGER_RTT_Read(0, buffer + res, buflen); + } + + return res; +} + +/**************************************************************************** + * Name: rtt_write + ****************************************************************************/ + +static ssize_t rtt_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return (ssize_t) SEGGER_RTT_Write(0, buffer, buflen); Review Comment: remove the cast ########## drivers/segger/console_rtt.c: ########## @@ -0,0 +1,127 @@ +/**************************************************************************** + * drivers/segger/console_rtt.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 <unistd.h> +#include <debug.h> +#include <nuttx/fs/fs.h> + +#include <SEGGER_RTT.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, + size_t buflen); +static ssize_t rtt_write(FAR struct file *filep, + FAR const char *buffer, + size_t buflen); + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_rttops = +{ + NULL, /* open */ + NULL, /* close */ + rtt_read, /* read */ + rtt_write, /* write */ + NULL, /* seek */ + NULL, /* ioctl */ + NULL /* poll */ +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL /* unlink */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtt_read + ****************************************************************************/ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, size_t buflen) +{ + ssize_t res = 0; + + res += SEGGER_RTT_Read(0, buffer + res, buflen); + while(res != buflen) Review Comment: need return immediately if something is received ########## drivers/segger/console_rtt.c: ########## @@ -0,0 +1,127 @@ +/**************************************************************************** + * drivers/segger/console_rtt.c Review Comment: console->serial ########## drivers/segger/console_rtt.c: ########## @@ -0,0 +1,127 @@ +/**************************************************************************** + * drivers/segger/console_rtt.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 <unistd.h> +#include <debug.h> +#include <nuttx/fs/fs.h> + +#include <SEGGER_RTT.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static ssize_t rtt_read(FAR struct file *filep, + FAR char *buffer, + size_t buflen); +static ssize_t rtt_write(FAR struct file *filep, + FAR const char *buffer, + size_t buflen); + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_rttops = +{ + NULL, /* open */ + NULL, /* close */ + rtt_read, /* read */ + rtt_write, /* write */ + NULL, /* seek */ + NULL, /* ioctl */ Review Comment: need implement ioctl and basic ctlid -- 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