Add reference C implementations for MultiU16X8toH16/MultiU24X24toH16
Higher step counts might still overflow the ASM MultiU24X24toH16.
e4595fa24a
This commit is contained in:
parent
30a806608f
commit
b8e8f182ca
@ -80,15 +80,21 @@ asm volatile ( \
|
|||||||
|
|
||||||
#else //_NO_ASM
|
#else //_NO_ASM
|
||||||
|
|
||||||
// NOTE: currently not implemented
|
static inline void MultiU16X8toH16(uint16_t& intRes, uint8_t& charIn1, uint16_t& intIn2)
|
||||||
void MultiU16X8toH16(unsigned short& intRes, unsigned char& charIn1, unsigned short& intIn2);
|
{
|
||||||
void MultiU24X24toH16(uint16_t& intRes, int32_t& longIn1, long& longIn2);
|
intRes = ((uint32_t)charIn1 * (uint32_t)intIn2) >> 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void MultiU24X24toH16(uint16_t& intRes, uint32_t& longIn1, uint32_t& longIn2)
|
||||||
|
{
|
||||||
|
intRes = ((uint64_t)longIn1 * (uint64_t)longIn2) >> 24;
|
||||||
|
}
|
||||||
|
|
||||||
#endif //_NO_ASM
|
#endif //_NO_ASM
|
||||||
|
|
||||||
|
|
||||||
FORCE_INLINE unsigned short calc_timer(uint16_t step_rate, uint8_t& step_loops) {
|
FORCE_INLINE unsigned short calc_timer(uint16_t step_rate, uint8_t& step_loops) {
|
||||||
unsigned short timer;
|
uint16_t timer;
|
||||||
if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY;
|
if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY;
|
||||||
|
|
||||||
if(step_rate > 20000) { // If steprate > 20kHz >> step 4 times
|
if(step_rate > 20000) { // If steprate > 20kHz >> step 4 times
|
||||||
@ -108,7 +114,7 @@ FORCE_INLINE unsigned short calc_timer(uint16_t step_rate, uint8_t& step_loops)
|
|||||||
if(step_rate >= (8*256)){ // higher step rate
|
if(step_rate >= (8*256)){ // higher step rate
|
||||||
unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0];
|
unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0];
|
||||||
unsigned char tmp_step_rate = (step_rate & 0x00ff);
|
unsigned char tmp_step_rate = (step_rate & 0x00ff);
|
||||||
unsigned short gain = (unsigned short)pgm_read_word_near(table_address+2);
|
uint16_t gain = (uint16_t)pgm_read_word_near(table_address+2);
|
||||||
MultiU16X8toH16(timer, tmp_step_rate, gain);
|
MultiU16X8toH16(timer, tmp_step_rate, gain);
|
||||||
timer = (unsigned short)pgm_read_word_near(table_address) - timer;
|
timer = (unsigned short)pgm_read_word_near(table_address) - timer;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user