From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2707 invoked by alias); 4 Dec 2002 18:06:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 2686 invoked by uid 71); 4 Dec 2002 18:06:00 -0000 Resent-Date: 4 Dec 2002 18:06:00 -0000 Resent-Message-ID: <20021204180600.2685.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, michaelgcc@mytelescope.com Received: (qmail 2090 invoked from network); 4 Dec 2002 18:03:33 -0000 Received: from unknown (HELO sea.tw.teletrek.com) (142.163.64.9) by sources.redhat.com with SMTP; 4 Dec 2002 18:03:33 -0000 Received: (from michael@localhost) by sea.tw.teletrek.com (8.11.6/8.11.6) id gB4I3gg05684; Wed, 4 Dec 2002 14:33:42 -0330 Message-Id: <200212041803.gB4I3gg05684@sea.tw.teletrek.com> Date: Wed, 04 Dec 2002 10:06:00 -0000 From: michaelgcc@mytelescope.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: 3.113 Subject: target/8812: Registers allocated for two uses at once X-SW-Source: 2002-12/txt/msg00224.txt.bz2 List-Id: >Number: 8812 >Category: target >Synopsis: Registers allocated for two uses at once >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Wed Dec 04 10:06:00 PST 2002 >Closed-Date: >Last-Modified: >Originator: Michael Rendell >Release: 3.3 20021202 (experimental) >Organization: >Environment: System: Linux sea 2.4.18-17.7.x #1 Tue Oct 8 11:34:32 EDT 2002 i686 unknown Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: avr-unknown-none configured with: ./configure --target=avr --enable-languages=c --prefix=/opt/avr-tools-20021202 >Description: The machine code generated for: int32_t offset2MatchDest = offset2Dest - matchOffset; allocates registers 24,25,26,27 for offset2Dest and registers 22,23,24,25 for matchOffset. Thus registers 24,25 are used twice and the result of the subtraction is incorrect. The generated code is; .stabn 68,0,252,.LM20-mc_motionControl .LM20: movw r26,r12 movw r24,r10 ldd r22,Y+5 ldd r23,Y+6 ldd r24,Y+7 ldd r25,Y+8 sub r24,r22 sbc r25,r23 sbc r26,r24 sbc r27,r25 This problem also exists in the 20021021 snapshot. >How-To-Repeat: Run: avr-gcc -mmcu=atmega323 -Wall -Wstrict-prototypes -Os -g -S mx.c on the input: # 1 "mx.c" # 1 "" # 1 "" # 1 "mx.c" # 1 "/opt/avr-tools-20021202/avr/include/stdlib.h" 1 3 # 41 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 # 1 "/opt/avr-tools-20021202/lib/gcc-lib/avr/3.3/include/stddef.h" 1 3 4 # 213 "/opt/avr-tools-20021202/lib/gcc-lib/avr/3.3/include/stddef.h" 3 4 typedef unsigned int size_t; # 325 "/opt/avr-tools-20021202/lib/gcc-lib/avr/3.3/include/stddef.h" 3 4 typedef int wchar_t; # 42 "/opt/avr-tools-20021202/avr/include/stdlib.h" 2 3 # 60 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 typedef struct { int quot; int rem; } div_t; typedef struct { long quot; long rem; } ldiv_t; typedef int (*__compar_fn_t)(const void *, const void *); # 94 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern __inline__ void abort(void) __attribute__((__noreturn__)); extern __inline__ void abort(void) { for (;;); } extern int abs(int __i) __attribute__((__const__)); # 117 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern long labs(long __i) __attribute__((__const__)); # 140 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern void *bsearch(const void *__key, const void *__base, size_t __nmemb, size_t __size, int (*__compar)(const void *, const void *)); extern div_t div(int __num, int __denom) __asm__("__divmodhi4") __attribute__((__const__)); extern ldiv_t ldiv(long __num, long __denom) __asm__("__divmodsi4") __attribute__((__const__)); # 172 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern void qsort(void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar); # 205 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern long strtol(const char *__nptr, char **__endptr, int __base); # 239 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern unsigned long strtoul(const char *__nptr, char **__endptr, int __base); # 249 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern __inline__ long atol(const char *__nptr) __attribute__((__pure__)); extern __inline__ long atol(const char *__nptr) { return strtol(__nptr, (char **) 0, 10); } # 273 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern int atoi(const char *) __attribute__((__pure__)); # 285 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern void exit(int __status) __attribute__((__noreturn__)); # 297 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern void *malloc(size_t __size) __attribute__((__malloc__)); extern void free(void *__ptr); extern size_t __malloc_margin; extern char *__malloc_heap_start; extern char *__malloc_heap_end; extern void *calloc(size_t __nele, size_t __size) __attribute__((__malloc__)); # 361 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern double strtod(const char *__nptr, char **__endptr); # 383 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern int rand(void); extern void srand(unsigned int __seed); extern int rand_r(unsigned long *ctx); # 413 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern char *itoa(int __val, char *__s, int __radix); # 428 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern char *ltoa(long int __val, char *__s, int __radix); # 443 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern char *utoa(unsigned int __val, char *__s, int __radix); # 459 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern char *ultoa(unsigned long int __val, char *__s, int __radix); # 477 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern long random(void); extern void srandom(unsigned long __seed); extern long random_r(unsigned long *ctx); # 530 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern char *dtostre(double __val, char *__s, unsigned char __prec, unsigned char __flags); # 543 "/opt/avr-tools-20021202/avr/include/stdlib.h" 3 extern char *dtostrf(double __val, char __width, char __prec, char *__s); # 2 "mx.c" 2 # 1 "/opt/avr-tools-20021202/avr/include/avr/pgmspace.h" 1 3 # 57 "/opt/avr-tools-20021202/avr/include/avr/pgmspace.h" 3 # 1 "/opt/avr-tools-20021202/lib/gcc-lib/avr/3.3/include/stddef.h" 1 3 4 # 58 "/opt/avr-tools-20021202/avr/include/avr/pgmspace.h" 2 3 # 77 "/opt/avr-tools-20021202/avr/include/avr/pgmspace.h" 3 typedef void prog_void __attribute__((__progmem__)); typedef char prog_char __attribute__((__progmem__)); typedef unsigned char prog_uchar __attribute__((__progmem__)); typedef int prog_int __attribute__((__progmem__)); typedef long prog_long __attribute__((__progmem__)); typedef long long prog_long_long __attribute__((__progmem__)); # 159 "/opt/avr-tools-20021202/avr/include/avr/pgmspace.h" 3 static inline unsigned char __lpm_inline(unsigned short __addr) __attribute__((__const__)); static inline unsigned char __lpm_inline(unsigned short __addr) { return ({ unsigned short __addr16 = (unsigned short)(__addr); unsigned char __result; __asm__ ( "lpm %0, Z" : "=r" (__result) : "z" (__addr16) ); __result; }); } # 209 "/opt/avr-tools-20021202/avr/include/avr/pgmspace.h" 3 extern void *memcpy_P(void *, const prog_void *, size_t); extern char *strcat_P(char *, const prog_char *); extern int strcmp_P(const char *, const prog_char *) __attribute__((__pure__)); extern char *strcpy_P(char *, const prog_char *); extern int strcasecmp_P(const char *, const prog_char *) __attribute__((__pure__)); extern size_t strlen_P(const prog_char *) __attribute__((__const__)); extern int strncmp_P(const char *, const prog_char *, size_t) __attribute__((__pure__)); extern int strncasecmp_P(const char *, const prog_char *, size_t) __attribute__((__pure__)); extern char *strncpy_P(char *, const prog_char *, size_t); # 3 "mx.c" 2 # 1 "/opt/avr-tools-20021202/avr/include/string.h" 1 3 # 38 "/opt/avr-tools-20021202/avr/include/string.h" 3 # 1 "/opt/avr-tools-20021202/lib/gcc-lib/avr/3.3/include/stddef.h" 1 3 4 # 39 "/opt/avr-tools-20021202/avr/include/string.h" 2 3 # 57 "/opt/avr-tools-20021202/avr/include/string.h" 3 extern void *memccpy(void *, const void *, int, size_t); extern void *memchr(const void *, int, size_t) __attribute__((__pure__)); extern int memcmp(const void *, const void *, size_t) __attribute__((__pure__)); extern void *memcpy(void *, const void *, size_t); extern void *memmove(void *, const void *, size_t); extern void *memset(void *, int, size_t); extern char *strcat(char *, const char *); extern char *strchr(const char *, int) __attribute__((__pure__)); extern int strcmp(const char *, const char *) __attribute__((__pure__)); extern char *strcpy(char *, const char *); extern int strcasecmp(const char *, const char *) __attribute__((__pure__)); extern size_t strlcat(char *, const char *, size_t); extern size_t strlcpy(char *, const char *, size_t); extern size_t strlen(const char *) __attribute__((__pure__)); extern char *strlwr(char *); extern char *strncat(char *, const char *, size_t); extern int strncmp(const char *, const char *, size_t); extern char *strncpy(char *, const char *, size_t); extern int strncasecmp(const char *, const char *, size_t) __attribute__((__pure__)); extern size_t strnlen(const char *, size_t) __attribute__((__pure__)); extern char *strrchr(const char *, int) __attribute__((__pure__)); extern char *strrev(char *); extern char *strstr(const char *, const char *) __attribute__((__pure__)); extern char *strupr(char *); # 4 "mx.c" 2 # 1 "../../libavr/hack.h" 1 # 5 "mx.c" 2 # 1 "../../libavr/misc.h" 1 # 6 "mx.c" 2 # 1 "../../libavr/timer2.h" 1 # 1 "/opt/avr-tools-20021202/avr/include/inttypes.h" 1 3 # 46 "/opt/avr-tools-20021202/avr/include/inttypes.h" 3 typedef signed char int8_t; typedef unsigned char uint8_t; typedef int int16_t; typedef unsigned int uint16_t; typedef long int32_t; typedef unsigned long uint32_t; typedef long long int64_t; typedef unsigned long long uint64_t; typedef int16_t intptr_t; typedef uint16_t uintptr_t; # 5 "../../libavr/timer2.h" 2 extern void timer2_init( int clockFreq ); extern uint16_t timer2_getMS(void); extern void timer2_getTimeToMS(uint32_t *secsp, uint16_t *msp); extern uint32_t periodicTimer_secs; extern uint16_t periodicTimer_msec; # 7 "mx.c" 2 # 1 "../../libavr/isqrt.h" 1 # 40 "../../libavr/isqrt.h" extern uint16_t isqrt_uint16(uint16_t m); extern uint32_t isqrt_uint32(uint32_t m); extern uint64_t isqrt_uint64(uint64_t m); # 8 "mx.c" 2 # 1 "../motorCntlr/iomap.h" 1 # 1 "/opt/avr-tools-20021202/avr/include/avr/io.h" 1 3 # 81 "/opt/avr-tools-20021202/avr/include/avr/io.h" 3 # 1 "/opt/avr-tools-20021202/avr/include/avr/iom323.h" 1 3 # 43 "/opt/avr-tools-20021202/avr/include/avr/iom323.h" 3 # 1 "/opt/avr-tools-20021202/avr/include/avr/sfr_defs.h" 1 3 # 44 "/opt/avr-tools-20021202/avr/include/avr/iom323.h" 2 3 # 82 "/opt/avr-tools-20021202/avr/include/avr/io.h" 2 3 # 5 "../motorCntlr/iomap.h" 2 # 1 "../../libavr/iomap.h" 1 # 1 "../../libavr/bool.h" 1 # 9 "../../libavr/bool.h" typedef uint8_t bool; # 5 "../../libavr/iomap.h" 2 extern void iomap_setLed(bool val); extern void iomap_setDebug0(bool val); extern void iomap_setDebug1(bool val); extern void iomap_setDebug2(bool val); extern void iomap_setDebug3(bool val); extern void iomap_setDebug4(bool val); extern void iomap_setDebug5(bool val); extern void iomap_setDebug6(bool val); extern void iomap_setDebug7(bool val); # 6 "../motorCntlr/iomap.h" 2 # 145 "../motorCntlr/iomap.h" extern inline uint8_t iomap_getIdent0( void ) { return ((*(volatile unsigned char *)(((unsigned int) &((*(volatile unsigned char *)((0x16) + 0x20)))))) & (1 << (1))); } extern inline void iomap_setStegTXE(bool val) { if (val) (*(volatile unsigned char *)((0x12) + 0x20)) |= (1 << (4)); else (*(volatile unsigned char *)((0x12) + 0x20)) &= ~(1 << (4)); } extern void iomap_init(void); # 9 "mx.c" 2 # 1 "../motorCntlr/motionControl.h" 1 # 1 "../motorCntlr/app.h" 1 # 1 "../../scopeMI/scope-controller.h" 1 # 10 "../../scopeMI/scope-controller.h" # 1 "../../libavr/errors-common.h" 1 # 12 "../../libavr/errors-common.h" enum { ERR_NONE = 0, ERR_CMD_UNKNOWN, ERR_PARAM_LEN, ERR_PARAM_INVALID, ERR_RESP_LEN, ERR_INTERNAL, ERR_UNIMPLEMENTED, ERR_PROTO_SEND_WHILE_SENDING, ERR_PROTO_SEND_TOO_BIG, ERR_PROTO_SEND_FAILED, ERR_PROTO_LINK_FAILED, ERR_PROTO_APP_EVENT_BAD, ERR_TWI__START, ERR_TWI_UNEXPECTED_TWSR = ERR_TWI__START, ERR_TWI_SEND_NOT_IDLE, ERR_TWI_SEND_BAD_LEN, ERR_TWI_SEND_TO_SELF, ERR_TWI_SEND_TO_NO_ONE, ERR_TWI_RESET_NOT_IDLE, ERR_TWI_RESET_TO_SELF, ERR_TWI_LINK_FAILED, ERR_TWI_TIMEOUT, ERR_TWI_NO_RESPONSE, ERR_TWI_ARB_LOST, ERR_TWI_BAD_CSUM, ERR_TWI_BAD_LEN, ERR_TWI_OVERFLOW, ERR_TWI_OVERRUN, ERR_TWI_DATA_NACK, ERR_TWI_NO_SEQ_MAP, ERR_TWI_NO_LINK, ERR_TWI_APP_EVENT_BAD, ERR_STEG_FRAMING, ERR_STEG_OVERRUN, ERR_STEG_PARITY, ERR_STEG_CSUM, ERR_STEG_OVERFLOW, ERR_STEG_ERROR, ERR_STEG_ERROR_STATUS, ERR_STEG_CMD_MISMATCH, ERR__APP_SPEC }; # 11 "../../scopeMI/scope-controller.h" 2 enum { ERR_SCOPE_BUSY = ERR__APP_SPEC, ERR_CU_TWI_RESET, ERR_CU_BAD_RESPONSE, ERR_STATE_INVALID, ERR_STEG_SERIAL_TIMEOUT, ERR_MEMORY_BUSY, ERR_FLASH_PAGE_WRITE_FAILED, ERR_SOFT_MOTION_LIMIT, }; enum { SC_CMD_RESP_ERR = '0', SC_CMD_RESP_OK = '1', }; enum { SC_CMD__UNINITIALIZED = 0, SC_CMD_RESET = 'R', SC_CMD_TWI_RESET = 'I', SC_CMD_VERSION = 'v', SC_CMD_GET_UPTIME = 'u', SC_CMD_PING = 'p', SC_CMD_GET_STATUS = 'a', SC_CMD_GET_POSITION = 'o', SC_CMD_FIND_ROTATION_POSITION = 'F', SC_CMD_STOP = 's', SC_CMD_GET_POSITION_PARAM = 'z', SC_CMD_SET_POSITION_PARAM = 'Z', SC_CMD_GET_TRACKING_RATE = 't', SC_CMD_SET_TRACKING_RATE = 'T', SC_CMD_GOTO_POSITION = 'G', SC_CMD_SLEW_START = 'S', SC_CMD_MEMORY_READ = 'm', SC_CMD_MEMORY_WRITE = 'M', SC_CMD_CHANGE_MODE = 'X', SC_CMD_DEBUG = 'D', SC_CMD_FILL_BUFFER = 'f', SC_CMD_WRITE_FLASH_PAGE = 'W', }; # 83 "../../scopeMI/scope-controller.h" enum { SC_CMD_STOP_SLEW_GOTO = 0, SC_CMD_STOP_ALL = 1, SC_CMD_STOP_ALL_IMMEDIATE = 2, }; enum { SC_CMD_POS_PARAM_ZERO_POSITION, SC_CMD_POS_PARAM_HARD_MOTION_LIMIT_LOW, SC_CMD_POS_PARAM_HARD_MOTION_LIMIT_HIGH, SC_CMD_POS_PARAM_ALIGN_POSITION, }; enum { SC_CU__UNINITIALIZED = 0, SC_CU_HUB = 1, SC_CU_LHA = 2, SC_CU_DEC = 3, SC_CU__MAX, SC_CU__MIN = SC_CU_HUB, }; enum { SC_AS__UNINITIALIZED = 0, SC_AS_TEXT = 1, SC_AS_DATA = 2, SC_AS_EEPROM = 3, SC_AS_FUSE = 4, }; enum { SC_CMD_CHANGE_MODE__UNINITIALIZED = 0, SC_CMD_CHANGE_MODE_DOWNLOAD, SC_CMD_CHANGE_MODE_APP, }; enum { SC_ST__UNINITIALIZED = 0, SC_ST_ERROR, SC_ST_INIT, SC_ST_UNCONFIGURED, SC_ST_ROTATION_UNKNOWN, SC_ST_ROTATION_FIND, SC_ST__OPERATIONAL, SC_ST_IDLE = SC_ST__OPERATIONAL, SC_ST_STOPPING, SC_ST_TRACKING, SC_ST_SLEWING, SC_ST_GOING_TO, SC_ST_MONITOR, }; enum { SC_MEMIO_SIZE_MAX = 40, }; enum { SC_SLAVE_WATCHDOG_POLL_MS = 1000, SC_SLAVE_WATCHDOG_TIMEOUT_MS = SC_SLAVE_WATCHDOG_POLL_MS * 2, }; enum { SC_EEPROM__VALID_VALUE = 0xa5, SC_EEPROM__INVALID_VALUE = 0xff, SC_EEPROM__WRITE_MAX = 16, SC_EEPROM_ZERO_POS_VALID = 0, SC_EEPROM_ZERO_POS_SIZE = 4, SC_EEPROM_HARD_MOTION_LIMIT_LOW_VALID = 5, SC_EEPROM_HARD_MOTION_LIMIT_LOW_SIZE = 4, SC_EEPROM_HARD_MOTION_LIMIT_HIGH_VALID = 10, SC_EEPROM_HARD_MOTION_LIMIT_HIGH_SIZE = 4, SC_EEPROM_ALIGN_POS_VALID = 15, SC_EEPROM_ALIGN_POS_SIZE = 4, }; typedef int32_t rPos_t; typedef uint32_t rDist_t; typedef int32_t rVelocity_t; typedef uint32_t rSpeed_t; # 6 "../motorCntlr/app.h" 2 enum { AES__UNINITIALIZED = 0, AES_TWI, AES_APP, AES_STEG_SERIAL, AES_EEPROM, AES_MOTION_CONTROL, }; struct app_pos { uint32_t stegPos; rDist_t zeroedRPos; int8_t wrapCount; rPos_t rPos; uint32_t sec; uint16_t ms; }; enum { ACF_ZERO_POSITION = 1, ACF_HARD_MOTION_LIMIT_LOW = 2, ACF_HARD_MOTION_LIMIT_HIGH = 4, ACF_ALIGN_POSITION = 8, ACF__REQUIRED = ACF_ZERO_POSITION|ACF_HARD_MOTION_LIMIT_LOW |ACF_HARD_MOTION_LIMIT_HIGH, }; struct app_config { uint8_t configuredFlags; rDist_t zeroPosition; rPos_t hardMotionLimitLow; rPos_t hardMotionLimitHigh; rPos_t alignPosition; rPos_t softMotionLimitLow; rPos_t softMotionLimitHigh; }; extern struct app_config app_config; extern void app_logError(uint8_t errorSource, uint8_t err, uint8_t info); extern void app_steg_setWrapCount(int8_t wrapCount); # 7 "../motorCntlr/motionControl.h" 2 extern void mc_init(void); extern void mc_timingEvents(void); extern bool mc_canChangeConfig(void); extern bool mc_canEnterDownload(void); extern uint8_t mc_getState(void); extern rVelocity_t mc_getTrackingRate(void); extern void mc_configChanged(void); extern void mc_positionUpdate(const struct app_pos *pos); extern uint8_t mc_stop(uint8_t stopMode); extern uint8_t mc_findRotationPosition(void); extern uint8_t mc_setTracking(rVelocity_t rate); extern uint8_t mc_goto(rPos_t rPos); extern uint8_t mc_slewStart(rDist_t dist, rVelocity_t rate); # 10 "mx.c" 2 # 1 "../motorCntlr/main.h" 1 # 11 "mx.c" 2 # 1 "../motorCntlr/motor.h" 1 # 12 "../motorCntlr/motor.h" enum { MOT_DIR_NEUTRAL, MOT_DIR_PLUS, MOT_DIR_MINUS, }; enum { MOT_MODE__UNINITIALIZED, MOT_MODE_PWM, MOT_MODE_INTR, }; # 32 "../motorCntlr/motor.h" enum { MOT_PWM_PS_MASK = 0xf, MOT_PWM_PS_SHIFT = 0, MOT_PWM_WIDTH_MASK = 0x3, MOT_PWM_WIDTH_SHIFT = 4, MOT_PWM_CENTERED = 0x40, }; struct motorParams { bool mode; uint8_t pwmBits; uint16_t pwmMatch; uint16_t periodUPS; uint16_t onUPS; uint8_t nOnCycles; }; extern void motor_init(void); extern void motor_setDir(uint8_t dir); extern void motor_stop(void); extern bool motor_setParams(const struct motorParams *params); # 12 "mx.c" 2 # 47 "mx.c" typedef int32_t rAccel_t; struct mc_velocityInfo { rVelocity_t velocity; }; struct mc_velocityHistory { struct mc_velocityInfo average; struct mc_velocityInfo totals; bool prevValid; struct app_pos prevPos; uint8_t nextEntry; uint8_t nEntries; struct mc_velocityInfo entries[16]; }; struct mc_speedEntry { rSpeed_t requiredSpeedMin; rSpeed_t requiredSpeedMax; uint16_t sampleIntervalMS; uint16_t minChangeIntervalMS; uint16_t tweakRangeMin; rSpeed_t tweakSpeedMin; uint16_t tweakRangeMax; rSpeed_t tweakSpeedMax; uint16_t tweakStepMax; rAccel_t accel; uint32_t speedTweakSlope; struct motorParams motorParams; }; enum { MC_RFS__UNINITIALIZED = 0, MC_RFS_INIT, }; struct mc_state { uint8_t amLHA; uint8_t stateMajor; uint16_t minChangeIntervalMSMAX; uint8_t rotFindState; int16_t rotFindWaitMS; struct app_pos pos; rDist_t positionTolerance; rPos_t destination; rSpeed_t maxSpeed; bool lockedOnTarget; rVelocity_t trackingVelocity; rSpeed_t trackingSpeedClose; rSpeed_t trackingSpeed; uint8_t trackingDir; uint16_t trMS; rPos_t trAmountDone; uint8_t motorDir; bool motorOn; uint8_t lastMotorChangeSpeed; uint32_t lastMotorChangeSec; uint16_t lastMotorChangeMS; struct motorParams motorParams; uint8_t lastSpeedTableIndex; uint32_t targetLostCount; }; enum { MC_CS__UNINITIALIZED, MC_CS_DECREASE, MC_CS_INCREASE, }; # 149 "mx.c" static struct mc_speedEntry mc_speedTable[] = { { 0, 3000ul * ((1L << (20 + 8)) / (1L << 20)), (10 * 2), (0) * (10 * 2), (0), (0), (0), (0), (0), (0) > 0 ? ((1000LL * ((0) - (0)) * (0)) / ((uint32_t) ((0) - (0)) * ((0) * (10 * 2)))) : 0, (0) > 0 ? ((0) - (0)) / (uint32_t) ((0) - (0)) : 0, # 160 "mx.c" { MOT_MODE__UNINITIALIZED, (((0) ? MOT_PWM_CENTERED : 0) | ((((0) - 8) & MOT_PWM_WIDTH_MASK) << MOT_PWM_WIDTH_SHIFT) | (((0) & MOT_PWM_PS_MASK) << MOT_PWM_PS_SHIFT)), 0, ((uint16_t) ((0) * 20000ul / 1000ul)), ((uint16_t) ((0) * 20000ul / 1000ul)), 0, }, }, }; static struct mc_velocityHistory mc_velocityHistory; static struct mc_state mc_state; extern void mc_deactivate(void); extern void mc_motionControl(void); extern rSpeed_t mc_deltaV(rDist_t dist2Dest); extern bool mc_updateVelocityHistory(void); extern void mc_setVelocity(rVelocity_t Vdesired); extern rPos_t mc_matchVelocityDist(rVelocity_t Vc, rVelocity_t Vt); extern rVelocity_t mc_desiredVelocity(rVelocity_t Vbase, rPos_t offset2MatchDest); static struct motionControl_errorInfo { uint16_t count; uint16_t max; uint8_t origSTI; rVelocity_t averageVelocity; rVelocity_t avgRelativeVelocity; rPos_t offset2Dest; rPos_t matchOffset; rPos_t offset2MatchDest; rPos_t fudge; rVelocity_t Vdesired; rVelocity_t finalVdesired; uint8_t finalSTI; uint8_t flag; int16_t decelHack; rVelocity_t decelVelocity; rPos_t decelStartMO; struct app_pos decelStartPos; rVelocity_t decelEndMO; struct app_pos decelEndPos; rPos_t decelDeltaPos; uint32_t decelDeltaT; uint8_t decelIndex; struct { uint8_t stI; uint16_t cnt; rPos_t rPos; } decelHist[7]; } motionControl_errorInfo; void mc_motionControl(void) { if (!mc_updateVelocityHistory()) return; if (mc_state.stateMajor == SC_ST_IDLE) { if (mc_state.motorOn || mc_state.motorDir != MOT_DIR_NEUTRAL) { mc_setVelocity(0); } return; } if (motionControl_errorInfo.max) { if (motionControl_errorInfo.count >= motionControl_errorInfo.max) return; ++motionControl_errorInfo.count; if (motionControl_errorInfo.count == motionControl_errorInfo.max) { mc_deactivate(); return; } } rVelocity_t averageVelocity = mc_velocityHistory.average.velocity; rSpeed_t averageSpeed = __builtin_labs(averageVelocity); rVelocity_t avgRelativeVelocity = averageVelocity - mc_state.trackingVelocity; rSpeed_t avgRelativeSpeed = __builtin_labs(avgRelativeVelocity); motionControl_errorInfo.origSTI = mc_state.lastSpeedTableIndex; motionControl_errorInfo.averageVelocity = averageVelocity; motionControl_errorInfo.avgRelativeVelocity = avgRelativeVelocity; rPos_t offset2Dest = mc_state.destination - mc_state.pos.rPos; rDist_t dist2Dest = __builtin_labs(offset2Dest); rPos_t matchOffset = mc_matchVelocityDist(averageVelocity, mc_state.trackingVelocity); rPos_t offset2MatchDest = offset2Dest - matchOffset; motionControl_errorInfo.offset2Dest = offset2Dest; motionControl_errorInfo.matchOffset = matchOffset; motionControl_errorInfo.offset2MatchDest = offset2MatchDest; rVelocity_t Vdesired; Vdesired = mc_desiredVelocity(averageVelocity, offset2MatchDest); motionControl_errorInfo.Vdesired = Vdesired; if (motionControl_errorInfo.max && Vdesired < 0) { motionControl_errorInfo.count = motionControl_errorInfo.max; mc_deactivate(); return; } # 280 "mx.c" rPos_t mo = matchOffset; if (averageSpeed < mc_state.trackingSpeed) mo = -mo; rSpeed_t deltaV = mc_deltaV(offset2Dest); if (Vdesired > mc_state.trackingVelocity + (rVelocity_t) deltaV) Vdesired = mc_state.trackingVelocity + (rVelocity_t) deltaV; else if (Vdesired < mc_state.trackingVelocity - (rVelocity_t) deltaV) Vdesired = mc_state.trackingVelocity - (rVelocity_t) deltaV; if (motionControl_errorInfo.decelHack) { if (motionControl_errorInfo.decelHack > 0) { if (mc_state.lastSpeedTableIndex == (sizeof(mc_speedTable) / sizeof((mc_speedTable)[0])) - 1 && mc_state.motorParams.pwmMatch <= 1) { if (--motionControl_errorInfo.decelHack == 0) { motionControl_errorInfo.decelHack = -1; motionControl_errorInfo.decelVelocity = averageVelocity; motionControl_errorInfo.decelStartMO = matchOffset; motionControl_errorInfo.decelStartPos = mc_state.pos; motionControl_errorInfo.decelIndex = 0; motionControl_errorInfo.decelHist[0].stI = mc_state.lastSpeedTableIndex; motionControl_errorInfo.decelHist[0].cnt = 0; motionControl_errorInfo.decelHist[0].rPos = mc_state.pos.rPos; } } } else { Vdesired = 0; uint8_t di = motionControl_errorInfo.decelIndex; if (di < (sizeof(motionControl_errorInfo.decelHist) / sizeof((motionControl_errorInfo.decelHist)[0]))) { if (motionControl_errorInfo.decelHist[di].stI != mc_state.lastSpeedTableIndex) { ++motionControl_errorInfo.decelIndex; ++di; if (di < (sizeof(motionControl_errorInfo.decelHist) / sizeof((motionControl_errorInfo.decelHist)[0]))) { motionControl_errorInfo.decelHist[di].stI = mc_state.lastSpeedTableIndex; motionControl_errorInfo.decelHist[di].cnt = 1; motionControl_errorInfo.decelHist[di].rPos = mc_state.pos.rPos; } } else ++motionControl_errorInfo.decelHist[di].cnt; } if (mc_state.motorDir == MOT_DIR_NEUTRAL && avgRelativeSpeed <= ((1L << (20 + 8)) / 360 * 30 / 60 / 60)) { motionControl_errorInfo.decelEndMO = matchOffset; motionControl_errorInfo.decelEndPos = mc_state.pos; motionControl_errorInfo.decelDeltaT = (motionControl_errorInfo.decelEndPos.sec-motionControl_errorInfo.decelStartPos.sec)*1000 + motionControl_errorInfo.decelEndPos.ms-motionControl_errorInfo.decelStartPos.ms; motionControl_errorInfo.decelDeltaPos = motionControl_errorInfo.decelEndPos.rPos - motionControl_errorInfo.decelStartPos.rPos; mc_state.lockedOnTarget = 1; mc_state.stateMajor = SC_ST_IDLE; } goto setV; } } rSpeed_t tkSClose = mc_state.trackingSpeedClose; if (dist2Dest <= tkSClose * 500 / 1000 && avgRelativeSpeed < tkSClose) { if (mc_state.trackingDir == MOT_DIR_NEUTRAL) { if (dist2Dest <= mc_state.positionTolerance) { if (mc_state.motorDir == MOT_DIR_NEUTRAL && avgRelativeSpeed <= ((1L << (20 + 8)) / 360 * 30 / 60 / 60)) { mc_state.lockedOnTarget = 1; mc_state.stateMajor = SC_ST_IDLE; } Vdesired = 0; } } else { if (!mc_state.lockedOnTarget && avgRelativeSpeed <= ((1L << (20 + 8)) / 360 * 30 / 60 / 60)) { mc_state.lockedOnTarget = 1; mc_state.stateMajor = SC_ST_TRACKING; } if (mc_state.trackingDir == MOT_DIR_PLUS) { if (Vdesired < 0) Vdesired = 0; } else { if (Vdesired > 0) Vdesired = 0; } } } else { if (mc_state.lockedOnTarget) { mc_state.lockedOnTarget = 0; ++mc_state.targetLostCount; } } setV: if (__builtin_labs(Vdesired) > mc_state.maxSpeed) { if (Vdesired < 0) Vdesired = -mc_state.maxSpeed; else Vdesired = mc_state.maxSpeed; } if (0 && Vdesired < motionControl_errorInfo.finalVdesired) { motionControl_errorInfo.flag |= 2; motionControl_errorInfo.count = motionControl_errorInfo.max = 1; } motionControl_errorInfo.finalVdesired = Vdesired; mc_setVelocity(Vdesired); motionControl_errorInfo.finalSTI = mc_state.lastSpeedTableIndex; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: