⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 44b_lib.c

📁 还是arm7操作源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
   Copyright (c) 2006 by RockOS.
   All rights reserved.

   This software is supported by Rock Software Workroom.

   Any bugs please contact the author with e-mail or QQ:
     E-mail : baobaoba520@yahoo.com.cn
         QQ : 59681888
*******************************************************************************
File name   : 44b_lib.c
Description : This is the hardware management libary for QW44B0x board, the CPU
            : is ARM S3C44B0x, you should write a new hwlib.c when you are
            : porting RockOS to other board.
            :
Auther      : sunxinqiu
History     :
  2006-3-15   first release.
******************************************************************************/
#include "bsp.h"

/******************************************************************************
Function    : void init_gpio(void)
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : This function is used to config the GPIO registers for QW44B0x
            : board only.
******************************************************************************/
void init_gpio()
{
    //ADB V1.0 B/D Status
    //USB D12SUSPD
    //    PC0
    //LED D0  D1  D2
    //    PC1 PC2 PC3
    //KEY K0  K1  K2  K3
    //    PG4 PG5 PG6 PG7

    //CAUTION:Follow the configuration order for setting the ports.
    // 1) setting value
    // 2) setting control register
    // 3) configure pull-up resistor.

    //16bit data bus configuration
    //PORT A GROUP
    //rPCONA[9:0]
    //|BIT9  |.......................................................|BIT0
    //|ADDR24|ADDR23|ADDR22|ADDR21|ADDR20|ADDR19|ADDR18|ADDR17|ADDR16|ADDR0
    //|     0|     1|     1|     1|     1|     1|     1|     1|     1|    1
    rPCONA=0x1ff;

    //PORT B GROUP
    //rPCONB[10:0]
    //|BIT10|....................................................|BIT0
    //|nGCS5|nGCS4|nGCS3|nGCS2|nGCS1|nWBE3|nWBE2|nSRAS|nSCAS|SCLK|SCKE
    //|    1|    1|    1|    1|    1|    1|    1|    1|    1|   1|   1
    rPDATB=0x3ff;
    rPCONB=0x3ff;

    //PORT C GROUP
    //BUSWIDTH=16
    //PORT C GROUP
    //rPCONC[31:0]
    //|GPC15|....................................................................|    GPC0
    //|BIT31|....................................................................|    BIT0
    //|nCTS0|nRTS0|RXD1|TXD1|nCTS1|nRTS1|nEL|nDISP|VD4|VD6|VD5|VD7|LED2|LED1|LED0|D12SUSPD
    //|   00|   00|  11|  11|   00|   00| 01|   01| 11| 11| 11| 11|  01|  01|  01|      01
    //rPUPC[15:0]
    //|    0|    0|   1|   1|    0|    0|  0|    0|  1|  1|  1|  1|   0|   0|   0|       0
    rPDATC=0xffff;  //All I/O Is High
    rPCONC=0x0f05ff55;
    rPUPC=0x30f0;   //PULL UP RESISTOR should be enabled to I/O

    //PORT D GROUP
    //rPCOND
    //| BIT15|.........................|BIT0
    //|VFRAME|VM|VLINE|VCLK|VD3|VD2|VD1|VD0
    //|    10|10|   10|  10| 10| 10| 10| 10
    rPDATD=0xff;
    rPCOND= 0x0;
    rPUPD = 0x0;
    //These pins must be set only after CPU's internal LCD controller is enable

    //rPCOND=0xaaaa;
    //rPUPD=0xff;

    //PORT E GROUP
    //rPCONE
    //| BIT17 |..............................|BIT0
    //|CODECLK|PE7|PE6|BEEP|PE4|PE3|RXD0|TXD0| PE0
    //|     10| 01| 01|  01| 01| 01|  10|  10|  00
    //|rPUPE[7:0]
    //        |  0|  0|   0|  0|  0|   1|   1|   0
    rPDATE=0x1ff;   //All I/O Is High
    rPCONE=0x25568; //All NC is INPUT
    rPUPE=0x0ff;    //PE8 do not have programmable pull-up resistor.

    //PORT F GROUP
    //rPCONF[21:0]
    //| BIT21|....................................|  BIT0
    //|IISCLK|PF7|IISDO|IISLRCK|PF4|PF3|PF2|IICSDA|IICSCL
    //|   100|000|  100|    100| 00| 00| 00|    10|    10
    //rPUPF[8:0]
    //|     1|  0|    1|      1|  0|  0|  0|     1|     1
    rPDATF=0x1ff;   //All I/O Is High
    rPCONF=0x20900a;//All NC is INPUT
    rPUPF=0x163;

    //PORT G GROUP
    //rPCONG[15:0]
    //|BIT15|....................................|   BIT0
    //| KEY3|KEY2|KEY1|KEY0|EXINT3|EXINT2|NET_INT|USB_INT
    //|   11|  11|  11|  11|    11|    11|     11|     11
    rPDATG=0xff;
    rPCONG=0x00ff;  //KEY0~KEY3定义为I/O,采用查询方式
                //rPCONG=0xffff,KEY0~KEY3定义为中断,

    rPUPG=0x0;      //should be enabled

    rSPUCR=0x7;     //D15-D0 pull-up disable

    rEXTINT=0x0;    //All EXTINT0-7 Low level interrupt

    //Define the Non_Cache area
    rNCACHBE0=(((Non_Cache_End)>>12)<<16)|((Non_Cache_Start)>>12);
}

