Atmel AT85C51SND3B User manual

AT85C51SND3B Firmware
..............................................................................................
User’s Guide

AT85C51SND3Bx Firmware User’s Guide 1
7691A–MP3–08/07
Section 1
Introduction ........................................................................................... 1-1
Section 2
Firmware Features................................................................................ 2-3
2.1 MMI Manager............................................................................................2-3
2.1.1 Features .............................................................................................2-3
2.1.2 Configuration ......................................................................................2-3
2.2 Device USB...............................................................................................2-3
2.2.1 Features .............................................................................................2-3
2.2.2 Configuration ......................................................................................2-4
2.3 Host USB ..................................................................................................2-4
2.3.1 Features .............................................................................................2-4
2.3.2 Configuration ......................................................................................2-4
2.4 Audio Player..............................................................................................2-4
2.4.1 Features .............................................................................................2-4
2.4.2 Configuration ......................................................................................2-5
2.5 Audio Recorder .........................................................................................2-5
2.5.1 Features .............................................................................................2-5
2.5.2 Configuration ......................................................................................2-5
2.6 Image Viewer ............................................................................................2-5
2.6.1 Features .............................................................................................2-5
2.6.2 Configuration ......................................................................................2-5
2.7 Settings .....................................................................................................2-5
2.7.1 Features .............................................................................................2-6
2.7.2 Configuration ......................................................................................2-6
2.8 Update ......................................................................................................2-6
2.8.1 Features .............................................................................................2-6
2.8.2 Configuration ......................................................................................2-6
2.9 File System ...............................................................................................2-6
2.9.1 Features .............................................................................................2-6
2.9.2 Configuration ......................................................................................2-7
2.10 Nand Flash................................................................................................2-7
2.10.1 Features .............................................................................................2-7
2.10.2 Configuration ......................................................................................2-7
2.11 MMC
®
SD
®
Cards .....................................................................................2-7
2.11.1 Features .............................................................................................2-7
2.11.2 Configuration ......................................................................................2-8
2.12 Display ......................................................................................................2-8

Table of Contents
2 AT85C51SND3Bx Firmware User’s Guide
7691A–MP3–08/07
2.12.1 Features .............................................................................................2-8
2.12.2 Configuration ......................................................................................2-8
2.13 Keyboard...................................................................................................2-8
2.13.1 Features .............................................................................................2-8
2.13.2 Configuration ......................................................................................2-8
2.14 Power Manager.........................................................................................2-8
2.14.1 Features .............................................................................................2-8
2.14.2 Configuration ......................................................................................2-8
2.15 Clock Manager..........................................................................................2-9
2.16 System ......................................................................................................2-9
2.16.1 Features .............................................................................................2-9
2.16.2 Configuration ......................................................................................2-9
Section 3
Source Files Organization .................................................................. 3-11
3.1 Directory Physical Structure....................................................................3-11
3.1.1 snd3b-dvk-x_y_z Directory ...............................................................3-11
3.1.2 _isp_modules Directory ....................................................................3-11
3.1.4 drivers Directory ...............................................................................3-12
3.1.5 lib_mcu Directory..............................................................................3-12
3.1.6 lib_mem Directory.............................................................................3-13
3.1.7 lib_system Directory .........................................................................3-13
3.1.8 mmi Directory ...................................................................................3-13
3.1.10 Tools directory ..................................................................................3-14
3.2 Directories Logical Organization .............................................................3-14
Section 4
Code & Data Management ................................................................. 4-15
4.1 Principle ..................................................................................................4-15
4.1.1 Custom memory organisation...........................................................4-15
Section 5
Architecture......................................................................................... 5-21
5.1 Overview .................................................................................................5-21
5.2 Architecture.............................................................................................5-22
5.3 KERNEL..................................................................................................5-23
5.3.2 The Tasks.........................................................................................5-24
5.3.3 The Inter-Task Communication ........................................................5-24
5.3.4 MMI Manager task............................................................................5-26
5.4 MMI Applications.....................................................................................5-28
5.4.1 Application IDs..................................................................................5-28

Table of Contents
AT85C51SND3Bx Firmware User’s Guide 3
7691A–MP3–08/07
5.4.2 Generic Modules ..............................................................................5-28
5.4.3 Useful Functions and Macro-functions .............................................5-29
5.4.4 Automatic Screen Refreshing...........................................................5-30
5.4.5 Automatic display .............................................................................5-31
5.4.6 Software Timers ...............................................................................5-31
5.4.7 Keyboard Management ....................................................................5-32
5.5 Services ..................................................................................................5-34
5.5.1 Player service ...................................................................................5-34
5.5.2 Recorder Service..............................................................................5-35
5.5.3 Explorer service................................................................................5-35
5.5.4 Ebook service ...................................................................................5-36
5.6 Modules ..................................................................................................5-37
5.6.1 USB Interface ...................................................................................5-37
5.6.2 Player Interface ................................................................................5-38
5.6.3 Recorder Interface............................................................................5-39
5.6.4 Viewer Interface................................................................................5-40
5.6.6 Explorer Interface .............................................................................5-41
5.6.7 Update Interface ...............................................................................5-42
5.7 Debug trace text......................................................................................5-43
Section 6
Firmware Configuration ...................................................................... 6-45
6.1 Overview .................................................................................................6-45
6.2 Configuration Files ..................................................................................6-47
6.2.1 Control Access .................................................................................6-47
6.2.2 Audio Features .................................................................................6-47
6.2.3 Clock.................................................................................................6-49
6.2.4 File System.......................................................................................6-49
6.2.5 Setting ..............................................................................................6-50
6.2.6 Keyboard ..........................................................................................6-50
6.2.7 LCD Display......................................................................................6-53
6.2.8 MMC / SD Card ................................................................................6-54
6.2.9 MMI Applications ..............................................................................6-55
6.2.10 Nand-Flash Memory .........................................................................6-56
6.2.11 Power Management .........................................................................6-56
6.2.12 Scheduler module.............................................................................6-57
6.2.13 USB Module .....................................................................................6-58
6.2.14 Firmware update...............................................................................6-59

AT85C51SND3Bx Firmware User’s Guide 1-1
7691A–MP3–08/07
Section 1
Introduction
The AT85C51SND3Bx is a low power single-chip highly-integrated digital audio
decoder/encoder for applications such as audio players, recorders, cell phones, toys…
The AT85C51SND3Bx MP3 Player firmware is part of the AT85DVK-07 development kit
or the AT85RF D-0 7 reference d esign dedicated to the AT85C5 1SND3B x
microcontroller.
This document is the User’s Guide of the AT85C51SND3Bx MP3 Player firmware.
The topics covered are:
the functional features and options that the firmware brings
how the firmware source code files are organized
the firmware architecture
how to configure the firmware
the MMI layer
The AT85C51SND3Bx firmware described in this document has been developed to run
on the AT85DVK-07 as well as the AT85RFD-07.
For more information on the AT85DVK-07 development board, refer to the documents
“AT85DVK-07 Hardware User’s Guide” and “AT85DVK-07 Demonstration Firmware
User’s Manual”, available on the Atmel web site.
For more information on the AT85RFD-07 development board, refer to the documents
“AT85RFD-07 Hardware User’s Guide” and “AT85RFD-07 Demonstration Firmware
User’s Manual”, available on the Atmel web site.

AT85C51SND3Bx Firmware User’s Guide 2-3
7691A–MP3–08/07
Section 2
Firmware Features
The following sections describe the AT85C51SND3Bx firmware features and options.
Some of the firmware options are not supported by the AT85DVK-07 (e.g. image viewer)
or by AT85RFD-07 (e.g. MMC support).
2.1 MMI Manager
This module allows customers to easily develop their own MMI applications.
2.1.1 Features Application management
– execute
– kill
Mailbox management
– send command to system drivers
– get event from system drivers or MMI applications
– forward event to MMI applications
Software timers
Animated icons
2.1.2 Configuration Applications names
MMI events creation
2.2 Device USB
This module is the USB mass-storage driver.
2.2.1 Features USB 2.0, High and Full Speed Transfer
Class provide : Mass Storage, HID, CDC.
Mass Storage Class :
– rate performance :
typical, 10MB/s read - 8MB/s write on NandFlash
up to 12MB/s on MMC V4 / SD / SD HC
– Supported hosts : Win XP, Win 2K, Mac OSx, Linux
– Secure disk option content through password management

Firmware Features
2-4 AT85C51SND3Bx Firmware User’s Guide
7691A–MP3–08/07
2.2.2 Configuration Connection Speed
– authorize high or full speed (depending on the host)
– authorize only full speed
enable/disable USB Class used (Mass Storage, HID, CDC)
USB device information (vendor ID, product ID, manufacturer name, ...)
– product name
– serial number
Class description (Class name, ...)
enable/disable Disk Password Management (for Mass Storage Class)
2.3 Host USB
This module is the USB host driver.
2.3.1 Features Reduced host implementation
USB 2.0 full speed transfer with USB device
USB class provide:
– HUB
– Mass-storage (e.g. Udisk, multi-card reader)
– HID
– CDC
2.3.2 Configuration enable/disable USB class supported
2.4 Audio Player
This module allows the end-user to play some audio stream.
2.4.1 Features Audio stream
– MP1, MP2, MP3
– WMA
– WAV (PCM, G711, G726)
Stream management
– play
– pause
– stop
– next track
– previous track
– fast Forward
– fast Rewind
– repeat A/B
– speed Adjust (MP1, MP2, MP3 only)

Firmware Features
AT85C51SND3Bx Firmware User’s Guide 2-5
7691A–MP3–08/07
Stream Information
– synchronized play time
– bit rate
– sampling frequency
– number of channels
Tags
– ID3 v1.0, v1.1
– ID3 v2.2 and v2.3
Stereo volume control
Sound effects:
– bass boost
– spatial sound
Adjustable 3-band EQ
– Classic, Pop, Jazz, Rock…
2.4.2 Configuration DAC Output Selection
– internal
– external
External DAC interface
2.5 Audio Recorder
This module allows the end-user to play and record audio streams.
2.5.1 Features Recording (codec G726)
Input line in and micro
2.5.2 Configuration line in gains (analog & digital)
micro gains (analog & digital)
2.6 Image Viewer
This module allows the end-user to display images.
2.6.1 Features Supported Image Format:
– BMP
– JPEG
Automatic Resize
2.6.2 Configuration None
2.7 Settings
This module allows the user to manage user data in the setting segment located in the
customer or reserved data area of the Nand Flash.

Firmware Features
2-6 AT85C51SND3Bx Firmware User’s Guide
7691A–MP3–08/07
2.7.1 Features Management
– load
– save
– update from a file
2.7.2 Configuration Opened Settings structure content
Update file name
2.8 Update
This module allows the end-user to perform firmware update of its player.
2.8.1 Features Firmware, codecs, display, fonts update
No PC tool install required for end-user
Power failure resistant
Update file generated by the Atmel In System Programming tool
2.8.2 Configuration Enable/disable update module
Enable/disable update auto-start at power-up
If update auto-start is enable then configuration of “File Location” on Nand Flash or
MMC/SD card.
enable/disable file erase after update (always enable in case of update auto-start)
2.9 File System
This module allows management of the file system present in the Nand Flash memory
the MMC/SD card, the USB host disk, or through SIO, SPI….
2.9.1 Features FAT12, FAT16, FAT32
ASCII and/or Unicode
More than one file/disk opened at a time
File management
– file information
– I/O access
– create
– copy
– paste
– delete
– rename
Directory management
– directory information
– enter
– go to root
– exit

Firmware Features
AT85C51SND3Bx Firmware User’s Guide 2-7
7691A–MP3–08/07
– create
– delete
– rename
Disk management
– disk Information
– format: FAT12, FAT16, FAT32
2.9.2 Configuration Supported file systems
Maximum number of files to manage at same time
Cache optimization
2.10 Nand Flash
This module is the Nand Flash memory library.
2.10.1 Features Support Nand Flash SLC small or large blocks (16KB or 128KB)
10MB read / 7MB write with 1 Nand Flash
Physical system area
– code with redundancy
– codecs with redundancy
– pictures
– fonts
Logical data area
– proprietary wear-levelling algorithm with ECC management
– settings segment: user reserved data
– secure disk segment: mass storage disk for Data disk security management
– data disk segment: mass storage disk
2.10.2 Configuration Nand Flash auto-detection (average performance)
Nand Flash part number (best performance)
Number of devices: 1, 2, 4
2.11 MMC
®
SD
®
Cards
This module is the memory card library.
2.11.1 Features MMC cards:
– V3 in 1-bit mode at 20 MHz
– V4 in 4-bit mode at 24 MHz
SD cards:
– SD 4-bit mode at 24 MHz
– SD HC 4-bit mode at 24 MHz

Firmware Features
2-8 AT85C51SND3Bx Firmware User’s Guide
7691A–MP3–08/07
2.11.2 Configuration Enable/disable
Bus format:
– automatic: depends on card type
– 1-bit
2.12 Display
This module is the display management library.
2.12.1 Features
2.12.2 Configuration Interface configuration to fit display controller
– type: I80/6800
– timings
2.13 Keyboard
This module is the keypad driver.
2.13.1 Features Matrix choice leads to dedicated hardware schematic
Automatic event generation:
– key press
– key release
– key repeat
– key long press
2.13.2 Configuration Matrix size:
– from 4 keys up to 12 keys
Keypad timings:
– debounce
– auto-repeat start
– auto-repeat interval
– long press
2.14 Power Manager
This module is the system power driver.
2.14.1 Features Dynamic power management
Battery level information
Power on/off
2.14.2 Configuration Power source:
– DC-DC, Regulator…
– voltage
Power off

Firmware Features
AT85C51SND3Bx Firmware User’s Guide 2-9
7691A–MP3–08/07
2.15 Clock Manager
This module is the system clock driver
Oscillator Frequency
Clock Type:
– crystal
– oscillator
2.16 System
2.16.1 Features Memory mapping configurable (code & data)
Code swap between SND3 and Nand Flash (use system area code)
Store a large constant data in the NandFlash (use system area font and display)
2.16.2 Configuration Memory mapping
Banking code space

AT85C51SND3Bx Firmware User’s Guide 3-11
7691A–MP3–08/07
Section 3
Source Files Organization
3.1 Directory Physical Structure
The AT85C51SND3Bx MP3 player firmware source code is composed of several files.
This section describes the directory organization of the firmware package.
3.1.1 snd3b-dvk-x_y_z
Directory
The snd3b-dvk-x_y_z directory contains the firmware package where x_y_z is the firm-
ware version.
.................ISP files: codec, picture_, font
.............................................user’s system configuration files
.............................................user’s MMI peripherals high-level API source code
.............................................Atmel MCU peripherals drivers source code
.............................................Atmel high-level memory storage drivers source code
.............................................Atmel system services source code
.............................................user’s MMI applications source code
.............................................Atmel system modules source code
.............................................code hex and object files
.............................................Atmel firmware tools
.............................................versions history
.............................................Atmel system core configuration
.............................................end user license agreement
.............................................target code download tool for debug mode
.............................................the C language main() function of the firmware
.............................................peripherals option. Used as compilation switches
.............................................Keil project option file
.............................................player.uv2: Keil project file
.............................................basic description and basic getting started
3.1.2 _isp_modules
Directory
The _isp_modules directory contains the files used for In System Programming.
................codec binary files
.............................................font binary files
.............................................pictures binary files
.............................................ISP tool project file

Source Files Organization
3-12 AT85C51SND3Bx Firmware User’s Guide
7691A–MP3–08/07
3.1.3 conf Directory The conf directory contains header files allowing user to configure the Atmel libraries. Its
content is detailed in Section 6.
............conf_access.h: configuration of the memory access interfaces
.............................................conf_audio.h: configuration of the audio part (HW and SW)
.............................................conf_clock.h: configuration of the oscillator frequency
.............................................conf_explorer.h: configuration of the FAT and the navigator
.............................................conf_kbd.h: configuration of the keyboard (HW and SW)
.............................................conf_lbd.h: configuration of the LCD (HW and SW)
.............................................conf_lbd.h: configuration of the SD/MMC interface
.............................................conf_mmi.h: configuration of the MMI behavior
.............................................conf_nf.h: configuration of the nand-flash
.............................................conf_power.h: configuration of power (HW and SW)
.............................................conf_scheduler.h: scheduling of the tasks
.............................................conf_update.h: configuration of the firmware upgrade
.............................................conf_usb.h: configuration of the USB interface
3.1.4 drivers Directory The drivers directory contains the user’s MMI peripherals high-level API source code.
.............................user’s external DAC drivers
.............................................user’s FM receiver drivers
.............................................user’s LCD display drivers
.............................................user’s high-level API source code to display MMI graphical objects
3.1.5 lib_mcu Directory The lib_mcu directory contains the AT85C51SND3Bx core and peripherals drivers
source code.
.....................Audio Processor driver
.............................................Clock Manager driver
.............................................Data Flow Controller driver
.............................................Interrupt controller driver
.............................................Keyboard drivers
.............................................Display interface driver
.............................................MultiMediaCard drivers
.............................................Nand Flash Controller driver
.............................................Power management driver
.............................................Parallel Slave Interface driver
.............................................Serial I/O port driver
.............................................Memory space management driver
.............................................Timers driver
.............................................Universal Serial Bus controller driver
.............................................WatchDog Timer driver
.............................................Generic macro-functions define to get rid of compiler specificities
.............................................Routines of debug trace and assert
.............................................Routines of debug trace and assert
.............................................AT85C51SND3Bx SFR registers description file
.............................................AT85C51SND3Bx SFR registers description file
.............................................Include file to enable and put traces
Note: mcu_drv.h file defines a list of masks related to peripherals controller and provides a list
of macro-functions that maps SFR and pages.
The AT85C51SND3Bx implements a SFR pagination mechanism which allows mapping
of high number of peripherals in the SFR space. Four pages are accessible through the
PPCON register.

Source Files Organization
AT85C51SND3Bx Firmware User’s Guide 3-13
7691A–MP3–08/07
3.1.6 lib_mem Directory The lib_mem directory contains the Atmel high-level memory storage drivers source
code.
.....................MMC/SD memory card driver
.............................................Nand-Flash memory driver
3.1.7 lib_system Directory The lib_system directory contains the Atmel system service source code.
......................automatic display of time-depending graphical objects
.............................................code banking load & swap source code
.............................................inter-process communication library source code
.............................................memory manipulation routines
.............................................boot sequence source code
.............................................software timer library
.............................................unicode management library
.............................................miscellaneous C language manipulation routines
3.1.8 mmi Directory The mmi directory contains the user’s MMI application source code.
Note: This directory content may vary from reference-design firmware to development-kit
firmware.
.......................MMI module template
.............................................dummy application required for code banking mechanism
.............................................MMI equalizer control application
.............................................MMI file system explorer application
.............................................MMI games application
.............................................MMI default application
.............................................MMI display images (fonts & pictures)
.............................................MMI information & system status display application
.............................................MMI keyboard high-level driver
.............................................MMI lyrics display application
.............................................MMI mass-storage application
.............................................MMI audio player application
.............................................MMI playlist management application
.............................................MMI radio application
.............................................MMI recorder MMI control
.............................................MMI contextual menu application
.............................................MMI setting management module
.............................................MMI shared functions
.............................................MMI start-up application
.............................................MMI status control application
.............................................MMI firmware update application
.............................................MMI image viewer application
.............................................MMI volume control application

Source Files Organization
3-14 AT85C51SND3Bx Firmware User’s Guide
7691A–MP3–08/07
3.1.9 modules directory The modules directory contains the Atmel system libraries source code.
...............audio controller library
.............................................memory access and data transfer libraries
.............................................FAT file system library
.............................................MMI manager library
.............................................audio player library
.............................................power management library
.............................................audio recorder library
.............................................firmware scheduler library
.............................................firmware update library
.............................................USB management library
.............................................Picture viewer library
3.1.10 Tools directory The tool directory contains the Atmel image converter as well as the project images.
.............MMI pictures and image converter tool
.............................................Windows
®
USB drive secure executable
3.2 Directories
Logical
Organization
This purpose of this view is to show the logical links between the directories.
These source file directories can be grouped into two firmware parts:
– the customer MMI firmware
– the Atmel system firmware
The customer MMI firmware is the code source you have to develop and customize from
the software platform delivered with this package. Indeed, this layer is dedicated to inter-
face the user with the high-level services provided by the Atmel core firmware and the
AT85C51SNDA chip. See Firmware Architecture Section 5.
The Atmel system firmware is the code source you should not modify since this layer
has been designed to provide full and high-performance services from a low cost chip.
Only the configuration files are to set in order to configure this layer to your application
requirements. See Firmware Configuration Section 6.
drivers directory
lib_system directory lib_mem directory
lib_mcu directory
modules directory
mmi directory
AT85C51SND3B chip
Customer MMI
firmware
Atmel System
firmware

AT85C51SND3Bx Firmware User’s Guide 4-15
7691A–MP3–08/07
Section 4
Code & Data Management
4.1 Principle
The SND3 chip permits:
to customise the memory organisation
to use a code swap feature (= code banking)
to store a large constant data in the NandFlash
Reminder: The C51 core use different memory space (code, data, xdata). The size of
data space is 256B. The size of code space is limited at 64KB and xdata space is limited
at 64KB.
4.1.1 Custom memory
organisation
The AT85C51SND3B chip uses a 64KB of RAM to store the data and code, this particu-
larity permits to configure the memory size according to your needs.
4.1.1.1 Rules xdata space size + code space size = 64KB – 512B
code space size = code common size + code bank size*

Code & Data Management
4-16 AT85C51SND3Bx Firmware User’s Guide
7691A–MP3–08/07
xdata space size, code common size and code bank size* shall be a modulo 512B.
Figure 4-1. Memory organisation
Note: *code bank size is optional, see “Code swap”
64KB RAM
data
reserved
xdata
bank code
common code
256B
256B
Customizable
Customizable
Customizable

Code & Data Management
AT85C51SND3Bx Firmware User’s Guide 4-17
7691A–MP3–08/07
4.1.1.2 How to configure You must change the configuration in the « option.h » header file by defining following
constants:
• XDATA_LENGTH
• CODE_BANKING
• BANK_START_ADDRESS
Note: There are no « code size » #define, because this one is automatically computed using
XDATA_LENGTH.
You must modify the UV2 project according to « option.h » header file;
Figure 4-2. options are in ‘Options for Target’ pop-up in Target tab
Figure 4-3. options are in ‘Options for Target’ pop-up in BL51 Misc tab (linker file
player.lin)
WARNING : At compile time, there are no automatic coherency check between « UV2
project option » and « option.h » (no error and no warning). The execution code may be
corrupted if a difference exists.
CODE_BANKING (ENABLED)
BANK_START_ADDRESS
= 64KB-512B- XDATA_LENGTH
BankArea(0xC200,0xE5FF)
PRINT(".\List\player.m51") RAMSIZE(256)
DISABLEWARNING (15)
BANK10(?CO?FILE(0xC200),?PR?ROUTINE?FILE,?PR?ROUTINE2?FILE)
…
BANK01(?CO?FILE2(0xC200),?PR?ROUTINE?FILE2,?PR?ROUTINE2?FILE2)
OVERLAY( main!(?CO?MMI_LYRICS,…))
CODE( 0x0000-0xE5FF )
XDATA( 0x0000-0x17FF )
player.lin
BANK_START_ADDRESS XDATA_LENGTH 64KB-512B- XDATA_LENGTH

Code & Data Management
4-18 AT85C51SND3Bx Firmware User’s Guide
7691A–MP3–08/07
4.1.2 Code swap
4.1.2.1 Principle The code load swap consists in the downloading of temporary codes in a part of the
microcontroller code section to be executed immediately. When this temporary code has
been completely run, the microcontroller automatically runs back on the permanent
code or a previous temporary code. This makes it possible to have a code memory
space share for temporary codes, expanding then the total code beyond the 64KBytes.
Indeed, the downloading of code with deciphering produces a non-insignificant over-
head time (above 0.1s). The critical code section, that is the system part, must react as
quick as possible with the hardware layer. Also, the code load swap must be rarely exe-
cuted to not load the CPU with overhead routines to the detriment of the system
reactivity.
Figure 4-4. Code load swap representation
4.1.2.2 Mechanism The code load swap mechanism is based on the code banking frame available under
the environment Keil µ Vision. Indeed, the assembly file “lib_system\bank-
ing\l51_bank.a51” has been deeply customized by Atmel to link code-load-swap
routines to the code banking frame. Also, the debugger has been reworked to support
the code load swap and the downloading of code banks will be transparent for you in
debugging mode in a future software delivery.
Thus, the code-load-swap mode is fully supported under the environment Keil µVision
enabling you to develop software beyond the 64K of the code memory space without
difficulty.
64KB RAM
data
reserved
xdata
bank code
common code
Loading once at startup
system code area
bank N
bank N-1
...
bank 1
common code
of Nand Flash
bank 2
Loading for each
bank change
Table of contents