📄 main.c
字号:
//-----------------------------------------------------------------------------
//
// Filename: main.c
//
// DESCRIPTION:
//
//--------------------------------------------------------------------------
// $Archive:
// $Modtime:
// $Revision:
//--------------------------------------------------------------------------
//
// Copyright 2005-2006, Cypress Semiconductor Corporation.
//
// This software is owned by Cypress Semiconductor Corporation (Cypress)
// and is protected by and subject to worldwide patent protection (United
// States and foreign), United States copyright laws and international
// treaty provisions. Cypress hereby grants to licensee a personal,
// non-exclusive, non-transferable license to copy, use, modify, create
// derivative works of, and compile the Cypress Source Code and derivative
// works for the sole purpose of creating custom software in support of
// licensee product to be used only in conjunction with a Cypress integrated
// circuit as specified in the applicable agreement. Any reproduction,
// modification, translation, compilation, or representation of this
// software except as specified above is prohibited without the express
// written permission of Cypress.
//
// Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Cypress reserves the right to make changes without further notice to the
// materials described herein. Cypress does not assume any liability arising
// out of the application or use of any product or circuit described herein.
// Cypress does not authorize its products for use as critical components in
// life-support systems where a malfunction or failure may reasonably be
// expected to result in significant injury to the user. The inclusion of
// Cypress' product in a life-support systems application implies that the
// manufacturer assumes all risk of such use and in doing so indemnifies
// Cypress against all charges.
//
// Use may be limited by and subject to the applicable Cypress software
// license agreement.
//
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// INDENTATION NOTES:
// ASM files indent with HARD-TABs and assume standard 8-char/tab
// 'C' files indent with 4 SPACE characters
//--------------------------------------------------------------------------
#include "defines.h"
#include "lpradio.h"
#include "PWM16_1.h"
#include "voipRadio.h"
#include "voip8kIsr.h"
#include "GlobalParams.h"
#include "voip8kIsr.h"
#include "flash.h"
#define LED_GRN_ON (TEST_TMR_Data_ADDR &= ~LED_GRN_1_MASK) // GRN LED LOW
#define LED_GRN_OFF (TEST_TMR_Data_ADDR |= LED_GRN_1_MASK) // GRN LED HIGH
#define LED_RED_ON (TEST_TMR_Data_ADDR &= ~LED_RED_2_MASK) // RED LED LOW
#define LED_RED_OFF (TEST_TMR_Data_ADDR |= LED_RED_2_MASK) // RED LED HIGH
#define SW1_IDLE 0
#define SW1_JUST_ON 1
#define SW1_JUST_OFF 2
#define SW1_IS_ON 3
BYTE serveSw1 (void);
void timeSet (WORD *pTimer, WORD time); // 3 mS per count
BOOL timeExpired(WORD *pTimer);
/////////////////////////////////////////////////////////////////////////////
// ---------------------------------------------------------------------------
// PCM 16-bit data arrives little-endian over USB
// ---------------------------------------------------------------------------
#define USB_BUF_SIZE 128
#pragma data:Page1Data
WORD usbOutBuf[USB_BUF_SIZE] = {0}; // dedicated RAM page
#pragma data:data
#define USB_OUT_BUF_END &usbOutBuf[USB_BUF_SIZE-1]
#define USB_EPOUT_BYTE_LEN 16
WORD *usbOutOt; // Unload pointer for PCM data from PC
WORD *usbOutIn; // Load pointer for PCM data from PC
WORD insertVal;
char nulInsDel; // Pending: {0=none, 1=insert, 2=delete}
#pragma data:Page2Data
WORD usbInBuf[USB_BUF_SIZE] = {0}; // dedicated RAM page
#pragma data:data
#define USB_IN_BUF_END &usbInBuf[USB_BUF_SIZE-1]
WORD *usbInOt;
WORD *usbInIn;
#pragma data:Page3Data
int outInsertCt = 0;
int outDeleteCt = 0;
int rs232LineCt = 0;
WORD rssiFiltTbl[30] = {0};
#pragma data:data
static void doUsbOut (void);
static void doUsbIn (void);
static void monitorChannel (void);
static void doRs232Stats (void);
/////////////////////////////////////////////////////////////////////////////
static BYTE hexAscLsn(BYTE data) {
data &= 0x0F;
if (data > 9) return(data - 0x0A + 'A');
else return(data + '0');
}
static BYTE hexAscMsn(BYTE data) {
data >>= 4;
data &= 0x0F;
if (data > 9) return(data - 0x0A + 'A');
else return(data + '0');
}
extern WORD mibMissRx_2;
extern WORD mibMissRx_1;
extern BYTE uartTxD;
#define CR 0x0D
#define LF 0x0A
#define PG3_BASE ((BYTE*)0x380)
BYTE *pg3base;
BYTE hexdec(BYTE hex) {
BYTE retval;
retval = 0;
while (hex >= 10) {
retval += 0x10;
hex -= 10;
}
return (retval + hex);
}
#pragma data:Page3Data
BOOL grnLedOn = 0;
WORD ledTimer = 0;
#pragma data:data
void main()
{
usbOutIn = &usbOutBuf[0];
usbOutOt = &usbOutBuf[0];
usbInIn = &usbInBuf[0];
usbInOt = &usbInBuf[0];
outInsertCt = 0;
outDeleteCt = 0;
LED_RED_ON;
// does_not_work_yet OSC_CR0 = OSC_CR0_CPU_12MHz;
// does_not_work_yet flash_write_lite(255, (void *)(0x0));
// does_not_work_yet OSC_CR0 = OSC_CR0_CPU_24MHz;
// -----------------------------------------------------------------------
// START USB
// -----------------------------------------------------------------------
USB_Start(0, USB_5V_OPERATION);
M8C_EnableGInt;
while(!USB_bGetConfiguration()); // Wait for USB configuration to occur
// Disable endpoint interrupts
M8C_DisableIntMask (USB_INT_REG, (USB_INT_EP1_MASK | USB_INT_EP2_MASK));
INT_CLR2 = 0; // Clear possible pending interrupt
USB_EnableOutISOCEP(2);
USB_LoadInISOCEP(1, (BYTE*)&usbInIn[0], 16, USB_TOGGLE); // Prime USB IN
// -----------------------------------------------------------------------
// For some reason, Windows XP isn't really done enumerating yet.
// So watch USB OUT buffer before dedicate to radio synchronization
// (because radio may not be there yet)
// -----------------------------------------------------------------------
{
while(!(INT_CLR2 & INT_MSK2_EP2))
{
doUsbOut();
doUsbIn();
}
}
// -----------------------------------------------------------------------
// START RADIO AND 8 KHz ISR
// -----------------------------------------------------------------------
SPIM_Radio_Start(SPIM_Radio_SPIM_MODE_0 | SPIM_Radio_SPIM_MSB_FIRST);
WirelessInitialise();
// START RSSI GATHER FOREVER
// RadioInit(END_STATE_RXSYNTH, TX_CFG_RST);
// RadioSetXactConfig( 0 | FRC_END_STATE | END_STATE_RX);
// for (;;)
// {
// WirelessRssiGather();
// }
// END RSSI GATHER FOREVER
startIsr(); // Start Radio Tx/Rx slotting
LED_RED_OFF;
LED_GRN_ON;
// #######################################################################
//
// MAIN POLLING LOOP
//
// #######################################################################
for(;;)
{
// -------------------------------------------------------------------
// Service USB data
// -------------------------------------------------------------------
doUsbOut();
doUsbIn();
if (bufRxCtl[0] != 0) { // If NZ Rx Control buffer length
// num0 = bufRxCtl[1]; // load data and do something with it
// num1 = bufRxCtl[2];
// num2 = bufRxCtl[3];
bufRxCtl[0] = 0; // Clear length
}
// -------------------------------------------------------------------
// Format and buffer UART debug data
// -------------------------------------------------------------------
if (uartTxD == 0) { // If UART Tx holding register EMPTY
doRs232Stats(); // Then get another character
}
monitorChannel();
// -------------------------------------------------------------------
// Toggle blinking "ALIVE" LED
// -------------------------------------------------------------------
if (timeExpired(&ledTimer))
{
timeSet(&ledTimer, 100); // every 3 * 100 mS
if (grnLedOn) LED_GRN_ON;
else LED_GRN_OFF;
grnLedOn ^= 1;
// // ---------------------------------------------------------------
// // Send periodic Control message to Remote
// // ---------------------------------------------------------------
// if (radTxCtrlPutFull() == 0)
// {
// radTxCtrlPutByte(0x55);
// radTxCtrlPutByte(0xAA);
// radTxCtrlPutByte(0x0F);
// radTxCtrlPutLen(3); // Release for Tx
// }
}
// -------------------------------------------------------------------
// Watch for "resynchronize" button
// -------------------------------------------------------------------
SW1_Data_ADDR &= ~SW1_MASK; // Activate PULL-down
if (SW1_Data_ADDR & SW1_MASK)
{
char ivar;
for (ivar = voipCt + 20; ivar > voipCt; ); // make debounce
while (SW1_Data_ADDR & SW1_MASK)
SW1_Data_ADDR &= ~SW1_MASK; // Wait for break
for (ivar = voipCt + 20; ivar > voipCt; ); // break debounce
slotCt = 0xFF; // synchronization at next ISR
}
}
}
// ---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -