Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > Pointer problem

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Pointer problem
Moderator:
ARVI

Post Reply
Follow this topic



Pointer problem

kurti posted on 08 Jul 2011 10:47 PM PST

1 Forum Post

I added user module PWM8 3 times

PWM1, PWM2,PWM3

I wrote following code

typedef void (* const Function_Pass_Char)(char i);

static Function_Pass_Char SET_PWM[] = {
    &PWM1_WritePulseWidth,
    &PWM2_WritePulseWidth,
    &PWM3_WritePulseWidth,
}

void main(void){

SET_PWM[0](50);

}

 

code compiles fine, but the PWM(Pulsewidth value is not passed into A when calling the asm function

 PWM1_WritePulseWidth:
_PWM1_WritePulseWidth:
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov   reg[PWM1_COMPARE_REG], A                          using debug window register shows different value!!!???? not(0x32)
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
 

Any ideas???

 

 




Re: Pointer problem

pmad posted on 20 Jul 2011 06:53 AM PST
Cypress Employee
154 Forum Posts

 I tried the code snippet which you have provided and debugged the assembly code generated by the compiler. This is a compiler bug because when the function is called the values are always passed in A or X register but in the implementation of this routine the value is stored in stack. Thus, the code is not working as my function is taking the value of A and write into period register.

 

I have reported this problem to Imagecraft.

 

Best regards,

Pushek



Re: Pointer problem

TroyL posted on 27 Jul 2011 09:37 AM PST

1 Forum Post

I had a similar problem, and solved by using the code keyword as follows:

// Function pointer to PWM writes
code void (code *pwm_ptr[])(uint8 compare) =
{
	PWM_1_WriteCompare,
	PWM_2_WriteCompare,
	PWM_3_WriteCompare
};


void main()
{
	(*pwm_ptr[0])(50);
}

 






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20