Hi All,
The below is the snippet of code which i am working on .
i am wriiting a switch case to set each of the variables in structure .
Note : REG_ADDR is address of some say (0x1000) .
i will get channel as input ,based on that i am setting the registers as shown in "Compute" function.
Code:
/* Some header definitions */
---------------------------------
struct REG_TYPE_tag
{
int COUNT;
}REG_TYPE_T;
typedef struct TOTAL_REGS_tag
{
REG_TYPE_T SM0;
REG_TYPE_T SM1;
}TOTAL_REGS_T;
#define REG_ADDR (*( volatile TOTAL_REGS_T* )(0x1000 ))
----------------------------------------------------------------
"Compute" is a function which will just set the variable COUNT to a perticular value.
----------------------------------------------------------------------------
Code:
Void Compute(channel)
{ .....
switch(channel)
{
case 0 : REG_ADDR.SM0.COUNT = 10;
break;
case 1 : REG_ADDR.SM1.COUNT = 10;
break;
default :
break ;
}
}
----------------------------------
here in the above 'Compute' function if you see, only the
" SM(X) " is only changing in the case statements .
But is there a way where i can avoid "Switch" . and do like follwing
which will save me some lines of code
Code:
Compute(channel)
{
REG_ADDR.SM[channel].COUNT = 10;
}
Because i dont want to write so many switch cases
Note: i have taken part of code only in this ..
Are there any ways which is better in this case ?
Thanks
prabhakar