📄 power_sample.c
字号:
/**********************************************************************************/
/* */
/* Copyright (C) 2003 Oki Electric Industry Co., LTD. */
/* */
/* System Name : ML675001 CPU board series */
/* Module Name : Power control sample program */
/* File Name : power_sample.c */
/* Revision : 01.00 */
/* Date : 2003/03/09 initial version */
/* */
/**********************************************************************************/
#include "ML675001.h"
#include "common.h"
#include "irq.h"
#include "cache.h"
#include "pm675001_lib.h"
/* Constants */
#define CCLK (60000000L) /* (Hz) */
#define BAUDRATE (115200) /* Baudrate of SIO (baud) */
#define VALUE_OF_SIOBT(CCLK_GEAR) (256-CCLK/(CCLK_GEAR * 16 * BAUDRATE)) /* Value of SIOBT */
#define LED_H 0x0076
#define LED_S 0x006D
#if (VALUE_OF_SIOBT(1) < 0) || (256 <= VALUE_OF_SIOBT(1))
#error Invalid value : VALUE_OF_SIOBT(1)
#elsif (VALUE_OF_SIOBT(2) < 0) || (256 <= VALUE_OF_SIOBT(2))
#error Invalid value : VALUE_OF_SIOBT(2)
#elsif (VALUE_OF_SIOBT(4) < 0) || (256 <= VALUE_OF_SIOBT(4))
#error Invalid value : VALUE_OF_SIOBT(4)
#elsif (VALUE_OF_SIOBT(8) < 0) || (256 <= VALUE_OF_SIOBT(8))
#error Invalid value : VALUE_OF_SIOBT(8)
#elsif (VALUE_OF_SIOBT(16) < 0) || (256 <= VALUE_OF_SIOBT(16))
#error Invalid value : VALUE_OF_SIOBT(16)
#elsif (VALUE_OF_SIOBT(32) < 0) || (256 <= VALUE_OF_SIOBT(16))
#error Invalid value : VALUE_OF_SIOBT(32)
#endif
/* Functions */
int main(void); /* Main routine */
static void setup_sio(void); /* Setup of TIMER */
static void setup_exint(void); /* setup exint */
static HWORD value_of_siobt[6] = {
(HWORD)VALUE_OF_SIOBT(1),
(HWORD)VALUE_OF_SIOBT(2),
(HWORD)VALUE_OF_SIOBT(4),
(HWORD)VALUE_OF_SIOBT(8),
(HWORD)VALUE_OF_SIOBT(16),
(HWORD)VALUE_OF_SIOBT(32)
};
/****************************************************************************/
/* Entry point */
/* Function : main */
/* Parameters */
/* Input : Nothing */
/* Output : 0 */
/****************************************************************************/
int main(void)
{
UBYTE input;
UBYTE hclk_gear = 0;
UBYTE cclk_gear = 0;
UHWORD hclk_led_pattern[6] = {0x0020,0x0001,0x0021,0x0002,0x0022,0x0003};
UHWORD cclk_led_pattern[6] = {0x0010,0x0008,0x0018,0x0004,0x0014,0x000C};
init_cache(); /* Initialize CACHE memory */
cache_on(CACHE_BANK0); /* Bank0 : Cache enable */
init_irq(); /* Initialization of IRQ */
setup_sio(); /* Setup of SIO */
setup_exint();
init_led();
led_on(LED_START_PATTERN);
put_value(SIOBCN, SIOBCN_BGRUN); /* SIO start */
for(;;){
if(get_hvalue(SIOSTA)&SIOSTA_RVIRQ){
input = (UBYTE)get_hvalue(SIOBUF);
put_hvalue(SIOSTA, SIOSTA_RVIRQ);
switch(input){
case 'h':
case 'H':
led_on(LED_H);
pm_halt(0x00400400);
break;
case 's':
case 'S':
led_on(LED_S);
pm_stby(0x00400000);
break;
case '+':
if(hclk_gear > 0) hclk_gear--;
pm_hclkgear(hclk_gear, 0);
break;
case '-':
if(hclk_gear < 5) hclk_gear++;
pm_hclkgear(hclk_gear, 1);
break;
case '[':
if(cclk_gear > 0) cclk_gear--;
pm_cclkgear(cclk_gear, 0);
put_hvalue(SIOBT, value_of_siobt[cclk_gear]);
break;
case ']':
if(cclk_gear < 5) cclk_gear++;
pm_cclkgear(cclk_gear, 1);
put_hvalue(SIOBT, value_of_siobt[cclk_gear]);
break;
default:
continue;
}
led_on(hclk_led_pattern[hclk_gear]|cclk_led_pattern[cclk_gear]);
}
}
return 0;
}
/****************************************************************************/
/* Setup of SIO registers */
/* Function : setup_sio */
/* Parameters */
/* Input : nothing */
/* Output : nothing */
/****************************************************************************/
void setup_sio(void)
{
set_hbit(GPCTL, GPCTL_SIO);
/* Setup of SIO registers.
Please see SIO sample for details. */
put_wvalue(SIOCON, SIOCON_LN8|SIOCON_PDIS|SIOCON_TSTB1);
put_wvalue(SIOBT, VALUE_OF_SIOBT(1));
}
/****************************************************************************/
/* Setup of external interrupt */
/* Function : setup_exint */
/* Parameters */
/* Input : nothing */
/* Output : nothing */
/****************************************************************************/
void setup_exint(void)
{
set_wbit(IDM, IDM_INT_L_L&IDM_IRQ22); /* IRQ22 : level sensing and
interrupt occurs when input = 'L' */
set_hbit(GPCTL, GPCTL_EXINT0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -