本帖最后由 sunshitao 于 2011-9-26 22:57 编辑
去掉了原程序界面的显示部分、定时器只提供回调函数,
在实际中勉强凑合着用 但是有时候这种架构也不是很方便,感觉还是操作系统好用一点。。。
附上源码 供兄弟姐妹 大叔大婶们 拍砖
#include"LPC11xx.h" /* LPC11xx 外设寄存器定义 */
//#include"uart.h"
//#include"cmd.h"
//#include"study.h"
//#include"en25f16drv.h"
#include"mytime.h"
#include"message.h"
//#include"led.h"
#include"mytime.h"
#include"signal.h"
void LEDproc(void);
void FLASHproc(uint8_t);
void CMDproc(uint8_t infor);
SIGNAL * pledsig;
int main (void)
{
// uint8_t datatest[] = "sunshitao" ; //串口测试信息
uint16_t Msg;
uint8_t MsgVal;
SystemInit(); /* 系统初始化 */
MsgVal = MsgVal;
// pledsig = founn_signal();
// led_flicker_times = 3;
// led_flicker_time_interval = 3;
//-------------------------------------------------------------
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6); //使能GPIO模块
// LED1INIT(); //初始化LED1
// SSPPinInit();//初始化SPI引脚
// UARTInit(115200); //串口初始化
// UARTSend(datatest, 10);//测试串口
// timer32B1_init(); //TMR32B1初始化
SysTick_Config(48000);//系统时钟初始化(10MS)。
init_soft_timer();
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 16); //关闭引脚配置模块
//--------------------------------------------------------------
msg_init();//初始化消息队列
// CMD_Queue.out = 0;
// CMD_Queue.in = 0;
MSG_SEND_MSG(MSG_LED ,1);
while (1) {
MSG_GET_MSG(&Msg); /*获取消息*/
switch(MSG_TYPE(Msg)){
case MSG_LED:
// LEDproc();
break;
case MSG_FLASH:
// MsgVal = (uint8_t)MSG_VALUE(Msg);
// FLASHproc(MsgVal);
break;
case MSG_CMD:
// MsgVal = (uint8_t)MSG_VALUE(Msg);
// CMDproc(MsgVal);
default :
break;
}
}
}
//void LEDproc(void)
//{
// LED1_flicker();
//}
//void FLASHproc(uint8_t operate)
//{
// switch(operate){
// case 1:
// break;
// case 2:
// break;
// default:
// break;
//
// }
//}
//void CMDproc(uint8_t infor)
//{
//
//
//
//
//
//}
/********************************************************************************************************
** End Of File
********************************************************************************************************/
#ifndef MYTIME_H_
#define MYTIME_H_
typedef void (*pTimerCallBack)(void);
typedef struct {
uint32_t delay_counter;
pTimerCallBack TimerProcess;
}MYtimer;
#define TIMER_NUMBER 16
extern void init_soft_timer(void);
extern void TimerService(void);
extern void TimerStart(uint16_t delay,pTimerCallBack pcallback);
#endif
#include "lpc11xx.h"
#include "mytime.h"
//#include "led.h"
static uint16_t TimerID;
static MYtimer TimerArray[TIMER_NUMBER];
void init_soft_timer(void)
{
TimerID = 0;
}
static void destroy_Timer(uint8_t ID)
{
TimerID &=~(1<<ID);
}
static void found_Timer(uint8_t ID)
{
TimerID |= (1<<ID);
}
void TimerService(void)
{
uint8_t i;
uint16_t TimerID_MAP;
TimerID_MAP = TimerID;
i = 0;
while(TimerID_MAP){
if((TimerID_MAP & 0x01 )== 1){
if(!(--TimerArray.delay_counter)){
(*(TimerArray.TimerProcess))();
destroy_Timer(i);
}
}
TimerID_MAP >>= 1;
i++;
}
}
void TimerStart(uint16_t delay,pTimerCallBack pcallback)
{
uint8_t i;
uint16_t TimerID_MAP;
TimerID_MAP = TimerID;
for(i = 0;i < TIMER_NUMBER;i++){
if(TimerID_MAP&0x01){
TimerID_MAP >>= 1;
continue;
}
found_Timer(i);
TimerArray.delay_counter = delay;
TimerArray.TimerProcess = pcallback;
break;
}
return ;
}
#define __MESSAGE_H__
#define MSG_ARRAY_SIZE 8
typedef enum
{
MSG_NULL = 0x00, /*have no message*/
MSG_LED = 0x01, /*key message*/
MSG_UART = 0x02, /*uart message*/
MSG_FLASH = 0x03, /*flash operate message*/
MSG_CMD = 0x04, /*commend message*/
}MSG;
extern void msg_init(void);
extern void msg_put_in(uint16_t u16);
extern void msg_send_msg(uint8_t MsgType, uint8_t Val);
extern void msg_get_out(uint16_t *pU16);
#define MSG_SEND_MSG(MsgType, Val) msg_send_msg(MsgType, Val)
#define MSG_SEND_DATA(u16) msg_put_in(u16)
#define MSG_GET_MSG(pU16) msg_get_out(pU16)
#define MSG_TYPE(u16) ((uint8_t *)(&u16))[0]
#define MSG_VALUE(u16) ((uint8_t *)(&u16))[1]
#define MSG_GET_DATA(pU16) msg_get_out(pU16)
#endif
#include "lpc11xx.h"
#include "message.h"
static uint8_t u8MsgHead; /*position that msg will be put in*/
static uint8_t u8MsgTail; /*position that msg will be get out*/
static uint8_t u8MsgNum; /*msg number*/
static uint8_t u16MsgArray[MSG_ARRAY_SIZE]; /*msg queue*/
/*==================================================================
* Function : msg_init
* Description : init message
* Input Para : void
* Output Para : void
* Return Value: void
==================================================================*/
void msg_init(void)
{
u8MsgHead = 0;
u8MsgTail = 0;
u8MsgNum = 0;
}
/*==================================================================
* Function : msg_put_in
* Description : Put in a U16 data in msg queue.
Because there is no return value to indicate success or fail,
make sure msg queue is large enough, that is MSG_ARRAY_SIZE is big enough!!!
You can get a suitable MSG_ARRAY_SIZE with the debug message.
* Input Para : U16 u16Val : data to be put in
* Output Para : void
* Return Value: void
==================================================================*/
void msg_put_in(uint16_t u16)
{
if (u8MsgNum >= MSG_ARRAY_SIZE)
{
return;
}
//first put in data, then increase u8MsgHead
u16MsgArray[u8MsgHead] = u16;
u8MsgHead++;
if (u8MsgHead >= MSG_ARRAY_SIZE)
{
u8MsgHead = 0;
}
u8MsgNum++;
// INTERRUPT_SET(EA_MAP);
return;
}
void msg_send_msg(uint8_t MsgType, uint8_t Val)
{
if (u8MsgNum >= MSG_ARRAY_SIZE)
{
return;
}
//first put in data, then increase u8MsgHead
((uint8_t *)(&(u16MsgArray[ u8MsgHead])))[0] = MsgType;
((uint8_t *)(&(u16MsgArray[ u8MsgHead])))[1] = Val;
u8MsgHead++;
if (u8MsgHead >= MSG_ARRAY_SIZE)
{
u8MsgHead = 0;
}
u8MsgNum++;
return;
}
/*==================================================================
* Function : msg_get_out
* Description : get a U16 data out of the msg queue.
If the msg queue is empty, get MSG_NULL
* Input Para : void
* Output Para : U16 * pu16Val : pointer to hold data
* Return Value: void
==================================================================*/
void msg_get_out(uint16_t *pU16)
{
if (u8MsgNum == 0)
{
* pU16 = 0x0000;
return;
}
//first get out data, then increase u8MsgTail
*pU16 = u16MsgArray[u8MsgTail];
u8MsgTail++;
if (u8MsgTail >= MSG_ARRAY_SIZE)
{
u8MsgTail = 0;
}
u8MsgNum--;
return;
}
#ifndef __SIGNAL_H_
#define __SIGNAL_H_
typedef struct {
uint8_t signal_sta;
}SIGNAL;
#define SIG_USE 1
#define SIG_NUSE 0
#define SIG_VAL 1
#define SIG_UVAL 0
extern SIGNAL* founn_signal(void);
extern uint8_t apply_signal(SIGNAL* psig);
extern void release_signal(SIGNAL* psig);
extern void destroy_signal(SIGNAL *psig);
#endif
#include"lpc11xx.h"
#include"signal.h"
SIGNAL* founn_signal(void)
{
SIGNAL* psig;
static SIGNAL signal;
psig = &signal ;
psig->signal_sta = SIG_NUSE;
return psig;
}
uint8_t apply_signal(SIGNAL* psig)
{
if(psig->signal_sta == SIG_USE){
return SIG_UVAL;
} else {
psig->signal_sta = SIG_USE;
return SIG_VAL;
}
}
void release_signal(SIGNAL* psig)
{
psig->signal_sta = SIG_NUSE;
}
void destroy_signal(SIGNAL *psig)
{
psig = psig;
psig = 0;
}
#ifndef SYSTICK_H_
#define SYSTICK_H_
extern volatile uint32_t TimeTick;
extern volatile uint32_t TMRInt4ms标志寄存器 ;
extern void sys_process(void);
#endif
#include"LPC11xx.h"
#include"systick.h"
//#include"uart.h"
//#include"cmd.h"
#include"message.h"
//#include"led.h"
#include"mytime.h"
volatile uint32_t TimeTick = 0;
volatile uint32_t TMRInt4ms标志寄存器 = 0;
void SysTick_Handler(void)
{
TimerService();
sys_process();
}
void sys_process(void)
{
}
|