P2UWaterJiangXi/hardinterface/inc/libbase.h

80 lines
2.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*******************************************************************************
*
* Copyright(C) 2012 WANG XIBING All rights reserved.
*
* 文件libbase.h
* 作者wxb
* 版本V1.00
* 日期2012-1-1
* 描述:基本的数据类型和函数库
* 属性RL78
* 修改V1.00, 2012-1-1, wxb, 创建本文件
*
* 声明:本程序所有权归作者所有。
* 本程序仅用于实现特定产品的功能,任何修改或其它目的的应用均不作保证,
* 任何人未经作者同意不得将本程序的全部或部分用于商业目的。
*******************************************************************************/
#ifndef __LIBBASE_H__
#define __LIBBASE_H__
#include "type.h"
#include "ddl.h"
#include "wdt.h"
#define CHECK_OFFSET 0x5A
#define b2_to_bcd(b2) ((u16)bytes_to_bcd((b2), 2))
#define bcd_to_b2(bcd, b2) bcd_to_byte((bcd), (b2), 2)
#define b3_to_bcd(b3) bytes_to_bcd((b3), 3)
#define bcd_to_b3(bcd, b3) bcd_to_byte((bcd), (b3), 3)
#define b4_to_bcd(b4) bytes_to_bcd((b4), 4)
#define bcd_to_b4(bcd, b4) bcd_to_byte((bcd), (b4), 4)
#define abs(x) (((x)<0) ? (-(x)):(x))
#define ei() __enable_irq()
#define di() __disable_irq()
#define nop() __NOP()
#define halt() __WFI();
// Interrupt
#define enable_int() ei()
#define disable_int() di()
#define stop() halt()
// WDT
#define wdt_reset() Wdt_Feed();
u8 add_check(void *buffer, u8 len);
#define add_offset_check(buffer, len) ((u8)(add_check(buffer, len) + CHECK_OFFSET))
u8 xor_check(void *buffer, u8 len);
#define xor_offset_check(buffer, len) ((u8)(xor_check(buffer, len) + CHECK_OFFSET))
#define b2_to_hex(b2) ((u16)bytes_to_hex((b2), 2))
#define hex_to_b2(hex, b2) hex_to_byte((hex), (b2), 2)
#define b3_to_hex(b3) bytes_to_hex((b3), 3)
#define hex_to_b3(hex, b3) hex_to_byte((hex), (b3), 3)
#define b4_to_hex(b4) bytes_to_hex((b4), 4)
#define hex_to_b4(hex, b4) hex_to_byte((hex), (b4), 4)
#define hex_to_b2_5_high(hex, high) \
hex_to_b2(hex>>4, (high));
#define hex_to_b2_5_low(hex, low) \
low = hex & 0x0F;
#define b2_5_to_hex(high, low) \
((b2_to_hex(high)<<4)|low)
void memcpyinv(void *des, void* src, char len);
u8 u8_to_bcd(u8 n);
u8 bcd_to_u8(u8 b);
u8 u32_to_bcd(u32 n, PU8 bcd, u8 len);
u32 bcd_to_u32(PU8 bcd, u8 len);
u32 bytes_to_hex(const u8 *bytes, u8 len);
void hex_to_byte(u32 hex, u8 *bytes, u8 len);
u32 bytes_to_bcd(const u8 *bytes, u8 len);
void bcd_to_byte(u32 bcd, u8 *bytes, u8 len);
//void u32_to_time(u32 t, DATE_TIME *time);
//u32 time_to_u32(DATE_TIME *time);
void delay_us(u16 us);
void delay_ms(u16 ms);
#endif /*__LIBBASE_H__*/