#!   /usr/bin/env   python
#    coding: utf8

# Copyright <company>, 2011
# Author: John Doe <john.doe@example.com>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org

import sys
import rr		# Needed for accessing the rawrabbit driver
import time
import os
from tpsexcept import * # Declaration of Exceptions

"""
test00: example test which prints 'hello <name>'
"""

# Helping class to access to the chips or to do common things
# It is recommended to have them at the same file to not need
# extra dependencies, however it is not mandatory.
class CTest:
	
	def __init__(self, bus, base):
		self.bus = bus;
		self.base =base;
	
	def hello(self, val):
		print "Hello " + val
	

def main (default_directory='.'):

	# The following commented code just loads the firmware 
	# using a program fpga_loader. The user can use its own.

	"""
	path_fpga_loader = '../firmwares/fpga_loader';
	path_firmware = '../firmwares/test00.bin';
    	
	firmware_loader = os.path.join(default_directory, path_fpga_loader)
    	bitstream = os.path.join(default_directory, path_firmware)
    	os.system( firmware_loader + ' ' + bitstream)
    	time.sleep(2);
	"""

	# After loading the firmware, we are ready to access to the registers.
	gennum = rr.Gennum();

	# Instantiate CTest.
	# The parameters are the Gennum variable and the Wishbone base address
	# of the corresponding WB slave. At this case, we don't have a WB slave.
	hi = CTest(gennum, 0x40000); 
	
	# This function just print in command line 'Hello <name>' but it can be
	# much more complex than that: accessing to the board, changing register's
	# values, etc.
	hi.hello("world")


# This code calls the 'main' function when the program is executed by command-line
# using './test00.py' or 'python test00.py'. In case of importing this Python program
# into another one, you should call it as 'test00.main(path_of_tests)' 
if __name__ == '__main__' :
	main();

