/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define APPMAIN_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XLib.h"
#include "XLED.h"
#include "XKey.h"
#include "XADC.h"
#include "XRTC.h"
#include "XGPIO.h"
#include "XFlash.h"
#include "XBuzzer.h"
#include "XTimer.h"
#include "XTask.h"
#include "XSDCard.h"
#include "XDisplay.h"
#include "XKeyboard.h"
#include "XVarBank.h"
#include "XProFile.h"
#include "XFuseFlash.h"
#include "XPrtEng.h"
#include "XNutOS.h"
#include "XEthernet.h"
#include "XText.h"
#include "XImgMgr.h"
#include "XFunction.h"
#include "XParser.h"
#include "XAppVer.h"
#include "AppMain.h"
#include "XBt.h"
#include "XPrtEng.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#define FIRMWARE_START_ADDR FLASH_START_ADDR
#define UPDATE_LENGTH (FLASH_FILE_ADDR - FLASH_START_ADDR + 0x20000)
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
extern VOID InitailDuraLabel(VOID);
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
#if defined(NUTOS)
STATIC CHAR NutHeap[NUT_HEAP_SIZE];
#endif
ch_20211218
//STATIC UCHAR powerOnDone = 0;
//UCHAR PowerOnStatus(VOID)
//{
// return powerOnDone;
//}
extern UCHAR PowerOnStatus(VOID); // ch_20211220
// ch_20220411
STATIC UCHAR CalStatPowerOn = 0;
UCHAR GetCalStatPowerOn(VOID) {
return CalStatPowerOn;
}
VOID SetCalStatPowerOn(VOID) {
CalStatPowerOn = 1;
}
VOID RstCalStatPowerOn(VOID) {
CalStatPowerOn = 0;
}
STATIC VOID MakeFileMessage(VOID)
{
#if defined(LCD_MODEL)
DspClearDisplay();
ShowMessage(0, 0, MSG_ERASING, 0);
#endif
}
STATIC VOID AppInitial(VOID)
{
#if defined(__HITACHI__)
// initial heap
free(malloc(HEAPSIZE - 4));
#endif
// initial Profile
InitialProfile();
// initial library
InitialLib();
// initial system timer
InitialSysTimer();
// initial communication
InitialCommLibry();
// initial flash interface
//InitialFlash();
// initial SDCard interface
InitialMCI();
// initial key data
InitialKey();
// initial general purpose input output
#if defined(GPIO_MODEL)
InitialGPIO();
#endif
// initial keyboard
#if defined(PS2_MODEL) || defined(USB_HOST_MODEL)
InitialKeyboard();
#endif
//sysprintf("AppInitial-->InitialBuzzer\n");
// initial buzzer
InitialBuzzer();
//sysprintf("AppInitial-->InitialRTC\n");
// initial RTC
InitialRTC();
//sysprintf("AppInitial-->InitialVarBank\n");
// initial varbank
InitialVarBank();
//sysprintf("AppInitial-->InitialPrintEngine\n");
// initial print engine
InitialPrintEngine();
//sysprintf("AppInitial-->InitialImgEng\n");
// get image buffer
InitialImgEng(IMAGE_BUFFER_SIZE);
#if defined(LCD_MODEL)
// initial Dsiplay
DspInitialize();
InitialDspStatus();
#endif
//sysprintf("AppInitial-->initial file system\n");
// initial file system
InitialFile(MakeFileMessage);
//sysprintf("AppInitial-->InitialModel\n");
// initial model name
InitialModel();
//sysprintf("AppInitial-->InitialFunction\n");
// initial function
InitialFunction();
//sysprintf("AppInitial-->InitialParser\n");
// initial parser
InitialParser();
//sysprintf("AppInitial-->SetBufferUart\n");
SetBufferUart();
}
STATIC UCHAR CarriageHomeState = 0;
STATIC VOID CarriageHomeSend(VOID)
{
if(CarriageHomeState == 0)
{
CarriageHomeState=1;
}
}
STATIC VOID CarriageHomeLastPrintState(VOID)
{
if(GetJobErrorState()&0x00FE)
{
CarriageHomeState = 2;
}
else
{
if(CarriageHomeState == 1)
{
}
CarriageHomeState = 0;
}
//SendPrintf(" 0x%2x",GetJobErrorState());
}
STATIC UCHAR CarriageHomeGetOpen(VOID)
{
_PrintCfg *pPwrKeyCfg = GrabPrintConfig();
FLOAT data = 0;
if (GetProfileInt("CARRIAGE HOME", &data) == FALSE)
data = 0;
return ((BOOL)data == TRUE);
}
THREAD(CarriageHomeProcess, arg)
{
_PrintCfg *pPwrKeyCfg = GrabPrintConfig();
#ifdef DEBUG_PRNT
sysprintf("start app CarriageHomeProcess\r\n");
#endif
for (;;)
{
if(CarriageHomeState == 1)
{
if(pPwrKeyCfg->PrintOutMode!=PEEL_MODE)
PaperHome(pPwrKeyCfg);
CarriageHomeState = 0;
}
NutSleep(20);
}
}
extern void PowerOnFeed(void);
///
STATIC VOID AppMain(VOID)
{
_PrintCfg *pMainCfg = GrabPrintConfig();
TaskStart();
EnableInterrupt(0x0);
// sysprintf("start app main\r\n"); // ch_20220309
// sysprintf("2022-05-19 released.\r\n"); // ch_20220309
sysprintf("%s\n", SrcRevName); // ch_20220520
#if defined(MONO_LED)
ShowLED(HID_LED_ON, HID_LED_OFF, HID_LED_OFF);
#elif defined(POLY_LED)
ShowLED(HID_LED_DARK);
#endif
/*
* Automatically senses ribbon presence
*/
#if defined(RIBBON_MODEL)
if (pMainCfg->RibbonFlag) // ch_20220714
CheckRibbonExists(FALSE, TRUE);
#endif
//CutterHome();
/*
* Power on buzzing prompt
*/
if (!CheckKeyPin(FEED_KEY)) // ch_20211229
{
EnableBuzzer(8, 100);
while (CheckBuzzerStatus()) {}
delay_msec(50);
EnableBuzzer(8, 100);
while (CheckBuzzerStatus()) {}
}
// ch_20211229
else
{
EnableBuzzer(0, 0);
while (CheckBuzzerStatus()) {}
}
/*
* Request to send
*/
SetUsbHandShake(TRUE);
SetUartHandShake(UART_STATUS_READY);
UartChar(XOFF);
UartChar(XON);
delay_msec(100); // Waiting KP200 Plus cancel AUTO.BAS
/*
* Boot key function
*/
CheckPowerOnKey();
//powerOnDone = 1; // ch_20211218
GetKey(MENU_KEY);
GetKey(FEED_KEY);
GetKey(PAUSE_KEY);
StartKeyFunc(TRUE);
/*
* Lights and panel show ready
*/
#if defined(MONO_LED)
ShowLED(HID_LED_ON, HID_LED_ON, HID_LED_OFF);
#elif defined(POLY_LED)
SetLEDStat(LED_ON_BLUE); // ch_20220707
ShowLED(HID_LED_GREEN);
#endif
#if defined(LCD_MODEL)
SetDisplayStatus(DIS_READY);
#endif
#if defined(CARRIAGE_OPEN_MODEL)
if (IsCarriageOpen() && pMainCfg->CarriageOpen)
{
#if defined(MONO_LED)
ShowLED(HID_LED_IDLE, HID_LED_OFF, HID_LED_ON);
#elif defined(POLY_LED)
BackupPrevLEDStat(); // ch_20220609
ShowLED(HID_LED_RED);
#endif
}
#endif
if(CarriageHomeGetOpen())
{
SetCarriageCloseCallback(CarriageHomeSend);
SetCarriageOpenCallback(CarriageHomeLastPrintState);
NutThreadCreate("CarriageHome", CarriageHomeProcess, 0, NUT_THREAD_CARRIAGE_HOME_STACK);//THREAD(NutIdle, arg)
}
#if defined(DURALABEL)
// InitailDuraLabel();
#endif
#if defined(UART2_BT)
InitailBt();
#endif
//PowerOnFeed();
//#ifdef DEBUG_PRNT
// sysprintf("Parser\r\n");
//#endif
ClearRibbonEncode();
//while(1);
Parser(); //解析器
}
#if defined(NUTOS)
/*!
* \brief Main thread.
*/
THREAD(NutMain, arg)
{
NutThreadSetPriority(NUT_THREAD_MAIN_PRIORITY);
EnableInterrupt(0x0);
/* Assign stdio to the UART device. */
NutRegisterDevice(&DEV_DEBUG, 0, 0);
RegisterStandardIO(DEV_DEBUG_NAME, _O_WRONLY);
#ifdef NUTDEBUG
NutTraceOs(stdout, 0);
NutTraceHeap(stdout, 0);
#endif
#if defined(NUTNET)
InitialEthernet();
#endif
#if defined(USB_HOST_MODEL)
InitialUsbHost();
#endif
AppMain();
for (;;)
{
// NutThreadYield(); // ch_20211220
NutSleep(10); // ch_20211220
}
}
/*!
* \brief Idle thread.
*
* \param arg Ignored by the idle thread.
*
* This function runs in an endless loop as a lowest priority thread.
*/
//void led_led(void);
THREAD(NutIdle, arg)
{
/* Initialize system timers. */
// unsigned int i;
NutTimerInit();
/* Create the main application thread. */
NutThreadCreate("main", NutMain, 0, NUT_THREAD_MAIN_STACK);//THREAD(NutMain, arg)
/*
* Run in an idle loop at the lowest priority. We can still
* do something useful here, like killing terminated threads
* or putting the CPU into sleep mode.
*/
NutThreadSetPriority(NUT_THREAD_IDLE_PRIORITY);
for (;;)
{
NutThreadYield();
NutThreadDestroy();
}
}
#endif
#if 0
void led_led(void)
{
unsigned int i;
__disable_interrupt();
__enable_interrupt();
while(1)
{
LED1_DARK;
LED2_DARK;
for(i=1000000; i>0; i--);
LED1_LIGHT;
LED2_DARK;
for(i=1000000; i>0; i--);
LED1_DARK;
LED2_DARK;
for(i=1000000; i>0; i--);
LED1_DARK;
LED2_LIGHT;
for(i=1000000; i>0; i--);
}
}
#endif
/******************************************************************************
*
* Function:
* main
*
* Description:
* This global function is program start.
*
* Input:
* None
*
* Output:
* None.
*
******************************************************************************/
extern VOID CalculateCheckSumInit(VOID);
int main(VOID)
{
INT mask;
UINT32 index= 0;
/*
#if defined(DRAM_PROGRAM_LENGTH)
memcpy(DRAM_PROGRAM_ADDR, DRAM_PROGRAM_FLASH_ADDR, DRAM_PROGRAM_LENGTH);
#endif
*/
ii_main();
//sysprintf("main-->EnableInterrupt(0)\n");
EnableInterrupt(0);
//sysprintf("main-->spiFlashInit\n");
spiFlashInit();
//sysprintf("main-->spiFlashPDMARead\n");
spiFlashPDMARead(BOOT_FLASH_ADDR_END,sizeof(ProfileBuffer),(INT *)(((INT)ProfileBuffer)|NON_CACHE_BIT));
//sysprintf("main-->CalculateCheckSumInit\n");
CalculateCheckSumInit();
//sysprintf("main-->DisableInterrupt\n");
DisableInterrupt(INTERRUPT_MASK);
#if defined(MONO_LED)
ShowLED(HID_LED_ON, HID_LED_OFF, HID_LED_OFF);
#elif defined(POLY_LED)
ShowLED(HID_LED_ORANGE);
#endif
//sysprintf("main-->AppInitial\n");
AppInitial();
//sysprintf("main-->EnableInterrupt\n");
EnableInterrupt(mask);
#if defined(NUTOS)
NutHeapAdd(NutHeap, sizeof(NutHeap));
NutThreadCreate("idle", NutIdle, 0, NUT_THREAD_IDLE_STACK);//THREAD(NutIdle, arg)
#else
AppMain();
#endif
}
#if defined(__HITACHI__)
#pragma section End
#endif
VOID ProgramEnd(VOID) {}
以下为AppMain.h//
#ifndef APPMAIN_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define APPMAIN_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
int main(void);
void ii_main(void);
UCHAR PowerOnStatus(VOID); // ch_20211218
VOID SetCalStatPowerOn(VOID); // ch_20220411
VOID RstCalStatPowerOn(VOID); // ch_20220411
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif