BeagleBoard/GSoC/2022 Proposal/Adding features to simpPRU

= Proposal for Adding Features to simpPRU =


 * Student: Krishna Narayanan
 * Mentors: Vedant Paranjape, Abhishek, Archisman
 * Code: https://github.com/VedantParanjape/simpPRU/
 * Proposal : https://elinux.org/index.php?title=BeagleBoard/GSoC/2022_Proposal/Adding_features_to_simpPRU
 * Wiki: [N/A]
 * GSoC: Proposal Request

= Status =
 * Pre-application phase

= Proposal =
 * Completed all the prerequisites
 * Completed "Hello World" of cross-compilation mentioned in the requirements list.
 * Created a PR for the task #159

About You

 * IRC:Krishna Narayanan (@krishna_13:matrix.org)
 * Github:https://github.com/Krishna-13-cyber
 * College: Veermata Jijabai Technological Institute (VJTI)
 * Country: India
 * Primary language: English, Hindi, Tamil
 * Typical work hours: 9 AM - 7 PM Indian Standard Time
 * Experience :
 * BluetoothJoystickis the project I had worked on which aimed to make a joystick with the help of ESP-32 microcontroller using the Bluetooth connectivity.This is where I got the experience and exposure to embedded environment.
 * Micromouseis the project which we had designed a bot from scratch,in which we had used a left hand algorithm for solving the maze in the shortest time.
 * I have been contributing and referring to open source actively,I have been contributing to gcc and have submitted patches for test cases and fixes#PR99209,#93432.
 * I got a special mention for this competition Micromouse Challenge, coming in the top 5 positions in the International Micromouse Challenge hosted by Techfest IIT,Bombay.
 * My areas of interest are compiler development,Robotics,Embedded Systems in specific.
 * I am familiar with working in Linux environment and git.
 * I am actively involved in the robotics club of my institute Society of Robotics and Automation SRA as a core member.
 * I am participating in GSoC for the first time.

= About Your Project =


 * Project name: simpPRU

Description
simpPRU is a procedural programming language. It is a statically typed language. Variables and functions must be assigned data types during compilation. It is type safe, and data types of variables are decided during compilation.The PRU is a dual core micro-controller system present on the AM335x SoC which powers the BeagleBone. It is meant to be used for high speed jitter free IO control. Being independent from the linux scheduler and having direct access to the IO pins of the BeagleBone Black, the PRU is ideal for offloading IO intensive tasks.

Programming the PRU is a uphill task for a beginner, since it involves several steps, writing the firmware for the PRU, writing a loader program. This can be a easy task for a experienced developer, but it keeps many creative developers away. So, I propose to implement a easy to understand language for the PRU, hiding away all the low level stuff and providing a clean interface to program PRU.

This can be achieved by implementing a language on top of PRU C. It will directly compile down to PRU C. This could also be solved by implementing a bytecode engine on the PRU, but this will result in waste of already limited resources on PRU. With this approach, both PRU cores can be run independent of each other. simpPRU is a procedural programming language which simplifies this process to a great extent. Since it has a syntax quite similar to python, it is easier to code in simpPRU. It emits code in C, which is then compiled into binary using pru-gcc. So, it is as good as writing code in PRU C in terms of efficiency and functionality and far less in complexity.SimpPRU has already been given a programming level experience,adding more features to it will make it more user-friendly,compatible and programming for PRU's would'nt be such a complex task.


 * Goal: Adding features to simpPRU aims to provide more features and functionalities to make the programming for PRU's more vibrant and increase its usage across various domains.

Implementation Details
std::vector toggle_entry = { "ON", "OFF", }; int a := 5; int b := 2; c := a^b; println(c); /*This would yield 7 */
 * The test.py will be added to the Github Actions..
 * I will be adding the ON/OFF button to indicate the state of PRU,as mentioned in an issue.I will be referring to the FTUXI by Arthur to accomplish this task.
 * I am planning to add the compiler flags O2 ,O3 to the required gcc-pru compilation which would greatly impact the efficiency and usage.I would be making the required change in the main.c to add the compiler flags.The main motive here is to benchmark the results of the optimization flags added.
 * I will be adding the Bitwise operator

int a := 5; int b := 10; a+=b; b+=a; println(a); print(b); /*This would yield 15 25 */
 * I will be adding assignment operators +=,-= for enhancement of arithmetic operations.

int a := 5; int b := 10; b-=a; println(a); /*This would yield 5 */ int a := 5; int b := 10; a*=b; a/=b; println(a); print(b); /*This would yield 50 5 */
 * I will be adding assignment operators *=,/=,%= for enhancement of arithmetic operations.
 * I will be making the required changes for which simpPRU will have the ability to directly call C functions.Foreign functions are to be used for this part.

int a := 5; int b := 10; int c; c:= Add(a,b); println(c); /*This would yield 15 */
 * 1) include

/*sum.c*/ int a,b,c; int Add(int a,int b) { c=a+b; return c; }
 * 1) include
 * 2) include

/*sum.h*/ int Add(int a,int b);

def func: int: int a { if: a < 22 { return 1; } else { return 0; } }
 * Documentation is a must to portray the work which has been done till now,there are some explanations yet to be covered in the docs which I will be completing.
 * I am planning for error handling in some test cases due to invalid input or erroneous outputs and changing grammar for validation of return statements to be called anywhere in the function.
 * Try to implement return anywhere inside function,apply changes in grammar.

Earlier, this had to be written as:

def func: int: int a { int b;   if: a < 22 { b := 1; } else { b := 0; return b; }


 * I will be writing a research paper under the guidance of my mentors Vedant Paranjape, Abhishek, Archisman to document the benchmark results of simpPRU.
 * I will try to port the code to librobotcontrol that performs balancing on a 2-wheel robot using a lag-lead controller and moving the control loop over to the PRUs using simpPRU in the given timeframe,yet if it exceeds the time limit I will complete it in post GSoC period and continue to solve issues in cooperation with the project mentors.

Experience and approach
This project requires good knowledge and background of compiler development. https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591595.html https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590817.html.
 * I have been exploring the compiler developer environment for quite some time,having good knowledge about the compilers.
 * I am familiar with regression testing,changing diagnostics messages,adding test cases and enabling compiler flags in the required condition with respect to the warning or error expected.
 * I have been contributing to open source actively in the compiler development adding test cases for bug fixes and regression testing that to avoid regressions or failure of any other passing test
 * I have had experience with an esp-32 microcontroller in my project and now I am into compiler development which is a perfect blend of hardware and software which is now the requirement of this project.
 * I already have the beaglebone(pocket beagle) and have tried using the simpPRU console and getting accustomed to it.
 * I am an open source enthusiast,passionate about technologies and have always dedicated myself to the work I do with utmost perfection.I have no major commitment other than GSoC during the summer break and would give the best of my potential to complete the project idea in the given timeframe.
 * I plan to keep working with simpPRU even after GSoC and also engage with the community often.

Contingency
I have prepared a docs for all the links I have referred during my preparation phase and if I get stuck up anywhere I would be relying on these.Moreover the beagleboard community is extremely helpful and active in resolving doubts which makes it a great going for the project resources and clarification.

Benefit

 * Adding these additional features to the project would make it more compatible and user-friendly.
 * The research paper which I would be writing would cover all the topics,the detailed concepts implemented in simpPRU.
 * This project will make simpPRU more complete and robust, which will help with beginners learning to use the PRU or experienced users prototyping something on the PRU.

Quotes
"simpPRU will simplify programming the PRU, and probably make it easy even for a kid to program the PRU, which is a big plus point of this project." - Vedant Paranjape (@vedant16)

Misc
Cross-compilation task,sent a PR to the upstream: #159