Abstraction for S3C2440 bare board programming (without operating system)

Publisher:WanderlustSoulLatest update time:2016-03-03 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
          In the embedded field, almost all device controls and various protocol controls are in the same embedded CPU, which is very conducive to abstracting the CPU Core and devices. If the CPU Core and various device controls can be abstracted, people do not need to have a very deep understanding of the CPU when porting the OS or developing drivers, and do not need to understand what a certain bit of a register controls, nor do they need to understand how to initialize a certain control register, etc.

        When using the controller to write a bare board application, the programmer only needs to understand the initialization sequence and content of the controller without understanding the specific details of the initialization to complete the application. Obviously, it can greatly improve work efficiency, and the specific details of the hardware are the most error-prone part of the application, and the use of the controller can greatly reduce the possibility of errors.
        ARM is a more powerful single-chip microcomputer. In the process of learning bare metal programming, it is found that ARM integrates more peripherals than ordinary single-chip microcomputers (general single-chip microcomputers only integrate serial ports and four groups of IO ports), contains more GPIOs, and has more registers. The relevant pins are controlled by setting and enabling registers to control related devices. S3C2440 has an internal hardware controller integrated, and various driver protocols are generated by the hardware controller. We only need to configure the registers of the corresponding hardware controller to generate the corresponding driver timing. High-end ARM learning is mainly based on software programming (i.e., understanding). It has rich resources and rarely needs to expand peripherals. The focus of learning is how to configure registers and how to write applications.

        Just set the corresponding control registers and read and write the corresponding data registers. The key to learning bare board program development is to understand the principles of various interface protocols, so that you can understand the initialization sequence and content of the controller.

        The following is an example of the S3C2440 I2C controller. The following program is based on the interrupt mode. For the explanation of the I2C protocol, you can check my previous blog. The I2C protocol stipulates that after the receiver receives a byte (address or data), it must send an ACK. After the transmitter receives the ACK, it can continue to send data or end data transmission. After the receiver (here we are the S3C2440 I2C controller) receives the ACK, an interrupt will be generated. In the interrupt handler, you can continue to send the program or end the transmission. Understanding the basic principles of the I2C protocol, writing programs is a piece of cake.

