Objective 335 project development record 5_28335-Basics of CCS Programming

Source: Internet
Author: User

The CCS development environment has encapsulated the structures of many in-chip peripheral registers for us. We only need to include the corresponding official header files for use, how is it implemented internally?

The following is a typical example:

1. Use struct and Consortium A. use struct to define the role of a bit domain:

There is a section in dsp2833x_sci.h:

Struct sciccr_bits {// bit description uint16 scichar: 3; // 2: 0 character Length Control uint16 addridle_mode: 1; // 3 ADDR/idle mode control uint16 loopbkena: 1; // 4 loop back enable uint16 parityena: 1; // 5 parity enable uint16 parity: 1; // 6 even or odd parity uint16 stopbits: 1; // 7 Number of Stop bits uint16 rsvd1: 8; // 15: 8 reserved}; Union sciccr_reg {uint16 all; struct sciccr_bits bit ;};
Uint16 scichar: 3 indicates defining scichar, which occupies 3 of the first byte;

Note:: It must be 4-byte aligned! Observe the above definition of sciccr_bits and you will find that 3 + 1 + 1 + 1 + 1 + 1 = 8 bits = 1 byte

What if one item occupies 5 places? For example:

Uint16 SCICHAR1:4Uint16 SCICHAR2:5
Obviously, it cannot be written as above. It should be written:
Uint16 scichar1: 4uint16 NULL: 0 // In this case, the following variables will be stored in uint16 scichar2: 5 starting from the second byte


B. Let's look at the role of union.

union SCICCR_REG{      Uint16     all;      struct SCICCR_BITS bit;}
What is the effect of this definition?

To operate each bit in sciccr_bits, you only need to define Union sciccr_reg.

We can perform the entire operation, for example, Reg. All = 0x0011;

We can operate one of them: Reg. Bit. Parity = 0;

Do you still remember sharing the same memory space address in union in C language?


2. Use the CMD file to map data segments to memory space

Since the official website has helped us do everything above, the above items can certainly be used directly, why can we use them directly?

Can I access the registers on the real hardware by defining a variable above? No!

We need to bind the above variables to the actual hardware register storage space, how to bind them, through the CMD file.

 

Below is a piece of code from the official dsp2833x_globalvariabledefs.c:

//----------------------------------------#ifdef __cplusplus#pragma DATA_SECTION("ScicRegsFile")#else#pragma DATA_SECTION(ScicRegs,"ScicRegsFile");#endifvolatile struct SCI_REGS ScicRegs;

The official definition of scicregs to operate serial SCI-C related registers, but certainly can not be used directly, not bound;

You can use # pragma data_section to bind variables to data segments. Variables and data segments are defined by yourself and only need to be bound to them;


This binding obviously does not work. You need to map the data fields in the CMD file to the Register address space of the hardware!

View the dsp2833x_headers_nonbios.cmd file and we can find several lines as follows:

MEMORY{ PAGE 0:    /* Program Memory */ PAGE 1:    /* Data Memory */       ADC         : origin = 0x007100, length = 0x000020     /* ADC registers */   SCIB        : origin = 0x007750, length = 0x000010     /* SCI-B registers */   SCIC        : origin = 0x007770, length = 0x000010     /* SCI-C registers */      I2CA        : origin = 0x007900, length = 0x000040     /* I2C-A registers */ } SECTIONS{   AdcRegsFile       : > ADC,         PAGE = 1   ScibRegsFile      : > SCIB,        PAGE = 1   ScicRegsFile      : > SCIC,        PAGE = 1   I2caRegsFile      : > I2CA,        PAGE = 1}

Memory indicates the memory space, page1 indicates the program space, and page2 indicates the data space;

(Do you still remember the first lesson? 28335 sample the Harvard bus structure. The program and data are separated ~)

Sections represents the segment to be mapped;

After the above ing, you can operate scicregs to actually operate the serial port;


Objective 335 project development record 5_28335-Basics of CCS Programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.