📄 pwt.c
字号:
//------------------------------------------------------------------------------
// TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
//
// Property of Texas Instruments -- For Unrestricted Internal Use Only
// Unauthorized reproduction and/or distribution is strictly prohibited.
// This product is protected under copyright law and trade secret
// law as an unpublished work.
// Created 1987, (C) Copyright 1997 Texas Instruments. All rights reserved.
//
// Filename : pwt.c
// Description : Pulse Width Tones body
// Project : Samsom
// Author : salbert@tif.ti.com, Sylvie Albert
//adapted for Samsom by Francois Reygagne freygagne@tif.ti.com
//--------------------------------------------------------------------------------
#include "test.h"
#include "global_types.h"
#include "result.h"
#include "intvecs.h"
#include "pwt.h"
#include "mapping.h"
#include "reset.h"
#include "errorcodes.h"
//----------------------------------------------------------
// Definition of constant
//-----------------------------------------------------------
/* Buzzer frequencies definition */
UWORD8 f[] = { 0x2f, 0x2e, 0x2d, 0x2c };
UWORD8 fis[] = { 0x2b, 0x2a, 0x29, 0x28 };
UWORD8 g[] = { 0x27, 0x26, 0x25, 0x24 };
UWORD8 gis[] = { 0x23, 0x22, 0x21, 0x20 };
UWORD8 a[] = { 0x1f, 0x1e, 0x1d, 0x1c };
UWORD8 ais[] = { 0x1b, 0x1a, 0x19, 0x18 };
UWORD8 h[] = { 0x17, 0x16, 0x15, 0x14 };
UWORD8 c[] = { 0x10, 0x13, 0x12, 0x11, 0x10 };
UWORD8 cis[] = { 0x0c, 0x0f, 0x0e, 0x0d, 0x0c };
UWORD8 d[] = { 0x08, 0x0b, 0x0a, 0x09, 0x08 };
UWORD8 dis[] = { 0x04, 0x07, 0x06, 0x05, 0x04 };
UWORD8 e[] = { 0x00, 0x03, 0x02, 0x01, 0x00 };
void PWT_TestResetValue(void)
{
TEST_FIELD_RESET_VALUE8(PWT_FRC_REG,PWT_FRC_OCT);
TEST_FIELD_RESET_VALUE8(PWT_FRC_REG,PWT_FRC_FRQ);
TEST_FIELD_RESET_VALUE8(PWT_VRC_REG,PWT_ONOFF);
TEST_FIELD_RESET_VALUE8(PWT_VRC_REG,PWT_VOL);
TEST_FIELD_RESET_VALUE8(PWT_GCR_REG,PWT_CKEN);
TEST_FIELD_RESET_VALUE8(PWT_GCR_REG,PWT_TESTIN);
ARE_RESET_VALUES_OK();
}
void PWT_TestRegistersAccess(void)
{
MODIFY_FIELD_RESET_VALUE8(PWT_FRC_REG,PWT_FRC_OCT);
MODIFY_FIELD_RESET_VALUE8(PWT_FRC_REG,PWT_FRC_FRQ);
MODIFY_FIELD_RESET_VALUE8(PWT_VRC_REG,PWT_ONOFF);
MODIFY_FIELD_RESET_VALUE8(PWT_VRC_REG,PWT_VOL);
MODIFY_FIELD_RESET_VALUE8(PWT_GCR_REG,PWT_CKEN);
MODIFY_FIELD_RESET_VALUE8(PWT_GCR_REG,PWT_TESTIN);
ARE_RESET_VALUES_OK();
}
//----------------------------------------------------------------------
// PWT_Wait : Function use to generate a given duration value in ms.
// value is used to configure the timer, fiqCount is the
// fast interrupt counter
//-------------------------------------------------------------------------------
/*void PWT_Wait(const UWORD16 value, UWORD8* const fiqCount)
{
UWORD8 i;
UWORD16 currentvalue;
// Disable the watchdog timer
TIMER_WD_Disable_WatchDog();
// In SA007 the timer interrupt period is defined by the formula :
// Tint = Tclk * (LOAD_TIM +1) * 2^(PTV+1)
// Tclk = 1/Fclk. Fclk = VTCXO/14 because TIMER clock is divded by 14
// LOAD_TIM = Tint/(Tclk*2^(PTV+1) - 1
// Compute the value to be load in timer 1
currentvalue = ((value*PWT_VTCXO*1000)/(14*(2<<PWT_PRESCALE_TIMER_VALUE))-1);
// Initialize the timer
TIMER_1_Init_cntl(currentvalue, TIMER_ONESHOT_MODE,
PWT_PRESCALE_TIMER_VALUE, TIMER_CLOCK_ENABLED);
// wait timer 1 to be ready
for (i=0; i<5; i++) {}
// Start timer 1 count down
TIMER_1_Start();
while (*fiqCount == 0);
// wait timer to be stopped
for (i=0; i<5; i++) {}
}*/
//-------------------------------------------------------------------------------------
// PWT_Set : Program the timer without autoreload, read it back and
// stop when it is equal to 0 .
// (wait is 1 for boad simulation, 0 for RTL one.)
// (volume is > 25)
//-------------------------------------------------------------------------------------
void PWT_Set(const UWORD8 volume, const UWORD8 buz_freq, UWORD8* const fiqCount, const UWORD8 wait)
{
UWORD8 vol;
UWORD32 j;
// Compute volume value (volume => % of max. volume)
vol =(volume *64)/100;
// Set frequency
PWT_FRC_REG = buz_freq;
// Switch ON PWT and select volume value
PWT_VRC_REG = PWT_TONE_ONOFF | (vol << 1);
// Reset interupt counter
*fiqCount = 0;
// wait if requested
if (wait == 1)
for (j=1; j<=101000; j++);
else
for (j=1; j<=700; j++);
}
//------------------------------------------------------------------------
// PWT_TestRegisters
//------------------------------------------------------------------------
UWORD16 PWT_TestRegisters(void)
{
UWORD8 val;
UWORD16 err=RES_OK;
/* Get init. value of general control register */
val = PWT_GCR_REG & 0x03;
if (val != 0x00)
{
RES_Set(0x02);
RES_Set(val);
err=RES_BAD;
}
/* Test access of general control register */
PWT_GCR_REG = 0x1;
val = PWT_GCR_REG & 0x03;
if (val != 0x01)
{
RES_Set(0x03);
RES_Set(val);
err=RES_BAD;
}
/* Get init. value of volume control register */
val = PWT_VRC_REG & 0x7f;
if (val != 0x00)
{
RES_Set(0x04);
RES_Set(val);
err=RES_BAD;
}
/* Test access of volume control register */
PWT_VRC_REG = 0x5a;
val = PWT_VRC_REG;
if (val != 0x5a)
{
RES_Set(0x05);
RES_Set(val);
err=RES_BAD;
}
/* Get init. value of frequency control register */
val = PWT_FRC_REG & 0x3f;
if (val != 0x00)
{
RES_Set(0x06);
RES_Set(val);
err=RES_BAD;
}
/* Test access of frequency control register */
PWT_FRC_REG = 0x15;
val = PWT_FRC_REG;
if (val != 0x15)
{
RES_Set(0x07);
RES_Set(val);
err=RES_BAD;
}
/* end of test */
return err;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -