&axi_gpio_0 {
    compatible = "generic-uio";
};
axi_gpio_0: gpio@41200000 {
            #gpio-cells = <2>;
            compatible = "xlnx,xps-gpio-1.00.a";
            gpio-controller ;
            reg = <0x41200000 0x10000>;
            xlnx,all-inputs = <0x0>;
            xlnx,all-inputs-2 = <0x0>;
            xlnx,all-outputs = <0x0>;
            xlnx,all-outputs-2 = <0x0>;
            xlnx,dout-default = <0x00000000>;
            xlnx,dout-default-2 = <0x00000000>;
            xlnx,gpio-width = <0x18>;
            xlnx,gpio2-width = <0x20>;
            xlnx,interrupt-present = <0x0>;
            xlnx,is-dual = <0x0>;
            xlnx,tri-default = <0xFFFFFFFF>;
            xlnx,tri-default-2 = <0xFFFFFFFF>;
        };
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>

#define GPIO_MAP_SIZE 		0x10000
#define GPIO_DATA_OFFSET	0x00
#define GPIO_TRI_OFFSET		0x04
#define GPIO_DATA2_OFFSET	0x08
#define GPIO_TRI2_OFFSET	0x0C
#define GPIO_GLOBAL_IRQ		0x11C
#define GPIO_IRQ_CONTROL	0x128
#define GPIO_IRQ_STATUS		0x120

volatile int counter;

inline void gpio_write(void *gpio_base, unsigned int offset, unsigned int value)
{
	*((volatile unsigned *)(gpio_base + offset)) = value;
}

inline unsigned int gpio_read(void *gpio_base, unsigned int offset)
{
	return *((volatile unsigned *)(gpio_base + offset));
}

unsigned int get_memory_size(char *sysfs_path_file)
{
	FILE *size_fp;
	unsigned int size;

	// open the file that describes the memory range size that is based on the
	// reg property of the node in the device tree

	size_fp = fopen(sysfs_path_file, "r");

	if (!size_fp) {
		printf("unable to open the uio size file\n");
		exit(-1);
	}

	// get the size which is an ASCII string such as 0xXXXXXXXX and then be stop
	// using the file

	fscanf(size_fp, "0x%08X", &size);
	fclose(size_fp);

	return size;
}

void wait_for_interrupt(int fd, void *gpio_ptr)
{
	int pending = 0;
	int reenable = 1;
	unsigned int reg;


	// block on the file waiting for an interrupt */
	read(fd, (void *)&pending, sizeof(int));

	counter = counter + 1;


	// the interrupt occurred for the 1st GPIO channel so clear it
	reg = gpio_read(gpio_ptr, GPIO_IRQ_STATUS);
	if (reg)
		gpio_write(gpio_ptr, GPIO_IRQ_STATUS, 1); //


	// re-enable the interrupt in the interrupt controller thru the
	// the UIO subsystem now that it's been handled

	write(fd, (void *)&reenable, sizeof(int));
	}

int main()
{
	int uio1_fd;
	void *ptr;
	int gpio_size;


	if ((uio1_fd = open("/dev/uio1", O_RDWR)) < 0)
		{
			perror("open uio1");
		}
		else{printf("uio1 opened \n");}

	gpio_size = get_memory_size("/sys/class/uio/uio1/maps/map0/size");

	ptr = mmap(NULL, gpio_size, PROT_READ|PROT_WRITE, MAP_SHARED, uio1_fd, 0);

	if (ptr == MAP_FAILED) {
			printf("Mmap call failure.\n");
			return -1;
		}
	gpio_write(ptr, GPIO_TRI_OFFSET, 0xFF); // GPIO Channel 1 input

	gpio_write(ptr, GPIO_GLOBAL_IRQ, 0x80000000); // GIER, 31. Bit
	gpio_write(ptr, GPIO_IRQ_CONTROL, 1);  // Channel 1 Interrupt enable

	//wait for interrupt
	while(1)
	{
		wait_for_interrupt(uio1_fd, ptr);
		printf("Interrupt: %d", counter);
		puts("");
	}


	munmap(ptr, gpio_size);

	return 0;
}


'개발 > Xilinx Zynq' 카테고리의 다른 글