/******************************************************************************
Function    : void light_led (int led, int action)
Params      : led    - which led, running, flash, loading or OM uart.
            : action - light on or off, 0 for off, 1 for on.
            : 
            : 
Return      : N/A
Description : Use this function light a special led on or off. The all LEDs
            : should be controlled by software.
******************************************************************************/
void light_led (int led, int action)
{
    unsigned state;

    state = rPDATE;
    switch(led)
    {
    case LED1:
        if (action == LED_ON)
        {
            state &= 0xF7;
        }
        else
        {
            state |= 0x08;
        }
        rPDATE = 0xF5;
        break;
    case LED2:
        if (action == LED_ON)
        {
            state &= 0xEF;
        }
        else
        {
            state |= 0x10;
        }
        break;
    case LED3:
        if (action == LED_ON)
        {
            state &= 0xDF;
        }
        else
        {
            state |= 0x20;
        }
        break;
    case LED4:
        if (action == LED_ON)
        {
            state &= 0xBF;
        }
        else
        {
            state |= 0x40;
        }
        break;
    case LED5:
        if (action == LED_ON)
        {
            state &= 0x7F;
        }
        else
        {
            state |= 0x80;
        }
        break;
    default:
        break;
    }
    rPDATE = state;
}

/******************************************************************************
Function    : void init_rtc(void)
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : This function is used to config the RTC registers and should be
            : called only once, when the system is power on.
******************************************************************************/
void init_rtc()
{
    /* Bit3 : RTC clok count reset, 0 for no reset, 1 for reset.
     * Bit2 : BCD count select, should be 0
     * Bit1 : BCD clock select, should be 0
     * bit0 : RTC write enable, 0 for disable, 1 for enable.
    */
    rRTCCON = 0x1; /* RTC clk count don't reset and write enable. */

    /* Bit7 : not used, should be 0
     * Bit6 : Alarm global enable, 0 for disable, 1 for enable.
     * Bit5 : Year alarm enable.
     * Bit4 : Month alarm enable.
     * Bit3 : Date alarm enable.
     * Bit2 : Hour alarm enable.
     * Bit1 : Minute alarm enable.
     * Bit0 : Second alarm enable.
     */
    rRTCALM = 0x7f;    /* all alarm enable.*/

    /* Bit3    : Round second reset enable, 0 for disable, 1 for enable.
     * bit2..0 : Round boundary for second carry generation.
     */
    rRTCRST = 0;      /* Round second reset disable. */

    /* Bit7    : Tick time interrupt enable, 0 for disable, 1 for enable.
     * Bit6..0 : Tick time count value(1~127).
     */
    rTICINT = 0xBF;   /* Tick interrupt enable, period is 0.5Sec */
}

