MORA99 9 Posted September 29, 2014 Share Posted September 29, 2014 I am trying to do some fast bit bang in C to see what is possible without going to asm. But I havent had much luck in doing a simple on/off or toggle using bit manipulation instead of calling digitalWrite. My noble attempt didnt really do much. uint16_t pin; uint8_t port; uint8_t mask; void setup() { pinMode(4, OUTPUT); pin = digital_pin_to_pin_num[4]; //PIN_03 GPIO_12 port = digital_pin_to_port[4]; //S1 mask = digital_pin_to_bit_mask[4]; //BV(4), /* 4 - GPIO_12 */ } void loop() { port ^= mask; delay(500); } I found digitalWrite in the sourcecode, and it calls MAP_GPIOPinWrite When then calls GPIOPinWrite or ROM_GPIOPinWrite Which then calls ASSERT and HWREG. So maybe I need to call HWREG to get as close to bit bang as possible ? By the way, I tested the digitalWrite function just to have a baseline, in a while(1) loop turning on and off the same pin, it gets 400ns pulses at 80MHz, so 32cycles if I did the math correctly. Quote Link to post Share on other sites
spirilis 1,265 Posted September 29, 2014 Share Posted September 29, 2014 Ok, so digital_pin_to_port gives you an index in another table of BASE registers... So it's more like: port = digital_pin_to_port[4]; uint32_t portBase = (uint32_t) portBASEregister(port); HWREG(portBase + (GPIO_O_GPIO_DATA + (mask << 2))) ^= mask; (haven't tested this yet btw) Otoh, reading about how that register math works on page 115 of the CC3200 TRM was kind've interesting. With the GPIO data register, bits [9:2] on the address bus form a mask of which bits are affected by the assigned value, hence the "+ (mask << 2)" part. Neat. MORA99 1 Quote Link to post Share on other sites
igor 163 Posted September 30, 2014 Share Posted September 30, 2014 If the CC3200 uses the same port handling as Tiva (which it sounds like it does) might find some of this helpful: http://forum.stellarisiti.com/topic/1983-howto-porting-libraries-some-help-needed/?p=6966 See: portMaskedOutputRegister(port, mask) Quote Link to post Share on other sites
MORA99 9 Posted October 1, 2014 Author Share Posted October 1, 2014 If the CC3200 uses the same port handling as Tiva (which it sounds like it does) might find some of this helpful: http://forum.stellarisiti.com/topic/1983-howto-porting-libraries-some-help-needed/?p=6966 See: portMaskedOutputRegister(port, mask) Thanks, eventually I will have tight loops ... then we see if its enough Quote Link to post Share on other sites
igor 163 Posted October 1, 2014 Share Posted October 1, 2014 Having to do the xor is probably slowing this down a bit, (means reading the port, doing xor). Loop of course slows down a lot. If you really need it tight, could maybe get the port in a particular state, then do a series of write 0, write 0xFF, write 0, .... (i.e. unroll the loop). Resulting code should load 0 and 0xFF into a couple of registers, then just be a series of writing alternate registers to the fixed port address (so you get one toggle per instruction). Should give an order of magnitude speedup. To go any faster than that would probably involve either a deep knowledge of the ARM instruction set/pipelines/etc., using special hardware (DMA, EPI, etc.), etc. Quote Link to post Share on other sites
MORA99 9 Posted October 2, 2014 Author Share Posted October 2, 2014 In the final code I will know what state it needs to be, for now its just testing to see what is possible. To run WS2811 code from c I need toggles around 30-70 cycles and some time left to pull the bytes from a array. Quote Link to post Share on other sites
igor 163 Posted October 2, 2014 Share Posted October 2, 2014 Assume you have looked at some of the code for driving such devices on Tiva. (Not sure how much overlap there is on the devices/libraries with CC3200, but expect it might help.) http://forum.stellarisiti.com/topic/2074-ws2812-driver http://forum.stellarisiti.com/topic/2107-ws2812b-matrix Quote Link to post Share on other sites
spirilis 1,265 Posted October 2, 2014 Share Posted October 2, 2014 A cursory look at the CC3200 TRM against the TM4C123GH6PM datasheet seems to reveal that the GPIO registers are organized/function similarly. Quote Link to post Share on other sites
MORA99 9 Posted October 3, 2014 Author Share Posted October 3, 2014 Yea maybe, I will come back to it later, coming from Avr 8bit its a bit of a transistion working with 32bit magically wifi box Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.