DTSI 파일에 모듈 주소 추가  (0) 2016.11.17
Character device drivers automatically create node  (0) 2016.11.17
QSPI Kernel Booting  (0) 2016.11.17
DTSI수정하여 UART0 살리기  (0) 2016.11.16
U-Boot 설정에서 SDHCI 제거  (0) 2016.11.16

출처 : 지식인


http://kin.naver.com/qna/detail.nhn?d1id=11&dirId=1118&docId=210084618&qb=ZmZ0&enc=utf8&section=kin&rank=8&search_sort=0&spq=0


FFT 는 Fast Fourier Transform 즉 고속 푸리에 변환이 되겠읍니다.

무엇에 이용되는 것인가 하면 시간영역에서 계속 변화하는 데이터를 주파수 영역으로 가져다가 어떤 주파수 들이 사용되고 있는지를 알아볼 때 쓰게 됩니다.

 

보통 FFT 는 라이브러리화가 잘 되어 있어서 데이타를 모아서 라이브러리 함수를 call 하면 결과가 리턴되는 데 이것의 해석에

대하여 예를 들어서 이해하기 쉽게 설명해 보겠읍니다.

 

44.1KHz PCM 의 한채널을 가정해 보겠읍니다. (m = 44100)

1초에 44100  개의 데이타가 날라옵니다.

이중에서 100개의 연속된 데이터를 모아서 (n = 100)  FFT 함수를 call 했다고 가정해 봅니다.

for (i = 0; i < n; i++) {
  in[i] = sin(2.0*pi*4410*i/m);  // 4410Hz   
}

위의 경우는 마침 PCM 데이터가 4.41KHz 의 순수한 사인파라고 가정한 것입니다.

이와 같이 n 개의 데이타로 FFT 를 call 하면  k = [(n/2) + 1] 개의 복소수가 리턴되는데요

(복소수라고해 보아야  out[j][0]  out[j][1]   이렇게 두개의 실수이지요)

이것으로 부터 복소수의 크기를 구할 수 있읍니다.

for (j = 0; j < k; j++) {
  mag[j] = sqrt((out[j][0]*out[j][0]) + (out[j][1]*out[j][1]));
}

 

자 이제 해석을 해 볼까요!

n = 100 이었으므로 k = 51 이 됩니다. 즉 mag[0] 에서 mag[50] 까지 이지요.

그런데 1초에 44100 데이타 중에서 n = 100 개만 사용했으므로  m/n = 44100/100 = 441 이라는 값을

인덱스에 곱한 것이 각각의 인덱스가 나타네는 주파수가 됩니다. 즉

mag[0]  의 값은  0 X 441 = 0Hz 즉 DC 성분 이고요

mag[50] 의 값은  50 X 441 = 22050Hz = 22.050KHz 의 성분이 되는 것이지요.

데이타가 위에서 처럼 4.41KHz 였다면

mag[10] 에만 어떤 값이 존재하고  ---> 10 X 441 = 4410Hz = 4.41KHz  즉 4.41KHz 의 주파수 성분만 있고

나머지는 모두 0 이 됩니다.

 

결론은 샘플링 주파수를 알고 있을 때 (m)  n 의 값을 늘리면 k 도 증가하여 좀더 촘촘하게 주파수 간격을

따져 볼수 있게 됩니다. (m/n 은 감소)

즉 n = 44100 으로 하게되면 1 Hz 간격으로 주파수 성분을 알 수 있게 되지만 불행하게도 계산 기간이

엄청 많이 늘어나게 됩니다.

system-top.dtsi 에다가 하기 내용 추가


/{

    axi_radar: axi_radar@41200000 {

        compatible ="xlnx,axi-radar";

        reg = <0x41200000 0x10000>;

    };

};


'개발 > Xilinx Zynq' 카테고리의 다른 글

axi-gpio uio  (0) 2017.06.02
Character device drivers automatically create node  (0) 2016.11.17
QSPI Kernel Booting  (0) 2016.11.17
DTSI수정하여 UART0 살리기  (0) 2016.11.16
U-Boot 설정에서 SDHCI 제거  (0) 2016.11.16

+ Recent posts