📄 u_common.c
字号:
/*****************************************************************************
* File name : common.c
* Module name : Common function module
* Author : Hiromichi Kondo
*----------------------------------------------------------------------------
* $Id: common.c,v 1.1 2003/04/16 06:56:36 9551619 Exp $
*****************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "u_value.h"
#include "u_macro.h"
#include "u_com_fp.h"
#include "u_ram_data.h"
#include "u_rom_data.h"
#include "u_regNikka.h"
#include "u_c33cpu.h"
/*--- Function Prototype ---------------------------------------------------*/
void WaitTMStart(void);
void WaitTMStop(void);
void MonTMStart(void);
void MonTMStop(void);
int WaitTMCheck(BYTE timeout);
void ControlLED(int mode);
void CPU_GPIO_0(int flag);
void CPU_GPIO_1(int flag);
void CPU_GPIO_2(int flag);
void CPU_GPIO_3(int flag);
void CPU_GPIO_4(int flag);
void CPU_GPIO_5(int flag);
void CPU_GPIO_6(int flag);
void CPU_GPIO_7(int flag);
// gnu33
//
// /* 03/08/06 Endo : */
//void _panic(char *c_name,int line);
void panic( int );
void ei(void);
void di(void);
#ifdef DEBUG_PRINT
void DebugProc(void);
void o_rs232c(void);
void rs232c_rx(void);
void rs232c_dump(void);
void rs232c_printversion(void);
void rs232c_enable(int);
int rsicmp(char *str1, char *str2, int len);
void rsprint(char *str);
void rsprinthex(char *str, unsigned long hex, int size);
#ifdef MSGPRINT_ON
void rsprint(char *str);
void rsmsgprinthex(char *str, unsigned long hex, int size);
#endif /* MSGPRINT_ON */
#endif /* DEBUG_PRINT */
/*****************************************************************************
*
* : Timer0
* :
* :
* : timer0_cnt Timer0
*
*****************************************************************************/
void WaitTMStart(void)
{
*(volatile unsigned char*)REG_TM8_3_IMASK &= 0xf7; /* 8-bit timer 3 int disable */
*(volatile unsigned char*)REG_TM8_3_CTL = 0; /* 8-bit timer 3 stop */
*(volatile unsigned char*)REG_TM8_3_IFLAG |= 0x08; /* 8-bit timer 3 clr intflg */
*(volatile unsigned char*)REG_TM8_3_CTL |= 0x02; /* 8-bit timer 3 reload */
*(volatile unsigned char*)REG_TM8_3_IMASK |= 0x08; /* 8-bit timer 3 int enable */
*(volatile unsigned char*)REG_TM8_3_CTL |= 0x1; /* 8-bit timer 3 run */
timer0_cnt = 0;
}
/*****************************************************************************
*
* : Timer0
* :
* :
* :
*
*****************************************************************************/
void WaitTMStop(void)
{
*(volatile unsigned char*)REG_TM8_3_IMASK &= 0xf7; /* 8-bit timer 3 int disable */
*(volatile unsigned char*)REG_TM8_3_CTL = 0; /* 8-bit timer 3 stop */
*(volatile unsigned char*)REG_TM8_3_IFLAG |= 0x08; /* 8-bit timer 3 clr intflg */
*(volatile unsigned char*)REG_TM8_3_CTL |= 0x02; /* 8-bit timer 3 reload */
}
/*****************************************************************************
*
* : Timer3
* :
* :
*
*****************************************************************************/
void MonTMStart(void)
{
*(volatile unsigned char*)REG_TM8_4_IMASK &= 0xfe; /* 8-bit timer 4 int disable */
*(volatile unsigned char*)REG_TM8_4_CTL = 0; /* 8-bit timer 4 stop */
*(volatile unsigned char*)REG_TM8_4_IFLAG |= 0x01; /* 8-bit timer 4 clr intflg */
*(volatile unsigned char*)REG_TM8_4_CTL |= 0x02; /* 8-bit timer 4 reload */
*(volatile unsigned char*)REG_TM8_4_IMASK |= 0x01; /* 8-bit timer 4 int enable */
*(volatile unsigned char*)REG_TM8_4_CTL |= 0x1; /* 8-bit timer 4 run */
}
/*****************************************************************************
*
* : Timer3
* :
* :
* :
*
*****************************************************************************/
void MonTMStop(void)
{
*(volatile unsigned char*)REG_TM8_4_IMASK &= 0xfe; /* 8-bit timer 4 int disable */
*(volatile unsigned char*)REG_TM8_4_CTL = 0; /* 8-bit timer 4 stop */
*(volatile unsigned char*)REG_TM8_4_IFLAG |= 0x01; /* 8-bit timer 4 clr intflg */
*(volatile unsigned char*)REG_TM8_4_CTL |= 0x02; /* 8-bit timer 4 reload */
}
/*****************************************************************************
*
* : Timer0
* :
* :
*
* : timer0_cnt Timer0
*
*****************************************************************************/
int WaitTMCheck(BYTE timeout)
{
int ret = NOT_TIMEOUT;
if (timer0_cnt >= timeout) {
ret = TIMEOUT;
}
return ret;
}
/*****************************************************************************
*
* : LED
* : 0: LED ON1: LED OFF
* :
* :
*
*****************************************************************************/
void ControlLED(int mode)
{
#ifdef L05DMT
#endif
}
/*****************************************************************************
*
* : Output CPU GPIO 0
* : 0: Low1: High
* :
* :
*
*****************************************************************************/
void CPU_GPIO_0(int flag)
{
if( flag == 0 ){
CPU_GPIO_0_LO;
}else{
CPU_GPIO_0_HI;
}
}
/*****************************************************************************
*
* : Output CPU GPIO 1
* : 0: Low1: High
* :
* :
*
*****************************************************************************/
void CPU_GPIO_1(int flag)
{
if( flag == 0 ){
CPU_GPIO_1_LO;
}else{
CPU_GPIO_1_HI;
}
}
/*****************************************************************************
*
* : Output CPU GPIO 2
* : 0: Low1: High
* :
* :
*
*****************************************************************************/
void CPU_GPIO_2(int flag)
{
if( flag == 0 ){
CPU_GPIO_2_LO;
}else{
CPU_GPIO_2_HI;
}
}
/*****************************************************************************
*
* : Output CPU GPIO 3
* : 0: Low1: High
* :
* :
*
*****************************************************************************/
void CPU_GPIO_3(int flag)
{
if( flag == 0 ){
CPU_GPIO_3_LO;
}else{
CPU_GPIO_3_HI;
}
}
/*****************************************************************************
*
* : Output CPU GPIO 4
* : 0: Low1: High
* :
* :
*
*****************************************************************************/
void CPU_GPIO_4(int flag)
{
if( flag == 0 ){
CPU_GPIO_4_LO;
}else{
CPU_GPIO_4_HI;
}
}
/*****************************************************************************
*
* : Output CPU GPIO 5
* : 0: Low1: High
* :
* :
*
*****************************************************************************/
void CPU_GPIO_5(int flag)
{
if( flag == 0 ){
CPU_GPIO_5_LO;
}else{
CPU_GPIO_5_HI;
}
}
/*****************************************************************************
*
* : Output CPU GPIO 6
* : 0: Low1: High
* :
* :
*
*****************************************************************************/
void CPU_GPIO_6(int flag)
{
if( flag == 0 ){
CPU_GPIO_6_LO;
}else{
CPU_GPIO_6_HI;
}
}
/*****************************************************************************
*
* : Output CPU GPIO 7
* : 0: Low1: High
* :
* :
*
*****************************************************************************/
void CPU_GPIO_7(int flag)
{
if( flag == 0 ){
CPU_GPIO_7_LO;
}else{
CPU_GPIO_7_HI;
}
}
/*****************************************************************************
*
* :
* :
* :
* :
*
*****************************************************************************/
void panic( int er_num )
{
int i ;
i = er_num ;
asm("halt");
asm("halt");
asm("halt");
}
/*****************************************************************************
*
* :
* :
* :
* :
*
*****************************************************************************/
void ei(void)
{
asm("pushn %r0");
asm("ld.w %r0, %psr");
#ifdef GNU33
asm("xoor %r0, 0x00000010");
#else
asm("xoor %r0, %r0, 0x00000010");
#endif
asm("ld.w %psr, %r0");
asm("popn %r0");
}
/*****************************************************************************
*
* :
* :
* :
* :
*
*****************************************************************************/
void di(void)
{
asm("pushn %r0");
asm("ld.w %r0, %psr");
#ifdef GNU33
asm("xand %r0, 0xFFFFFFEF");
#else
asm("xand %r0, %r0, 0xFFFFFFEF");
#endif
asm("ld.w %psr, %r0");
asm("popn %r0");
}
#ifdef DEBUG_PRINT
/*****************************************************************************
*
* Debug
*
*
*
*****************************************************************************/
void DebugProc(void)
{
if (rs232c_flag.rs232c_rx == 1) {
rs232c_flag.rs232c_rx = 0;
rs232c_rx();
}
#if 1
if (rs232c_flag.rs232c_tx == 1) {
rs232c_dump();
}
#endif
}
/*****************************************************************************
*
* RS232C
*
*
*
*****************************************************************************/
void rs232c_rx(void)
{
int i;
unsigned long addr,data;
char *p;
for (i = 0;debugcounts[i].len > 0;i++) {
/* */
if ((sci_rxdata[0] == 'R' || sci_rxdata[0] == 'r') && sci_rxdata[1] == ' ') {
if (rsicmp(sci_rxdata + 2,debugcounts[i].name,debugcounts[i].len) == 0) {
rsprint("\r\n");
rsprint(debugcounts[i].name);
rsprinthex(" = ",*(debugcounts[i].dwcount),4);
rsprint("\r\n>");
break;
}
} else if ((sci_rxdata[0] == 'C' || sci_rxdata[0] == 'c') && sci_rxdata[1] == ' ') {
if (rsicmp(sci_rxdata + 2,debugcounts[i].name,debugcounts[i].len) == 0) {
*(debugcounts[i].dwcount) = 0L;
rsprint("\r\n");
rsprint(debugcounts[i].name);
rsprinthex(" = ",*(debugcounts[i].dwcount),4);
rsprint("\r\n>");
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -