By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

part of a c-code

P: n/a
Hi,

I have a function that checks or compare to see if the read value is same as
the written value in the register. (i.e. check if READ_value==WRITE_value in
REG_1)
It also checks if the READ==WRITE, then writes a value of 0x1 in REG_2.

Thank you for your suggestion, if the code below would do the same.
Kind regards,
vick

//--------------------------------------------------------------------------
---
// Function to check if the written value in the variable is same as the
read value
//--------------------------------------------------------------------------
---
int Prog(const Info *progInfo) {

int errors=0;
if (progInfo!=NULL) {
Regs RegPoint;
unsigned int i;
UInt32 tmp0;
int sig = 1;

/* Set registers base address */
RegPoint = (Regs)progInfo->location;

/* Write a value in the register */
// See if the value written in REG_1 writes a value in REG_2
PrintfMessage("Starting REG_2 test at %x\n", RegPoint);
RegPoint->REG_1 = 0x0F;
/* Read data of REG_1*/
/* See if REG_2 is triggered.... \n") */
tmp0 = RegPoint->REG_1;
if (tmp0 == 0x0F) {
sig = 0;
PrintfMessage("REG_2 is not triggered %x\n", RegPoint);
} else {
vhPrintfMessage("REG_2 is triggered %x\n", RegPoint);
}
PrintfMessage("Now clear the value in REG_2 %x\n", RegPoint);
RegPoint->REG_2 = 0x00;
return (sig);
}
return errors;
}
Apr 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Fri, 14 Apr 2006 22:41:43 +0200, "vicky" <vi***@yahoo.com> wrote:
Hi,

I have a function that checks or compare to see if the read value is same as
the written value in the register. (i.e. check if READ_value==WRITE_value in
REG_1)
It also checks if the READ==WRITE, then writes a value of 0x1 in REG_2.

Thank you for your suggestion, if the code below would do the same.
I do not see where 0x1 is written into REG_2. Please note that it is
hard to read code with unknown definitions.
//--------------------------------------------------------------------------
---
// Function to check if the written value in the variable is same as the
read value
//--------------------------------------------------------------------------
---
int Prog(const Info *progInfo) {

int errors=0;
if (progInfo!=NULL) {
I hate to read through a long body statement hoping that I do not miss
the ending brace. Why not just exit if progInfo is null?
Regs RegPoint;
unsigned int i;
UInt32 tmp0;
int sig = 1;

/* Set registers base address */
RegPoint = (Regs)progInfo->location;

/* Write a value in the register */
// See if the value written in REG_1 writes a value in REG_2
PrintfMessage("Starting REG_2 test at %x\n", RegPoint);
RegPoint->REG_1 = 0x0F;
/* Read data of REG_1*/
/* See if REG_2 is triggered.... \n") */
tmp0 = RegPoint->REG_1;
Did you mean 'tmp0 = RegPoint->REG_2;'? As written tmp0 must be 0x0f. if (tmp0 == 0x0F) {
How can this conditional not be true?
sig = 0;
PrintfMessage("REG_2 is not triggered %x\n", RegPoint);
} else {
vhPrintfMessage("REG_2 is triggered %x\n", RegPoint);
}
PrintfMessage("Now clear the value in REG_2 %x\n", RegPoint);
RegPoint->REG_2 = 0x00;


I thought that you wanted the value to be 0x1?

HTH.
--

Best wishes,

Bob
Apr 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.