Skip to content

Commit 8520f00

Browse files
committed
Implemented real time option (activated by define)
1 parent 49660ec commit 8520f00

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static char args_doc[] = "";
8484
static struct argp_option options[] = {
8585
{"verbose", 'v', "VERBOSITY_LEVEL", 0, "Verbosiity level: 0 quiet else verbose level (default : quiet)"},
8686
{"long-help", 'H', 0, 0, "Print a long help and exit"},
87+
{"real-time", 'T', 0, 0, "Engage so called \"real time\" scheduling (defalut 0: no)"},
8788
{"spi-device", 'd', "SPI_DEVICE", 0, "SPI device, (default : /dev/spidev0.0)"},
8889
{"modulation", 'M', "MODULATION_SCHEME", 0, "Radio modulation scheme, See long help (-H) option"},
8990
{"rate", 'R', "DATA_RATE_INDEX", 0, "Data rate index, See long help (-H) option"},
@@ -186,6 +187,7 @@ static void init_args(arguments_t *arguments)
186187
arguments->tnc_keyup_delay = 10000;
187188
arguments->tnc_keydown_delay = 0;
188189
arguments->tnc_switchover_delay = 0;
190+
arguments->real_time = 0;
189191
}
190192

191193
// ------------------------------------------------------------------------------------------------
@@ -214,6 +216,7 @@ static void print_args(arguments_t *arguments)
214216
{
215217
fprintf(stderr, "-- options --\n");
216218
fprintf(stderr, "Verbosity ...........: %d\n", arguments->verbose_level);
219+
fprintf(stderr, "Real time ...........: %s\n", (arguments->real_time ? "yes" : "no"));
217220
fprintf(stderr, "--- radio ---\n");
218221
fprintf(stderr, "Modulation ..........: %s\n", modulation_names[arguments->modulation]);
219222
fprintf(stderr, "Rate nominal ........: %d Baud\n", rate_values[arguments->rate]);
@@ -395,6 +398,17 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
395398
fprintf(stderr, "Variable length blocks are not allowed (yet?)\n");
396399
}
397400
break;
401+
// Real time scheduling
402+
case 'T':
403+
if (ALLOW_REAL_TIME)
404+
{
405+
arguments->real_time = 1;
406+
}
407+
else
408+
{
409+
fprintf(stderr, "Real time scheduling is not allowed\n");
410+
}
411+
break;
398412
// Repetition factor
399413
case 'n':
400414
arguments->repetition = strtol(arg, &end, 10);

main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <termios.h>
66

77
#define ALLOW_VAR_BLOCKS 0
8+
#define ALLOW_REAL_TIME 1
89

910
typedef enum test_mode_e {
1011
TEST_NONE = 0,
@@ -97,6 +98,7 @@ typedef struct arguments_s {
9798
uint32_t tnc_keyup_delay; // TNC keyup delay in microseconds
9899
uint32_t tnc_keydown_delay; // TNC keydown delay in microseconds
99100
uint32_t tnc_switchover_delay; // TNC Rx/Tx switchover delay in microseconds
101+
uint8_t real_time; // Engage so called "real time" scheduling
100102
} arguments_t;
101103

102104
#endif

radio.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,21 @@ int init_radio(radio_parms_t *radio_parms, spi_parms_t *spi_parms, arguments_t *
520520
wiringPiSetup(); // initialize Wiring Pi library and GDOx interrupt routines
521521
verbprintf(1, "wiringPiSetup done.\n");
522522

523+
// Switch main thread to real time
524+
if (arguments->real_time)
525+
{
526+
ret = piHiPri(1);
527+
528+
if (ret == 0)
529+
{
530+
fprintf(stderr, "RADIO: real time OK\n");
531+
}
532+
else
533+
{
534+
perror("RADIO: cannot set in real time");
535+
}
536+
}
537+
523538
// open SPI link
524539
PI_CC_SPIParmsDefaults(spi_parms);
525540
ret = PI_CC_SPISetup(spi_parms, arguments);

0 commit comments

Comments
 (0)