debug workers using gpio on rpi

This commit is contained in:
Devaev Maxim
2019-05-26 20:24:01 +03:00
parent 66ef566c9a
commit 9ca43f17a3
3 changed files with 42 additions and 0 deletions

View File

@@ -28,6 +28,12 @@ ifneq ($(call optbool,$(WITH_OMX_ENCODER)),)
endif
ifneq ($(call optbool,$(WITH_WORKERS_GPIO_DEBUG)),)
LIBS += -lwiringPi
override CFLAGS += -DWITH_WORKERS_GPIO_DEBUG
endif
# =====
all: $(SOURCES) $(PROG)

View File

@@ -32,6 +32,10 @@
#include <pthread.h>
#ifdef WITH_WORKERS_GPIO_DEBUG
# include <wiringPi.h>
#endif
#include "config.h"
#include "tools.h"
#include "logging.h"
@@ -377,6 +381,15 @@ int main(int argc, char *argv[]) {
LOGGING_INIT;
# ifdef WITH_WORKERS_GPIO_DEBUG
if (wiringPiSetupGpio() < 0) {
LOG_PERROR("Can't initialize wiringPi GPIO");
return 1;
} else {
LOG_INFO("Using wiringPi to debug using GPIO");
}
# endif
dev = device_init();
encoder = encoder_init();
stream = stream_init(dev, encoder);

View File

@@ -38,6 +38,13 @@
#include "encoder.h"
#include "stream.h"
#ifdef WITH_WORKERS_GPIO_DEBUG
# include <wiringPi.h>
# ifndef WORKERS_GPIO_DEBUG_START_PIN
# define WORKERS_GPIO_DEBUG_START_PIN 5
# endif
#endif
static long double _stream_get_fluency_delay(struct device_t *dev, struct workers_pool_t *pool);
static void _stream_expose_picture(struct stream_t *stream, unsigned buf_index);
@@ -440,8 +447,21 @@ static void *_stream_worker_thread(void *v_worker) {
LOG_DEBUG("Hello! I am a worker #%u ^_^", worker->number);
# ifdef WITH_WORKERS_GPIO_DEBUG
# define WORKER_GPIO_DEBUG_BUSY digitalWrite(WORKERS_GPIO_DEBUG_START_PIN + worker->number, HIGH)
# define WORKER_GPIO_DEBUG_FREE digitalWrite(WORKERS_GPIO_DEBUG_START_PIN + worker->number, LOW)
pinMode(WORKERS_GPIO_DEBUG_START_PIN + worker->number, OUTPUT);
WORKER_GPIO_DEBUG_FREE;
# else
# define WORKER_GPIO_DEBUG_BUSY
# define WORKER_GPIO_DEBUG_FREE
# endif
while (!atomic_load(worker->proc_stop) && !atomic_load(worker->workers_stop)) {
LOG_DEBUG("Worker %u waiting for a new job ...", worker->number);
WORKER_GPIO_DEBUG_FREE;
A_MUTEX_LOCK(&worker->has_job_mutex);
A_COND_WAIT_TRUE(atomic_load(&worker->has_job), &worker->has_job_cond, &worker->has_job_mutex);
A_MUTEX_UNLOCK(&worker->has_job_mutex);
@@ -451,6 +471,8 @@ static void *_stream_worker_thread(void *v_worker) {
LOG_DEBUG("Worker %u compressing JPEG from buffer %u ...", worker->number, worker->buf_index);
WORKER_GPIO_DEBUG_BUSY;
PICTURE(encode_begin_time) = get_now_monotonic();
if (encoder_compress_buffer(worker->encoder, worker->dev, worker->number, worker->buf_index) < 0) {
worker->job_failed = true;
@@ -484,6 +506,7 @@ static void *_stream_worker_thread(void *v_worker) {
}
LOG_DEBUG("Bye-bye (worker %u)", worker->number);
WORKER_GPIO_DEBUG_FREE;
return NULL;
}