cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

Anonymous
Not applicable

Looking at the C example code made me realized that I don't know how to write my own code. For example, the example generates the following C code:

   
    

 CapSense_CSD_Start();

    

    /* Initialize baselines */
    CapSense_CSD_InitializeAllBaselines();

    

    /*when return value is 1, perform while loop*/
    while(1u)
    {
        /* Check whether the scanning of all enabled widgets is completed. */
        if(0u == CapSense_CSD_IsBusy())
        {
            /* Update all baselines */
            CapSense_CSD_UpdateEnabledBaselines();

    

            /* Start scanning all enabled sensors */
            CapSense_CSD_ScanEnabledWidgets();
        }

    

        /* Display CapSense state using LEDs */
        CapSense_DisplayState();
        
    }

   
   

I can't figure out where the "1u" comes from that the while() function is using (thus where the "0u" that the if statement is using).

   

I assume that some register is loaded with a value that is checked by the while() loop as a result of the call to "CapSense_CSD_InitializeAllBaselines();" However, the capsense data sheet states that no value is returned as a result of the call to "CapSense_CSD_InitializeAllBaselines();" 

   

So, is there a reference that I can read that would provide this information?

   

What would lead me to write "while(1u);" if I didn't see this in the example?

   

What if I had other modules that required use of the what() function, how would I differentiate what source the "1u" would be used for the while loops?

   

Sincerely, Jeff

0 Likes
Reply
1 Solution
JoMe_264151
Expert II

Embedded processor projects usually have an infinite loop, so they perform their job as long as power is applied.

   

"1u" means nothing more that "Take the constant number 1 as an unsigned int"

   

Because any value except 0 (zero) has the meaning of "true" in C-language the statement

   

while(1u)

   

is the infinite loop.

   

I (personally dislike this writing. I use

   

#define forever 1

   

and a

   

while(forever)

   

which is quite more readable.

   

 

   

Bob

View solution in original post

0 Likes
Reply
2 Replies
JoMe_264151
Expert II

Embedded processor projects usually have an infinite loop, so they perform their job as long as power is applied.

   

"1u" means nothing more that "Take the constant number 1 as an unsigned int"

   

Because any value except 0 (zero) has the meaning of "true" in C-language the statement

   

while(1u)

   

is the infinite loop.

   

I (personally dislike this writing. I use

   

#define forever 1

   

and a

   

while(forever)

   

which is quite more readable.

   

 

   

Bob

View solution in original post

0 Likes
Reply
Anonymous
Not applicable

Bob,

   

Thanks a lot! That makes sense. As I noted, I thought it was a returned value and it isn't. This shows how important it is to comment code clearly.

   

 

   

Sincerely, Jeff

0 Likes
Reply