[cpp] view plain copy
 
 print?
  1. //===================================================================  
  2. //       SMDK2440 IIC configuration  
  3. //  GPE15=IICSDA, GPE14=IICSCL  
  4. //  "Interrupt mode" for IIC block  
  5. //===================================================================   
  6.   
  7. //******************[ Test_Iic ]**************************************  
  8. void Test_Iic(void)  
  9. {  
  10.     unsigned int i,j,save_E,save_PE;  
  11.     static U8 data[256];  
  12.   
  13.     Uart_Printf("\nIIC Test(Interrupt) using AT24C08\n");  
  14.   
  15.     save_E = rGPECON; //Save the previous value  
  16.     rGPECON |= 0xa00000;                //GPE15:IICSDA , GPE14:IICSCL   
  17.   
  18.     pISR_IIC = (unsigned)IicInt; //Set the interrupt processing function  
  19.     rINTMSK &= ~(BIT_IIC); //Open IIC interrupt  
  20.   
  21.       //Enable ACK, Prescaler IICCLK=PCLK/16, Enable interrupt, Transmit clock value Tx clock=IICCLK/16  
  22.       // If PCLK 50.7MHz, IICCLK = 3.17MHz, Tx Clock = 0.198MHz  
  23.     rIICCON = (1<<7) | (0<<6) | (1<<5) | (0xf); //The fourth bit is 1, the SCL line is pulled low, and the transmission is interrupted  
  24.   
  25.     rIICADD  = 0x10;                    //2440 slave address = [7:1]  
  26.     rIICSTAT = 0x10; //IIC bus data output enable (Rx/Tx) enable receive/send function  
  27.     rIICLC = (1<<2)|(1);               // Filter enable, 15 clocks SDA output delay       added by junon  
  28.       
  29.     Uart_Printf("Write test data into AT24C08\n");  
  30.   
  31.     for(i=0;i<256;i++)  
  32.         Wr24C080(0xa0,(U8)i,i);  
  33.              
  34.     for(i=0;i<256;i++)  
  35.         data[i] = 0;  
  36.   
  37.     Uart_Printf("Read test data from AT24C08\n");  
  38.       
  39.     for(i=0;i<256;i++)  
  40.         Rd24C080(0xa0,(U8)i,&(data[i]));   
  41.   
  42.         //Line changed 0 ~ f  
  43.     for(i=0;i<16;i++)  
  44.     {  
  45.         for(j=0;j<16;j++)  
  46.             Uart_Printf("%2x ",data[i*16+j]);  
  47.         Uart_Printf("\n");  
  48.     }  
  49.     rINTMSK |= BIT_IIC;      
  50.     rGPECON = save_E;  
  51. }  
  52.   
  53.   
  54. //*************************[ Wr24C080 ]****************************  
  55. void Wr24C080(U32 slvAddr,U32 addr,U8 data)  
  56. {  
  57.     _iicMode      = WRDATA;  
  58.     _iicPt        = 0;  
  59.     _iicData[0]   = (U8)addr;  
  60.     _iicData[1]   = data;  
  61.     _iicDataCount = 2;  
  62.       
  63.     rIICDS   = slvAddr;                 //0xa0  
  64.     rIICSTAT = 0xf0; //MasTx, Start host transmitter sends S signal  
  65.       //Clearing the pending bit isn't needed because the pending bit has been cleared.  
  66.       
  67.     while(_iicDataCount!=-1);//Wait for data to be sent  
  68.   
  69.   
  70.   
  71.   
  72. //Start a new transmission, but only send the device address and wait for a response to prove that the last transmission is complete. The next time Wr24C080 starts, it will start again. No data is written in this transmission.  
  73.     _iicMode = POLLACK;  
  74.   
  75.     while(1)  
  76.     {  
  77.         rIICDS     = slvAddr;  
  78.         _iicStatus = 0x100;  
  79.         rIICSTAT   = 0xf0;              //MasTx,Start  
  80.         rIICCON    = 0xaf;              //Resumes IIC operation.   
  81.              
  82.         while(_iicStatus==0x100); //Wait for data to be sent and the status register to change.  
  83.              
  84.         if(!(_iicStatus&0x1)) //The last bit received is 0 (ACK signal received)  
  85.             break; //When ACK is received, determine the status of the last bit  
  86.     }  
  87.     rIICSTAT = 0xd0;                    //Stop MasTx condition   
  88.     rIICCON  = 0xaf;                    //Resumes IIC operation.   
  89.     Delay(1);                           //Wait until stop condtion is in effect.  
  90.        //Write is completed.  
  91. }  
  92.           
  93. //**********************[ Rd24C080 ] ***********************************  
  94. void Rd24C080(U32 slvAddr,U32 addr,U8 *data)  
  95. {  
  96.     _iicMode      = SETRDADDR;  
  97.     _iicPt        = 0;  
  98.     _iicData[0]   = (U8)addr;  
  99.     _iicDataCount = 1;  
  100.   
  101.     rIICDS   = slvAddr;  
  102.     rIICSTAT = 0xf0;                    //MasTx,Start    
  103.       //Clearing the pending bit isn't needed because the pending bit has been cleared.  
  104.     while(_iicDataCount!=-1);  
  105.   
  106.     _iicMode = RDDATA;  
  107.     _iicPt        = 0;  
  108.     _iicDataCount = 1;  
  109.       
  110.     rIICDS        = slvAddr;  
  111.     rIICSTAT      = 0xb0;               //MasRx,Start  
  112.     rIICCON       = 0xaf;               //Resumes IIC operation.     
  113.     while(_iicDataCount!=-1);  
  114.   
  115.     *data = _iicData[1];  
  116. }  
  117.   
  118.   
  119. //-------------------------------------------------------------------------  
  120. void __irq IicInt(void)  
  121. {  
  122.     U32 iicSt,i;  
  123.       
  124.     rSRCPND = BIT_IIC;          //Clear pending bit  
  125.     rINTPND = BIT_IIC;  
  126.     iicSt = rIICSTAT;   
  127.       
  128.     if(iicSt & 0x8){}           //When bus arbitration is failed.  
  129.     if(iicSt & 0x4){}           //When a slave address is matched with IICADD  
  130.     if(iicSt & 0x2){}           //When a slave address is 0000000b  
  131.     if(iicSt & 0x1){}           //When ACK isn't received  
  132.   
  133.     switch(_iicMode)  
  134.     {  
  135.        case POLLACK:  
  136.            _iicStatus = iicSt;  
  137.            break;  
  138.   
  139.        case RDDATA:  
  140.            if((_iicDataCount--)==0)  
  141.            {  
  142.                _iicData[_iicPt++] = rIICDS;  
  143.               
  144.                rIICSTAT = 0x90;                 //Stop MasRx condition   
  145.                rIICCON  = 0xaf;                 //Resumes IIC operation.  
  146.                Delay(1);                        //Wait until stop condtion is in effect.  
  147.                                                 //Too long time...   
  148.                                                 //The pending bit will not be set after issuing stop condition.  
  149.                break;      
  150.            }        
  151.            _iicData[_iicPt++] = rIICDS;         //The last data has to be read with no ack.  
  152.   
  153.            if((_iicDataCount)==0)  
  154.                rIICCON = 0x2f;                  //Resumes IIC operation with NOACK.    
  155.            else   
  156.                rIICCON = 0xaf;                  //Resumes IIC operation with ACK  
  157.                break;  
  158.   
  159.         case WRDATA:  
  160.             if((_iicDataCount--)==0)  
  161.             {  
  162.                 rIICSTAT = 0xd0;                //Stop MasTx condition   
  163.                 rIICCON  = 0xaf;                //Resumes IIC operation.  
  164.                 Delay(1);                       //Wait until stop condtion is in effect.  
  165.                        //The pending bit will not be set after issuing stop condition.  
  166.                 break;      
  167.             }  
  168.             rIICDS = _iicData[_iicPt++];        //_iicData[0] has dummy.  
  169.             for(i=0;i<10;i++);                  //for setup time until rising edge of IICSCL  
  170.                 
  171.             rIICCON = 0xaf;                     //resumes IIC operation.  
  172.             break;  
  173.   
  174.         case SETRDADDR:  
  175. //          Uart_Printf("[ S%d ]",_iicDataCount);  
  176.             if((_iicDataCount--)==0)  
  177.                 break;                          //IIC operation is stopped because of IICCON[4]      
  178.             rIICDS = _iicData[_iicPt++];  
  179.             for(i=0;i<10;i++);                  //For setup time until rising edge of IICSCL  
  180.             rIICCON = 0xaf;                     //Resumes IIC operation.  
  181.             break;  
  182.   
  183.         default:  
  184.             break;        
  185.     }  
  186. }  

Keywords:S3C2440 Reference address:Abstraction for S3C2440 bare board programming (without operating system)

Previous article:In-depth analysis of the big-endian and small-endian issues in the S3C2440 startup code
Next article:GPIO (II) C Program

Recommended ReadingLatest update time:2024-11-16 19:48

Boa Web server transplanted on S3C2440 development board
The transplantation of the boa server has been completed on the PC. For "Transplantation of Boa Web Server on PC", see http://www.linuxidc.com/Linux/2011-10/44729.htm. The following will introduce how to complete the corresponding work on the S3C2440 hardware platform. The two are similar, with slight differences in
[Microcontroller]
【s3c2440】Lesson 4: External Interrupts
External interrupt initialization process The flowchart of external interrupt is as follows: The interrupt priority is not considered here, and the registers involved are as follows: External interrupt configuration 1. Initialization interrupt Set the system mode (MODE) from SVC (supervise) mode to USER mode. S
[Microcontroller]
【s3c2440】Lesson 4: External Interrupts
How to write the interrupt vector of s3c2440 bare metal (2)
Let’s first explain the LDR pseudo-instruction. The LDR pseudo-instruction reads a 32-bit constant or an address value into a register. Syntax format LDR{cond} register,={expr|label-expr} The symbols and parameters are explained as follows: ●cond is an optional instruction execution condition. ●register is the target
[Microcontroller]
The difference between MMU and MPU
The S3C2440 has an MMU, while the popular Cortex-M3/4 has an MPU. MMU vs MPU Memory is one of the most important components of a modern computer. Therefore, its contents cannot be tampered with by any errant application. This function can be achieved by an MMU (Memory Management Unit) or an MPU (Memory
[Microcontroller]
S3c2440 code relocation details 3---analysis of link script
Linker script syntax SECTIONS { ... secname start BLOCK(align) (NOLOAD) : AT ( ldadr )   { contents } region :phdr =fill ... } explain:  secname : section name  start: starting address: runtime address (runtime addr); relocation address (relocate addr)  AT (ldadr): optional (load addr: load address) If not writ
[Microcontroller]
S3c2440 code relocation details 3---analysis of link script
Build jz2440v3 (arm s3c2440) development and gdb debugging environment under win10
I originally planned to develop it entirely under Ubuntu, but my level was limited and I couldn't find a suitable tool to read large codes under Ubuntu, so I had to build a development environment on Windows. 1. Main contents: 1. Build arm (s3c2440) development environment under windows10 Use vmware workstation12 pr
[Microcontroller]
Design of Remote Image Wireless Monitoring System Based on S3C2440 Processor
For image monitoring systems, users often put forward such functional requirements: they hope to be able to monitor objects that are far away. These objects may be distributed in suburbs, deep mountains, wastelands or other unattended places; in addition, they hope to obtain clearer monitoring images, but the real-t
[Microcontroller]
Design of Remote Image Wireless Monitoring System Based on S3C2440 Processor
02 Linux entry command
1 Shell Interpreter The shell interpreter receives the input characters and displays them immediately. After you press Enter, it searches for the command based on the string. Where to search? It searches in the path specified by the environment variable. # Display environment variables echo $PATH # The results are a
[Microcontroller]
02 Linux entry command
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号