Skip to content

Commit

Permalink
Support dumping EEPROM and FPGA registers (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Aug 4, 2023
1 parent a8cb1fa commit 220649d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
1 change: 0 additions & 1 deletion tfrog-motordriver/communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ uint8_t receive_buf485[RECV_BUF_LEN];
volatile int32_t w_receive_buf485 = 0;
volatile int32_t r_receive_buf485 = 0;
extern const Pin pinPWMEnable;
extern Tfrog_EEPROM_data saved_param;
extern volatile char rs485_timeout;
extern volatile int16_t tic;
extern volatile uint8_t usb_read_pause;
Expand Down
3 changes: 1 addition & 2 deletions tfrog-motordriver/controlPWM.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const Pin pinPWMCycle2 = PIN_PWM_CYCLE2;
// / PWM Enable pin instance.
static const Pin pinPWMEnable = PIN_PWM_ENABLE;

#define SinTB_2PI 4096
#define SinTB_2PI 4096
#define AtanTB_LEN 512

static char init = 1;
Expand Down Expand Up @@ -81,7 +81,6 @@ inline int16_t atan_(const int32_t x)
return AtanTB[AtanTB_LEN - 1];
}

extern Tfrog_EEPROM_data saved_param;
extern volatile char rs485_timeout;

void controlPWM_config(int32_t i)
Expand Down
2 changes: 0 additions & 2 deletions tfrog-motordriver/controlVelocity.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ int16_t soft_start[2] = {0, 0};
Filter1st accelf[2];
Filter1st accelf0;

extern Tfrog_EEPROM_data saved_param;

void ISR_VelocityControl() RAMFUNC;
void timer0_vel_calc() RAMFUNC;

Expand Down
7 changes: 4 additions & 3 deletions tfrog-motordriver/controlVelocity.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ typedef enum _ErrorID
#define ERROR_NUM 6

// ENC0_BUF_MAX must be 2^n to reduce computation cost.
#define ENC0_BUF_MAX 64
#define ENC0_BUF_MAX 64
#define ENC0_DENOMINATOR_MAX ((int)(ENC0_BUF_MAX / 6))
#define ENC0_BUF_UNKNOWN 0x7FFFFFF
#define ENC0_BUF_UNKNOWN 0x7FFFFFF

#ifdef static_assert
static_assert(
Expand All @@ -53,7 +53,7 @@ static_assert(
#endif

#define ACCEL_FILTER_TIME 15 // Timeconstant in velocity control steps
#define ENC0_FILTER_TIME 32 // Timeconstant in velocity control steps
#define ENC0_FILTER_TIME 32 // Timeconstant in velocity control steps

typedef struct _MotorState
{
Expand Down Expand Up @@ -176,6 +176,7 @@ typedef struct _DriverState
uint8_t protocol_version;
uint32_t velcontrol;
uint32_t ping_request;
uint32_t odom_drop;
} DriverState;

#ifdef static_assert
Expand Down
12 changes: 11 additions & 1 deletion tfrog-motordriver/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
#include "communication.h"
#include "controlVelocity.h"
#include "debug.h"
#include "eeprom.h"
#include "registerFPGA.h"

extern uint8_t send_buf[SEND_BUF_LEN];
extern volatile uint32_t send_buf_pos;

static int32_t dump_id = -1;
static void* dump_ptr = 0;
static volatile void* dump_ptr = 0;
static int32_t dump_size = -1;
static int32_t dump_cnt = 0;

Expand Down Expand Up @@ -54,6 +56,14 @@ void start_dump(const int32_t imotor, const int32_t arg)
dump_ptr = &driver_param;
dump_size = sizeof(DriverParam);
break;
case 4:
dump_ptr = &saved_param;
dump_size = sizeof(Tfrog_EEPROM_data);
break;
case 5:
dump_ptr = &THEVA;
dump_size = sizeof(THEVA_REG);
break;
default:
dump_ptr = 0;
break;
Expand Down
6 changes: 4 additions & 2 deletions tfrog-motordriver/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ typedef struct _Tfrog_EEPROM_data
0, \
}

#define TFROG_EEPROM_DATA_TEXT 0
#define TFROG_EEPROM_DATA_BIN 1
#define TFROG_EEPROM_DATA_TEXT 0
#define TFROG_EEPROM_DATA_BIN 1
#define TFROG_EEPROM_DATA_BIN_SAVING 2
#define TFROG_EEPROM_DATA_BIN_LOCKED 3

extern Tfrog_EEPROM_data saved_param;

#endif
5 changes: 5 additions & 0 deletions tfrog-motordriver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ int main()
driver_state.error.hallenc[1] = 0;
driver_state.ifmode = 0;
driver_state.watchdog = 0;
driver_state.odom_drop = 0;
// Driver loop
while (1)
{
Expand Down Expand Up @@ -942,6 +943,10 @@ int main()
int32_t i;
/* 約5msおき */
driver_state.cnt_updated -= 5;
for (; driver_state.cnt_updated >= 5; driver_state.cnt_updated -= 5)
{
driver_state.odom_drop++;
}

mask = driver_state.admask; // analog_mask;
if (driver_state.io_mask[0])
Expand Down

0 comments on commit 220649d

Please sign in to comment.