part of a c-code

V

vicky

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;
}
 
R

Robert W Hand

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,153
Latest member
NamKaufman
Top