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

📄 projectorctl.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      All Rights Reserved.                                                */
/*                                                                          */
/*  Property of Texas Instruments Incorporated. Restricted Rights -         */
/*  Use, duplication, or disclosure is subject to restrictions set          */
/*  forth in TI's program license agreement and associated documentation.   */
/****************************************************************************/

/****************************************************************************/
/* projectorCtl.c                                                           */
/****************************************************************************/

#include <stddef.h>
#include <string.h>

#include "ddp2230_rtos_include.h"
#include "gpio.h"
#include "urt.h"

#include "gpioFunction.h"
#include "projectorCtl.h"
#include "projectorCtlExt.h"
#include "usbIO.h"
#include "dbmessage.h"
#include "taskParm.h"
#include "global.h"
#include "app_cfg.h"


/****************************************************************************/
/* Local declarations.                                                      */
/****************************************************************************/

typedef struct _messageStruct                 /* Projector control message. */
{
    struct _head
    {
        uint08 cmd1;                                           /* command 1 */
        uint08 seq;                                      /* sequence number */
        uint08 nada;                                              /* unused */
        uint08 length[2];            /* length, as 2 bytes to avoid padding */
    } head;
    uint08 text[256];                                       /* message text */
    uint08 cksum;                                   /* checksum placeholder */
}
    MESSAGE_STRUCT;


/****************************************************************************/
/* Local data.                                                              */
/****************************************************************************/

static const char cmdTaskName[] = "projCtlTask";

static const uint16 msTimeout[8] =                   /* Max UART read time. */
{
    1084,                                                           /* 2400 */
     542,                                                           /* 4800 */
     271,                                                           /* 9600 */
     181,                                                          /* 14400 */
     136,                                                          /* 19200 */
      68,                                                          /* 38400 */
      46,                                                          /* 57600 */
      23                                                          /* 115200 */
};

static const URTINIT urtTemplate =         /* UART initialization template. */
{
    TRUE,                                                    /* PortEnable  */
    URT_115200,                                              /* BaudRate    */
    URT_8DBITS,                                              /* DataBits    */
    URT_1SBITS,                                              /* StopBits    */
    URT_NONE,                                                /* Parity      */
    URT_OFF,                                                 /* FlowControl */
    URT_RX_ONE_HALF_FULL,                                    /* RXTrigLevel */
    URT_TX_ONE_HALF_FULL,                                    /* TXTrigLevel */
    URT_NONINV_RXDPOL                                        /* RXDPolarity */
};

static uint08  pctlConfig;               /* projector control configuration */

static uint32  cmdTaskID = ID_INVALID;                   /* command task ID */
static uint16  uartTimeout;                          /* max message timeout */
static URTPORT uartPortPC;                   /* projector control UART port */

                        /****************************************************/
                        /* Message parser variables.                        */
                        /****************************************************/

static uint16 nWritten;                  /* number of message bytes written */

static BOOL readUnderFlag;                    /* message read underrun flag */
static BOOL writeOverFlag;                    /* message write overrun flag */

int16   nRemReadPC;            /* number of message bytes remaining to read */
int16   nRemWritePC;          /* number of message bytes remaining to write */

uint08 *rdp;                        /* pointer to next message byte to read */
uint08 *wrp;                       /* pointer to next message byte to write */

union parmUnionType parmUnion;   /* macro helper object. See projectorCtl.h */

                        /****************************************************/
                        /* Command dictionary.                              */
                        /****************************************************/

extern CMD_DICT_ENTRY refDictArray;         /* reference command dictionary */
extern size_t         refDictSize;  /* size of reference command dictionary */

#define DICTMAX 4                 /* maximum number of command dictionaries */

static CMD_ARRAY_STRUCT dictArray[ DICTMAX ];           /* dictionary array */

                        /****************************************************/
                        /* 4-byte aligned message structure. Alignment is   */
                        /* required since a pointer to this struct will be  */
                        /* passed to the USB driver.                        */
                        /****************************************************/

__align(4) static MESSAGE_STRUCT Msg;                  /* message structure */



/****************************************************************************/
/* Local functions.                                                         */
/****************************************************************************/

static uint16     cmdExecute( void );
static void       cmdTaskSerial( void );
static void       cmdTaskUSB( void );

static BOOL      _pctlCksumCheck( void );
static void      _pctlCksumGen( void );

static CMD1_TYPE _pctlCmdRead( void );
static CMD1_TYPE _pctlCmdWrite( void );

static void      _pctlFormatAck( void );
static void      _pctlFormatNack( void );

static uint16    _pctlLengthGet( void );
static void      _pctlLengthSet( uint16 length );

static CMD1_TYPE _pctlVector( CMD1_TYPE ctype, uint32 key );



/****************************************************************************/
/* Valid address table.                                                     */
/****************************************************************************/

