📄 app.c
字号:
/************************************************************
// Copyright (C) 2004 Texas Instruments, Inc.
//
// File: app.c
//
// Comment: [MSP + DSP] Audio Player using Salvo RTOS
//
// Author: Randy Wu
// Company: Texas Instruments, Inc
// Date: September 2004
// IDE: Built with IAR Systems Embedded Workbench 430 V3.20A
//
// Hardware:
// - SoftBaugh ES449 Demo Board featuring SBLCDA2T 4-Mux LCD
//
************************************************************/
#include "app.h"
#include "es449_sblcda2t.h"
#include <salvo.h>
extern unsigned int timerInts;
unsigned int wPlayStatus = AUDIO_MUTE;
unsigned int wCurrentVolume = STARTVOLUME;
unsigned int wMaxVolume = MAXVOLUME;
_OSLabel(TaskPeriodic1)
_OSLabel(TaskPP2)
void ProcessButtonSW1( void )
{
unsigned char msg;
if (wPlayStatus == AUDIO_MUTE) {
LCD_putON();
wPlayStatus = AUDIO_FIR_ON;
msg = (CMD01 << 6) + (wCurrentVolume / 2);
}
else if (wPlayStatus == AUDIO_FIR_ON) {
LCD_putOFF();
wPlayStatus = AUDIO_FIR_OFF;
msg = (CMD02 << 6) + (wCurrentVolume / 2);
}
else if (wPlayStatus == AUDIO_FIR_OFF) {
LCD_putMUTE();
wPlayStatus = AUDIO_MUTE;
msg = (CMD00 << 6) + 0;
}
else {
LCD_putMUTE();
wPlayStatus = AUDIO_MUTE;
}
while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready?
TXBUF0 = msg;
}
void ProcessButtonSW2( void )
{
unsigned char msg;
wCurrentVolume += 5;
if (wCurrentVolume > wMaxVolume)
wCurrentVolume = STARTVOLUME;
switch (wCurrentVolume / 10) { // Display 10's digit of volume level
case 0 : LCD_putChar(CHAR0, CHAR_DISPLAY_6);
break;
case 1 : LCD_putChar(CHAR1, CHAR_DISPLAY_6);
break;
case 2 : LCD_putChar(CHAR2, CHAR_DISPLAY_6);
break;
case 3 : LCD_putChar(CHAR3, CHAR_DISPLAY_6);
break;
case 4 : LCD_putChar(CHAR4, CHAR_DISPLAY_6);
break;
case 5 : LCD_putChar(CHAR5, CHAR_DISPLAY_6);
break;
case 6 : LCD_putChar(CHAR6, CHAR_DISPLAY_6);
break;
case 7 : LCD_putChar(CHAR7, CHAR_DISPLAY_6);
break;
case 8 : LCD_putChar(CHAR8, CHAR_DISPLAY_6);
break;
case 9 : LCD_putChar(CHAR9, CHAR_DISPLAY_6);
break;
default: break;
}
switch (wCurrentVolume % 10) { // Display 1's digit of volume level
case 0 : LCD_putChar(CHAR0, CHAR_DISPLAY_7);
break;
case 1 : LCD_putChar(CHAR1, CHAR_DISPLAY_7);
break;
case 2 : LCD_putChar(CHAR2, CHAR_DISPLAY_7);
break;
case 3 : LCD_putChar(CHAR3, CHAR_DISPLAY_7);
break;
case 4 : LCD_putChar(CHAR4, CHAR_DISPLAY_7);
break;
case 5 : LCD_putChar(CHAR5, CHAR_DISPLAY_7);
break;
case 6 : LCD_putChar(CHAR6, CHAR_DISPLAY_7);
break;
case 7 : LCD_putChar(CHAR7, CHAR_DISPLAY_7);
break;
case 8 : LCD_putChar(CHAR8, CHAR_DISPLAY_7);
break;
case 9 : LCD_putChar(CHAR9, CHAR_DISPLAY_7);
break;
default: break;
}
// Send the message (only if currently in FIR mode)
if (wPlayStatus == AUDIO_FIR_ON) {
msg = (CMD01 << 6) + (wCurrentVolume / 2);
while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready?
TXBUF0 = msg;
}
else if (wPlayStatus == AUDIO_FIR_OFF) {
msg = (CMD02 << 6) + (wCurrentVolume / 2);
while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready?
TXBUF0 = msg;
}
else
_NOP(); // TODO: Placeholder for handling additional command(s) if needed
}
void ProcessReadLinkMsg( void )
{
// Look at RXBUF0 and decode the message
_NOP(); // TODO: Placeholder for decoding and processing the incoming message if needed
}
void TaskProcessPort2( void )
{
OStypeMsgP msgP;
for (;;)
{
OS_WaitMsg(MSG_PORT2_P, &msgP, OSNO_TIMEOUT, TaskPP2);
if ( *(char *)msgP == SW1_PRESSED )
ProcessButtonSW1();
else if ( *(char *)msgP == SW2_PRESSED )
ProcessButtonSW2();
else if ( *(char *)msgP == INCOMING_MSG )
ProcessReadLinkMsg();
else
_NOP(); // invalid message; ignore & do nothing or insert error handler code here
}
}
void TaskPeriodic( void )
{
P1DIR |= 0xFF;
P1OUT = 0x00;
for (;;)
{
OS_WaitBinSem(BINSEM_PERIODIC_P, OSNO_TIMEOUT, TaskPeriodic1);
ADC12CTL0 |= REFON; // Turn on the ADC12 internal reference (only as needed to save power)
timerInts = 0; // Delay approx. 20 msec (2 Timer_A tics) to allow reference to stabilize
while (timerInts <= 2);
P1OUT ^= BIT0; // Toggle P1.0 LED using exclusive-OR
if (wPlayStatus == AUDIO_FIR_ON || wPlayStatus == AUDIO_FIR_OFF)
LCD_displayAccessories(); // Animate LCD (rotate accessory elements)
ADC12CTL0 |= ADC12SC; // Trigger ADC12 temp sensor reading
}
}
void InitRegs( void )
{
// Turn on Basic Timer interrupts
IE2 |= BTIE;
BTCTL = (BTDIV + BTIP1 + BTIP0); // 125ms interrupt
// Initialize the ADC12 module
ADC12CTL0 = (ADC12ON + REF2_5V + SHT0_7); // Setup ADC12, ref, sampling time for temp sensor, int enable
ADC12CTL1 = SHP; // Use sampling timer
ADC12MCTL0 = (INCH_10 + SREF_1); // Select channel A10, Vref+
ADC12IE = BIT0;
ADC12CTL0 |= ENC; // Enable conversions
P1DIR |= BIT0; // Enable output to LED
P2IE |= (BIT2 + BIT0); // Enable SW1 & SW2 interrupts
// Configure USART0 for UART operation (follow this sequence!)
U0CTL |= SWRST; // Recommended init procedure
U0CTL |= CHAR; // 8-bit characters
UTCTL0 = SSEL1; // UCLK = SMCLK = 1048576 Hz
//UBR00 = 0x6D; // 1MHz --> 9600 bps
//UBR10 = 0x00; // 1MHz --> 9600 bps
//UMCTL0 = 0x00; // no modulation
//UBR00 = 0x12; // 1MHz --> 57600 bps
//UBR10 = 0x00; // 1MHz --> 57600 bps
//UMCTL0 = 0x84; // modulation for 57600 bps
UBR00 = 0x09; // 1MHz --> 115200 bps
UBR10 = 0x00; // 1MHz --> 115200 bps
UMCTL0 = 0x08; // modulation for 115200 bps
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
U0CTL &= ~SWRST; // Do this *just before* enabling USART interrupt(s)
IE1 |= URXIE0; // Enable USART0 RX interrupt
P2SEL |= (BIT5 + BIT4); // P2.4,5 = USART0 TXD/RXD
P2DIR |= BIT4; // P2.4 TXD output direction
P2DIR &= ~BIT5; // P2.5 RXD input direction
}
void InitApp( void )
{
InitRegs(); // Set all standard register bits
while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready?
TXBUF0 = 0; // Start out in MUTE mode
LCD_init(); // Initialize all LCD configuration hardware & parameters
LCD_splashScreen(); // Kick off with title banner
LCD_putMUTE(); // Get ready to accept commands
LCD_putChar(CHAR0, CHAR_DISPLAY_6); // Reset volume to minimum level
LCD_putChar(CHAR0, CHAR_DISPLAY_7);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -