Skip to content

lupyuen/nshtask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apache NuttX RTOS: NSH Task Demo

To build and run this NSH Task Demo...

  1. Install the Build Prerequisites, skip the RISC-V Toolchain...

    "Install Prerequisites"

  2. Download the ARM64 Toolchain for AArch64 Bare-Metal Target aarch64-none-elf

    Arm GNU Toolchain Downloads

    (Skip the section for Beta Releases)

  3. Add the downloaded toolchain to the PATH Environment Variable...

    gcc-arm-...-aarch64-none-elf/bin
    

    Check the ARM64 Toolchain...

    aarch64-none-elf-gcc -v
  4. Download QEMU Machine Emulator...

    "Download QEMU"

  5. Download NuttX...

    mkdir nuttx
    cd nuttx
    git clone https://github.com/apache/nuttx nuttx
    git clone https://github.com/apache/nuttx-apps apps
    cd nuttx
  6. Add nshtask to our NuttX Project...

    pushd ../apps/examples
    git submodule add https://github.com/lupyuen/nshtask
    popd
  7. Configure our NuttX Project...

    tools/configure.sh -l qemu-armv8a:nsh
    make menuconfig
  8. In "Application Configuration > Examples"

    Enable "NSH Task Demo"

  9. Optional: If we wish to start nshtask when NuttX boots...

    In "RTOS Features > Tasks and Scheduling"

    Set "Application entry point" to nshtask_main

    Set "Application entry name" to nshtask_main

  10. Save the configuration and exit menuconfig

  11. Build NuttX...

    make
  12. Run NuttX with QEMU...

    qemu-system-aarch64 -cpu cortex-a53 -nographic \
      -machine virt,virtualization=on,gic-version=3 \
      -net none -chardev stdio,id=con,mux=on -serial chardev:con \
      -mon chardev=con,mode=readline -kernel ./nuttx
  13. At the NSH Prompt, enter this to run the demo...

    nshtask

    When we're done, press Ctrl-C to quit QEMU.

Incorrect Response from ChatGPT

"How to create a NuttX Task for NSH Shell"

"To create a NuttX task for the NSH shell, you will need to do the following steps"

"In your NuttX application's main file, include the necessary headers for task creation and the NSH shell"

#include <nuttx/sched.h>
#include <nuttx/nsh.h>

"In the main function of your application, create a new task using the task_create() function, passing in the necessary parameters such as the task's entry point, its name, and its stack size."

"In the entry point function for the task, call the nsh_main() function to start the NSH shell."

"Finally, start the task using the task_start() function, passing in the task's ID as a parameter."

"This code creates a task named "nsh", with a priority of 100 and a stack size of 2048 bytes, that runs the nsh_main() function when started."

nshtask/nshtask.c

Lines 2 to 28 in c9d4f0b

#include <nuttx/sched.h>
#include <nuttx/nsh.h>
int nsh_main(int argc, char *argv[]);
int nsh_task(int argc, char *argv[])
{
nsh_main(argc, argv);
return 0;
}
int main(int argc, char *argv[])
{
pid_t pid = task_create(
"nsh", // Task Name
100, // Task Priority
2048, // Task Stack Size
nsh_task, // Task Function
(FAR char * const *)argv // Task Arguments
);
if (pid < 0) {
printf("Error creating task\n");
} else {
task_start(pid);
}
return 0;
}

The corrected source code is here: nshtask.c

About

Apache NuttX RTOS: NSH Task Demo

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published