root/PlatformSupport/sysgen2opb/sysgen2opb.m

Revision 835, 76.1 kB (checked in by murphpo, 5 months ago)

updating copyright date

Line 
1% Copyright (c) 2006-2008 Rice University
2% All Rights Reserved
3% This code is covered by the Rice-WARP license
4% See http://warp.rice.edu/license/ for details
5%
6% 'sysgen2opb' is a MATLAB script which converts a model built in Xilinx
7% System Generator into an OPB-compliant peripheral for use with the
8% embedded PowerPCs. The script replaces all the model's From/To Registerse
9% with memory mapped registers. It also creates the necessary address
10% decode logic and a C header file with the resulting register map.
11%
12% In addition, there is an option that can be turned on/off:
13% Shared Memory Extension Script - This script adds in an option to allow
14% the usage of Shared Memory. This script requires the usage of Dual Port
15% RAM's.
16%
17% This script is only supported for Xilinx System Generator 8.1 and 8.2
18%
19% To run the script, type the following on the Matlab command line:
20% sysgen2opb('yourModelName', 'yourSMChoice')
21%
22%   Replace 'yourModelName' with your Simulink model's name
23%   without the .mdl extension.
24%
25%   Replace 'yourSMChoice' with one of the following:
26%       1. 'smon' which will turn on the Shared Memory Extension Script
27%       2. 'smoff' which will turn off the Shared Memory Extension Script
28%
29% If you want to run the original script that utilizes From/To Registers
30% with no shared memory extension, run: sysgen2opb('yourModelName')
31
32function sysgen2opb(sys, varargin)
33warning off;
34
35% Run the model to see if there are any errors in the model
36try
37        sim(sys, 0)
38catch
39        display(['Error: Simulating the model resulted in error. Please check your model and initialization script.']);
40        return;
41end 
42
43% Base Address is always zero due to relocatable memory
44base = 0;
45
46appendString = '';
47
48% Look at the length of varargin to determine whether to run default
49% scripts
50if length(varargin) == 0
51        %Defult to no shared memory
52        smChoice = 'smoff';
53elseif length(varargin) == 1
54        smChoice = char(varargin(1));
55else
56        display('Unrecognized parameters on command line.');
57        return;
58end
59
60% Find the sample time period from the System Generator block
61sysgenblock = find_system(sys, 'block_type', 'sysgen');
62if length(sysgenblock) == 0
63        display(['Error: Please include a System Generator block.']);
64        return;
65elseif length(sysgenblock) > 1
66        display(['Error: Please only include one System Generator block in model.']);
67        return;
68else
69        sysgenperiod = get_param(sysgenblock, 'simulink_period');
70        sysgenperiod = mat2str(cell2mat(sysgenperiod));
71end
72
73% Load the model. Inform the user if it fails to load (ie: the model does
74% not exist)
75try
76        load_system(sys);
77catch
78        display(['Error: System ' sys ' does not exist']);
79        return;
80end
81
82% Check smChoice
83if ~(strcmp(smChoice, 'smon') | strcmp(smChoice, 'smoff'))
84        display(['Error smChoice input ''' smChoice ''' does not exist. Please use ''smon'' or ''smoff'' as your inputs.']);
85        return;
86end
87
88
89% Find the current sysgen version
90try
91        version = xlVersion;
92catch
93        display('Error: Sysgen is not found!');
94        return;
95end
96
97if length(version) >= 1
98        % The latest version is the first one in the cell
99        version = version{1};
100        % Get the first digit of the string array
101        version = str2num(version(1:3));
102else
103        display('Error: Sysgen is not found!');
104        return;
105end
106
107if ((version == 8.1) | (version == 8.2) | (version == 9.1))
108        % Find the From/To Registers
109        gatewaysInCheck = find_system(sys, 'LookUnderMasks', 'all', 'FollowLinks', 'on',   'block_type', 'fromreg');
110        gatewaysOutCheck = find_system(sys, 'LookUnderMasks', 'all', 'FollowLinks', 'on',    'block_type', 'toreg');
111else
112        display(['Error: Version ' version ' is not supported.']);
113        return;
114end
115
116% Check how many Gateways we have
117numberGateways = length(gatewaysInCheck) + length(gatewaysOutCheck);
118if numberGateways > 450
119    display('Error: The script only allows a max of 450 From/To Registers');
120        return;
121elseif numberGateways == 0
122    display('Error: The script needs From/To Regs within the model');
123        return;
124end
125
126% Check to see if we have a converted model by checking if we have the
127% Memory Mapped IO
128% If we do, inform the user and exit the script
129MemoryMappedIO = find_system(sys, 'LookUnderMasks', 'all', 'FollowLinks', 'on',  'BlockType', 'SubSystem', 'Name', 'Memory Mapped I_O');
130if length(MemoryMappedIO) > 0
131        display('You already have converted this design to a peripheral.');
132        display('Please get rid of the Memory Mapped I_O block and make sure')
133        display('your gateways are all still in place before trying again.');
134        return;
135end
136
137% Try saving an unconverted backup
138try
139        save_system(sys,[sys '_unconverted_backup']);
140catch
141        % There's a system with that name that's opened right now
142        % Close that system without saving
143        close_system([sys '_unconverted_backup'], 0);
144
145        % Save the backup system
146        save_system(sys,[sys '_unconverted_backup']);
147end
148close_system([sys '_unconverted_backup']);
149
150% Load the system
151load_system(sys);
152save_system(sys, sys, 'BreakLinks');
153
154% Try loading a local copy from the skeleton model
155% If it is not there, load it from the toolbox
156spm = 'skeleton_periph_model';
157try
158        load_system(spm);
159catch
160        load_system([matlabroot '\toolbox\WARP\' spm]);
161end
162
163%Find Sybsystems and correct all the names
164subsystems = find_system(sys,'LookUnderMasks', 'all', 'FollowLinks', 'on', 'BlockType', 'SubSystem');
165%First we need to look for duplicate names
166for c=1:length(subsystems)
167        subsysName = subsystems{c};
168        shortName = get_param(subsysName, 'Name');
169        parent = get_param(subsysName, 'Parent');
170        compName = [shortName '                 '];
171        % Make sure that we do not edit the name of the System Generator
172        if ~strcmp(compName(1:17), ' System Generator')
173            idx=0;  %appended to the end of a duplicate name
174            for d=c+1:length(subsystems)
175                subsysName2 = subsystems{d};
176                shortName2 = get_param(subsysName2,'Name');
177                parent2 = get_param(subsysName2, 'Parent');
178                if strcmp(parent, parent2) & strcmp(cleanName(shortName), cleanName(shortName2))
179                    set_param(subsysName2,'Name', [shortName2 '_' int2str(idx)]);
180                    idx=idx+1;           
181                    subsystems = find_system(sys,'LookUnderMasks','all','BlockType','SubSystem')';
182                end
183            end
184        end
185end
186
187% Update the Subsystem list
188subsystems = find_system(sys, 'LookUnderMasks', 'all', 'FollowLinks', 'on',  'BlockType', 'SubSystem');
189%Now for Subsystems with spaces, we want to clean up the name
190for c=length(subsystems):-1:1
191        subsysName = subsystems{c};
192        shortName = get_param(subsysName, 'Name');
193        compName = [shortName '                 '];
194        % Make sure that we do not edit the name of the System Generator
195        if ~strcmp(compName(1:17), ' System Generator')
196            set_param(subsysName, 'Name', cleanName(shortName));
197        end
198end
199
200if strcmp(smChoice, 'smon')
201        % Define the variables that will be
202        % later used for shared memory extension
203        dpramWOAddr={};
204        dpramWOAddrIndex = 0;
205        dpramWODataI={};
206        dpramWODataIIndex = 0;
207        dpramWOWE={};
208        dpramWOWEIndex = 0;
209        dpramROAddr={};
210        dpramROAddrIndex = 0;
211        dpramRODataO={};
212        dpramRODataOIndex = 0;
213       
214        % dpramROIndex will be used to determine the number of dpram Read-only's
215        % This will be used to determine whether we need a delay of one within
216        % the mem_if_out
217        dpramROIndex = 0;
218       
219        % maxdpram will be used to determine how many shared memory blocks we
220        % can have
221        binBaseAddress = dec2bin(base);
222        try
223            maxdpram = 15 - bin2dec(binBaseAddress(13:16));
224        catch
225            maxdpram = 15;
226        end
227       
228        % dpram will hold the list of all dual port RAM's
229        dpram = find_system(sys,'LookUnderMasks', 'all', 'FollowLinks', 'on',  'block_type', 'dpram');
230
231        % dpramWORO will hold the list of all WO, RO dual port RAM's
232        dpramWORO={};
233        dpramWOROidx = 0;
234        for c=1:length(dpram)
235            dpramName = dpram{c};
236            compName = [get_param(dpramName, 'Name') '     '];
237
238            % Delete all broken lines
239            brokenlines = find_system(sys,'LookUnderMasks', 'all', 'FollowLinks', 'on',  'FindAll', 'on', 'type', 'line', 'SrcBlockHandle', -1);
240            delete_line(brokenlines);
241            brokenlines = find_system(sys,'LookUnderMasks', 'all', 'FollowLinks', 'on',  'FindAll', 'on', 'type', 'line', 'DstBlockHandle', -1);
242            delete_line(brokenlines);
243           
244            if strcmp(compName(1:5), 'SMWO_') | strcmp(compName(1:5), 'SMRO_')
245                dpramWOROidx = dpramWOROidx + 1;
246                if dpramWOROidx > maxdpram
247                    display(['Error: We are allowed a total of ' num2str(maxdpram) ' dual port RAMS that are read-only/write-only.']);
248                    return;
249                end
250               
251                dpramWORO{dpramWOROidx} = [get_param(dpramName, 'Name') '_sm' num2str(dpramWOROidx - 1)] ;
252               
253                DpramPortHandles = get_param(dpramName, 'PortHandles');
254
255                ports = [DpramPortHandles.Inport(4), DpramPortHandles.Inport(5), DpramPortHandles.Inport(6), DpramPortHandles.Outport(2)];
256
257                SrcBlockHandleAddr = get_param(get_param(ports(1), 'Line'), 'SrcBlockHandle');
258                SrcBlockHandleDataI = get_param(get_param(ports(2), 'Line'), 'SrcBlockHandle');
259                SrcBlockHandleWE = get_param(get_param(ports(3), 'Line'), 'SrcBlockHandle');
260               
261
262                AddrName = get_param(SrcBlockHandleAddr, 'Name');
263                CompAddrName = [AddrName '         '];
264                AddrFullName = [get_param(SrcBlockHandleAddr, 'Parent') '/' AddrName];
265                if ~strcmp(get_param(SrcBlockHandleAddr, 'block_type'), 'gatewayin')
266                    display(['A GatewayIn is needed in order to connect to the addrb inport of the dpram ' dpramName '.']);
267                    return;
268                end
269                if  ~strcmp(get_param(SrcBlockHandleAddr, 'arith_type'), 'Unsigned') | (str2num(get_param(SrcBlockHandleAddr, 'n_bits')) > 14) |  (str2num(get_param(SrcBlockHandleAddr, 'bin_pt')) > 0)
270                    display(['The GatewayIn ' AddrFullName ' needs to be UFix, with number of bits <= 14, and binary point at 0.']);
271                    return;
272                end
273                orientationAddr = get_param(SrcBlockHandleAddr, 'Orientation');
274                placeAddr = get_param(SrcBlockHandleAddr, 'position');
275                parentAddr = get_param(SrcBlockHandleAddr, 'Parent');
276                fromAddr = [parentAddr '/' cleanName(AddrName) '_sm' int2str(dpramWOROidx)];
277                fromAddrSlice = [parentAddr '/' cleanName(AddrName) '_slice_sm' int2str(dpramWOROidx)];
278                fromAddrSliceBits = get_param(SrcBlockHandleAddr, 'n_bits');
279               
280                DataIName = get_param(SrcBlockHandleDataI, 'Name');
281                CompDataIName = [DataIName '          '];
282                DataIFullName = [get_param(SrcBlockHandleDataI, 'Parent') '/' DataIName];
283                orientationDataI = get_param(SrcBlockHandleDataI, 'Orientation');
284                placeDataI = get_param(SrcBlockHandleDataI, 'position');
285                parentDataI = get_param(SrcBlockHandleDataI, 'Parent');
286                fromDataI = [parentAddr '/' cleanName(DataIName) '_sm' int2str(dpramWOROidx)];
287               
288                WEName = get_param(SrcBlockHandleWE, 'Name');
289                CompWEName = [WEName '       '];
290                WEFullName = [get_param(SrcBlockHandleWE, 'Parent') '/' WEName];
291                orientationWE = get_param(SrcBlockHandleWE, 'Orientation');
292                placeWE = get_param(SrcBlockHandleWE, 'position');
293                parentWE = get_param(SrcBlockHandleWE, 'Parent');
294                fromWE = [parentWE '/' cleanName(WEName) '_sm' int2str(dpramWOROidx)];
295               
296            end
297
298            if strcmp(compName(1:5), 'SMWO_')
299                if ~strcmp(CompAddrName(1:9), 'SMWOAddr_')
300                    display(['The Gateway In ' AddrName ' needs to have the prefix of SMWOAddr_']);
301                    return;
302                end
303               
304                %%%%% SMWOAddr %%%%%%
305                % Delete the GatewayIn
306                delete_block(SrcBlockHandleAddr);
307
308               
309                deleteSource(sys, cleanName(AddrName));
310               
311                % Find the broken lines that starts from the output port of the
312                % deleted GatewayIn
313                brokenlines = find_system(sys,'LookUnderMasks', 'all', 'FollowLinks', 'on',  'FindAll', 'on', 'type', 'line', 'SrcBlockHandle', -1);
314
315                % Find out the handle of the port and the block
316                % These two handles will be used to extract more information
317                DstPortHandle = get_param(brokenlines, 'DstPortHandle');
318                DstBlockHandle = get_param(brokenlines, 'DstBlockHandle');
319
320                % From DstPortHandle, we can find out what is
321                % the destination port number
322                if length(DstPortHandle) > 1
323                    DstPortNumber = cell2mat(get_param(DstPortHandle{length(DstPortHandle)}, 'PortNumber'));
324                else
325                    DstPortNumber = get_param(DstPortHandle, 'PortNumber');
326                end
327
328                % From DstBlockHandle, we can find out what is the name of the
329                % destination block
330                if length(DstBlockHandle) > 1
331                    DstName = get_param(DstBlockHandle{length(DstBlockHandle)}, 'Name');
332                    try
333                        DstBlockType = get_param(DstBlockHandle{length(DstBlockHandle)}, 'block_type');
334                    catch
335                        DstBlockType = get_param(DstBlockHandle{length(DstBlockHandle)}, 'BlockType');
336                    end
337                else
338                    DstName = get_param(DstBlockHandle, 'Name');
339                    try
340                        DstBlockType = get_param(DstBlockHandle, 'block_type');
341                    catch
342                        DstBlockType = get_param(DstBlockHandle, 'BlockType');
343                    end
344                end
345
346                % Delete the borken lines
347                delete_line(brokenlines);
348
349                dpramWOAddrIndex = dpramWOAddrIndex + 1;
350                dpramWOAddr{dpramWOAddrIndex} = fromAddr;
351                %placeAddr(1,1) = placeAddr(1,1) - 60;
352                placeAddr(1,3) = placeAddr(1,1) + 75;
353                placeAddrSlice = placeAddr;
354                placeAddrSlice(1,1) = placeAddrSlice(1,3) + 30;
355                placeAddrSlice(1,3) = placeAddrSlice(1,1) + 50;
356                add_block('built-in/From', fromAddr, 'GotoTag', ['SMWOAddr_' int2str(dpramWOAddrIndex - 1)], 'position', placeAddr);
357                if ((version == 8.1) | (version == 8.2) | (version == 9.1))
358                    add_block([spm '/Slice8'], fromAddrSlice, 'position', placeAddrSlice, 'nbits', fromAddrSliceBits);
359                end
360                                       
361                FromName = get_param(fromAddr, 'Name');
362                FromSliceName = get_param(fromAddrSlice, 'Name');
363                set_param(fromAddr,'Orientation', orientationAddr);
364
365                add_line(parentAddr, [FromName '/1' ], [FromSliceName '/1']);
366                if size(DstName, 1) == 1
367                   
368                    add_line(parentAddr, [FromSliceName '/1'], [DstName '/' int2str(DstPortNumber)]);
369                    %add_line(parentAddr, [FromName '/1' ], [DstName '/' int2str(DstPortNumber)]);
370                else
371                    for i=1:size(DstName, 1)
372                        if ~strcmp(DstName{i}, get_param(dpramName, 'Name'))
373                            add_line(parentAddr, [FromName '/1'], [DstName{i} '/' mat2str(DstPortNumber(i))]);
374                        else
375                            add_line(parentAddr, [FromSliceName '/1'], [DstName{i} '/' mat2str(DstPortNumber(i))]);
376                        end
377                    end
378                end
379               
380                %%%%% SMWODataI %%%%%%
381                if ~strcmp(get_param(SrcBlockHandleDataI, 'block_type'), 'gatewayin')
382                    display(['A Gateway In is needed in order to connect to the datb inport of the dpram ' dpramName '.']);
383                    return;
384                end
385                if ~strcmp(get_param(SrcBlockHandleDataI, 'n_bits'), '32')
386                    display(['The Xilinx block ' DataIFullName ' needs to set the number of bits to 32.']);
387                    return;
388                end
389                if ~strcmp(CompDataIName(1:10), 'SMWODataI_')
390                    display(['The Xilinx block ' DataIName ' needs to have a prefix of SMWODataI_']);
391                    return;
392                end
393                SMWODataIArithType = get_param(SrcBlockHandleDataI, 'arith_type');
394                SMWODataIArithType = [SMWODataIArithType '      '];
395                SMWODataIArithType = SMWODataIArithType(1:8);
396                if strcmp(SMWODataIArithType, 'Unsigned')
397                   fromDataIForce = [parentAddr '/' cleanName(DataIName) '_force_sm' int2str(dpramWOROidx)];
398                end
399               
400                % Delete the GatewayIn
401                delete_block(SrcBlockHandleDataI);
402
403                deleteSource(sys, cleanName(DataIName));
404               
405                % Find the broken lines that starts from the output port of the
406                % deleted GatewayIn
407                brokenlines = find_system(sys,'LookUnderMasks', 'all', 'FollowLinks', 'on',  'FindAll', 'on', 'type', 'line', 'SrcBlockHandle', -1);
408
409                % Find out the handle of the port and the block
410                % These two handles will be used to extract more information
411                DstPortHandle = get_param(brokenlines, 'DstPortHandle');
412                DstBlockHandle = get_param(brokenlines, 'DstBlockHandle');
413
414                % From DstPortHandle, we can find out what is
415                % the destination port number
416                if length(DstPortHandle) > 1
417                    DstPortNumber = cell2mat(get_param(DstPortHandle{length(DstPortHandle)}, 'PortNumber'));
418                else
419                    DstPortNumber = get_param(DstPortHandle, 'PortNumber');
420                end
421
422                % From DstBlockHandle, we can find otu what is the name of the
423                % destination block
424                if length(DstBlockHandle) > 1
425                    DstName = get_param(DstBlockHandle{length(DstBlockHandle)}, 'Name');
426                    try
427                        DstBlockType = get_param(DstBlockHandle{length(DstBlockHandle)}, 'block_type');
428                    catch
429                        DstBlockType = get_param(DstBlockHandle{length(DstBlockHandle)}, 'BlockType');
430                    end
431                else
432                    DstName = get_param(DstBlockHandle, 'Name');
433                    try
434                        DstBlockType = get_param(DstBlockHandle, 'block_type');
435                    catch
436                        DstBlockType = get_param(DstBlockHandle, 'BlockType');
437                    end
438                end
439
440                % Delete the borken lines
441                delete_line(brokenlines);
442               
443                dpramWODataIIndex = dpramWODataIIndex + 1;
444                dpramWODataI{dpramWODataIIndex} = fromDataI;
445               
446                if strcmp(SMWODataIArithType, 'Unsigned')
447                    %placeDataI(1,1) = placeDataI(1,1) + 75;
448                    placeDataIForce = placeDataI;
449                    placeDataIForce(1,1) = placeDataIForce(1,3) + 30;
450                    placeDataIForce(1,3) = placeDataIForce(1,1) + 50;
451                    add_block('built-in/From', fromDataI, 'GotoTag', ['SMWODataI_' int2str(dpramWODataIIndex - 1)], 'position', placeDataI);
452                    add_block([spm '/Force8'], fromDataIForce, 'position', placeDataIForce);
453                   
454                    FromName = get_param(fromDataI, 'Name');
455                    FromForceName = get_param(fromDataIForce, 'Name');
456                    set_param(fromDataI, 'Orientation', orientationDataI);
457                   
458                    add_line(parentAddr, [FromName '/1' ], [FromForceName '/1']);
459                    if size(DstName, 1) == 1
460
461                        add_line(parentAddr, [FromForceName '/1'], [DstName '/' int2str(DstPortNumber)]);
462                        %add_line(parentAddr, [FromName '/1' ], [DstName '/' int2str(DstPortNumber)]);
463                    else
464                        for i=1:size(DstName, 1)
465                            if ~strcmp(DstName{i}, get_param(dpramName, 'Name'))
466                                add_line(parentAddr, [FromName '/1'], [DstName{i} '/' mat2str(DstPortNumber(i))]);
467                            else
468                                add_line(parentAddr, [FromForceName '/1'], [DstName{i} '/' mat2str(DstPortNumber(i))]);
469                            end
470                        end
471                    end
472                else           
473                    placeDataI(1,1) = placeDataI(1,1) - 60;
474                    add_block('built-in/From', fromDataI, 'GotoTag', ['SMWODataI_' int2str(dpramWODataIIndex - 1)], 'position', placeDataI);
475
476                    FromName = get_param(fromDataI, 'Name');
477                    set_param(fromDataI,'Orientation', orientationDataI);
478
479                    if size(DstName, 1) == 1
480                        add_line(parentDataI, [FromName '/1' ], [DstName '/' int2str(DstPortNumber)]);
481                    else
482                        for i=1:size(DstName, 1)
483                            add_line(parentDataI, [FromName '/1'], [DstName{i} '/' mat2str(DstPortNumber(i))]);
484                        end
485                    end
486                end
487               
488                %%%%% SMWOWE %%%%%
489                if ~strcmp(get_param(SrcBlockHandleWE, 'block_type'), 'gatewayin')
490                    display(['A Gateway In is needed in order to connect to the web inport of the dpram ' dpramName '.']);
491                    return;
492                    end 
493                if ~strcmp(CompWEName(1:7), 'SMWOWE_')
494                    display(['The Gateway In ', WEName ' needs to have the prefix SMWOWE_']);
495                    return;
496                end
497                if ~strcmp(get_param(SrcBlockHandleWE, 'arith_type'), 'Boolean')
498                    display(['The GatewayIn ' WEFullName ' needs to have an Output type of Boolean.']);
499                    return;
500                end
501               
502                % Delete the GatewayIn
503                delete_block(SrcBlockHandleWE);
504
505                deleteSource(sys, cleanName(WEName));
506               
507                % Find the broken lines that starts from the output port of the
508                % deleted GatewayIn
509                brokenlines = find_system(sys,'LookUnderMasks', 'all', 'FollowLinks', 'on',  'FindAll', 'on', 'type', 'line', 'SrcBlockHandle', -1);
510
511                % Find out the handle of the port and the block
512                % These two handles will be used to extract more information
513                DstPortHandle = get_param(brokenlines, 'DstPortHandle');
514                DstBlockHandle = get_param(brokenlines, 'DstBlockHandle');
515
516                % From DstPortHandle, we can find out what is
517                % the destination port number
518                if length(DstPortHandle) > 1
519                    DstPortNumber = cell2mat(get_param(DstPortHandle{length(DstPortHandle)}, 'PortNumber'));
520                else
521                    DstPortNumber = get_param(DstPortHandle, 'PortNumber');
522                end
523
524                % From DstBlockHandle, we can find out what is the name of the
525                % destination block
526                if length(DstBlockHandle) > 1
527                    DstName = get_param(DstBlockHandle{length(DstBlockHandle)}, 'Name');
528                    try
529                        DstBlockType = get_param(DstBlockHandle{length(DstBlockHandle)}, 'block_type');
530                    catch
531                        DstBlockType = get_param(DstBlockHandle{length(DstBlockHandle)}, 'BlockType');
532                    end
533                else
534                    DstName = get_param(DstBlockHandle, 'Name');
535                    try
536                        DstBlockType = get_param(DstBlockHandle, 'block_type');
537                    catch
538                        DstBlockType = get_param(DstBlockHandle, 'BlockType');
539                    end
540                end
541
542                % Delete the borken lines
543                delete_line(brokenlines);
544
545                dpramWOWEIndex = dpramWOWEIndex + 1;
546                dpramWOWE{dpramWOWEIndex} = fromWE;
547                placeWE(1,1) = placeWE(1,1) - 60;
548                add_block('built-in/From', fromWE, 'GotoTag', ['SMWOWE_' int2str(dpramWOWEIndex - 1)], 'position', placeWE);
549               
550                FromName = get_param(fromWE, 'Name');
551                set_param(fromWE,'Orientation', orientationWE);
552
553                if size(DstName, 1) == 1
554                    add_line(parentWE, [FromName '/1' ], [DstName '/' int2str(DstPortNumber)]);
555                else
556                    for i=1:size(DstName, 1)
557                        add_line(parentWE, [FromName '/1'], [DstName{i} '/' mat2str(DstPortNumber(i))]);
558                    end
559                end
560               
561
562            elseif strcmp(compName(1:5), 'SMRO_')       
563                dpramROIndex = dpramROIndex + 1;
564               
565                DstBlockHandleDataO = get_param(get_param(ports(4), 'Line'), 'DstBlockHandle');
566               
567               
568                %%%%%% SMROAddr %%%%%
569                if ~strcmp(CompAddrName(1:9), 'SMROAddr_')
570                    display(['The Gateway In ' AddrName ' needs to have the prefix of SMROAddr_']);
571                    return;
572                end
573               
574                % Delete the GatewayIn
575                delete_block(SrcBlockHandleAddr);
576
577                deleteSource(sys, cleanName(AddrName));
578               
579                % Find the broken lines that starts from the output port of the
580                % deleted GatewayIn
581                brokenlines = find_system(sys,'LookUnderMasks', 'all', 'FollowLinks', 'on',  'FindAll', 'on', 'type', 'line', 'SrcBlockHandle', -1);
582
583                % Find out the handle of the port and the block
584                % These two handles will be used to extract more information
585                DstPortHandle = get_param(brokenlines, 'DstPortHandle');
586                DstBlockHandle = get_param(brokenlines, 'DstBlockHandle');
587
588                % From DstPortHandle, we can find out what is
589                % the destination port number
590                if length(DstPortHandle) > 1
591                    DstPortNumber = cell2mat(get_param(DstPortHandle{length(DstPortHandle)}, 'PortNumber'));
592                else
593                    DstPortNumber = get_param(DstPortHandle, 'PortNumber');
594                end
595
596                % From DstBlockHandle, we can find out what is the name of the
597                % destination block
598                if length(DstBlockHandle) > 1
599                    DstName = get_param(DstBlockHandle{length(DstBlockHandle)}, 'Name');
600                    try
601                        DstBlockType = get_param(DstBlockHandle{length(DstBlockHandle)}, 'block_type');
602                    catch
603                        DstBlockType = get_param(DstBlockHandle{length(DstBlockHandle)}, 'BlockType');
604                    end
605                else
606                    DstName = get_param(DstBlockHandle, 'Name');
607                    try
608                        DstBlockType = get_param(DstBlockHandle, 'block_type');
609                    catch
610                        DstBlockType = get_param(DstBlockHandle, 'BlockType');
611                    end
612                end
613
614                % Delete the borken lines
615                delete_line(brokenlines);
616
617                dpramROAddrIndex = dpramROAddrIndex + 1;
618                dpramROAddr{dpramROAddrIndex} = fromAddr;
619                %placeAddr(1,1) = placeAddr(1,1) - 60;
620                placeAddr(1,3) = placeAddr(1,1) + 75;
621                placeAddrSlice = placeAddr;
622                placeAddrSlice(1,1) = placeAddrSlice(1,3) + 30;
623                placeAddrSlice(1,3) = placeAddrSlice(1,1) + 50;
624                add_block('built-in/From', fromAddr, 'GotoTag', ['SMROAddr_' int2str(dpramROAddrIndex - 1)], 'position', placeAddr);
625               
626                if(( version == 8.1) | (version == 8.2) | (version == 9.1))
627                    add_block([spm '/Slice8'], fromAddrSlice, 'position', placeAddrSlice, 'nbits', fromAddrSliceBits);
628                end
629               
630                FromName = get_param(fromAddr, 'Name');
631                FromSliceName = get_param(fromAddrSlice, 'Name');
632                set_param(fromAddr,'Orientation', orientationAddr);
633
634                add_line(parentAddr, [FromName '/1' ], [FromSliceName '/1']);
635                if size(DstName, 1) == 1
636                   
637                    add_line(parentAddr, [FromSliceName '/1'], [DstName '/' int2str(DstPortNumber)]);
638                    %add_line(parentAddr, [FromName '/1' ], [DstName '/' int2str(DstPortNumber)]);
639                else
640                    for i=1:size(DstName, 1)
641                        if ~strcmp(DstName{i}, get_param(dpramName, 'Name'))
642                            add_line(parentAddr, [FromName '/1'], [DstName{i} '/' mat2str(DstPortNumber(i))]);
643                        else
644                            add_line(parentAddr, [FromSliceName '/1'], [DstName{i} '/' mat2str(DstPortNumber(i))]);
645                        end
646                    end
647                end
648
649                if ~strcmp(get_param(SrcBlockHandleDataI, 'block_type'), 'constant')
650                    display(['A Xilinx constant is needed in order to connect to the dinb inport of the dpram ' dpramName '.']);
651                    return;
652                end
653                if ~strcmp(CompDataIName(1:10), 'SMRODataI_')
654                    display(['The Xilinx block ' DataIName ' needs to have a prefix of SMRODataI_']);
655                    return;
656                end
657                if (str2num(get_param(SrcBlockHandleDataI, 'const')) ~= 0) | ~strcmp(get_param(SrcBlockHandleDataI, 'n_bits'), '32')
658                    display(['The Xilinx constant ' DataIFullName ' needs to have a constant value of zero. Number of bits needs to be 32.']);
659                    return;
660                end
661
662                if ~strcmp(get_param(SrcBlockHandleWE, 'block_type'), 'constant')
663                    display(['A Xilinx constant is needed in order to connect to the web inport of the dpram ' dpramName '.']);
664                    return;
665                end
666                if ~strcmp(CompWEName(1:7), 'SMROWE_')
667                    display(['The Gateway In ', WEName ' needs to have the prefix SMROWE_']);
668                    return;
669                end
670                if (str2num(get_param(SrcBlockHandleWE, 'const')) ~=0) | (~strcmp(get_param(SrcBlockHandleWE, 'arith_type'), 'Boolean'))
671                    display(['The Xilinx constant ' WEFullName ' needs to be a Boolean constant with a value of zero.']);
672                    return;
673                end
674
675                %%%%% SMRODataO %%%%%
676                DataOName = get_param(DstBlockHandleDataO, 'Name');
677                DataONameIdx = 1;
678                if length(DstBlockHandleDataO) == 1
679                    CompDataOName = [DataOName '          '];
680                    DataOFullName = [get_param(DstBlockHandleDataO, 'Parent') '/' DataOName];
681                else
682                    for i=1:length(DstBlockHandleDataO)
683                        CompDataOName{i} = [DataOName{i} '          '];
684                        DataOFullName{i} = [get_param(DstBlockHandleDataO(i), 'Parent') '/' DataOName{i}];                           
685                    end
686                end
687               
688                IsGatewayOut = false;
689               
690                for d=1:length(DstBlockHandleDataO)
691                    if strcmp(get_param(DstBlockHandleDataO(d), 'block_type'), 'gatewayout')
692                        IsGatewayOut = true;
693
694  Â