主题 : 菜鸟实在不懂来求教了……关于NDK编译的问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 38877
精华: 0
发帖: 40
金钱: 200 两
威望: 40 点
综合积分: 80 分
注册时间: 2011-03-02
最后登录: 2013-12-11
楼主  发表于: 2011-05-09 10:21

 菜鸟实在不懂来求教了……关于NDK编译的问题

在网上找到的资料比较少,一直搞不懂该怎么做
我准备把一个nrf2401的传输程序编译成so文件,驱动已经装好
传输程序原代码如下:
复制代码
  1. #include <stdint.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <getopt.h>
  6. #include <fcntl.h>
  7. #include <sys/ioctl.h>
  8. #include <linux/types.h>
  9. #include <linux/spi/spidev.h>
  10. #include "tx01_30_simply.h"
  11. #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
  12. static const char *device = "/dev/spidev0.0";
  13. static uint8_t mode;
  14. static uint8_t bits = 8;
  15. static uint32_t speed = 500000;
  16. static uint16_t delay;
  17. void init_NRF24L01(int fdo, int fd)  //initialize the NRF24L01
  18. {
  19.          int t;
  20.                 uint8_t tx1[] = {
  21.         0x30, 0xE7, 0xD3, 0xF0, 0x35, 0x77,
  22.     };
  23.     uint8_t rx1[ARRAY_SIZE(tx1)] = {0, };
  24.     struct spi_ioc_transfer tr1 = {
  25.         .tx_buf = (unsigned long)tx1,
  26.         .rx_buf = (unsigned long)rx1,
  27.         .len = ARRAY_SIZE(tx1),
  28.         .delay_usecs = delay,
  29.         .speed_hz = speed,
  30.         .bits_per_word = bits,
  31.     };
  32.         uint8_t tx2[] = {
  33.         0x2A, 0xE7, 0xD3, 0xF0, 0x35, 0x77,
  34.     };
  35.     uint8_t rx2[ARRAY_SIZE(tx2)] = {0, };
  36.     struct spi_ioc_transfer tr2 = {
  37.         .tx_buf = (unsigned long)tx2,
  38.         .rx_buf = (unsigned long)rx2,
  39.         .len = ARRAY_SIZE(tx2),
  40.         .delay_usecs = delay,
  41.         .speed_hz = speed,
  42.         .bits_per_word = bits,
  43.     };
  44.         uint8_t tx3[] = {
  45.         0x21, 0x01,
  46.     };
  47.     uint8_t rx3[ARRAY_SIZE(tx3)] = {0, };
  48.     struct spi_ioc_transfer tr3 = {
  49.         .tx_buf = (unsigned long)tx3,
  50.         .rx_buf = (unsigned long)rx3,
  51.         .len = ARRAY_SIZE(tx3),
  52.         .delay_usecs = delay,
  53.         .speed_hz = speed,
  54.         .bits_per_word = bits,
  55.     };
  56.         uint8_t tx4[] = {
  57.         0x22, 0x01,
  58.     };
  59.     uint8_t rx4[ARRAY_SIZE(tx4)] = {0, };
  60.     struct spi_ioc_transfer tr4 = {
  61.         .tx_buf = (unsigned long)tx4,
  62.         .rx_buf = (unsigned long)rx4,
  63.         .len = ARRAY_SIZE(tx4),
  64.         .delay_usecs = delay,
  65.         .speed_hz = speed,
  66.         .bits_per_word = bits,
  67.     };
  68.         uint8_t tx5[] = {
  69.         0x25, 0x00,
  70.     };
  71.     uint8_t rx5[ARRAY_SIZE(tx5)] = {0, };
  72.     struct spi_ioc_transfer tr5 = {
  73.         .tx_buf = (unsigned long)tx5,
  74.         .rx_buf = (unsigned long)rx5,
  75.         .len = ARRAY_SIZE(tx5),
  76.         .delay_usecs = delay,
  77.         .speed_hz = speed,
  78.         .bits_per_word = bits,
  79.     };
  80.         uint8_t tx6[] = {
  81.         0x31, 30,
  82.     };
  83.     uint8_t rx6[ARRAY_SIZE(tx6)] = {0, };
  84.     struct spi_ioc_transfer tr6 = {
  85.         .tx_buf = (unsigned long)tx6,
  86.         .rx_buf = (unsigned long)rx6,
  87.         .len = ARRAY_SIZE(tx6),
  88.         .delay_usecs = delay,
  89.         .speed_hz = speed,
  90.         .bits_per_word = bits,
  91.     };
  92.         uint8_t tx7[] = {
  93.         0x26, 0x07,
  94.     };
  95.     uint8_t rx7[ARRAY_SIZE(tx7)] = {0, };
  96.     struct spi_ioc_transfer tr7 = {
  97.         .tx_buf = (unsigned long)tx7,
  98.         .rx_buf = (unsigned long)rx7,
  99.         .len = ARRAY_SIZE(tx7),
  100.         .delay_usecs = delay,
  101.         .speed_hz = speed,
  102.         .bits_per_word = bits,
  103.     };
  104.         uint8_t tx8[] = {
  105.         0x20, 0x0E,
  106.     };
  107.     uint8_t rx8[ARRAY_SIZE(tx8)] = {0, };
  108.     struct spi_ioc_transfer tr8 = {
  109.         .tx_buf = (unsigned long)tx8,
  110.         .rx_buf = (unsigned long)rx8,
  111.         .len = ARRAY_SIZE(tx8),
  112.         .delay_usecs = delay,
  113.         .speed_hz = speed,
  114.         .bits_per_word = bits,
  115.     };
  116.          ioctl(fdo,1,0); //CE=0, chip enable
  117.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr1);
  118.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr2);
  119.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr3);
  120.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr4);
  121.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr5);
  122.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr6);
  123.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr7);
  124.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr8);
  125.     
  126. }
  127. void NRF24L01_TX (int fdo, int fd) //send message funcion
  128. {
  129.         int num;
  130.         int t;
  131.                 uint8_t tx1[] = {
  132.         0x30, 0xE7, 0xD3, 0xF0, 0x35, 0x77,
  133.     };
  134.     uint8_t rx1[ARRAY_SIZE(tx1)] = {0, };
  135.     struct spi_ioc_transfer tr1 = {
  136.         .tx_buf = (unsigned long)tx1,
  137.         .rx_buf = (unsigned long)rx1,
  138.         .len = ARRAY_SIZE(tx1),
  139.         .delay_usecs = delay,
  140.         .speed_hz = speed,
  141.         .bits_per_word = bits,
  142.     };
  143.         uint8_t tx2[] = {
  144.         0x2A, 0xE7, 0xD3, 0xF0, 0x35, 0x77,
  145.     };
  146.     uint8_t rx2[ARRAY_SIZE(tx2)] = {0, };
  147.     struct spi_ioc_transfer tr2 = {
  148.         .tx_buf = (unsigned long)tx2,
  149.         .rx_buf = (unsigned long)rx2,
  150.         .len = ARRAY_SIZE(tx2),
  151.         .delay_usecs = delay,
  152.         .speed_hz = speed,
  153.         .bits_per_word = bits,
  154.     };
  155.         uint8_t tx3[] = {
  156.         0x21, 0x01,
  157.     };
  158.     uint8_t rx3[ARRAY_SIZE(tx3)] = {0, };
  159.     struct spi_ioc_transfer tr3 = {
  160.         .tx_buf = (unsigned long)tx3,
  161.         .rx_buf = (unsigned long)rx3,
  162.         .len = ARRAY_SIZE(tx3),
  163.         .delay_usecs = delay,
  164.         .speed_hz = speed,
  165.         .bits_per_word = bits,
  166.     };
  167.         uint8_t tx4[] = {
  168.         0x22, 0x01,
  169.     };
  170.     uint8_t rx4[ARRAY_SIZE(tx4)] = {0, };
  171.     struct spi_ioc_transfer tr4 = {
  172.         .tx_buf = (unsigned long)tx4,
  173.         .rx_buf = (unsigned long)rx4,
  174.         .len = ARRAY_SIZE(tx4),
  175.         .delay_usecs = delay,
  176.         .speed_hz = speed,
  177.         .bits_per_word = bits,
  178.     };
  179.         uint8_t tx5[] = {
  180.         0x25, 0x00,
  181.     };
  182.     uint8_t rx5[ARRAY_SIZE(tx5)] = {0, };
  183.     struct spi_ioc_transfer tr5 = {
  184.         .tx_buf = (unsigned long)tx5,
  185.         .rx_buf = (unsigned long)rx5,
  186.         .len = ARRAY_SIZE(tx5),
  187.         .delay_usecs = delay,
  188.         .speed_hz = speed,
  189.         .bits_per_word = bits,
  190.     };
  191.         uint8_t tx6[] = {
  192.         0x31, 30,
  193.     };
  194.     uint8_t rx6[ARRAY_SIZE(tx6)] = {0, };
  195.     struct spi_ioc_transfer tr6 = {
  196.         .tx_buf = (unsigned long)tx6,
  197.         .rx_buf = (unsigned long)rx6,
  198.         .len = ARRAY_SIZE(tx6),
  199.         .delay_usecs = delay,
  200.         .speed_hz = speed,
  201.         .bits_per_word = bits,
  202.     };
  203.         uint8_t tx7[] = {
  204.         0x26, 0x07,
  205.     };
  206.     uint8_t rx7[ARRAY_SIZE(tx7)] = {0, };
  207.     struct spi_ioc_transfer tr7 = {
  208.         .tx_buf = (unsigned long)tx7,
  209.         .rx_buf = (unsigned long)rx7,
  210.         .len = ARRAY_SIZE(tx7),
  211.         .delay_usecs = delay,
  212.         .speed_hz = speed,
  213.         .bits_per_word = bits,
  214.     };
  215.         uint8_t tx8[] = {
  216.         0x20, 0x0E,
  217.     };
  218.     uint8_t rx8[ARRAY_SIZE(tx8)] = {0, };
  219.     struct spi_ioc_transfer tr8 = {
  220.         .tx_buf = (unsigned long)tx8,
  221.         .rx_buf = (unsigned long)rx8,
  222.         .len = ARRAY_SIZE(tx8),
  223.         .delay_usecs = delay,
  224.         .speed_hz = speed,
  225.         .bits_per_word = bits,
  226.     };
  227.                 uint8_t txa[] = {
  228.         0xA0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
  229. 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,0x28, 0x29, 0x30,
  230.     };
  231.     uint8_t rxa[ARRAY_SIZE(txa)] = {0, };
  232.     struct spi_ioc_transfer tra = {
  233.         .tx_buf = (unsigned long)txa,
  234.         .rx_buf = (unsigned long)rxa,
  235.         .len = ARRAY_SIZE(txa),
  236.         .delay_usecs = delay,
  237.         .speed_hz = speed,
  238.         .bits_per_word = bits,
  239.     };
  240.         ioctl(fdo, 1, 0);  //CE=0, StandBy Mode
  241.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr2);  //load the address of the receiver
  242.         ioctl(fd, SPI_IOC_MESSAGE(1), &tra);  //load the data
  243.         ioctl(fd, SPI_IOC_MESSAGE(1), &tr8);  //IRQ works, and 16CRC, and TX mode
  244.         ioctl(fdo, 0, 0);  //CE=1, to send the message
  245.        //****To display the sending message
  246.         for (num = 1; num < 31; num++) {
  247.         printf("%.2X ", txa[num]);  //txa[] is right, not rxa[]
  248.     }
  249.     puts("");
  250. }
  251.           
  252. int tx01()
  253. {
  254.         int success = 0;
  255.     int fd;
  256.         int fdo;
  257.     fd = open(device, O_RDWR);
  258.         fdo = open("/dev/CE", O_RDWR);
  259.     /*
  260.      * spi mode
  261.      */
  262.     ioctl(fd, SPI_IOC_WR_MODE, &mode);
  263.     ioctl(fd, SPI_IOC_RD_MODE, &mode);
  264.     
  265.     /*
  266.      * bits per word
  267.      */
  268.     ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
  269.     
  270.     ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
  271.     
  272.     /*
  273.      * max speed hz
  274.      */
  275.     ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
  276.     ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
  277.     printf("spi mode: %d\n", mode);
  278.     printf("bits per word: %d\n", bits);
  279.     printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
  280.                 uint8_t txi[] = {
  281.         0x27, 0xFF,
  282.     };
  283.     uint8_t rxi[ARRAY_SIZE(txi)] = {0, };
  284.     struct spi_ioc_transfer tri = {
  285.         .tx_buf = (unsigned long)txi,
  286.         .rx_buf = (unsigned long)rxi,
  287.         .len = ARRAY_SIZE(txi),
  288.         .delay_usecs = delay,
  289.         .speed_hz = speed,
  290.         .bits_per_word = bits,
  291.     };
  292.                 uint8_t txj[] = {
  293.         0x07,
  294.     };
  295.     uint8_t rxj[ARRAY_SIZE(txj)] = {0, };
  296.     struct spi_ioc_transfer trj = {
  297.         .tx_buf = (unsigned long)txj,
  298.         .rx_buf = (unsigned long)rxj,
  299.         .len = ARRAY_SIZE(txj),
  300.         .delay_usecs = delay,
  301.         .speed_hz = speed,
  302.         .bits_per_word = bits,
  303.     };
  304.         init_NRF24L01(fdo,fd);
  305.         while(1)
  306. {
  307.         NRF24L01_TX (fdo,fd);
  308.   
  309.         ioctl(fdo, 1, 0);  //CE=0
  310.         ioctl(fd, SPI_IOC_MESSAGE(1), &trj);  //read the STATUS
  311.         if((rxj[0]&0x20)==0x20)  //send messages successfully
  312.            success = 1;
  313.         ioctl(fd, SPI_IOC_MESSAGE(1), &tri);  // write the STATUS,to clear the IRQ
  314.         if(success==1)
  315.           break;
  316. }
  317.         close(fd);
  318.         close(fdo);
  319.         return 1;
  320. }


