s = SystemConsole.refreshMasters;
if(isempty(s))
  disp('------------------------------------------------------');
  disp('# ERROR, Found No Jtag Avalon Master, Check FPGA Board');
  return;
end

disp('# Open Jtag Master ... ');
M = SystemConsole.openMaster(1);
disp('# Done.');

led_address = hex2dec('0010');
sw_address  = hex2dec('0000');

loop_cnt = 0;
while(1)
  led_data = bitand(loop_cnt, 255); 
  M.write('uint32',led_address,led_data);  %  向 Avalon 总线的地址写数据
  sw_data = M.read('uint32',sw_address,1);   % 从 Avalon 总线地址读取数据

  fprintf(1,'# Write LED 0x%02x, Read SW 0x%02x\n', led_data, sw_data);
  loop_cnt = loop_cnt + 1;
  pause(1);
end
