jackarm 发表于 2009-9-20 09:31:21

mini2440串口测试代码,bootloader

/*
;************************************************************************************************************
;*
;*                                        http://blog.chinaunix.net/u3/104083/
;*                                    
;*--------------------------------------------- 文件信息 ----------------------------------------------------                                    
;*
;* 文件名称 : MAIN.c       
;* 文件功能 : 应用程序
;* 补充说明 :
;*-------------------------------------------- 最新版本信息 -------------------------------------------------
;* 修改作者 : JackArm
;* 修改日期 : 2009/09/09
;* 版本声明 : V1.0.1
;*-----------------------------------------------------------------------------------------------------------
;*-----------------------------------------------------------------------------------------------------------
;************************************************************************************************************
;*/

#include   <stdio.h>   
#include   <stdlib.h>   
#include   <stdarg.h>
#include   <string.h>

#include"../Inc/jack2440.h"

#define UART_BAUD0 115200//串口波特率

#define FCLK 400000000
#define HCLK (FCLK/4)
#define PCLK (HCLK/2)
#define U32 unsigned int

void UartSend_String(char *pdate);
/*
*************************************************************************************************************
- 函数名称 : void Delay(unsigned int tem)
- 函数说明 : 延时函数
- 输入参数 : tem
- 输出参数 : 无
*************************************************************************************************************
*/
void Delay(unsigned int tem)
{
while(tem--);
}

/*
*************************************************************************************************************
- 函数名称 : void UartZero_Rcv(void)
- 函数说明 : 中断初始化函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void __irq UartZero_Rcv(void)
{
unsigned char Rcv;

Rcv = rURXH0;
Rcv = '\0';
UartSend_String((char*)Rcv);
ClearSubPending(BIT_SUB_RXD0);
ClearPending(BIT_UART0);
}

/*
*************************************************************************************************************
- 函数名称 : void Interrupt_Init(void)
- 函数说明 : 中断初始化函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void Interrupt_Init()
{
        pISR_UART0=(unsigned int)UartZero_Rcv;//串口收中断函数
        rINTMOD=0;                            //所用中断都是IRQ
        rINTMSK=0xefffffff;                   //开串口的中断
        rINTSUBMSK=0x7fe;                     //开串口收的中断
}
/*
*************************************************************************************************************
- 函数名称 : void UartInit(void)
- 函数说明 : 串口0的初始化函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void UartInit(void)
{
        rGPHCON = (2 << 6) | (2 << 4) | (2 << 2) | 2;//TXD0-GPH2 RXD0-GPH3 都在H口的
           rGPHUP= 0x0F;                                     //GPH上拉除能
    //初始化Uart相关寄存器
        rULCON0 = 0x3;
        rUCON0= 0x245;
        rUFCON0 = 0x0;
        rUMCON0 = 0x0;
    rUBRDIV0=( (int)(PCLK/16./UART_BAUD0+0.5) -1 );   //Baud rate divisior register 0
}

/*
*************************************************************************************************************
- 函数名称 : void UartInit(void)
- 函数说明 : 串口0的初始化函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void UartSend_String(char *pdate)
{
while((*pdate) != '\0' )
{
while(!(rUTRSTAT0&0x4));//等到发送缓冲区为空;
rUTXH0=*pdate;          //发送一个BYTE
pdate++;                //指针指向下一个字符
}
}
/*
*************************************************************************************************************
- 函数名称 : int Main(void)
- 函数说明 : C代码入口函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
int Main(void)
{
UartInit();
Interrupt_Init();
UartSend_String("/*********************************************/\n");
UartSend_String("/*    http://blog.chinaunix.net/u3/104083/   */\n");
UartSend_String("/*                   JackArm               */\n");
UartSend_String("/*********************************************/\n");
while(1)
{
Delay(900000);//灯闪烁
rGPBDAT =(rGPBDAT|(0xA<<5))&(~(rGPBDAT&(0xA<<5)));
}
return 0;
}

yanyi103 发表于 2009-9-21 13:02:51

没人顶我座个位置

heky 发表于 2009-9-21 13:03:28

kongxmxm 发表于 2009-11-6 14:09:42

gooogleman 发表于 2009-11-7 00:29:47

嘿嘿,不错。

jackarm 发表于 2010-7-15 18:40:50

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

MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Lu Li");
MODULE_DESCRIPTION("A simple Hello World");
MODULE_VERSION("V1.0");
static int hello_init(void)
{
      printk(KERN_ALERT"Hello World init!\n");
      return 0;
}

static void hello_exit(void)
{
      printk(KERN_ALERT"Hello World exit!\n");
}

module_init(hello_init);
module_exit(hello_exit);

Bird 发表于 2010-8-31 20:25:12

顶一个!

gracialee 发表于 2012-4-30 12:55:31

回头测试一下第一个程序,看能否在2440下裸奔。
页: [1]
查看完整版本: mini2440串口测试代码,bootloader