[] Non-embedded operating system GPIO port and the LED lamp controller programming

GPIO controller

Outline

S3C6410 total IO port 187, is divided into 17 PORT, each of the IO port may be used in the input line pins, output pins and other function pin wire lines, can be arranged by each port own function control register . Here Insert Picture Description
'Here Insert Picture Description

The internal architecture

  • GPIO controller hanging APB bus, belonging to the low-speed device.
  • The controller includes a register file and the corresponding functional circuit composed of the functional circuit can be controlled by the user according to the working registers manner.
  • Entire controller including Alive-Part , OFF-Part two portions, except that if there is a power supply when MODE SLEEP , power is supplied when alive-part, so that the port can be used as a wake up signal wake -up
    Here Insert Picture Description

Port register

GPIO Control Register

  • Function - function configuration corresponding port

Here Insert Picture Description

GPIO Data Register

  • Data register bit corresponding to each bit line of the corresponding port IO
  • If the IO line is used as input pins, pins with the change line level changes (which corresponds to a value of 0 or 1) by a single bit;
  • If the IO line is used as output pin, then the bit value is 1 bit , the corresponding outer lead wire is high (typically about 3.3V), then the bit when the bit is 0 , the corresponding outer lead foot line is low (typically slightly larger than 0V)

Here Insert Picture Description

Pull-up register GPIO

  • This register can cook for pulling arm or pull-down io some special treatment, which in some instances is very useful to avoid the pull-up or pull-down resistor on the pcb, the circuit design can be simplified external

Here Insert Picture Description

LED flashes non-OS

Development steps

  1. Understand the hardware chart
  2. Write drive
  3. Write applications
  4. use tools
  5. system debugging
    Here Insert Picture Description

Development board diode

Here Insert Picture Description

Read circuit diagrams

S3C6410 chip manual

Here Insert Picture Description

Framework program

  • compilation
;asses.s内容
	AREA Init, CODE READONLY
	ENTRY
_start
        B Main
	END
  • Write applications
// ledapp.c
void main()
{
	ledconfig();
	for()
	{
		ledon();delay();
	  	ledoff();delay();
	}
}
  • Write drive
// leddrv.c
void ledconfig()
{
	……
}
void ledon()
{
	……
}
void ledoff()
{
	……
}

Write drive example leddrv.c

  • M M1 port configured as an output pin
#define rGPMCON  *((volatile int *) 0x7f008820 )
void ledconfig()
	tmp= rGPMCON;		//读出端口寄存器值
	tmp &=! (0xF<<4);	//把bit4~7清0
	tmp |= (1<<4);		//把bit4~7写入0x1值
	rGPMCON = tmp;		//写回到端口寄存器
}
  • Lighting
    configuration port M1 outputs a low level M
#define rGPMDAT  *((volatile int *) 0x7f008824 )
void ledon()
{
	tmp= rGPMDAT;		//读出端口寄存器值
	tmp &=! (0x1<<1);	//把bit1清0
	tmp |= (0<<1);		//把bit1写入0x0值
	rGPMDAT = tmp;		//写回到端口寄存器
}
  • Off
    configuration port M1 outputs a high level M
void ledoff()
{
	tmp= rGPMDAT;		//读出端口寄存器值
	tmp &=	! (0x1<<1);	//把bit1清0
	tmp |= (1<<1);		//把bit1写入0x1值
	rGPMDAT = tmp;		//写回到端口寄存器
}

after class homework

In the preparation of a non-flashing LED light operating system program, claim
1) and the control GPM2 GPM4 port;
2) write drivers and applications.

At first embedded, many do not understand for the hardware, but this does not affect my program.
Here Insert Picture Description

The answer is as follows:

  • Drivers leddrv.c
//  leddrv.c
#define rGPMCON  *((volatile int *) 0x7f008820 )
// 控制GPM2和GPM4端口
void ledconfig(){
	tmp= rGPMCON;		//读出端口寄存器值
	tmp &= !(0xF<<8);	//把bit8~11清0
	tmp |= (1<<8);		//把bit8~11写入0x1值
	tmp &= !(0xF<<16);	//把bit16~19清0	
	tmp |= (1<<16);		//把bit16~19写入0x1值
	// 这里再提供一种简便写法,完全等价上面四行
	// tmp &= !(0xF<<8 | 0xF<<16);
	// tmp |= (1<<8 | 1 <<16);
	// 这里再再提供一种写法
	// tmp &= !(0xF0F << 8);
	// tmp |= (0x101 << 8);
	rGPMCON = tmp;		//写回到端口寄存器
}
#define rGPMDAT  *((volatile int *) 0x7f008824 )
void ledon()
{
	tmp= rGPMDAT;		//读出端口寄存器值
	tmp &= !(0x1<<2);	//把bit2清0
	tmp |= (0<<2);		//把bit2写入0x0值
	tmp &= !(0x1<<4);	//把bit4清0
	tmp |= (0<<4);		//把bit4写入0x0值
	// 这里再提供一种简便写法,完全等价上面四行
	// tmp &= !(0x1<<2 | 0x1<<4);
	// tmp |= (0<<2 | 0<<4)
	rGPMDAT = tmp;		//写回到端口寄存器
}
void ledoff()
{
	tmp= rGPMDAT;		//读出端口寄存器值
	tmp &= !(0x1<<2);	//把bit2清0
	tmp |= (1<<2);		//把bit2写入0x1值
	tmp &= !(0x1<<4);	//把bit4清0
	tmp |= (1<<4);		//把bit4写入0x1值
	// 这里再提供一种简便写法,完全等价上面四行
	// tmp &= !(0x1<<2 | 0x1<<4);
	// tmp |= (1<<2 | 1<<4)
	// 还可以这么写
	// tmp &= !(0x5 << 2);
	// tmp |= (0x5 << 2);// bit2,bit4写入1,相当于101左移2位
	rGPMDAT = tmp;		//写回到端口寄存器
}
  • Applications ledapp.c
// leadapp.c
void delay(){ // 停止一段时间
	for( i=0;i<1000;i++)
		for( j=0;j<1000;j++);
}
void main()
{
	ledconfig(); // 配置驱动
	while(1)
	{
		ledon();delay();
		ledoff();delay();
	}
}

Supporting the work

(1) S3C6410 processor using its internal IP core ( the ARM11 ), the built-in processor ( watchdog controller, GPIO interface controller ) and other interface controllers.

(2) the core is to master programming interface port registers, general programmer to understand the definitions and usage port registers by (chip manual). Suppose a 0xC2000004,32 port register address bit size, it needs to be written to the binary value of bits 8-9 (10) 2, while the other bit remains unchanged, write the key code (method using a memory pointer)

tmp = *((volatile int*)0xC2000004);
tmp &= !( 0x3 << 8);
tmp |= (0x3 << 8);
*((volatile int*)0xC2000004) = tmp;

(3) components belonging to the watchdog ( hardware module ), which is a core function ( detection software code runaway, when the system is "running out" into the loop and restore the operation of the system ).

Published 170 original articles · won praise 47 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_43734095/article/details/104803058