AT91SAM9260 驱动编写

dickens88 2011-03-28 08:55:53
我是第一次弄嵌入式,前几天终于弄好了一个字符驱动设备,现在想写程序控制板子上的GPIO,比如控制LED什么的,可是在网上也找不到资料。。。求高手指点,最好有个示例程序什么的,我现在手头就只有板子的数据手册,但是看那个数据手册我实在不知道要怎么编程
...全文
293 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dickens88 2011-03-29
  • 打赏
  • 举报
回复
非常感谢~
jian 2011-03-29
  • 打赏
  • 举报
回复
http://www.atmel.com/get_started/AT91/next_step.asp?category_id=163&family_id=605&source=getting_started

可以连接到linux4sam
jian 2011-03-29
  • 打赏
  • 举报
回复
访问下这里:

http://www.atmel.com/dyn/products/tools_docs.asp?category_id=163&family_id=605&subfamily_id=722&tool_id=3933

然后你就可以发现所有的资源,包括linux的sdk都有,而且有几个版本,都可以运行的。
jian 2011-03-28
  • 打赏
  • 举报
回复
1. 你可以到atmel的网站下载相关例程。atmel已经在库里面包装了gpio操作。
2. 如果你想了解的更深刻一些,那可以按照寄存器说明自己来写。下面是我以前的一段程序,用在at91sam7x上的,和at91sam9x基本上是一样的。你稍微改改也可以用起来的。

/*
*********************************************************************************************************
* gpio.h
*
* Module Description:
* gpio operations
*
* Copyright (C) 2007 http://dzdaren.taobao.com
* Author: http://dzaren.taobao.com
* http://blog.csdn.net/sjsj
* Date: 2007-Oct-24th
*
* Modify History:
*********************************************************************************************************
*/

#ifndef __GPIO_H__
#define __GPIO_H__

extern void vGPIOISREntry(void); // GPIO interrupt entry. see in gpio_isr.s79

extern xSemaphoreHandle xSemaphoreGPIO;


/****************************************************************************
* function name: gpio_init
*
* description : This function initializes gpio port for infra-red sensor.
*
* return : none
****************************************************************************/
void gpio_init(void);

/****************************************************************************
* function name: vuGPIO_TASK
*
* description : task responding to infra red GPIO level change interrupt.
*
* return : none
****************************************************************************/
void vuGPIO_TASK( void *pvParameters );

#endif // __GPIO_H__





/*
*********************************************************************************************************
* gpio.c
*
* Module Description:
* GPIO operations.
*
* Copyright (C) 2007 http://dzdaren.taobao.com
* Author: http://dzaren.taobao.com
* http://blog.csdn.net/sjsj
* Date: 2007-Oct-24th
*
* Modify History:
*********************************************************************************************************
*/

#include "bsp_includes.h"
#include "esmtp.h"

#define SET_REG(addr, value) (*((unsigned int *)(addr)))=((unsigned int)(value))
#define GET_REG(addr) (*((unsigned int *)(addr)))

#define INFRARED_OUT_CHANNEL1 0x01
#define INFRARED_OUT_CHANNEL2 0x02

xSemaphoreHandle xSemaphoreGPIO = NULL;
static int interrupt_count = 0;

/****************************************************************************
* function name: gpio_init
*
* description : This function initializes gpio port for infra-red sensor.
*
* return : none
****************************************************************************/
void gpio_init(void)
{
SET_REG(0xFFFFFC10, 0x00000008); // PMC clock enable GPIOB (PMC_PCER)
SET_REG(0xFFFFF600, 0x60000000); // Select GPIO function, PB29&PB30 (PIO_PER)
SET_REG(0xFFFFF614, 0x60000000); // Configure GPIO as input, PB29&PB30 (PIO_ODR)
SET_REG(0xFFFFF620, 0x60000000); // Enable input glitch filter to avoid noise (PIO_IFER)

// Setup GPIO interrupt
vSemaphoreCreateBinary(xSemaphoreGPIO);
if(xSemaphoreGPIO)
{
xSemaphoreTake(xSemaphoreGPIO, 0);
portENTER_CRITICAL();
{
printk("config gpio interrupts...\n");
SET_REG(0xFFFFF124, 0x00000008); // Disable GPIOB levle-change interrupt (AIC_IDCR)
SET_REG(0xFFFFF08C, (unsigned int)vGPIOISREntry); // Set GPIOB handler entry (AIC_SVR3)
SET_REG(0xFFFFF00C, 0x00000006); // Set GPIOB at level 6, low level trigger (AIC_SMR3)
SET_REG(0xFFFFF128, 0x00000008); // Clear existing GPIOB interrupt if any (AIC_ICCR)
SET_REG(0xFFFFF640, 0x60000000); // Enable PB29&PB30 level-change interrupt (PIO_PER)
SET_REG(0xFFFFF120, 0x00000008); // Enable GPIO interrup in AIC (AIC_IECR)
}
portEXIT_CRITICAL();
}

interrupt_count = 0;
}

/****************************************************************************
* function name: gpiob_isr_handler
*
* description : This is GPIOB level-change interrupt handler.
*
* AT91SAM7X256 can not identify low level or high level trigger
* of GPIO interrupt. So every voltage process of high->low->high
* will generate two interrupts: high->low and low->high.
*
* In fact, in a process of high->low->high, usually two high->low
* interrupts and two low->high interrupts can occur. And I can not
* find a way to remove these additional interrupts, so I can only
* count the interrupt times in such a proces, and release semophore
* only in the handler of the first high->low interrupt. The glitch
* filter seems help little here.
*
* return : none
****************************************************************************/
__arm void gpiob_isr_handler(void)
{
unsigned int pio_isr;
unsigned int pio_value;
int i;

portBASE_TYPE xSwitchRequired = pdFALSE;

pio_isr = GET_REG(0xFFFFF64C);
if((pio_isr & 0x60000000) == 0)
{
interrupt_count = 0;
portEND_SWITCHING_ISR( xSwitchRequired );
SET_REG(0xFFFFF130, 0); // Write any value to AIC_EOICR to end int handling
return;
}

pio_value = GET_REG(0xFFFFF63C);
if((pio_value & 0x40000000) == 0) // if PB30 is changed
{
for(i=0; i<1024*6*300; i++); // delay 300ms
pio_value = GET_REG(0xFFFFF63C); // read again
if((pio_value & 0x40000000) == 0)
{
//printk("PB30 is changed\n");
interrupt_count ++;
}
}
else if ((pio_value & 0x20000000) == 0) // if PB29 is changed
{
for(i=0; i<1024*6*300; i++); // delay 300ms
pio_value = GET_REG(0xFFFFF63C); // read again
if((pio_value & 0x20000000) == 0)
{
//printk("PB29 is changed\n");
interrupt_count ++;
}
}
else
{
//printk("Unknown IO is changed.\n");
interrupt_count = 0;
}

if(interrupt_count == 1)
{
xSwitchRequired = xSemaphoreGiveFromISR( xSemaphoreGPIO, pdFALSE );
}
portEND_SWITCHING_ISR( xSwitchRequired );

SET_REG(0xFFFFF130, 0); // Write any value to AIC_EOICR to end int handling
}

/****************************************************************************
* function name: vuGPIO_TASK
*
* description : task responding to infra red GPIO level change interrupt.
*
* return : none
****************************************************************************/
void vuGPIO_TASK( void *pvParameters )
{
while(1)
{
// try to get gpio semaphore
if(xSemaphoreTake(xSemaphoreGPIO, (portTickType)-1) < 1) // wait the semphore infinitely
{
continue;
}

printk("GPIO task ...\n");
if(test_email_para())
{
//error
printk("Email para setting error!\r\n");
}
else
{
send_email_handle();
}

}
}

如果觉得我的回复有价值,请进一步访问
http://dzaren.taobao.com
http://blog.csdn.net/sjsj












dickens88 2011-03-28
  • 打赏
  • 举报
回复
求高手啊~
dickens88 2011-03-28
  • 打赏
  • 举报
回复
我现在手头有的就只有arm-linux-gcc的交叉编译环境,是不是还有其他的东西呢
dickens88 2011-03-28
  • 打赏
  • 举报
回复
那这些库在哪里下载呢

27,511

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