nmem
Newbie level 4
Hello. I am confused in c programming when a function is called by (pointer to an instance). For example in the code below:
what could be the other method to re-write the code.?
mem
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 /** * Set the I2C bus speed in conjunction with the clock frequency. * param p_twi Pointer to a TWI instance. * ul_speed: The desired I2C bus speed (in Hz) (ul_speed to DesiredClock) * ul_mck: Main clock of the device (in Hz). (ul_mck to MainClock) * return value PASS\Fail New speed setting is accepted\rejected */ uint32_t twi_set_speed(Twi *p_twi, uint32_t ul_speed, uint32_t ul_mck) { uint32_t ckdiv = 0; uint32_t c_lh_div; if (ul_speed > I2C_FAST_MODE_SPEED) { return FAIL; } c_lh_div = ul_mck / (ul_speed * TWI_CLK_DIVIDER) - TWI_CLK_CALC_ARGU; /* cldiv must fit in 8 bits, ckdiv must fit in 3 bits */ while ((c_lh_div > TWI_CLK_DIV_MAX) && (ckdiv < TWI_CLK_DIV_MIN)) { /* Increase clock divider */ ckdiv++; /* Divide cldiv value */ c_lh_div /= TWI_CLK_DIVIDER; } /* set clock waveform generator register */ p_twi->TWI_CWGR = TWI_CWGR_CLDIV(c_lh_div) | TWI_CWGR_CHDIV(c_lh_div) | TWI_CWGR_CKDIV(ckdiv); return PASS; }
what could be the other method to re-write the code.?
mem
Last edited by a moderator: