Page 2 of 3
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:11 am
by Giovanni
mabl wrote:mabl wrote:Tectu,
I guess Giovanni wants you to learn the hard way by looking at the documentation

But to help you, why don't you do:
Code: Select all
palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d);
palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d);
palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d);
palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d);
My bad, I think it should read.
Code: Select all
palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4) << 0, LCD_DATA_PORT_1_BASE, d);
palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4) << 4, LCD_DATA_PORT_2_BASE, d);
palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4) << 8, LCD_DATA_PORT_2_BASE, d);
palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4) << 12, LCD_DATA_PORT_2_BASE, d);
The first one was correct, the mask does not need to be shifted. The function is a simple macro:
Code: Select all
palWritePort(port, (palReadLatch(port) & ~((mask) << (offset))) | \
(((bits) & (mask)) << (offset)))
"bits" and "mask" are shifted by "offset" internally.
Giovanni
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:13 am
by Giovanni
The STM32 version is optimized for the HW, it is implemented differently but does the same thing:
Code: Select all
#define pal_lld_writegroup(port, mask, offset, bits) \
((port)->BSRR.W = ((~(bits) & (mask)) << (16 + (offset))) | \
(((bits) & (mask)) << (offset)))
The advantage is that the above implementation is atomic, the default implementation in the previous post is not.
Giovanni
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:16 am
by mabl
Giovanni wrote:mabl wrote:mabl wrote:Tectu,
I guess Giovanni wants you to learn the hard way by looking at the documentation

But to help you, why don't you do:
Code: Select all
palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d);
palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d);
palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d);
palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d);
My bad, I think it should read.
Code: Select all
palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4) << 0, LCD_DATA_PORT_1_BASE, d);
palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4) << 4, LCD_DATA_PORT_2_BASE, d);
palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4) << 8, LCD_DATA_PORT_2_BASE, d);
palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4) << 12, LCD_DATA_PORT_2_BASE, d);
The first one was correct, the mask does not need to be shifted. The function is a simple macro:
Code: Select all
palWritePort(port, (palReadLatch(port) & ~((mask) << (offset))) | \
(((bits) & (mask)) << (offset)))
"bits" and "mask" are shifted by "offset" internally.
Giovanni
Hehe, I think it get's confusing quite quickly. But you are wrong, I missed the shifts on the data. So
Code: Select all
palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d >> 0);
palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 4);
palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 8);
palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 12);
Is my bet now. Hopfully it's correct now

Otherwise I just keep silent now.
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:18 am
by Giovanni
OMG, I missed that part

It should be final.
Giovanni
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:29 am
by Tectu
mabl wrote:Is my bet now. Hopfully it's correct now

Otherwise I just keep silent now.
Giovanni wrote:OMG, I missed that part

It should be final.
Giovanni
Still not right. This does the job:
Code: Select all
palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d >> 12);
palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 8);
palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_3_BASE, d >> 4);
palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_4_BASE, d >> 0);
@mabl: I am a guy who always reads the documentation first - I know how it is when you write a shitload of documentation and people don't even read it then. I wouldn't even know about the two macros, when I wouldn't have read it. I was just confused about the playing together with the mask and the offset. I tried to understand the macro, but because I didn', I asked here. I thought this forum might be there for such questions

Thank you for your help, guys!
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:37 am
by mabl
Hi Tectu,
this reverse shift order is only due on how you choose to label your ports. I'd propose to do it the other way around, since it's more common to start numbering from the lower bits.
What you could also think about is grouping several IOBus together and specify the shifts. That way you would be totally generic from how many ports you split. But I don't know the speed trade-off for that.
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:40 am
by Tectu
Hey mabl,
Yeah, I already took a look at the IOBus stuff after Giovanni pointed to it. I am not sure about the performance either. But the thing I worry more is the configuration. I couldn't figure out how to use it a way the configuration for the user is easy and the sourcecode is still clean and readable.
Maybe Giovanni can give some more informations to this?
~ Tectu
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:47 am
by Giovanni
The IOBus structure contains the same parameters of the "group" functions but bus functions have a performance impact compared to "groups". Groups are inlined and become a direct access to the GPIO register in the generated asm code.
The advantage with IOBus is that you could have those supplied from outside the library, you just do writes on the bus without knowing how it is done.
One thing I don't like is splitting the write in 4 operations, that will hurt performance a lot. You should assume from 1 to N "groups" of variable size (not always 4 bits).
The best way would be to expect an external write_lcd() function (for example) and do not try to abstract it internally, the integrator would have to provide the function.
Giovanni
Re: palWriteGroup() macro
Posted: Mon Jun 25, 2012 9:54 am
by Tectu
Giovanni wrote:The best way would be to expect an external write_lcd() function (for example) and do not try to abstract it internally, the integrator would have to provide the function.
That solutions dosen't sound that bad. That would be two functions (one writing 16-bit and one reading 16-bit).
I'll think about it. Thank you very much for your suggestion!
~ Tectu
Re: palWriteGroup() macro
Posted: Fri Sep 20, 2013 8:23 pm
by avtop
I want drive LCD that is 16bit wide data interface but I dosn't have single port 16bit wide free so palWriteGroup,IOBus,IOBus_DATA can I declare 2 port bits as SINGLE BUS
what is deference between palWriteGroup,palWriteBus and palWritePort