📄 44b_lib.c
字号:
/******************************************************************************
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()
{
// PORT A GROUP
/* BIT 9 8 7 6 5 4 3 2 1 0 */
/* A24 A23 A22 A21 A20 A19 A18 A17 A16 A0 */
/* 0 1 1 1 1 1 1 1 1 1 */
rPCONA = 0x1ff;
// PORT B GROUP
/* BIT 10 9 8 7 6 5 4 3 2 1 0 */
/* /CS5 /CS4 /CS3 /CS2 /CS1 nWBE3 nWBE2 /SRAS /SCAS SCLK SCKE */
/* EXT NIC 8019 IDE D12 NC NC Sdram Sdram Sdram Sdram */
/* 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 */
rPDATB = 0x04f;
rPCONB = 0x3cf;
//PORT C GROUP
//BUSWIDTH=16 */
/* PC15 14 13 12 11 10 9 8 */
/* o o RXD1 TXD1 o o o o */
/* NC NC Uart1 Uart1 NC NC NC NC */
/* 01 01 11 11 01 01 01 01 */
/* PC7 6 5 4 3 2 1 0 */
/* o o o o o o o o */
/* NC NC NC NC LED LED LED LED */
/* 01 01 01 01 01 01 01 01 */
rPDATC = 0x0000; //All IO is low
rPCONC = 0x5f555555;
rPUPC = 0x3000; //PULL UP RESISTOR should be enabled to I/O
//PORT D GROUP
/* PORT D GROUP(I/O OR LCD) */
/* BIT7 6 5 4 3 2 1 0 */
/* VF VM VLINE VCLK VD3 VD2 VD1 VD0 */
/* 01 01 01 01 01 01 01 01 */
rPDATD= 0x55;
rPCOND= 0xaaaa;
rPUPD = 0x00;
//These pins must be set only after CPU's internal LCD controller is enable
/////////////////////////////////////////////////////
//PORT E GROUP
/* Bit 8 7 6 5 4 3 2 1 0 */
/* ENDLAN o o TOU2 o o RXD0 TXD0 FOUT */
/* 00 01 01 10 01 01 10 10 11 */
rPDATE = 0x157; //Beep = 10
rPCONE = 0x596b;
rPUPE = 0xff;
//PORT F GROUP
/* Bit8 7 6 5 4 3 2 1 0 */
/* IISCLK IISDI IISDO IISLRCK Input Input Input IICSDA IICSCL */
/* 100 100 100 100 00 00 00 10 10 */
rPDATF = 0x0;
rPCONF = 0x24900a;
rPUPF = 0x1d3;
//PORT G GROUP
/* BIT7 6 5 4 3 2 1 0 */
/* EINT7 EINT6 EINT5 EINT4 EINT3 EINT2 EINT1 EINT0 */
/* KEY3 KEY2 KEY1 KEY0 NIC EXT IDE USB */
/* 11 11 11 11 11 11 11 11 */
rPDATG = 0xff;
rPCONG = 0x0000;
rPUPG = 0x00; //should be enabled
rSPUCR= 0x4;//0x7; //D15-D0 pull-up disable
//rSPUCR= 0x6; //D15-D0 pull-up enable
rSYSCFG = 0x0e; //使用8K字节的指令缓存,write buffer disable
rNCACHBE0 = 0xc0002000; //定义非Cache区,从0x2000000到0xbffffff,中断时进入ROM,若不允许CACHE不正常
rEXTINT = 0x0; //所有的外部硬件中断为低电平触发
}
/******************************************************************************
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)
{
switch (led)
{
case LED_ALL:
if (LED_ON == action)
{
rPDATC |= 0x0E;
}
else
{
rPDATC &= ~0x0E;
}
break;
case LED1:
case LED2:
case LED3:
if (LED_ON == action)
{
rPDATC |= 1<<(led);
}
else
{
rPDATC &= ~(1<<(led));
}
break;
default:
break;
}
}
/******************************************************************************
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;
char buff[256];
if ((tout > 65535)||(tout == 0))
{
sprintf(&buff[0], "pwm_start(): tout [%d] invalid for pwm timer [%d]...\n", tout, which);
UART_sendString(UART_CH0, &buff[0]);
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 */
rTCNTB0 = tout;
rTCMPB0 = tout>>1;
/* Set the manual update bit of the corresponding timer. */
ctrlMsk = ~(0xf<<0);
ctrl = rTCON & ctrlMsk;
ctrl |= (0x2<<0); /* auto reload off,
* inverter off,
* manual update,
* timer stop.
*/
rTCON = ctrl;
/* Set the start bit of the corresponding timer to start the timer,
* At the same time, clear the manual update bit.*/
ctrl &= ~(0xf<<0);
if (periodly != 0)
{
ctrl |= (0xd<<0); /* auto-reload on(Interval mode)
* Timer output inverter on
* No operation (for manual update off)
* Timer start
*/
}
else
{
ctrl |= (0x5<<0); /* auto-reload off (one shot mode)
* Timer output inverter on
* No operation (for manual update off)
* Timer start
*/
}
rTCON = ctrl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -