Commit b6f6fbd7 authored by linhuang's avatar linhuang

add USRP functions

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4191 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 2b9eaa64
# compiles the openair_usrp
#OPENAIRTARGETS_DIR ?=../../../..
#OPENAIROBJS += $(OPENAIRTARGETS_DIR)/ARCH/USRP/USERSPACE/LIB/openair0_lib.o
#CFLAGS += -I$(OPENAIRTARGETS_DIR)/ARCH/USRP/USERSPACE/LIB -I$(OPENAIRTARGETS_DIR)/ARCH/USRP/DEFS
#example: example.o $(OPENAIROBJS)
# gcc -o $@ $(CFLAGS) -lm $(OPENAIROBJS) $<
#openair_usrp.o:
# $(CXX) -c openair_usrp.cpp -o openair_usrp.o
#clean:
# rm -f *.o *~
#a rm -f example
USRP_OBJ += $(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/openair_usrp.o
USRP_FILE_OBJ += $(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/openair_usrp.cpp
USRP_CFLAGS += -I$(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/
#include <stdarg.h>
#define SAMPLES_PER_FRM 76800
#define SAMPLES_PER_SLOT 3840
#define HW_offset 32
#define N_slot_offset 4
#define T_start 3840*20*100
void format_printf(int flag,const char * fmt, ...)
{
if(flag)
{
va_list args;
va_start(args,fmt);
vprintf(fmt,args);
va_end(args);
}
}
This diff is collapsed.
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <sched.h>
#include "thread_ipc.h"
g_thread_ipc_t thread_ipc = {0};
void loop_buffer_reset(buffer_t *loop_buf)
{
int i;
for (i = 0; i < BUFFERMAX; i++) {
loop_buf[i].subframe_num = -1;
}
return;
}
static void loop_buffer_init(loop_buffer_op_t *loop_buffer)
{
loop_buffer->packet_num = 0;
loop_buffer->isfull = 0;
loop_buffer->isempty = 1;
pthread_mutex_init(&loop_buffer->buffer_mutex, NULL);
pthread_cond_init(&loop_buffer->full_cond, NULL);
pthread_cond_init(&loop_buffer->empty_cond, NULL);
loop_buffer_reset(loop_buffer->loop_buf);
return;
}
static void sync_buffer_init(sync_buffer_t *sync_buffer)
{
sync_buffer->decoding_subframe_num = 0;
pthread_mutex_init(&sync_buffer->buffer_mutex, NULL);
return;
}
int thread_ipc_init(void)
{
//printf("recv %d\n", thread_ipc.sync_buffer.decoding_subframe_num);
thread_ipc.ue_sync_state = 0;
thread_ipc.rx_timestamp = 0;
thread_ipc.tx_timestamp = 0;
thread_ipc.current_subframe = 0;
pthread_mutex_init(&thread_ipc.dl_decode_mutex, NULL);
pthread_mutex_lock(&thread_ipc.dl_decode_mutex);
pthread_mutex_init(&thread_ipc.ul_send_mutex, NULL);
pthread_mutex_lock(&thread_ipc.ul_send_mutex);
pthread_mutex_init(&thread_ipc.sync_mutex, NULL);
pthread_mutex_lock(&thread_ipc.sync_mutex);
loop_buffer_init(&thread_ipc.loop_buffer);
sync_buffer_init(&thread_ipc.sync_buffer);
return 0;
}
int thread_ipc_deinit(void)
{
pthread_mutex_destroy(&thread_ipc.ul_send_mutex);
pthread_mutex_destroy(&thread_ipc.sync_mutex);
pthread_mutex_destroy(&thread_ipc.dl_decode_mutex);
pthread_mutex_destroy(&thread_ipc.loop_buffer.buffer_mutex);
pthread_cond_destroy(&thread_ipc.loop_buffer.full_cond);
pthread_cond_destroy(&thread_ipc.loop_buffer.empty_cond);
pthread_mutex_destroy(&thread_ipc.sync_buffer.buffer_mutex);
return 0;
}
int set_thread_attr(pthread_attr_t *attr, int policy, int priority, int cpuid)
{
struct sched_param param;
cpu_set_t cpu_info;
pthread_attr_init(attr);
if (pthread_attr_setschedpolicy(attr, policy) != 0) {
perror("pthread_attr_setschedpolicy");
return -1;
}
param.sched_priority = priority;
if (pthread_attr_setschedparam(attr, &param) != 0) {
perror("pthread_attr_setschedparam");
return -1;
}
CPU_ZERO(&cpu_info);
CPU_SET(cpuid, &cpu_info);
if (pthread_attr_setaffinity_np(attr,sizeof(cpu_set_t),&cpu_info)) {
perror("pthread_attr_setaffinity_np");
return -1;
}
if (pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED) != 0) {
perror("pthread_attr_setinheritsched");
return -1;
}
return 0;
}
int find_subframe_num(unsigned long long current_subframe_num, buffer_t *buf, int *flag)
{
long long tmp;
int i;
tmp = current_subframe_num;
for ( i = 0; i < HIGHBUFFER + 1; i++)
{
if(tmp == buf[i].subframe_num)
{
return i;
} else if (tmp < buf[i].subframe_num) {
*flag = 1;
}
}
return -1;
}
int ue_unsync_thread_ipc_reset(void)
{
thread_ipc.ue_sync_state = 0;
pthread_mutex_lock(&thread_ipc.loop_buffer.buffer_mutex);
if (thread_ipc.loop_buffer.isempty) {
pthread_cond_signal(&thread_ipc.loop_buffer.empty_cond);
}
if (thread_ipc.loop_buffer.isfull) {
pthread_cond_signal(&thread_ipc.loop_buffer.full_cond);
}
thread_ipc.loop_buffer.packet_num = 0;
thread_ipc.loop_buffer.isfull = 0;
thread_ipc.loop_buffer.isempty = 1;
loop_buffer_reset(thread_ipc.loop_buffer.loop_buf);
pthread_mutex_unlock(&thread_ipc.loop_buffer.buffer_mutex);
thread_ipc.current_subframe = 0;
return 0;
}
void bind_thread2kernel(int cpu_id)
{
cpu_set_t mask;
cpu_set_t get;
int i;
int num = sysconf(_SC_NPROCESSORS_CONF);
//printf("system has %d processor(s) by super\n", num);
CPU_ZERO(&mask);
CPU_SET(cpu_id, &mask);
if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) {
fprintf(stderr, "set thread affinity failed\n");
}
/*CPU_ZERO(&get);
if (pthread_getaffinity_np(pthread_self(), sizeof(get), &get) < 0) {
fprintf(stderr, "get thread affinity failed\n");
}
for (i = 0; i < num; i++) {
if (CPU_ISSET(i, &get)) {
printf("thread %d is running in processor %d\n", (int)pthread_self(), i);
}
}
if (CPU_ISSET(cpu_id, &get)) {
printf("thread %d is running in processor %d by super\n", (int)pthread_self(), cpu_id);
}*/
}
void get_thread2kernel(void)
{
cpu_set_t get;
int i;
int num = sysconf(_SC_NPROCESSORS_CONF);
printf("system has %d processor(s) by super\n", num);
CPU_ZERO(&get);
if (pthread_getaffinity_np(pthread_self(), sizeof(get), &get) < 0) {
fprintf(stderr, "get thread affinity failed\n");
}
for (i = 0; i < num; i++) {
if (CPU_ISSET(i, &get)) {
printf("The thread %d is running in processor %d by super\n", (int)pthread_self(), i);
}
}
}
#ifndef __THREAD_IPC_H__
#define __THREAD_IPC_H__
#define SUB_FRAME_LENGTH 7680
#define FRAME_LENGTH 76800
#define UE_UL_DELAY 6 /*设置上行组帧在同步时钟基础上的延时(子帧个数)*/
#define UE_UL_SEND_DELAY 6 /*上行发送子帧号在接收子帧时间戳上的延时(子帧个数)*/
#define BUFFERMAX 5 /*环形缓冲区个数*/
#define LOWBUFFER 3 /*环形缓冲区下限, 不能为0*/
#define HIGHBUFFER 4 /*环形缓冲区上限*/
typedef struct {
long long subframe_num; /*子帧编号*/
int buffer[SUB_FRAME_LENGTH * 2]; /*一子帧数据*/
}buffer_t;
typedef struct {
int packet_num; /*环形缓冲区数据包计数器,表示环形缓冲区有效数据包个数*/
int isfull; /*标记环形缓冲区有效数据包是否达到上限标志*/
int isempty; /*标记环形缓冲区有效数据包是否达到下限标志*/
pthread_mutex_t buffer_mutex; /*环形缓冲区操作保护锁*/
pthread_cond_t full_cond; /*环形缓冲区上限条件变量,配合isfull使用 */
pthread_cond_t empty_cond; /*环形缓冲区下限条件变量,配合isempty使用*/
buffer_t loop_buf[BUFFERMAX]; /*环形缓冲区*/
}loop_buffer_op_t;
typedef struct {
int decoding_subframe_num; /*待解码子帧的编号*/
pthread_mutex_t buffer_mutex; /*对sync_buffer临界区的保护锁*/
int sync_buffer[SUB_FRAME_LENGTH * 10]; /*同步线程与下行解码线程数据共享缓冲区*/
}sync_buffer_t;
typedef struct {
unsigned int rx_timestamp; /*接收数据包第一个sample时间戳*/
unsigned int tx_timestamp; /*待发送数据包的时间戳*/
unsigned long long current_subframe; /*当前子帧编号*/
int ue_sync_state; /*表示UE是否在同步状态,0表示失同步,1表示同步*/
pthread_mutex_t sync_mutex; /*根据ue_sync_state标志,唤醒组帧线程*/
pthread_mutex_t ul_send_mutex; /*用于sync线程唤醒发送线程发送数据*/
pthread_mutex_t dl_decode_mutex;/*下行解码保护锁,用于sync线程唤醒解码线程解码*/
loop_buffer_op_t loop_buffer;
sync_buffer_t sync_buffer;
}g_thread_ipc_t;
void loop_buffer_reset(buffer_t *loop_buf);
int thread_ipc_init(void);
int thread_ipc_deinit(void);
int set_thread_attr(pthread_attr_t *attr, int policy, int priority, int cpuid);
int find_subframe_num(unsigned long long current_subframe_num, buffer_t *buf, int *flag);
int ue_unsync_thread_ipc_reset(void);
extern g_thread_ipc_t thread_ipc;
#endif
#!/bin/bash
############### make nasmesh.ko ###############
sudo rmmod nasmesh
#cd ${OPENAIR2_DIR} && make nasmesh_netlink.ko
#cd ${OPENAIR2_DIR}/NAS/DRIVER/MESH/RB_TOOL/ && make
#make all
sudo insmod $OPENAIR2_DIR/NAS/DRIVER/MESH/nasmesh.ko
############## Ethernet config ####################
sudo ifconfig eth0 mtu 4000
sudo sysctl -w net.core.wmem_max=1048576
sudo sysctl -w net.core.rmem_max=50000000
############## rtai modules ###################
if test \! -c /dev/rtai_shm; then
mknod -m 666 /dev/rtai_shm c 10 254
fi
for n in `seq 0 9`; do
f=/dev/rtf$n
if test \! -c $f; then
mknod -m 666 $f c 150 $n
fi
done
modprobe rtai_hal
modprobe rtai_sched
modprobe rtai_fifos
modprobe rtai_sem
modprobe rtai_mbx
modprobe rtai_msg
############## make ###################
make lte-softmodem-usrp NAS=1 USRP=1 XFORMS=1 RTAI=1 HARD_RT=1 #DRIVER2013=1
#make lte-softmodem NAS=1 XFORMS=1 USRP=0 RTAI=1 DRIVER2013=1
echo DONE!
exit 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment