Pages

Poll

Powered by Blogger.

About Me

Followers

Blog Archive

About Me

Followers

Programming Tutorials on different platforms

HYe all

Search This Blog

RSS

SYSTEM PROGRAMMING II

C-language header file that describes the processor's registers should also be created. An example of descriptive names for some of the registers in the PXA255 processor follows. It is also helpful to define descriptive names for particular bits in a register if they will be addressed individually.
/********************************************************
* PXA255 XScale ARM Processor On-Chip Peripherals
********************************************************/

/* Timer Registers */
#define TIMER_0_MATCH_REG (*((uint32_t volatile *)0x40A00000))
#define TIMER_1_MATCH_REG (*((uint32_t volatile *)0x40A00004))
#define TIMER_2_MATCH_REG (*((uint32_t volatile *)0x40A00008))
#define TIMER_3_MATCH_REG (*((uint32_t volatile *)0x40A0000C))
#define TIMER_COUNT_REG (*((uint32_t volatile *)0x40A00010))
#define TIMER_STATUS_REG (*((uint32_t volatile *)0x40A00014))
#define TIMER_INT_ENABLE_REG (*((uint32_t volatile *)0x40A0001C))

/* Timer Interrupt Enable Register Bit Descriptions */
#define TIMER_0_INTEN (0x01)
#define TIMER_1_INTEN (0x02)
#define TIMER_2_INTEN (0x04)
#define TIMER_3_INTEN (0x08)

/* Timer Status Register Bit Descriptions */
#define TIMER_0_MATCH (0x01)
#define TIMER_1_MATCH (0x02)
#define TIMER_2_MATCH (0x04)
#define TIMER_3_MATCH (0x08)

/* Interrupt Controller Registers */
#define INTERRUPT_PENDING_REG (*((uint32_t volatile *)0x40D00000))
#define INTERRUPT_ENABLE_REG (*((uint32_t volatile *)0x40D00004))
#define INTERRUPT_TYPE_REG (*((uint32_t volatile *)0x40D00008))

/* Interrupt Enable Register Bit Descriptions */
#define GPIO_0_ENABLE (0x00000100)
#define UART_ENABLE (0x00400000)
#define TIMER_0_ENABLE (0x04000000)
#define TIMER_1_ENABLE (0x08000000)
#define TIMER_2_ENABLE (0x10000000)
#define TIMER_3_ENABLE (0x20000000)

/* General Purpose I/O (GPIO) Registers */
#define GPIO_0_LEVEL_REG (*((uint32_t volatile *)0x40E00000))
#define GPIO_1_LEVEL_REG (*((uint32_t volatile *)0x40E00004))
#define GPIO_2_LEVEL_REG (*((uint32_t volatile *)0x40E00008))
#define GPIO_0_DIRECTION_REG (*((uint32_t volatile *)0x40E0000C))
#define GPIO_1_DIRECTION_REG (*((uint32_t volatile *)0x40E00010))
#define GPIO_2_DIRECTION_REG (*((uint32_t volatile *)0x40E00014))
#define GPIO_0_SET_REG (*((uint32_t volatile *)0x40E00018))
#define GPIO_1_SET_REG (*((uint32_t volatile *)0x40E0001C))
#define GPIO_2_SET_REG (*((uint32_t volatile *)0x40E00020))
#define GPIO_0_CLEAR_REG (*((uint32_t volatile *)0x40E00024))
#define GPIO_1_CLEAR_REG (*((uint32_t volatile *)0x40E00028))
#define GPIO_2_CLEAR_REG (*((uint32_t volatile *)0x40E0002C))
#define GPIO_0_FUNC_LO_REG (*((uint32_t volatile *)0x40E00054))
#define GPIO_0_FUNC_HI_REG (*((uint32_t volatile *)0x40E00058))

Let's take a look at the earlier code snippet written to use a register definition from the example header file:
if (bLedEnable == TRUE)
{
GPIO_0_SET_REG = 0x00400000;
}

This code is a lot easier to read and understand, even without a comment. Defining registers in a header file, as we have shown in the preceding code, also prevents you or another team member from running to the databook every other minute to look up a register address.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

1 comments:

Unknown said...

Hi, nice description about System Programming.Thanks for your help..

-Aparna
Theosoft