头文件写好以后,写了一个starttx.c文件:
复制代码
  1. #include "tx01_30_simply.h"
  2. #include <jni.h>
  3. jint
  4. Java_com_test_r1_R1_starttx( JNIEnv* env,
  5.                                                   jobject this )
  6. {
  7.     return tx01();
  8. }


android.mk文件是这么写的:
复制代码
  1. LOCAL_PATH := $(call my-dir)
  2. include $(CLEAR_VARS)
  3. LOCAL_MODULE    := tx01
  4. LOCAL_SRC_FILES := tx01_30_simply.c
  5. LOCAL_C_INCLUDES := /opt/FriendlyARM/mini6410/android/linux-2.6.36-android/include
  6. include $(BUILD_SHARED_LIBRARY)
  7. include $(CLEAR_VARS)
  8. LOCAL_MODULE    := starttx
  9. LOCAL_SRC_FILES := starttx.c
  10. LOCAL_STATIC_LIBRARIES := tx01
  11. include $(BUILD_SHARED_LIBRARY)

但是在linux下编译无论如何也无法通过,求助这里的高手们,谢谢!!!
级别: 新手上路
UID: 38877
精华: 0
发帖: 40
金钱: 200 两
威望: 40 点
综合积分: 80 分
注册时间: 2011-03-02
最后登录: 2013-12-11
1楼  发表于: 2011-05-09 13:20
编译时的提示信息如下:
Compile thumb  : tx01 <= tx01_30_simply.c
In file included from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/sys/types.h:39,
                 from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/unistd.h:33,
                 from /opt/FriendlyARM/mini6410/android/linux-2.6.36-android/R1/jni/tx01_30_simply.c:3:
/opt/FriendlyARM/mini6410/linux/linux-2.6.36/include/linux/types.h:13:2: warning: #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
In file included from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/asm/signal.h:82,
                 from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/signal.h:35,
                 from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/sys/select.h:34,
                 from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/unistd.h:34,
                 from /opt/FriendlyARM/mini6410/android/linux-2.6.36-android/R1/jni/tx01_30_simply.c:3:
/opt/FriendlyARM/mini6410/linux/linux-2.6.36/include/asm-generic/signal.h:94: error: '__BITS_PER_LONG' undeclared here (not in a function)
/opt/FriendlyARM/mini6410/linux/linux-2.6.36/include/asm-generic/signal.h:95: error: conflicting types for 'sigset_t'
/opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/asm/signal.h:20: note: previous declaration of 'sigset_t' was here
In file included from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/signal.h:35,
                 from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/sys/select.h:34,
                 from /opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/unistd.h:34,
                 from /opt/FriendlyARM/mini6410/android/linux-2.6.36-android/R1/jni/tx01_30_simply.c:3:
/opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/asm/signal.h:84: error: redefinition of 'struct sigaction'
/opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/asm/signal.h:97: error: redefinition of 'struct sigaltstack'
/opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/asm/signal.h:101: error: conflicting types for 'stack_t'
/opt/FriendlyARM/mini6410/linux/linux-2.6.36/include/asm-generic/signal.h:119: note: previous declaration of 'stack_t' was here
make: *** [/opt/FriendlyARM/mini6410/android/linux-2.6.36-android/R1/obj/local/armeabi/objs/tx01/tx01_30_simply.o] 错误 1
级别: 圣骑士
UID: 9690
精华: 0
发帖: 369
金钱: 1955 两
威望: 415 点
综合积分: 738 分
注册时间: 2009-10-10
最后登录: 2017-11-21
2楼  发表于: 2011-05-11 11:15
我怎么看的error都是undefined 或者redefine,代码有问题吧
级别: 新手上路
UID: 40694
精华: 0
发帖: 13
金钱: 65 两
威望: 13 点
综合积分: 26 分
注册时间: 2011-03-21
最后登录: 2012-04-16
3楼  发表于: 2011-05-11 19:34
别人看了这些打印,解决起来确实很难。
级别: 新手上路
UID: 38877
精华: 0
发帖: 40
金钱: 200 两
威望: 40 点
综合积分: 80 分
注册时间: 2011-03-02
最后登录: 2013-12-11
4楼  发表于: 2011-05-12 09:46

 回 2楼(xiexiedajia) 的帖子

谢谢了,我把spi驱动拷到了ndk的android-3文件夹下,然后编译就没问题了
级别: 骑士
UID: 42149
精华: 2
发帖: 201
金钱: 1115 两
威望: 223 点
综合积分: 442 分
注册时间: 2011-04-05
最后登录: 2013-03-29
5楼  发表于: 2011-05-12 17:19
拷过来的文件中有类型已经在原来的文件中定义过了。
/opt/FriendlyARM/mini6410/android/android-ndk-r5b/platforms/android-3/arch-arm/usr/include/asm/signal.h
/opt/FriendlyARM/mini6410/linux/linux-2.6.36/include/asm-generic/signal.h