static const struct _memMapStruct
{
  uint32 laddr;
  uint32 uaddr;
}
mapTable[] =
{
  { 0x00000000, 0x00003FFF }, { 0x11000000, 0x11000FFF },
  { 0x11002000, 0x11002FFF }, { 0x11003000, 0x11003FFF },
  { 0x11004000, 0x11004FFF }, { 0x11005000, 0x11005FFF },
  { 0x11006000, 0x11006FFF }, { 0x11007000, 0x11007FFF },
  { 0x1100E000, 0x1100EFFF }, { 0x1100F000, 0x1100FFFF },
  { 0x11010000, 0x110107FF }, { 0x11011000, 0x110117FF },
  { 0x11011800, 0x11011FFF }, { 0x11012000, 0x110127FF },
  { 0x11013000, 0x110137FF }, { 0x11014000, 0x110147FF },
  { 0x11014800, 0x11014FFF }, { 0x11015000, 0x110157FF },
  { 0x11015800, 0x11015FFF }, { 0x11016000, 0x110167FF },
  { 0x11016800, 0x11016FFF }, { 0x11020000, 0x11020FFF },
  { 0x11021000, 0x11021FFF }, { 0x11022000, 0x11022FFF },
  { 0x11023000, 0x110234FF }, { 0x11023500, 0x110237FF },
  { 0x11023800, 0x11023A7F }, { 0x20000000, 0x27FFFFFF },
  { 0xF7FF6000, 0xF7FF7FFF }, { 0xF7FF8000, 0xF7FFFFFF },
  { 0xF8000000, 0xF9FFFFFF }, { 0xFA000000, 0xFAFFFFFF },
  { 0xFB000000, 0xFBFFFFFF }, { 0xFFFF0000, 0xFFFFFFFF }
};

static const int tabSize = sizeof( mapTable ) / sizeof( struct _memMapStruct );



/****************************************************************************/
/* Determine validity of address.                                           */
/****************************************************************************/

BOOL invalidAddress( void *addr )
{
    int x;
    uint32 address = (uint32)addr;

    for( x = 0; x < tabSize; x++ )
        if(( address >= mapTable[x].laddr ) && ( address <= mapTable[x].uaddr ))
            break;                                          /* found in map */

  return x == tabSize;
}



/****************************************************************************/
/* Get parameter from request.                                              */
/****************************************************************************/

BOOL cmdGet( int32 nBytes, void *parm )
{
    if(nRemReadPC < nBytes )                          /* if no bytes to get */
    {
        readUnderFlag = TRUE;
        return FALSE;
    }

    memcpy( parm, rdp, nBytes );                       /* copy from message */
    rdp += nBytes;                                          /* bump pointer */
    nRemReadPC -= nBytes;                                     /* bump count */

    return TRUE;                                                 /* success */
}



/****************************************************************************/
/* Put parameter to response.                                               */
/****************************************************************************/

BOOL cmdPut( int32 nBytes, void *parm )
{
    if( nRemWritePC < nBytes )
    {
        writeOverFlag = TRUE;
        return FALSE;
    }

    memcpy( wrp, parm, nBytes );                         /* copy to message */
    wrp += nBytes;                                          /* bump pointer */
    nRemWritePC -= nBytes;                                    /* bump count */
    nWritten  += nBytes;                                      /* bump count */

    return TRUE;                                                 /* success */
}



/****************************************************************************/
/* Bump the read pointer when the caller has directly read the message      */
/* buffer instead of using the serialized accessors.                        */
/****************************************************************************/

BOOL cmdIncRead( int32 nBytes )
{
    if(nRemReadPC < nBytes )                          /* if no bytes to get */
    {
        readUnderFlag = TRUE;
        return FALSE;
    }

    rdp += nBytes;                                          /* bump pointer */
    nRemReadPC -= nBytes;                                     /* bump count */

    return TRUE;                                                 /* success */
}



/****************************************************************************/
/* Bump the write pointer when the caller has directly written the message  */
/* buffer instead of using the serialized accessors.                        */
/****************************************************************************/

BOOL cmdIncWrite( int32 nBytes )
{
    if( nRemWritePC < nBytes )
    {
        writeOverFlag = TRUE;
        return FALSE;
    }

    wrp += nBytes;                                          /* bump pointer */
    nRemWritePC -= nBytes;                                    /* bump count */
    nWritten  += nBytes;                                      /* bump count */

    return TRUE;                                                 /* success */
}



/****************************************************************************/
/* Convert float to fixed point with 'precision' fractional bits.           */
/****************************************************************************/

int cmdFloatToFixed( float flt, int precision )
{
    int powerOf2 = 1 << precision;
    int result   = ((int)flt) << precision;

    flt -= ( (int)flt );
    result += (int)( flt / (1.0 / (float)powerOf2) );

    return result;
}



/****************************************************************************/
/* Convert fixed point with 'precision' fractional bits to float.           */
/****************************************************************************/

float cmdFixedToFloat( int fixed, int precision )
{

⌨️ 快捷键说明

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