MPU Java

Innovative Computer Engineering
(Redirected from Category:MPU Java)
Jump to: navigation, search

Since Java is the base language for NeXtMidas, it should be the easiest implementation of an MPULib function. A Java MPULib object only requires the coder to create one Java file.

Category Contents

This category is empty

Example

The following is an example of what a Java MPULib function would look like:

Foo.java

 package nxm.demo.lib;
 import nxm.sys.lib.Data;
 import nxm.sys.lib.DataOp;
 import nxm.sys.lib.MPULib;
 import nxm.sys.lib.MidasException;
 import nxm.sys.lib.Shell;

 /** Example Java MPULib object */
 public class Foo extends MPULib {

   private int mult;  // output multiplier
   private String format; // input/output format
   private String str; // test string 
 
   public Foo () {    
     /* run MPULib's constructor */
     super();
     // init the multiplier to 2
     mult = 2;
     str = "";
     format = "SI";
   }
 
   /* Override the integer set function */
   @Override 
   public void set (String key, int val) {
     if ( key.equals("MULTKEY") )
       mult = val;
     else
       throw new MidasException("Error! Key " + key + " not found!!!!");
   }
 
   /* Override the string set function */
   @Override 
   public void set (String key, String val) {
     if ( key.equals("STRKEY") ) {
       str = val;
       System.out.printf("The string resource is now set to: %s\n", str);
     }
     else if ( key.equals("FORMAT") ) {
       format = val;
     }
     else
       throw new MidasException("Error! Key " + key + " not found!!!!");      
   }
   
   /* override open function
   This function is just confirming data types
   */
   @Override
   public int open () {
     if ( !format.equals("SI") && !format.equals("CI") ) {
       throw new MidasException("Error! Input type must be of type SI or CI!!!!");
     }
     return 0;
   }
  
   /* Override MPULib's process function with our own
    Note: there are easier ways to perform this same operation 
    but this is a example of Midas Data Types */
   @Override 
   public int process(byte[] buf1, int n1, byte[] buf2, int n2) {
     /* only have integer cases */
     byte itype = Data.BYTE;
     int  ele = (int)(buf1.length / Data.getBPS(itype));
     Data dbi = Data.fromBuffer(buf1, Shell.rep, 0, ele, itype);
     /* scale by mult */
     DataOp.scale(dbi, dbi, mult);
     /* true for copy protection */
     byte[] tmp = dbi.castB(true);
     System.arraycopy(tmp, 0, buf2, 0, tmp.length);
     dbi.uncast(tmp, false);    
     return ele;
   }
 }

Other Examples

Native: MPU Native

GPU: MPU GPU

ICE: MPU ICE

Verilator: MPU Verilator

Personal tools
Namespaces
Variants
Actions
Navigation
Products
Support
Corporate
Toolbox
Help