M
Mark
[Sorry if this is somewhat offtopic here, but I can't see another place with
a number of C-gurus]
I'm writing code for a communication processor with 25 port, where I need
to set up VLAN (virtual LAN) parameters for every port (bit0 is for port 0
be a member of group, bit1 is for port 2 and so on). It's fine, except that
each port is represented with two 16-bit registers: one has 16 bits valid,
and the second only 9.
Each register has the meaning "the ports which p1~p25 can forward to", so
for example if I want to set port {5, 6, 7, 8, 25} to be a in VLAN group A,
I set registers:
reg5-1 to 0x00f0, reg5-2 to 0x100 (for port 5)
reg6-1 to 0x00f0, reg6-2 to 0x100 (for port 6)
reg7-1 to 0x00f0, reg7-2 to 0x100 (for port 7)
reg8-1 to 0x00f0, reg8-2 to 0x100 (for port 8)
reg25-1 to 0x00f0, reg25-2 to 0x100 (for port 25)
So, I'm writing a function with two arguments (VLAN id and port number) to
set these registers, but I stuck with that the function should write values,
at the same time considering
int vlan_port_add(int unit, unsigned int vid, unsigned int port)
{
int p;
long portmask;
uint16_t val;
portmask = getPortmask(vid); /* current bitmask stored in NVRAM */
portmask |= 1 << (port - 1);
savePortmask(vid, portmask);
mask = portmask;
for (p = 0; p < PORT_MAX; p++) {
if (mask & 1) {
addr = R_VLAN_ENTRY_BASE + (p * 2); /* evaluate register
address */
val = portmask & 0x0000ffff; /* take bit[0..15] */
writeReg(unit, addr, val);
/* XXX */
}
mask >>= 1;
}
...
}
At XXX I can't find a way to write at both regs, because it appears that the
value of one register depends on another, suppose, I need ports 1 and 19 be
added the same group, which means when I begin running through 'portmask', I
don't yet know about 19th bit, and when I arrive to bit 19, there is no way
I can know about bit 1.
Is there appropriate method to solve this?
Would very much appreciate your suggestions!
a number of C-gurus]
I'm writing code for a communication processor with 25 port, where I need
to set up VLAN (virtual LAN) parameters for every port (bit0 is for port 0
be a member of group, bit1 is for port 2 and so on). It's fine, except that
each port is represented with two 16-bit registers: one has 16 bits valid,
and the second only 9.
Each register has the meaning "the ports which p1~p25 can forward to", so
for example if I want to set port {5, 6, 7, 8, 25} to be a in VLAN group A,
I set registers:
reg5-1 to 0x00f0, reg5-2 to 0x100 (for port 5)
reg6-1 to 0x00f0, reg6-2 to 0x100 (for port 6)
reg7-1 to 0x00f0, reg7-2 to 0x100 (for port 7)
reg8-1 to 0x00f0, reg8-2 to 0x100 (for port 8)
reg25-1 to 0x00f0, reg25-2 to 0x100 (for port 25)
So, I'm writing a function with two arguments (VLAN id and port number) to
set these registers, but I stuck with that the function should write values,
at the same time considering
int vlan_port_add(int unit, unsigned int vid, unsigned int port)
{
int p;
long portmask;
uint16_t val;
portmask = getPortmask(vid); /* current bitmask stored in NVRAM */
portmask |= 1 << (port - 1);
savePortmask(vid, portmask);
mask = portmask;
for (p = 0; p < PORT_MAX; p++) {
if (mask & 1) {
addr = R_VLAN_ENTRY_BASE + (p * 2); /* evaluate register
address */
val = portmask & 0x0000ffff; /* take bit[0..15] */
writeReg(unit, addr, val);
/* XXX */
}
mask >>= 1;
}
...
}
At XXX I can't find a way to write at both regs, because it appears that the
value of one register depends on another, suppose, I need ports 1 and 19 be
added the same group, which means when I begin running through 'portmask', I
don't yet know about 19th bit, and when I arrive to bit 19, there is no way
I can know about bit 1.
Is there appropriate method to solve this?
Would very much appreciate your suggestions!