Skip to content

Commit

Permalink
Merge branch 'release/fw0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
MicBoucinha committed Nov 26, 2021
2 parents 9bff5c0 + 78d0dfe commit bf5a01b
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 18 deletions.
15 changes: 10 additions & 5 deletions Firmware/Pump/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void hwbp_app_initialize(void)
uint8_t hwH = 1;
uint8_t hwL = 1;
uint8_t fwH = 0;
uint8_t fwL = 2;
uint8_t fwL = 3;
uint8_t ass = 0;

/* Start core */
Expand Down Expand Up @@ -68,6 +68,9 @@ void core_callback_catastrophic_error_detected(void)
/************************************************************************/
/* User functions */
/************************************************************************/
#define DIR_FORWARD 1
#define DIR_REVERSE 0

uint16_t inactivity_counter = 0;

uint8_t but_push_counter_ms = 0;
Expand All @@ -84,16 +87,14 @@ bool but_reset_dir_change = false;
bool switch_f_active = false;
bool switch_r_active = false;

uint8_t curr_dir = 0;
uint8_t curr_dir = DIR_FORWARD;
uint8_t prev_dir = DIR_FORWARD;
uint16_t step_period_counter = 0;

bool running_protocol = false;
uint16_t prot_remaining_steps = 0;
uint16_t prot_step_period = 0;

#define DIR_FORWARD 1
#define DIR_REVERSE 0


void stop_and_reset_protocol()
{
Expand All @@ -102,6 +103,9 @@ void stop_and_reset_protocol()
prot_remaining_steps = app_regs.REG_PROTOCOL_NUMBER_STEPS + 1;
prot_step_period = app_regs.REG_PROTOCOL_PERIOD * 2;
app_regs.REG_START_PROTOCOL = 0;

// revert direction
app_write_REG_DIR_STATE(&prev_dir);
}

void switch_pressed(uint8_t direction)
Expand Down Expand Up @@ -220,6 +224,7 @@ void core_callback_reset_registers(void)
app_regs.REG_DI0_CONFIG = GM_DI0_SYNC;
app_regs.REG_MOTOR_MICROSTEP = GM_STEP_FULL;

app_regs.REG_PROTOCOL_DIRECTION = DIR_FORWARD;
app_regs.REG_PROTOCOL_NUMBER_STEPS = 15;
app_regs.REG_PROTOCOL_FLOWRATE = 0.5;
app_regs.REG_PROTOCOL_PERIOD = 10;
Expand Down
73 changes: 67 additions & 6 deletions Firmware/Pump/app_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/************************************************************************/
extern AppRegs app_regs;
extern uint8_t curr_dir;
extern uint8_t prev_dir;
extern uint8_t step_period_counter;
extern bool running_protocol;
extern void stop_and_reset_protocol();
Expand Down Expand Up @@ -34,7 +35,8 @@ void (*app_func_rd_pointer[])(void) = {
&app_read_REG_CALIBRATION_VALUE_2,
&app_read_REG_EVT_ENABLE,
&app_read_REG_SET_BOARD_TYPE,
&app_read_REG_PROTOCOL_STATE
&app_read_REG_PROTOCOL_STATE,
&app_read_REG_PROTOCOL_DIRECTION
};

bool (*app_func_wr_pointer[])(void*) = {
Expand All @@ -60,7 +62,8 @@ bool (*app_func_wr_pointer[])(void*) = {
&app_write_REG_CALIBRATION_VALUE_2,
&app_write_REG_EVT_ENABLE,
&app_write_REG_SET_BOARD_TYPE,
&app_write_REG_PROTOCOL_STATE
&app_write_REG_PROTOCOL_STATE,
&app_write_REG_PROTOCOL_DIRECTION
};


Expand Down Expand Up @@ -99,7 +102,31 @@ bool app_write_REG_START_PROTOCOL(void *a)
// will only be updated after stopping and starting the protocol again
stop_and_reset_protocol();

// prevent activating protocol if the switch for the same direction is active
if( reg > 0 )
{
// forward switch and forward direction
if(read_SW_F && app_regs.REG_PROTOCOL_DIRECTION)
{
return true;
}

// reverse switch and reverse direction
if(read_SW_R && !app_regs.REG_PROTOCOL_DIRECTION)
{
return true;
}
}

running_protocol = reg > 0;

// set current direction to the one defined in the protocol_direction reg
if( running_protocol )
{
prev_dir = curr_dir;
//FIXME: seems that the first event is not triggered
app_write_REG_DIR_STATE(&app_regs.REG_PROTOCOL_DIRECTION);
}

app_regs.REG_START_PROTOCOL = reg;
app_regs.REG_PROTOCOL_STATE = reg;
Expand All @@ -122,7 +149,7 @@ bool app_write_REG_STEP_STATE(void *a)
{
uint8_t reg = *((uint8_t*)a);

if(reg)
if( reg > 0 )
{
// force starting counting from the start
step_period_counter = 0;
Expand All @@ -133,10 +160,22 @@ bool app_write_REG_STEP_STATE(void *a)
app_write_REG_ENABLE_MOTOR_DRIVER(&app_regs.REG_ENABLE_MOTOR_DRIVER);
}

set_STEP;
if((app_regs.REG_DO1_CONFIG & MSK_OUT1_CONF) == GM_OUT1_STEP_STATE)
// only allow steps if the switch on the same direction is not active
if(!read_SW_F && curr_dir == 1)
{
set_OUT01;
set_STEP;
if((app_regs.REG_DO1_CONFIG & MSK_OUT1_CONF) == GM_OUT1_STEP_STATE)
{
set_OUT01;
}
}
if(!read_SW_R && curr_dir == 0)
{
set_STEP;
if((app_regs.REG_DO1_CONFIG & MSK_OUT1_CONF) == GM_OUT1_STEP_STATE)
{
set_OUT01;
}
}
}

Expand Down Expand Up @@ -173,6 +212,11 @@ bool app_write_REG_DIR_STATE(void *a)
core_func_send_event(ADD_REG_DIR_STATE, true);
}

if(!running_protocol)
{
prev_dir = curr_dir;
}

if(curr_dir)
set_DIR;
else
Expand Down Expand Up @@ -582,4 +626,21 @@ bool app_write_REG_PROTOCOL_STATE(void *a)
core_func_send_event(ADD_REG_PROTOCOL_STATE, true);

return true;
}

/************************************************************************/
/* REG_PROTOCOL_DIRECTION */
/************************************************************************/
void app_read_REG_PROTOCOL_DIRECTION(void)
{
//app_regs.REG_PROTOCOL_DIRECTION = 0;

}

bool app_write_REG_PROTOCOL_DIRECTION(void *a)
{
uint8_t reg = *((uint8_t*)a);

app_regs.REG_PROTOCOL_DIRECTION = reg;
return true;
}
2 changes: 2 additions & 0 deletions Firmware/Pump/app_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void app_read_REG_CALIBRATION_VALUE_2(void);
void app_read_REG_EVT_ENABLE(void);
void app_read_REG_SET_BOARD_TYPE(void);
void app_read_REG_PROTOCOL_STATE(void);
void app_read_REG_PROTOCOL_DIRECTION(void);

bool app_write_REG_ENABLE_MOTOR_DRIVER(void *a);
bool app_write_REG_START_PROTOCOL(void *a);
Expand All @@ -67,6 +68,7 @@ bool app_write_REG_CALIBRATION_VALUE_2(void *a);
bool app_write_REG_EVT_ENABLE(void *a);
bool app_write_REG_SET_BOARD_TYPE(void *a);
bool app_write_REG_PROTOCOL_STATE(void *a);
bool app_write_REG_PROTOCOL_DIRECTION(void *a);


#endif /* _APP_FUNCTIONS_H_ */
5 changes: 4 additions & 1 deletion Firmware/Pump/app_ios_and_regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ uint8_t app_regs_type[] = {
TYPE_U8,
TYPE_U8,
TYPE_U8,
TYPE_U8,
TYPE_U8
};

Expand All @@ -109,6 +110,7 @@ uint16_t app_regs_n_elements[] = {
1,
1,
1,
1,
1
};

Expand All @@ -135,5 +137,6 @@ uint8_t *app_regs_pointer[] = {
(uint8_t*)(&app_regs.REG_CALIBRATION_VALUE_2),
(uint8_t*)(&app_regs.REG_EVT_ENABLE),
(uint8_t*)(&app_regs.REG_SET_BOARD_TYPE),
(uint8_t*)(&app_regs.REG_PROTOCOL_STATE)
(uint8_t*)(&app_regs.REG_PROTOCOL_STATE),
(uint8_t*)(&app_regs.REG_PROTOCOL_DIRECTION)
};
6 changes: 4 additions & 2 deletions Firmware/Pump/app_ios_and_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ typedef struct
uint8_t REG_EVT_ENABLE;
uint8_t REG_SET_BOARD_TYPE;
uint8_t REG_PROTOCOL_STATE;
uint8_t REG_PROTOCOL_DIRECTION;
} AppRegs;

/************************************************************************/
Expand Down Expand Up @@ -165,6 +166,7 @@ typedef struct
#define ADD_REG_EVT_ENABLE 52 // U8 Enable the Events
#define ADD_REG_SET_BOARD_TYPE 53 // U8 Type of the board
#define ADD_REG_PROTOCOL_STATE 54 // U8 State of the protocol (running or stopped)
#define ADD_REG_PROTOCOL_DIRECTION 55 // U8 Protocol direction

/************************************************************************/
/* PWM Generator registers' memory limits */
Expand All @@ -174,8 +176,8 @@ typedef struct
/************************************************************************/
/* Memory limits */
#define APP_REGS_ADD_MIN 0x20
#define APP_REGS_ADD_MAX 0x36
#define APP_NBYTES_OF_REG_BANK 31
#define APP_REGS_ADD_MAX 0x37
#define APP_NBYTES_OF_REG_BANK 32

/************************************************************************/
/* Registers' bits */
Expand Down
10 changes: 6 additions & 4 deletions Firmware/Pump/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ ISR(PORTB_INT0_vect, ISR_NAKED)
app_regs.REG_STEP_STATE = aux;
app_write_REG_STEP_STATE(&app_regs.REG_STEP_STATE);
}

previous_in0 = aux;
}

if((app_regs.REG_DI0_CONFIG & MSK_DI0_CONF) == GM_DI0_RISE_START_PROTOCOL)
{
// transition from low to high
if(previous_in0 == 0 && aux == 1)
running_protocol = true;
app_regs.REG_START_PROTOCOL = 1;
else
running_protocol = false;
app_regs.REG_START_PROTOCOL = 0;

app_write_REG_START_PROTOCOL(&app_regs.REG_START_PROTOCOL);
}

previous_in0 = aux;

reti();
}

Expand Down
Binary file modified Firmware/Pump/registers.xls
Binary file not shown.

0 comments on commit bf5a01b

Please sign in to comment.