문제점 좀 지적해 주세요...

pdjj14의 이미지

spi 모듈을 작성했습니다...

그런데 크로스 컴파일 해서 올리면...

insert 까지는 되는데...

오픈하는 순간 다시 릴리즈 되어 버리네요...

문제점 좀 해결해 주세요...

코드 올립니다...

다른 문제점도 발견되면 말씀해 주세요...

참...리드도 인식이 안되더군요...ㅠㅠ...

컴파일 할 때, initialization from incompatible pointer type 라는 메시지가 나오더군요...

롸이트는 아직 코딩 안 했구요...
----------------------------------------------------------------

/*********************************************************************************
*
* SPI Standalone  Microwire Device Driver for LINUX based on PXA255
* by Jae Joong Han
*
*********************************************************************************


*/

#ifndef __KERNEL__
#  define __KERNEL__
#endif
#ifndef MODULE
#  define MODULE
#endif

#include <linux/config.h>
#include <linux/module.h>

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/fcntl.h>
#include <linux/ioport.h>
#include <linux/vmalloc.h>
#include <linux/ioctl.h>
#include <linux/init.h>

#include <asm/system.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/hardware.h>
#include <asm/arch-pxa/pxa-regs.h>




#define SSP          0x41000000
#define SSCR0_OFFSET 0x00
#define SSCR1_OFFSET 0x04
#define SSDR_OFFSET  0x10
#define SSSR_OFFSET  0x08

static void *ssp_base;


#define MODULE_VERSION "1.0"
#define MODULE_NAME    "SPI"


#define SPI_MAJOR          114
#define DEVICE_NAME         "spi"


static int tiny_spi_usage = 0;



int tiny_spi_open(struct inode *inode, struct file *file)
{
     int b;

     if( tiny_spi_usage != 0 ) return -EBUSY; /* already use? */

     MOD_INC_USE_COUNT;

     tiny_spi_usage = 1;

     printk("TINY SPI DEVICE OPEN\n");

     for(b=0;b<9;b++)
        printk("count = %d\n", b);


     return 0;
}


int tiny_spi_release(struct inode *inode, struct file *file)
{
    tiny_spi_usage = 0;

    printk("TINY SPI DEVICE CLOSE\n");

    MOD_DEC_USE_COUNT;

    return 0;
}


ssize_t tiny_spi_write(struct file *file, const char *data, size_t len, loff_t *offset)
{

    return(1);
}


ssize_t tiny_spi_read(struct file *file, const char *data, size_t len, loff_t *offset)
{
        int sspdata, status, temp;
        u8 buffer[20];
        u8 *w_data;
        u8 k_data;
        unsigned int i,j;
        i = 0;
        j = 0;

        printk("check1\n");
        while((status = readl(ssp_base + SSSR_OFFSET)) != 0 ) /* read the status register */
        {
printk("check2\n");

                temp = readl(ssp_base + SSDR_OFFSET);
                buffer[j++] = (u8)(temp >> 8);
                /* read the receive FIFO to clear out old stuff */
        }
printk("check3\n");

#ifdef M_DEBUG
        printk("old Data [ ");
        for(i=0 ; i<j ;i++)
                printk(" 0x%02X ", buffer[i]);
        printk("], i:%d\n",i);
        i=j=0;
#endif
printk("check4\n");

//      w_data = data;
        for(i=0 ; i<len ; i++) {
printk("check5\n");

                        k_data = w_data[i];
                        writel(k_data << 8, ssp_base + SSDR_OFFSET);
        }
printk("check6\n");

#ifdef M_DEBUG
        printk("Written Data [ ");
                                 for(j=0 ; j<i ;j++)
                printk(" 0x%02X ", w_data[j]);
        printk("], j:%d\n",j);
        j=0;
#endif
printk("check7\n");

        while((status = readl(ssp_base + SSSR_OFFSET)) != 0)
        {
printk("check8\n");
                sspdata = readl(ssp_base + SSDR_OFFSET);
                buffer[j++] = (u8)sspdata;

        }
printk("check9\n");

#ifdef M_DEBUG
        printk("Read Data [ ");
        for(i=0 ; i<j ;i++)
                printk(" 0x%02X ", buffer[i]);
        printk("], j:%d\n",j);
#endif
printk("check10\n");

        for(i=0 ; i<j ; i++)
{printk("check11\n");
//              *data++ = buffer[i];
}
        return (1);
}




static struct file_operations tiny_spi_fops =
{
        read:           tiny_spi_read,
        write:          tiny_spi_write,
        open:           tiny_spi_open,
        release:        tiny_spi_release,
};





int init_module(void)
{
    int result;
 unsigned int r;


 ssp_base = ioremap_nocache(SSP,0x2000000);
  printk("ssp_base       = 0x%08X\n",ssp_base);

/*
 * SSCR1 binary value 0000 0000 0000 0000 = 0x0000
 * External Clock Select (ECS),          0 uses internal clock
 * Serial Clock Phase (SPH),             0 adds 1 clock cycle delay
 * Serial Clock Polarity (SPO),          0 holds SC low during idle
 * Loopback Mode (LBM),                  0 diables loopback mode
 * Transmit FIFO Interrupt Enable (TIE), 0 masks interrupt
 * Receive FIFO Interrupt Enable (RIE),  0 masks interrupt
*/
  writel(0x0020, ssp_base + SSCR1_OFFSET);

/*
 * SSCR0 binary value 1111 1111 1000 0111 = 0xFF87
 * Data Size Select (DSS),               0111 selects 8 bit length
 * Frame Format (FRF),                   00 selects Motorola SPI
 * Synchronous Serial Port Enable (SSE), 1 for enable
 * Serial Clock Rate (SCR),              11111111 selects slowest clock
*/
  writel(0xFFA0, ssp_base + SSCR0_OFFSET);

/* read the registers and printout results */
  r = readl(ssp_base + SSCR1_OFFSET);

  printk("SSCR1          = 0x%04X\n",r);
  r = readl(ssp_base + SSCR0_OFFSET);
  printk("SSCR0          = 0x%04X\n",r);

/* everything initialized */
  printk(KERN_INFO "%s %s initialized\n", MODULE_NAME, MODULE_VERSION);

/* Register the character driver */
    result = register_chrdev( SPI_MAJOR, DEVICE_NAME, &tiny_spi_fops );
    printk("%d....\n", result);
    if (result < 0)
    {
        printk(KERN_WARNING "SPI: Can't get Major Number [%d]\n", SPI_MAJOR);
        return result;
    }
    printk(" Init madule, Succeed. This Device is [%s] and Major Number is [%d]\n", DEVICE_NAME, SPI_MAJOR);
    return 0;
}



void cleanup_module(void)
{
    iounmap(ssp_base);

    if ( !unregister_chrdev( SPI_MAJOR, DEVICE_NAME) )
    {
        printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION);
    }
    else
    {
        printk("SPI Device EXIT FAIL.\n");
    }
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.