/******************************************************************************
Function    : void init_pwm(void)
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : This function configs some basic registers for PWM timer.
            : 
******************************************************************************/
void init_pwm()
{
    /* MCLK is 32MHz,
     * Timer 4&5's resolving power is 0.1ms(100us, frequency is 10KHz)
     * Timer 2&3's resolving power is 0.01ms(10us, frequency is 0.1MHz)
     * Timer 0&1's resolving power is 0.001ms(1us, frequency is 1MHz)
     */

    /* Bit 31..24 : Dead zone length
     * Bit 23..16 : Perscaler2, for Timer 4 & 5
     * Bit 15..8  : Perscaler1, for Timer 2 & 3
     * Bit 7..0   : Perscaler0, for Timer 0 & 1
     */
    rTCFG0 = (0<<24)      /* dead zone */
             |(199<<16)   /* perscaler for Timer 4&5 */
             |(19<<8)     /* perscaler for Timer 2&3 */
             |1;          /* perscaler for Timer 0&1 */

    /* Bit 27..24 : DAM mode
     * Bit 23..20 : MUX 5
     * Bit 19..16 : MUX 4
     * Bit 15..12 : MUX 3
     * BIT 11..8  : MUX 2
     * BIT 7..4   : MUX 1
     * BIT 3..0   : MUX 0
     */
    rTCFG1 = (0<<24)      /* DMA mode, none timer */
             |(3<<20)     /* 1/16 for timer 5. */
             |(3<<16)     /* 1/16 for timer 4. */
             |(3<<12)     /* 1/16 for timer 3. */
             |(3<<8)      /* 1/16 for timer 2. */
             |(3<<4)      /* 1/16 for timer 1. */
             |3;          /* 1/16 for timer 0. */
}

/******************************************************************************
Function    : void pwm_start (int which, int tout, int periodly)
Params      : which  - PWM Timer 0, 1 ... 5
            : tout   - the counter for generating TOUT with devidered frequence.
            :          should be 1 ~ 65535
            : periodly - indicate whether start pwm timer periodly or only once,
            :            0 for only once, 1 for periodly.
            : 
Return      : N/A
Description : This function start a special PWM timer.
            : 
******************************************************************************/
void pwm_start (int which, int tout, int periodly)
{
    unsigned ctrl;
    unsigned ctrlMsk;

    if ((tout > 65535)||(tout == 0))
    {
        OS_printf ("pwm_start(): tout [%d] invalid for pwm timer [%d]...\n", tout, which);
        return;
    }

    /* The TCON register format is:
     * Bit 26 : Timer 5 auto reload on/off
     * Bit 25 : Timer 5 manual update
     * Bit 24 : Timer 5 start/stop
     * Bit 23 : Timer 4 auto reload on/off
     * Bit 22 : Timer 4 output inverter on/off
     * Bit 21 : Timer 4 manual update
     * Bit 20 : Timer 4 start/stop
     * Bit 19 : Timer 3 auto reload on/off
     * Bit 18 : Timer 3 output inverter on/off
     * Bit 17 : Timer 3 manual update
     * Bit 16 : Timer 3 start/stop
     * Bit 15 : Timer 2 auto reload on/off
     * Bit 14 : Timer 2 output inverter on/off
     * Bit 13 : Timer 2 manual update
     * Bit 12 : Timer 2 start/stop
     * Bit 11 : Timer 1 auto reload on/off
     * Bit 10 : Timer 1 output inverter on/off
     * Bit 9  : Timer 1 manual update
     * Bit 8  : Timer 1 start/stop
     * Bit 7..5 : not used.
     * Bit 4  : Dead zone enable
     * Bit 3  : Timer 0 auto reload on/off, 1 for auto reload
     * Bit 2  : Timer 0 output inverter on/off, 1 for inverter on
     * Bit 1  : Timer 0 manual update, 1 for manual update, 0 for no operation
     * Bit 0  : Timer 0 start/stop, 1 for start
     */
    switch (which)
    {
    case PWM_TIMER0:
        /* Write the initial value into TCNTB0 and TCMPB0 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -