📄 ezkit.m
字号:
function ezkit(op)
% EZKit is a Graphical User Interface used for communicating with the
% SHAERC EZ-Kit Lite DSP board.
%
% Hit F5, or type "ezkit" in the matlab command window to run the program.
%
% This GUI enables the user to control, through the serial port, an FIR filter
% implemented on a SHARC EZ-Kit Lite Evaluation board. The code here does not do the
% actual filtering, it simply allows the user to poke and peek at the filter
% coefficients stored in the memory of the SHARC processor. This GUI is to be used in
% conjunction with an assembly program that does the filtering on the board.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % File: ezkit.m %
% % Author: Jesse Hansen (12-1-01) %
% % Email: hansenj@ele.uri.edu %
% % Web: www.ele.uri.edu/~hansenj/ %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% NOTE: You must have Matlab 6.0 or higher to successfully run this program due to the
% use of the 'serial' function.
% Last updated 10-12-02
%---------------------------------------------------------------------------------------
global s h % global variables allow data to exist between callbacks
% s - The serial port object
% h - A structure containing handles to the GUI controls, axis, etc
if nargin == 0 % if no input argument, draw the GUI
op = 0;
end
switch op
%----------------------------------------------------------------------------------- 0.0
case 0 % Draw figure
width = 950;
height = 700;
LeftBord = 40/width;
RightBord = (width-40)/width;
TopBord = (height-30)/height;
h.fig = figure('Position',[25 50 width height],...
'Color',[0.8 0.8 0.8],...
'NumberTitle','off',...
'Name','SHARC EZ-Kit Lite');
up_ax = 0.5;
lw_ax = 0.1;
top_frame = 0.85;
% ------------------------------------------------------------------------------- 0.1
% --------------------------------- UPPER FRAME -----------------------------------
uicontrol('Style','frame',...
'Units','normalized',...
'Position',[LeftBord top_frame RightBord-LeftBord TopBord-top_frame]);
h.cntrl(1) = uicontrol('Style','text',... % STATUS DISPLAY
'Units','normalized',...
'Position',[LeftBord+20/width (height-75)/height 240/width 20/height],...
'String','Status: Ready...',...
'HorizontalAlignment','left',...
'FontSize',10);
uicontrol('Style','text',...
'Units','normalized',...
'Position',[LeftBord+0.515 (height-58)/height 340/width 20/height],...
'String','Evaluate expression for GUI data',...
'HorizontalAlignment','center',...
'FontSize',10);
h.cntrl(4) = uicontrol('Style','edit',... % ENTER EXPR IN BOX TO CREATE COEFFS
'Units','normalized',...
'Position',[LeftBord+0.515 (height-92)/height 340/width 25/height],...
'HorizontalAlignment','left',...
'FontSize',10,...
'CallBack','ezkit(3)');
% ------------------------------------------------------------------------------- 0.2
% ------------------------------ FRAME FOR MATLAB DATA -----------------------------
uicontrol('Style','frame',...
'Units','normalized',...
'Position',[LeftBord up_ax 120/width 210/height]);
uicontrol('Style','text',...
'Units','normalized',...
'Position',[LeftBord+1/width up_ax+180/height 118/width 20/height],...
'String','Matlab Data',...
'FontWeight','bold',...
'FontSize',10);
h.cntrl(3) = uicontrol('Style','pushbutton',... % SEND COEFFS TO BOARD
'Units','normalized',...
'Position',[LeftBord+20/width up_ax+25/height 80/width 30/height],...
'TooltipString','Send new coeffs to the board',...
'String','Send ''Em',...
'ForegroundColor',[1 0 0],...
'FontWeight','bold',...
'CallBack','ezkit(2)');
% ------------------------------------------------------------------------------- 0.3
% ----------------------------- FRAME FOR DSP BOARD DATA ---------------------------
uicontrol('Style','frame',...
'Units','normalized',...
'Position',[LeftBord lw_ax 120/width 210/height]);
uicontrol('Style','text',...
'Units','normalized',...
'Position',[LeftBord+1/width lw_ax+180/height 118/width 20/height],...
'String','DSP Board',...
'FontWeight','bold',...
'FontSize',10);
h.cntrl(2) = uicontrol('Style','pushbutton',... % GET COEFFS FROM BOARD
'Units','normalized',...
'Position',[LeftBord+20/width lw_ax+25/height 80/width 30/height],...
'TooltipString','Take a look at the coeffs on the board',...
'String','Peek',...
'ForegroundColor',[1 0 0],...
'FontWeight','bold',...
'CallBack','ezkit(1)');
% ------------------------------------------------------------------------------- 0.4
% --------------------------------- THE COEFF PLOTS -------------------------------
lft = LeftBord+170/width;
h.ax(1) = subplot('position',[lft up_ax RightBord-lft 0.3]);
h.ax(2) = subplot('position',[lft lw_ax RightBord-lft 0.3]);
%----------------------------------------------------------------------------------- 1.0
case 1 % Download coeffs from board to computer
% Connect to board -------------------------------------------------------------- 1.1
set(h.cntrl(2),'Enable','off')
set(h.cntrl(3),'Enable','off')
set(h.cntrl(1),'String','Status: Connecting')
% 's' is a serial port object that is manipulated both to send messages from
% the computer to the SHARC EZ-Kit Lite and to recieve messages in response.
s = EZWakeUp; % Establish communications with the board
s = EZRaiseSpeed(s); % Raise the interface speed
% Download coeffs from board to computer ---------------------------------------- 1.2
set(h.cntrl(1),'String','Status: Downloading Coefficients')
% Coeffs are stored at 0x23000, the start of the program data memory
h.BoardCoeffs = EZReadDM(s,'23000',251);
% Plot the coeffs on one of the axes
x = h.BoardCoeffs(1:max(find(h.BoardCoeffs)));
n = 0:max(find(h.BoardCoeffs))-1;
axes(h.ax(2)),stem(n,x)
axis([0 max(max(n),11) get(gca,'YLim')]), grid on
% Disconnect from board --------------------------------------------------------- 1.3
set(h.cntrl(1),'String','Status: Disonnecting')
ExitCode = EZEndCommun(s);
set(h.cntrl(1),'String','Status: Coeffs downloaded from board')
set(h.cntrl(2),'Enable','on')
set(h.cntrl(3),'Enable','on')
%----------------------------------------------------------------------------------- 2.0
case 2
possible_len = 251;
data_len = length(h.LocalCoeffs);
if data_len > possible_len
set( h.cntrl(1), 'String', ['Status: Max Coeff length = ' num2str(possible_len)] )
beep
return
end
% Connect to board -------------------------------------------------------------- 2.1
set(h.cntrl(2),'Enable','off')
set(h.cntrl(3),'Enable','off')
set(h.cntrl(1),'String','Status: Connecting')
% 's' is a serial port object that is manipulated both to send messages from
% the computer to the SHARC EZ-Kit Lite and to recieve messages in response.
s = EZWakeUp; % Establish communications with the board
s = EZRaiseSpeed(s); % Raise the interface speed
% Sending Coeffs to the DSP board ----------------------------------------------- 2.2
set(h.cntrl(1),'String','Status: Uploading Coefficients')
% Coeffs are stored at 0x23000, the start of the program data memory
total_len = 251;
data_len = length(h.LocalCoeffs);
data = [h.LocalCoeffs zeros(1,possible_len-data_len)];
success = EZWriteDM(s,'23000',possible_len,data);
% Disconnect from board --------------------------------------------------------- 2.3
set(h.cntrl(1),'String','Status: Disonnecting')
ExitCode = EZEndCommun(s);
set(h.cntrl(1),'String','Status: Coeffs uploaded to board')
set(h.cntrl(2),'Enable','on')
set(h.cntrl(3),'Enable','on')
%----------------------------------------------------------------------------------- 3.0
case 3
expr = get(h.cntrl(4),'String');
success = 1;
temp = eval(expr);
if success
if (ndims(temp) < 3) & (min(size(temp)) == 1)
len = length(temp);
h.LocalCoeffs = temp;
n = 0:len-1;
axes(h.ax(1)), stem(n,h.LocalCoeffs), grid
axis([0 max(len-1,11) get(gca,'YLim')])
end
end
end
%----------------------------------------------------------------------------------- end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Functions for manipulating the SHARC EZ-Kit Lite through the serial port
% - EZWakeUp
% - EZRaiseSpeed
% - EZEndCommun
% - EZReadDM
% - EZWriteDM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function s = EZWakeUp()
%
% Esablish communications with the board with the following steps
%
% 1) Create a serial port object on COM1 with BaudRate of 9600
% 2) Open the serial port
% 3) Send the Host Re-synchronization command to the EZ-Kit
%
% Returns a serial port object in 's'
%
HostResyncCmd = [ 180 13 220 186 ];
s = serial('COM1', 'BaudRate', 9600,... % initialize the serial
'Parity', 'none',... % communications to 9600 baud
'DataBits', 8,...
'StopBits', 1,...
'InputBufferSize', 1024,...
'OutputBufferSize', 1024,...
'Timeout', 2);
fopen(s) % open the serial port
fwrite(s, HostResyncCmd) % send the host re-sync command
%---------------------------------------------------------------------------------------
function s = EZRaiseSpeed(s)
%
% Raise the interface speed to 115200 baud
%
% Return the modified serial object 's'
%
InterfaceSpeedCmd115200 = [ 0 0 0 0 ,...
4 0 6 2 ,...
10 0 0 0 ,...
0 0 0 0 ];
InterfaceSpeedRsp = [ 0 0 0 0 ,...
2 0 6 130 ];
% Send the "set serial port speed" packet ordering a speed of 115200 baud
fwrite(s,InterfaceSpeedCmd115200)
fclose(s)
s.BaudRate = 115200; % Set the local serial communications to 115200 baud
fopen(s)
if EZWaitForResponse(s,2); % wait for response from board
error('No response, please manually reset the board');
end
rsp = fread(s,s.BytesAvailable)'; % read response
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -