How do I create a new component that prevents instancing?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Hi,

I've successfully created a simple component.  What I what to do is PREVENT instancing on this component.

I've imported the cy_boot_xx component which disallows instancing.  I reviewed the source code available, the properties and the Symbol parameters.

The only thing I noticed is the cy_boot_xx  property "Doc.DefaultInstanceName" is 'blank'.

When I try to set my component's property "Doc.DefaultInstanceName" to 'blank'.  The error message comes up "Property value is not valid" => "Illegal character".

What do I need to do to prevent instancing?  I just want to drop only one of these components on the schematic.  Only one is necessary.

Len.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
1 Solution

Again, I'm going to say this is not recommend and very strange to do.  But you can create an error when two instances are put down if you do something like this in a header file (assuming your component name was CP1):

#if !defined(CP1_`$INSTANCE_NAME`_H)

#define CP1_`$INSTANCE_NAME`_H

#if !defined(CP1_ONLY_ONE)

#define CP1_ONLY_ONE

#else

#error There can only be one instance of CP1

#endif

#endif

Users of course can import you component and change this behavior or simply disable code generation and edit to their hearts content.

View solution in original post

10 Replies
ScottA_91
Employee
Employee
10 solutions authored 100 replies posted 50 replies posted

CyBoot is special as you never actually see it on the schematic.  For any component you can drag and drop, there isn't a great way to prevent dropping multiple copies.  In general the fitter will give an error on overuse of resources.

I believe you can play some games with the c code that will give an error on compilation (just leave a nice comment as to why the user's getting an error) or there may be a way to create a DRC error on generating source if you see two copies.

0 Likes

Scott,

Thanks again for your assistance.

Since my original post here, I have been able to prevent incrementing instancing.  However, the component object still uses the instance (_1) when it creates the .h file.  I'd like to fix that too.

I'll look into the DRC checking.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Len,

I wonder how you were able to block incrementing instances? Can you share an example?

0 Likes
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hi

If you want to prevent instancing of the UDB Component you created then go to the .cysym page of the component created. Double click (select) the instance name on the component. delete the name and save. Now when you use the component in the schematic it will not have any instance name.

0 Likes

Ekta,

Thanks for the suggestion.  It didn't work.   I still had instancing occurring.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

Hi

I have build a simple project, see if this works for you.

0 Likes

EktaN,

I dropped two components on schematic and it compiles just fine. By "no instancing" I assume that only a single component can exist in schematic.

/odissey1

Instansing_01a.png

0 Likes

Again, I'm going to say this is not recommend and very strange to do.  But you can create an error when two instances are put down if you do something like this in a header file (assuming your component name was CP1):

#if !defined(CP1_`$INSTANCE_NAME`_H)

#define CP1_`$INSTANCE_NAME`_H

#if !defined(CP1_ONLY_ONE)

#define CP1_ONLY_ONE

#else

#error There can only be one instance of CP1

#endif

#endif

Users of course can import you component and change this behavior or simply disable code generation and edit to their hearts content.

ScottA,

Thank you for the hint. Do you think it is possible to add something similar to the customizer file so that it will throw Error if another instance is found?

/odissey1

0 Likes

Possible?  Sure, most things are possible given enough time and effort.  I suppose you could create a shape customizer and a semaphore for counting, and then use the count in the UI customizer.  That said I really don't recommend doing that.

The C code is far simpler and has a lot less gotchas to deal with.  For example, if you use the semaphore, you need to make sure it takes into account multiple projects, multiple schematic pages that could be enable/disabled, and multiple instances of Creator running.

0 Likes