initial import of the usb ccid example for the sam7s
This commit is contained in:
commit
98f9d442b4
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal Flash on the AT91SAM7S128.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x8000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x20000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fixed :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >flash
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} >sram
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x208000;
|
||||
}
|
||||
end = .;
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal SRAM on the AT91SAM7S128.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x8000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x20000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ALIGN(4);
|
||||
.fixed :
|
||||
{
|
||||
_sfixed = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >sram
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
}
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x208000;
|
||||
}
|
||||
end = .;
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal Flash on the AT91SAM7S256.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x10000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x40000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fixed :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >flash
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} >sram
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x210000;
|
||||
}
|
||||
end = .;
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal SRAM on the AT91SAM7S256.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x10000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x40000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ALIGN(4);
|
||||
.fixed :
|
||||
{
|
||||
_sfixed = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >sram
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
}
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x210000;
|
||||
}
|
||||
end = .;
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal Flash on the AT91SAM7S32.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x2000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x8000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fixed :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >flash
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} >sram
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x202000;
|
||||
}
|
||||
end = .;
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal SRAM on the AT91SAM7S32.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x2000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x8000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ALIGN(4);
|
||||
.fixed :
|
||||
{
|
||||
_sfixed = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >sram
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
}
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x202000;
|
||||
}
|
||||
end = .;
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal Flash on the AT91SAM7S321.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x2000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x8000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fixed :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >flash
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} >sram
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x202000;
|
||||
}
|
||||
end = .;
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal SRAM on the AT91SAM7S321.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x2000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x8000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ALIGN(4);
|
||||
.fixed :
|
||||
{
|
||||
_sfixed = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >sram
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
}
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x202000;
|
||||
}
|
||||
end = .;
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal Flash on the AT91SAM7S512.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x10000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x80000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fixed :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >flash
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} >sram
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x210000;
|
||||
}
|
||||
end = .;
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal SRAM on the AT91SAM7S512.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x10000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x80000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ALIGN(4);
|
||||
.fixed :
|
||||
{
|
||||
_sfixed = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >sram
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
}
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x210000;
|
||||
}
|
||||
end = .;
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal Flash on the AT91SAM7S64.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x4000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x10000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fixed :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >flash
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} >sram
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x204000;
|
||||
}
|
||||
end = .;
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal SRAM on the AT91SAM7S64.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(entry)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
sram (W!RX) : ORIGIN = 0x202000, LENGTH = 0x4000
|
||||
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x10000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ALIGN(4);
|
||||
.fixed :
|
||||
{
|
||||
_sfixed = .;
|
||||
*(.vectors)
|
||||
*(.ramfunc)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_efixed = .;
|
||||
} >sram
|
||||
|
||||
.relocate : AT (_efixed)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
}
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
_szero = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4);
|
||||
_ezero = .;
|
||||
} >sram
|
||||
|
||||
_sstack = 0x204000;
|
||||
}
|
||||
end = .;
|
||||
|
|
@ -0,0 +1,301 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of AT91SAM7S-EK characteristics, AT91SAM7S-dependant PIOs and
|
||||
/// external components interfacing.
|
||||
///
|
||||
/// !Contents
|
||||
/// This file provide a large number of definitions, which are of three
|
||||
/// different types.
|
||||
///
|
||||
/// PIO definitions are prefixed with #PIN_# or #PINS_#. They are to be used
|
||||
/// with the pio peripheral to configure the pins required by the application.
|
||||
///
|
||||
/// First, additional information about the platform is provided by several
|
||||
/// constants:
|
||||
/// - BOARD_NAME is a string containing the board name
|
||||
/// - The chip family and board (at91sam7s and at91sam7sek) are also
|
||||
/// provided.
|
||||
/// - BOARD_MAINOSC and BOARD_MCK contains the standard frequency for the
|
||||
/// main oscillator and the master clock.
|
||||
///
|
||||
/// Contants prefixed with #BOARD_USB_# give information about the USB device
|
||||
/// peripheral that is provided in the chip.
|
||||
///
|
||||
/// Defines prefixed with #PIN_# contain only one pin (and thus can be safely
|
||||
/// used to initialize a single Pin instance), whereas defines starting with
|
||||
/// #PINS_# contains either a single Pin instance with multiple pins inside it,
|
||||
/// or a list of several Pin instances; they must be used as Pin[] array
|
||||
/// initializer values, otherwise they are not safe.
|
||||
///
|
||||
/// Finally, some information about the flash controller is given by definitions
|
||||
/// prefixed with #BOARD_FLASH_#.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef BOARD_H
|
||||
#define BOARD_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#if defined(at91sam7s32)
|
||||
#include "at91sam7s32/AT91SAM7S32.h"
|
||||
#elif defined(at91sam7s321)
|
||||
#include "at91sam7s321/AT91SAM7S321.h"
|
||||
#elif defined(at91sam7s64)
|
||||
#include "at91sam7s64/AT91SAM7S64.h"
|
||||
#elif defined(at91sam7s128)
|
||||
#include "at91sam7s128/AT91SAM7S128.h"
|
||||
#elif defined(at91sam7s256)
|
||||
#include "at91sam7s256/AT91SAM7S256.h"
|
||||
#elif defined(at91sam7s512)
|
||||
#include "at91sam7s512/AT91SAM7S512.h"
|
||||
#else
|
||||
#error Board does not support the specified chip.
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Board
|
||||
//------------------------------------------------------------------------------
|
||||
/// String containing the name of the board.
|
||||
#define BOARD_NAME "AT91SAM7S-EK"
|
||||
/// Board definition.
|
||||
#define at91sam7sek
|
||||
/// Family definition.
|
||||
#define at91sam7s
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Clocks
|
||||
//------------------------------------------------------------------------------
|
||||
/// Frequency of the board main oscillator, in Hz.
|
||||
#define BOARD_MAINOSC 18432000
|
||||
|
||||
/// Master clock frequency (when using board_lowlevel.c), in Hz.
|
||||
#define BOARD_MCK 48000000
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ADC
|
||||
//------------------------------------------------------------------------------
|
||||
/// ADC clock frequency, at 10-bit resolution (in Hz)
|
||||
#define ADC_MAX_CK_10BIT 5000000
|
||||
/// ADC clock frequency, at 8-bit resolution (in Hz)
|
||||
#define ADC_MAX_CK_8BIT 8000000
|
||||
/// Startup time max, return from Idle mode (in µs)
|
||||
#define ADC_STARTUP_TIME_MAX 20
|
||||
/// Track and hold Acquisition Time min (in ns)
|
||||
#define ADC_TRACK_HOLD_TIME_MIN 600
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// USB
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the chip has a UDP controller.
|
||||
#define BOARD_USB_UDP
|
||||
|
||||
/// Indicates the D+ pull-up is externally controlled.
|
||||
#define BOARD_USB_PULLUP_EXTERNAL
|
||||
|
||||
/// Number of endpoints in the USB controller.
|
||||
#define BOARD_USB_NUMENDPOINTS 4
|
||||
|
||||
/// Returns the maximum packet size of the given endpoint.
|
||||
/// \param i Endpoint number.
|
||||
/// \return Maximum packet size in bytes of endpoint.
|
||||
#define BOARD_USB_ENDPOINTS_MAXPACKETSIZE(i) ((i == 0) ? 8 : 64)
|
||||
|
||||
/// Returns the number of FIFO banks for the given endpoint.
|
||||
/// \param i Endpoint number.
|
||||
/// \return Number of FIFO banks for the endpoint.
|
||||
#define BOARD_USB_ENDPOINTS_BANKS(i) (((i == 0) || (i == 3)) ? 1 : 2)
|
||||
|
||||
/// USB attributes configuration descriptor (bus or self powered, remote wakeup)
|
||||
#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
|
||||
//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
|
||||
//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Pins
|
||||
//------------------------------------------------------------------------------
|
||||
/// DBGU pins definition. Contains DRXD (PA9) and DTXD (PA10).
|
||||
#define PINS_DBGU {0x00000600, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
|
||||
/// LED #0 pin definition (PA0).
|
||||
#define PIN_LED_DS1 {1 << 0, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/// LED #1 pin definition (PA1).
|
||||
#define PIN_LED_DS2 {1 << 1, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/// LED #2 pin definition (PA2).
|
||||
#define PIN_LED_DS3 {1 << 2, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/// LED #3 pin definition (PA3).
|
||||
#define PIN_LED_DS4 {1 << 3, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/// List of the four LED pin definitions (PA0, PA1, PA2 & PA3)
|
||||
#define PINS_LEDS PIN_LED_DS1, PIN_LED_DS2, PIN_LED_DS3, PIN_LED_DS4
|
||||
|
||||
/// Push button #0 definition (PA19).
|
||||
#define PIN_PUSHBUTTON_1 {1 << 19, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_PULLUP}
|
||||
/// Push button #1 definition (PA20).
|
||||
#define PIN_PUSHBUTTON_2 {1 << 20, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_PULLUP}
|
||||
/// Push button #2 definition (PA15).
|
||||
#define PIN_PUSHBUTTON_3 {1 << 15, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_PULLUP}
|
||||
/// Push button #3 definition (PA14).
|
||||
#define PIN_PUSHBUTTON_4 {1 << 14, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_PULLUP}
|
||||
/// List of all push button definitions (PA19, PA20, PA15 & PA14).
|
||||
#define PINS_PUSHBUTTONS PIN_PUSHBUTTON_1, PIN_PUSHBUTTON_2, PIN_PUSHBUTTON_3, PIN_PUSHBUTTON_4
|
||||
/// Push button #1 index.
|
||||
#define PUSHBUTTON_BP1 0
|
||||
/// Push button #2 index.
|
||||
#define PUSHBUTTON_BP2 1
|
||||
/// Push button #1 index.
|
||||
#define PUSHBUTTON_BP3 2
|
||||
/// Push button #2 index.
|
||||
#define PUSHBUTTON_BP4 3
|
||||
/// Simulated joystick LEFT index.
|
||||
#define JOYSTICK_LEFT 0
|
||||
/// Simulated joystick RIGHT index.
|
||||
#define JOYSTICK_RIGHT 1
|
||||
|
||||
/// USART0 TXD pin definition (PA5).
|
||||
#define PIN_USART0_RXD {1 << 5, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// USART0 RXD pin definition (PA6).
|
||||
#define PIN_USART0_TXD {1 << 6, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// USART0 RTS pin definition.
|
||||
#define PIN_USART0_RTS {1 << 7, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// USART0 CTS pin definition.
|
||||
#define PIN_USART0_CTS {1 << 8, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// USART0 SCK pin definition.
|
||||
#define PIN_USART0_SCK {1 << 2, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
|
||||
/// SPI MISO pin definition (PA12).
|
||||
#define PIN_SPI_MISO {1 << 12, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_PULLUP}
|
||||
/// SPI MOSI pin definition (PA13).
|
||||
#define PIN_SPI_MOSI {1 << 13, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// SPI SPCK pin definition (PA14).
|
||||
#define PIN_SPI_SPCK {1 << 14, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// SPI pins definition. Contains MISO, MOSI & SPCK (PA12, PA13 & PA14).
|
||||
#define PINS_SPI PIN_SPI_MISO, PIN_SPI_MOSI, PIN_SPI_SPCK
|
||||
/// SPI chip select 0 pin definition (PA11).
|
||||
#define PIN_SPI_NPCS0 {1 << 11, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// SPI chip select 1
|
||||
#define PIN_SPI_NPCS1 {1 << 31, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// SPI chip select 2
|
||||
#define PIN_SPI_NPCS2 {1 << 10, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
/// SPI chip select 3
|
||||
#define PIN_SPI_NPCS3 {1 << 3, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
|
||||
/// PWMC PWM0 pin definition (PA0).
|
||||
#define PIN_PWMC_PWM0 {1 << 0, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// PWMC PWM0 pin definition (PA1).
|
||||
#define PIN_PWMC_PWM1 {1 << 1, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/// PWMC PWM0 pin definition (PA2).
|
||||
#define PIN_PWMC_PWM2 {1 << 2, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
|
||||
/// PWM pin definition for LED0
|
||||
#define PIN_PWM_LED0 PIN_PWMC_PWM1
|
||||
/// PWM pin definition for LED1
|
||||
#define PIN_PWM_LED1 PIN_PWMC_PWM2
|
||||
/// PWM channel for LED0
|
||||
#define CHANNEL_PWM_LED0 1
|
||||
/// PWM channel for LED1
|
||||
#define CHANNEL_PWM_LED1 2
|
||||
|
||||
/// TWI pins definition. Contains TWD (PA3) and TWCK (PA4).
|
||||
#define PINS_TWI {0x00000018, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
|
||||
/// ADC_AD0 pin definition.
|
||||
#define PIN_ADC_AD0 {1 << 17, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD1 pin definition.
|
||||
#define PIN_ADC_AD1 {1 << 18, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD2 pin definition. (mixed with PIN_PUSHBUTTON_1)
|
||||
#define PIN_ADC_AD2 {1 << 19, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD3 pin definition. (mixed with PIN_PUSHBUTTON_2)
|
||||
#define PIN_ADC_AD3 {1 << 20, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// Pins ADC
|
||||
#define PINS_ADC PIN_ADC_AD0, PIN_ADC_AD1, PIN_ADC_AD2, PIN_ADC_AD3
|
||||
|
||||
/// USB VBus monitoring pin definition (PA13).
|
||||
#define PIN_USB_VBUS {1 << 13, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// USB pull-up control pin definition (PA16).
|
||||
#define PIN_USB_PULLUP {1 << 16, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// !SD Card SPI
|
||||
/// - BOARD_SD_SPI_BASE
|
||||
/// - BOARD_SD_SPI_ID
|
||||
/// - BOARD_SD_SPI_PINS
|
||||
/// - BOARD_SD_NPCS
|
||||
|
||||
/// Not define in our board, but customer can add this feature
|
||||
/// Base address of the SPI peripheral connected to the SD card.
|
||||
#define BOARD_SD_SPI_BASE AT91C_BASE_SPI
|
||||
/// Identifier of the SPI peripheral connected to the SD card.
|
||||
#define BOARD_SD_SPI_ID AT91C_ID_SPI
|
||||
/// List of pins to configure to access the SD card
|
||||
#define BOARD_SD_SPI_PINS PINS_SPI, PIN_SPI_NPCS1
|
||||
/// NPCS number
|
||||
#define BOARD_SD_NPCS 1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Flash
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates chip has an EFC.
|
||||
#define BOARD_FLASH_EFC
|
||||
/// Address of the IAP function in ROM.
|
||||
#define BOARD_FLASH_IAP_ADDRESS 0x300E08
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "SAM7S-EK - External components"
|
||||
/// This page lists the definitions related to external on-board components
|
||||
/// located in the board.h file for the SAM7S-EK.
|
||||
///
|
||||
/// !ISO7816
|
||||
/// - PIN_SMARTCARD_CONNECT
|
||||
/// - PIN_ISO7816_RSTMC
|
||||
/// - PINS_ISO7816
|
||||
|
||||
/// Smartcard detection pin
|
||||
#define PIN_SMARTCARD_CONNECT {1 << 5, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// PIN used for reset the smartcard
|
||||
#define PIN_ISO7816_RSTMC {1 << 7, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
|
||||
/// Pins used for connect the smartcard
|
||||
#define PINS_ISO7816 PIN_USART0_TXD, PIN_USART0_SCK, PIN_ISO7816_RSTMC
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef BOARD_H
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
# ----------------------------------------------------------------------------
|
||||
# ATMEL Microcontroller Software Support
|
||||
# ----------------------------------------------------------------------------
|
||||
# Copyright (c) 2008, Atmel Corporation
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# - Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the disclaimer below.
|
||||
#
|
||||
# Atmel's name may not be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# Defines which are the available memory targets for the AT91SAM7S-EK board.
|
||||
|
||||
MEMORIES = flash sram
|
|
@ -0,0 +1,181 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "board.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define IRQ_STACK_SIZE 8*3*4
|
||||
|
||||
#define ARM_MODE_ABT 0x17
|
||||
#define ARM_MODE_FIQ 0x11
|
||||
#define ARM_MODE_IRQ 0x12
|
||||
#define ARM_MODE_SVC 0x13
|
||||
|
||||
#define I_BIT 0x80
|
||||
#define F_BIT 0x40
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Startup routine
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
.align 4
|
||||
.arm
|
||||
|
||||
/* Exception vectors
|
||||
*******************/
|
||||
.section .vectors, "a"
|
||||
|
||||
resetVector:
|
||||
ldr pc, =resetHandler /* Reset */
|
||||
undefVector:
|
||||
b undefVector /* Undefined instruction */
|
||||
swiVector:
|
||||
b swiVector /* Software interrupt */
|
||||
prefetchAbortVector:
|
||||
b prefetchAbortVector /* Prefetch abort */
|
||||
dataAbortVector:
|
||||
b dataAbortVector /* Data abort */
|
||||
reservedVector:
|
||||
b reservedVector /* Reserved for future use */
|
||||
irqVector:
|
||||
b irqHandler /* Interrupt */
|
||||
fiqVector:
|
||||
/* Fast interrupt */
|
||||
//------------------------------------------------------------------------------
|
||||
/// Handles a fast interrupt request by branching to the address defined in the
|
||||
/// AIC.
|
||||
//------------------------------------------------------------------------------
|
||||
fiqHandler:
|
||||
b fiqHandler
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Handles incoming interrupt requests by branching to the corresponding
|
||||
/// handler, as defined in the AIC. Supports interrupt nesting.
|
||||
//------------------------------------------------------------------------------
|
||||
irqHandler:
|
||||
|
||||
/* Save interrupt context on the stack to allow nesting */
|
||||
sub lr, lr, #4
|
||||
stmfd sp!, {lr}
|
||||
mrs lr, SPSR
|
||||
stmfd sp!, {r0, lr}
|
||||
|
||||
/* Write in the IVR to support Protect Mode */
|
||||
ldr lr, =AT91C_BASE_AIC
|
||||
ldr r0, [r14, #AIC_IVR]
|
||||
str lr, [r14, #AIC_IVR]
|
||||
|
||||
/* Branch to interrupt handler in Supervisor mode */
|
||||
msr CPSR_c, #ARM_MODE_SVC
|
||||
stmfd sp!, {r1-r3, r4, r12, lr}
|
||||
mov lr, pc
|
||||
bx r0
|
||||
ldmia sp!, {r1-r3, r4, r12, lr}
|
||||
msr CPSR_c, #ARM_MODE_IRQ | I_BIT
|
||||
|
||||
/* Acknowledge interrupt */
|
||||
ldr lr, =AT91C_BASE_AIC
|
||||
str lr, [r14, #AIC_EOICR]
|
||||
|
||||
/* Restore interrupt context and branch back to calling code */
|
||||
ldmia sp!, {r0, lr}
|
||||
msr SPSR_cxsf, lr
|
||||
ldmia sp!, {pc}^
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes the chip and branches to the main() function.
|
||||
//------------------------------------------------------------------------------
|
||||
.section .text
|
||||
.global entry
|
||||
|
||||
entry:
|
||||
resetHandler:
|
||||
|
||||
/* Dummy access to the .vectors section so it does not get optimized */
|
||||
ldr r0, =resetVector
|
||||
|
||||
/* Set pc to actual code location (i.e. not in remap zone) */
|
||||
ldr pc, =1f
|
||||
|
||||
/* Perform low-level initialization of the chip using LowLevelInit() */
|
||||
1:
|
||||
ldr r4, =_sstack
|
||||
mov sp, r4
|
||||
ldr r0, =LowLevelInit
|
||||
mov lr, pc
|
||||
bx r0
|
||||
|
||||
/* Initialize the relocate segment */
|
||||
|
||||
ldr r0, =_efixed
|
||||
ldr r1, =_srelocate
|
||||
ldr r2, =_erelocate
|
||||
1:
|
||||
cmp r1, r2
|
||||
ldrcc r3, [r0], #4
|
||||
strcc r3, [r1], #4
|
||||
bcc 1b
|
||||
|
||||
/* Clear the zero segment */
|
||||
ldr r0, =_szero
|
||||
ldr r1, =_ezero
|
||||
mov r2, #0
|
||||
1:
|
||||
cmp r0, r1
|
||||
strcc r2, [r0], #4
|
||||
bcc 1b
|
||||
|
||||
/* Setup stacks
|
||||
**************/
|
||||
/* IRQ mode */
|
||||
msr CPSR_c, #ARM_MODE_IRQ | I_BIT | F_BIT
|
||||
mov sp, r4
|
||||
sub r4, r4, #IRQ_STACK_SIZE
|
||||
|
||||
/* Supervisor mode (interrupts enabled) */
|
||||
msr CPSR_c, #ARM_MODE_SVC | F_BIT
|
||||
mov sp, r4
|
||||
|
||||
/* Branch to main()
|
||||
******************/
|
||||
ldr r0, =main
|
||||
mov lr, pc
|
||||
bx r0
|
||||
|
||||
/* Loop indefinitely when program is finished */
|
||||
1:
|
||||
b 1b
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "board.h"
|
||||
#include "board_memories.h"
|
||||
#include <pmc/pmc.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal definitions
|
||||
//------------------------------------------------------------------------------
|
||||
// Startup time of main oscillator (in number of slow clock ticks).
|
||||
#define BOARD_OSCOUNT (AT91C_CKGR_OSCOUNT & (0x40 << 8))
|
||||
|
||||
// USB PLL divisor value to obtain a 48MHz clock.
|
||||
#define BOARD_USBDIV AT91C_CKGR_USBDIV_1
|
||||
|
||||
// PLL frequency range.
|
||||
#define BOARD_CKGR_PLL AT91C_CKGR_OUT_0
|
||||
|
||||
// PLL startup time (in number of slow clock ticks).
|
||||
#define BOARD_PLLCOUNT (16 << 8)
|
||||
|
||||
// PLL MUL value.
|
||||
#define BOARD_MUL (AT91C_CKGR_MUL & (72 << 16))
|
||||
|
||||
// PLL DIV value.
|
||||
#define BOARD_DIV (AT91C_CKGR_DIV & 14)
|
||||
|
||||
// Master clock prescaler value.
|
||||
#define BOARD_PRESCALER AT91C_PMC_PRES_CLK_2
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Default spurious interrupt handler. Infinite loop.
|
||||
//------------------------------------------------------------------------------
|
||||
void defaultSpuriousHandler( void )
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Default handler for fast interrupt requests. Infinite loop.
|
||||
//------------------------------------------------------------------------------
|
||||
void defaultFiqHandler( void )
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Default handler for standard interrupt requests. Infinite loop.
|
||||
//------------------------------------------------------------------------------
|
||||
void defaultIrqHandler( void )
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Performs the low-level initialization of the chip. This includes EFC, master
|
||||
/// clock, AIC & watchdog configuration, as well as memory remapping.
|
||||
//------------------------------------------------------------------------------
|
||||
void LowLevelInit(void)
|
||||
{
|
||||
unsigned char i;
|
||||
|
||||
// Set flash wait states in the EFC
|
||||
// 48MHz = 1 wait state
|
||||
#if defined(at91sam7s512)
|
||||
AT91C_BASE_EFC0->EFC_FMR = AT91C_MC_FWS_1FWS;
|
||||
AT91C_BASE_EFC1->EFC_FMR = AT91C_MC_FWS_1FWS;
|
||||
#else
|
||||
AT91C_BASE_MC->MC_FMR = AT91C_MC_FWS_1FWS;
|
||||
#endif
|
||||
|
||||
// Initialize main oscillator
|
||||
AT91C_BASE_PMC->PMC_MOR = BOARD_OSCOUNT | AT91C_CKGR_MOSCEN;
|
||||
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
|
||||
|
||||
// Initialize PLL at 96MHz (96.109) and USB clock to 48MHz
|
||||
AT91C_BASE_PMC->PMC_PLLR = BOARD_USBDIV | BOARD_CKGR_PLL | BOARD_PLLCOUNT
|
||||
| BOARD_MUL | BOARD_DIV;
|
||||
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK));
|
||||
|
||||
// Wait for the master clock if it was already initialized
|
||||
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
|
||||
|
||||
// Switch to slow clock + prescaler
|
||||
AT91C_BASE_PMC->PMC_MCKR = BOARD_PRESCALER;
|
||||
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
|
||||
|
||||
// Switch to fast clock + prescaler
|
||||
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
|
||||
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
|
||||
|
||||
// Initialize AIC
|
||||
AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;
|
||||
AT91C_BASE_AIC->AIC_SVR[0] = (unsigned int) defaultFiqHandler;
|
||||
for (i = 1; i < 31; i++) {
|
||||
|
||||
AT91C_BASE_AIC->AIC_SVR[i] = (unsigned int) defaultIrqHandler;
|
||||
}
|
||||
AT91C_BASE_AIC->AIC_SPU = (unsigned int) defaultSpuriousHandler;
|
||||
|
||||
// Unstack nested interrupts
|
||||
for (i = 0; i < 8 ; i++) {
|
||||
|
||||
AT91C_BASE_AIC->AIC_EOICR = 0;
|
||||
}
|
||||
|
||||
// Enable Debug mode
|
||||
AT91C_BASE_AIC->AIC_DCR = AT91C_AIC_DCR_PROT;
|
||||
|
||||
// Watchdog initialization
|
||||
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
|
||||
|
||||
// Remap the internal SRAM at 0x0
|
||||
BOARD_RemapRam();
|
||||
|
||||
// Disable RTT and PIT interrupts (potential problem when program A
|
||||
// configures RTT, then program B wants to use PIT only, interrupts
|
||||
// from the RTT will still occur since they both use AT91C_ID_SYS)
|
||||
AT91C_BASE_RTTC->RTTC_RTMR &= ~(AT91C_RTTC_ALMIEN | AT91C_RTTC_RTTINCIEN);
|
||||
AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "board_memories.h"
|
||||
#include "board.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// \internal Flash is mirrored in the remap zone.
|
||||
#define BOARD_FLASH 0
|
||||
|
||||
/// \internal RAM is mirrored in the remap zone.
|
||||
#define BOARD_RAM 1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal function
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the current remap, either BOARD_FLASH or BOARD_RAM.
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned char BOARD_GetRemap( void )
|
||||
{
|
||||
unsigned int *remap = (unsigned int *) 0;
|
||||
unsigned int *ram = (unsigned int *) AT91C_ISRAM;
|
||||
|
||||
// Try to write in 0 and see if this affects the RAM
|
||||
unsigned int temp = *ram;
|
||||
*ram = temp + 1;
|
||||
if (*remap == *ram) {
|
||||
|
||||
*ram = temp;
|
||||
return BOARD_RAM;
|
||||
}
|
||||
else {
|
||||
|
||||
*ram = temp;
|
||||
return BOARD_FLASH;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Changes the mapping of the chip so that the remap area mirrors the
|
||||
/// internal flash.
|
||||
//------------------------------------------------------------------------------
|
||||
void BOARD_RemapFlash( void )
|
||||
{
|
||||
if (BOARD_GetRemap() != BOARD_FLASH) {
|
||||
|
||||
AT91C_BASE_MC->MC_RCR = AT91C_MC_RCB;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Changes the mapping of the chip so that the remap area mirrors the
|
||||
/// internal RAM.
|
||||
//------------------------------------------------------------------------------
|
||||
void BOARD_RemapRam( void )
|
||||
{
|
||||
if (BOARD_GetRemap() != BOARD_RAM) {
|
||||
|
||||
AT91C_BASE_MC->MC_RCR = AT91C_MC_RCB;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Methods for remapping AT91SAM7S chips internal memory.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Remap the Flash at address 0 using BOARD_RemapFlash.
|
||||
/// -# Remap the internal RAM at address 0 using BOARD_RemapRam.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef BOARD_MEMORIES_H
|
||||
#define BOARD_MEMORIES_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void BOARD_RemapFlash( void );
|
||||
extern void BOARD_RemapRam( void );
|
||||
|
||||
#endif //#ifndef BOARD_MEMORIES_H
|
||||
|
|
@ -0,0 +1,620 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// ISO 7816 driver
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// Explanation on the usage of the code made available through the header file.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <board.h>
|
||||
#include <usart/usart.h>
|
||||
#include <utility/trace.h>
|
||||
#include <pio/pio.h>
|
||||
#include "iso7816_4.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
/// Case for APDU commands
|
||||
#define CASE1 1
|
||||
#define CASE2 2
|
||||
#define CASE3 3
|
||||
|
||||
/// Flip flop for send and receive char
|
||||
#define USART_SEND 0
|
||||
#define USART_RCV 1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//------------------------------------------------------------------------------
|
||||
/// Variable for state of send and receive froom USART
|
||||
static unsigned char StateUsartGlobal = USART_RCV;
|
||||
/// Pin reset master card
|
||||
static Pin st_pinIso7816RstMC;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Get a character from ISO7816
|
||||
/// \param pCharToReceive Pointer for store the received char
|
||||
/// \return 0: if timeout else status of US_CSR
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned int ISO7816_GetChar( unsigned char *pCharToReceive )
|
||||
{
|
||||
unsigned int status;
|
||||
unsigned int timeout=0;
|
||||
|
||||
if( StateUsartGlobal == USART_SEND ) {
|
||||
while((AT91C_BASE_US0->US_CSR & AT91C_US_TXEMPTY) == 0) {}
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA | AT91C_US_RSTIT | AT91C_US_RSTNACK;
|
||||
StateUsartGlobal = USART_RCV;
|
||||
}
|
||||
|
||||
// Wait USART ready for reception
|
||||
while( ((AT91C_BASE_US0->US_CSR & AT91C_US_RXRDY) == 0) ) {
|
||||
if(timeout++ >6000) {
|
||||
TRACE_DEBUG("TimeOut\n\r");
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
TRACE_DEBUG("T: %d\n\r", timeout);
|
||||
|
||||
|
||||
// At least one complete character has been received and US_RHR has not yet been read.
|
||||
|
||||
// Get a char
|
||||
*pCharToReceive = ((AT91C_BASE_US0->US_RHR) & 0xFF);
|
||||
|
||||
status = (AT91C_BASE_US0->US_CSR&(AT91C_US_OVRE|AT91C_US_FRAME|
|
||||
AT91C_US_PARE|AT91C_US_TIMEOUT|AT91C_US_NACK|
|
||||
(1<<10)));
|
||||
|
||||
if (status != 0 ) {
|
||||
// TRACE_DEBUG("R:0x%X\n\r", status);
|
||||
TRACE_DEBUG("R:0x%X\n\r", AT91C_BASE_US0->US_CSR);
|
||||
TRACE_DEBUG("Nb:0x%X\n\r", AT91C_BASE_US0->US_NER );
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA;
|
||||
}
|
||||
|
||||
// Return status
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Send a char to ISO7816
|
||||
/// \param CharToSend char to be send
|
||||
/// \return status of US_CSR
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned int ISO7816_SendChar( unsigned char CharToSend )
|
||||
{
|
||||
unsigned int status;
|
||||
|
||||
if( StateUsartGlobal == USART_RCV ) {
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA | AT91C_US_RSTIT | AT91C_US_RSTNACK;
|
||||
StateUsartGlobal = USART_SEND;
|
||||
}
|
||||
|
||||
// Wait USART ready for transmit
|
||||
while((AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) == 0) {}
|
||||
// There is no character in the US_THR
|
||||
|
||||
// Transmit a char
|
||||
AT91C_BASE_US0->US_THR = CharToSend;
|
||||
|
||||
status = (AT91C_BASE_US0->US_CSR&(AT91C_US_OVRE|AT91C_US_FRAME|
|
||||
AT91C_US_PARE|AT91C_US_TIMEOUT|AT91C_US_NACK|
|
||||
(1<<10)));
|
||||
|
||||
if (status != 0 ) {
|
||||
TRACE_DEBUG("E:0x%X\n\r", AT91C_BASE_US0->US_CSR);
|
||||
TRACE_DEBUG("Nb:0x%X\n\r", AT91C_BASE_US0->US_NER );
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA;
|
||||
}
|
||||
|
||||
// Return status
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Iso 7816 ICC power on
|
||||
//------------------------------------------------------------------------------
|
||||
static void ISO7816_IccPowerOn( void )
|
||||
{
|
||||
// Set RESET Master Card
|
||||
PIO_Set(&st_pinIso7816RstMC);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Iso 7816 ICC power off
|
||||
//------------------------------------------------------------------------------
|
||||
void ISO7816_IccPowerOff( void )
|
||||
{
|
||||
// Clear RESET Master Card
|
||||
PIO_Clear(&st_pinIso7816RstMC);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Transfert Block TPDU T=0
|
||||
/// \param pAPDU APDU buffer
|
||||
/// \param pMessage Message buffer
|
||||
/// \param wLength Block length
|
||||
/// \return Message index
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short ISO7816_XfrBlockTPDU_T0(const unsigned char *pAPDU,
|
||||
unsigned char *pMessage,
|
||||
unsigned short wLength )
|
||||
{
|
||||
unsigned short NeNc;
|
||||
unsigned short indexApdu = 4;
|
||||
unsigned short indexMessage = 0;
|
||||
unsigned char SW1 = 0;
|
||||
unsigned char procByte;
|
||||
unsigned char cmdCase;
|
||||
|
||||
TRACE_DEBUG("pAPDU[0]=0x%X\n\r",pAPDU[0]);
|
||||
TRACE_DEBUG("pAPDU[1]=0x%X\n\r",pAPDU[1]);
|
||||
TRACE_DEBUG("pAPDU[2]=0x%X\n\r",pAPDU[2]);
|
||||
TRACE_DEBUG("pAPDU[3]=0x%X\n\r",pAPDU[3]);
|
||||
TRACE_DEBUG("pAPDU[4]=0x%X\n\r",pAPDU[4]);
|
||||
TRACE_DEBUG("pAPDU[5]=0x%X\n\r",pAPDU[5]);
|
||||
TRACE_DEBUG("wlength=%d\n\r",wLength);
|
||||
|
||||
ISO7816_SendChar( pAPDU[0] ); // CLA
|
||||
ISO7816_SendChar( pAPDU[1] ); // INS
|
||||
ISO7816_SendChar( pAPDU[2] ); // P1
|
||||
ISO7816_SendChar( pAPDU[3] ); // P2
|
||||
ISO7816_SendChar( pAPDU[4] ); // P3
|
||||
|
||||
// Handle the four structures of command APDU
|
||||
indexApdu = 4;
|
||||
|
||||
if( wLength == 4 ) {
|
||||
cmdCase = CASE1;
|
||||
NeNc = 0;
|
||||
}
|
||||
else if( wLength == 5) {
|
||||
cmdCase = CASE2;
|
||||
NeNc = pAPDU[4]; // C5
|
||||
if (NeNc == 0) {
|
||||
NeNc = 256;
|
||||
}
|
||||
}
|
||||
else if( wLength == 6) {
|
||||
NeNc = pAPDU[4]; // C5
|
||||
cmdCase = CASE3;
|
||||
}
|
||||
else if( wLength == 7) {
|
||||
NeNc = pAPDU[4]; // C5
|
||||
if( NeNc == 0 ) {
|
||||
cmdCase = CASE2;
|
||||
NeNc = (pAPDU[5]<<8)+pAPDU[6];
|
||||
}
|
||||
else {
|
||||
cmdCase = CASE3;
|
||||
}
|
||||
}
|
||||
else {
|
||||
NeNc = pAPDU[4]; // C5
|
||||
if( NeNc == 0 ) {
|
||||
cmdCase = CASE3;
|
||||
NeNc = (pAPDU[5]<<8)+pAPDU[6];
|
||||
}
|
||||
else {
|
||||
cmdCase = CASE3;
|
||||
}
|
||||
}
|
||||
|
||||
TRACE_DEBUG("CASE=0x%X NeNc=0x%X\n\r", cmdCase, NeNc);
|
||||
|
||||
// Handle Procedure Bytes
|
||||
do {
|
||||
ISO7816_GetChar(&procByte);
|
||||
// Handle NULL
|
||||
if ( procByte == ISO_NULL_VAL ) {
|
||||
TRACE_DEBUG("INS\n\r");
|
||||
continue;
|
||||
}
|
||||
// Handle SW1
|
||||
else if ( ((procByte & 0xF0) ==0x60) || ((procByte & 0xF0) ==0x90) ) {
|
||||
TRACE_DEBUG("SW1\n\r");
|
||||
SW1 = 1;
|
||||
}
|
||||
// Handle INS
|
||||
else if ( pAPDU[1] == procByte) {
|
||||
TRACE_DEBUG("HdlINS\n\r");
|
||||
if (cmdCase == CASE2) {
|
||||
// receive data from card
|
||||
do {
|
||||
ISO7816_GetChar(&pMessage[indexMessage++]);
|
||||
} while( 0 != --NeNc );
|
||||
}
|
||||
else {
|
||||
// Send data
|
||||
do {
|
||||
ISO7816_SendChar(pAPDU[indexApdu++]);
|
||||
} while( 0 != --NeNc );
|
||||
}
|
||||
}
|
||||
// Handle INS ^ 0xff
|
||||
else if ( pAPDU[1] == (procByte ^ 0xff)) {
|
||||
TRACE_DEBUG("HdlINS+\n\r");
|
||||
if (cmdCase == CASE2) {
|
||||
// receive data from card
|
||||
ISO7816_GetChar(&pMessage[indexMessage++]);
|
||||
}
|
||||
else {
|
||||
ISO7816_SendChar(pAPDU[indexApdu++]);
|
||||
}
|
||||
NeNc--;
|
||||
}
|
||||
else {
|
||||
// ??
|
||||
TRACE_DEBUG("procByte=0x%X\n\r", procByte);
|
||||
break;
|
||||
}
|
||||
} while (NeNc != 0);
|
||||
|
||||
// Status Bytes
|
||||
if (SW1 == 0) {
|
||||
ISO7816_GetChar(&pMessage[indexMessage++]); // SW1
|
||||
}
|
||||
else {
|
||||
pMessage[indexMessage++] = procByte;
|
||||
}
|
||||
ISO7816_GetChar(&pMessage[indexMessage++]); // SW2
|
||||
|
||||
return( indexMessage );
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Escape ISO7816
|
||||
//------------------------------------------------------------------------------
|
||||
void ISO7816_Escape( void )
|
||||
{
|
||||
TRACE_DEBUG("For user, if needed\n\r");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Restart clock ISO7816
|
||||
//------------------------------------------------------------------------------
|
||||
void ISO7816_RestartClock( void )
|
||||
{
|
||||
TRACE_DEBUG("ISO7816_RestartClock\n\r");
|
||||
AT91C_BASE_US0->US_BRGR = 13;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Stop clock ISO7816
|
||||
//------------------------------------------------------------------------------
|
||||
void ISO7816_StopClock( void )
|
||||
{
|
||||
TRACE_DEBUG("ISO7816_StopClock\n\r");
|
||||
AT91C_BASE_US0->US_BRGR = 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// T0 APDU
|
||||
//------------------------------------------------------------------------------
|
||||
void ISO7816_toAPDU( void )
|
||||
{
|
||||
TRACE_DEBUG("ISO7816_toAPDU\n\r");
|
||||
TRACE_DEBUG("Not supported at this time\n\r");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
/// Answer To Reset (ATR)
|
||||
/// \param pAtr ATR buffer
|
||||
/// \param pLength Pointer for store the ATR length
|
||||
//----------------------------------------------------------------------
|
||||
void ISO7816_Datablock_ATR( unsigned char* pAtr, unsigned char* pLength )
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int y;
|
||||
|
||||
*pLength = 0;
|
||||
|
||||
// Read ATR TS
|
||||
ISO7816_GetChar(&pAtr[0]);
|
||||
// Read ATR T0
|
||||
ISO7816_GetChar(&pAtr[1]);
|
||||
y = pAtr[1] & 0xF0;
|
||||
i = 2;
|
||||
|
||||
// Read ATR Ti
|
||||
while (y) {
|
||||
|
||||
if (y & 0x10) { // TA[i]
|
||||
ISO7816_GetChar(&pAtr[i++]);
|
||||
}
|
||||
if (y & 0x20) { // TB[i]
|
||||
ISO7816_GetChar(&pAtr[i++]);
|
||||
}
|
||||
if (y & 0x40) { // TC[i]
|
||||
ISO7816_GetChar(&pAtr[i++]);
|
||||
}
|
||||
if (y & 0x80) { // TD[i]
|
||||
ISO7816_GetChar(&pAtr[i]);
|
||||
y = pAtr[i++] & 0xF0;
|
||||
}
|
||||
else {
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Historical Bytes
|
||||
y = pAtr[1] & 0x0F;
|
||||
for( j=0; j < y; j++ ) {
|
||||
ISO7816_GetChar(&pAtr[i++]);
|
||||
}
|
||||
|
||||
TRACE_DEBUG_WP("Length = %d", i);
|
||||
TRACE_DEBUG_WP("ATR = ");
|
||||
|
||||
for (j=0; j < i; j++) {
|
||||
TRACE_DEBUG_WP("%02x ", pAtr[j]);
|
||||
}
|
||||
|
||||
|
||||
TRACE_DEBUG_WP("\n\r");
|
||||
|
||||
*pLength = i;
|
||||
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
/// Set data rate and clock frequency
|
||||
/// \param dwClockFrequency ICC clock frequency in KHz.
|
||||
/// \param dwDataRate ICC data rate in bpd
|
||||
//----------------------------------------------------------------------
|
||||
void ISO7816_SetDataRateandClockFrequency( unsigned int dwClockFrequency, unsigned int dwDataRate )
|
||||
{
|
||||
unsigned char ClockFrequency;
|
||||
|
||||
// Define the baud rate divisor register
|
||||
// CD = MCK / SCK
|
||||
// SCK = FIDI x BAUD = 372 x 9600
|
||||
// BOARD_MCK
|
||||
// CD = MCK/(FIDI x BAUD) = 48000000 / (372x9600) = 13
|
||||
AT91C_BASE_US0->US_BRGR = BOARD_MCK / (dwClockFrequency*1000);
|
||||
|
||||
ClockFrequency = BOARD_MCK / AT91C_BASE_US0->US_BRGR;
|
||||
|
||||
AT91C_BASE_US0->US_FIDI = (ClockFrequency)/dwDataRate;
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Pin status for ISO7816 RESET
|
||||
/// \return 1 if the Pin RstMC is high; otherwise 0.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char ISO7816_StatusReset( void )
|
||||
{
|
||||
return PIO_Get(&st_pinIso7816RstMC);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// cold reset
|
||||
//------------------------------------------------------------------------------
|
||||
void ISO7816_cold_reset( void )
|
||||
{
|
||||
volatile unsigned int i;
|
||||
|
||||
// tb: wait 400 cycles, 3.58MHz => 80µs 48000000Hz (3840)
|
||||
for( i=0; i<(120*(BOARD_MCK/1000000)); i++ ) {
|
||||
}
|
||||
|
||||
AT91C_BASE_US0->US_RHR;
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA | AT91C_US_RSTIT | AT91C_US_RSTNACK;
|
||||
|
||||
ISO7816_IccPowerOn();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Warm reset
|
||||
//------------------------------------------------------------------------------
|
||||
void ISO7816_warm_reset( void )
|
||||
{
|
||||
volatile unsigned int i;
|
||||
|
||||
ISO7816_IccPowerOff();
|
||||
|
||||
// tb: wait 400 cycles, 3.58MHz => 80µs 48000000Hz (3840)
|
||||
for( i=0; i<(120*(BOARD_MCK/1000000)); i++ ) {
|
||||
}
|
||||
|
||||
AT91C_BASE_US0->US_RHR;
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA | AT91C_US_RSTIT | AT91C_US_RSTNACK;
|
||||
|
||||
ISO7816_IccPowerOn();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
/// Decode ATR trace
|
||||
/// \param pAtr pointer on ATR buffer
|
||||
//----------------------------------------------------------------------
|
||||
void ISO7816_Decode_ATR( unsigned char* pAtr )
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int y;
|
||||
unsigned char offset;
|
||||
|
||||
TRACE_INFO_WP("ATR: Answer To Reset:\n\r");
|
||||
TRACE_INFO_WP("TS = 0x%X Initial caracter ",pAtr[0]);
|
||||
if( pAtr[0] == 0x3B ) {
|
||||
|
||||
TRACE_INFO_WP("Direct Convention\n\r");
|
||||
}
|
||||
else {
|
||||
if( pAtr[0] == 0x3F ) {
|
||||
|
||||
TRACE_INFO_WP("Inverse Convention\n\r");
|
||||
}
|
||||
else {
|
||||
TRACE_INFO_WP("BAD Convention\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
TRACE_INFO_WP("T0 = 0x%X Format caracter\n\r",pAtr[1]);
|
||||
TRACE_INFO_WP(" Number of historical bytes: K = %d\n\r", pAtr[1]&0x0F);
|
||||
TRACE_INFO_WP(" Presence further interface byte:\n\r");
|
||||
if( pAtr[1]&0x80 ) {
|
||||
TRACE_INFO_WP("TA ");
|
||||
}
|
||||
if( pAtr[1]&0x40 ) {
|
||||
TRACE_INFO_WP("TB ");
|
||||
}
|
||||
if( pAtr[1]&0x20 ) {
|
||||
TRACE_INFO_WP("TC ");
|
||||
}
|
||||
if( pAtr[1]&0x10 ) {
|
||||
TRACE_INFO_WP("TD ");
|
||||
}
|
||||
if( pAtr[1] != 0 ) {
|
||||
TRACE_INFO_WP(" present\n\r");
|
||||
}
|
||||
|
||||
i = 2;
|
||||
y = pAtr[1] & 0xF0;
|
||||
|
||||
// Read ATR Ti
|
||||
offset = 1;
|
||||
while (y) {
|
||||
|
||||
if (y & 0x10) { // TA[i]
|
||||
TRACE_INFO_WP("TA[%d] = 0x%X ", offset, pAtr[i]);
|
||||
if( offset == 1 ) {
|
||||
TRACE_INFO_WP("FI = %d ", (pAtr[i]>>8));
|
||||
TRACE_INFO_WP("DI = %d", (pAtr[i]&0x0F));
|
||||
}
|
||||
TRACE_INFO_WP("\n\r");
|
||||
i++;
|
||||
}
|
||||
if (y & 0x20) { // TB[i]
|
||||
TRACE_INFO_WP("TB[%d] = 0x%X\n\r", offset, pAtr[i]);
|
||||
i++;
|
||||
}
|
||||
if (y & 0x40) { // TC[i]
|
||||
TRACE_INFO_WP("TC[%d] = 0x%X ", offset, pAtr[i]);
|
||||
if( offset == 1 ) {
|
||||
TRACE_INFO_WP("Extra Guard Time: N = %d", pAtr[i]);
|
||||
}
|
||||
TRACE_INFO_WP("\n\r");
|
||||
i++;
|
||||
}
|
||||
if (y & 0x80) { // TD[i]
|
||||
TRACE_INFO_WP("TD[%d] = 0x%X\n\r", offset, pAtr[i]);
|
||||
y = pAtr[i++] & 0xF0;
|
||||
}
|
||||
else {
|
||||
y = 0;
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
|
||||
// Historical Bytes
|
||||
TRACE_INFO_WP("Historical bytes:\n\r");
|
||||
y = pAtr[1] & 0x0F;
|
||||
for( j=0; j < y; j++ ) {
|
||||
|
||||
TRACE_INFO_WP(" 0x%X", pAtr[i]);
|
||||
if( (pAtr[i] > 0x21) && (pAtr[i] < 0x7D) ) { // ASCII
|
||||
TRACE_INFO_WP("(%c) ", pAtr[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
TRACE_INFO_WP("\n\r");
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Initializes a ISO driver
|
||||
/// \param pPinIso7816RstMC Pin ISO 7816 Rst MC
|
||||
//------------------------------------------------------------------------------
|
||||
void ISO7816_Init( const Pin pPinIso7816RstMC )
|
||||
{
|
||||
TRACE_DEBUG("ISO_Init\n\r");
|
||||
|
||||
// Pin ISO7816 initialize
|
||||
st_pinIso7816RstMC = pPinIso7816RstMC;
|
||||
|
||||
USART_Configure( AT91C_BASE_US0,
|
||||
AT91C_US_USMODE_ISO7816_0
|
||||
| AT91C_US_CLKS_CLOCK
|
||||
| AT91C_US_NBSTOP_1_BIT
|
||||
| AT91C_US_PAR_EVEN
|
||||
| AT91C_US_CHRL_8_BITS
|
||||
| AT91C_US_CKLO
|
||||
| (3<<24), // MAX_ITERATION
|
||||
1,
|
||||
0);
|
||||
|
||||
// Configure USART0
|
||||
AT91C_BASE_PMC->PMC_PCER = ((unsigned int) 1 << AT91C_ID_US0);
|
||||
// Disable interrupts
|
||||
AT91C_BASE_US0->US_IDR = (unsigned int) -1;
|
||||
|
||||
AT91C_BASE_US0->US_FIDI = 372; // by default
|
||||
// Define the baud rate divisor register
|
||||
// CD = MCK / SCK
|
||||
// SCK = FIDI x BAUD = 372 x 9600
|
||||
// BOARD_MCK
|
||||
// CD = MCK/(FIDI x BAUD) = 48000000 / (372x9600) = 13
|
||||
AT91C_BASE_US0->US_BRGR = BOARD_MCK / (372*9600);
|
||||
|
||||
// Write the Timeguard Register
|
||||
AT91C_BASE_US0->US_TTGR = 5;
|
||||
|
||||
USART_SetTransmitterEnabled(AT91C_BASE_US0, 1);
|
||||
USART_SetReceiverEnabled(AT91C_BASE_US0, 1);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of methods for ISO7816 driver.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# ISO7816_Init
|
||||
/// -# ISO7816_IccPowerOff
|
||||
/// -# ISO7816_XfrBlockTPDU_T0
|
||||
/// -# ISO7816_Escape
|
||||
/// -# ISO7816_RestartClock
|
||||
/// -# ISO7816_StopClock
|
||||
/// -# ISO7816_toAPDU
|
||||
/// -# ISO7816_Datablock_ATR
|
||||
/// -# ISO7816_SetDataRateandClockFrequency
|
||||
/// -# ISO7816_StatusReset
|
||||
/// -# ISO7816_cold_reset
|
||||
/// -# ISO7816_warm_reset
|
||||
/// -# ISO7816_Decode_ATR
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef ISO7816_4_H
|
||||
#define ISO7816_4_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Size max of Answer To Reset
|
||||
#define ATR_SIZE_MAX 55
|
||||
|
||||
/// NULL byte to restart byte procedure
|
||||
#define ISO_NULL_VAL 0x60
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
extern void ISO7816_Init( const Pin pPinIso7816RstMC );
|
||||
extern void ISO7816_IccPowerOff(void);
|
||||
extern unsigned short ISO7816_XfrBlockTPDU_T0(const unsigned char *pAPDU,
|
||||
unsigned char *pMessage,
|
||||
unsigned short wLength );
|
||||
extern void ISO7816_Escape( void );
|
||||
extern void ISO7816_RestartClock(void);
|
||||
extern void ISO7816_StopClock( void );
|
||||
extern void ISO7816_toAPDU( void );
|
||||
extern void ISO7816_Datablock_ATR( unsigned char* pAtr, unsigned char* pLength );
|
||||
extern void ISO7816_SetDataRateandClockFrequency( unsigned int dwClockFrequency, unsigned int dwDataRate );
|
||||
extern unsigned char ISO7816_StatusReset( void );
|
||||
extern void ISO7816_cold_reset( void );
|
||||
extern void ISO7816_warm_reset( void );
|
||||
extern void ISO7816_Decode_ATR( unsigned char* pAtr );
|
||||
|
||||
#endif // ISO7816_4_H
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "aic.h"
|
||||
#include <board.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures an interrupt in the AIC. The interrupt is identified by its
|
||||
/// source (AT91C_ID_xxx) and is configured to use the specified mode and
|
||||
/// interrupt handler function. Mode is the value that will be put in AIC_SMRx
|
||||
/// and the function address will be set in AIC_SVRx.
|
||||
/// The interrupt is disabled before configuration, so it is useless
|
||||
/// to do it before calling this function. When AIC_ConfigureIT returns, the
|
||||
/// interrupt will always be disabled and cleared; it must be enabled by a
|
||||
/// call to AIC_EnableIT().
|
||||
/// \param source Interrupt source to configure.
|
||||
/// \param mode Triggering mode and priority of the interrupt.
|
||||
/// \param handler Interrupt handler function.
|
||||
//------------------------------------------------------------------------------
|
||||
void AIC_ConfigureIT(
|
||||
unsigned int source,
|
||||
unsigned int mode,
|
||||
void (*handler)(void))
|
||||
{
|
||||
// Disable the interrupt first
|
||||
AT91C_BASE_AIC->AIC_IDCR = 1 << source;
|
||||
|
||||
// Configure mode and handler
|
||||
AT91C_BASE_AIC->AIC_SMR[source] = mode;
|
||||
AT91C_BASE_AIC->AIC_SVR[source] = (unsigned int) handler;
|
||||
|
||||
// Clear interrupt
|
||||
AT91C_BASE_AIC->AIC_ICCR = 1 << source;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enables interrupts coming from the given (unique) source (AT91C_ID_xxx).
|
||||
/// \param source Interrupt source to enable.
|
||||
//------------------------------------------------------------------------------
|
||||
void AIC_EnableIT(unsigned int source)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IECR = 1 << source;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disables interrupts coming from the given (unique) source (AT91C_ID_xxx).
|
||||
/// \param source Interrupt source to enable.
|
||||
//------------------------------------------------------------------------------
|
||||
void AIC_DisableIT(unsigned int source)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IDCR = 1 << source;
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Methods and definitions for configuring interrupts using the Advanced
|
||||
/// Interrupt Controller (AIC).
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Configure an interrupt source using AIC_ConfigureIT
|
||||
/// -# Enable or disable interrupt generation of a particular source with
|
||||
/// AIC_EnableIT and AIC_DisableIT.
|
||||
///
|
||||
/// \note Most of the time, peripheral interrupts must be also configured
|
||||
/// inside the peripheral itself.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef AIC_H
|
||||
#define AIC_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <board.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL
|
||||
/// Interrupt is internal and uses a logical 1 level.
|
||||
#define AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void AIC_ConfigureIT(unsigned int source,
|
||||
unsigned int mode,
|
||||
void (*handler)( void ));
|
||||
|
||||
extern void AIC_EnableIT(unsigned int source);
|
||||
|
||||
extern void AIC_DisableIT(unsigned int source);
|
||||
|
||||
#endif //#ifndef AIC_H
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <board.h>
|
||||
|
||||
#ifdef CP15_PRESENT
|
||||
|
||||
#include <utility/trace.h>
|
||||
#include "cp15.h"
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
#include <intrinsics.h>
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Macros
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Defines
|
||||
//-----------------------------------------------------------------------------
|
||||
/*
|
||||
#define CP15_RR_BIT 14 // RR bit Replacement strategy for ICache and DCache:
|
||||
// 0 = Random replacement
|
||||
// 1 = Round-robin replacement.
|
||||
|
||||
#define CP15_V_BIT 13 // V bit Location of exception vectors:
|
||||
// 0 = Normal exception vectors selected address range = 0x0000 0000 to 0x0000 001C
|
||||
// 1 = High exception vect selected, address range = 0xFFFF 0000 to 0xFFFF 001C
|
||||
*/
|
||||
#define CP15_I_BIT 12 // I bit ICache enable/disable:
|
||||
// 0 = ICache disabled
|
||||
// 1 = ICache enabled
|
||||
/*
|
||||
#define CP15_R_BIT 9 // R bit ROM protection
|
||||
|
||||
#define CP15_S_BIT 8 // S bit System protection
|
||||
|
||||
#define CP15_B_BIT 7 // B bit Endianness:
|
||||
// 0 = Little-endian operation
|
||||
// 1 = Big-endian operation.
|
||||
*/
|
||||
#define CP15_C_BIT 2 // C bit DCache enable/disable:
|
||||
// 0 = Cache disabled
|
||||
// 1 = Cache enabled
|
||||
/*
|
||||
#define CP15_A_BIT 1 // A bit Alignment fault enable/disable:
|
||||
// 0 = Data address alignment fault checking disabled
|
||||
// 1 = Data address alignment fault checking enabled
|
||||
*/
|
||||
#define CP15_M_BIT 0 // M bit MMU enable/disable: 0 = disabled 1 = enabled.
|
||||
// 0 = disabled
|
||||
// 1 = enabled
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Check Instruction Cache
|
||||
/// \return 0 if I_Cache disable, 1 if I_Cache enable
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int CP15_Is_I_CacheEnabled(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
return ((control & (1 << CP15_I_BIT)) != 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enable Instruction Cache
|
||||
//------------------------------------------------------------------------------
|
||||
void CP15_Enable_I_Cache(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
|
||||
// Check if cache is disabled
|
||||
if ((control & (1 << CP15_I_BIT)) == 0) {
|
||||
|
||||
control |= (1 << CP15_I_BIT);
|
||||
_writeControlRegister(control);
|
||||
TRACE_INFO("I cache enabled.\n\r");
|
||||
}
|
||||
#if !defined(OP_BOOTSTRAP_on)
|
||||
else {
|
||||
|
||||
TRACE_INFO("I cache is already enabled.\n\r");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disable Instruction Cache
|
||||
//------------------------------------------------------------------------------
|
||||
void CP15_Disable_I_Cache(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
|
||||
// Check if cache is enabled
|
||||
if ((control & (1 << CP15_I_BIT)) != 0) {
|
||||
|
||||
control &= ~(1 << CP15_I_BIT);
|
||||
_writeControlRegister(control);
|
||||
TRACE_INFO("I cache disabled.\n\r");
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO("I cache is already disabled.\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Check MMU
|
||||
/// \return 0 if MMU disable, 1 if MMU enable
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int CP15_Is_MMUEnabled(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
return ((control & (1 << CP15_M_BIT)) != 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enable MMU
|
||||
//------------------------------------------------------------------------------
|
||||
void CP15_EnableMMU(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
|
||||
// Check if MMU is disabled
|
||||
if ((control & (1 << CP15_M_BIT)) == 0) {
|
||||
|
||||
control |= (1 << CP15_M_BIT);
|
||||
_writeControlRegister(control);
|
||||
TRACE_INFO("MMU enabled.\n\r");
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO("MMU is already enabled.\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disable MMU
|
||||
//------------------------------------------------------------------------------
|
||||
void CP15_DisableMMU(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
|
||||
// Check if MMU is enabled
|
||||
if ((control & (1 << CP15_M_BIT)) != 0) {
|
||||
|
||||
control &= ~(1 << CP15_M_BIT);
|
||||
control &= ~(1 << CP15_C_BIT);
|
||||
_writeControlRegister(control);
|
||||
TRACE_INFO("MMU disabled.\n\r");
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO("MMU is already disabled.\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Check D_Cache
|
||||
/// \return 0 if D_Cache disable, 1 if D_Cache enable (with MMU of course)
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int CP15_Is_DCacheEnabled(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
return ((control & ((1 << CP15_C_BIT)||(1 << CP15_M_BIT))) != 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enable Data Cache
|
||||
//------------------------------------------------------------------------------
|
||||
void CP15_Enable_D_Cache(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
|
||||
if( !CP15_Is_MMUEnabled() ) {
|
||||
TRACE_ERROR("Do nothing: MMU not enabled\n\r");
|
||||
}
|
||||
else {
|
||||
// Check if cache is disabled
|
||||
if ((control & (1 << CP15_C_BIT)) == 0) {
|
||||
|
||||
control |= (1 << CP15_C_BIT);
|
||||
_writeControlRegister(control);
|
||||
TRACE_INFO("D cache enabled.\n\r");
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO("D cache is already enabled.\n\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disable Data Cache
|
||||
//------------------------------------------------------------------------------
|
||||
void CP15_Disable_D_Cache(void)
|
||||
{
|
||||
unsigned int control;
|
||||
|
||||
control = _readControlRegister();
|
||||
|
||||
// Check if cache is enabled
|
||||
if ((control & (1 << CP15_C_BIT)) != 0) {
|
||||
|
||||
control &= ~(1 << CP15_C_BIT);
|
||||
_writeControlRegister(control);
|
||||
TRACE_INFO("D cache disabled.\n\r");
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO("D cache is already disabled.\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CP15_PRESENT
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Methods to manage the Coprocessor 15. Coprocessor 15, or System Control
|
||||
/// Coprocessor CP15, is used to configure and control all the items in the
|
||||
/// list below:
|
||||
/// • ARM core
|
||||
/// • Caches (ICache, DCache and write buffer)
|
||||
/// • TCM
|
||||
/// • MMU
|
||||
/// • Other system options
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Enable or disable D cache with Enable_D_Cache and Disable_D_Cache
|
||||
/// -# Enable or disable I cache with Enable_I_Cache and Disable_I_Cache
|
||||
///
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _CP15_H
|
||||
#define _CP15_H
|
||||
|
||||
#ifdef CP15_PRESENT
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
extern void CP15_Enable_I_Cache(void);
|
||||
extern unsigned int CP15_Is_I_CacheEnabled(void);
|
||||
extern void CP15_Enable_I_Cache(void);
|
||||
extern void CP15_Disable_I_Cache(void);
|
||||
extern unsigned int CP15_Is_MMUEnabled(void);
|
||||
extern void CP15_EnableMMU(void);
|
||||
extern void CP15_DisableMMU(void);
|
||||
extern unsigned int CP15_Is_DCacheEnabled(void);
|
||||
extern void CP15_Enable_D_Cache(void);
|
||||
extern void CP15_Disable_D_Cache(void);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// External functions defined in cp15.S
|
||||
//-----------------------------------------------------------------------------
|
||||
extern unsigned int _readControlRegister(void);
|
||||
extern void _writeControlRegister(unsigned int value);
|
||||
extern void _waitForInterrupt(void);
|
||||
extern void _writeTTB(unsigned int value);
|
||||
extern void _writeDomain(unsigned int value);
|
||||
extern void _writeITLBLockdown(unsigned int value);
|
||||
extern void _prefetchICacheLine(unsigned int value);
|
||||
|
||||
#endif // CP15_PRESENT
|
||||
|
||||
#endif // #ifndef _CP15_H
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define __ASSEMBLY__
|
||||
#include "board.h"
|
||||
|
||||
#ifdef CP15_PRESENT
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Functions to access CP15 coprocessor register
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
.global _readControlRegister
|
||||
.global _writeControlRegister
|
||||
.global _waitForInterrupt
|
||||
.global _writeTTB
|
||||
.global _writeDomain
|
||||
.global _writeITLBLockdown
|
||||
.global _prefetchICacheLine
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Control Register c1
|
||||
/// Register c1 is the Control Register for the ARM926EJ-S processor.
|
||||
/// This register specifies the configuration used to enable and disable the
|
||||
/// caches and MMU. It is recommended that you access this register using a
|
||||
/// read-modify-write sequence.
|
||||
//------------------------------------------------------------------------------
|
||||
// CP15 Read Control Register
|
||||
_readControlRegister:
|
||||
mov r0, #0
|
||||
mrc p15, 0, r0, c1, c0, 0
|
||||
bx lr
|
||||
|
||||
// CP15 Write Control Register
|
||||
_writeControlRegister:
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
bx lr
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// CP15 Wait For Interrupt operation
|
||||
/// The purpose of the Wait For Interrupt operation is to put the processor in
|
||||
/// to a low power state.
|
||||
/// This puts the processor into a low-power state and stops it executing more
|
||||
/// instructions until an interrupt, or debug request occurs, regardless of
|
||||
/// whether the interrupts are disabled by the masks in the CPSR.
|
||||
/// When an interrupt does occur, the MCR instruction completes and the IRQ or
|
||||
/// FIQ handler is entered as normal. The return link in r14_irq or r14_fiq
|
||||
/// contains the address of the MCR instruction plus 8, so that the normal
|
||||
/// instruction used for interrupt return (SUBS PC,R14,#4) returns to the
|
||||
/// instruction following the MCR.
|
||||
/// Wait For Interrupt : MCR p15, 0, <Rd>, c7, c0, 4
|
||||
//------------------------------------------------------------------------------
|
||||
_waitForInterrupt:
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c7, c0, 4
|
||||
bx lr
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// CP15 Translation Table Base Register c2
|
||||
/// Register c2 is the Translation Table Base Register (TTBR), for the base
|
||||
/// address of the first-level translation table.
|
||||
/// Reading from c2 returns the pointer to the currently active first-level
|
||||
/// translation table in bits [31:14] and an Unpredictable value in bits [13:0].
|
||||
/// Writing to register c2 updates the pointer to the first-level translation
|
||||
/// table from the value in bits [31:14] of the written value. Bits [13:0]
|
||||
/// Should Be Zero.
|
||||
/// You can use the following instructions to access the TTBR:
|
||||
/// Read TTBR : MRC p15, 0, <Rd>, c2, c0, 0
|
||||
/// Write TTBR : MCR p15, 0, <Rd>, c2, c0, 0
|
||||
//------------------------------------------------------------------------------
|
||||
_writeTTB:
|
||||
MCR p15, 0, r0, c2, c0, 0
|
||||
bx lr
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Domain Access Control Register c3
|
||||
/// Read domain access permissions : MRC p15, 0, <Rd>, c3, c0, 0
|
||||
/// Write domain access permissions : MCR p15, 0, <Rd>, c3, c0, 0
|
||||
//------------------------------------------------------------------------------
|
||||
_writeDomain:
|
||||
MCR p15, 0, r0, c3, c0, 0
|
||||
bx lr
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// TLB Lockdown Register c10
|
||||
/// The TLB Lockdown Register controls where hardware page table walks place the
|
||||
/// TLB entry, in the set associative region or the lockdown region of the TLB,
|
||||
/// and if in the lockdown region, which entry is written. The lockdown region
|
||||
/// of the TLB contains eight entries. See TLB structure for a description of
|
||||
/// the structure of the TLB.
|
||||
/// Read data TLB lockdown victim : MRC p15,0,<Rd>,c10,c0,0
|
||||
/// Write data TLB lockdown victim : MCR p15,0,<Rd>,c10,c0,0
|
||||
//------------------------------------------------------------------------------
|
||||
_writeITLBLockdown:
|
||||
MCR p15, 0, r0, c10, c0, 0
|
||||
bx lr
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Prefetch ICache line
|
||||
/// Performs an ICache lookup of the specified modified virtual address.
|
||||
/// If the cache misses, and the region is cacheable, a linefill is performed.
|
||||
/// Prefetch ICache line (MVA): MCR p15, 0, <Rd>, c7, c13, 1
|
||||
//------------------------------------------------------------------------------
|
||||
_prefetchICacheLine:
|
||||
MCR p15, 0, r0, c7, c13, 1
|
||||
bx lr
|
||||
#endif
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "dbgu.h"
|
||||
#include <stdarg.h>
|
||||
#include <board.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes the DBGU with the given parameters, and enables both the
|
||||
/// transmitter and the receiver. The mode parameter contains the value of the
|
||||
/// DBGU_MR register.
|
||||
/// Value DBGU_STANDARD can be used for mode to get the most common configuration
|
||||
/// (i.e. aysnchronous, 8bits, no parity, 1 stop bit, no flow control).
|
||||
/// \param mode Operating mode to configure.
|
||||
/// \param baudrate Desired baudrate (e.g. 115200).
|
||||
/// \param mck Frequency of the system master clock in Hz.
|
||||
//------------------------------------------------------------------------------
|
||||
void DBGU_Configure(
|
||||
unsigned int mode,
|
||||
unsigned int baudrate,
|
||||
unsigned int mck)
|
||||
{
|
||||
// Reset & disable receiver and transmitter, disable interrupts
|
||||
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
|
||||
AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF;
|
||||
|
||||
// Configure baud rate
|
||||
AT91C_BASE_DBGU->DBGU_BRGR = mck / (baudrate * 16);
|
||||
|
||||
// Configure mode register
|
||||
AT91C_BASE_DBGU->DBGU_MR = mode;
|
||||
|
||||
// Disable DMA channel
|
||||
AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS;
|
||||
|
||||
// Enable receiver and transmitter
|
||||
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RXEN | AT91C_US_TXEN;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Outputs a character on the DBGU line.
|
||||
/// \note This function is synchronous (i.e. uses polling).
|
||||
/// \param c Character to send.
|
||||
//------------------------------------------------------------------------------
|
||||
void DBGU_PutChar(unsigned char c)
|
||||
{
|
||||
// Wait for the transmitter to be ready
|
||||
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY) == 0);
|
||||
|
||||
// Send character
|
||||
AT91C_BASE_DBGU->DBGU_THR = c;
|
||||
|
||||
// Wait for the transfer to complete
|
||||
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY) == 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Return 1 if a character can be read in DBGU
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int DBGU_IsRxReady()
|
||||
{
|
||||
return (AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Reads and returns a character from the DBGU.
|
||||
/// \note This function is synchronous (i.e. uses polling).
|
||||
/// \return Character received.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char DBGU_GetChar(void)
|
||||
{
|
||||
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY) == 0);
|
||||
return AT91C_BASE_DBGU->DBGU_RHR;
|
||||
}
|
||||
|
||||
#ifndef NOFPUT
|
||||
#include <stdio.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \exclude
|
||||
/// Implementation of fputc using the DBGU as the standard output. Required
|
||||
/// for printf().
|
||||
/// \param c Character to write.
|
||||
/// \param pStream Output stream.
|
||||
/// \param The character written if successful, or -1 if the output stream is
|
||||
/// not stdout or stderr.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int fputc(signed int c, FILE *pStream)
|
||||
{
|
||||
if ((pStream == stdout) || (pStream == stderr)) {
|
||||
|
||||
DBGU_PutChar(c);
|
||||
return c;
|
||||
}
|
||||
else {
|
||||
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \exclude
|
||||
/// Implementation of fputs using the DBGU as the standard output. Required
|
||||
/// for printf(). Does NOT currently use the PDC.
|
||||
/// \param pStr String to write.
|
||||
/// \param pStream Output stream.
|
||||
/// \return Number of characters written if successful, or -1 if the output
|
||||
/// stream is not stdout or stderr.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int fputs(const char *pStr, FILE *pStream)
|
||||
{
|
||||
signed int num = 0;
|
||||
|
||||
while (*pStr != 0) {
|
||||
|
||||
if (fputc(*pStr, pStream) == -1) {
|
||||
|
||||
return -1;
|
||||
}
|
||||
num++;
|
||||
pStr++;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
#undef putchar
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \exclude
|
||||
/// Outputs a character on the DBGU.
|
||||
/// \param c Character to output.
|
||||
/// \return The character that was output.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int putchar(signed int c)
|
||||
{
|
||||
return fputc(c, stdout);
|
||||
}
|
||||
|
||||
#endif //#ifndef NOFPUT
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// This module provides definitions and functions for using the Debug Unit
|
||||
/// (DBGU).
|
||||
///
|
||||
/// It also overloads the fputc(), fputs() & putchar() functions so the printf()
|
||||
/// method outputs its data on the DBGU. This behavior can be suppressed by
|
||||
/// defining NOFPUT during compilation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Enable the DBGU pins (see pio & board.h).
|
||||
/// -# Configure the DBGU using DBGU_Configure with the desired operating mode.
|
||||
/// -# Send characters using DBGU_PutChar() or the printf() method.
|
||||
/// -# Receive characters using DBGU_GetChar().
|
||||
///
|
||||
/// \note Unless specified, all the functions defined here operate synchronously;
|
||||
/// i.e. they all wait the data is sent/received before returning.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef DBGU_H
|
||||
#define DBGU_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Standard operating mode (asynchronous, 8bit, no parity, 1 stop bit)
|
||||
#define DBGU_STANDARD AT91C_US_PAR_NONE
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void DBGU_Configure(
|
||||
unsigned int mode,
|
||||
unsigned int baudrate,
|
||||
unsigned int mck);
|
||||
|
||||
extern unsigned char DBGU_GetChar(void);
|
||||
|
||||
extern void DBGU_PutChar(unsigned char c);
|
||||
|
||||
extern unsigned int DBGU_IsRxReady(void);
|
||||
|
||||
#endif //#ifndef DBGU_H
|
||||
|
|
@ -0,0 +1,346 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "pio.h"
|
||||
#include <board.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures one or more pin(s) of a PIO controller as being controlled by
|
||||
/// peripheral A. Optionally, the corresponding internal pull-up(s) can be
|
||||
/// enabled.
|
||||
/// \param pio Pointer to a PIO controller.
|
||||
/// \param mask Bitmask of one or more pin(s) to configure.
|
||||
/// \param enablePullUp Indicates if the pin(s) internal pull-up shall be
|
||||
/// configured.
|
||||
//------------------------------------------------------------------------------
|
||||
static void PIO_SetPeripheralA(
|
||||
AT91S_PIO *pio,
|
||||
unsigned int mask,
|
||||
unsigned char enablePullUp)
|
||||
{
|
||||
// Disable interrupts on the pin(s)
|
||||
pio->PIO_IDR = mask;
|
||||
|
||||
// Enable the pull-up(s) if necessary
|
||||
if (enablePullUp) {
|
||||
|
||||
pio->PIO_PPUER = mask;
|
||||
}
|
||||
else {
|
||||
|
||||
pio->PIO_PPUDR = mask;
|
||||
}
|
||||
|
||||
// Configure pin
|
||||
pio->PIO_ASR = mask;
|
||||
pio->PIO_PDR = mask;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures one or more pin(s) of a PIO controller as being controlled by
|
||||
/// peripheral B. Optionally, the corresponding internal pull-up(s) can be
|
||||
/// enabled.
|
||||
/// \param pio Pointer to a PIO controller.
|
||||
/// \param mask Bitmask of one or more pin(s) to configure.
|
||||
/// \param enablePullUp Indicates if the pin(s) internal pull-up shall be
|
||||
/// configured.
|
||||
//------------------------------------------------------------------------------
|
||||
static void PIO_SetPeripheralB(
|
||||
AT91S_PIO *pio,
|
||||
unsigned int mask,
|
||||
unsigned char enablePullUp)
|
||||
{
|
||||
// Disable interrupts on the pin(s)
|
||||
pio->PIO_IDR = mask;
|
||||
|
||||
// Enable the pull-up(s) if necessary
|
||||
if (enablePullUp) {
|
||||
|
||||
pio->PIO_PPUER = mask;
|
||||
}
|
||||
else {
|
||||
|
||||
pio->PIO_PPUDR = mask;
|
||||
}
|
||||
|
||||
// Configure pin
|
||||
pio->PIO_BSR = mask;
|
||||
pio->PIO_PDR = mask;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures one or more pin(s) or a PIO controller as inputs. Optionally,
|
||||
/// the corresponding internal pull-up(s) and glitch filter(s) can be
|
||||
/// enabled.
|
||||
/// \param pio Pointer to a PIO controller.
|
||||
/// \param mask Bitmask indicating which pin(s) to configure as input(s).
|
||||
/// \param enablePullUp Indicates if the internal pull-up(s) must be enabled.
|
||||
/// \param enableFilter Indicates if the glitch filter(s) must be enabled.
|
||||
//------------------------------------------------------------------------------
|
||||
static void PIO_SetInput(
|
||||
AT91S_PIO *pio,
|
||||
unsigned int mask,
|
||||
unsigned char enablePullUp,
|
||||
unsigned char enableFilter)
|
||||
{
|
||||
// Disable interrupts
|
||||
pio->PIO_IDR = mask;
|
||||
|
||||
// Enable pull-up(s) if necessary
|
||||
if (enablePullUp) {
|
||||
|
||||
pio->PIO_PPUER = mask;
|
||||
}
|
||||
else {
|
||||
|
||||
pio->PIO_PPUDR = mask;
|
||||
}
|
||||
|
||||
// Enable filter(s) if necessary
|
||||
if (enableFilter) {
|
||||
|
||||
pio->PIO_IFER = mask;
|
||||
}
|
||||
else {
|
||||
|
||||
pio->PIO_IFDR = mask;
|
||||
}
|
||||
|
||||
// Configure pin as input
|
||||
pio->PIO_ODR = mask;
|
||||
pio->PIO_PER = mask;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures one or more pin(s) of a PIO controller as outputs, with the
|
||||
/// given default value. Optionally, the multi-drive feature can be enabled
|
||||
/// on the pin(s).
|
||||
/// \param pio Pointer to a PIO controller.
|
||||
/// \param mask Bitmask indicating which pin(s) to configure.
|
||||
/// \param defaultValue Default level on the pin(s).
|
||||
/// \param enableMultiDrive Indicates if the pin(s) shall be configured as
|
||||
/// open-drain.
|
||||
/// \param enablePullUp Indicates if the pin shall have its pull-up activated.
|
||||
//------------------------------------------------------------------------------
|
||||
static void PIO_SetOutput(
|
||||
AT91S_PIO *pio,
|
||||
unsigned int mask,
|
||||
unsigned char defaultValue,
|
||||
unsigned char enableMultiDrive,
|
||||
unsigned char enablePullUp)
|
||||
{
|
||||
// Disable interrupts
|
||||
pio->PIO_IDR = mask;
|
||||
|
||||
// Enable pull-up(s) if necessary
|
||||
if (enablePullUp) {
|
||||
|
||||
pio->PIO_PPUER = mask;
|
||||
}
|
||||
else {
|
||||
|
||||
pio->PIO_PPUDR = mask;
|
||||
}
|
||||
|
||||
// Enable multi-drive if necessary
|
||||
if (enableMultiDrive) {
|
||||
|
||||
pio->PIO_MDER = mask;
|
||||
}
|
||||
else {
|
||||
|
||||
pio->PIO_MDDR = mask;
|
||||
}
|
||||
|
||||
// Set default value
|
||||
if (defaultValue) {
|
||||
|
||||
pio->PIO_SODR = mask;
|
||||
}
|
||||
else {
|
||||
|
||||
pio->PIO_CODR = mask;
|
||||
}
|
||||
|
||||
// Configure pin(s) as output(s)
|
||||
pio->PIO_OER = mask;
|
||||
pio->PIO_PER = mask;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures a list of Pin instances, each of which can either hold a single
|
||||
/// pin or a group of pins, depending on the mask value; all pins are configured
|
||||
/// by this function. The size of the array must also be provided and is easily
|
||||
/// computed using PIO_LISTSIZE whenever its length is not known in advance.
|
||||
/// \param list Pointer to a list of Pin instances.
|
||||
/// \param size Size of the Pin list (calculated using PIO_LISTSIZE).
|
||||
/// \return 1 if the pins have been configured properly; otherwise 0.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char PIO_Configure(const Pin *list, unsigned int size)
|
||||
{
|
||||
// Configure pins
|
||||
while (size > 0) {
|
||||
|
||||
switch (list->type) {
|
||||
|
||||
case PIO_PERIPH_A:
|
||||
PIO_SetPeripheralA(list->pio,
|
||||
list->mask,
|
||||
(list->attribute & PIO_PULLUP) ? 1 : 0);
|
||||
break;
|
||||
|
||||
case PIO_PERIPH_B:
|
||||
PIO_SetPeripheralB(list->pio,
|
||||
list->mask,
|
||||
(list->attribute & PIO_PULLUP) ? 1 : 0);
|
||||
break;
|
||||
|
||||
case PIO_INPUT:
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << list->id;
|
||||
PIO_SetInput(list->pio,
|
||||
list->mask,
|
||||
(list->attribute & PIO_PULLUP) ? 1 : 0,
|
||||
(list->attribute & PIO_DEGLITCH)? 1 : 0);
|
||||
break;
|
||||
|
||||
case PIO_OUTPUT_0:
|
||||
case PIO_OUTPUT_1:
|
||||
PIO_SetOutput(list->pio,
|
||||
list->mask,
|
||||
(list->type == PIO_OUTPUT_1),
|
||||
(list->attribute & PIO_OPENDRAIN) ? 1 : 0,
|
||||
(list->attribute & PIO_PULLUP) ? 1 : 0);
|
||||
break;
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
|
||||
list++;
|
||||
size--;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sets a high output level on all the PIOs defined in the given Pin instance.
|
||||
/// This has no immediate effects on PIOs that are not output, but the PIO
|
||||
/// controller will memorize the value they are changed to outputs.
|
||||
/// \param pin Pointer to a Pin instance describing one or more pins.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIO_Set(const Pin *pin)
|
||||
{
|
||||
pin->pio->PIO_SODR = pin->mask;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sets a low output level on all the PIOs defined in the given Pin instance.
|
||||
/// This has no immediate effects on PIOs that are not output, but the PIO
|
||||
/// controller will memorize the value they are changed to outputs.
|
||||
/// \param pin Pointer to a Pin instance describing one or more pins.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIO_Clear(const Pin *pin)
|
||||
{
|
||||
pin->pio->PIO_CODR = pin->mask;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns 1 if one or more PIO of the given Pin instance currently have a high
|
||||
/// level; otherwise returns 0. This method returns the actual value that is
|
||||
/// being read on the pin. To return the supposed output value of a pin, use
|
||||
/// PIO_GetOutputDataStatus() instead.
|
||||
/// \param pin Pointer to a Pin instance describing one or more pins.
|
||||
/// \return 1 if the Pin instance contains at least one PIO that currently has
|
||||
/// a high level; otherwise 0.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char PIO_Get(const Pin *pin)
|
||||
{
|
||||
unsigned int reg;
|
||||
if ((pin->type == PIO_OUTPUT_0) || (pin->type == PIO_OUTPUT_1)) {
|
||||
|
||||
reg = pin->pio->PIO_ODSR;
|
||||
}
|
||||
else {
|
||||
|
||||
reg = pin->pio->PIO_PDSR;
|
||||
}
|
||||
|
||||
if ((reg & pin->mask) == 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns 1 if one or more PIO of the given Pin are configured to output a
|
||||
/// high level (even if they are not output).
|
||||
/// To get the actual value of the pin, use PIO_Get() instead.
|
||||
/// \param pin Pointer to a Pin instance describing one or more pins.
|
||||
/// \return 1 if the Pin instance contains at least one PIO that is configured
|
||||
/// to output a high level; otherwise 0.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char PIO_GetOutputDataStatus(const Pin *pin)
|
||||
{
|
||||
if ((pin->pio->PIO_ODSR & pin->mask) == 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the value of ISR for the PIO controller of the pin.
|
||||
/// Reading this register acknoledges all the ITs.
|
||||
/// \param pin Pointer to a Pin instance describing one or more pins.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int PIO_GetISR(const Pin *pin)
|
||||
{
|
||||
return (pin->pio->PIO_ISR);
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// This file provides a basic API for PIO configuration and usage of
|
||||
/// user-controlled pins. Please refer to the board.h file for a list of
|
||||
/// available pin definitions.
|
||||
///
|
||||
/// !!!Usage
|
||||
///
|
||||
/// -# Define a constant pin description array such as the following one, using
|
||||
/// the existing definitions provided by the board.h file if possible:
|
||||
/// \code
|
||||
/// const Pin pPins[] = {PIN_USART0_TXD, PIN_USART0_RXD};
|
||||
/// \endcode
|
||||
/// Alternatively, it is possible to add new pins by provided the full Pin
|
||||
/// structure:
|
||||
/// \code
|
||||
/// // Pin instance to configure PA10 & PA11 as inputs with the internal
|
||||
/// // pull-up enabled.
|
||||
/// const Pin pPins = {
|
||||
/// (1 << 10) | (1 << 11),
|
||||
/// AT91C_BASE_PIOA,
|
||||
/// AT91C_ID_PIOA,
|
||||
/// PIO_INPUT,
|
||||
/// PIO_PULLUP
|
||||
/// };
|
||||
/// \endcode
|
||||
/// -# Configure a pin array by calling PIO_Configure() with a pointer to the
|
||||
/// array and its size (which is computed using the PIO_LISTSIZE macro).
|
||||
/// -# Change and get the value of a user-controlled pin using the PIO_Set,
|
||||
/// PIO_Clear and PIO_Get methods.
|
||||
/// -# Get the level being currently output by a user-controlled pin configured
|
||||
/// as an output using PIO_GetOutputDataStatus().
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef PIO_H
|
||||
#define PIO_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <board.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// The pin is controlled by the associated signal of peripheral A.
|
||||
#define PIO_PERIPH_A 0
|
||||
/// The pin is controlled by the associated signal of peripheral B.
|
||||
#define PIO_PERIPH_B 1
|
||||
/// The pin is an input.
|
||||
#define PIO_INPUT 2
|
||||
/// The pin is an output and has a default level of 0.
|
||||
#define PIO_OUTPUT_0 3
|
||||
/// The pin is an output and has a default level of 1.
|
||||
#define PIO_OUTPUT_1 4
|
||||
|
||||
/// Default pin configuration (no attribute).
|
||||
#define PIO_DEFAULT (0 << 0)
|
||||
/// The internal pin pull-up is active.
|
||||
#define PIO_PULLUP (1 << 0)
|
||||
/// The internal glitch filter is active.
|
||||
#define PIO_DEGLITCH (1 << 1)
|
||||
/// The pin is open-drain.
|
||||
#define PIO_OPENDRAIN (1 << 2)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Macros
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Calculates the size of an array of Pin instances. The array must be defined
|
||||
/// locally (i.e. not a pointer), otherwise the computation will not be correct.
|
||||
/// \param pPins Local array of Pin instances.
|
||||
/// \return Number of elements in array.
|
||||
//------------------------------------------------------------------------------
|
||||
#define PIO_LISTSIZE(pPins) (sizeof(pPins) / sizeof(Pin))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Describes the type and attribute of one PIO pin or a group of similar pins.
|
||||
/// The #type# field can have the following values:
|
||||
/// - PIO_PERIPH_A
|
||||
/// - PIO_PERIPH_B
|
||||
/// - PIO_OUTPUT_0
|
||||
/// - PIO_OUTPUT_1
|
||||
/// - PIO_INPUT
|
||||
///
|
||||
/// The #attribute# field is a bitmask that can either be set to PIO_DEFAULt,
|
||||
/// or combine (using bitwise OR '|') any number of the following constants:
|
||||
/// - PIO_PULLUP
|
||||
/// - PIO_DEGLITCH
|
||||
/// - PIO_OPENDRAIN
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Bitmask indicating which pin(s) to configure.
|
||||
unsigned int mask;
|
||||
/// Pointer to the PIO controller which has the pin(s).
|
||||
AT91S_PIO *pio;
|
||||
/// Peripheral ID of the PIO controller which has the pin(s).
|
||||
unsigned char id;
|
||||
/// Pin type.
|
||||
unsigned char type;
|
||||
/// Pin attribute.
|
||||
unsigned char attribute;
|
||||
|
||||
} Pin;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char PIO_Configure(const Pin *list, unsigned int size);
|
||||
|
||||
extern void PIO_Set(const Pin *pin);
|
||||
|
||||
extern void PIO_Clear(const Pin *pin);
|
||||
|
||||
extern unsigned char PIO_Get(const Pin *pin);
|
||||
|
||||
extern unsigned int PIO_GetISR(const Pin *pin);
|
||||
|
||||
extern unsigned char PIO_GetOutputDataStatus(const Pin *pin);
|
||||
|
||||
#endif //#ifndef PIO_H
|
||||
|
|
@ -0,0 +1,395 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/// Disable traces for this file
|
||||
#undef TRACE_LEVEL
|
||||
#define TRACE_LEVEL 0
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "pio_it.h"
|
||||
#include "pio.h"
|
||||
#include <board.h>
|
||||
#include <aic/aic.h>
|
||||
#include <utility/assert.h>
|
||||
#include <utility/trace.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// \exclude
|
||||
/// Maximum number of interrupt sources that can be defined. This
|
||||
/// constant can be increased, but the current value is the smallest possible
|
||||
/// that will be compatible with all existing projects.
|
||||
#define MAX_INTERRUPT_SOURCES 7
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \exclude
|
||||
/// Describes a PIO interrupt source, including the PIO instance triggering the
|
||||
/// interrupt and the associated interrupt handler.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Pointer to the source pin instance.
|
||||
const Pin *pPin;
|
||||
|
||||
/// Interrupt handler.
|
||||
void (*handler)(const Pin *);
|
||||
|
||||
} InterruptSource;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// List of interrupt sources.
|
||||
static InterruptSource pSources[MAX_INTERRUPT_SOURCES];
|
||||
|
||||
/// Number of currently defined interrupt sources.
|
||||
static unsigned int numSources;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Handles all interrupts on the given PIO controller.
|
||||
/// \param id PIO controller ID.
|
||||
/// \param pPio PIO controller base address.
|
||||
//------------------------------------------------------------------------------
|
||||
static void PioInterruptHandler(unsigned int id, AT91S_PIO *pPio)
|
||||
{
|
||||
unsigned int status;
|
||||
unsigned int i;
|
||||
|
||||
// Read PIO controller status
|
||||
status = pPio->PIO_ISR;
|
||||
status &= pPio->PIO_IMR;
|
||||
|
||||
// Check pending events
|
||||
if (status != 0) {
|
||||
|
||||
TRACE_DEBUG("PIO interrupt on PIO controller #%d\n\r", id);
|
||||
|
||||
// Find triggering source
|
||||
i = 0;
|
||||
while (status != 0) {
|
||||
|
||||
// There cannot be an unconfigured source enabled.
|
||||
SANITY_CHECK(i < numSources);
|
||||
|
||||
// Source is configured on the same controller
|
||||
if (pSources[i].pPin->id == id) {
|
||||
|
||||
// Source has PIOs whose statuses have changed
|
||||
if ((status & pSources[i].pPin->mask) != 0) {
|
||||
|
||||
TRACE_DEBUG("Interrupt source #%d triggered\n\r", i);
|
||||
|
||||
pSources[i].handler(pSources[i].pPin);
|
||||
status &= ~(pSources[i].pPin->mask);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Generic PIO interrupt handler. Single entry point for interrupts coming
|
||||
/// from any PIO controller (PIO A, B, C ...). Dispatches the interrupt to
|
||||
/// the user-configured handlers.
|
||||
//------------------------------------------------------------------------------
|
||||
static void InterruptHandler(void)
|
||||
{
|
||||
#if defined(AT91C_ID_PIOA)
|
||||
// Treat PIOA interrupts
|
||||
PioInterruptHandler(AT91C_ID_PIOA, AT91C_BASE_PIOA);
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOB)
|
||||
// Treat PIOB interrupts
|
||||
PioInterruptHandler(AT91C_ID_PIOB, AT91C_BASE_PIOB);
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOC)
|
||||
// Treat PIOC interrupts
|
||||
PioInterruptHandler(AT91C_ID_PIOC, AT91C_BASE_PIOC);
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOD)
|
||||
// Treat PIOD interrupts
|
||||
PioInterruptHandler(AT91C_ID_PIOD, AT91C_BASE_PIOD);
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOE)
|
||||
// Treat PIOE interrupts
|
||||
PioInterruptHandler(AT91C_ID_PIOE, AT91C_BASE_PIOE);
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOABCD)
|
||||
// Treat PIOABCD interrupts
|
||||
#if !defined(AT91C_ID_PIOA)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCD, AT91C_BASE_PIOA);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOB)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCD, AT91C_BASE_PIOB);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOC)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCD, AT91C_BASE_PIOC);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOD)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCD, AT91C_BASE_PIOD);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOABCDE)
|
||||
// Treat PIOABCDE interrupts
|
||||
#if !defined(AT91C_ID_PIOA)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOA);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOB)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOB);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOC)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOC);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOD)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOD);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOE)
|
||||
PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOE);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOCDE)
|
||||
// Treat PIOCDE interrupts
|
||||
#if !defined(AT91C_ID_PIOC)
|
||||
PioInterruptHandler(AT91C_ID_PIOCDE, AT91C_BASE_PIOC);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOD)
|
||||
PioInterruptHandler(AT91C_ID_PIOCDE, AT91C_BASE_PIOD);
|
||||
#endif
|
||||
#if !defined(AT91C_ID_PIOE)
|
||||
PioInterruptHandler(AT91C_ID_PIOCDE, AT91C_BASE_PIOE);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes the PIO interrupt management logic. The desired priority of PIO
|
||||
/// interrupts must be provided. Calling this function multiple times result in
|
||||
/// the reset of currently configured interrupts.
|
||||
/// \param priority PIO controller interrupts priority.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIO_InitializeInterrupts(unsigned int priority)
|
||||
{
|
||||
TRACE_DEBUG("PIO_Initialize()\n\r");
|
||||
|
||||
SANITY_CHECK((priority & ~AT91C_AIC_PRIOR) == 0);
|
||||
|
||||
// Reset sources
|
||||
numSources = 0;
|
||||
|
||||
#ifdef AT91C_ID_PIOA
|
||||
// Configure PIO interrupt sources
|
||||
TRACE_DEBUG("PIO_Initialize: Configuring PIOA\n\r");
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
|
||||
AT91C_BASE_PIOA->PIO_ISR;
|
||||
AT91C_BASE_PIOA->PIO_IDR = 0xFFFFFFFF;
|
||||
AIC_ConfigureIT(AT91C_ID_PIOA, priority, InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_PIOA);
|
||||
#endif
|
||||
|
||||
#ifdef AT91C_ID_PIOB
|
||||
TRACE_DEBUG("PIO_Initialize: Configuring PIOB\n\r");
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
|
||||
AT91C_BASE_PIOB->PIO_ISR;
|
||||
AT91C_BASE_PIOB->PIO_IDR = 0xFFFFFFFF;
|
||||
AIC_ConfigureIT(AT91C_ID_PIOB, priority, InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_PIOB);
|
||||
#endif
|
||||
|
||||
#ifdef AT91C_ID_PIOC
|
||||
TRACE_DEBUG("PIO_Initialize: Configuring PIOC\n\r");
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOC;
|
||||
AT91C_BASE_PIOC->PIO_ISR;
|
||||
AT91C_BASE_PIOC->PIO_IDR = 0xFFFFFFFF;
|
||||
AIC_ConfigureIT(AT91C_ID_PIOC, priority, InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_PIOC);
|
||||
#endif
|
||||
|
||||
#ifdef AT91C_ID_PIOD
|
||||
TRACE_DEBUG("PIO_Initialize: Configuring PIOD\n\r");
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOD;
|
||||
AT91C_BASE_PIOC->PIO_ISR;
|
||||
AT91C_BASE_PIOC->PIO_IDR = 0xFFFFFFFF;
|
||||
AIC_ConfigureIT(AT91C_ID_PIOD, priority, InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_PIOD);
|
||||
#endif
|
||||
|
||||
#ifdef AT91C_ID_PIOE
|
||||
TRACE_DEBUG("PIO_Initialize: Configuring PIOE\n\r");
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOE;
|
||||
AT91C_BASE_PIOC->PIO_ISR;
|
||||
AT91C_BASE_PIOC->PIO_IDR = 0xFFFFFFFF;
|
||||
AIC_ConfigureIT(AT91C_ID_PIOE, priority, InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_PIOE);
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOABCD)
|
||||
// Treat PIOABCD interrupts
|
||||
#if !defined(AT91C_ID_PIOA) \
|
||||
&& !defined(AT91C_ID_PIOB) \
|
||||
&& !defined(AT91C_ID_PIOC) \
|
||||
&& !defined(AT91C_ID_PIOD)
|
||||
|
||||
TRACE_DEBUG("PIO_Initialize: Configuring PIOABCD\n\r");
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOABCD;
|
||||
AT91C_BASE_PIOA->PIO_ISR;
|
||||
AT91C_BASE_PIOA->PIO_IDR = 0xFFFFFFFF;
|
||||
AIC_ConfigureIT(AT91C_ID_PIOABCD, priority, InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_PIOABCD);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOABCDE)
|
||||
// Treat PIOABCDE interrupts
|
||||
#if !defined(AT91C_ID_PIOA) \
|
||||
&& !defined(AT91C_ID_PIOB) \
|
||||
&& !defined(AT91C_ID_PIOC) \
|
||||
&& !defined(AT91C_ID_PIOD) \
|
||||
&& !defined(AT91C_ID_PIOE)
|
||||
|
||||
TRACE_DEBUG("PIO_Initialize: Configuring PIOABCDE\n\r");
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOABCDE;
|
||||
AT91C_BASE_PIOA->PIO_ISR;
|
||||
AT91C_BASE_PIOA->PIO_IDR = 0xFFFFFFFF;
|
||||
AIC_ConfigureIT(AT91C_ID_PIOABCDE, priority, InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_PIOABCDE);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(AT91C_ID_PIOCDE)
|
||||
// Treat PIOCDE interrupts
|
||||
#if !defined(AT91C_ID_PIOC) \
|
||||
&& !defined(AT91C_ID_PIOD) \
|
||||
&& !defined(AT91C_ID_PIOE)
|
||||
|
||||
TRACE_DEBUG("PIO_Initialize: Configuring PIOC\n\r");
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOCDE;
|
||||
AT91C_BASE_PIOC->PIO_ISR;
|
||||
AT91C_BASE_PIOC->PIO_IDR = 0xFFFFFFFF;
|
||||
AIC_ConfigureIT(AT91C_ID_PIOCDE, priority, InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_PIOCDE);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures a PIO or a group of PIO to generate an interrupt on status
|
||||
/// change. The provided interrupt handler will be called with the triggering
|
||||
/// pin as its parameter (enabling different pin instances to share the same
|
||||
/// handler).
|
||||
/// \param pPin Pointer to a Pin instance.
|
||||
/// \param handler Interrupt handler function pointer.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIO_ConfigureIt(const Pin *pPin, void (*handler)(const Pin *))
|
||||
{
|
||||
InterruptSource *pSource;
|
||||
|
||||
TRACE_DEBUG("PIO_ConfigureIt()\n\r");
|
||||
|
||||
SANITY_CHECK(pPin);
|
||||
ASSERT(numSources < MAX_INTERRUPT_SOURCES,
|
||||
"-F- PIO_ConfigureIt: Increase MAX_INTERRUPT_SOURCES\n\r");
|
||||
|
||||
// Define new source
|
||||
TRACE_DEBUG("PIO_ConfigureIt: Defining new source #%d.\n\r", numSources);
|
||||
|
||||
pSource = &(pSources[numSources]);
|
||||
pSource->pPin = pPin;
|
||||
pSource->handler = handler;
|
||||
numSources++;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enables the given interrupt source if it has been configured. The status
|
||||
/// register of the corresponding PIO controller is cleared prior to enabling
|
||||
/// the interrupt.
|
||||
/// \param pPin Interrupt source to enable.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIO_EnableIt(const Pin *pPin)
|
||||
{
|
||||
TRACE_DEBUG("PIO_EnableIt()\n\r");
|
||||
|
||||
SANITY_CHECK(pPin);
|
||||
|
||||
#ifndef NOASSERT
|
||||
unsigned int i = 0;
|
||||
unsigned char found = 0;
|
||||
while ((i < numSources) && !found) {
|
||||
|
||||
if (pSources[i].pPin == pPin) {
|
||||
|
||||
found = 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
ASSERT(found, "-F- PIO_EnableIt: Interrupt source has not been configured\n\r");
|
||||
#endif
|
||||
|
||||
pPin->pio->PIO_ISR;
|
||||
pPin->pio->PIO_IER = pPin->mask;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disables a given interrupt source, with no added side effects.
|
||||
/// \param pPin Interrupt source to disable.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIO_DisableIt(const Pin *pPin)
|
||||
{
|
||||
SANITY_CHECK(pPin);
|
||||
|
||||
TRACE_DEBUG("PIO_DisableIt()\n\r");
|
||||
|
||||
pPin->pio->PIO_IDR = pPin->mask;
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Configuration and handling of interrupts on PIO status changes. The API
|
||||
/// provided here have several advantages over the traditional PIO interrupt
|
||||
/// configuration approach:
|
||||
/// - It is highly portable
|
||||
/// - It automatically demultiplexes interrupts when multiples pins have been
|
||||
/// configured on a single PIO controller
|
||||
/// - It allows a group of pins to share the same interrupt
|
||||
///
|
||||
/// However, it also has several minor drawbacks that may prevent from using it
|
||||
/// in particular applications:
|
||||
/// - It enables the clocks of all PIO controllers
|
||||
/// - PIO controllers all share the same interrupt handler, which does the
|
||||
/// demultiplexing and can be slower than direct configuration
|
||||
/// - It reserves space for a fixed number of interrupts, which can be
|
||||
/// increased by modifying the appropriate constant in pio_it.c.
|
||||
///
|
||||
/// !!!Usage
|
||||
///
|
||||
/// -# Initialize the PIO interrupt mechanism using PIO_InitializeInterrupts()
|
||||
/// with the desired priority (0 ... 7).
|
||||
/// -# Configure a status change interrupt on one or more pin(s) with
|
||||
/// PIO_ConfigureIt().
|
||||
/// -# Enable & disable interrupts on pins using PIO_EnableIt() and
|
||||
/// PIO_DisableIt().
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef PIO_IT_H
|
||||
#define PIO_IT_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "pio.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void PIO_InitializeInterrupts(unsigned int priority);
|
||||
|
||||
extern void PIO_ConfigureIt(const Pin *pPin, void (*handler)(const Pin *));
|
||||
|
||||
extern void PIO_EnableIt(const Pin *pPin);
|
||||
|
||||
extern void PIO_DisableIt(const Pin *pPin);
|
||||
|
||||
#endif //#ifndef PIO_IT_H
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "pit.h"
|
||||
#include <board.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initialize the Periodic Interval Timer to generate a tick at the specified
|
||||
/// period, given the current master clock frequency.
|
||||
/// \param period Period in µsecond.
|
||||
/// \param pit_frequency Master clock frequency in MHz.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIT_Init(unsigned int period, unsigned int pit_frequency)
|
||||
{
|
||||
AT91C_BASE_PITC->PITC_PIMR = period? (period * pit_frequency + 8) >> 4 : 0;
|
||||
AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Set the Periodic Interval Value of the PIT.
|
||||
/// \param piv PIV value to set.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIT_SetPIV(unsigned int piv)
|
||||
{
|
||||
AT91C_BASE_PITC->PITC_PIMR = (AT91C_BASE_PITC->PITC_PIMR & AT91C_PITC_PIV)
|
||||
| piv;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enables the PIT if this is not already the case.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIT_Enable(void)
|
||||
{
|
||||
AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Enable the PIT periodic interrupt.
|
||||
//----------------------------------------------------------------------------
|
||||
void PIT_EnableIT(void)
|
||||
{
|
||||
AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITIEN;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disables the PIT periodic interrupt.
|
||||
//------------------------------------------------------------------------------
|
||||
void PIT_DisableIT(void)
|
||||
{
|
||||
AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the value of the PIT mode register.
|
||||
/// \return PIT_MR value.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int PIT_GetMode(void)
|
||||
{
|
||||
return AT91C_BASE_PITC->PITC_PIMR;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the value of the PIT status register, clearing it as a side effect.
|
||||
/// \return PIT_SR value.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int PIT_GetStatus(void)
|
||||
{
|
||||
return AT91C_BASE_PITC->PITC_PISR;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the value of the PIT Image Register, to read PICNT and CPIV without
|
||||
/// clearing the current values.
|
||||
/// \return PIT_PIIR value.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int PIT_GetPIIR(void)
|
||||
{
|
||||
return AT91C_BASE_PITC->PITC_PIIR;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the value of the PIT Value Register, clearing it as a side effect.
|
||||
/// \return PIT_PIVR value.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int PIT_GetPIVR(void)
|
||||
{
|
||||
return AT91C_BASE_PITC->PITC_PIVR;
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Interface for configuration the Periodic Interval Timer (PIT) peripheral.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Initialize the PIT with the desired period using PIT_Init().
|
||||
/// Alternatively, the Periodic Interval Value (PIV) can be configured
|
||||
/// manually using PIT_SetPIV().
|
||||
/// -# Start the PIT counting using PIT_Enable().
|
||||
/// -# Enable & disable the PIT interrupt using PIT_EnableIT() and
|
||||
/// PIT_DisableIT().
|
||||
/// -# Retrieve the current status of the PIT using PIT_GetStatus().
|
||||
/// -# To get the current value of the internal counter and the number of ticks
|
||||
/// that have occurred, use either PIT_GetPIVR() or PIT_GetPIIR() depending
|
||||
/// on whether you want the values to be cleared or not.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef PIT_H
|
||||
#define PIT_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void PIT_Init(unsigned int period, unsigned int pit_frequency);
|
||||
|
||||
extern void PIT_SetPIV(unsigned int piv);
|
||||
|
||||
extern void PIT_Enable(void);
|
||||
|
||||
extern void PIT_EnableIT(void);
|
||||
|
||||
extern void PIT_DisableIT(void);
|
||||
|
||||
extern unsigned int PIT_GetMode(void);
|
||||
|
||||
extern unsigned int PIT_GetStatus(void);
|
||||
|
||||
extern unsigned int PIT_GetPIIR(void);
|
||||
|
||||
extern unsigned int PIT_GetPIVR(void);
|
||||
|
||||
#endif //#ifndef PIT_H
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "pmc.h"
|
||||
#include <board.h>
|
||||
#include <utility/assert.h>
|
||||
#include <utility/trace.h>
|
||||
|
||||
#ifdef CP15_PRESENT
|
||||
#include <cp15/cp15.h>
|
||||
#endif
|
||||
|
||||
#define MASK_STATUS 0x3FFFFFFC
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#if defined(at91sam7l64) || defined(at91sam7l128)
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sets the fast wake-up inputs that can get the device out of Wait mode.
|
||||
/// \param inputs Fast wake-up inputs to enable.
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_SetFastWakeUpInputs(unsigned int inputs)
|
||||
{
|
||||
SANITY_CHECK((inputs & ~0xFF) == 0);
|
||||
AT91C_BASE_PMC->PMC_FSMR = inputs;
|
||||
}
|
||||
|
||||
#if !defined(__ICCARM__)
|
||||
__attribute__ ((section (".ramfunc"))) // GCC
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disables the main oscillator, making the device enter Wait mode.
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_DisableMainOscillatorForWaitMode(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_MOR = 0x37 << 16;
|
||||
while ((AT91C_BASE_PMC->PMC_MOR & AT91C_PMC_MAINSELS) != AT91C_PMC_MAINSELS);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(at91sam7l)
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disables the main oscillator when NOT running on it.
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_DisableMainOscillator(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_MOR = 0x37 << 16;
|
||||
while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MAINSELS) == AT91C_PMC_MAINSELS);
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disables the processor clock
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_DisableProcessorClock(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK;
|
||||
while ((AT91C_BASE_PMC->PMC_SCSR & AT91C_PMC_PCK) != AT91C_PMC_PCK);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enables the clock of a peripheral. The peripheral ID (AT91C_ID_xxx) is used
|
||||
/// to identify which peripheral is targetted.
|
||||
/// Note that the ID must NOT be shifted (i.e. 1 << AT91C_ID_xxx).
|
||||
/// \param id Peripheral ID (AT91C_ID_xxx).
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_EnablePeripheral(unsigned int id)
|
||||
{
|
||||
SANITY_CHECK(id < 32);
|
||||
|
||||
if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) == (1 << id)) {
|
||||
|
||||
TRACE_INFO("PMC_EnablePeripheral: clock of peripheral"
|
||||
" %u is already enabled\n\r",
|
||||
id);
|
||||
}
|
||||
else {
|
||||
|
||||
AT91C_BASE_PMC->PMC_PCER = 1 << id;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disables the clock of a peripheral. The peripheral ID (AT91C_ID_xxx) is used
|
||||
/// to identify which peripheral is targetted.
|
||||
/// Note that the ID must NOT be shifted (i.e. 1 << AT91C_ID_xxx).
|
||||
/// \param id Peripheral ID (AT91C_ID_xxx).
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_DisablePeripheral(unsigned int id)
|
||||
{
|
||||
SANITY_CHECK(id < 32);
|
||||
|
||||
if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) != (1 << id)) {
|
||||
|
||||
TRACE_INFO("PMC_DisablePeripheral: clock of peripheral"
|
||||
" %u is not enabled\n\r",
|
||||
id);
|
||||
}
|
||||
else {
|
||||
|
||||
AT91C_BASE_PMC->PMC_PCDR = 1 << id;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enable all the periph clock via PMC
|
||||
/// (Becareful of the last 2 bits, it is not periph clock)
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_EnableAllPeripherals(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = MASK_STATUS;
|
||||
while( (AT91C_BASE_PMC->PMC_PCSR & MASK_STATUS) != MASK_STATUS);
|
||||
TRACE_INFO("Enable all periph clocks\n\r");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Disable all the periph clock via PMC
|
||||
/// (Becareful of the last 2 bits, it is not periph clock)
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_DisableAllPeripherals(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCDR = MASK_STATUS;
|
||||
while((AT91C_BASE_PMC->PMC_PCSR & MASK_STATUS) != 0);
|
||||
TRACE_INFO("Disable all periph clocks\n\r");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Get Periph Status
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int PMC_IsAllPeriphEnabled(void)
|
||||
{
|
||||
return (AT91C_BASE_PMC->PMC_PCSR == MASK_STATUS);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Get Periph Status
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int PMC_IsPeriphEnabled(unsigned int id)
|
||||
{
|
||||
return (AT91C_BASE_PMC->PMC_PCSR & (1 << id));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/// Put the CPU in Idle Mode for lower consumption
|
||||
//------------------------------------------------------------------------------
|
||||
void PMC_CPUInIdleMode(void)
|
||||
{
|
||||
PMC_DisableProcessorClock();
|
||||
#ifdef CP15_PRESENT
|
||||
_waitForInterrupt();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PMC_H
|
||||
#define PMC_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#if defined(at91sam7l64) || defined(at91sam7l128)
|
||||
extern void PMC_SetFastWakeUpInputs(unsigned int inputs);
|
||||
extern void PMC_DisableMainOscillator(void);
|
||||
extern
|
||||
#ifdef __ICCARM__
|
||||
__ramfunc
|
||||
#endif //__ICCARM__
|
||||
void PMC_DisableMainOscillatorForWaitMode(void);
|
||||
#endif // at91sam7l64 at91sam7l128
|
||||
|
||||
extern void PMC_DisableProcessorClock(void);
|
||||
extern void PMC_EnablePeripheral(unsigned int id);
|
||||
extern void PMC_DisablePeripheral(unsigned int id);
|
||||
extern void PMC_CPUInIdleMode(void);
|
||||
|
||||
|
||||
extern void PMC_EnableAllPeripherals(void);
|
||||
|
||||
extern void PMC_DisableAllPeripherals(void);
|
||||
|
||||
extern unsigned int PMC_IsAllPeriphEnabled(void);
|
||||
|
||||
extern unsigned int PMC_IsPeriphEnabled(unsigned int id);
|
||||
|
||||
#endif //#ifndef PMC_H
|
||||
|
|
@ -0,0 +1,272 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "usart.h"
|
||||
#include <utility/trace.h>
|
||||
#include <utility/assert.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures an USART peripheral with the specified parameters.
|
||||
/// \param usart Pointer to the USART peripheral to configure.
|
||||
/// \param mode Desired value for the USART mode register (see the datasheet).
|
||||
/// \param baudrate Baudrate at which the USART should operate (in Hz).
|
||||
/// \param masterClock Frequency of the system master clock (in Hz).
|
||||
//------------------------------------------------------------------------------
|
||||
void USART_Configure(AT91S_USART *usart,
|
||||
unsigned int mode,
|
||||
unsigned int baudrate,
|
||||
unsigned int masterClock)
|
||||
{
|
||||
// Reset and disable receiver & transmitter
|
||||
usart->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX
|
||||
| AT91C_US_RXDIS | AT91C_US_TXDIS;
|
||||
|
||||
// Configure mode
|
||||
usart->US_MR = mode;
|
||||
|
||||
// Configure baudrate
|
||||
// Asynchronous, no oversampling
|
||||
if (((mode & AT91C_US_SYNC) == 0)
|
||||
&& ((mode & AT91C_US_OVER) == 0)) {
|
||||
|
||||
usart->US_BRGR = (masterClock / baudrate) / 16;
|
||||
}
|
||||
// TODO other modes
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enables or disables the transmitter of an USART peripheral.
|
||||
/// \param usart Pointer to an USART peripheral
|
||||
/// \param enabled If true, the transmitter is enabled; otherwise it is
|
||||
/// disabled.
|
||||
//------------------------------------------------------------------------------
|
||||
void USART_SetTransmitterEnabled(AT91S_USART *usart,
|
||||
unsigned char enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
|
||||
usart->US_CR = AT91C_US_TXEN;
|
||||
}
|
||||
else {
|
||||
|
||||
usart->US_CR = AT91C_US_TXDIS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Enables or disables the receiver of an USART peripheral
|
||||
/// \param usart Pointer to an USART peripheral
|
||||
/// \param enabled If true, the receiver is enabled; otherwise it is disabled.
|
||||
//------------------------------------------------------------------------------
|
||||
void USART_SetReceiverEnabled(AT91S_USART *usart,
|
||||
unsigned char enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
|
||||
usart->US_CR = AT91C_US_RXEN;
|
||||
}
|
||||
else {
|
||||
|
||||
usart->US_CR = AT91C_US_RXDIS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends one packet of data through the specified USART peripheral. This
|
||||
/// function operates synchronously, so it only returns when the data has been
|
||||
/// actually sent.
|
||||
/// \param usart Pointer to an USART peripheral.
|
||||
/// \param data Data to send including 9nth bit and sync field if necessary (in
|
||||
/// the same format as the US_THR register in the datasheet).
|
||||
/// \param timeOut Time out value (0 = no timeout).
|
||||
//------------------------------------------------------------------------------
|
||||
void USART_Write(
|
||||
AT91S_USART *usart,
|
||||
unsigned short data,
|
||||
volatile unsigned int timeOut)
|
||||
{
|
||||
if (timeOut == 0) {
|
||||
|
||||
while ((usart->US_CSR & AT91C_US_TXEMPTY) == 0);
|
||||
}
|
||||
else {
|
||||
|
||||
while ((usart->US_CSR & AT91C_US_TXEMPTY) == 0) {
|
||||
|
||||
if (timeOut == 0) {
|
||||
|
||||
TRACE_ERROR("USART_Write: Timed out.\n\r");
|
||||
return;
|
||||
}
|
||||
timeOut--;
|
||||
}
|
||||
}
|
||||
|
||||
usart->US_THR = data;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends the contents of a data buffer through the specified USART peripheral.
|
||||
/// This function returns immediately (1 if the buffer has been queued, 0
|
||||
/// otherwise); poll the ENDTX and TXBUFE bits of the USART status register
|
||||
/// to check for the transfer completion.
|
||||
/// \param usart Pointer to an USART peripheral.
|
||||
/// \param buffer Pointer to the data buffer to send.
|
||||
/// \param size Size of the data buffer (in bytes).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USART_WriteBuffer(
|
||||
AT91S_USART *usart,
|
||||
void *buffer,
|
||||
unsigned int size)
|
||||
{
|
||||
// Check if the first PDC bank is free
|
||||
if ((usart->US_TCR == 0) && (usart->US_TNCR == 0)) {
|
||||
|
||||
usart->US_TPR = (unsigned int) buffer;
|
||||
usart->US_TCR = size;
|
||||
usart->US_PTCR = AT91C_PDC_TXTEN;
|
||||
|
||||
return 1;
|
||||
}
|
||||
// Check if the second PDC bank is free
|
||||
else if (usart->US_TNCR == 0) {
|
||||
|
||||
usart->US_TNPR = (unsigned int) buffer;
|
||||
usart->US_TNCR = size;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Reads and return a packet of data on the specified USART peripheral. This
|
||||
/// function operates asynchronously, so it waits until some data has been
|
||||
/// received.
|
||||
/// \param usart Pointer to an USART peripheral.
|
||||
/// \param timeOut Time out value (0 -> no timeout).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USART_Read(
|
||||
AT91S_USART *usart,
|
||||
volatile unsigned int timeOut)
|
||||
{
|
||||
if (timeOut == 0) {
|
||||
|
||||
while ((usart->US_CSR & AT91C_US_RXRDY) == 0);
|
||||
}
|
||||
else {
|
||||
|
||||
while ((usart->US_CSR & AT91C_US_RXRDY) == 0) {
|
||||
|
||||
if (timeOut == 0) {
|
||||
|
||||
TRACE_ERROR("USART_Read: Timed out.\n\r");
|
||||
return 0;
|
||||
}
|
||||
timeOut--;
|
||||
}
|
||||
}
|
||||
|
||||
return usart->US_RHR;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Reads data from an USART peripheral, filling the provided buffer until it
|
||||
/// becomes full. This function returns immediately with 1 if the buffer has
|
||||
/// been queued for transmission; otherwise 0.
|
||||
/// \param usart Pointer to an USART peripheral.
|
||||
/// \param buffer Pointer to the buffer where the received data will be stored.
|
||||
/// \param size Size of the data buffer (in bytes).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USART_ReadBuffer(AT91S_USART *usart,
|
||||
void *buffer,
|
||||
unsigned int size)
|
||||
{
|
||||
// Check if the first PDC bank is free
|
||||
if ((usart->US_RCR == 0) && (usart->US_RNCR == 0)) {
|
||||
|
||||
usart->US_RPR = (unsigned int) buffer;
|
||||
usart->US_RCR = size;
|
||||
usart->US_PTCR = AT91C_PDC_RXTEN;
|
||||
|
||||
return 1;
|
||||
}
|
||||
// Check if the second PDC bank is free
|
||||
else if (usart->US_RNCR == 0) {
|
||||
|
||||
usart->US_RNPR = (unsigned int) buffer;
|
||||
usart->US_RNCR = size;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns 1 if some data has been received and can be read from an USART;
|
||||
/// otherwise returns 0.
|
||||
/// \param usart Pointer to an AT91S_USART instance.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USART_IsDataAvailable(AT91S_USART *usart)
|
||||
{
|
||||
if ((usart->US_CSR & AT91C_US_RXRDY) != 0) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sets the filter value for the IRDA demodulator.
|
||||
/// \param pUsart Pointer to an AT91S_USART instance.
|
||||
/// \param filter Filter value.
|
||||
//------------------------------------------------------------------------------
|
||||
void USART_SetIrdaFilter(AT91S_USART *pUsart, unsigned char filter)
|
||||
{
|
||||
SANITY_CHECK(pUsart);
|
||||
|
||||
pUsart->US_IF = filter;
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \dir
|
||||
/// !Purpose
|
||||
///
|
||||
/// This module provides several definitions and methods for using an USART
|
||||
/// peripheral.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Enable the USART peripheral clock in the PMC.
|
||||
/// -# Enable the required USART PIOs (see pio.h).
|
||||
/// -# Configure the UART by calling USART_Configure.
|
||||
/// -# Enable the transmitter and/or the receiver of the USART using
|
||||
/// USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
|
||||
/// -# Send data through the USART using the USART_Write and
|
||||
/// USART_WriteBuffer methods.
|
||||
/// -# Receive data from the USART using the USART_Read and
|
||||
/// USART_ReadBuffer functions; the availability of data can be polled
|
||||
/// with USART_IsDataAvailable.
|
||||
/// -# Disable the transmitter and/or the receiver of the USART with
|
||||
/// USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USART_H
|
||||
#define USART_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <board.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USART modes"
|
||||
/// This page lists several common operating modes for an USART peripheral.
|
||||
///
|
||||
/// !Modes
|
||||
/// - USART_MODE_ASYNCHRONOUS
|
||||
/// - USART_MODE_IRDA
|
||||
|
||||
/// Basic asynchronous mode, i.e. 8 bits no parity.
|
||||
#define USART_MODE_ASYNCHRONOUS (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE)
|
||||
|
||||
/// IRDA mode
|
||||
#define USART_MODE_IRDA (AT91C_US_USMODE_IRDA | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_FILTER)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void USART_Configure(
|
||||
AT91S_USART *usart,
|
||||
unsigned int mode,
|
||||
unsigned int baudrate,
|
||||
unsigned int masterClock);
|
||||
|
||||
extern void USART_SetTransmitterEnabled(AT91S_USART *usart, unsigned char enabled);
|
||||
|
||||
extern void USART_SetReceiverEnabled(AT91S_USART *usart, unsigned char enabled);
|
||||
|
||||
extern void USART_Write(
|
||||
AT91S_USART *usart,
|
||||
unsigned short data,
|
||||
volatile unsigned int timeOut);
|
||||
|
||||
extern unsigned char USART_WriteBuffer(
|
||||
AT91S_USART *usart,
|
||||
void *buffer,
|
||||
unsigned int size);
|
||||
|
||||
extern unsigned short USART_Read(
|
||||
AT91S_USART *usart,
|
||||
volatile unsigned int timeOut);
|
||||
|
||||
extern unsigned char USART_ReadBuffer(
|
||||
AT91S_USART *usart,
|
||||
void *buffer,
|
||||
unsigned int size);
|
||||
|
||||
extern unsigned char USART_IsDataAvailable(AT91S_USART *usart);
|
||||
|
||||
extern void USART_SetIrdaFilter(AT91S_USART *pUsart, unsigned char filter);
|
||||
|
||||
#endif //#ifndef USART_H
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBConfigurationDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBConfigurationDescriptor class.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "USBConfigurationDescriptor.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the total length of a configuration, i.e. including the
|
||||
/// descriptors following it.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return Total length (in bytes) of the configuration.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int USBConfigurationDescriptor_GetTotalLength(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
return configuration->wTotalLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the number of interfaces in a configuration.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return Number of interfaces in configuration.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned char USBConfigurationDescriptor_GetNumInterfaces(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
return configuration->bNumInterfaces;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Indicates if the device is self-powered when in a given configuration.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return 1 if the device is self-powered when in the given configuration;
|
||||
/// otherwise 0.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned char USBConfigurationDescriptor_IsSelfPowered(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
if ((configuration->bmAttributes & (1 << 6)) != 0) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Parses the given Configuration descriptor (followed by relevant
|
||||
/// interface, endpoint and class-specific descriptors) into three arrays.
|
||||
/// *Each array must have its size equal or greater to the number of
|
||||
/// descriptors it stores plus one*. A null-value is inserted after the last
|
||||
/// descriptor of each type to indicate the array end.
|
||||
///
|
||||
/// Note that if the pointer to an array is null (0), nothing is stored in
|
||||
/// it.
|
||||
/// \param configuration Pointer to the start of the whole Configuration
|
||||
/// descriptor.
|
||||
/// \param interfaces Pointer to the Interface descriptor array.
|
||||
/// \param endpoints Pointer to the Endpoint descriptor array.
|
||||
/// \param others Pointer to the class-specific descriptor array.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBConfigurationDescriptor_Parse(
|
||||
const USBConfigurationDescriptor *configuration,
|
||||
USBInterfaceDescriptor **interfaces,
|
||||
USBEndpointDescriptor **endpoints,
|
||||
USBGenericDescriptor **others)
|
||||
{
|
||||
// Get size of configuration to parse
|
||||
int size = USBConfigurationDescriptor_GetTotalLength(configuration);
|
||||
size -= sizeof(USBConfigurationDescriptor);
|
||||
|
||||
// Start parsing descriptors
|
||||
USBGenericDescriptor *descriptor = (USBGenericDescriptor *) configuration;
|
||||
while (size > 0) {
|
||||
|
||||
// Get next descriptor
|
||||
descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
|
||||
size -= USBGenericDescriptor_GetLength(descriptor);
|
||||
|
||||
// Store descriptor in correponding array
|
||||
if (USBGenericDescriptor_GetType(descriptor)
|
||||
== USBGenericDescriptor_INTERFACE) {
|
||||
|
||||
if (interfaces) {
|
||||
|
||||
*interfaces = (USBInterfaceDescriptor *) descriptor;
|
||||
interfaces++;
|
||||
}
|
||||
}
|
||||
else if (USBGenericDescriptor_GetType(descriptor)
|
||||
== USBGenericDescriptor_ENDPOINT) {
|
||||
|
||||
if (endpoints) {
|
||||
|
||||
*endpoints = (USBEndpointDescriptor *) descriptor;
|
||||
endpoints++;
|
||||
}
|
||||
}
|
||||
else if (others) {
|
||||
|
||||
*others = descriptor;
|
||||
others++;
|
||||
}
|
||||
}
|
||||
|
||||
// Null-terminate arrays
|
||||
if (interfaces) {
|
||||
|
||||
*interfaces = 0;
|
||||
}
|
||||
if (endpoints) {
|
||||
|
||||
*endpoints = 0;
|
||||
}
|
||||
if (others) {
|
||||
|
||||
*others = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
!!!Purpose
|
||||
|
||||
Definitions and methods for USB configuration descriptor structures
|
||||
described by the USB specification.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare USBConfigurationDescriptor instance as a part
|
||||
of the configuration descriptors of a USB device.
|
||||
-# To get useful information (field values) from the defined USB device
|
||||
configuration descriptor, use
|
||||
- USBConfigurationDescriptor_GetTotalLength
|
||||
- USBConfigurationDescriptor_GetNumInterfaces
|
||||
- USBConfigurationDescriptor_IsSelfPowered
|
||||
-# To pase the defined USB device configuration descriptor, use
|
||||
- USBConfigurationDescriptor_Parse
|
||||
*/
|
||||
|
||||
#ifndef USBCONFIGURATIONDESCRIPTOR_H
|
||||
#define USBCONFIGURATIONDESCRIPTOR_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "USBGenericDescriptor.h"
|
||||
#include "USBInterfaceDescriptor.h"
|
||||
#include "USBEndpointDescriptor.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \page "USB device Attributes"
|
||||
///
|
||||
/// This page lists the codes of the usb attributes.
|
||||
///
|
||||
/// !Attributes
|
||||
/// - USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
|
||||
/// - USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
|
||||
/// - USBConfigurationDescriptor_BUSPOWERED_RWAKEUP
|
||||
/// - USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
|
||||
/// - USBConfigurationDescriptor_POWER
|
||||
|
||||
/// Device is bus-powered and not support remote wake-up.
|
||||
#define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80
|
||||
/// Device is self-powered and not support remote wake-up.
|
||||
#define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0
|
||||
/// Device is bus-powered and supports remote wake-up.
|
||||
#define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0
|
||||
/// Device is self-powered and supports remote wake-up.
|
||||
#define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0
|
||||
|
||||
/// Calculates the value of the power consumption field given the value in mA.
|
||||
/// \param power The power consumption value in mA
|
||||
/// \return The value that should be set to the field in descriptor
|
||||
#define USBConfigurationDescriptor_POWER(power) (power / 2)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// USB standard configuration descriptor structure.
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBDESC_CONFIGURATION of "USB Descriptor types").
|
||||
unsigned char bDescriptorType;
|
||||
/// Length of all descriptors returned along with this configuration
|
||||
/// descriptor.
|
||||
unsigned short wTotalLength;
|
||||
/// Number of interfaces in this configuration.
|
||||
unsigned char bNumInterfaces;
|
||||
/// Value for selecting this configuration.
|
||||
unsigned char bConfigurationValue;
|
||||
/// Index of the configuration string descriptor.
|
||||
unsigned char iConfiguration;
|
||||
/// Configuration characteristics.
|
||||
unsigned char bmAttributes;
|
||||
/// Maximum power consumption of the device when in this configuration.
|
||||
unsigned char bMaxPower;
|
||||
|
||||
} __attribute__ ((packed)) USBConfigurationDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int USBConfigurationDescriptor_GetTotalLength(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern unsigned char USBConfigurationDescriptor_GetNumInterfaces(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern unsigned char USBConfigurationDescriptor_IsSelfPowered(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern void USBConfigurationDescriptor_Parse(
|
||||
const USBConfigurationDescriptor *configuration,
|
||||
USBInterfaceDescriptor **interfaces,
|
||||
USBEndpointDescriptor **endpoints,
|
||||
USBGenericDescriptor **others);
|
||||
|
||||
#endif //#ifndef USBCONFIGURATIONDESCRIPTOR_H
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating USB device descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare a USBDeviceDescriptor instance as the device descriptor of a
|
||||
USB device.
|
||||
*/
|
||||
|
||||
#ifndef USBDEVICEDESCRIPTOR_H
|
||||
#define USBDEVICEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB release numbers"
|
||||
///
|
||||
/// This page lists the codes of USB release numbers.
|
||||
///
|
||||
/// !Code
|
||||
/// - USBDeviceDescriptor_USB2_00
|
||||
|
||||
/// The device supports USB 2.00.
|
||||
#define USBDeviceDescriptor_USB2_00 0x0200
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard device descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of this descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_DEVICE).
|
||||
unsigned char bDescriptorType;
|
||||
/// USB specification release number in BCD format.
|
||||
unsigned short bcdUSB;
|
||||
/// Device class code.
|
||||
unsigned char bDeviceClass;
|
||||
/// Device subclass code.
|
||||
unsigned char bDeviceSubClass;
|
||||
/// Device protocol code.
|
||||
unsigned char bDeviceProtocol;
|
||||
/// Maximum packet size of endpoint 0 (in bytes).
|
||||
unsigned char bMaxPacketSize0;
|
||||
/// Vendor ID.
|
||||
unsigned short idVendor;
|
||||
/// Product ID.
|
||||
unsigned short idProduct;
|
||||
/// Device release number in BCD format.
|
||||
unsigned short bcdDevice;
|
||||
/// Index of the manufacturer string descriptor.
|
||||
unsigned char iManufacturer;
|
||||
/// Index of the product string descriptor.
|
||||
unsigned char iProduct;
|
||||
/// Index of the serial number string descriptor.
|
||||
unsigned char iSerialNumber;
|
||||
/// Number of possible configurations for the device.
|
||||
unsigned char bNumConfigurations;
|
||||
|
||||
} __attribute__ ((packed)) USBDeviceDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDEVICEDESCRIPTOR_H
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating USB device qualifier descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare a USBDeviceQualifierDescriptor instance as the device qualifier
|
||||
descriptor of a USB device.
|
||||
*/
|
||||
|
||||
#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
#define USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Alternate device descriptor indicating the capabilities of the device
|
||||
/// in full-speed, if currently in high-speed; or in high-speed, if it is
|
||||
/// currently in full-speed. Only relevant for devices supporting the
|
||||
/// high-speed mode.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBDESC_DEVICE_QUALIFIER or "USB device types").
|
||||
unsigned char bDescriptorType;
|
||||
/// USB specification release number (in BCD format).
|
||||
unsigned short bcdUSB;
|
||||
/// Device class code.
|
||||
unsigned char bDeviceClass;
|
||||
/// Device subclass code.
|
||||
unsigned char bDeviceSubClass;
|
||||
/// Device protocol code.
|
||||
unsigned char bDeviceProtocol;
|
||||
/// Maximum packet size of endpoint 0.
|
||||
unsigned char bMaxPacketSize0;
|
||||
/// Number of possible configurations for the device.
|
||||
unsigned char bNumConfigurations;
|
||||
/// Reserved.
|
||||
unsigned char bReserved;
|
||||
|
||||
} __attribute__ ((packed)) USBDeviceQualifierDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBEndpointDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBEndpointDescriptor class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBEndpointDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the number of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetNumber(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bEndpointAddress & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the direction of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint direction (see <Endpoint directions>).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetDirection(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
if ((endpoint->bEndpointAddress & 0x80) != 0) {
|
||||
|
||||
return USBEndpointDescriptor_IN;
|
||||
}
|
||||
else {
|
||||
|
||||
return USBEndpointDescriptor_OUT;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint type (see <Endpoint types>).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetType(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bmAttributes & 0x3;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the maximum size of a packet (in bytes) on an endpoint given
|
||||
/// its descriptor.
|
||||
/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Maximum packet size of endpoint.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBEndpointDescriptor_GetMaxPacketSize(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->wMaxPacketSize;
|
||||
}
|
||||
|
|
@ -0,0 +1,221 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for handling USB endpoint descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare USBEndpointDescriptor instance as a part of the
|
||||
configuration descriptors of a USB device.
|
||||
-# To get useful information (field values) from the defined USB device
|
||||
endpoint descriptor (to configure hardware for endpoints, etc), use
|
||||
- USBEndpointDescriptor_GetNumber
|
||||
- USBEndpointDescriptor_GetDirection
|
||||
- USBEndpointDescriptor_GetType
|
||||
- USBEndpointDescriptor_GetMaxPacketSize
|
||||
*/
|
||||
|
||||
#ifndef USBENDPOINTDESCRIPTOR_H
|
||||
#define USBENDPOINTDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint definitions"
|
||||
///
|
||||
/// This page lists definitions and macro for endpoint descriptors.
|
||||
///
|
||||
/// - USB Endpoint directions
|
||||
/// - USBEndpointDescriptor_OUT
|
||||
/// - USBEndpointDescriptor_IN
|
||||
///
|
||||
/// - USB Endpoint types
|
||||
/// - USBEndpointDescriptor_CONTROL
|
||||
/// - USBEndpointDescriptor_ISOCHRONOUS
|
||||
/// - USBEndpointDescriptor_BULK
|
||||
/// - USBEndpointDescriptor_INTERRUPT
|
||||
///
|
||||
/// - USB Endpoint maximun sizes
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
|
||||
///
|
||||
/// - USB Endpoint address define
|
||||
/// - USBEndpointDescriptor_ADDRESS
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint directions"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint directions.
|
||||
///
|
||||
/// !Directions
|
||||
/// - USBEndpointDescriptor_OUT
|
||||
/// - USBEndpointDescriptor_IN
|
||||
|
||||
/// Endpoint receives data from the host.
|
||||
#define USBEndpointDescriptor_OUT 0
|
||||
/// Endpoint sends data to the host.
|
||||
#define USBEndpointDescriptor_IN 1
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint types"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint types.
|
||||
///
|
||||
/// !Types
|
||||
/// - USBEndpointDescriptor_CONTROL
|
||||
/// - USBEndpointDescriptor_ISOCHRONOUS
|
||||
/// - USBEndpointDescriptor_BULK
|
||||
/// - USBEndpointDescriptor_INTERRUPT
|
||||
|
||||
/// Control endpoint type.
|
||||
#define USBEndpointDescriptor_CONTROL 0
|
||||
/// Isochronous endpoint type.
|
||||
#define USBEndpointDescriptor_ISOCHRONOUS 1
|
||||
/// Bulk endpoint type.
|
||||
#define USBEndpointDescriptor_BULK 2
|
||||
/// Interrupt endpoint type.
|
||||
#define USBEndpointDescriptor_INTERRUPT 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint maximun sizes"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint maximun sizes.
|
||||
///
|
||||
/// !Sizes
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
|
||||
|
||||
/// Maximum size for a full-speed control endpoint.
|
||||
#define USBEndpointDescriptor_MAXCTRLSIZE_FS 64
|
||||
/// Maximum size for a high-speed control endpoint.
|
||||
#define USBEndpointDescriptor_MAXCTRLSIZE_HS 64
|
||||
/// Maximum size for a full-speed bulk endpoint.
|
||||
#define USBEndpointDescriptor_MAXBULKSIZE_FS 64
|
||||
/// Maximum size for a high-speed bulk endpoint.
|
||||
#define USBEndpointDescriptor_MAXBULKSIZE_HS 512
|
||||
/// Maximum size for a full-speed interrupt endpoint.
|
||||
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64
|
||||
/// Maximum size for a high-speed interrupt endpoint.
|
||||
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024
|
||||
/// Maximum size for a full-speed isochronous endpoint.
|
||||
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023
|
||||
/// Maximum size for a high-speed isochronous endpoint.
|
||||
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint address define"
|
||||
///
|
||||
/// This page lists macro for USB endpoint address definition.
|
||||
///
|
||||
/// !Macro
|
||||
/// - USBEndpointDescriptor_ADDRESS
|
||||
|
||||
/// Calculates the address of an endpoint given its number and direction
|
||||
/// \param direction USB endpoint direction definition
|
||||
/// \param number USB endpoint number
|
||||
/// \return The value used to set the endpoint descriptor based on input number
|
||||
/// and direction
|
||||
#define USBEndpointDescriptor_ADDRESS(direction, number) \
|
||||
(((direction & 0x01) << 7) | (number & 0xF))
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard endpoint descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (<USBGenericDescriptor_ENDPOINT>).
|
||||
unsigned char bDescriptorType;
|
||||
/// Address and direction of the endpoint.
|
||||
unsigned char bEndpointAddress;
|
||||
/// Endpoint type and additional characteristics (for isochronous endpoints).
|
||||
unsigned char bmAttributes;
|
||||
/// Maximum packet size (in bytes) of the endpoint.
|
||||
unsigned short wMaxPacketSize;
|
||||
/// Polling rate of the endpoint.
|
||||
unsigned char bInterval;
|
||||
|
||||
} __attribute__ ((packed)) USBEndpointDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetNumber(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetDirection(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetType(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned short USBEndpointDescriptor_GetMaxPacketSize(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
#endif //#ifndef USBENDPOINTDESCRIPTOR_H
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBFeatureRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBFeatureRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBFeatureRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the feature selector of a given CLEAR_FEATURE or SET_FEATURE
|
||||
/// request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Feature selector.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBFeatureRequest_GetFeatureSelector(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the test that the device must undertake following a
|
||||
/// SET_FEATURE request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Test selector.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBFeatureRequest_GetTestSelector(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetIndex(request) >> 8) & 0xFF;
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating CLEAR_FEATURE and SET_FEATURE
|
||||
requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- To get USB feature request information (field values) from the
|
||||
USBGenericRequest instance, use
|
||||
- USBFeatureRequest_GetFeatureSelector
|
||||
- USBFeatureRequest_GetTestSelector
|
||||
*/
|
||||
|
||||
#ifndef USBFEATUREREQUEST_H
|
||||
#define USBFEATUREREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Feature Request definitions"
|
||||
///
|
||||
/// This page lists codes of USB Feature Request
|
||||
///
|
||||
/// - USB Feature selectors
|
||||
/// - USBFeatureRequest_ENDPOINTHALT
|
||||
/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
|
||||
/// - USBFeatureRequest_TESTMODE
|
||||
///
|
||||
/// - USB Test mode selectors
|
||||
/// - USBFeatureRequest_TESTJ
|
||||
/// - USBFeatureRequest_TESTK
|
||||
/// - USBFeatureRequest_TESTSE0NAK
|
||||
/// - USBFeatureRequest_TESTPACKET
|
||||
/// - USBFeatureRequest_TESTFORCEENABLE
|
||||
/// - USBFeatureRequest_TESTSENDZLP
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Feature selectors"
|
||||
///
|
||||
/// This page lists codes of USB feature selectors.
|
||||
///
|
||||
/// !Selectors
|
||||
/// - USBFeatureRequest_ENDPOINTHALT
|
||||
/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
|
||||
/// - USBFeatureRequest_TESTMODE
|
||||
|
||||
/// Halt feature of an endpoint.
|
||||
#define USBFeatureRequest_ENDPOINTHALT 0
|
||||
/// Remote wake-up feature of the device.
|
||||
#define USBFeatureRequest_DEVICEREMOTEWAKEUP 1
|
||||
/// Test mode of the device.
|
||||
#define USBFeatureRequest_TESTMODE 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Test mode selectors"
|
||||
///
|
||||
/// This page lists codes of USB high speed test mode selectors.
|
||||
///
|
||||
/// !Selectors
|
||||
/// - USBFeatureRequest_TESTJ
|
||||
/// - USBFeatureRequest_TESTK
|
||||
/// - USBFeatureRequest_TESTSE0NAK
|
||||
/// - USBFeatureRequest_TESTPACKET
|
||||
/// - USBFeatureRequest_TESTFORCEENABLE
|
||||
/// - USBFeatureRequest_TESTSENDZLP
|
||||
|
||||
/// Tests the high-output drive level on the D+ line.
|
||||
#define USBFeatureRequest_TESTJ 1
|
||||
/// Tests the high-output drive level on the D- line.
|
||||
#define USBFeatureRequest_TESTK 2
|
||||
/// Tests the output impedance, low-level output voltage and loading
|
||||
/// characteristics.
|
||||
#define USBFeatureRequest_TESTSE0NAK 3
|
||||
/// Tests rise and fall times, eye patterns and jitter.
|
||||
#define USBFeatureRequest_TESTPACKET 4
|
||||
/// Tests the hub disconnect detection.
|
||||
#define USBFeatureRequest_TESTFORCEENABLE 5
|
||||
/// Send a ZLP in Test Mode.
|
||||
#define USBFeatureRequest_TESTSENDZLP 6
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBFeatureRequest_GetFeatureSelector(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBFeatureRequest_GetTestSelector(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBFEATUREREQUEST_H
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGenericDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGenericDescriptor class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBGenericDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the length of a descriptor.
|
||||
/// \param descriptor Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Length of descriptor in bytes.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int USBGenericDescriptor_GetLength(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return descriptor->bLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of a descriptor.
|
||||
/// \param descriptor Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Type of descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericDescriptor_GetType(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return descriptor->bDescriptorType;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns a pointer to the descriptor right after the given one, when
|
||||
/// parsing a Configuration descriptor.
|
||||
/// \param descriptor - Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Pointer to the next descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return (USBGenericDescriptor *)
|
||||
(((char *) descriptor) + USBGenericDescriptor_GetLength(descriptor));
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Definition of a generic USB descriptor class.
|
||||
///
|
||||
/// !!!Usage
|
||||
///
|
||||
/// -# Declare or access USB descriptors by USBGenericDescriptor instance.
|
||||
/// -# To get usful information (field values) from the USB descriptors, use
|
||||
/// - USBGenericDescriptor_GetLength
|
||||
/// - USBGenericDescriptor_GetType
|
||||
/// -# To scan the descriptors, use
|
||||
/// - USBGenericDescriptor_GetNextDescriptor
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USBGENERICDESCRIPTOR_H
|
||||
#define USBGENERICDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Descriptor types"
|
||||
///
|
||||
/// This page lists the codes of the usb descriptor types
|
||||
///
|
||||
/// !Types
|
||||
/// - USBGenericDescriptor_DEVICE
|
||||
/// - USBGenericDescriptor_CONFIGURATION
|
||||
/// - USBGenericDescriptor_STRING
|
||||
/// - USBGenericDescriptor_INTERFACE
|
||||
/// - USBGenericDescriptor_ENDPOINT
|
||||
/// - USBGenericDescriptor_DEVICEQUALIFIER
|
||||
/// - USBGenericDescriptor_OTHERSPEEDCONFIGURATION
|
||||
/// - USBGenericDescriptor_INTERFACEPOWER
|
||||
/// - USBGenericDescriptor_OTG
|
||||
/// - USBGenericDescriptor_DEBUG
|
||||
/// - USBGenericDescriptor_INTERFACEASSOCIATION
|
||||
|
||||
/// Device descriptor type.
|
||||
#define USBGenericDescriptor_DEVICE 1
|
||||
/// Configuration descriptor type.
|
||||
#define USBGenericDescriptor_CONFIGURATION 2
|
||||
/// String descriptor type.
|
||||
#define USBGenericDescriptor_STRING 3
|
||||
/// Interface descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACE 4
|
||||
/// Endpoint descriptor type.
|
||||
#define USBGenericDescriptor_ENDPOINT 5
|
||||
/// Device qualifier descriptor type.
|
||||
#define USBGenericDescriptor_DEVICEQUALIFIER 6
|
||||
/// Other speed configuration descriptor type.
|
||||
#define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7
|
||||
/// Interface power descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACEPOWER 8
|
||||
/// On-The-Go descriptor type.
|
||||
#define USBGenericDescriptor_OTG 9
|
||||
/// Debug descriptor type.
|
||||
#define USBGenericDescriptor_DEBUG 10
|
||||
/// Interface association descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACEASSOCIATION 11
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
/// Holds the few fields shared by all USB descriptors.
|
||||
typedef struct {
|
||||
|
||||
/// Length of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type.
|
||||
unsigned char bDescriptorType;
|
||||
|
||||
} __attribute__ ((packed)) USBGenericDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int USBGenericDescriptor_GetLength(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
extern unsigned char USBGenericDescriptor_GetType(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
#endif //#ifndef USBGENERICDESCRIPTOR_H
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGenericRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGenericRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return "USB Request Types"
|
||||
//------------------------------------------------------------------------------
|
||||
extern unsigned char USBGenericRequest_GetType(const USBGenericRequest *request)
|
||||
{
|
||||
return ((request->bmRequestType >> 5) & 0x3);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the request code of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request code.
|
||||
/// \sa "USB Request Codes"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetRequest(const USBGenericRequest *request)
|
||||
{
|
||||
return request->bRequest;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the wValue field of the given request.
|
||||
/// \param request - Pointer to a USBGenericRequest instance.
|
||||
/// \return Request value.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetValue(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wValue;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the wIndex field of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request index;
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetIndex(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wIndex;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the expected length of the data phase following a request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Length of data phase.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetLength(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the endpoint number targetted by a given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetEndpointNumber(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetIndex(request) & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the intended recipient of a given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request recipient.
|
||||
/// \sa "USB Request Recipients"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetRecipient(const USBGenericRequest *request)
|
||||
{
|
||||
// Recipient is in bits [0..4] of the bmRequestType field
|
||||
return request->bmRequestType & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the direction of the data transfer following the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Transfer direction.
|
||||
/// \sa "USB Request Directions"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetDirection(const USBGenericRequest *request)
|
||||
{
|
||||
// Transfer direction is located in bit D7 of the bmRequestType field
|
||||
if ((request->bmRequestType & 0x80) != 0) {
|
||||
|
||||
return USBGenericRequest_IN;
|
||||
}
|
||||
else {
|
||||
|
||||
return USBGenericRequest_OUT;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,244 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of the USBGenericRequest class and its methods.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare or access USB requests by USBGenericRequest instance.
|
||||
-# To get usful information (field values) from the USB requests, use
|
||||
- USBGenericRequest_GetType
|
||||
- USBGenericRequest_GetRequest
|
||||
- USBGenericRequest_GetValue
|
||||
- USBGenericRequest_GetIndex
|
||||
- USBGenericRequest_GetLength
|
||||
- USBGenericRequest_GetEndpointNumber
|
||||
- USBGenericRequest_GetRecipient
|
||||
- USBGenericRequest_GetDirection
|
||||
*/
|
||||
|
||||
#ifndef USBGENERICREQUEST_H
|
||||
#define USBGENERICREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Generic Request definitions"
|
||||
///
|
||||
/// This page lists the codes of USB generic request.
|
||||
///
|
||||
/// - USB Request codes
|
||||
/// - USBGenericRequest_GETSTATUS
|
||||
/// - USBGenericRequest_CLEARFEATURE
|
||||
/// - USBGenericRequest_SETFEATURE
|
||||
/// - USBGenericRequest_SETADDRESS
|
||||
/// - USBGenericRequest_GETDESCRIPTOR
|
||||
/// - USBGenericRequest_SETDESCRIPTOR
|
||||
/// - USBGenericRequest_GETCONFIGURATION
|
||||
/// - USBGenericRequest_SETCONFIGURATION
|
||||
/// - USBGenericRequest_GETINTERFACE
|
||||
/// - USBGenericRequest_SETINTERFACE
|
||||
/// - USBGenericRequest_SYNCHFRAME
|
||||
///
|
||||
/// - USB Request Recipients
|
||||
/// - USBGenericRequest_DEVICE
|
||||
/// - USBGenericRequest_INTERFACE
|
||||
/// - USBGenericRequest_ENDPOINT
|
||||
/// - USBGenericRequest_OTHER
|
||||
///
|
||||
/// - USB Request Types
|
||||
/// - USBGenericRequest_STANDARD
|
||||
/// - USBGenericRequest_CLASS
|
||||
/// - USBGenericRequest_VENDOR
|
||||
///
|
||||
/// - USB Request Directions
|
||||
/// - USBGenericRequest_IN
|
||||
/// - USBGenericRequest_OUT
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request codes"
|
||||
///
|
||||
/// This page lists the USB generic request codes.
|
||||
///
|
||||
/// !Codes
|
||||
/// - USBGenericRequest_GETSTATUS
|
||||
/// - USBGenericRequest_CLEARFEATURE
|
||||
/// - USBGenericRequest_SETFEATURE
|
||||
/// - USBGenericRequest_SETADDRESS
|
||||
/// - USBGenericRequest_GETDESCRIPTOR
|
||||
/// - USBGenericRequest_SETDESCRIPTOR
|
||||
/// - USBGenericRequest_GETCONFIGURATION
|
||||
/// - USBGenericRequest_SETCONFIGURATION
|
||||
/// - USBGenericRequest_GETINTERFACE
|
||||
/// - USBGenericRequest_SETINTERFACE
|
||||
/// - USBGenericRequest_SYNCHFRAME
|
||||
|
||||
/// GET_STATUS request code.
|
||||
#define USBGenericRequest_GETSTATUS 0
|
||||
/// CLEAR_FEATURE request code.
|
||||
#define USBGenericRequest_CLEARFEATURE 1
|
||||
/// SET_FEATURE request code.
|
||||
#define USBGenericRequest_SETFEATURE 3
|
||||
/// SET_ADDRESS request code.
|
||||
#define USBGenericRequest_SETADDRESS 5
|
||||
/// GET_DESCRIPTOR request code.
|
||||
#define USBGenericRequest_GETDESCRIPTOR 6
|
||||
/// SET_DESCRIPTOR request code.
|
||||
#define USBGenericRequest_SETDESCRIPTOR 7
|
||||
/// GET_CONFIGURATION request code.
|
||||
#define USBGenericRequest_GETCONFIGURATION 8
|
||||
/// SET_CONFIGURATION request code.
|
||||
#define USBGenericRequest_SETCONFIGURATION 9
|
||||
/// GET_INTERFACE request code.
|
||||
#define USBGenericRequest_GETINTERFACE 10
|
||||
/// SET_INTERFACE request code.
|
||||
#define USBGenericRequest_SETINTERFACE 11
|
||||
/// SYNCH_FRAME request code.
|
||||
#define USBGenericRequest_SYNCHFRAME 12
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Recipients"
|
||||
///
|
||||
/// This page lists codes of USB request recipients.
|
||||
///
|
||||
/// !Recipients
|
||||
/// - USBGenericRequest_DEVICE
|
||||
/// - USBGenericRequest_INTERFACE
|
||||
/// - USBGenericRequest_ENDPOINT
|
||||
/// - USBGenericRequest_OTHER
|
||||
|
||||
/// Recipient is the whole device.
|
||||
#define USBGenericRequest_DEVICE 0
|
||||
/// Recipient is an interface.
|
||||
#define USBGenericRequest_INTERFACE 1
|
||||
/// Recipient is an endpoint.
|
||||
#define USBGenericRequest_ENDPOINT 2
|
||||
/// Recipient is another entity.
|
||||
#define USBGenericRequest_OTHER 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Types"
|
||||
///
|
||||
/// This page lists codes of USB request types.
|
||||
///
|
||||
/// !Types
|
||||
/// - USBGenericRequest_STANDARD
|
||||
/// - USBGenericRequest_CLASS
|
||||
/// - USBGenericRequest_VENDOR
|
||||
|
||||
/// Request is standard.
|
||||
#define USBGenericRequest_STANDARD 0
|
||||
/// Request is class-specific.
|
||||
#define USBGenericRequest_CLASS 1
|
||||
/// Request is vendor-specific.
|
||||
#define USBGenericRequest_VENDOR 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Directions"
|
||||
///
|
||||
/// This page lists codes of USB request directions.
|
||||
///
|
||||
/// !Directions
|
||||
/// - USBGenericRequest_IN
|
||||
/// - USBGenericRequest_OUT
|
||||
|
||||
/// Transfer occurs from device to the host.
|
||||
#define USBGenericRequest_OUT 0
|
||||
/// Transfer occurs from the host to the device.
|
||||
#define USBGenericRequest_IN 1
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Generic USB SETUP request sent over Control endpoints.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Type of request
|
||||
/// \sa "USB Request Recipients"
|
||||
/// \sa "USB Request Types"
|
||||
/// \sa "USB Request Directions"
|
||||
unsigned char bmRequestType:8;
|
||||
/// Request code
|
||||
/// \sa "USB Request Codes"
|
||||
unsigned char bRequest:8;
|
||||
/// Request-specific value parameter.
|
||||
unsigned short wValue:16;
|
||||
/// Request-specific index parameter.
|
||||
unsigned short wIndex:16;
|
||||
/// Expected length (in bytes) of the data phase.
|
||||
unsigned short wLength:16;
|
||||
|
||||
} USBGenericRequest;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBGenericRequest_GetType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBGenericRequest_GetRequest(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetValue(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetIndex(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetLength(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetEndpointNumber(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetRecipient(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetDirection(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBGENERICREQUEST_H
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGetDescriptorRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGetDescriptorRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBGetDescriptorRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of the descriptor requested by the host given the
|
||||
/// corresponding GET_DESCRIPTOR request.
|
||||
/// \param request Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Type of the requested descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGetDescriptorRequest_GetDescriptorType(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
// Requested descriptor type is in the high-byte of the wValue field
|
||||
return (USBGenericRequest_GetValue(request) >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the index of the requested descriptor, given the corresponding
|
||||
/// GET_DESCRIPTOR request.
|
||||
/// \param request Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Index of the requested descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
// Requested descriptor index if in the low byte of the wValue field
|
||||
return USBGenericRequest_GetValue(request) & 0xFF;
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of the USBGetDescriptorRequest class.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a GET_DESCRIPTOR request has been received, retrive the useful
|
||||
values with following functions:
|
||||
- USBGetDescriptorRequest_GetDescriptorType: the descriptor type
|
||||
- USBGetDescriptorRequest_GetDescriptorIndex: the index of the requested
|
||||
descriptor
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBGETDESCRIPTORREQUEST_H
|
||||
#define USBGETDESCRIPTORREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBGetDescriptorRequest_GetDescriptorType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBGETDESCRIPTORREQUEST_H
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating USB interface descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare USBInterfaceDescriptor instance as a part of the configuration
|
||||
descriptors of a USB device.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBINTERFACEDESCRIPTOR_H
|
||||
#define USBINTERFACEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard interface descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_INTERFACE).
|
||||
unsigned char bDescriptorType;
|
||||
/// Number of the interface in its configuration.
|
||||
unsigned char bInterfaceNumber;
|
||||
/// Value to select this alternate interface setting.
|
||||
unsigned char bAlternateSetting;
|
||||
/// Number of endpoints used by the inteface (excluding endpoint 0).
|
||||
unsigned char bNumEndpoints;
|
||||
/// Interface class code.
|
||||
unsigned char bInterfaceClass;
|
||||
/// Interface subclass code.
|
||||
unsigned char bInterfaceSubClass;
|
||||
/// Interface protocol code.
|
||||
unsigned char bInterfaceProtocol;
|
||||
/// Index of the interface string descriptor.
|
||||
unsigned char iInterface;
|
||||
|
||||
} __attribute__ ((packed)) USBInterfaceDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBINTERFACEDESCRIPTOR_H
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBInterfaceRequest
|
||||
|
||||
About: Purpose
|
||||
Implementation of USBInterfaceRequest class methods.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBInterfaceRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates which interface is targetted by a GET_INTERFACE or
|
||||
/// SET_INTERFACE request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Interface number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBInterfaceRequest_GetInterface(const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetIndex(request) & 0xFF);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the new alternate setting that the interface targetted by a
|
||||
/// SET_INTERFACE request should use.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return New active setting for the interface.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBInterfaceRequest_GetAlternateSetting(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetValue(request) & 0xFF);
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions for manipulating SET_INTERFACE and GET_INTERFACE request.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# After a SET_INTERFACE request has been received, retrieve the
|
||||
target interface using USBInterfaceRequest_GetInterface and its
|
||||
new alternate setting with USBInterfaceRequest_GetAlternateSetting.
|
||||
-# After a GET_INTERFACE request has been received, retrieve the target
|
||||
interface using USBInterfaceRequest_GetInterface.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBINTERFACEREQUEST_H
|
||||
#define USBINTERFACEREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBInterfaceRequest_GetInterface(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBInterfaceRequest_GetAlternateSetting(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBINTERFACEREQUEST_H
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBSetAddressRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBSetAddressRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBSetAddressRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the address that the device must take in response to a
|
||||
/// SET_ADDRESS request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return New device address.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBSetAddressRequest_GetAddress(const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request) & 0x7F;
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating SET_ADDRESS USB requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a SET_ADDRESS request has been received, retrive the new address
|
||||
value with USBSetAddressRequest_GetAddress.
|
||||
*/
|
||||
|
||||
#ifndef USBSETADDRESSREQUEST_H
|
||||
#define USBSETADDRESSREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBSetAddressRequest_GetAddress(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBSETADDRESSREQUEST_H
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBSetConfigurationRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBSetConfigurationRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBSetConfigurationRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the number of the configuration that should be set in response
|
||||
/// to the given SET_CONFIGURATION request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Number of the requested configuration.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBSetConfigurationRequest_GetConfiguration(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request);
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for the Set Configuration request.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a SET_CONFIGURATION request has been received, retrive the new
|
||||
configuration value with USBSetConfigurationRequest_GetConfiguration.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBSETCONFIGURATIONREQUEST_H
|
||||
#define USBSETCONFIGURATIONREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBSetConfigurationRequest_GetConfiguration(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBSETCONFIGURATIONREQUEST_H
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Definition of a class for manipulating String descriptors.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USBSTRINGDESCRIPTOR_H
|
||||
#define USBSTRINGDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB String Descriptor definitions"
|
||||
///
|
||||
/// This page lists the codes and macros for USB string descriptor definition.
|
||||
///
|
||||
/// !Language IDs
|
||||
/// - USBStringDescriptor_ENGLISH_US
|
||||
///
|
||||
/// !String Descriptor Length
|
||||
/// - USBStringDescriptor_LENGTH
|
||||
///
|
||||
/// !ASCII to UNICODE convertion
|
||||
/// - USBStringDescriptor_UNICODE
|
||||
|
||||
/// Language ID for US english.
|
||||
#define USBStringDescriptor_ENGLISH_US 0x09, 0x04
|
||||
|
||||
/// Calculates the length of a string descriptor given the number of ascii
|
||||
/// characters/language IDs in it.
|
||||
/// \param length The ascii format string length.
|
||||
/// \return The actual data length in bytes.
|
||||
#define USBStringDescriptor_LENGTH(length) ((length) * 2 + 2)
|
||||
/// Converts an ascii character to its unicode representation.
|
||||
/// \param ascii The ASCII character to convert
|
||||
/// \return A 2-byte-array for the UNICODE based on given ASCII
|
||||
#define USBStringDescriptor_UNICODE(ascii) (ascii), 0
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef USBSTRINGDESCRIPTOR_H
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,378 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of methods for using a CCID device driver.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# CCIDDriver_Initialize
|
||||
/// -# CCID_Read
|
||||
/// -# CCID_Write
|
||||
/// -# CCID_SmartCardRequest
|
||||
/// -# CCID_Insertion
|
||||
/// -# CCID_Removal
|
||||
/// -# RDRtoPCHardwareError
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef CCID_DRIVER_H
|
||||
#define CCID_DRIVER_H
|
||||
|
||||
/// For reference, the absolute maximum block size
|
||||
/// for a TPDU T=0 block is 260 bytes (5 bytes command; 255 bytes data), or
|
||||
/// for a TPDU T=1 block is 259 bytes, or
|
||||
/// for a short APDU T=1 block is 261 bytes, or
|
||||
/// for an extended APDU T=1 block is 65544 bytes.
|
||||
#define ABDATA_SIZE 260
|
||||
|
||||
/// define protocol T=0
|
||||
#define PROTOCOL_TO 0
|
||||
/// define protocol T=1
|
||||
#define PROTOCOL_T1 1
|
||||
|
||||
/// define for dwFeatures see Table 5.1-1 Smart Card Device Class Descriptors
|
||||
/// No special characteristics
|
||||
#define CCID_FEATURES_NADA 0x00000000
|
||||
/// Automatic parameter configuration based on ATR data
|
||||
#define CCID_FEATURES_AUTO_PCONF 0x00000002
|
||||
/// Automatic activation of ICC on inserting
|
||||
#define CCID_FEATURES_AUTO_ACTIV 0x00000004
|
||||
/// Automatic ICC voltage selection
|
||||
#define CCID_FEATURES_AUTO_VOLT 0x00000008
|
||||
/// Automatic ICC clock frequency change according to active parameters provided
|
||||
/// by the Host or self determined
|
||||
#define CCID_FEATURES_AUTO_CLOCK 0x00000010
|
||||
/// Automatic baud rate change according to active parameters provided by the
|
||||
/// Host or self determined
|
||||
#define CCID_FEATURES_AUTO_BAUD 0x00000020
|
||||
/// Automatic parameters negotiation made by the CCID (use of warm or cold
|
||||
/// resets or PPS according to a manufacturer proprietary algorithm to select
|
||||
/// the communication parameters with the ICC)
|
||||
#define CCID_FEATURES_AUTO_PNEGO 0x00000040
|
||||
/// Automatic PPS made by the CCID according to the active parameters
|
||||
#define CCID_FEATURES_AUTO_PPS 0x00000080
|
||||
/// CCID can set ICC in clock stop mode
|
||||
#define CCID_FEATURES_ICCSTOP 0x00000100
|
||||
/// NAD value other than 00 accepted (T=1 protocol in use)
|
||||
#define CCID_FEATURES_NAD 0x00000200
|
||||
/// Automatic IFSD exchange as first exchange (T=1 protocol in use)
|
||||
#define CCID_FEATURES_AUTO_IFSD 0x00000400
|
||||
/// TPDU level exchanges with CCID
|
||||
#define CCID_FEATURES_EXC_TPDU 0x00010000
|
||||
/// Short APDU level exchange with CCID
|
||||
#define CCID_FEATURES_EXC_SAPDU 0x00020000
|
||||
/// Short and Extended APDU level exchange with CCID
|
||||
#define CCID_FEATURES_EXC_APDU 0x00040000
|
||||
/// USB Wake up signaling supported on card insertion and removal
|
||||
#define CCID_FEATURES_WAKEUP 0x00100000
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Bulk CCID Message header structure
|
||||
typedef struct
|
||||
{
|
||||
unsigned char bMessageType;
|
||||
/// Message-specific data length
|
||||
unsigned long wLength;
|
||||
/// Identifies the slot number for this command
|
||||
unsigned char bSlot;
|
||||
/// Sequence number for command.
|
||||
unsigned char bSeq;
|
||||
/// Slot status register
|
||||
unsigned char bStatus;
|
||||
/// Slot error
|
||||
unsigned char bError;
|
||||
/// specific register
|
||||
unsigned char bSpecific;
|
||||
/// Data block sent to the CCID.
|
||||
unsigned char abData[ABDATA_SIZE];
|
||||
unsigned char bSizeToSend;
|
||||
} __attribute__ ((packed)) S_ccid_bulk_in_header;
|
||||
|
||||
/// 6.1 Bulk Transfers
|
||||
typedef struct
|
||||
{
|
||||
unsigned char bMessageType;
|
||||
/// Message-specific data length
|
||||
unsigned long wLength;
|
||||
/// Identifies the slot number for this command
|
||||
unsigned char bSlot;
|
||||
/// Sequence number for command.
|
||||
unsigned char bSeq;
|
||||
/// specific register
|
||||
unsigned char bSpecific_0;
|
||||
unsigned char bSpecific_1;
|
||||
unsigned char bSpecific_2;
|
||||
/// Application Protocol Data Unit
|
||||
unsigned char APDU[ABDATA_SIZE];
|
||||
} __attribute__ ((packed)) S_ccid_bulk_out_header;
|
||||
|
||||
|
||||
/// 6.1.11.2 PIN Verification Data Structure
|
||||
typedef struct
|
||||
{
|
||||
/// Number of seconds.
|
||||
unsigned char bTimerOut;
|
||||
/// Several parameters for the PIN format options
|
||||
unsigned char bmFormatString;
|
||||
/// Define the length of the PIN to present in the APDU command
|
||||
unsigned char bmPINBlockString;
|
||||
/// Allows the length PIN insertion in the APDU command
|
||||
unsigned char bmPINLengthFormat;
|
||||
/// Minimum PIN size in digit and Maximum PIN size in digit
|
||||
unsigned char wPINMaxExtraDigit;
|
||||
/// The value is a bit wise OR operation.
|
||||
unsigned char bEntryValidationCondition;
|
||||
/// Number of messages to display for the PIN modify command
|
||||
unsigned char bNumberMessage;
|
||||
/// Language used to display the messages.
|
||||
unsigned char wLangId;
|
||||
/// Message index in the Reader message table
|
||||
unsigned char bMsgIndex;
|
||||
/// T=1 I-block prologue field to use
|
||||
unsigned char bTeoPrologue[3];
|
||||
/// APDU to send to the ICC
|
||||
unsigned char abPINApdu[255];
|
||||
}__attribute__ ((packed)) S_ccid_PIN_Verification;
|
||||
|
||||
|
||||
/// 6.1.11.7 PIN Modification Data Structure
|
||||
typedef struct
|
||||
{
|
||||
/// Number of seconds. If 00h then CCID default value is used.
|
||||
unsigned char bTimeOut;
|
||||
/// Several parameters for the PIN format options (defined in § 6.1.11.4)
|
||||
unsigned char bmFormatString4;
|
||||
/// Define the length of the PIN to present in the APDU command
|
||||
unsigned char bmPINBlockString;
|
||||
/// Allows the length PIN insertion in the APDU command (defined in § 6.1.11.6)
|
||||
unsigned char bmPinLengthFormat;
|
||||
/// Insertion position offset in byte for the current PIN
|
||||
unsigned char bInsertionOffsetOld;
|
||||
/// Insertion position offset in byte for the new PIN
|
||||
unsigned char bInsertionOffsetNew;
|
||||
/// XXYYh
|
||||
/// XX: Minimum PIN size in digit
|
||||
/// YY: Maximum PIN size in digit
|
||||
unsigned char wPINMaxExtraDigit;
|
||||
/// 00h,01h,02h,03h
|
||||
/// Indicates if a confirmation is requested before acceptance of a new PIN (meaning that the user has to enter this new PIN twice before it is accepted)
|
||||
/// Indicates if the current PIN must be entered and set in the same APDU field of not.
|
||||
unsigned char bConfirmPIN;
|
||||
/// The value is a bit wise OR operation.
|
||||
/// 01h Max size reached
|
||||
/// 02h Validation key pressed
|
||||
/// 04h Timeout occurred
|
||||
unsigned char bEntryValidationCondition;
|
||||
/// 00h,01h,02h,03h,or FFh
|
||||
/// Number of messages to display for the PIN modify command.
|
||||
unsigned char bNumberMessage;
|
||||
/// Language used to display the messages. The 16 bit
|
||||
unsigned char wLangId;
|
||||
/// Message index in the Reader message table (should be 00h or 01h).
|
||||
unsigned char bMsgIndex1;
|
||||
/// Message index in the Reader message table (should be 01h or 02h).
|
||||
unsigned char bMsgIndex2;
|
||||
/// Message index in the Reader message table (should be 02h).
|
||||
unsigned char bMsgIndex3;
|
||||
/// T=1 I-block prologue field to use. Significant only if protocol in use is T=1.
|
||||
unsigned char bTeoPrologue[3];
|
||||
/// Byte array APDU to send to the ICC
|
||||
unsigned char abPINApdu[255];
|
||||
}__attribute__ ((packed)) S_ccid_PIN_Modification;
|
||||
|
||||
/// Protocol Data Structure for Protocol T=0 (bProtocolNum=0, dwLength=00000005h)
|
||||
typedef struct
|
||||
{
|
||||
/// B7-4 – FI – Index into the table 7 in ISO/IEC 7816-3:1997 selecting a
|
||||
/// clock rate conversion factor
|
||||
/// B3-0 – DI - Index into the table 8 in ISO/IEC 7816-3:1997 selecting a
|
||||
/// baud rate conversion factor
|
||||
unsigned char bmFindexDindex;
|
||||
/// For T=0 ,B0 – 0b, B7-2 – 000000b
|
||||
/// B1 – Convention used (b1=0 for direct, b1=1 for inverse)
|
||||
unsigned char bmTCCKST0; // 0 to 2
|
||||
/// Extra Guardtime between two characters. Add 0 to 254 etu to the normal
|
||||
/// guardtime of 12etu. FFh is the same as 00h.
|
||||
unsigned char bGuardTimeT0; // 0 to FF
|
||||
/// WI for T=0 used to define WWT
|
||||
unsigned char bWaitingIntegerT0; // 0 to FF
|
||||
/// ICC Clock Stop Support
|
||||
/// 00 = Stopping the Clock is not allowed
|
||||
/// 01 = Stop with Clock signal Low
|
||||
/// 02 = Stop with Clock signal High
|
||||
/// 03 = Stop with Clock either High or Low
|
||||
unsigned char bClockStop; // 0 to 3
|
||||
} __attribute__ ((packed)) S_ccid_protocol_t0;
|
||||
|
||||
|
||||
/// Protocol Data Structure for Protocol T=1 (bProtocolNum=1, dwLength=00000007h)
|
||||
typedef struct
|
||||
{
|
||||
/// B7-4 – FI – Index into the table 7 in ISO/IEC 7816-3:1997 selecting a
|
||||
/// clock rate conversion factor
|
||||
/// B3-0 – DI - Index into the table 8 in ISO/IEC 7816-3:1997 selecting a
|
||||
/// baud rate conversion factor
|
||||
unsigned char bmFindexDindex;
|
||||
/// For T=1, B7-2 – 000100b
|
||||
/// B0 – Checksum type (b0=0 for LRC, b0=1 for CRC
|
||||
/// B1 – Convention used (b1=0 for direct, b1=1 for inverse)
|
||||
unsigned char bmTCCKST1; // 10h, 11h, 12h, 13h
|
||||
/// Extra Guardtime (0 to 254 etu between two characters).
|
||||
/// If value is FFh, then guardtime is reduced by 1.
|
||||
unsigned char bGuardTimeT1; // 0 to FF
|
||||
/// B7-4 = BWI
|
||||
/// B3-0 = CWI
|
||||
unsigned char bmWaitingIntegersT1; // 0 to 9
|
||||
/// ICC Clock Stop Support
|
||||
/// 00 = Stopping the Clock is not allowed
|
||||
/// 01 = Stop with Clock signal Low
|
||||
/// 02 = Stop with Clock signal High
|
||||
/// 03 = Stop with Clock either High or Low
|
||||
unsigned char bClockStop; // 0 to 3
|
||||
/// Size of negotiated IFSC
|
||||
unsigned char bIFSC; // 0 to FE
|
||||
/// Nad value used by CCID
|
||||
unsigned char bNadValue; // 0 to FF
|
||||
} __attribute__ ((packed)) S_ccid_protocol_t1;
|
||||
|
||||
|
||||
/// Identifies the length of type of subordinate descriptors of a CCID device
|
||||
/// Table 5.1-1 Smart Card Device Class descriptors
|
||||
typedef struct
|
||||
{
|
||||
/// Size of this descriptor, in bytes.
|
||||
unsigned char bLength;
|
||||
/// Functional Descriptor type
|
||||
unsigned char bDescriptorType;
|
||||
/// Integrated Circuit(s) Cards Interface Devices (CCID) Specification
|
||||
/// Release Number
|
||||
unsigned short bcdCCID;
|
||||
/// Index of the highest available slot. An USB-ICC is regarded as a single
|
||||
/// slot CCID.
|
||||
unsigned char bMaxSlotIndex;
|
||||
/// This value indicates what voltages the CCID can supply to its slots.
|
||||
/// It is a bitwise OR operation performed on the following values:
|
||||
/// - 01h 5.0V
|
||||
/// - 02h 3.0V
|
||||
/// - 04h 1.8V
|
||||
/// Other bits are RFU.
|
||||
unsigned char bVoltageSupport;
|
||||
/// RRRR –Upper Word- is RFU = 0000h
|
||||
/// PPPP –Lower Word- Encodes the supported protocol types. A ‘1’ in a given
|
||||
/// bit position indicates support for the associated ISO protocol.
|
||||
/// 0001h = Protocol T=0
|
||||
/// 0002h = Protocol T=1
|
||||
/// All other bits are reserved and must be set to zero. The field is
|
||||
/// intended to correspond to the PCSC specification definitions.
|
||||
unsigned long dwProtocols;
|
||||
/// Default ICC clock frequency in KHz. This is an integer value.
|
||||
unsigned long dwDefaultClock;
|
||||
/// Maximum supported ICC clock frequency in KHz. This is an integer value.
|
||||
unsigned long dwMaximumClock;
|
||||
/// The number of clock frequencies that are supported by the CCID. If the
|
||||
/// value is 00h, the supported clock frequencies are assumed to be the
|
||||
/// default clock frequency defined by dwDefaultClock and the maximum clock
|
||||
/// frequency defined by dwMaximumClock.
|
||||
unsigned char bNumClockSupported;
|
||||
/// Default ICC I/O data rate in bps. This is an integer value
|
||||
unsigned long dwDataRate;
|
||||
/// Maximum supported ICC I/O data rate in bps
|
||||
unsigned long dwMaxDataRate;
|
||||
/// The number of data rates that are supported by the CCID.
|
||||
unsigned char bNumDataRatesSupported;
|
||||
/// Indicates the maximum IFSD supported by CCID for protocol T=1.
|
||||
unsigned long dwMaxIFSD;
|
||||
/// - RRRR-Upper Word- is RFU = 0000h
|
||||
/// - PPPP-Lower Word- encodes the supported protocol types. A ‘1’ in a given
|
||||
/// bit position indicates support for the associated protocol.
|
||||
/// 0001h indicates support for the 2-wire protocol 1
|
||||
/// 0002h indicates support for the 3-wire protocol 1
|
||||
/// 0004h indicates support for the I2C protocol 1
|
||||
/// All other values are outside of this specification, and must be handled
|
||||
/// by vendor-supplied drivers.
|
||||
unsigned long dwSynchProtocols;
|
||||
/// The value is a bitwise OR operation performed on the following values:
|
||||
/// - 00000000h No special characteristics
|
||||
/// - 00000001h Card accept mechanism 2
|
||||
/// - 00000002h Card ejection mechanism 2
|
||||
/// - 00000004h Card capture mechanism 2
|
||||
/// - 00000008h Card lock/unlock mechanism
|
||||
unsigned long dwMechanical;
|
||||
/// This value indicates what intelligent features the CCID has.
|
||||
unsigned long dwFeatures;
|
||||
/// For extended APDU level the value shall be between 261 + 10 (header) and
|
||||
/// 65544 +10, otherwise the minimum value is the wMaxPacketSize of the
|
||||
/// Bulk-OUT endpoint.
|
||||
unsigned long dwMaxCCIDMessageLength;
|
||||
/// Significant only for CCID that offers an APDU level for exchanges.
|
||||
unsigned char bClassGetResponse;
|
||||
/// Significant only for CCID that offers an extended APDU level for exchanges.
|
||||
unsigned char bClassEnvelope;
|
||||
/// Number of lines and characters for the LCD display used to send messages for PIN entry.
|
||||
unsigned short wLcdLayout;
|
||||
/// This value indicates what PIN support features the CCID has.
|
||||
unsigned char bPINSupport;
|
||||
/// Maximum number of slots which can be simultaneously busy.
|
||||
unsigned char bMaxCCIDBusySlots;
|
||||
|
||||
} __attribute__ ((packed)) CCIDDescriptor;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char RDRtoPCHardwareError( unsigned char bSlot,
|
||||
unsigned char bSeq,
|
||||
unsigned char bHardwareErrorCode );
|
||||
|
||||
#if !defined(NOAUTOCALLBACK)
|
||||
extern void USBDCallbacks_RequestReceived(const USBGenericRequest *pRequest);
|
||||
#endif
|
||||
extern void CCID_SmartCardRequest( void );
|
||||
extern void CCIDDriver_Initialize( void );
|
||||
extern unsigned char CCID_Read(void *pBuffer,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void *pArgument);
|
||||
extern unsigned char CCID_Write(void *pBuffer,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void *pArgument);
|
||||
extern unsigned char CCID_Insertion( void );
|
||||
extern unsigned char CCID_Removal( void );
|
||||
|
||||
#endif //#ifndef CCID_DRIVER_H
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Title: cciddriverdescriptors.h
|
||||
//
|
||||
// About: Purpose
|
||||
// Definitions of the descriptors required by the ccid device driver.
|
||||
// DWG_Smart-Card_CCID_Rev110.pdf
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef CCID_DRIVER_DESCRIPTORS_H
|
||||
#define CCID_DRIVER_DESCRIPTORS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants: Endpoints
|
||||
// CCID_EPT_DATA_OUT endpoint data out bulk 1
|
||||
// CCID_EPT_DATA_IN endpoint data in bulk 2
|
||||
// CCID_EPT_NOTIFICATION endpoint data interupt 3
|
||||
//------------------------------------------------------------------------------
|
||||
#define CCID_EPT_DATA_OUT 1
|
||||
#define CCID_EPT_DATA_IN 2
|
||||
#define CCID_EPT_NOTIFICATION 3
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// USB-ICC protocol
|
||||
//------------------------------------------------------------------------------
|
||||
// CCID specification version 1.10
|
||||
#define CCID1_10 0x0110
|
||||
|
||||
#define SMART_CARD_DEVICE_CLASS 0x0B
|
||||
// Smart Card Device Class Descriptor Type
|
||||
#define CCID_DECRIPTOR_TYPE 0x21
|
||||
|
||||
// Table 5.3-1 Summary of CCID Class Specific Request
|
||||
#define CCIDGenericRequest_ABORT 0x01
|
||||
#define CCIDGenericRequest_GET_CLOCK_FREQUENCIES 0x02
|
||||
#define CCIDGenericRequest_GET_DATA_RATES 0x03
|
||||
|
||||
// 6.1 Command Pipe, Bulk-OUT Messages
|
||||
#define PC_TO_RDR_ICCPOWERON 0x62
|
||||
#define PC_TO_RDR_ICCPOWEROFF 0x63
|
||||
#define PC_TO_RDR_GETSLOTSTATUS 0x65
|
||||
#define PC_TO_RDR_XFRBLOCK 0x6F
|
||||
#define PC_TO_RDR_GETPARAMETERS 0x6C
|
||||
#define PC_TO_RDR_RESETPARAMETERS 0x6D
|
||||
#define PC_TO_RDR_SETPARAMETERS 0x61
|
||||
#define PC_TO_RDR_ESCAPE 0x6B
|
||||
#define PC_TO_RDR_ICCCLOCK 0x6E
|
||||
#define PC_TO_RDR_T0APDU 0x6A
|
||||
#define PC_TO_RDR_SECURE 0x69
|
||||
#define PC_TO_RDR_MECHANICAL 0x71
|
||||
#define PC_TO_RDR_ABORT 0x72
|
||||
#define PC_TO_RDR_SETDATARATEANDCLOCKFREQUENCY 0x73
|
||||
|
||||
// 6.2 Response Pipe, Bulk-IN Messages
|
||||
#define RDR_TO_PC_DATABLOCK 0x80
|
||||
#define RDR_TO_PC_SLOTSTATUS 0x81
|
||||
#define RDR_TO_PC_PARAMETERS 0x82
|
||||
#define RDR_TO_PC_ESCAPE 0x83
|
||||
#define RDR_TO_PC_DATARATEANDCLOCKFREQUENCY 0x84
|
||||
|
||||
// 6.3 Interrupt-IN Messages
|
||||
#define RDR_TO_PC_NOTIFYSLOTCHANGE 0x50
|
||||
#define RDR_TO_PC_HARDWAREERROR 0x51
|
||||
|
||||
// Table 6.2-2 Slot error register when bmCommandStatus = 1
|
||||
#define CMD_ABORTED 0xFF
|
||||
#define ICC_MUTE 0xFE
|
||||
#define XFR_PARITY_ERROR 0xFD
|
||||
#define XFR_OVERRUN 0xFC
|
||||
#define HW_ERROR 0xFB
|
||||
#define BAD_ATR_TS 0xF8
|
||||
#define BAD_ATR_TCK 0xF7
|
||||
#define ICC_PROTOCOL_NOT_SUPPORTED 0xF6
|
||||
#define ICC_CLASS_NOT_SUPPORTED 0xF5
|
||||
#define PROCEDURE_BYTE_CONFLICT 0xF4
|
||||
#define DEACTIVATED_PROTOCOL 0xF3
|
||||
#define BUSY_WITH_AUTO_SEQUENCE 0xF2
|
||||
#define PIN_TIMEOUT 0xF0
|
||||
#define PIN_CANCELLED 0xEF
|
||||
#define CMD_SLOT_BUSY 0xE0
|
||||
// User defined 0xC0 to 0x81
|
||||
// Reserved for futur use 0x80
|
||||
// not supported incorrect message parameter 0x7F to 0x01
|
||||
// Command not supported 0x00
|
||||
|
||||
// CCID rev 1.1, p.27
|
||||
#define VOLTS_AUTO 0x00
|
||||
#define VOLTS_5_0 0x01
|
||||
#define VOLTS_3_0 0x02
|
||||
#define VOLTS_1_8 0x03
|
||||
|
||||
// 6.3.1 RDR_to_PC_NotifySlotChange
|
||||
#define ICC_NOT_PRESENT 0x00
|
||||
#define ICC_PRESENT 0x01
|
||||
#define ICC_CHANGE 0x02
|
||||
#define ICC_INSERTED_EVENT ICC_PRESENT+ICC_CHANGE
|
||||
|
||||
// ICCD: Table 6.1-8 Bitmap for bStatus field
|
||||
#define ICC_BS_PRESENT_ACTIVATED 0x00 // USB-ICC is present and activated
|
||||
#define ICC_BS_PRESENT_NOTACTIVATED 0x01 // USB-ICC is present but not activated
|
||||
#define ICC_BS_NOTPRESENT 0x02 // USB-ICC is virtually not present
|
||||
#define ICC_BS_RFU 0x03 // RFU
|
||||
#define ICC_CS_NO_ERROR (0x00<<6) // Processed without error
|
||||
#define ICC_CS_FAILED (0x01<<6) // Failed, error condition given by bError
|
||||
#define ICC_CS_TIME_EXT (0x02<<6) // Time extension is requested
|
||||
#define ICC_CS_RFU (0x03<<6) // RFU
|
||||
|
||||
/*
|
||||
#define NO_ERROR 0x00
|
||||
#define NO_EXTRA_BYTES 0x00
|
||||
#define CCID_FLAG_INITIAL_VALUE 0x05
|
||||
#define CCID_EVENT_SIZE 0x02
|
||||
#define STATUS_MASK 0x41
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef CCID_DRIVER_DESCRIPTORS_H
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Collection of methods for using the USB device controller on AT91
|
||||
/// microcontrollers.
|
||||
///
|
||||
/// !!!Usage
|
||||
///
|
||||
/// Please refer to the corresponding application note.
|
||||
/// - "AT91 USB device framework"
|
||||
/// - "USBD API" . "USBD API Methods"
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USBD_H
|
||||
#define USBD_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <usb/common/core/USBEndpointDescriptor.h>
|
||||
#include <usb/common/core/USBGenericRequest.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB device API return values"
|
||||
///
|
||||
/// This page lists the return values of the USB %device driver API
|
||||
///
|
||||
/// !Return codes
|
||||
/// - USBD_STATUS_SUCCESS
|
||||
/// - USBD_STATUS_LOCKED
|
||||
/// - USBD_STATUS_ABORTED
|
||||
/// - USBD_STATUS_RESET
|
||||
|
||||
/// Indicates the operation was successful.
|
||||
#define USBD_STATUS_SUCCESS 0
|
||||
/// Endpoint/device is already busy.
|
||||
#define USBD_STATUS_LOCKED 1
|
||||
/// Operation has been aborted.
|
||||
#define USBD_STATUS_ABORTED 2
|
||||
/// Operation has been aborted because the device has been reset.
|
||||
#define USBD_STATUS_RESET 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB device states"
|
||||
///
|
||||
/// This page lists the %device states of the USB %device driver.
|
||||
///
|
||||
/// !States
|
||||
/// - USBD_STATE_SUSPENDED
|
||||
/// - USBD_STATE_ATTACHED
|
||||
/// - USBD_STATE_POWERED
|
||||
/// - USBD_STATE_DEFAULT
|
||||
/// - USBD_STATE_ADDRESS
|
||||
/// - USBD_STATE_CONFIGURED
|
||||
|
||||
/// The device is currently suspended.
|
||||
#define USBD_STATE_SUSPENDED 0
|
||||
/// USB cable is plugged into the device.
|
||||
#define USBD_STATE_ATTACHED 1
|
||||
/// Host is providing +5V through the USB cable.
|
||||
#define USBD_STATE_POWERED 2
|
||||
/// Device has been reset.
|
||||
#define USBD_STATE_DEFAULT 3
|
||||
/// The device has been given an address on the bus.
|
||||
#define USBD_STATE_ADDRESS 4
|
||||
/// A valid configuration has been selected.
|
||||
#define USBD_STATE_CONFIGURED 5
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB device LEDs"
|
||||
///
|
||||
/// This page lists the LEDs used in the USB %device driver.
|
||||
///
|
||||
/// !LEDs
|
||||
/// - USBD_LEDPOWER
|
||||
/// - USBD_LEDUSB
|
||||
/// - USBD_LEDOTHER
|
||||
|
||||
/// LED for indicating that the device is powered.
|
||||
#define USBD_LEDPOWER 0
|
||||
/// LED for indicating USB activity.
|
||||
#define USBD_LEDUSB 1
|
||||
/// LED for custom usage.
|
||||
#define USBD_LEDOTHER 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Callback used by transfer functions (USBD_Read & USBD_Write) to notify
|
||||
/// that a transaction is complete.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef void (*TransferCallback)(void *pArg,
|
||||
unsigned char status,
|
||||
unsigned int transferred,
|
||||
unsigned int remaining);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void USBD_InterruptHandler(void);
|
||||
|
||||
extern void USBD_Init(void);
|
||||
|
||||
extern void USBD_Connect(void);
|
||||
|
||||
extern void USBD_Disconnect(void);
|
||||
|
||||
extern char USBD_Write(
|
||||
unsigned char bEndpoint,
|
||||
const void *pData,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *pArg);
|
||||
|
||||
extern char USBD_Read(
|
||||
unsigned char bEndpoint,
|
||||
void *pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void *pArg);
|
||||
|
||||
extern unsigned char USBD_Stall(unsigned char bEndpoint);
|
||||
|
||||
extern void USBD_Halt(unsigned char bEndpoint);
|
||||
|
||||
extern void USBD_Unhalt(unsigned char bEndpoint);
|
||||
|
||||
extern void USBD_ConfigureEndpoint(const USBEndpointDescriptor *pDescriptor);
|
||||
|
||||
extern unsigned char USBD_IsHalted(unsigned char bEndpoint);
|
||||
|
||||
extern void USBD_RemoteWakeUp(void);
|
||||
|
||||
extern void USBD_SetAddress(unsigned char address);
|
||||
|
||||
extern void USBD_SetConfiguration(unsigned char cfgnum);
|
||||
|
||||
extern unsigned char USBD_GetState(void);
|
||||
|
||||
extern unsigned char USBD_IsHighSpeed(void);
|
||||
|
||||
extern void USBD_Test(unsigned char bIndex);
|
||||
|
||||
#endif //#ifndef USBD_H
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions of callbacks used by the USBD API to notify the user
|
||||
application of incoming events. These functions are declared as 'weak',
|
||||
so they can be re-implemented elsewhere in the application in a
|
||||
transparent way.
|
||||
*/
|
||||
|
||||
#ifndef USBDCALLBACKS_H
|
||||
#define USBDCALLBACKS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <usb/common/core/USBGenericRequest.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void USBDCallbacks_Initialized(void);
|
||||
|
||||
extern void USBDCallbacks_Reset(void);
|
||||
|
||||
extern void USBDCallbacks_Suspended(void);
|
||||
|
||||
extern void USBDCallbacks_Resumed(void);
|
||||
|
||||
extern void USBDCallbacks_RequestReceived(const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBDCALLBACKS_H
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBDCallbacks.h"
|
||||
#include "USBD.h"
|
||||
#include <board.h>
|
||||
#include <aic/aic.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported function
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Invoked after the USB driver has been initialized. By default, configures
|
||||
/// the UDP/UDPHS interrupt.
|
||||
//------------------------------------------------------------------------------
|
||||
void USBDCallbacks_Initialized(void)
|
||||
{
|
||||
#if defined(BOARD_USB_UDP)
|
||||
// Configure and enable the UDP interrupt
|
||||
AIC_ConfigureIT(AT91C_ID_UDP, 0, USBD_InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_UDP);
|
||||
|
||||
#elif defined(BOARD_USB_UDPHS)
|
||||
// Configure and enable the UDPHS interrupt
|
||||
AIC_ConfigureIT(AT91C_ID_UDPHS, 0, USBD_InterruptHandler);
|
||||
AIC_EnableIT(AT91C_ID_UDPHS);
|
||||
#else
|
||||
#error Unsupported controller.
|
||||
#endif
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBDCallbacks.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported function
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Invoked when the USB driver is reset. Does nothing by default.
|
||||
//------------------------------------------------------------------------------
|
||||
void USBDCallbacks_Reset(void)
|
||||
{
|
||||
// Does nothing
|
||||
}
|
||||
|
|
@ -0,0 +1,682 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBDDriver.h"
|
||||
#include "USBDDriverCallbacks.h"
|
||||
#include "USBD.h"
|
||||
#include <board.h>
|
||||
#include <utility/trace.h>
|
||||
#include <usb/common/core/USBGenericDescriptor.h>
|
||||
#include <usb/common/core/USBDeviceDescriptor.h>
|
||||
#include <usb/common/core/USBConfigurationDescriptor.h>
|
||||
#include <usb/common/core/USBDeviceQualifierDescriptor.h>
|
||||
#include <usb/common/core/USBEndpointDescriptor.h>
|
||||
#include <usb/common/core/USBFeatureRequest.h>
|
||||
#include <usb/common/core/USBSetAddressRequest.h>
|
||||
#include <usb/common/core/USBGetDescriptorRequest.h>
|
||||
#include <usb/common/core/USBSetConfigurationRequest.h>
|
||||
#include <usb/common/core/USBInterfaceRequest.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures the device by setting it into the Configured state and
|
||||
/// initializing all endpoints.
|
||||
/// \param pDriver Pointer to a USBDDriver instance.
|
||||
/// \param cfgnum Configuration number to set.
|
||||
//------------------------------------------------------------------------------
|
||||
static void SetConfiguration(USBDDriver *pDriver, unsigned char cfgnum)
|
||||
{
|
||||
USBEndpointDescriptor *pEndpoints[BOARD_USB_NUMENDPOINTS+1];
|
||||
const USBConfigurationDescriptor *pConfiguration;
|
||||
|
||||
// Use different descriptor depending on device speed
|
||||
if (USBD_IsHighSpeed()) {
|
||||
|
||||
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
|
||||
}
|
||||
else {
|
||||
|
||||
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
|
||||
}
|
||||
|
||||
// Set & save the desired configuration
|
||||
USBD_SetConfiguration(cfgnum);
|
||||
pDriver->cfgnum = cfgnum;
|
||||
|
||||
// If the configuration is not 0, configure endpoints
|
||||
if (cfgnum != 0) {
|
||||
|
||||
// Parse configuration to get endpoint descriptors
|
||||
USBConfigurationDescriptor_Parse(pConfiguration, 0, pEndpoints, 0);
|
||||
|
||||
// Configure endpoints
|
||||
int i = 0;
|
||||
while (pEndpoints[i] != 0) {
|
||||
|
||||
USBD_ConfigureEndpoint(pEndpoints[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Should be done before send the ZLP
|
||||
USBDDriverCallbacks_ConfigurationChanged(cfgnum);
|
||||
|
||||
// Acknowledge the request
|
||||
USBD_Write(0, // Endpoint #0
|
||||
0, // No data buffer
|
||||
0, // No data buffer
|
||||
(TransferCallback) 0,
|
||||
(void *) 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends the current configuration number to the host.
|
||||
/// \param pDriver Pointer to a USBDDriver instance.
|
||||
//------------------------------------------------------------------------------
|
||||
static void GetConfiguration(const USBDDriver *pDriver)
|
||||
{
|
||||
USBD_Write(0, &(pDriver->cfgnum), 1, 0, 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends the current status of the device to the host.
|
||||
/// \param pDriver Pointer to a USBDDriver instance.
|
||||
//------------------------------------------------------------------------------
|
||||
static void GetDeviceStatus(const USBDDriver *pDriver)
|
||||
{
|
||||
unsigned short data = 0;
|
||||
const USBConfigurationDescriptor *pConfiguration;
|
||||
|
||||
// Use different configuration depending on device speed
|
||||
if (USBD_IsHighSpeed()) {
|
||||
|
||||
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
|
||||
}
|
||||
else {
|
||||
|
||||
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
|
||||
}
|
||||
|
||||
// Check current configuration for power mode (if device is configured)
|
||||
if (pDriver->cfgnum != 0) {
|
||||
|
||||
if (USBConfigurationDescriptor_IsSelfPowered(pConfiguration)) {
|
||||
|
||||
data |= 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if remote wake-up is enabled
|
||||
if (pDriver->isRemoteWakeUpEnabled) {
|
||||
|
||||
data |= 2;
|
||||
}
|
||||
|
||||
// Send the device status
|
||||
USBD_Write(0, &data, 2, 0, 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends the current status of an endpoints to the USB host.
|
||||
/// \param bEndpoint Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
static void GetEndpointStatus(unsigned char bEndpoint)
|
||||
{
|
||||
unsigned short data = 0;
|
||||
|
||||
// Check if the endpoint exists
|
||||
if (bEndpoint > BOARD_USB_NUMENDPOINTS) {
|
||||
|
||||
USBD_Stall(0);
|
||||
}
|
||||
else {
|
||||
|
||||
// Check if the endpoint if currently halted
|
||||
if (USBD_IsHalted(bEndpoint)) {
|
||||
|
||||
data = 1;
|
||||
}
|
||||
|
||||
// Send the endpoint status
|
||||
USBD_Write(0, &data, 2, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends the requested USB descriptor to the host if available, or STALLs the
|
||||
/// request.
|
||||
/// \param pDriver Pointer to a USBDDriver instance.
|
||||
/// \param type Type of the requested descriptor
|
||||
/// \param index Index of the requested descriptor.
|
||||
/// \param length Maximum number of bytes to return.
|
||||
//------------------------------------------------------------------------------
|
||||
static void GetDescriptor(
|
||||
const USBDDriver *pDriver,
|
||||
unsigned char type,
|
||||
unsigned char index,
|
||||
unsigned int length)
|
||||
{
|
||||
const USBDeviceDescriptor *pDevice;
|
||||
const USBConfigurationDescriptor *pConfiguration;
|
||||
const USBDeviceQualifierDescriptor *pQualifier;
|
||||
const USBConfigurationDescriptor *pOtherSpeed;
|
||||
const USBGenericDescriptor **pStrings =
|
||||
(const USBGenericDescriptor **) pDriver->pDescriptors->pStrings;
|
||||
unsigned char numStrings = pDriver->pDescriptors->numStrings;
|
||||
const USBGenericDescriptor *pString;
|
||||
|
||||
// Use different set of descriptors depending on device speed
|
||||
if (USBD_IsHighSpeed()) {
|
||||
|
||||
TRACE_DEBUG("HS ");
|
||||
pDevice = pDriver->pDescriptors->pHsDevice;
|
||||
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
|
||||
pQualifier = pDriver->pDescriptors->pHsQualifier;
|
||||
pOtherSpeed = pDriver->pDescriptors->pHsOtherSpeed;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_DEBUG("FS ");
|
||||
pDevice = pDriver->pDescriptors->pFsDevice;
|
||||
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
|
||||
pQualifier = pDriver->pDescriptors->pFsQualifier;
|
||||
pOtherSpeed = pDriver->pDescriptors->pFsOtherSpeed;
|
||||
}
|
||||
|
||||
// Check the descriptor type
|
||||
switch (type) {
|
||||
|
||||
case USBGenericDescriptor_DEVICE:
|
||||
TRACE_INFO_WP("Dev ");
|
||||
|
||||
// Adjust length and send descriptor
|
||||
if (length > USBGenericDescriptor_GetLength((USBGenericDescriptor *) pDevice)) {
|
||||
|
||||
length = USBGenericDescriptor_GetLength((USBGenericDescriptor *) pDevice);
|
||||
}
|
||||
USBD_Write(0, pDevice, length, 0, 0);
|
||||
break;
|
||||
|
||||
case USBGenericDescriptor_CONFIGURATION:
|
||||
TRACE_INFO_WP("Cfg ");
|
||||
|
||||
// Adjust length and send descriptor
|
||||
if (length > USBConfigurationDescriptor_GetTotalLength(pConfiguration)) {
|
||||
|
||||
length = USBConfigurationDescriptor_GetTotalLength(pConfiguration);
|
||||
}
|
||||
USBD_Write(0, pConfiguration, length, 0, 0);
|
||||
break;
|
||||
|
||||
case USBGenericDescriptor_DEVICEQUALIFIER:
|
||||
TRACE_INFO_WP("Qua ");
|
||||
|
||||
// Check if descriptor exists
|
||||
if (!pQualifier) {
|
||||
|
||||
USBD_Stall(0);
|
||||
}
|
||||
else {
|
||||
|
||||
// Adjust length and send descriptor
|
||||
if (length > USBGenericDescriptor_GetLength((USBGenericDescriptor *) pQualifier)) {
|
||||
|
||||
length = USBGenericDescriptor_GetLength((USBGenericDescriptor *) pQualifier);
|
||||
}
|
||||
USBD_Write(0, pQualifier, length, 0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBGenericDescriptor_OTHERSPEEDCONFIGURATION:
|
||||
TRACE_INFO_WP("OSC ");
|
||||
|
||||
// Check if descriptor exists
|
||||
if (!pOtherSpeed) {
|
||||
|
||||
USBD_Stall(0);
|
||||
}
|
||||
else {
|
||||
|
||||
// Adjust length and send descriptor
|
||||
if (length > USBConfigurationDescriptor_GetTotalLength(pOtherSpeed)) {
|
||||
|
||||
length = USBConfigurationDescriptor_GetTotalLength(pOtherSpeed);
|
||||
}
|
||||
USBD_Write(0, pOtherSpeed, length, 0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBGenericDescriptor_STRING:
|
||||
TRACE_INFO_WP("Str%d ", index);
|
||||
|
||||
// Check if descriptor exists
|
||||
if (index > numStrings) {
|
||||
|
||||
USBD_Stall(0);
|
||||
}
|
||||
else {
|
||||
|
||||
pString = pStrings[index];
|
||||
|
||||
// Adjust length and send descriptor
|
||||
if (length > USBGenericDescriptor_GetLength(pString)) {
|
||||
|
||||
length = USBGenericDescriptor_GetLength(pString);
|
||||
}
|
||||
USBD_Write(0, pString, length, 0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
TRACE_WARNING(
|
||||
"USBDDriver_GetDescriptor: Unknown descriptor type (%d)\n\r",
|
||||
type);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sets the active setting of the given interface if the configuration supports
|
||||
/// it; otherwise, the control pipe is STALLed. If the setting of an interface
|
||||
/// changes.
|
||||
/// \parma pDriver Pointer to a USBDDriver instance.
|
||||
/// \parma infnum Interface number.
|
||||
/// \parma setting New active setting for the interface.
|
||||
//------------------------------------------------------------------------------
|
||||
static void SetInterface(
|
||||
USBDDriver *pDriver,
|
||||
unsigned char infnum,
|
||||
unsigned char setting)
|
||||
{
|
||||
// Make sure alternate settings are supported
|
||||
if (!pDriver->pInterfaces) {
|
||||
|
||||
USBD_Stall(0);
|
||||
}
|
||||
else {
|
||||
|
||||
// Change the current setting of the interface and trigger the callback
|
||||
// if necessary
|
||||
if (pDriver->pInterfaces[infnum] != setting) {
|
||||
|
||||
pDriver->pInterfaces[infnum] = setting;
|
||||
USBDDriverCallbacks_InterfaceSettingChanged(infnum, setting);
|
||||
}
|
||||
|
||||
// Acknowledge the request
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends the currently active setting of the given interface to the USB
|
||||
/// host. If alternate settings are not supported, this function STALLs the
|
||||
/// control pipe.
|
||||
/// \param pDriver Pointer to a USBDDriver instance.
|
||||
/// \param infnum Interface number.
|
||||
//------------------------------------------------------------------------------
|
||||
static void GetInterface(
|
||||
const USBDDriver *pDriver,
|
||||
unsigned char infnum)
|
||||
{
|
||||
// Make sure alternate settings are supported, or STALL the control pipe
|
||||
if (!pDriver->pInterfaces) {
|
||||
|
||||
USBD_Stall(0);
|
||||
}
|
||||
else {
|
||||
|
||||
// Sends the current interface setting to the host
|
||||
USBD_Write(0, &(pDriver->pInterfaces[infnum]), 1, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOARD_USB_UDPHS
|
||||
//------------------------------------------------------------------------------
|
||||
// Performs the selected test on the USB device (high-speed only).
|
||||
// \param test Test selector value.
|
||||
//------------------------------------------------------------------------------
|
||||
static void USBDDriver_Test(unsigned char test)
|
||||
{
|
||||
TRACE_DEBUG("UDPHS_Test\n\r");
|
||||
|
||||
// the lower byte of wIndex must be zero
|
||||
// the most significant byte of wIndex is used to specify the specific test mode
|
||||
switch (test) {
|
||||
case USBFeatureRequest_TESTPACKET:
|
||||
//Test mode Test_Packet:
|
||||
//Upon command, a port must repetitively transmit the following test packet until
|
||||
//the exit action is taken. This enables the testing of rise and fall times, eye
|
||||
//patterns, jitter, and any other dynamic waveform specifications.
|
||||
//The test packet is made up by concatenating the following strings.
|
||||
//(Note: For J/K NRZI data, and for NRZ data, the bit on the left is the first one
|
||||
//transmitted. “S” indicates that a bit stuff occurs, which inserts an “extra” NRZI data bit.
|
||||
//“* N” is used to indicate N occurrences of a string of bits or symbols.)
|
||||
//A port in Test_Packet mode must send this packet repetitively. The inter-packet timing
|
||||
//must be no less than the minimum allowable inter-packet gap as defined in Section 7.1.18 and
|
||||
//no greater than 125 us.
|
||||
// Send ZLP
|
||||
USBD_Test(USBFeatureRequest_TESTSENDZLP);
|
||||
// Tst PACKET
|
||||
USBD_Test(USBFeatureRequest_TESTPACKET);
|
||||
while (1);
|
||||
break;
|
||||
|
||||
case USBFeatureRequest_TESTJ:
|
||||
//Test mode Test_J:
|
||||
//Upon command, a port’s transceiver must enter the high-speed J state and remain in that
|
||||
//state until the exit action is taken. This enables the testing of the high output drive
|
||||
//level on the D+ line.
|
||||
// Send ZLP
|
||||
USBD_Test(USBFeatureRequest_TESTSENDZLP);
|
||||
// Tst J
|
||||
USBD_Test(USBFeatureRequest_TESTJ);
|
||||
while (1);
|
||||
break;
|
||||
|
||||
case USBFeatureRequest_TESTK:
|
||||
//Test mode Test_K:
|
||||
//Upon command, a port’s transceiver must enter the high-speed K state and remain in
|
||||
//that state until the exit action is taken. This enables the testing of the high output drive
|
||||
//level on the D- line.
|
||||
// Send a ZLP
|
||||
USBD_Test(USBFeatureRequest_TESTSENDZLP);
|
||||
USBD_Test(USBFeatureRequest_TESTK);
|
||||
while (1);
|
||||
break;
|
||||
|
||||
case USBFeatureRequest_TESTSE0NAK:
|
||||
//Test mode Test_SE0_NAK:
|
||||
//Upon command, a port’s transceiver must enter the high-speed receive mode
|
||||
//and remain in that mode until the exit action is taken. This enables the testing
|
||||
//of output impedance, low level output voltage, and loading characteristics.
|
||||
//In addition, while in this mode, upstream facing ports (and only upstream facing ports)
|
||||
//must respond to any IN token packet with a NAK handshake (only if the packet CRC is
|
||||
//determined to be correct) within the normal allowed device response time. This enables testing of
|
||||
//the device squelch level circuitry and, additionally, provides a general purpose stimulus/response
|
||||
//test for basic functional testing.
|
||||
USBD_Test(USBFeatureRequest_TESTSE0NAK);
|
||||
// Send a ZLP
|
||||
USBD_Test(USBFeatureRequest_TESTSENDZLP);
|
||||
while (1);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_Stall( 0 );
|
||||
break;
|
||||
|
||||
}
|
||||
// The exit action is to power cycle the device.
|
||||
// The device must be disconnected from the host
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes a USBDDriver instance with a list of descriptors. If
|
||||
/// interfaces can have multiple alternate settings, an array to store the
|
||||
/// current setting for each interface must be provided.
|
||||
/// \param pDriver Pointer to a USBDDriver instance.
|
||||
/// \param pDescriptors Pointer to a USBDDriverDescriptors instance.
|
||||
/// \param pInterfaces Pointer to an array for storing the current alternate
|
||||
/// setting of each interface (optional).
|
||||
//------------------------------------------------------------------------------
|
||||
void USBDDriver_Initialize(
|
||||
USBDDriver *pDriver,
|
||||
const USBDDriverDescriptors *pDescriptors,
|
||||
unsigned char *pInterfaces)
|
||||
{
|
||||
|
||||
pDriver->cfgnum = 0;
|
||||
#if (BOARD_USB_BMATTRIBUTES == USBConfigurationDescriptor_SELFPOWERED_RWAKEUP) \
|
||||
|| (BOARD_USB_BMATTRIBUTES == USBConfigurationDescriptor_BUSPOWERED_RWAKEUP)
|
||||
pDriver->isRemoteWakeUpEnabled = 1;
|
||||
#else
|
||||
pDriver->isRemoteWakeUpEnabled = 0;
|
||||
#endif
|
||||
|
||||
pDriver->pDescriptors = pDescriptors;
|
||||
pDriver->pInterfaces = pInterfaces;
|
||||
|
||||
// Initialize interfaces array if not null
|
||||
if (pInterfaces != 0) {
|
||||
|
||||
memset(pInterfaces, sizeof(pInterfaces), 0);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Handles the given request if it is standard, otherwise STALLs it.
|
||||
/// \param pDriver Pointer to a USBDDriver instance.
|
||||
/// \param pRequest Pointer to a USBGenericRequest instance.
|
||||
//------------------------------------------------------------------------------
|
||||
void USBDDriver_RequestHandler(
|
||||
USBDDriver *pDriver,
|
||||
const USBGenericRequest *pRequest)
|
||||
{
|
||||
unsigned char cfgnum;
|
||||
unsigned char infnum;
|
||||
unsigned char eptnum;
|
||||
unsigned char setting;
|
||||
unsigned char type;
|
||||
unsigned char index;
|
||||
unsigned int length;
|
||||
unsigned int address;
|
||||
|
||||
TRACE_INFO_WP("Std ");
|
||||
|
||||
// Check request code
|
||||
switch (USBGenericRequest_GetRequest(pRequest)) {
|
||||
|
||||
case USBGenericRequest_GETDESCRIPTOR:
|
||||
TRACE_INFO_WP("gDesc ");
|
||||
|
||||
// Send the requested descriptor
|
||||
type = USBGetDescriptorRequest_GetDescriptorType(pRequest);
|
||||
index = USBGetDescriptorRequest_GetDescriptorIndex(pRequest);
|
||||
length = USBGenericRequest_GetLength(pRequest);
|
||||
GetDescriptor(pDriver, type, index, length);
|
||||
break;
|
||||
|
||||
case USBGenericRequest_SETADDRESS:
|
||||
TRACE_INFO_WP("sAddr ");
|
||||
|
||||
// Sends a zero-length packet and then set the device address
|
||||
address = USBSetAddressRequest_GetAddress(pRequest);
|
||||
USBD_Write(0, 0, 0, (TransferCallback) USBD_SetAddress, (void *) address);
|
||||
break;
|
||||
|
||||
case USBGenericRequest_SETCONFIGURATION:
|
||||
TRACE_INFO_WP("sCfg ");
|
||||
|
||||
// Set the requested configuration
|
||||
cfgnum = USBSetConfigurationRequest_GetConfiguration(pRequest);
|
||||
SetConfiguration(pDriver, cfgnum);
|
||||
break;
|
||||
|
||||
case USBGenericRequest_GETCONFIGURATION:
|
||||
TRACE_INFO_WP("gCfg ");
|
||||
|
||||
// Send the current configuration number
|
||||
GetConfiguration(pDriver);
|
||||
break;
|
||||
|
||||
case USBGenericRequest_GETSTATUS:
|
||||
TRACE_INFO_WP("gSta ");
|
||||
|
||||
// Check who is the recipient
|
||||
switch (USBGenericRequest_GetRecipient(pRequest)) {
|
||||
|
||||
case USBGenericRequest_DEVICE:
|
||||
TRACE_INFO_WP("Dev ");
|
||||
|
||||
// Send the device status
|
||||
GetDeviceStatus(pDriver);
|
||||
break;
|
||||
|
||||
case USBGenericRequest_ENDPOINT:
|
||||
TRACE_INFO_WP("Ept ");
|
||||
|
||||
// Send the endpoint status
|
||||
eptnum = USBGenericRequest_GetEndpointNumber(pRequest);
|
||||
GetEndpointStatus(eptnum);
|
||||
break;
|
||||
|
||||
default:
|
||||
TRACE_WARNING(
|
||||
"USBDDriver_RequestHandler: Unknown recipient (%d)\n\r",
|
||||
USBGenericRequest_GetRecipient(pRequest));
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBGenericRequest_CLEARFEATURE:
|
||||
TRACE_INFO_WP("cFeat ");
|
||||
|
||||
// Check which is the requested feature
|
||||
switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {
|
||||
|
||||
case USBFeatureRequest_ENDPOINTHALT:
|
||||
TRACE_INFO_WP("Hlt ");
|
||||
|
||||
// Unhalt endpoint and send a zero-length packet
|
||||
USBD_Unhalt(USBGenericRequest_GetEndpointNumber(pRequest));
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
case USBFeatureRequest_DEVICEREMOTEWAKEUP:
|
||||
TRACE_INFO_WP("RmWU ");
|
||||
|
||||
// Disable remote wake-up and send a zero-length packet
|
||||
pDriver->isRemoteWakeUpEnabled = 0;
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
TRACE_WARNING(
|
||||
"USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
|
||||
USBFeatureRequest_GetFeatureSelector(pRequest));
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBGenericRequest_SETFEATURE:
|
||||
TRACE_INFO_WP("sFeat ");
|
||||
|
||||
// Check which is the selected feature
|
||||
switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {
|
||||
|
||||
case USBFeatureRequest_DEVICEREMOTEWAKEUP:
|
||||
TRACE_INFO_WP("RmWU ");
|
||||
|
||||
// Enable remote wake-up and send a ZLP
|
||||
pDriver->isRemoteWakeUpEnabled = 1;
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
case USBFeatureRequest_ENDPOINTHALT:
|
||||
TRACE_INFO_WP("Ept ");
|
||||
|
||||
// Halt endpoint
|
||||
USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest));
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
#if defined(BOARD_USB_UDPHS)
|
||||
|
||||
case USBFeatureRequest_TESTMODE:
|
||||
// 7.1.20 Test Mode Support
|
||||
if ((USBGenericRequest_GetType(pRequest) == USBGenericRequest_DEVICE)
|
||||
&& ((USBGenericRequest_GetIndex(pRequest) & 0x000F) == 0)) {
|
||||
|
||||
// Handle test request
|
||||
USBDDriver_Test(USBFeatureRequest_GetTestSelector(pRequest));
|
||||
}
|
||||
else {
|
||||
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
TRACE_WARNING(
|
||||
"USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
|
||||
USBFeatureRequest_GetFeatureSelector(pRequest));
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBGenericRequest_SETINTERFACE:
|
||||
TRACE_INFO_WP("sInterface ");
|
||||
|
||||
infnum = USBInterfaceRequest_GetInterface(pRequest);
|
||||
setting = USBInterfaceRequest_GetAlternateSetting(pRequest);
|
||||
SetInterface(pDriver, infnum, setting);
|
||||
break;
|
||||
|
||||
case USBGenericRequest_GETINTERFACE:
|
||||
TRACE_INFO_WP("gInterface ");
|
||||
|
||||
infnum = USBInterfaceRequest_GetInterface(pRequest);
|
||||
GetInterface(pDriver, infnum);
|
||||
break;
|
||||
|
||||
default:
|
||||
TRACE_WARNING(
|
||||
"USBDDriver_RequestHandler: Unknown request code (%d)\n\r",
|
||||
USBGenericRequest_GetRequest(pRequest));
|
||||
USBD_Stall(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Test if RemoteWakeUP feature is enabled
|
||||
/// \param pDriver Pointer to an USBDDriver instance.
|
||||
/// \return 1 if remote wake up has been enabled by the host; otherwise, returns
|
||||
/// 0
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBDDriver_IsRemoteWakeUpEnabled(const USBDDriver *pDriver)
|
||||
{
|
||||
return pDriver->isRemoteWakeUpEnabled;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
USB Device Driver class definition.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Instanciate a USBDDriver object and initialize it using
|
||||
USBDDriver_Initialize.
|
||||
-# When a USB SETUP request is received, forward it to the standard
|
||||
driver using USBDDriver_RequestHandler.
|
||||
-# Check the Remote Wakeup setting via USBDDriver_IsRemoteWakeUpEnabled.
|
||||
*/
|
||||
|
||||
#ifndef USBDDRIVER_H
|
||||
#define USBDDRIVER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBDDriverDescriptors.h"
|
||||
#include <usb/common/core/USBGenericRequest.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB device driver structure, holding a list of descriptors identifying
|
||||
/// the device as well as the driver current state.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// List of descriptors used by the device.
|
||||
const USBDDriverDescriptors *pDescriptors;
|
||||
/// Current setting for each interface.
|
||||
unsigned char *pInterfaces;
|
||||
/// Current configuration number (0 -> device is not configured).
|
||||
unsigned char cfgnum;
|
||||
/// Indicates if remote wake up has been enabled by the host.
|
||||
unsigned char isRemoteWakeUpEnabled;
|
||||
|
||||
} USBDDriver;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void USBDDriver_Initialize(
|
||||
USBDDriver *pDriver,
|
||||
const USBDDriverDescriptors *pDescriptors,
|
||||
unsigned char *pInterfaces);
|
||||
|
||||
extern void USBDDriver_RequestHandler(
|
||||
USBDDriver *pDriver,
|
||||
const USBGenericRequest *pRequest);
|
||||
|
||||
extern unsigned char USBDDriver_IsRemoteWakeUpEnabled(const USBDDriver *pDriver);
|
||||
|
||||
#endif //#ifndef USBDDRIVER_H
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of several callbacks which are triggered by the USB software
|
||||
driver after receiving specific requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Re-implement the USBDDriverCallbacks_ConfigurationChanged
|
||||
callback to know when the hosts changes the active configuration of
|
||||
the device.
|
||||
-# Re-implement the USBDDriverCallbacks_InterfaceSettingChanged
|
||||
callback to get notified whenever the active setting of an interface
|
||||
is changed by the host.
|
||||
*/
|
||||
|
||||
#ifndef USBDDRIVERCALLBACKS_H
|
||||
#define USBDDRIVERCALLBACKS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum);
|
||||
|
||||
extern void USBDDriverCallbacks_InterfaceSettingChanged(unsigned char interface,
|
||||
unsigned char setting);
|
||||
|
||||
#endif //#ifndef USBDDRIVERCALLBACKS_H
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBDDriverCallbacks.h"
|
||||
#include <utility/trace.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates that the current configuration of the device has changed.
|
||||
/// \param cfgnum New device configuration index.
|
||||
//------------------------------------------------------------------------------
|
||||
void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
{
|
||||
TRACE_INFO_WP("ConfigurationChanged ");
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "USBDDriverCallbacks.h"
|
||||
#include <utility/trace.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Notifies of a change in the currently active setting of an interface.
|
||||
/// \param interface Number of the interface whose setting has changed.
|
||||
/// \param setting New interface setting.
|
||||
//------------------------------------------------------------------------------
|
||||
void USBDDriverCallbacks_InterfaceSettingChanged(
|
||||
unsigned char interface,
|
||||
unsigned char setting)
|
||||
{
|
||||
TRACE_INFO_WP("InterfaceSettingChanged ");
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for declaring USB descriptors required by the
|
||||
device driver.
|
||||
*/
|
||||
|
||||
#ifndef USBDDRIVERDESCRIPTORS_H
|
||||
#define USBDDRIVERDESCRIPTORS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <usb/common/core/USBDeviceDescriptor.h>
|
||||
#include <usb/common/core/USBConfigurationDescriptor.h>
|
||||
#include <usb/common/core/USBDeviceQualifierDescriptor.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// List of all descriptors used by a USB device driver. Each descriptor can
|
||||
/// be provided in two versions: full-speed and high-speed. Devices which are
|
||||
/// not high-speed capable do not need to provided high-speed descriptors and
|
||||
/// the full-speed qualifier & other speed descriptors.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Pointer to the full-speed device descriptor.
|
||||
const USBDeviceDescriptor *pFsDevice;
|
||||
/// Pointer to the full-speed configuration descriptor.
|
||||
const USBConfigurationDescriptor *pFsConfiguration;
|
||||
/// Pointer to the full-speed qualifier descriptor.
|
||||
const USBDeviceQualifierDescriptor *pFsQualifier;
|
||||
/// Pointer to the full-speed other speed configuration descriptor.
|
||||
const USBConfigurationDescriptor *pFsOtherSpeed;
|
||||
/// Pointer to the high-speed device descriptor.
|
||||
const USBDeviceDescriptor *pHsDevice;
|
||||
/// Pointer to the high-speed configuration descriptor.
|
||||
const USBConfigurationDescriptor *pHsConfiguration;
|
||||
/// Pointer to the high-speed qualifier descriptor.
|
||||
const USBDeviceQualifierDescriptor *pHsQualifier;
|
||||
/// Pointer to the high-speed other speed configuration descriptor.
|
||||
const USBConfigurationDescriptor *pHsOtherSpeed;
|
||||
/// Pointer to the list of string descriptors.
|
||||
const unsigned char **pStrings;
|
||||
/// Number of string descriptors in list.
|
||||
unsigned char numStrings;
|
||||
|
||||
} USBDDriverDescriptors;
|
||||
|
||||
#endif //#ifndef USBDDRIVERDESCRIPTORS_H
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,114 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of the ASSERT() and SANITY_CHECK() macros, which are used for
|
||||
/// runtime condition & parameter verifying.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Use ASSERT() in your code to check the value of function parameters,
|
||||
/// return values, etc. *Warning:* the ASSERT() condition must not have
|
||||
/// any side-effect; otherwise, the program may not work properly
|
||||
/// anymore when assertions are disabled.
|
||||
/// -# Use SANITY_CHECK() to perform checks with a default error message
|
||||
/// (outputs the file and line number where the error occured). This
|
||||
/// reduces memory overhead caused by assertion error strings.
|
||||
/// -# Initialize the dbgu to see failed assertions at run-time.
|
||||
/// -# Assertions can be entirely disabled by defining the NOASSERT symbol
|
||||
/// at compilation time.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef ASSERT_H
|
||||
#define ASSERT_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include "trace.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
#if defined(NOASSERT)
|
||||
#define ASSERT(...)
|
||||
#define SANITY_CHECK(...)
|
||||
#else
|
||||
|
||||
#if (TRACE_LEVEL == 0)
|
||||
/// Checks that the given condition is true,
|
||||
/// otherwise stops the program execution.
|
||||
/// \param condition Condition to verify.
|
||||
#define ASSERT(condition, ...) { \
|
||||
if (!(condition)) { \
|
||||
while (1); \
|
||||
} \
|
||||
}
|
||||
|
||||
/// Performs the same duty as the ASSERT() macro
|
||||
/// \param condition Condition to verify.
|
||||
#define SANITY_CHECK(condition) ASSERT(condition, ...)
|
||||
|
||||
#else
|
||||
/// Checks that the given condition is true, otherwise displays an error
|
||||
/// message and stops the program execution.
|
||||
/// \param condition Condition to verify.
|
||||
#define ASSERT(condition, ...) { \
|
||||
if (!(condition)) { \
|
||||
printf("-F- ASSERT: "); \
|
||||
printf(__VA_ARGS__); \
|
||||
while (1); \
|
||||
} \
|
||||
}
|
||||
#define SANITY_ERROR "Sanity check failed at %s:%d\n\r"
|
||||
|
||||
/// Performs the same duty as the ASSERT() macro, except a default error
|
||||
/// message is output if the condition is false.
|
||||
/// \param condition Condition to verify.
|
||||
#define SANITY_CHECK(condition) ASSERT(condition, SANITY_ERROR, __FILE__, __LINE__)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //#ifndef ASSERT_H
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "led.h"
|
||||
#include <board.h>
|
||||
#include <pio/pio.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local Variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef PINS_LEDS
|
||||
static const Pin pinsLeds[] = {PINS_LEDS};
|
||||
static const unsigned int numLeds = PIO_LISTSIZE(pinsLeds);
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configures the pin associated with the given LED number. If the LED does
|
||||
/// not exist on the board, the function does nothing.
|
||||
/// \param led Number of the LED to configure.
|
||||
/// \return 1 if the LED exists and has been configured; otherwise 0.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LED_Configure(unsigned int led)
|
||||
{
|
||||
#ifdef PINS_LEDS
|
||||
// Check that LED exists
|
||||
if (led >= numLeds) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Configure LED
|
||||
return (PIO_Configure(&pinsLeds[led], 1));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Turns the given LED on if it exists; otherwise does nothing.
|
||||
/// \param led Number of the LED to turn on.
|
||||
/// \return 1 if the LED has been turned on; 0 otherwise.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LED_Set(unsigned int led)
|
||||
{
|
||||
#ifdef PINS_LEDS
|
||||
// Check if LED exists
|
||||
if (led >= numLeds) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Turn LED on
|
||||
if (pinsLeds[led].type == PIO_OUTPUT_0) {
|
||||
|
||||
PIO_Set(&pinsLeds[led]);
|
||||
}
|
||||
else {
|
||||
|
||||
PIO_Clear(&pinsLeds[led]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Turns a LED off.
|
||||
/// \param led Number of the LED to turn off.
|
||||
/// \param 1 if the LED has been turned off; 0 otherwise.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LED_Clear(unsigned int led)
|
||||
{
|
||||
#ifdef PINS_LEDS
|
||||
// Check if LED exists
|
||||
if (led >= numLeds) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Turn LED off
|
||||
if (pinsLeds[led].type == PIO_OUTPUT_0) {
|
||||
|
||||
PIO_Clear(&pinsLeds[led]);
|
||||
}
|
||||
else {
|
||||
|
||||
PIO_Set(&pinsLeds[led]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Toggles the current state of a LED.
|
||||
/// \param led Number of the LED to toggle.
|
||||
/// \return 1 if the LED has been toggled; otherwise 0.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LED_Toggle(unsigned int led)
|
||||
{
|
||||
#ifdef PINS_LEDS
|
||||
// Check if LED exists
|
||||
if (led >= numLeds) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Toggle LED
|
||||
if (PIO_GetOutputDataStatus(&pinsLeds[led])) {
|
||||
|
||||
PIO_Clear(&pinsLeds[led]);
|
||||
}
|
||||
else {
|
||||
|
||||
PIO_Set(&pinsLeds[led]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Small set of functions for simple and portable LED usage.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Configure one or more LEDs using LED_Configure and
|
||||
/// LED_ConfigureAll.
|
||||
/// -# Set, clear and toggle LEDs using LED_Set, LED_Clear and
|
||||
/// LED_Toggle.
|
||||
///
|
||||
/// LEDs are numbered starting from 0; the number of LEDs depend on the
|
||||
/// board being used. All the functions defined here will compile properly
|
||||
/// regardless of whether the LED is defined or not; they will simply
|
||||
/// return 0 when a LED which does not exist is given as an argument.
|
||||
/// Also, these functions take into account how each LED is connected on to
|
||||
/// board; thus, <LED_Set> might change the level on the corresponding pin
|
||||
/// to 0 or 1, but it will always light the LED on; same thing for the other
|
||||
/// methods.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char LED_Configure(unsigned int led);
|
||||
|
||||
extern unsigned char LED_Set(unsigned int led);
|
||||
|
||||
extern unsigned char LED_Clear(unsigned int led);
|
||||
|
||||
extern unsigned char LED_Toggle(unsigned int led);
|
||||
|
||||
#endif //#ifndef LED_H
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "math.h"
|
||||
#include "trace.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the minimum value between two integers.
|
||||
/// \param a First integer to compare.
|
||||
/// \param b Second integer to compare.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int min(unsigned int a, unsigned int b)
|
||||
{
|
||||
if (a < b) {
|
||||
|
||||
return a;
|
||||
}
|
||||
else {
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the absolute value of an integer.
|
||||
/// \param value Integer value.
|
||||
//------------------------------------------------------------------------------
|
||||
// Do not call this function "abs", problem with gcc !
|
||||
unsigned int absv(signed int value)
|
||||
{
|
||||
if (value < 0) {
|
||||
|
||||
return -value;
|
||||
}
|
||||
else {
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Computes and returns x power of y.
|
||||
/// \param x Value.
|
||||
/// \param y Power.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int power(unsigned int x, unsigned int y)
|
||||
{
|
||||
unsigned int result = 1;
|
||||
|
||||
while (y > 0) {
|
||||
|
||||
result *= x;
|
||||
y--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef MATH_H
|
||||
#define MATH_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int min(unsigned int a, unsigned int b);
|
||||
extern unsigned int absv(signed int value);
|
||||
#if defined(__ARMCC_VERSION)
|
||||
extern unsigned int pow(unsigned int x, unsigned int y);
|
||||
#else
|
||||
extern unsigned int power(unsigned int x, unsigned int y);
|
||||
#endif
|
||||
#endif //#ifndef MATH_H
|
||||
|
|
@ -0,0 +1,512 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Implementation of several stdio.h methods, such as printf(), sprintf() and
|
||||
/// so on. This reduces the memory footprint of the binary when using those
|
||||
/// methods, compared to the libc implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// Adds stdio.c to the list of file to compile for the project. This will
|
||||
/// automatically replace libc methods by the custom ones.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Maximum string size allowed (in bytes).
|
||||
#define MAX_STRING_SIZE 100
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Required for proper compilation.
|
||||
struct _reent r = {0, (FILE *) 0, (FILE *) 1, (FILE *) 0};
|
||||
struct _reent *_impure_ptr = &r;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Writes a character inside the given string. Returns 1.
|
||||
// \param pStr Storage string.
|
||||
// \param c Character to write.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int PutChar(char *pStr, char c)
|
||||
{
|
||||
*pStr = c;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Writes a string inside the given string.
|
||||
// Returns the size of the written
|
||||
// string.
|
||||
// \param pStr Storage string.
|
||||
// \param pSource Source string.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int PutString(char *pStr, const char *pSource)
|
||||
{
|
||||
signed int num = 0;
|
||||
|
||||
while (*pSource != 0) {
|
||||
|
||||
*pStr++ = *pSource++;
|
||||
num++;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Writes an unsigned int inside the given string, using the provided fill &
|
||||
// width parameters.
|
||||
// Returns the size in characters of the written integer.
|
||||
// \param pStr Storage string.
|
||||
// \param fill Fill character.
|
||||
// \param width Minimum integer width.
|
||||
// \param value Integer value.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int PutUnsignedInt(
|
||||
char *pStr,
|
||||
char fill,
|
||||
signed int width,
|
||||
unsigned int value)
|
||||
{
|
||||
signed int num = 0;
|
||||
|
||||
// Take current digit into account when calculating width
|
||||
width--;
|
||||
|
||||
// Recursively write upper digits
|
||||
if ((value / 10) > 0) {
|
||||
|
||||
num = PutUnsignedInt(pStr, fill, width, value / 10);
|
||||
pStr += num;
|
||||
}
|
||||
// Write filler characters
|
||||
else {
|
||||
|
||||
while (width > 0) {
|
||||
|
||||
PutChar(pStr, fill);
|
||||
pStr++;
|
||||
num++;
|
||||
width--;
|
||||
}
|
||||
}
|
||||
|
||||
// Write lower digit
|
||||
num += PutChar(pStr, (value % 10) + '0');
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Writes a signed int inside the given string, using the provided fill & width
|
||||
// parameters.
|
||||
// Returns the size of the written integer.
|
||||
// \param pStr Storage string.
|
||||
// \param fill Fill character.
|
||||
// \param width Minimum integer width.
|
||||
// \param value Signed integer value.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int PutSignedInt(
|
||||
char *pStr,
|
||||
char fill,
|
||||
signed int width,
|
||||
signed int value)
|
||||
{
|
||||
signed int num = 0;
|
||||
unsigned int absolute;
|
||||
|
||||
// Compute absolute value
|
||||
if (value < 0) {
|
||||
|
||||
absolute = -value;
|
||||
}
|
||||
else {
|
||||
|
||||
absolute = value;
|
||||
}
|
||||
|
||||
// Take current digit into account when calculating width
|
||||
width--;
|
||||
|
||||
// Recursively write upper digits
|
||||
if ((absolute / 10) > 0) {
|
||||
|
||||
if (value < 0) {
|
||||
|
||||
num = PutSignedInt(pStr, fill, width, -(absolute / 10));
|
||||
}
|
||||
else {
|
||||
|
||||
num = PutSignedInt(pStr, fill, width, absolute / 10);
|
||||
}
|
||||
pStr += num;
|
||||
}
|
||||
else {
|
||||
|
||||
// Reserve space for sign
|
||||
if (value < 0) {
|
||||
|
||||
width--;
|
||||
}
|
||||
|
||||
// Write filler characters
|
||||
while (width > 0) {
|
||||
|
||||
PutChar(pStr, fill);
|
||||
pStr++;
|
||||
num++;
|
||||
width--;
|
||||
}
|
||||
|
||||
// Write sign
|
||||
if (value < 0) {
|
||||
|
||||
num += PutChar(pStr, '-');
|
||||
pStr++;
|
||||
}
|
||||
}
|
||||
|
||||
// Write lower digit
|
||||
num += PutChar(pStr, (absolute % 10) + '0');
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Writes an hexadecimal value into a string, using the given fill, width &
|
||||
// capital parameters.
|
||||
// Returns the number of char written.
|
||||
// \param pStr Storage string.
|
||||
// \param fill Fill character.
|
||||
// \param width Minimum integer width.
|
||||
// \param maj Indicates if the letters must be printed in lower- or upper-case.
|
||||
// \param value Hexadecimal value.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int PutHexa(
|
||||
char *pStr,
|
||||
char fill,
|
||||
signed int width,
|
||||
unsigned char maj,
|
||||
unsigned int value)
|
||||
{
|
||||
signed int num = 0;
|
||||
|
||||
// Decrement width
|
||||
width--;
|
||||
|
||||
// Recursively output upper digits
|
||||
if ((value >> 4) > 0) {
|
||||
|
||||
num += PutHexa(pStr, fill, width, maj, value >> 4);
|
||||
pStr += num;
|
||||
}
|
||||
// Write filler chars
|
||||
else {
|
||||
|
||||
while (width > 0) {
|
||||
|
||||
PutChar(pStr, fill);
|
||||
pStr++;
|
||||
num++;
|
||||
width--;
|
||||
}
|
||||
}
|
||||
|
||||
// Write current digit
|
||||
if ((value & 0xF) < 10) {
|
||||
|
||||
PutChar(pStr, (value & 0xF) + '0');
|
||||
}
|
||||
else if (maj) {
|
||||
|
||||
PutChar(pStr, (value & 0xF) - 10 + 'A');
|
||||
}
|
||||
else {
|
||||
|
||||
PutChar(pStr, (value & 0xF) - 10 + 'a');
|
||||
}
|
||||
num++;
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Stores the result of a formatted string into another string. Format
|
||||
/// arguments are given in a va_list instance.
|
||||
/// Return the number of characters written.
|
||||
/// \param pStr Destination string.
|
||||
/// \param length Length of Destination string.
|
||||
/// \param pFormat Format string.
|
||||
/// \param ap Argument list.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int vsnprintf(char *pStr, size_t length, const char *pFormat, va_list ap)
|
||||
{
|
||||
char fill;
|
||||
unsigned char width;
|
||||
signed int num = 0;
|
||||
signed int size = 0;
|
||||
|
||||
// Clear the string
|
||||
if (pStr) {
|
||||
|
||||
*pStr = 0;
|
||||
}
|
||||
|
||||
// Phase string
|
||||
while (*pFormat != 0 && size < length) {
|
||||
|
||||
// Normal character
|
||||
if (*pFormat != '%') {
|
||||
|
||||
*pStr++ = *pFormat++;
|
||||
size++;
|
||||
}
|
||||
// Escaped '%'
|
||||
else if (*(pFormat+1) == '%') {
|
||||
|
||||
*pStr++ = '%';
|
||||
pFormat += 2;
|
||||
size++;
|
||||
}
|
||||
// Token delimiter
|
||||
else {
|
||||
|
||||
fill = ' ';
|
||||
width = 0;
|
||||
pFormat++;
|
||||
|
||||
// Parse filler
|
||||
if (*pFormat == '0') {
|
||||
|
||||
fill = '0';
|
||||
pFormat++;
|
||||
}
|
||||
|
||||
// Parse width
|
||||
while ((*pFormat >= '0') && (*pFormat <= '9')) {
|
||||
|
||||
width = (width*10) + *pFormat-'0';
|
||||
pFormat++;
|
||||
}
|
||||
|
||||
// Check if there is enough space
|
||||
if (size + width > length) {
|
||||
|
||||
width = length - size;
|
||||
}
|
||||
|
||||
// Parse type
|
||||
switch (*pFormat) {
|
||||
case 'd':
|
||||
case 'i': num = PutSignedInt(pStr, fill, width, va_arg(ap, signed int)); break;
|
||||
case 'u': num = PutUnsignedInt(pStr, fill, width, va_arg(ap, unsigned int)); break;
|
||||
case 'x': num = PutHexa(pStr, fill, width, 0, va_arg(ap, unsigned int)); break;
|
||||
case 'X': num = PutHexa(pStr, fill, width, 1, va_arg(ap, unsigned int)); break;
|
||||
case 's': num = PutString(pStr, va_arg(ap, char *)); break;
|
||||
case 'c': num = PutChar(pStr, va_arg(ap, unsigned int)); break;
|
||||
default:
|
||||
return EOF;
|
||||
}
|
||||
|
||||
pFormat++;
|
||||
pStr += num;
|
||||
size += num;
|
||||
}
|
||||
}
|
||||
|
||||
// NULL-terminated (final \0 is not counted)
|
||||
if (size < length) {
|
||||
|
||||
*pStr = 0;
|
||||
}
|
||||
else {
|
||||
|
||||
*(--pStr) = 0;
|
||||
size--;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Stores the result of a formatted string into another string. Format
|
||||
/// arguments are given in a va_list instance.
|
||||
/// Return the number of characters written.
|
||||
/// \param pString Destination string.
|
||||
/// \param length Length of Destination string.
|
||||
/// \param pFormat Format string.
|
||||
/// \param ... Other arguments
|
||||
//------------------------------------------------------------------------------
|
||||
signed int snprintf(char *pString, size_t length, const char *pFormat, ...)
|
||||
{
|
||||
va_list ap;
|
||||
signed int rc;
|
||||
|
||||
va_start(ap, pFormat);
|
||||
rc = vsnprintf(pString, length, pFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Stores the result of a formatted string into another string. Format
|
||||
/// arguments are given in a va_list instance.
|
||||
/// Return the number of characters written.
|
||||
/// \param pString Destination string.
|
||||
/// \param pFormat Format string.
|
||||
/// \param ap Argument list.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int vsprintf(char *pString, const char *pFormat, va_list ap)
|
||||
{
|
||||
return vsnprintf(pString, MAX_STRING_SIZE, pFormat, ap);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Outputs a formatted string on the given stream. Format arguments are given
|
||||
/// in a va_list instance.
|
||||
/// \param pStream Output stream.
|
||||
/// \param pFormat Format string
|
||||
/// \param ap Argument list.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap)
|
||||
{
|
||||
char pStr[MAX_STRING_SIZE];
|
||||
char pError[] = "stdio.c: increase MAX_STRING_SIZE\n\r";
|
||||
|
||||
// Write formatted string in buffer
|
||||
if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) {
|
||||
|
||||
fputs(pError, stderr);
|
||||
while (1); // Increase MAX_STRING_SIZE
|
||||
}
|
||||
|
||||
// Display string
|
||||
return fputs(pStr, pStream);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Outputs a formatted string on the DBGU stream. Format arguments are given
|
||||
/// in a va_list instance.
|
||||
/// \param pFormat Format string
|
||||
/// \param ap Argument list.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int vprintf(const char *pFormat, va_list ap)
|
||||
{
|
||||
return vfprintf(stdout, pFormat, ap);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Outputs a formatted string on the given stream, using a variable number of
|
||||
/// arguments.
|
||||
/// \param pStream Output stream.
|
||||
/// \param pFormat Format string.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int fprintf(FILE *pStream, const char *pFormat, ...)
|
||||
{
|
||||
va_list ap;
|
||||
signed int result;
|
||||
|
||||
// Forward call to vfprintf
|
||||
va_start(ap, pFormat);
|
||||
result = vfprintf(pStream, pFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Outputs a formatted string on the DBGU stream, using a variable number of
|
||||
/// arguments.
|
||||
/// \param pFormat Format string.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int printf(const char *pFormat, ...)
|
||||
{
|
||||
va_list ap;
|
||||
signed int result;
|
||||
|
||||
// Forward call to vprintf
|
||||
va_start(ap, pFormat);
|
||||
result = vprintf(pFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Writes a formatted string inside another string.
|
||||
/// \param pStr Storage string.
|
||||
/// \param pFormat Format string.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int sprintf(char *pStr, const char *pFormat, ...)
|
||||
{
|
||||
va_list ap;
|
||||
signed int result;
|
||||
|
||||
// Forward call to vsprintf
|
||||
va_start(ap, pFormat);
|
||||
result = vsprintf(pStr, pFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Outputs a string on stdout.
|
||||
/// \param pStr String to output.
|
||||
//------------------------------------------------------------------------------
|
||||
signed int puts(const char *pStr)
|
||||
{
|
||||
return fputs(pStr, stdout);
|
||||
}
|
||||
|
|
@ -0,0 +1,236 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !Purpose
|
||||
///
|
||||
/// Standard output methods for reporting debug information, warnings and
|
||||
/// errors, which can be easily be turned on/off.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Initialize the DBGU using TRACE_CONFIGURE() if you intend to eventually
|
||||
/// disable ALL traces; otherwise use DBGU_Configure().
|
||||
/// -# Uses the TRACE_DEBUG(), TRACE_INFO(), TRACE_WARNING(), TRACE_ERROR()
|
||||
/// TRACE_FATAL() macros to output traces throughout the program.
|
||||
/// -# Each type of trace has a level : Debug 5, Info 4, Warning 3, Error 2
|
||||
/// and Fatal 1. Disable a group of traces by changing the value of
|
||||
/// TRACE_LEVEL during compilation; traces with a level bigger than TRACE_LEVEL
|
||||
/// are not generated. To generate no trace, use the reserved value 0.
|
||||
/// -# Trace disabling can be static or dynamic. If dynamic disabling is selected
|
||||
/// the trace level can be modified in runtime. If static disabling is selected
|
||||
/// the disabled traces are not compiled.
|
||||
///
|
||||
/// !Trace level description
|
||||
/// -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program,
|
||||
/// and which do not produce meaningful information otherwise.
|
||||
/// -# TRACE_INFO (4): Informational trace about the program execution. Should
|
||||
/// enable the user to see the execution flow.
|
||||
/// -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case
|
||||
/// it can be discarded safely; it may even be expected.
|
||||
/// -# TRACE_ERROR (2): Indicates an error which may not stop the program execution,
|
||||
/// but which indicates there is a problem with the code.
|
||||
/// -# TRACE_FATAL (1): Indicates a major error which prevents the program from going
|
||||
/// any further.
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef TRACE_H
|
||||
#define TRACE_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <board.h>
|
||||
#include <dbgu/dbgu.h>
|
||||
#include <pio/pio.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Softpack Version
|
||||
#define SOFTPACK_VERSION "1.5"
|
||||
|
||||
#define TRACE_LEVEL_DEBUG 5
|
||||
#define TRACE_LEVEL_INFO 4
|
||||
#define TRACE_LEVEL_WARNING 3
|
||||
#define TRACE_LEVEL_ERROR 2
|
||||
#define TRACE_LEVEL_FATAL 1
|
||||
#define TRACE_LEVEL_NO_TRACE 0
|
||||
|
||||
// By default, all traces are output except the debug one.
|
||||
#if !defined(TRACE_LEVEL)
|
||||
#define TRACE_LEVEL TRACE_LEVEL_INFO
|
||||
#endif
|
||||
|
||||
// By default, trace level is static (not dynamic)
|
||||
#if !defined(DYN_TRACES)
|
||||
#define DYN_TRACES 0
|
||||
#endif
|
||||
|
||||
#if defined(NOTRACE)
|
||||
#error "Error: NOTRACE has to be not defined !"
|
||||
#endif
|
||||
|
||||
#undef NOTRACE
|
||||
#if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
|
||||
#define NOTRACE
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global Macros
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes the DBGU
|
||||
/// \param mode DBGU mode.
|
||||
/// \param baudrate DBGU baudrate.
|
||||
/// \param mck Master clock frequency.
|
||||
//------------------------------------------------------------------------------
|
||||
#define TRACE_CONFIGURE(mode, baudrate, mck) { \
|
||||
const Pin pinsDbgu[] = {PINS_DBGU}; \
|
||||
PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \
|
||||
DBGU_Configure(mode, baudrate, mck); \
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes the DBGU for ISP project
|
||||
/// \param mode DBGU mode.
|
||||
/// \param baudrate DBGU baudrate.
|
||||
/// \param mck Master clock frequency.
|
||||
//------------------------------------------------------------------------------
|
||||
#if (TRACE_LEVEL==0) && (DYNTRACE==0)
|
||||
#define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {}
|
||||
#else
|
||||
#define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \
|
||||
const Pin pinsDbgu[] = {PINS_DBGU}; \
|
||||
PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \
|
||||
DBGU_Configure(mode, baudrate, mck); \
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Outputs a formatted string using <printf> if the log level is high
|
||||
/// enough. Can be disabled by defining TRACE_LEVEL=0 during compilation.
|
||||
/// \param format Formatted string to output.
|
||||
/// \param ... Additional parameters depending on formatted string.
|
||||
//------------------------------------------------------------------------------
|
||||
#if defined(NOTRACE)
|
||||
|
||||
// Empty macro
|
||||
#define TRACE_DEBUG(...) { }
|
||||
#define TRACE_INFO(...) { }
|
||||
#define TRACE_WARNING(...) { }
|
||||
#define TRACE_ERROR(...) { }
|
||||
#define TRACE_FATAL(...) { while(1); }
|
||||
|
||||
#define TRACE_DEBUG_WP(...) { }
|
||||
#define TRACE_INFO_WP(...) { }
|
||||
#define TRACE_WARNING_WP(...) { }
|
||||
#define TRACE_ERROR_WP(...) { }
|
||||
#define TRACE_FATAL_WP(...) { while(1); }
|
||||
|
||||
#elif (DYN_TRACES == 1)
|
||||
|
||||
// Trace output depends on traceLevel value
|
||||
#define TRACE_DEBUG(...) { if (traceLevel >= TRACE_LEVEL_DEBUG) { printf("-D- " __VA_ARGS__); } }
|
||||
#define TRACE_INFO(...) { if (traceLevel >= TRACE_LEVEL_INFO) { printf("-I- " __VA_ARGS__); } }
|
||||
#define TRACE_WARNING(...) { if (traceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
|
||||
#define TRACE_ERROR(...) { if (traceLevel >= TRACE_LEVEL_ERROR) { printf("-E- " __VA_ARGS__); } }
|
||||
#define TRACE_FATAL(...) { if (traceLevel >= TRACE_LEVEL_FATAL) { printf("-F- " __VA_ARGS__); while(1); } }
|
||||
|
||||
#define TRACE_DEBUG_WP(...) { if (traceLevel >= TRACE_LEVEL_DEBUG) { printf(__VA_ARGS__); } }
|
||||
#define TRACE_INFO_WP(...) { if (traceLevel >= TRACE_LEVEL_INFO) { printf(__VA_ARGS__); } }
|
||||
#define TRACE_WARNING_WP(...) { if (traceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
|
||||
#define TRACE_ERROR_WP(...) { if (traceLevel >= TRACE_LEVEL_ERROR) { printf(__VA_ARGS__); } }
|
||||
#define TRACE_FATAL_WP(...) { if (traceLevel >= TRACE_LEVEL_FATAL) { printf(__VA_ARGS__); while(1); } }
|
||||
|
||||
#else
|
||||
|
||||
// Trace compilation depends on TRACE_LEVEL value
|
||||
#if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
|
||||
#define TRACE_DEBUG(...) { printf("-D- " __VA_ARGS__); }
|
||||
#define TRACE_DEBUG_WP(...) { printf(__VA_ARGS__); }
|
||||
#else
|
||||
#define TRACE_DEBUG(...) { }
|
||||
#define TRACE_DEBUG_WP(...) { }
|
||||
#endif
|
||||
|
||||
#if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
|
||||
#define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); }
|
||||
#define TRACE_INFO_WP(...) { printf(__VA_ARGS__); }
|
||||
#else
|
||||
#define TRACE_INFO(...) { }
|
||||
#define TRACE_INFO_WP(...) { }
|
||||
#endif
|
||||
|
||||
#if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
|
||||
#define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); }
|
||||
#define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
|
||||
#else
|
||||
#define TRACE_WARNING(...) { }
|
||||
#define TRACE_WARNING_WP(...) { }
|
||||
#endif
|
||||
|
||||
#if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
|
||||
#define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); }
|
||||
#define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); }
|
||||
#else
|
||||
#define TRACE_ERROR(...) { }
|
||||
#define TRACE_ERROR_WP(...) { }
|
||||
#endif
|
||||
|
||||
#if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
|
||||
#define TRACE_FATAL(...) { printf("-F- " __VA_ARGS__); while(1); }
|
||||
#define TRACE_FATAL_WP(...) { printf(__VA_ARGS__); while(1); }
|
||||
#else
|
||||
#define TRACE_FATAL(...) { while(1); }
|
||||
#define TRACE_FATAL_WP(...) { while(1); }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported variables
|
||||
//------------------------------------------------------------------------------
|
||||
// Depending on DYN_TRACES, traceLevel is a modifable runtime variable
|
||||
// or a define
|
||||
#if !defined(NOTRACE) && (DYN_TRACES == 1)
|
||||
extern unsigned int traceLevel;
|
||||
#endif
|
||||
|
||||
#endif //#ifndef TRACE_H
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
# SDRAM initialization script for the AT91SAM7SE
|
||||
#-----------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Enable PLL
|
||||
set *0xFFFFFC2C = 0x1048100E
|
||||
while ((*0xFFFFFC68 & 0x4) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler value
|
||||
set *0xFFFFFC30 = 0x00000004
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000007
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
echo Configuring the SDRAM controller...\n
|
||||
|
||||
# Enable EBI chip select for the SDRAM
|
||||
set *0xFFFFFF80 = 0x2
|
||||
|
||||
# Enable EBI pios
|
||||
# PMC
|
||||
set *0xFFFFFC10 = 0x1C
|
||||
# PIOA
|
||||
set *0xFFFFF404 = 0x3F800000
|
||||
set *0xFFFFF474 = 0x3F800000
|
||||
# PIOB
|
||||
set *0xFFFFF604 = 0x0003FFFF
|
||||
set *0xFFFFF674 = 0x0003FFFF
|
||||
# PIOC
|
||||
set *0xFFFFF804 = 0x0000FFFF
|
||||
set *0xFFFFF870 = 0x0000FFFF
|
||||
|
||||
# SDRAM configuration (see corresponding application note)
|
||||
set *0xFFFFFFB8 = 0x21922159
|
||||
|
||||
set *0xFFFFFFB0 = 0x11
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFFFB0 = 0x12
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFFFB0 = 0x14
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFFFB0 = 0x14
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFFFB0 = 0x14
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFFFB0 = 0x14
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFFFB0 = 0x14
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFFFB0 = 0x14
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFFFB0 = 0x14
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFFFB0 = 0x14
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFFFB0 = 0x13
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFFFB0 = 0x10
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFFFB4 = 0x150
|
||||
|
||||
echo SDRAM configuration ok.\n
|
|
@ -0,0 +1,70 @@
|
|||
# SDRAM initialization script for the AT91SAM9260
|
||||
#------------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLLA to 200MHz
|
||||
set *0xFFFFFC28 = 0x2060BF09
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Set PLLB for USB usage
|
||||
set *0xFFFFFC2C = 0x207C3F0C
|
||||
while ((*0xFFFFFC68 & 0x4) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00000100
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000102
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
echo Configuring the SDRAM controller...\n
|
||||
|
||||
# Enable EBI chip select for the SDRAM
|
||||
set *0xFFFFEF1C = 0x2
|
||||
|
||||
# SDRAM configuration
|
||||
set *0xFFFFEA08 = 0x85227259
|
||||
|
||||
set *0xFFFFEA00 = 0x1
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x2
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x3
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x0
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA04 = 0x2B7
|
||||
|
||||
echo SDRAM configuration ok.\n
|
|
@ -0,0 +1,26 @@
|
|||
# MCK initialization script for the AT91SAM9260
|
||||
#------------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLLA to 200MHz
|
||||
set *0xFFFFFC28 = 0x2060BF09
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00000100
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000102
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
# SDRAM initialization script for the AT91SAM9263
|
||||
#------------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLLA to 200MHz
|
||||
set *0xFFFFFC28 = 0x206DBF09
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Set PLLB for USB usage
|
||||
set *0xFFFFFC2C = 0x20AF3F0F
|
||||
while ((*0xFFFFFC68 & 0x4) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00000100
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000102
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
echo Configuring the SDRAM controller...\n
|
||||
|
||||
# Configure PIOD as peripheral (D16/D31)
|
||||
# __writeMemory32(0xFFFF0000,0xFFFFF870,"Memory");
|
||||
set *0xFFFFF870 = 0xFFFF0000
|
||||
# __writeMemory32(0x00000000,0xFFFFF874,"Memory");
|
||||
set *0xFFFFF874 = 0x00000000
|
||||
# __writeMemory32(0xFFFF0000,0xFFFFF804,"Memory");
|
||||
set *0xFFFFF804 = 0xFFFF0000
|
||||
|
||||
# Enable EBI chip select for the SDRAM
|
||||
set *0xFFFFED20 = 0x2
|
||||
|
||||
# SDRAM configuration
|
||||
set *0xFFFFE208 = 0x85227259
|
||||
|
||||
set *0xFFFFE200 = 0x1
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFE200 = 0x2
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFE200 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFE200 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFE200 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFE200 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFE200 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFE200 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFE200 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFE200 = 0x4
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFE200 = 0x3
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFE200 = 0x0
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFE204 = 0x2B7
|
||||
|
||||
echo SDRAM configuration ok.\n
|
|
@ -0,0 +1,25 @@
|
|||
# MCK initialization script for the AT91SAM9263
|
||||
#------------------------------------------------
|
||||
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLLA to 200MHz
|
||||
set *0xFFFFFC28 = 0x206DBF09
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00000100
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000102
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
|
@ -0,0 +1,75 @@
|
|||
# SDRAM initialization script for the AT91SAM9G20
|
||||
#------------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLLA to 800MHz
|
||||
set *0xFFFFFC28 = 0x202A3F01
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Set PLLB for USB usage
|
||||
set *0xFFFFFC2C = 0x10193F05
|
||||
while ((*0xFFFFFC68 & 0x4) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00001300
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00001302
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
echo Configuring the SDRAM controller...\n
|
||||
|
||||
# Enable EBI chip select for the SDRAM
|
||||
set *0xFFFFEF1C = 0x2
|
||||
|
||||
# Enable PC16-PC31 pins
|
||||
set *0xFFFFF870 = 0xFFFF0000
|
||||
set *0xFFFFF874 = 0x00000000
|
||||
set *0xFFFFF804 = 0xFFFF0000
|
||||
|
||||
# SDRAM configuration
|
||||
set *0xFFFFEA08 = 0x96338379
|
||||
|
||||
set *0xFFFFEA00 = 0x1
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x2
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x3
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x0
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA04 = 0x39D
|
||||
|
||||
echo SDRAM configuration ok.\n
|
|
@ -0,0 +1,26 @@
|
|||
# MCK initialization script for the AT91SAM9G20
|
||||
#------------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLLA to 800MHz
|
||||
set *0xFFFFFC28 = 0x202A3F01
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00001300
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00001302
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
# SDRAM initialization script for the AT91SAM9RL
|
||||
#------------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLL to 200MHz
|
||||
set *0xFFFFFC28 = 0x2031BF03
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00000100
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000102
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
echo Configuring the SDRAM controller...\n
|
||||
|
||||
# Enable EBI chip select for the SDRAM
|
||||
set *0xFFFFEF20 = 0x2
|
||||
|
||||
# SDRAM configuration
|
||||
set *0xFFFFEA08 = 0x85227259
|
||||
|
||||
set *0xFFFFEA00 = 0x1
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x2
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x3
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x0
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA04 = 0x2BC
|
||||
|
||||
echo SDRAM configuration ok.\n
|
|
@ -0,0 +1,25 @@
|
|||
# MCK initialization script for the AT91SAM9RL
|
||||
#------------------------------------------------
|
||||
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLL to 200MHz
|
||||
set *0xFFFFFC28 = 0x0031BF03
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00000100
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000102
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
|
@ -0,0 +1,70 @@
|
|||
# SDRAM initialization script for the AT91SAM9XE
|
||||
#------------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLLA to 200MHz
|
||||
set *0xFFFFFC28 = 0x2060BF09
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Set PLLB for USB usage
|
||||
set *0xFFFFFC2C = 0x207C7F0C
|
||||
while ((*0xFFFFFC68 & 0x4) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00000100
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000102
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
echo Configuring the SDRAM controller...\n
|
||||
|
||||
# Enable EBI chip select for the SDRAM
|
||||
set *0xFFFFEF1C = 0x2
|
||||
|
||||
# SDRAM configuration
|
||||
set *0xFFFFEA08 = 0x85227259
|
||||
|
||||
set *0xFFFFEA00 = 0x1
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x2
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
set *0xFFFFEA00 = 0x4
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x3
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA00 = 0x0
|
||||
set *0x20000000 = 0
|
||||
|
||||
set *0xFFFFEA04 = 0x2B7
|
||||
|
||||
echo SDRAM configuration ok.\n
|
|
@ -0,0 +1,26 @@
|
|||
# MCK initialization script for the AT91SAM9XE
|
||||
#------------------------------------------------
|
||||
# Configure master clock
|
||||
echo Configuring the master clock...\n
|
||||
# Enable main oscillator
|
||||
set *0xFFFFFC20 = 0x00004001
|
||||
while ((*0xFFFFFC68 & 0x1) == 0)
|
||||
end
|
||||
|
||||
# Set PLLA to 200MHz
|
||||
set *0xFFFFFC28 = 0x2060BF09
|
||||
while ((*0xFFFFFC68 & 0x2) == 0)
|
||||
end
|
||||
|
||||
# Select prescaler
|
||||
set *0xFFFFFC30 = 0x00000100
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
# Select master clock
|
||||
set *0xFFFFFC30 = 0x00000102
|
||||
while ((*0xFFFFFC68 & 0x8) == 0)
|
||||
end
|
||||
|
||||
echo Master clock ok.\n
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
# Perl script to easily launch AT91 debug sessions.
|
||||
|
||||
use File::Basename;
|
||||
|
||||
# List of supported boards
|
||||
my @boards = ("at91sam7se-ek",
|
||||
"at91sam9260-ek",
|
||||
"at91sam9261-ek",
|
||||
"at91sam9263-ek",
|
||||
"at91sam9rl-ek",
|
||||
"at91sam9xe-ek",
|
||||
"at91sam9g20-ek",
|
||||
"at91sam9m10-ek",
|
||||
"at91cap9-dk",
|
||||
"at91cap9-stk"
|
||||
);
|
||||
|
||||
# Check that an argument has been provided
|
||||
if (!@ARGV[0]) {
|
||||
|
||||
print("Usage: " . basename($0) . " <elf-file>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
# Parse file name
|
||||
my $file = @ARGV[0];
|
||||
my $script = "";
|
||||
my $gdb = dirname($0);
|
||||
|
||||
# Check #2: this must be an elf file
|
||||
if ($file !~ m/.*.elf/i) {
|
||||
|
||||
print(".elf file expected.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
# Check #1: 'sdram' or 'ddram' or 'bcram' token in filename
|
||||
if (($file =~ m/.*sdram.*/i) or ($file =~ m/.*ddram.*/i) or ($file =~ m/.*bcram.*/i) or ($file =~ m/.*sam9.*/i) or ($file =~ m/.*cap9.*/i) ) {
|
||||
|
||||
# Find board basename
|
||||
foreach $board (@boards) {
|
||||
|
||||
if (index($file, $board) != -1) {
|
||||
|
||||
$script = "$gdb\\$board";
|
||||
}
|
||||
}
|
||||
|
||||
# Add -ek-mck or -ek-sdram depending on need
|
||||
if ($file =~ m/.*sdram.*/i) {
|
||||
|
||||
$script .= "-sdram.gdb";
|
||||
}
|
||||
elsif ($file =~ m/.*ddram.*/i) {
|
||||
|
||||
$script .= "-ddram.gdb";
|
||||
}
|
||||
elsif ($file =~ m/.*bcram.*/i) {
|
||||
|
||||
$script .= "-bcram.gdb";
|
||||
}
|
||||
else {
|
||||
|
||||
$script .= "-sram.gdb";
|
||||
}
|
||||
}
|
||||
|
||||
# Create command file to define "reset" command
|
||||
open(CMD, ">cmd.gdb") or die("Could not create command file:\n$!");
|
||||
print(CMD "define reset\n");
|
||||
print(CMD " target remote localhost:2331\n");
|
||||
print(CMD " monitor reset\n");
|
||||
if ($script) {
|
||||
|
||||
print(CMD " source $script\n");
|
||||
}
|
||||
print(CMD " load\n");
|
||||
print(CMD "end");
|
||||
close(CMD);
|
||||
|
||||
# Launch GDB
|
||||
$pid = fork();
|
||||
if ($pid == 0) {
|
||||
|
||||
exec("arm-none-eabi-gdb -x cmd.gdb -ex \"reset\" $file");
|
||||
}
|
||||
else {
|
||||
|
||||
$SIG{INT} = 'IGNORE';
|
||||
$res = waitpid($pid, 0);
|
||||
}
|
||||
print("Done\n");
|
||||
unlink("cmd.gdb");
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue