⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdlist.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
字号:
/****************************************************************
**                                                              *
**  FILE         :  LCDList.C                                   *
**  COPYRIGHT    :  (c) 2001 .Xiamen Yaxon NetWork CO.LTD       *
**                                                              *
**                                                              *
**  By : CCH 2002.1.15                                          *
****************************************************************/
#include "includes.h"
#include "message.h"
#include "tools.h"
#include "errtask.h"
#include "list.h"
#include "uart_drv.h"
#include "timetask.h"
#include "lcddrv.h"
#include "systask.h"
#include "lcdlist.h"

#include "printer.h"


#if EN_LCD > 0                      /* EN_LCD */


/*
********************************************************************************
*                  DEFINE CONFIG PARAMETERS
********************************************************************************
*/
#define NUM_MEM                                 5

#define MAX_OVERFLOW                            10                  /* MAX_OVERFLOW = 30 seconds */
#define MAX_RESEND                              3
#define MAX_WAIT                                100                 /* MAX_WAIT = 2*100 = 200 ticks */

#define PERIOD_RESEND                           SECOND,  1
#define PERIOD_WAIT                             MILTICK, 2


/*
********************************************************************************
*                  DEFINE CELL STRUCTURE
********************************************************************************
*/
typedef struct {
    INT8U       attrib;                         /* attribute */
    INT8U       ct_resend;                      /* resend count */
    INT16U      ct_overflow;                    /* overflow count */
    INT16U      len;                            /* data length */
    INT8U       buffer[LCD_BUFSIZE];            /* buffer */
    void        (*fp)(INT8U result);            /* informer */
} CELL_STRUCT;


/*
********************************************************************************
*                  DEFINE MODULE VARIANT
********************************************************************************
*/
static LIST wacklist, readylist, freelist;
static struct {
    NODE        reserve;
    CELL_STRUCT cell;
} memory[NUM_MEM];

static INT16U   ct_wait;
static INT8U    tempbuf[2*LCD_BUFSIZE];
static TMR_TSK *resendtmr, *waittmr;
static LIST    *findlist[2] = {&readylist, &wacklist};



static void DelCell(CELL_STRUCT *cell, INT8U reason)
{
    void (*fp)(INT8U result);
    
    fp = cell->fp;
    AppendListEle(&freelist, (LISTMEM *)cell);
    if (fp != NULL) fp(reason);
}

static void WaitTmrProc(void)
{
    StartTmr(waittmr, PERIOD_WAIT);
    if (++ct_wait > MAX_WAIT) 
        ErrExit(ERR_LCDLIST_WAIT);
    else 
        OSQPost(SysTaskMsgQue, MSG_LCDLIST_TSK, 0, 0);
}

static void ResendTmrProc(void)
{
    CELL_STRUCT *curcell, *nextcell;
    
    StartTmr(resendtmr, PERIOD_RESEND);
    curcell = (CELL_STRUCT *)GetListHead(&wacklist);
    while(curcell != NULL) {
        if (++curcell->ct_overflow > MAX_OVERFLOW) {
            nextcell = (CELL_STRUCT *)DelListEle(&wacklist, (LISTMEM *)curcell);
            if (++curcell->ct_resend > MAX_RESEND) {
                DelCell(curcell, _OVERTIME);
            } else {
                curcell->ct_overflow = 0;
                AppendListEle(&readylist, (LISTMEM *)curcell);
                OSQPost(SysTaskMsgQue, MSG_LCDLIST_TSK, 0, 0);
            }
            curcell = nextcell;
        } else {
            curcell = (CELL_STRUCT *)ListNextEle((LISTMEM *)curcell);
        }
    }
}

static void DiagnoseProc(void)
{
    INT16U itemcount;
    
    itemcount = ListItem(&wacklist) + ListItem(&readylist) + ListItem(&freelist);
    if (itemcount != sizeof(memory)/sizeof(memory[0])) ErrExit(ERR_LCDLIST_MEM);
    if (GetTmrSwitch(resendtmr) != ON) ErrExit(ERR_LCDLIST_TMR);
}

void InitLCDList(void)
{
    InitList(&wacklist);
    InitList(&readylist);
    InitMemList(&freelist, (LISTMEM *)memory, sizeof(memory)/sizeof(memory[0]), sizeof(memory[0]));

    waittmr   = CreateTimer(WaitTmrProc, 0);
    resendtmr = CreateTimer(ResendTmrProc, 0);
    StartTmr(resendtmr, PERIOD_RESEND);
    
    InstallDiagProc(DiagnoseProc);
}

void LCDListEntry(void)
{
    INT16U i, len;
    CELL_STRUCT *curcell;
    
    if ((curcell = (CELL_STRUCT *)GetListHead(&readylist)) == NULL) {
        if (GetTmrSwitch(waittmr) == ON) StopTmr(waittmr);
        return;
    }
    if(ComType != USE_LCD) {
		DelCell(curcell, _SUCCESS);
		return;
    }
    len = AssembleByRules(tempbuf, curcell->buffer, curcell->len, &lcdrule);
    if (len > sizeof(tempbuf)) ErrExit(ERR_LCDLIST_ASM);
    #if DEBUG_LCD_IO > 0
    PrintFromUART(DEBUG_UARTNo_LCD, "\n<LCDListEntry>");
    #endif    
    if (len > uarts_ready(UART_LCD)) {
        if (GetTmrSwitch(waittmr) != ON) {
            ct_wait = 0;
            StartTmr(waittmr, PERIOD_WAIT);
        }
    } else {
        #if DEBUG_LCD_IO > 0
        PrintFromUART(DEBUG_UARTNo_LCD, "\n<send data to LCD: ");
        #endif
        for (i = 0; i < len; i++) {
            #if DEBUG_LCD_IO > 0
            SendFromUART_HEX(DEBUG_UARTNo_LCD, tempbuf[i]);
            #endif
            uarts_write(UART_LCD, tempbuf[i]);
        }
        #if DEBUG_LCD_IO > 0
        PrintFromUART(DEBUG_UARTNo_LCD, ">\n");
        #endif
        DelListHead(&readylist);
        if (curcell->attrib == LCD_ATTR_ACK) {
            curcell->ct_overflow = 0;
            AppendListEle(&wacklist, (LISTMEM *)curcell);
        } else {
            DelCell(curcell, _SUCCESS);
        }
        OSQPost(SysTaskMsgQue, MSG_LCDLIST_FREE, 0, 0);
        OSQPost(SysTaskMsgQue, MSG_LCDLIST_TSK, 0, 0);
    }
}

BOOLEAN RequestSend_LCD(INT8U attrib, INT8U type, INT8U *ptr, INT16U len, void (*fp)(INT8U))
{
    CELL_STRUCT *curcell;
    
    if(ComType != USE_LCD) {
		return FALSE;
    }
    if (attrib != LCD_ATTR_COMMON && attrib != LCD_ATTR_ACK) return FALSE;
    if ((len + 2) > sizeof(curcell->buffer)) return FALSE;
    if ((curcell = (CELL_STRUCT *)DelListHead(&freelist)) == NULL) return FALSE;
    
    memcpy(&curcell->buffer[2], ptr, len);
    curcell->buffer[1]    = type;
    curcell->buffer[0]    = GetChkSum(&curcell->buffer[1], len + 1);
    curcell->len          = len + 2;
    
    curcell->attrib       = attrib;
    curcell->ct_resend    = 1;
    curcell->ct_overflow  = 0;
    curcell->fp           = fp;
    AppendListEle(&readylist, (LISTMEM *)curcell);
    
    #if DEBUG_LCD_SEND > 0
    PrintFromUART(DEBUG_UARTNo_LCD, "<request send data to LCD>\n");
    FormatPrintDataBlock(FORMAT_HEX, DEBUG_UARTNo_LCD, curcell->buffer, curcell->len);
    #endif

    OSQPost(SysTaskMsgQue, MSG_LCDLIST_TSK, 0, 0);
    return TRUE;
}

BOOLEAN ConfirmSend_LCD(INT8U type, INT8U reason)
{
    INT16U i;
    CELL_STRUCT *curcell;
    
    for (i = 0; i < sizeof(findlist)/sizeof(findlist[0]); i++) {
        curcell = (CELL_STRUCT *)GetListHead(findlist[i]);
        while (curcell != NULL) {
            if (curcell->attrib == LCD_ATTR_ACK && curcell->buffer[1] == type) {
                DelListEle(findlist[i], (LISTMEM *)curcell);
                DelCell(curcell, reason);
                return TRUE;
            } else {
                curcell = (CELL_STRUCT *)ListNextEle((LISTMEM *)curcell);
            }
        }
    }
    return FALSE;
}

#endif                              /* EN_LCD */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -