📄 tone.ss
字号:
// ----------------------------------------------------------------------------
// Copyright (c) 2008 Semiconductor Components Industries, LLC
// (d/b/a ON Semiconductor). All Rights Reserved.
//
// This code is the property of ON Semiconductor and may not be redistributed
// in any form without prior written permission from ON Semiconductor. The
// terms of use and warranty for this code are covered by contractual
// agreements between ON Semiconductor and the licensee.
// ----------------------------------------------------------------------------
// Tone.ss
// - Application-specific functions
// - A 2 kHz tone is toggled on and off every time the timer expires.
// The 2 kHz tone is mixed with the pass-through audio.
// ----------------------------------------------------------------------------
// $Revision: 1.16 $
// $Date: 2008/10/29 18:00:25 $
// ----------------------------------------------------------------------------
#include <boss.inc>
#include <bat.inc>
#include "Tone.inc"
#include "Tone_internal.inc"
Mem_Start_Reloc_Segment(Tone_segment, SYSTEM_MEMORY_TYPE_P, 0x1000)
// ---------------------------------------------------------------------------
// Tone generation Version
// ---------------------------------------------------------------------------
// Set the global assembler symbol Tone_Version equal to the
// pre-processor define TONE_VERSION that was defined in Tone.inc
.global Tone_Version
.equ Tone_Version, TONE_VERSION
// -----------------------------------------------------------------------------
// Function: Tone_Initialize
// Description: Tone generation algorithm initialization routine.
// Clock cycles: 8
// Modifies: AH, AE
// -----------------------------------------------------------------------------
.global Tone_Initialize
Tone_Initialize:
// Initialize XL_TONE_TABLE_PTR to point to the beginning of the tone table
LDI AH, XH_TONE_TABLE
LD XL_TONE_TABLE_PTR, A, X
// Initialize YL_TONE_STATUS to TONE_OFF
LDI AH, TONE_OFF
LD YL_TONE_STATUS, A, Y
RET R3
// -----------------------------------------------------------------------------
// Function: Tone_Generation
// Description: Generates a tone by mixing a sinusoidal signal with the output
// audio (i.e. the signal in the output FIFO).
// Clock cycles: Min: 14 Max: 24+5*TONE_R
// Modifies: AH, AE, LC0, R1, R4
// -----------------------------------------------------------------------------
// Control Registers
// -----------------------------------------------------------------------------
// Reads: D_SMART_OUT_FIFO_BASE
// Writes: D_SMART_OUT_FIFO_BASE
// -----------------------------------------------------------------------------
.global Tone_Generation
Tone_Generation:
// - First, the YL_TONE_STATUS flag is checked. If the flag is TONE_ON,
// generate a tone. Otherwise, jump directly to turn_off_tone and no
// tone is generated
// - A tone is generated by looking up a value in the tone table (starting
// address of tone table = XH_TONE_TABLE). The tone table contains 2
// periods of a 2 kHz sine sampled at 16 kHz (i.e. the table contains
// 16 samples of the sine).
// - Each time this function is executed without branching to turn_off_tone,
// TONE_R consecutive samples from the tone table are extracted and added
// to the data in the smart output FIFO
// - A pointer is used to point to the tone table. Every time R samples have
// been extracted from the tone table, the pointer is updated such that it
// points to the beginning of the next R samples. When the pointer reaches
// the end of the tone table, it will wrap around to the beginning of the
// table.
PUSH PCFG1
// Check the status of YL_TONE_STATUS flag. If the flag is set to TONE_OFF
// branch to turn_off_tone and end the function. Otherwise, generate a tone.
LD A, YL_TONE_STATUS, Y
CMSI A, TONE_OFF
BRA turn_off_tone, Z
// YL_TONE_STATUS is set to TONE_ON. The following code will generate the
// tone.
PUSH ST
// Set overflow protection bit to prevent overflowing when a
// tone is added to the existing data in the smart output FIFO
SET ST, ST_OP
// The following BOS macro configures PCFG1 such that
// R1 runs in linear circular mode. The macro only needs
// 3 parameters when configuring a PCFG register for
// linear circular mode. Therefore, the last parameter
// (i.e. 0) is a dummy parameter.
Addr_Config_to_Reg(PCFG1, SIZE_TONE_TABLE, LINEAR, 0)
// XL_TONE_TABLE_PTR stores a pointer to the tone table.
LD A, XL_TONE_TABLE_PTR, X
// Set R1 to point to the tone table. Because of the PCFG1
// configuration, R1 will wrap around when it reaches the
// end of the tone table.
LD R1, AH
// Make R4 point to the beginning of the current output
// block in the output FIFO
LDI R4, (D_SMART_OUT_FIFO_BASE + TONE_R - 1)
LDSI LC0, (TONE_R - 1)
add_tone:
LD AH, (R1+) // Load a value in the tone table to AH.
ADD A, (R4) // Add the sample in the output FIFO.
LD (R4-), AH // Save the addition result back to the
DBNZ0 add_tone // output FIFO.
LD AH, R1 // update the tone table pointer
LD XL_TONE_TABLE_PTR, A, X
POP ST
turn_off_tone:
POP PCFG1
RET R3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -