提交SMOD ATSC IMX APP版本 V122
This commit is contained in:
Executable
+123
@@ -0,0 +1,123 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../inc/type.h"
|
||||
#include "talise_config.h"
|
||||
#include "adrv9009_config.h"
|
||||
|
||||
#define FPGA_ORX1_GAIN_REG 0xC4
|
||||
#define ORX_GAIN_POLL_MS 100//100
|
||||
|
||||
static pthread_t g_orx_poll_thread;
|
||||
static volatile int g_orx_poll_running = 0;
|
||||
pthread_mutex_t g_orx_gain_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static uint8_t g_last_orx1_gain = 0xFF;
|
||||
static taliseDevice_t *g_dev = NULL;
|
||||
|
||||
extern int fpga_read_axi0(uint32 addr, uint32 *pdata, uint32 count);
|
||||
extern taliseInit_t *p_myTalInit;
|
||||
extern taliseDevice_t *p_myTaliseDevice_shm;;
|
||||
|
||||
static int set_orx_gain_index_safe(unsigned int ch, uint8_t gain)
|
||||
{
|
||||
taliseObsRxChannels_t channel;
|
||||
uint8_t min_idx, max_idx;
|
||||
|
||||
switch (ch) {
|
||||
case 1:
|
||||
channel = TAL_ORX1;
|
||||
min_idx = p_myTalInit->obsRx.orxGainCtrl.orx1MinGainIndex;
|
||||
max_idx = p_myTalInit->obsRx.orxGainCtrl.orx1MaxGainIndex;
|
||||
break;
|
||||
case 2:
|
||||
channel = TAL_ORX2;
|
||||
min_idx = p_myTalInit->obsRx.orxGainCtrl.orx2MinGainIndex;
|
||||
max_idx = p_myTalInit->obsRx.orxGainCtrl.orx2MaxGainIndex;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (gain < min_idx) gain = min_idx;
|
||||
if (gain > max_idx) gain = max_idx;
|
||||
|
||||
printf("start TALISE_setObsRxManualGain\n");
|
||||
pthread_mutex_lock(&g_orx_gain_lock);
|
||||
int ret = TALISE_setObsRxManualGain(g_dev, channel, gain);
|
||||
pthread_mutex_unlock(&g_orx_gain_lock);
|
||||
printf("end TALISE_setObsRxManualGain\n");
|
||||
|
||||
if (ret == TALACT_NO_ACTION) {
|
||||
printf("[ORxGain] set ORx%u gain=0x%02X (range %u-%u)\n", ch, gain, min_idx, max_idx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("[ORxGain] FAIL: set ORx%u gain=0x%02X, ret=%d\n", ch, gain, ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void *orx_gain_poll_loop(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
uint8_t reg_val;
|
||||
int ret;
|
||||
|
||||
|
||||
g_dev = (taliseDevice_t *)p_myTaliseDevice_shm;
|
||||
g_last_orx1_gain = 0xFF;
|
||||
|
||||
printf("[ORxGain] Polling thread started, period=%dms\n", ORX_GAIN_POLL_MS);
|
||||
|
||||
while (1) {
|
||||
ret = fpga_read_axi0(FPGA_ORX1_GAIN_REG, (uint32_t *)®_val, 1);
|
||||
if (ret != OK) {
|
||||
usleep(ORX_GAIN_POLL_MS * 1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (reg_val == g_last_orx1_gain) {
|
||||
usleep(ORX_GAIN_POLL_MS * 1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(g_dev){
|
||||
ret = set_orx_gain_index_safe(TAL_ORX1, reg_val);
|
||||
if (ret == 0) {
|
||||
printf("chg orx1_gain %d->%d\n", g_last_orx1_gain, reg_val);
|
||||
g_last_orx1_gain = reg_val;
|
||||
}
|
||||
}
|
||||
else{
|
||||
printf("warning, dev null\n");
|
||||
}
|
||||
|
||||
usleep(ORX_GAIN_POLL_MS * 1000);
|
||||
}
|
||||
|
||||
printf("[ORxGain] Polling thread exited\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int adrv9009_orx_gain_thr()
|
||||
{
|
||||
if (pthread_create(&g_orx_poll_thread, NULL, orx_gain_poll_loop, NULL) != 0) {
|
||||
printf("[ORxGain] Failed to create polling thread\n");
|
||||
g_orx_poll_running = 0;
|
||||
return -1;
|
||||
}
|
||||
//pthread_detach(g_orx_poll_thread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void adrv9009_orx_gain_stop(void)
|
||||
{
|
||||
if (!g_orx_poll_running)
|
||||
return;
|
||||
|
||||
g_orx_poll_running = 0;
|
||||
usleep(ORX_GAIN_POLL_MS * 2);
|
||||
printf("[ORxGain] Polling stopped\n");
|
||||
}
|
||||
Reference in New Issue
Block a user