#===========================================================
# Enter your BFM commands in this file. 
#
# Syntax: 
# ------- 
#
# memmap    resource_name base_address;
#
# write     width resource_name byte_offset data;
# read      width resource_name byte_offset;
# readcheck width resource_name byte_offset data;
#
#===========================================================

include "subsystem.bfm"

procedure user_main;

# perform subsystem initialization routine
  call subsystem_init; 

# add your BFM commands below:
# perform subsystem initialization routine
  call subsystem_init; 
memmap FABRIC_0     0x30000000;
wait 400;
wait 400;
wait 400;
wait 400;
wait 400;
wait 400;

# add your BFM commands below:


#+++++++++++++++++++++++++++++++++++++++
#Rate limiter parameters
#+++++++++++++++++++++++++++++++++++++++
# Ref in
write w FABRIC_0 0x070 0x10000;
# slew count
write w FABRIC_0 0x074 0x1;
# Rate count
write w FABRIC_0 0x078 0x1000;
#+++++++++++++++++++++++++++++++++++++++

#+++++++++++++++++++++++++++++++++++++++
#SQMNG parameters address
#+++++++++++++++++++++++++++++++++++++++
write w FABRIC_0 0x520 0x00069;
write w FABRIC_0 0x524 0x1;
write w FABRIC_0 0x528 0x800;
write w FABRIC_0 0x52C 0x01FFF;
write w FABRIC_0 0x530 0xFFFF;
#+++++++++++++++++++++++++++++++++++++++

#+++++++++++++++++++++++++++++++++++++++
#ADC Scale Value
write w FABRIC_0 0x534 0x30D4;
#+++++++++++++++++++++++++++++++++++++++


#+++++++++++++++++++++++++++++++++++++++
#PWM parameters
#+++++++++++++++++++++++++++++++++++++++
#PWM Period
write w FABRIC_0 0x34 0x9C4;
#PWM Dead time
write w FABRIC_0 0x38  0x1;
#PWM Delay time
write w FABRIC_0 0x3C  0x00000000;
#PWM gain
write w FABRIC_0 0x40  0x00000000;
#+++++++++++++++++++++++++++++++++++++++


#Start Motor command
write w FABRIC_0 0x94  0x1;

#Direction
write w FABRIC_0 0x90  0x1;

# angle kp, ki
write w FABRIC_0 0x208  0x2710;
write w FABRIC_0 0x20C  0x1388;
#speed kp ki
write w FABRIC_0 0x50  0x3E8;
write w FABRIC_0 0x54  0x12C;
# id,iq kp,ki
write w FABRIC_0 0x58  0x258;
write w FABRIC_0 0x5C  0x148;
write w FABRIC_0 0x60  0x258;
write w FABRIC_0 0x64  0x148;

# Filter factor values
# BEMF FF
write w FABRIC_0 0x210 0x9;
# OMEGA FF
write w FABRIC_0 0x214 0x2;

#Theta factor
write w FABRIC_0 0x98 0x1BD;

#c by f val
write w FABRIC_0 0x9C 0x1;


# DV value
write w FABRIC_0 0xA0  0x1B58;

#IQ ref val
write w FABRIC_0 0xA4  0x7D00;

#CL OMEGA val
write w FABRIC_0 0xA8  0x2710;

#adc scale val
write w FABRIC_0 0x20  0x6FBB;
write w FABRIC_0 0x24  0x1FFFF;

#ls_by_ts val
write w FABRIC_0 0x200  0xD71;
#Rs val
write w FABRIC_0 0x204  0x77;
return