Difference between revisions of "BeagleBoard/GSoC/2020 Projects/PRU Improvements"

From eLinux.org
Jump to: navigation, search
(Added Description)
(Implementation Details)
 
(25 intermediate revisions by 2 users not shown)
Line 11: Line 11:
  
 
''Student'': [https://elinux.org/User:Vedant16 Vedant Paranjape]<br>
 
''Student'': [https://elinux.org/User:Vedant16 Vedant Paranjape]<br>
''Mentors'': [http://elinux.org/User:Abhishek_ Kumar Abhishek], [https://elinux.org/User:Jkridner Jason Kridner]<br>
+
''Mentors'': [http://elinux.org/User:Abhishek_ Kumar Abhishek], Pratim Ugale, Andrew Henderson<br>
 
''Code'': [N/A]<br>
 
''Code'': [N/A]<br>
 
''Wiki'': https://elinux.org/BeagleBoard/GSoC/2020Proposal/VedantParanjape2<br>
 
''Wiki'': https://elinux.org/BeagleBoard/GSoC/2020Proposal/VedantParanjape2<br>
Line 18: Line 18:
  
 
=Status=
 
=Status=
This project is currently just a proposal.
+
This project is selected for GSoC 2020
  
 
=Proposal=
 
=Proposal=
Line 36: Line 36:
 
==Description==
 
==Description==
  
:This project will enable the control of the Beaglebone's PRUs using remoteproc and rpmsg driver rather than using uio drivers. 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 Bhilack, the PRU is ideal for offloading IO intensive tasks.
+
: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 Bhilack, 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 REPL based control of the PRU, hiding all the low level things behind the REPL and providing a clean interface to uses PRU.
 
: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 REPL based control of the PRU, hiding all the low level things behind the REPL and providing a clean interface to uses PRU.
  
:This can be achieved by implementing a PRU firmware which only runs some specific user defined commands delivered by RPMSG, executes and then sends a appropriate response. This can be achieved by offloading major task like lexing, parsing to the linux core, and through RPMSG only certain set of commands will be run, the high level code will be converted to these set of commands, on the linux machine itself.
+
:This can be achieved by implementing a language on top of the PRU Assembly. It will directly compile down to PRU assembly. 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. 
 +
Deliverables:
 +
# Implement a language for PRU which compiles down to PRU Assembly.
 +
# Solve issues on [https://github.com/beagleboard/am335x_pru_package/issues am335x_pru_package] github.
 +
# Update [https://github.com/deepakkarki/pruspeak PRUSpeak] to work with the latest kernel.
  
 
==Implementation Details==
 
==Implementation Details==
 +
;Implement a language for PRU which compiles down to PRU Assembly.
  
;PRU Firmware
+
* Language Name: SimpPRU
:PRU will run a firmware which will basically run a while loop, which will evaluate certain specified commands sent to it through RPMSG. Accordingly it will execute the described commands on the PRU. After taking a look at PRUSpeak, its command set enables to do advance PRU control. So, proposed commands set will be
+
* Statically typed language
:{| class="wikitable
+
* TAB or 4 spaces for indentation
| SET_PWM || Sets PWM output
+
 
|-
+
;Primitive data types:
| SET_OUT || Sets HIGH/LOW value of an output pin
+
* `int`
|-
+
* `bool`
| READ_IN || Reads HIGH/LOW value of an input pin
+
 
|-
+
;Arithmetic operators
| SET_MEM || Sets specified value to specified memory location
+
* `/` divide
|-
+
* `*` multiply
| READ_MEM || Reads value at the specified location
+
* `+` plus
|-
+
* `-` minus   
| WAIT || Waits for given amount of clock cycles
+
;Relational operators
|-
+
* `>`  greater than
| CMP || Compares the two operands, returns 0 if equal, -1 if less than and +1 if greater than
+
* `>=` greater than or equal to
|-
+
* `<`  less than
| ADD || Adds two operands.
+
* `<=` less than or equal to
|-
+
* `=`  equal to
| SUB || Subtracts two operands
+
* `!=` not equal to
|-
+
;Bitwise operators
| AND || ANDs the two operands
+
* `&` unary and
|-
+
* `|` unary or
| OR || ORs the two operands
+
* `~` unary not
|-
+
;logical operators
| HALT || Stops program execution
+
* `and` logical and
|}
+
* `or` logical or
 +
* `not` logical not
 +
operator precedence, as arranged
 +
 
 +
;Arithmetic operations
 +
* `int` and `float` can be operated together, `int` will be promoted to float
 +
* `bool` cannot be operated with anything other than `bool`
 +
* `bool` only supports unary operators
 +
;Variable assignment
 +
* `<data_type> <identifier> := <value>`   
 +
* int value := 34
 +
 
 +
;if elif else loop       
 +
 
 +
    if <condition_to_be_evaluated>:
 +
        <do something>
 +
    elif <condition_to_be_evaluated>:
 +
        <do something>
 +
    else:
 +
        <do something>
 +
 
 +
;for loop
 +
 
 +
    for <identifier>, <condition>, <action to loop completion>:
 +
        <do something>
 +
 
 +
;functions
 +
    <return type> <function name> (<data type> variable name, ...):
 +
        <do something>
  
:Commands will be sent through RPMSG to the PRU and a response, either SUCCESS or error a message, will be sent through RPMSG by the PRU to ARM.
+
    int add(int a, int b):
;Interpreter on linux core
+
        return a + b
 +
* Each functions must always return something, since void data type is not included
  
 +
;Register Access
 +
    bool read_register(register_name, bit_to_be_read)
 +
    bool write_register(register_name, bit_to_be_written, bool value_to_be_written)
 +
* Implementing utility functions like GPO/GPI control, delay, setting Pin out and automatically setting pinmux.
 +
* Packaging the compiler with system images
 +
;Solve issues on [https://github.com/beagleboard/am335x_pru_package/issues am335x_pru_package] github
 +
# Solve issue [https://github.com/beagleboard/am335x_pru_package/issues/44 #44], [https://github.com/beagleboard/am335x_pru_package/issues/41 #41], [https://github.com/beagleboard/am335x_pru_package/issues/49 #49]
 
===Timeline===
 
===Timeline===
 
{| class="wikitable"
 
{| class="wikitable"
| May 4 || Proposal accepted or rejected || Community Bonding Period and discussion on the project and resources available.  
+
| May 4 || Proposal accepted or rejected ||  
 +
* Community Bonding Period and discussion on the project and resources available.  
 +
* Complete [https://www.coursera.org/learn/build-a-computer/home/welcome this] course, which teaches how to build a assembler, lexer, parser.
 +
* Go through the given tutorials to learn about building a programming language:
 +
# [https://aosabook.org/en/500L/a-python-interpreter-written-in-python.html A Python interpreter written in Python]
 +
# [https://effbot.org/zone/simple-iterator-parser.htm Simple iterator based parser]
 +
# [http://effbot.org/zone/simple-top-down-parsing.htm Simple top down parsing in python]
 +
# [https://ruslanspivak.com/lsbasi-part1/ Lets build a simple interpreter]
 +
# [https://www.youtube.com/watch?v=dj9CBS3ikGA&list=PLZQftyCk7_SdoVexSmwy_tBgs7P0b97yD&index=1 Make Your Own Simple Interpreted Programming Language]
 +
# [https://github.com/lotabout/write-a-C-interpreter Write a C interpreter]
 
|-
 
|-
 
| June 1 || Pre-work complete || Coding officially begins!
 
| June 1 || Pre-work complete || Coding officially begins!
Line 83: Line 133:
 
| June 8 || Milestone #1 ||  
 
| June 8 || Milestone #1 ||  
 
* Introductory YouTube video  
 
* Introductory YouTube video  
* Setting up PocketBeagle i.e flashing up to date Linux image and Testing user-led blink code :D  
+
* Setting up BeagleBone Black Wireless i.e flashing up to date Linux image and Testing user-led blink code :D  
 
* Running existing example codes from this [https://github.com/beagleboard/am335x_pru_package repository]
 
* Running existing example codes from this [https://github.com/beagleboard/am335x_pru_package repository]
 +
* Implementing int, bool data types
 +
* Implementing Arithmetic operators
 +
* Implementing Relational operators
 
|-
 
|-
 
| June 15 || Milestone #2 ||
 
| June 15 || Milestone #2 ||
* Testing the above functions
+
* Implementing Bitwise operators
 +
* Implementing Logical operators
 +
* Implementing Arithmetic operations
 +
* Implementing Variable assignment
 
* Writing documentation for same
 
* Writing documentation for same
 
* Setting up documentation generators like readthedocs
 
* Setting up documentation generators like readthedocs
 
|-
 
|-
 
| June 22 || Milestone #3 ||
 
| June 22 || Milestone #3 ||
* Testing the above functions
+
* Implementing if else elif
 +
* Implementing for loop
 +
* Implementing functions
 +
* Implementing Register access
 
* Writing documentation for same
 
* Writing documentation for same
 
|-
 
|-
Line 99: Line 158:
 
|-
 
|-
 
| July 10 || Milestone #5 ||
 
| July 10 || Milestone #5 ||
* Testing the above tool
+
* Implementing Language backend for variables and arithmetic operators
 +
* Implementing Language backend for for loop and if elif else
 
* Writing documentation  
 
* Writing documentation  
 
|-
 
|-
 
| July 17 || Milestone #6 ||
 
| July 17 || Milestone #6 ||
 +
* Implementing Language backend for functions and register access
 +
* Implementing Utility functions
 +
* Writing documentation
 
|-
 
|-
 
| July 24 || Milestone #7 ||
 
| July 24 || Milestone #7 ||
 +
* Testing the language, and implementing example codes.
 
* Writing documentation
 
* Writing documentation
 
|-
 
|-
Line 111: Line 175:
 
|-
 
|-
 
| August 3 || Milestone #9 ||
 
| August 3 || Milestone #9 ||
* Documenting the GUI
+
* Solving github issues
 +
* getting PRUSpeaks to work on the new kernel
 +
* Writing documentation
 
|-
 
|-
 
| August 10 || Milestone #10 ||
 
| August 10 || Milestone #10 ||
 +
* Packaging the compiler for distribution, like packaging into debian package.
 
* Completing the documentation
 
* Completing the documentation
 
* Taking feedback from mentors  
 
* Taking feedback from mentors  
Line 140: Line 207:
 
# [https://software-dl.ti.com/processor-sdk-linux/esd/docs/06_01_00_08/linux/index.html Processor SDK Linux Software Guide] is a good reference material
 
# [https://software-dl.ti.com/processor-sdk-linux/esd/docs/06_01_00_08/linux/index.html Processor SDK Linux Software Guide] is a good reference material
 
===Benefit===
 
===Benefit===
If successfully completed, what will its impact be on the BeagleBoard.org community? Include quotes from BeagleBoard.org community members who can be found on http://beagleboard.org/discuss and http://bbb.io/gsocchat.
+
:Currently interfacing with the PRU requires a lot of makefile manipulation, kernel drivers and stuff. There's no working around that for more advanced applications but if you can get something simple up and running quickly with a REPL, that'd be great.
 
+
:: -Abhishek Kumar
==Misc==
 
Please complete the requirements listed on the [[BeagleBoard/GSoC/Ideas#General_requirements|ideas page]]. Provide link to pull request.
 
 
 
===Suggestions===
 
Is there anything else we should have asked you?
 

Latest revision as of 06:53, 1 June 2020


Proposal for Implement a REPL interpreter for PRU

Student: Vedant Paranjape
Mentors: Kumar Abhishek, Pratim Ugale, Andrew Henderson
Code: [N/A]
Wiki: https://elinux.org/BeagleBoard/GSoC/2020Proposal/VedantParanjape2
GSoC: [N/A]

Status

This project is selected for GSoC 2020

Proposal

Completed all the requirements listed on the ideas page. the code for the cross-compilation task can be found here submitted through the pull request #138.

About you

IRC: vedant16
Github: https://github.com/vedantparanjape/
School: Veermata Jijabai Technological Institute (VJTI)
Country: India
Primary language : English, Hindi, Marathi
Typical work hours : 10AM - 7PM Indian Standard Time
Previous GSoC participation: I find embedded pretty interesting, given I have experience with ESP32, I think I will be able to excel in this project. This is the first time i am participating in GSoC

About your project

Project name: Implement a REPL interpreter for PRU

Description

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 Bhilack, 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 REPL based control of the PRU, hiding all the low level things behind the REPL and providing a clean interface to uses PRU.
This can be achieved by implementing a language on top of the PRU Assembly. It will directly compile down to PRU assembly. 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.

Deliverables:

  1. Implement a language for PRU which compiles down to PRU Assembly.
  2. Solve issues on am335x_pru_package github.
  3. Update PRUSpeak to work with the latest kernel.

Implementation Details

Implement a language for PRU which compiles down to PRU Assembly.
  • Language Name: SimpPRU
  • Statically typed language
  • TAB or 4 spaces for indentation
Primitive data types
  • `int`
  • `bool`
Arithmetic operators
  • `/` divide
  • `*` multiply
  • `+` plus
  • `-` minus
Relational operators
  • `>` greater than
  • `>=` greater than or equal to
  • `<` less than
  • `<=` less than or equal to
  • `=` equal to
  • `!=` not equal to
Bitwise operators
  • `&` unary and
  • `|` unary or
  • `~` unary not
logical operators
  • `and` logical and
  • `or` logical or
  • `not` logical not

operator precedence, as arranged

Arithmetic operations
  • `int` and `float` can be operated together, `int` will be promoted to float
  • `bool` cannot be operated with anything other than `bool`
  • `bool` only supports unary operators
Variable assignment
  • `<data_type> <identifier> := <value>`
  • int value := 34
if elif else loop
   if <condition_to_be_evaluated>:
       <do something>
   elif <condition_to_be_evaluated>:
       <do something>
   else:
       <do something>
for loop
   for <identifier>, <condition>, <action to loop completion>:
       <do something>
functions
   <return type> <function name> ( variable name, ...):
       <do something>
   int add(int a, int b):
       return a + b
  • Each functions must always return something, since void data type is not included
Register Access
   bool read_register(register_name, bit_to_be_read)
   bool write_register(register_name, bit_to_be_written, bool value_to_be_written)
  • Implementing utility functions like GPO/GPI control, delay, setting Pin out and automatically setting pinmux.
  • Packaging the compiler with system images
Solve issues on am335x_pru_package github
  1. Solve issue #44, #41, #49

Timeline

May 4 Proposal accepted or rejected
  • Community Bonding Period and discussion on the project and resources available.
  • Complete this course, which teaches how to build a assembler, lexer, parser.
  • Go through the given tutorials to learn about building a programming language:
  1. A Python interpreter written in Python
  2. Simple iterator based parser
  3. Simple top down parsing in python
  4. Lets build a simple interpreter
  5. Make Your Own Simple Interpreted Programming Language
  6. Write a C interpreter
June 1 Pre-work complete Coding officially begins!
June 8 Milestone #1
  • Introductory YouTube video
  • Setting up BeagleBone Black Wireless i.e flashing up to date Linux image and Testing user-led blink code :D
  • Running existing example codes from this repository
  • Implementing int, bool data types
  • Implementing Arithmetic operators
  • Implementing Relational operators
June 15 Milestone #2
  • Implementing Bitwise operators
  • Implementing Logical operators
  • Implementing Arithmetic operations
  • Implementing Variable assignment
  • Writing documentation for same
  • Setting up documentation generators like readthedocs
June 22 Milestone #3
  • Implementing if else elif
  • Implementing for loop
  • Implementing functions
  • Implementing Register access
  • Writing documentation for same
June 29 - July 3 18:00 UTC Milestone #4 (Phase 1 evaluations)
  • Finalizing and documenting everything done till now, submitting first report for evaluation
July 10 Milestone #5
  • Implementing Language backend for variables and arithmetic operators
  • Implementing Language backend for for loop and if elif else
  • Writing documentation
July 17 Milestone #6
  • Implementing Language backend for functions and register access
  • Implementing Utility functions
  • Writing documentation
July 24 Milestone #7
  • Testing the language, and implementing example codes.
  • Writing documentation
July 27 - July 31 18:00 UTC Milestone #8 (Phase 2 evaluations)
  • Finalizing and documenting everything done till now, submitting second report for evaluation
August 3 Milestone #9
  • Solving github issues
  • getting PRUSpeaks to work on the new kernel
  • Writing documentation
August 10 Milestone #10
  • Packaging the compiler for distribution, like packaging into debian package.
  • Completing the documentation
  • Taking feedback from mentors
August 17 Milestone #11 Completion YouTube video
August 24 - August 31 18:00 UTC Final week Students submit their final work product and their final mentor evaluation
August 31 - September 7 18:00 UTC End of Session Mentors submit final student evaluations

Experience and approach

I have decent experience in C++, C and Python. I have done several projects involving embedded systems like ESP32, I well-versed with freeRTOS. I recently did a project on ESP32, in which I used ESP to control and plot PID loop running on the embedded device, plotting the values on a python GUI. Other than that I have developed firmware for a 3 DOF arm based on a ESP32 custom board. I did a internship with a embedded deviced startup, where I built:

  1. Built TCP network stack for embedded IoT Devices
  2. Implemented Synchronous TCP server using Boost.Asio(C++) and Boost.Thread(C++)
  3. Implemented a tool to calculate round trip time(RTT) of tcp packets

I actively contribute to open source and do a lot of mini projects throughout the year, you can find my several more interesting projects at my github page

Contingency

I believe that if I get stuck on my project and my mentor isn’t around, I will use the resources that are available to me. Some of those information portals are listed below.

  1. https://git.ti.com/pru-software-support-package
  2. https://processors.wiki.ti.com/index.php/PRU_Training:_Hands-on_Labs PRU Guide
  3. https://markayoder.github.io/PRUCookbook/ Mark Yoder's cookbook is a excellent guide
  4. Derek Molly's beagle bone guide provides all the information needed for getting up and running with my beagle.
  5. The technical reference manuals provided by TI on am3358 and am5729 are the best source
  6. Processor SDK Linux Software Guide is a good reference material

Benefit

Currently interfacing with the PRU requires a lot of makefile manipulation, kernel drivers and stuff. There's no working around that for more advanced applications but if you can get something simple up and running quickly with a REPL, that'd be great.
-Abhishek Kumar