Skip to content

Commit

Permalink
Add SUMP mode autodetection (#72)
Browse files Browse the repository at this point in the history
This patch adds the possibility to automatically switch to SUMP mode
when Hydrabus is polled by a SUMP client (tested with OLS client and
Sigrok).
  • Loading branch information
Baldanos authored and bvernoux committed Mar 3, 2017
1 parent e08a6b0 commit ca90ec2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
19 changes: 13 additions & 6 deletions hydrabus/hydrabus_sump.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,19 @@ static void sump_deinit(void)
}
}

int cmd_sump(t_hydra_console *con, __attribute__((unused)) t_tokenline_parsed *p) __attribute__((optimize("-O3")));
int cmd_sump(t_hydra_console *con, __attribute__((unused)) t_tokenline_parsed *p)
int cmd_sump(t_hydra_console *con, t_tokenline_parsed *p)
{
(void) p;
cprintf(con, "Interrupt by pressing user button.\r\n");
cprint(con, "\r\n", 2);

sump(con);

return TRUE;
}

void sump(t_hydra_console *con) __attribute__((optimize("-O3")));
void sump(t_hydra_console *con)
{

sump_init();
Expand All @@ -164,9 +175,6 @@ int cmd_sump(t_hydra_console *con, __attribute__((unused)) t_tokenline_parsed *p
uint8_t sump_parameters[4] = {0};
uint32_t index=0;

cprintf(con, "Interrupt by pressing user button.\r\n");
cprint(con, "\r\n", 2);

while (!palReadPad(GPIOA, 0)) {
if(chnReadTimeout(con->sdu, &sump_command, 1, 1)) {
switch(sump_command) {
Expand Down Expand Up @@ -296,6 +304,5 @@ int cmd_sump(t_hydra_console *con, __attribute__((unused)) t_tokenline_parsed *p
}
}
sump_deinit();
return TRUE;
}

1 change: 1 addition & 0 deletions hydrabus/hydrabus_sump.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ typedef struct {
uint8_t state;
uint8_t channels;
} sump_config;
void sump(t_hydra_console *con);
18 changes: 15 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "hydrabus.h"
#include "hydranfc.h"
#include "hydrabus/hydrabus_bbio.h"
#include "hydrabus/hydrabus_sump.h"

#include "bsp.h"

Expand Down Expand Up @@ -73,7 +74,7 @@ THD_FUNCTION(console, arg)
con = arg;
chRegSetThreadName(con->thread_name);
tl_init(con->tl, tl_tokens, tl_dict, print, con);
tl_set_prompt(con->tl, PROMPT);
con->tl->prompt = PROMPT;
tl_set_callback(con->tl, execute);

if(is_file_present(INIT_SCRIPT_NAME)) {
Expand All @@ -82,11 +83,22 @@ THD_FUNCTION(console, arg)

while (1) {
input = get_char(con);
if(input == 0) {
switch(input) {
case 0:
if (++i == 20) {
cmd_bbio(con);
return;
}
} else {
break;
/* SUMP identification is 5*\x00 \x02 */
/* Allows to enter SUMP mode autmomatically */
case 2:
if(i == 5) {
cprintf(con, "1ALS");
sump(con);
}
break;
default:
i=0;
tl_input(con->tl, input);
}
Expand Down

0 comments on commit ca90ec2

Please sign in to comment.