/* * Copyright (C) 2015, 2016 "IoT.bzh" * Author "Manuel Bachmann" * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include "radio-api.h" #include "radio-rtlsdr.h" static unsigned int init_dev_count = 0; static struct dev_ctx **dev_ctx = NULL; /* ------------- RADIO RTLSDR IMPLEMENTATION ---------------- */ /* --- PUBLIC FUNCTIONS --- */ /* Radio initialization should be done only when user start the radio and not at plugin initialization Making this call too early would impose to restart the binder to detect a radio */ unsigned char _radio_on (unsigned int num, radioCtxHandleT *ctx) { if (num >= _radio_dev_count()) return 0; if (init_dev_count < _radio_dev_count()) { init_dev_count = _radio_dev_count(); dev_ctx = (dev_ctx_T**) realloc (dev_ctx, init_dev_count * sizeof(dev_ctx_T*)); } dev_ctx[num] = (dev_ctx_T*) malloc (sizeof(dev_ctx_T)); dev_ctx[num]->dev = NULL; dev_ctx[num]->mode = ctx->mode; dev_ctx[num]->freq = ctx->freq; dev_ctx[num]->mute = ctx->mute; dev_ctx[num]->should_run = 0; dev_ctx[num]->dongle = NULL; dev_ctx[num]->demod = NULL; dev_ctx[num]->output = NULL; _radio_dev_init (dev_ctx[num], num); return 1; } void _radio_off (unsigned int num) { if (num >= _radio_dev_count()) return; if (dev_ctx[num]) { _radio_dev_free (dev_ctx[num]); free (dev_ctx[num]); } /* free(dev_ctx); */ } void _radio_set_mode (unsigned int num, Mode mode) { if (!dev_ctx || !dev_ctx[num]) return; dev_ctx[num]->mode = mode; _radio_apply_params (dev_ctx[num]); } void _radio_set_freq (unsigned int num, double freq) { if (!dev_ctx || !dev_ctx[num]) return; dev_ctx[num]->freq = (float)freq; _radio_apply_params (dev_ctx[num]); } void _radio_set_mute (unsigned int num, unsigned char mute) { if (!dev_ctx || !dev_ctx[num]) return; dev_ctx[num]->mute = mute; _radio_apply_params (dev_ctx[num]); } void _radio_play (unsigned int num) { if (!dev_ctx || !dev_ctx[num]) return; _radio_start_threads (dev_ctx[num]); } void _radio_stop (unsigned int num) { if (!dev_ctx || !dev_ctx[num]) return; _radio_stop_threads (dev_ctx[num]); } unsigned int _radio_dev_count () { return rtlsdr_get_device_count(); } const char* _radio_dev_name (unsigned int num) { return rtlsdr_get_device_name (num); } /* --- LOCAL HELPER FUNCTIONS --- */ unsigned char _radio_dev_init (dev_ctx_T *dev_ctx, unsigned int num) { rtlsdr_dev_t *dev = dev_ctx->dev; if (rtlsdr_open (&dev, num) < 0) return 0; rtlsdr_set_tuner_gain_mode (dev, 0); if (rtlsdr_reset_buffer (dev) < 0) return 0; dev_ctx->dev = dev; _radio_apply_params (dev_ctx); return 1; } unsigned char _radio_dev_free (dev_ctx_T *dev_ctx) { rtlsdr_dev_t *dev = dev_ctx->dev; if (rtlsdr_close (dev) < 0) return 0; dev = NULL; dev_ctx->dev = dev; return 1; } void _radio_apply_params (dev_ctx_T *dev_ctx) { rtlsdr_dev_t *dev = dev_ctx->dev; Mode mode = dev_ctx->mode; float freq = dev_ctx->freq; int rate; freq *= 1000000; rate = ((1000000 / 200000) + 1) * 200000; if (mode == FM) freq += 16000; freq += rate / 4; rtlsdr_set_center_freq (dev, freq); rtlsdr_set_sample_rate (dev, rate); dev_ctx->dev = dev; } void _radio_start_threads (dev_ctx_T *dev_ctx) { dev_ctx->dongle = (dongle_ctx*) malloc (sizeof(dongle_ctx)); dev_ctx->demod = (demod_ctx*) malloc (sizeof(demod_ctx)); dev_ctx->output = (output_ctx*) malloc (sizeof(output_ctx)); dongle_ctx *dongle = dev_ctx->dongle; demod_ctx *demod = dev_ctx->demod; output_ctx *output = dev_ctx->output; pthread_rwlock_init (&demod->lck, NULL); pthread_cond_init (&demod->ok, NULL); pthread_mutex_init (&demod->ok_m, NULL); pthread_rwlock_init (&output->lck, NULL); pthread_cond_init (&output->ok, NULL); pthread_mutex_init (&output->ok_m, NULL); dev_ctx->should_run = 1; /* dongle thread */ dongle->thr_finished = 0; pthread_create (&dongle->thr, NULL, _dongle_thread_fn, (void*)dev_ctx); /* demod thread */ demod->pre_r = demod->pre_j = 0; demod->now_r = demod->now_j = 0; demod->index = demod->pre_index = demod->now_index = 0; demod->thr_finished = 0; pthread_create (&demod->thr, NULL, _demod_thread_fn, (void*)dev_ctx); /* output thread */ output->thr_finished = 0; pthread_create (&output->thr, NULL, _output_thread_fn, (void*)dev_ctx); } void _radio_stop_threads (dev_ctx_T *dev_ctx) { rtlsdr_dev_t *dev = dev_ctx->dev; dongle_ctx *dongle = dev_ctx->dongle; demod_ctx *demod = dev_ctx->demod; output_ctx *output = dev_ctx->output; if (!dongle || !demod || !output) return; /* stop each "while" loop in threads */ dev_ctx->should_run = 0; rtlsdr_cancel_async (dev); pthread_signal (&demod->ok, &demod->ok_m); pthread_signal (&output->o
TMPDIR = "${TOPDIR}/tmp-${BB_CURRENT_MC}"

MACHINE = "virtio-aarch64"

# Avoid parse errors caused by linux-renesas, and all the other
# random bbappends in meta-rcar-gen3.
BBMASK += "meta-rcar-gen3/ meta-rcar-gen3-adas/ meta-agl-refhw-gen3/"

DISTRO_FEATURES:append = " kvm virtualization"

# Use our own wks file
WKS_FILE = "directdisk.wks.in"

# We only need ext4 images for guests for now
AGL_DEFAULT_IMAGE_FSTYPES = "ext4"
AGL_EXTRA_IMAGE_FSTYPES = ""

# Need to run QEMU with virtio-gpu device
#PACKAGECONFIG:append:pn-qemu-system-native = " virglrenderer glx gtk+"
PACKAGECONFIG:append:pn-qemu-system-target = " virglrenderer glx"

# Until aglsetup.sh potentially changes to split features per multiconfig,
# remove problematic ones from the host build here
AGL_FEATURES:remove = "agl-refhw-h3"