📄 main.c
字号:
/*
Turbo BDM Light ColdFire - main program loop
Copyright (C) 2005 Daniel Malik
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "hidef.h"
#include "MC68HC908JB16.h"
#include "options.h"
#include "commands.h"
#include "usb.h"
#include "led.h"
#include "main.h"
#include "timer.h"
#include "bdmcf.h"
#include "cmd_processing.h"
/* basic program flow:
1. all BDM activity is driven by commands received from the USB
2. all BDM commands are executed from within the ISRs servicing the USB IRQ (i.e. with interrupts disabled)
3. suspend timekeeping is performed in the main loop
4. the only asynchronous activity is detection of external resets on RESET_IN pin through KBD interrupts
*/
/* timer counts up and the part is suspended when it reaches treshold value */
/* the USB interrupt resets the timer */
volatile signed char suspend_timer;
/* initialise the CPU */
void init(void) {
CONFIG = CONFIG_URSTD_MASK | CONFIG_STOP_MASK | CONFIG_COPD_MASK; /* disable part reset on USB reset, enable STOP instruction & disable COP */
ISCR = ISCR_ACK_MASK | ISCR_IMASK_MASK; /* acknowledge IRQ interrupt and disable it */
usb_init(); /* initilise the USB interface */
timer2_init(); /* initialise 10ms system tick */
LED_SW_ON(); /* switch the LED ON */
bdmcf_init(); /* initialise the BDM interface */
cable_status.target_type=CF_BDM; /* initialise cable status */
cable_status.reset=NO_RESET_ACTIVITY;
EnableInterrupts; /* enable interrupts */
}
/* main function */
void main(void) {
unsigned char i;
unsigned char result;
unsigned char buffer[20];
#ifdef STACK_SIZE_EVALUATION
/* initialise stack space with 0x55 */
asm {
TSX /* transfer SP to H:X */
LDA #0x55 /* pattern will be 0x55 */
INCX /* pre-increment the address for simple loop construction */
stack_fill_loop:
DECX /* decrement the address, stack is always from 100 to 1FF so this cannot underflow */
STA ,X /* store A at H:X */
CPX #(@__SEG_START_SSTACK) /* compare the lower 8-bits of the address (upper 8 bits are always 0x01) */
BNE stack_fill_loop
}
#endif
init();
while(1) {
wait_10us(10); /* wait 100us */
suspend_timer++;
if (suspend_timer>=SUSPEND_TIME) {
/* host is not sending keepalive signals, time to suspend all operation */
/* BDM is in idle mode when not communicating, so nothing to do there */
unsigned int i;
T1SC0 &= ~T1SC0_CH0IE_MASK; /* disable input capture interrupt (RSTO detect) */
T2SC &= ~T2SC_TOIE_MASK; /* disable timer ticks */
led_state=LED_OFF; /* switch the LED off */
LED_SW_OFF(); /* do it now, the interrupt which would do it normally is not going to come */
UIR0_SUSPND=1; /* suspend USB */
while (suspend_timer) asm(STOP); /* go to sleep, wait for USB resume or reset */
for (i=0;i<RESUME_RECOVERY;i++) wait_10us(10); /* wait for host to recover */
led_state=LED_ON; /* switch the LED back on */
LED_SW_ON(); /* switch the LED ON */
timer2_init(); /* initialise 10ms system tick */
bdmcf_init(); /* initialise the BDM interface */
cable_status.target_type=CF_BDM; /* initialise cable status */
cable_status.reset=NO_RESET_ACTIVITY;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -