common.c
来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 198 行
C
198 行
/**************************************************************************/
/* */
/* Copyright (C) 2006 Oki Electric Industry Co., LTD. */
/* */
/* System Name : uPLAT7D series */
/* Module Name : common program */
/* File Name : common.c */
/* Revision : 01.00 */
/* Date : 2006/1/1 */
/* */
/**************************************************************************/
#include "common.h"
#include "hal_api.h"
#define DEBUG 1
#ifdef __arm
//#ifndef SemiSWI
//#ifdef __thumb
///* Define Angel Semihosting SWI to be Thumb one */
//#define SemiSWI (0xAB)
//#else
///* Define Angel Semihosting SWI to be ARM one */
//#define SemiSWI (0x123456)
//#endif
//#endif
///* Write a string */
//__swi(SemiSWI) void _Write0(uint32_t op, const int8_t *string);
//#define Write0(string) _Write0((0x4), (string))
/* Read a character */
//__swi(SemiSWI) int _ReadC(unsigned op);
//#define ReadC() _ReadC (0x7)
/* Exit */
//__swi(SemiSWI) void _Exit(unsigned long op, unsigned long except);
#define Exit() _Exit(0x18, 0x20026)
#endif
/******************************/
/* Private declaration */
/******************************/
static void set_3_led_on(uint16_t led_i);
static void set_7_led_on(uint16_t led_i, uint16_t value);
/********************************************************************/
/* */
/* Function Name : debug_msg */
/* Input : kind This is hexadecimal number that is the */
/* kinds of LED. */
/* 0x3100 : LED start, 3 bit LED1 is on. */
/* 7 segment LED is on by 0. */
/* 0x3200 : If result is OK, 3 bit LED2 */
/* is on. */
/* 0x3300 : If result is NG, 3 bit LED3 */
/* is on. */
/* 0x7iXX : 7 segment LEDi(i = 1, 2, 3...) */
/* is on by XX(0, 1, ... F). */
/* msg Debug message to console. */
/* If msg is NULL, no output. */
/* Output : void */
/* */
/* Note : Let LEDs be on and output debug message. */
/* */
/********************************************************************/
void debug_msg(uint16_t kind, const int8_t *msg) {
#if DEBUG
/* Let LED be on. */
if (kind != NO_LED) {
if ((kind & 0xf000) == _3_LED) {
set_3_led_on((uint16_t)(kind & 0xFF00));
}
else if ((kind & 0xf000) == _7_LED) {
set_7_led_on((uint16_t)(kind & 0xFF00), (uint16_t)(kind & 0x00FF));
}
else {
;
}
}
#ifdef __arm
/* Output message to console. */
if (msg != NULL) {
//Write0(msg);
}
#endif
#endif
}
/********************************************************************/
/* */
/* Function Name : set_3_led_on */
/* Input : led_i 3 bit led number. */
/* Output : void */
/* */
/* Note : Let 3 bit LEDs be on. */
/* */
/********************************************************************/
static void set_3_led_on(uint16_t led_i) {
uint16_t i;
/* Set PD5(green), PD6(orange), PD7(red) output mode. */
uplat7dHAL_PioSetIo(PD, 0xE0);
/* Set PD5, PD6, PD7 all off. */
uplat7dHAL_PioOutData(PD, 0x0);
switch (led_i) {
case _3_LED_START:
/* Set PD5 on only. */
uplat7dHAL_PioOutData(PD, 0x20);
for (i = 0; i < 0x8fff; i++) {
;
}
/* Set PD6 on only. */
uplat7dHAL_PioOutData(PD, 0x40);
break;
case _3_LED_OK:
/* Set PD5 on only. */
uplat7dHAL_PioOutData(PD, 0x20);
break;
case _3_LED_NG:
/* Set PD7 on only. */
uplat7dHAL_PioOutData(PD, 0x80);
break;
default :
break;
}
}
/********************************************************************/
/* */
/* Function Name : set_7_led_on */
/* Input : led_i 7 segment LEDs number. */
/* value 7 segment LEDs value. */
/* Output : void */
/* */
/* Note : Let 7 segment LEDs be on. */
/* */
/********************************************************************/
static void set_7_led_on(uint16_t led_i, uint16_t value) {
uint32_t led_value;
led_value = value;
switch (led_i) {
case _7_LED1:
/* Set 7 segment LED 1. */
led_value = led_value << 16; /* bit16 ~ bit23 */
OkiCLib_write32(_7_LED_ADDR, led_value);
break;
case _7_LED2:
/* Set 7 segment LED 2. */
led_value = led_value << 24; /* bit24 ~ bit31 */
OkiCLib_write32(_7_LED_ADDR, led_value);
break;
default :
break;
}
}
volatile int16_t AP_FIQ_Flag; /* Flag of AP FIQ handler */
/************************************************************************/
/* */
/* Function Name : void AP_FIQ_handler( uint16_t dummy ) */
/* Input : dummy(Unused) */
/* Output : Noting */
/* */
/* Note : AP FIQ handler. */
/* */
/************************************************************************/
void AP_FIQ_handler( uint16_t dummy )
{
AP_FIQ_Flag = 1;
}
volatile int16_t AP_EXINT1_Flag; /* Flag of AP EXINT1 handler */
/************************************************************************/
/* */
/* Function Name : void AP_EXINT1_handler( uint16_t dummy ) */
/* Input : dummy(Unused) */
/* Output : Noting */
/* */
/* Note : AP FIQ handler. */
/* */
/************************************************************************/
void AP_EXINT1_handler( uint16_t dummy )
{
AP_EXINT1_Flag = 1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?