ext: hal: Remove Altera HAL from the tree and use a module
Use an external Altera HAL repo instead of keeping a copy in ext/hal. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
ffa10eba83
commit
4181d41643
|
@ -1,3 +1,2 @@
|
|||
add_subdirectory(lib)
|
||||
add_subdirectory(hal)
|
||||
add_subdirectory(debug)
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
menu "External Sources"
|
||||
|
||||
source "ext/hal/Kconfig"
|
||||
|
||||
source "ext/lib/crypto/Kconfig"
|
||||
|
||||
source "ext/lib/fnmatch/Kconfig"
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
add_subdirectory_ifdef(CONFIG_HAS_ALTERA_HAL altera)
|
|
@ -1,12 +0,0 @@
|
|||
# External HAL source code configuration options
|
||||
|
||||
# Copyright (c) 2016-2017 Linaro Ltd.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# When adding new entries keep the list in alphabetical order
|
||||
|
||||
menu "HALs"
|
||||
|
||||
source "ext/hal/altera/Kconfig"
|
||||
|
||||
endmenu
|
|
@ -1,62 +0,0 @@
|
|||
|
||||
#nios2 core/system level headers
|
||||
zephyr_include_directories(
|
||||
include
|
||||
altera_hal/HAL/inc
|
||||
)
|
||||
|
||||
zephyr_compile_definitions(ZEPHYR_RTOS)
|
||||
add_subdirectory(altera_hal/HAL/src)
|
||||
|
||||
if(CONFIG_ALTERA_AVALON_TIMER)
|
||||
zephyr_include_directories(
|
||||
drivers/altera_avalon_timer/inc
|
||||
drivers/altera_avalon_timer/HAL/inc
|
||||
)
|
||||
add_subdirectory(drivers/altera_avalon_timer/HAL/src)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ALTERA_AVALON_SYSID)
|
||||
zephyr_include_directories(
|
||||
drivers/altera_avalon_sysid/inc
|
||||
drivers/altera_avalon_sysid/HAL/inc
|
||||
)
|
||||
add_subdirectory(drivers/altera_avalon_sysid/HAL/src)
|
||||
endif()
|
||||
|
||||
if(CONFIG_UART_ALTERA_JTAG)
|
||||
zephyr_compile_definitions(ALTERA_AVALON_JTAG_UART_SMALL)
|
||||
zephyr_include_directories(
|
||||
drivers/altera_avalon_jtag_uart/inc
|
||||
drivers/altera_avalon_jtag_uart/HAL/inc
|
||||
drivers/altera_avalon_jtag_uart/LWHAL/inc
|
||||
)
|
||||
add_subdirectory(
|
||||
drivers/altera_avalon_jtag_uart/HAL/src
|
||||
drivers/altera_avalon_jtag_uart/LWHAL/src
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ALTERA_AVALON_MSGDMA)
|
||||
zephyr_include_directories(
|
||||
drivers/altera_msgdma/inc
|
||||
drivers/altera_msgdma/HAL/inc
|
||||
)
|
||||
add_subdirectory(drivers/altera_msgdma/HAL/src)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ALTERA_AVALON_I2C)
|
||||
zephyr_include_directories(
|
||||
drivers/altera_avalon_i2c/inc
|
||||
drivers/altera_avalon_i2c/HAL/inc
|
||||
)
|
||||
add_subdirectory(drivers/altera_avalon_i2c/HAL/src)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ALTERA_AVALON_QSPI)
|
||||
zephyr_include_directories(
|
||||
drivers/altera_generic_qspi_controller2/inc
|
||||
drivers/altera_generic_qspi_controller2/HAL/inc
|
||||
)
|
||||
endif()
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
Altera HAL
|
||||
#####################
|
||||
|
||||
Origin:
|
||||
Altera Quartus Prime Lite SDK
|
||||
http://dl.altera.com/?edition=lite
|
||||
|
||||
Status:
|
||||
v17.0
|
||||
|
||||
Purpose:
|
||||
Hardware Abstraction Layer for NIOSII based soft IP blocks.
|
||||
|
||||
Description:
|
||||
Altera Hardware Abstraction Layer(or Altera HAL) provides the
|
||||
low level driver support for NIOSII based soft IP blocks.
|
||||
|
||||
Altera HAL primarily abstracts the low level hardware interactions
|
||||
of different NIOSII based soft IP blocks like UART, I2C, SPI etc...
|
||||
and provides the high level API's for the shim drivers.
|
||||
|
||||
Dependencies:
|
||||
Some of the Altera HAL drivers have dependency on the newlibc and
|
||||
it needs to be enabled before enabling the Altera HAL.
|
||||
|
||||
The NIOSII port of Zephyr will be accessing the Altera HAL through
|
||||
shim drivers to enable the different soft IP blocks on Zephyr.
|
||||
|
||||
URL:
|
||||
https://www.altera.com/products/processors/support.html
|
||||
|
||||
Maintained-by:
|
||||
External
|
||||
|
||||
License:
|
||||
MIT
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef __ALT_COMMON_H__
|
||||
#define __ALT_COMMON_H__
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
extern void alt_handle_irq(void* base, alt_u32 id);
|
||||
|
||||
#endif /* __ALT_COMMON_H__ */
|
|
@ -1,96 +0,0 @@
|
|||
#ifndef __ALT_FLAG_H__
|
||||
#define __ALT_FLAG_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* This header provides macro definitions that can be used to create and use
|
||||
* uc/OS-II style event flags. These macros can be used in both a uC/OS-II based
|
||||
* environment, and a single threaded HAL based environment.
|
||||
*
|
||||
* The motivation for these macros is to allow code to be developed which is
|
||||
* thread safe under uC/OS-II, but incurs no additional overhead when used in a
|
||||
* single threaded HAL environment.
|
||||
*
|
||||
* In the case of a single threaded HAL environment, they compile to
|
||||
* "do nothing" directives, which ensures they do not contribute to the final
|
||||
* executable.
|
||||
*
|
||||
* The following macros are available:
|
||||
*
|
||||
* ALT_FLAG_GRP - Create a flag group instance.
|
||||
* ALT_EXTERN_FLAG_GRP - Create a reference to an external flag group instance.
|
||||
* ALT_STATIC_FLAG_GRP - Create a static flag group instance.
|
||||
* ALT_FLAG_CREATE - Initialise a flag group.
|
||||
* ALT_FLAG_PEND - Pend on a flag group.
|
||||
* ALT_FLAG_POST - Set a flag condition.
|
||||
|
||||
*
|
||||
* Input arguments and return codes are all consistant with the equivalent
|
||||
* uC/OS-II function.
|
||||
*
|
||||
* It's important to be careful in the use of the macros: ALT_FLAG_GRP,
|
||||
* ALT_EXTERN_FLAG_GRP, and ALT_STATIC_FLAG_GRP. In these three cases the
|
||||
* semi-colon is included in the macro definition; so, for example, you should
|
||||
* use:
|
||||
*
|
||||
* ALT_FLAG_GRP(mygroup)
|
||||
*
|
||||
* not:
|
||||
*
|
||||
* ALT_FLAG_GRP(mygroup);
|
||||
*
|
||||
* The inclusion of the semi-colon has been necessary to ensure the macros can
|
||||
* compile with no warnings when used in a single threaded HAL environment.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "priv/alt_no_error.h"
|
||||
|
||||
#define ALT_FLAG_GRP(group)
|
||||
#define ALT_EXTERN_FLAG_GRP(group)
|
||||
#define ALT_STATIC_FLAG_GRP(group)
|
||||
|
||||
#define ALT_FLAG_CREATE(group, flags) alt_no_error ()
|
||||
#define ALT_FLAG_PEND(group, flags, wait_type, timeout) alt_no_error ()
|
||||
#define ALT_FLAG_POST(group, flags, opt) alt_no_error ()
|
||||
|
||||
#ifndef ALT_SINGLE_THREADED
|
||||
#define ALT_SINGLE_THREADED
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_FLAG_H__ */
|
|
@ -1,59 +0,0 @@
|
|||
#ifndef __ALT_HOOKS_H__
|
||||
#define __ALT_HOOKS_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* This header provides "do-nothing" macro definitions for operating system
|
||||
* hooks within the HAL. The O/S component can override these to provide it's
|
||||
* own implementation.
|
||||
*/
|
||||
|
||||
#define ALT_OS_TIME_TICK() while(0)
|
||||
#define ALT_OS_INIT() while(0)
|
||||
#define ALT_OS_STOP() while(0)
|
||||
|
||||
/* Call from assembly code */
|
||||
#define ALT_OS_INT_ENTER_ASM
|
||||
#define ALT_OS_INT_EXIT_ASM
|
||||
|
||||
/* Call from C code */
|
||||
#define ALT_OS_INT_ENTER() while(0)
|
||||
#define ALT_OS_INT_EXIT() while(0)
|
||||
|
||||
|
||||
#endif /* __ALT_HOOKS_H__ */
|
|
@ -1,94 +0,0 @@
|
|||
#ifndef __ALT_SEM_H__
|
||||
#define __ALT_SEM_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* This header provides macro definitions that can be used to create and use
|
||||
* semaphores. These macros can be used in both a uC/OS-II based environment,
|
||||
* and a single threaded HAL based environment.
|
||||
*
|
||||
* The motivation for these macros is to allow code to be developed which is
|
||||
* thread safe under uC/OS-II, but incurs no additional overhead when used in a
|
||||
* single threaded HAL environment.
|
||||
*
|
||||
* In the case of a single threaded HAL environment, they compile to
|
||||
* "do nothing" directives, which ensures they do not contribute to the final
|
||||
* executable.
|
||||
*
|
||||
* The following macros are available:
|
||||
*
|
||||
* ALT_SEM - Create a semaphore instance.
|
||||
* ALT_EXTERN_SEM - Create a reference to an external semaphore instance.
|
||||
* ALT_STATIC_SEM - Create a static semaphore instance.
|
||||
* ALT_SEM_CREATE - Initialise a semaphore.
|
||||
* ALT_SEM_PEND - Pend on a semaphore.
|
||||
* ALT_SEM_POST - Increment a semaphore.
|
||||
*
|
||||
* Input arguments and return codes are all consistant with the equivalent
|
||||
* uC/OS-II function.
|
||||
*
|
||||
* It's important to be careful in the use of the macros: ALT_SEM,
|
||||
* ALT_EXTERN_SEM, and ALT_STATIC_SEM. In these three cases the semi-colon is
|
||||
* included in the macro definition; so, for example, you should use:
|
||||
*
|
||||
* ALT_SEM(mysem)
|
||||
*
|
||||
* not:
|
||||
*
|
||||
* ALT_SEM(mysem);
|
||||
*
|
||||
* The inclusion of the semi-colon has been necessary to ensure the macros can
|
||||
* compile with no warnings when used in a single threaded HAL environment.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "priv/alt_no_error.h"
|
||||
|
||||
#define ALT_SEM(sem)
|
||||
#define ALT_EXTERN_SEM(sem)
|
||||
#define ALT_STATIC_SEM(sem)
|
||||
|
||||
#define ALT_SEM_CREATE(sem, value) alt_no_error ()
|
||||
#define ALT_SEM_PEND(sem, timeout) alt_no_error ()
|
||||
#define ALT_SEM_POST(sem) alt_no_error ()
|
||||
|
||||
#ifndef ALT_SINGLE_THREADED
|
||||
#define ALT_SINGLE_THREADED
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_SEM_H__ */
|
|
@ -1,73 +0,0 @@
|
|||
#ifndef __ALT_SYSCALL_H__
|
||||
#define __ALT_SYSCALL_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* The macros defined in this file are used to provide the function names used
|
||||
* for the HAL 'UNIX style' interface, e.g. read(), write() etc.
|
||||
*
|
||||
* Operating systems which are ported to the HAL can provide their own
|
||||
* version of this file, which will be used in preference. This allows
|
||||
* the operating system to provide it's own implementation of the top level
|
||||
* system calls, while retaining the HAL functions under a different name,
|
||||
* for example, alt_read(), alt_write() etc.
|
||||
*/
|
||||
|
||||
#define ALT_CLOSE close
|
||||
#define ALT_ENVIRON environ
|
||||
#define ALT_EXECVE execve
|
||||
#define ALT_EXIT _exit
|
||||
#define ALT_FCNTL fcntl
|
||||
#define ALT_FORK fork
|
||||
#define ALT_FSTAT fstat
|
||||
#define ALT_GETPID getpid
|
||||
#define ALT_GETTIMEOFDAY gettimeofday
|
||||
#define ALT_IOCTL ioctl
|
||||
#define ALT_ISATTY isatty
|
||||
#define ALT_KILL kill
|
||||
#define ALT_LINK link
|
||||
#define ALT_LSEEK lseek
|
||||
#define ALT_OPEN open
|
||||
#define ALT_READ read
|
||||
#define ALT_RENAME _rename
|
||||
#define ALT_SBRK sbrk
|
||||
#define ALT_SETTIMEOFDAY settimeofday
|
||||
#define ALT_STAT stat
|
||||
#define ALT_UNLINK unlink
|
||||
#define ALT_USLEEP usleep
|
||||
#define ALT_WAIT wait
|
||||
#define ALT_WRITE write
|
||||
#define ALT_TIMES times
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#endif /* __ALT_SYSCALL_H__ */
|
|
@ -1,99 +0,0 @@
|
|||
#ifndef __ALT_PRIV_ALARM_H__
|
||||
#define __ALT_PRIV_ALARM_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
/*
|
||||
* This header provides the internal defenitions required by the public
|
||||
* interface alt_alarm.h. These variables and structures are not guaranteed to
|
||||
* exist in future implementations of the HAL.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* "alt_alarm_s" is a structure type used to maintain lists of alarm callback
|
||||
* functions.
|
||||
*/
|
||||
|
||||
struct alt_alarm_s
|
||||
{
|
||||
alt_llist llist; /* linked list */
|
||||
alt_u32 time; /* time in system ticks of the callback */
|
||||
alt_u32 (*callback) (void* context); /* callback function. The return
|
||||
* value is the period for the next callback; where
|
||||
* zero indicates that the alarm should be removed
|
||||
* from the list.
|
||||
*/
|
||||
alt_u8 rollover; /* set when desired alarm time + current time causes
|
||||
overflow, to prevent premature alarm */
|
||||
void* context; /* Argument for the callback */
|
||||
};
|
||||
|
||||
/*
|
||||
* "_alt_tick_rate" is a global variable used to store the system clock rate
|
||||
* in ticks per second. This is initialised to zero, which coresponds to there
|
||||
* being no system clock available.
|
||||
*
|
||||
* It is then set to it's final value by the system clock driver through a call
|
||||
* to alt_sysclk_init().
|
||||
*/
|
||||
|
||||
extern alt_u32 _alt_tick_rate;
|
||||
|
||||
/*
|
||||
* "_alt_nticks" is a global variable which records the elapsed number of
|
||||
* system clock ticks since the last call to settimeofday() or since reset if
|
||||
* settimeofday() has not been called.
|
||||
*/
|
||||
|
||||
extern volatile alt_u32 _alt_nticks;
|
||||
|
||||
/* The list of registered alarms. */
|
||||
|
||||
extern alt_llist alt_alarm_list;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_PRIV_ALARM_H__ */
|
|
@ -1,75 +0,0 @@
|
|||
#ifndef __ALT_DEV_LLIST_H__
|
||||
#define __ALT_DEV_LLIST_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "sys/alt_llist.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
/*
|
||||
* This header provides the internal defenitions required to control file
|
||||
* access. These variables and functions are not guaranteed to exist in
|
||||
* future implementations of the HAL.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* The alt_dev_llist is an internal structure used to form a common base
|
||||
* class for all device types. The use of this structure allows common code
|
||||
* to be used to manipulate the various device lists.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
alt_llist llist;
|
||||
const char* name;
|
||||
} alt_dev_llist;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
extern int alt_dev_llist_insert (alt_dev_llist* dev, alt_llist* list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_DEV_LLIST_H__ */
|
|
@ -1,37 +0,0 @@
|
|||
#ifndef __ALT_EXCEPTION_HANDLER_REGISTRY_H__
|
||||
#define __ALT_EXCEPTION_HANDLER_REGISTRY_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
#include "sys/alt_exceptions.h"
|
||||
|
||||
/* Function pointer to exception callback routine */
|
||||
extern alt_exception_result (*alt_instruction_exception_handler)
|
||||
(alt_exception_cause, alt_u32, alt_u32);
|
||||
|
||||
#endif /* __ALT_EXCEPTION_HANDLER_REGISTRY_H__ */
|
|
@ -1,177 +0,0 @@
|
|||
#ifndef __ALT_FILE_H__
|
||||
#define __ALT_FILE_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "sys/alt_dev.h"
|
||||
#include "sys/alt_llist.h"
|
||||
#include "os/alt_sem.h"
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
/*
|
||||
* This header provides the internal defenitions required to control file
|
||||
* access. These variables and functions are not guaranteed to exist in
|
||||
* future implementations of the HAL.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* The function alt_find_dev() is used to search the device list "list" to
|
||||
* locate a device named "name". If a match is found, then a pointer to the
|
||||
* device is returned, otherwise NULL is returned.
|
||||
*/
|
||||
|
||||
extern alt_dev* alt_find_dev (const char* name, alt_llist* list);
|
||||
|
||||
/*
|
||||
* alt_find_file() is used to search the list of registered file systems to
|
||||
* find the filesystem that the file named "name" belongs to. If a match is
|
||||
* found, then a pointer to the filesystems alt_dev structure is returned,
|
||||
* otherwise NULL is returned.
|
||||
*
|
||||
* Note that a match does not indicate that the file exists, only that a
|
||||
* filesystem exists that is registered for a partition that could contain
|
||||
* the file. The filesystems open() function would need to be called in order
|
||||
* to determine if the file exists.
|
||||
*/
|
||||
|
||||
extern alt_dev* alt_find_file (const char* name);
|
||||
|
||||
/*
|
||||
* alt_get_fd() is used to allocate a file descriptor for the device or
|
||||
* filesystem "dev". A negative return value indicates an error, otherwise the
|
||||
* return value is the index of the file descriptor within the file descriptor
|
||||
* pool.
|
||||
*/
|
||||
|
||||
extern int alt_get_fd (alt_dev* dev);
|
||||
|
||||
/*
|
||||
* alt_release_fd() is called to free the file descriptor with index "fd".
|
||||
*/
|
||||
|
||||
extern void alt_release_fd (int fd);
|
||||
|
||||
/*
|
||||
* alt_fd_lock() is called by ioctl() to mark the file descriptor "fd" as
|
||||
* being open for exclusive access. Subsequent calls to open() for the device
|
||||
* associated with "fd" will fail. A device is unlocked by either calling
|
||||
* close() for "fd", or by an alternate call to ioctl() (see ioctl.c for
|
||||
* details).
|
||||
*/
|
||||
|
||||
extern int alt_fd_lock (alt_fd* fd);
|
||||
|
||||
/*
|
||||
* alt_fd_unlock() is called by ioctl() to unlock a descriptor previously
|
||||
* locked by a call to alt_fd_lock().
|
||||
*/
|
||||
|
||||
extern int alt_fd_unlock (alt_fd* fd);
|
||||
|
||||
/*
|
||||
* "alt_fd_list" is the pool of file descriptors.
|
||||
*/
|
||||
|
||||
extern alt_fd alt_fd_list[];
|
||||
|
||||
/*
|
||||
* flags used by alt_fd.
|
||||
*
|
||||
* ALT_FD_EXCL is used to mark a file descriptor as locked for exclusive
|
||||
* access, i.e. further calls to open() for the associated device should
|
||||
* fail.
|
||||
*
|
||||
* ALT_FD_DEV marks a dile descriptor as belonging to a device as oposed to a
|
||||
* filesystem.
|
||||
*/
|
||||
|
||||
#define ALT_FD_EXCL 0x80000000
|
||||
#define ALT_FD_DEV 0x40000000
|
||||
|
||||
#define ALT_FD_FLAGS_MASK (ALT_FD_EXCL | ALT_FD_DEV)
|
||||
|
||||
/*
|
||||
* "alt_dev_list" is the head of the linked list of registered devices.
|
||||
*/
|
||||
|
||||
extern alt_llist alt_dev_list;
|
||||
|
||||
/*
|
||||
* "alt_fs_list" is the head of the linked list of registered filesystems.
|
||||
*/
|
||||
|
||||
extern alt_llist alt_fs_list;
|
||||
|
||||
/*
|
||||
* "alt_fd_list_lock" is a semaphore used to ensure that access to the pool
|
||||
* of file descriptors is thread safe.
|
||||
*/
|
||||
|
||||
ALT_EXTERN_SEM(alt_fd_list_lock)
|
||||
|
||||
/*
|
||||
* "alt_max_fd" is a 'high water mark'. It indicates the highest file
|
||||
* descriptor allocated. Use of this can save searching the entire pool
|
||||
* for active file descriptors, which helps avoid contention on access
|
||||
* to the file descriptor pool.
|
||||
*/
|
||||
|
||||
extern alt_32 alt_max_fd;
|
||||
|
||||
/*
|
||||
* alt_io_redirect() is called at startup to redirect stdout, stdin, and
|
||||
* stderr to the devices named in the input arguments. By default these streams
|
||||
* are directed at /dev/null, and are then redirected using this function once
|
||||
* all of the devices have been registered within the system.
|
||||
*/
|
||||
|
||||
extern void alt_io_redirect(const char* stdout_dev,
|
||||
const char* stdin_dev,
|
||||
const char* stderr_dev);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_FILE_H__ */
|
|
@ -1,37 +0,0 @@
|
|||
#ifndef __ALT_IIC_ISR_REGISTER_H_
|
||||
#define __ALT_IIC_ISR_REGISTER_H_
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2009 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
#include "alt_types.h"
|
||||
#include "sys/alt_irq.h"
|
||||
|
||||
extern int alt_iic_isr_register(alt_u32 ic_id, alt_u32 irq, alt_isr_func isr,
|
||||
void *isr_context, void *flags);
|
||||
|
||||
#endif /* __ALT_IIC_ISR_REGISTER_H_ */
|
|
@ -1,57 +0,0 @@
|
|||
#ifndef __ALT_IRQ_TABLE_H__
|
||||
#define __ALT_IRQ_TABLE_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2009 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* Definition of a table describing each interrupt handler. The index into
|
||||
* the array is the interrupt id associated with the handler.
|
||||
*
|
||||
* When an interrupt occurs, the associated handler is called with
|
||||
* the argument stored in the context member.
|
||||
*
|
||||
* The table is physically created in alt_irq_handler.c
|
||||
*/
|
||||
extern struct ALT_IRQ_HANDLER
|
||||
{
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
void (*handler)(void*);
|
||||
#else
|
||||
void (*handler)(void*, alt_u32);
|
||||
#endif
|
||||
void *context;
|
||||
} alt_irq[ALT_NIRQ];
|
||||
|
||||
#endif
|
|
@ -1,75 +0,0 @@
|
|||
#ifndef __ALT_NO_ERROR_H__
|
||||
#define __ALT_NO_ERROR_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* alt_no_error() is a dummy function used by alt_sem.h and alt_flag.h. It
|
||||
* substitutes for functions that have a return code by creating a function
|
||||
* that always returns zero.
|
||||
*
|
||||
* This may seem a little obscure, but what happens is that the compiler can
|
||||
* then optomise away the call to this function, and any code written which
|
||||
* handles the error path (i.e. non zero return values).
|
||||
*
|
||||
* This allows code to be written which correctly use the uC/OS-II semaphore
|
||||
* and flag utilities, without the use of those utilities impacting on
|
||||
* excutables built for a single threaded HAL environment.
|
||||
*
|
||||
* This function is considered to be part of the internal implementation of
|
||||
* the HAL, and should not be called directly by application code or device
|
||||
* drivers. It is not guaranteed to be preserved in future versions of the
|
||||
* HAL.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int ALT_ALWAYS_INLINE alt_no_error (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_NO_ERROR_H__ */
|
|
@ -1,161 +0,0 @@
|
|||
#ifndef __ALT_ALARM_H__
|
||||
#define __ALT_ALARM_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_llist.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
#include "priv/alt_alarm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* "alt_alarm" is a structure type used by applications to register an alarm
|
||||
* callback function. An instance of this type must be passed as an input
|
||||
* argument to alt_alarm_start(). The user is not responsible for initialising
|
||||
* the contents of the instance. This is done by alt_alarm_start().
|
||||
*/
|
||||
|
||||
typedef struct alt_alarm_s alt_alarm;
|
||||
|
||||
/*
|
||||
* alt_alarm_start() can be called by an application/driver in order to register
|
||||
* a function for periodic callback at the system clock frequency. Be aware that
|
||||
* this callback is likely to occur in interrupt context.
|
||||
*/
|
||||
|
||||
extern int alt_alarm_start (alt_alarm* the_alarm,
|
||||
alt_u32 nticks,
|
||||
alt_u32 (*callback) (void* context),
|
||||
void* context);
|
||||
|
||||
/*
|
||||
* alt_alarm_stop() is used to unregister a callback. Alternatively the callback
|
||||
* can return zero to unregister.
|
||||
*/
|
||||
|
||||
extern void alt_alarm_stop (alt_alarm* the_alarm);
|
||||
|
||||
#ifndef ZEPHYR_RTOS
|
||||
/*
|
||||
* Obtain the system clock rate in ticks/s.
|
||||
*/
|
||||
|
||||
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_ticks_per_second (void)
|
||||
{
|
||||
return _alt_tick_rate;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_sysclk_init() is intended to be only used by the system clock driver
|
||||
* in order to initialise the value of the clock frequency.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int ALT_ALWAYS_INLINE alt_sysclk_init (alt_u32 nticks)
|
||||
{
|
||||
if (! _alt_tick_rate)
|
||||
{
|
||||
_alt_tick_rate = nticks;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_nticks() returns the elapsed number of system clock ticks since reset.
|
||||
*/
|
||||
|
||||
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_nticks (void)
|
||||
{
|
||||
return _alt_nticks;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_tick() should only be called by the system clock driver. This is used
|
||||
* to notify the system that the system timer period has expired.
|
||||
*/
|
||||
|
||||
extern void alt_tick (void);
|
||||
#else
|
||||
/*
|
||||
* Obtain the system clock rate in ticks/s.
|
||||
*/
|
||||
|
||||
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_ticks_per_second (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_sysclk_init() is intended to be only used by the system clock driver
|
||||
* in order to initialise the value of the clock frequency.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int ALT_ALWAYS_INLINE alt_sysclk_init (alt_u32 nticks)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_nticks() returns the elapsed number of system clock ticks since reset.
|
||||
*/
|
||||
|
||||
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_nticks (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_tick() should only be called by the system clock driver. This is used
|
||||
* to notify the system that the system timer period has expired.
|
||||
*/
|
||||
|
||||
extern void alt_tick (void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_ALARM_H__ */
|
|
@ -1,115 +0,0 @@
|
|||
#ifndef __ALT_CACHE_H__
|
||||
#define __ALT_CACHE_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003, 2007 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
/*
|
||||
* alt_cache.h defines the processor specific functions for manipulating the
|
||||
* cache.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* alt_icache_flush() is called to flush the instruction cache for a memory
|
||||
* region of length "len" bytes, starting at address "start".
|
||||
*/
|
||||
|
||||
extern void alt_icache_flush (void* start, alt_u32 len);
|
||||
|
||||
/*
|
||||
* alt_dcache_flush() is called to flush the data cache for a memory
|
||||
* region of length "len" bytes, starting at address "start".
|
||||
* Any dirty lines in the data cache are written back to memory.
|
||||
*/
|
||||
|
||||
extern void alt_dcache_flush (void* start, alt_u32 len);
|
||||
|
||||
/*
|
||||
* alt_dcache_flush() is called to flush the data cache for a memory
|
||||
* region of length "len" bytes, starting at address "start".
|
||||
* Any dirty lines in the data cache are NOT written back to memory.
|
||||
*/
|
||||
|
||||
extern void alt_dcache_flush_no_writeback (void* start, alt_u32 len);
|
||||
|
||||
/*
|
||||
* Flush the entire instruction cache.
|
||||
*/
|
||||
|
||||
extern void alt_icache_flush_all (void);
|
||||
|
||||
/*
|
||||
* Flush the entire data cache.
|
||||
*/
|
||||
|
||||
extern void alt_dcache_flush_all (void);
|
||||
|
||||
/*
|
||||
* Allocate a block of uncached memory.
|
||||
*/
|
||||
|
||||
extern volatile void* alt_uncached_malloc (size_t size);
|
||||
|
||||
/*
|
||||
* Free a block of uncached memory.
|
||||
*/
|
||||
|
||||
extern void alt_uncached_free (volatile void* ptr);
|
||||
|
||||
/*
|
||||
* Convert a pointer to a block of cached memory, into a block of
|
||||
* uncached memory.
|
||||
*/
|
||||
|
||||
extern volatile void* alt_remap_uncached (void* ptr, alt_u32 len);
|
||||
|
||||
/*
|
||||
* Convert a pointer to a block of uncached memory, into a block of
|
||||
* cached memory.
|
||||
*/
|
||||
|
||||
extern void* alt_remap_cached (volatile void* ptr, alt_u32 len);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_CACHE_H__ */
|
|
@ -1,113 +0,0 @@
|
|||
#ifndef __ALT_DEV_H__
|
||||
#define __ALT_DEV_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "system.h"
|
||||
#include "sys/alt_llist.h"
|
||||
#include "priv/alt_dev_llist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* The value ALT_IRQ_NOT_CONNECTED is used to represent an unconnected
|
||||
* interrupt line. It cannot evaluate to a valid interrupt number.
|
||||
*/
|
||||
|
||||
#define ALT_IRQ_NOT_CONNECTED (-1)
|
||||
|
||||
typedef struct alt_dev_s alt_dev;
|
||||
|
||||
struct stat;
|
||||
|
||||
/*
|
||||
* The file descriptor structure definition.
|
||||
*/
|
||||
|
||||
typedef struct alt_fd_s
|
||||
{
|
||||
alt_dev* dev;
|
||||
alt_u8* priv;
|
||||
int fd_flags;
|
||||
} alt_fd;
|
||||
|
||||
/*
|
||||
* The device structure definition.
|
||||
*/
|
||||
|
||||
struct alt_dev_s {
|
||||
alt_llist llist; /* for internal use */
|
||||
const char* name;
|
||||
int (*open) (alt_fd* fd, const char* name, int flags, int mode);
|
||||
int (*close) (alt_fd* fd);
|
||||
int (*read) (alt_fd* fd, char* ptr, int len);
|
||||
int (*write) (alt_fd* fd, const char* ptr, int len);
|
||||
int (*lseek) (alt_fd* fd, int ptr, int dir);
|
||||
int (*fstat) (alt_fd* fd, struct stat* buf);
|
||||
int (*ioctl) (alt_fd* fd, int req, void* arg);
|
||||
};
|
||||
|
||||
/*
|
||||
* Functions used to register device for access through the C standard
|
||||
* library.
|
||||
*
|
||||
* The only difference between alt_dev_reg() and alt_fs_reg() is the
|
||||
* interpretation that open() places on the device name. In the case of
|
||||
* alt_dev_reg the device is assumed to be a particular character device,
|
||||
* and so there must be an exact match in the name for open to succeed.
|
||||
* In the case of alt_fs_reg() the name of the device is treated as the
|
||||
* mount point for a directory, and so any call to open() where the name
|
||||
* is the root of the device filename will succeed.
|
||||
*/
|
||||
|
||||
extern int alt_fs_reg (alt_dev* dev);
|
||||
|
||||
static ALT_INLINE int alt_dev_reg (alt_dev* dev)
|
||||
{
|
||||
extern alt_llist alt_dev_list;
|
||||
|
||||
return alt_dev_llist_insert ((alt_dev_llist*) dev, &alt_dev_list);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_DEV_H__ */
|
|
@ -1,224 +0,0 @@
|
|||
#ifndef __ALT_DMA_H__
|
||||
#define __ALT_DMA_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004-2005 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "sys/alt_dma_dev.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* This header contains the application side interface for accessing DMA
|
||||
* resources. See alt_dma_dev.h for the dma device driver interface.
|
||||
*
|
||||
* The interface model treats a DMA transaction as being composed of two
|
||||
* halves (read and write).
|
||||
*
|
||||
* The application can supply data for transmit using an "alt_dma_txchan"
|
||||
* descriptor. Alternatively an "alt_dma_rxchan" descriptor can be used to
|
||||
* receive data.
|
||||
*/
|
||||
|
||||
/*
|
||||
* alt_dma_txchan_open() is used to obtain an "alt_dma_txchan" descriptor for
|
||||
* a DMA transmit device. The name is the name of the associated physical
|
||||
* device (e.g. "/dev/dma_0").
|
||||
*
|
||||
* The return value will be NULL on failure, and non-NULL otherwise.
|
||||
*/
|
||||
|
||||
extern alt_dma_txchan alt_dma_txchan_open (const char* name);
|
||||
|
||||
/*
|
||||
* alt_dma_txchan_close() is provided so that an application can notify the
|
||||
* system that it has finished with a given DMA transmit channel. This is only
|
||||
* provided for completness.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_txchan_close (alt_dma_txchan dma)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_dma_txchan_send() posts a transmit request to a DMA transmit channel.
|
||||
* The input arguments are:
|
||||
*
|
||||
* dma: the channel to use.
|
||||
* from: a pointer to the start of the data to send.
|
||||
* length: the length of the data to send in bytes.
|
||||
* done: callback function that will be called once the data has been sent.
|
||||
* handle: opaque value passed to "done".
|
||||
*
|
||||
* The return value will be negative if the request cannot be posted, and
|
||||
* zero otherwise.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_txchan_send (alt_dma_txchan dma,
|
||||
const void* from,
|
||||
alt_u32 length,
|
||||
alt_txchan_done* done,
|
||||
void* handle)
|
||||
{
|
||||
return dma ? dma->dma_send (dma,
|
||||
from,
|
||||
length,
|
||||
done,
|
||||
handle) : -ENODEV;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_dma_txchan_space() returns the number of tranmit requests that can be
|
||||
* posted to the specified DMA transmit channel.
|
||||
*
|
||||
* A negative value indicates that the value could not be determined.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_txchan_space (alt_dma_txchan dma)
|
||||
{
|
||||
return dma ? dma->space (dma) : -ENODEV;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_dma_txchan_ioctl() can be used to perform device specific I/O
|
||||
* operations on the indicated DMA transmit channel. For example some drivers
|
||||
* support options to control the width of the transfer operations. See
|
||||
* alt_dma_dev.h for the list of generic requests.
|
||||
*
|
||||
* A negative return value indicates failure, otherwise the interpretation
|
||||
* of the return value is request specific.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_txchan_ioctl (alt_dma_txchan dma,
|
||||
int req,
|
||||
void* arg)
|
||||
{
|
||||
return dma ? dma->ioctl (dma, req, arg) : -ENODEV;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_dma_rxchan_open() is used to obtain an "alt_dma_rxchan" descriptor for
|
||||
* a DMA receive channel. The name is the name of the associated physical
|
||||
* device (e.g. "/dev/dma_0").
|
||||
*
|
||||
* The return value will be NULL on failure, and non-NULL otherwise.
|
||||
*/
|
||||
|
||||
extern alt_dma_rxchan alt_dma_rxchan_open (const char* dev);
|
||||
|
||||
/*
|
||||
* alt_dma_rxchan_close() is provided so that an application can notify the
|
||||
* system that it has finished with a given DMA receive channel. This is only
|
||||
* provided for completness.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_rxchan_close (alt_dma_rxchan dma)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* alt_dma_rxchan_prepare() posts a receive request to a DMA receive channel.
|
||||
*
|
||||
* The input arguments are:
|
||||
*
|
||||
* dma: the channel to use.
|
||||
* data: a pointer to the location that data is to be received to.
|
||||
* len: the maximum length of the data to receive.
|
||||
* done: callback function that will be called once the data has been
|
||||
* received.
|
||||
* handle: opaque value passed to "done".
|
||||
*
|
||||
* The return value will be negative if the request cannot be posted, and
|
||||
* zero otherwise.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_rxchan_prepare (alt_dma_rxchan dma,
|
||||
void* data,
|
||||
alt_u32 len,
|
||||
alt_rxchan_done* done,
|
||||
void* handle)
|
||||
{
|
||||
return dma ? dma->prepare (dma, data, len, done, handle) : -ENODEV;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_dma_rxchan_ioctl() can be used to perform device specific I/O
|
||||
* operations on the indicated DMA receive channel. For example some drivers
|
||||
* support options to control the width of the transfer operations. See
|
||||
* alt_dma_dev.h for the list of generic requests.
|
||||
*
|
||||
* A negative return value indicates failure, otherwise the interpretation
|
||||
* of the return value is request specific.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_rxchan_ioctl (alt_dma_rxchan dma,
|
||||
int req,
|
||||
void* arg)
|
||||
{
|
||||
return dma ? dma->ioctl (dma, req, arg) : -ENODEV;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_dma_rxchan_depth() returns the depth of the receive FIFO used to store
|
||||
* receive requests.
|
||||
*/
|
||||
|
||||
static ALT_INLINE alt_u32 alt_dma_rxchan_depth(alt_dma_rxchan dma)
|
||||
{
|
||||
return dma->depth;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_DMA_H__ */
|
|
@ -1,198 +0,0 @@
|
|||
#ifndef __ALT_DMA_DEV_H__
|
||||
#define __ALT_DMA_DEV_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004-2005 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "priv/alt_dev_llist.h"
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* This header contains the device driver interface for accessing DMA
|
||||
* resources. See alt_dma.h for the DMA application side interface.
|
||||
*
|
||||
* The interface model treats a DMA transaction as being composed of two
|
||||
* halves (read and write).
|
||||
*
|
||||
* An "alt_dma_txchan_dev" is used to describe the device associated with a
|
||||
* DMA transmit channel. An "alt_dma_rxchan_dev" is used to describe the
|
||||
* device associated with a DMA receive channel.
|
||||
*/
|
||||
|
||||
/*
|
||||
* List of generic ioctl requests that may be supported by a DMA device.
|
||||
*
|
||||
* ALT_DMA_RX_ONLY_ON: This causes a DMA channel to operate in a mode
|
||||
* where only the receiver is under software control.
|
||||
* The other side reads continously from a single
|
||||
* location. The address to read is the argument to
|
||||
* this request.
|
||||
* ALT_DMA_RX_ONLY_OFF: Return to the default mode where both the receive
|
||||
* and transmit sides of the DMA can be under software
|
||||
* control.
|
||||
* ALT_DMA_TX_ONLY_ON: This causes a DMA channel to operate in a mode
|
||||
* where only the transmitter is under software control.
|
||||
* The other side writes continously to a single
|
||||
* location. The address to write to is the argument to
|
||||
* this request.
|
||||
* ALT_DMA_TX_ONLY_OFF: Return to the default mode where both the receive
|
||||
* and transmit sides of the DMA can be under software
|
||||
* control.
|
||||
* ALT_DMA_SET_MODE_8: Transfer data in units of 8 bits.
|
||||
* ALT_DMA_SET_MODE_16: Transfer data in units of 16 bits.
|
||||
* ALT_DMA_SET_MODE_32: Transfer data in units of 32 bits.
|
||||
* ALT_DMA_SET_MODE_64: Transfer data in units of 64 bits.
|
||||
* ALT_DMA_SET_MODE_128: Transfer data in units of 128 bits.
|
||||
* ALT_DMA_GET_MODE: Get the current transfer mode.
|
||||
*
|
||||
* The use of the macros: ALT_DMA_TX_STREAM_ON, ALT_DMA_TX_STREAM_OFF
|
||||
* ALT_DMA_RX_STREAM_OFF and ALT_DMA_RX_STREAM_ON are depreciated. You should
|
||||
* instead use the macros: ALT_DMA_RX_ONLY_ON, ALT_DMA_RX_ONLY_OFF,
|
||||
* ALT_DMA_TX_ONLY_ON and ALT_DMA_TX_ONLY_OFF.
|
||||
*/
|
||||
|
||||
#define ALT_DMA_TX_STREAM_ON (0x1)
|
||||
#define ALT_DMA_TX_STREAM_OFF (0x2)
|
||||
#define ALT_DMA_RX_STREAM_ON (0x3)
|
||||
#define ALT_DMA_RX_STREAM_OFF (0x4)
|
||||
#define ALT_DMA_SET_MODE_8 (0x5)
|
||||
#define ALT_DMA_SET_MODE_16 (0x6)
|
||||
#define ALT_DMA_SET_MODE_32 (0x7)
|
||||
#define ALT_DMA_SET_MODE_64 (0x8)
|
||||
#define ALT_DMA_SET_MODE_128 (0x9)
|
||||
#define ALT_DMA_GET_MODE (0xa)
|
||||
|
||||
#define ALT_DMA_RX_ONLY_ON ALT_DMA_TX_STREAM_ON
|
||||
#define ALT_DMA_RX_ONLY_OFF ALT_DMA_TX_STREAM_OFF
|
||||
#define ALT_DMA_TX_ONLY_ON ALT_DMA_RX_STREAM_ON
|
||||
#define ALT_DMA_TX_ONLY_OFF ALT_DMA_RX_STREAM_OFF
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct alt_dma_txchan_dev_s alt_dma_txchan_dev;
|
||||
typedef struct alt_dma_rxchan_dev_s alt_dma_rxchan_dev;
|
||||
|
||||
typedef alt_dma_txchan_dev* alt_dma_txchan;
|
||||
typedef alt_dma_rxchan_dev* alt_dma_rxchan;
|
||||
|
||||
typedef void (alt_txchan_done)(void* handle);
|
||||
typedef void (alt_rxchan_done)(void* handle, void* data);
|
||||
|
||||
/*
|
||||
* devices that provide a DMA transmit channel are required to provide an
|
||||
* instance of the "alt_dma_txchan_dev" structure.
|
||||
*/
|
||||
|
||||
struct alt_dma_txchan_dev_s {
|
||||
alt_llist llist; /* for internal use */
|
||||
const char* name; /* name of the device instance
|
||||
* (e.g. "/dev/dma_0").
|
||||
*/
|
||||
int (*space) (alt_dma_txchan dma); /* returns the maximum number of
|
||||
* transmit requests that can be posted
|
||||
*/
|
||||
int (*dma_send) (alt_dma_txchan dma,
|
||||
const void* from,
|
||||
alt_u32 len,
|
||||
alt_txchan_done* done,
|
||||
void* handle); /* post a transmit request */
|
||||
int (*ioctl) (alt_dma_txchan dma, int req, void* arg); /* perform device
|
||||
* specific I/O control.
|
||||
*/
|
||||
};
|
||||
|
||||
/*
|
||||
* devices that provide a DMA receive channel are required to provide an
|
||||
* instance of the "alt_dma_rxchan_dev" structure.
|
||||
*/
|
||||
|
||||
struct alt_dma_rxchan_dev_s {
|
||||
alt_llist list; /* for internal use */
|
||||
const char* name; /* name of the device instance
|
||||
* (e.g. "/dev/dma_0").
|
||||
*/
|
||||
alt_u32 depth; /* maximum number of receive requests that
|
||||
* can be posted.
|
||||
*/
|
||||
int (*prepare) (alt_dma_rxchan dma,
|
||||
void* data,
|
||||
alt_u32 len,
|
||||
alt_rxchan_done* done,
|
||||
void* handle); /* post a receive request */
|
||||
int (*ioctl) (alt_dma_rxchan dma, int req, void* arg); /* perform device
|
||||
* specific I/O control.
|
||||
*/
|
||||
};
|
||||
|
||||
/*
|
||||
* Register a DMA transmit channel with the system.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_txchan_reg (alt_dma_txchan_dev* dev)
|
||||
{
|
||||
extern alt_llist alt_dma_txchan_list;
|
||||
|
||||
return alt_dev_llist_insert((alt_dev_llist*) dev, &alt_dma_txchan_list);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register a DMA receive channel with the system.
|
||||
*/
|
||||
|
||||
static ALT_INLINE int alt_dma_rxchan_reg (alt_dma_rxchan_dev* dev)
|
||||
{
|
||||
extern alt_llist alt_dma_rxchan_list;
|
||||
|
||||
return alt_dev_llist_insert((alt_dev_llist*) dev, &alt_dma_rxchan_list);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_DMA_DEV_H__ */
|
|
@ -1,166 +0,0 @@
|
|||
#ifndef __ALT_DRIVER_H__
|
||||
#define __ALT_DRIVER_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* Macros used to access a driver without HAL file descriptors.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ALT_MODULE_CLASS
|
||||
*
|
||||
* This macro returns the module class name for the specified module instance.
|
||||
* It uses information in the system.h file.
|
||||
* Neither the instance name or class name are quoted (so that they can
|
||||
* be used with other pre-processor macros).
|
||||
*
|
||||
* Example:
|
||||
* Assume the design has an instance of an altera_avalon_uart called uart1.
|
||||
* Calling ALT_MODULE_CLASS(uart1) returns altera_avalon_uart.
|
||||
*/
|
||||
|
||||
#define ALT_MODULE_CLASS(instance) ALT_MODULE_CLASS_ ## instance
|
||||
|
||||
|
||||
/*
|
||||
* ALT_DRIVER_FUNC_NAME
|
||||
*
|
||||
* --> instance Instance name.
|
||||
* --> func Function name.
|
||||
*
|
||||
* This macro returns the device driver function name of the specified
|
||||
* module instance for the specified function name.
|
||||
*
|
||||
* Example:
|
||||
* Assume the design has an instance of an altera_avalon_uart called uart1.
|
||||
* Calling ALT_DRIVER_FUNC_NAME(uart1, write) returns
|
||||
* altera_avalon_uart_write.
|
||||
*/
|
||||
|
||||
#define ALT_DRIVER_FUNC_NAME(instance, func) \
|
||||
ALT_DRIVER_FUNC_NAME1(ALT_MODULE_CLASS(instance), func)
|
||||
#define ALT_DRIVER_FUNC_NAME1(module_class, func) \
|
||||
ALT_DRIVER_FUNC_NAME2(module_class, func)
|
||||
#define ALT_DRIVER_FUNC_NAME2(module_class, func) \
|
||||
module_class ## _ ## func
|
||||
|
||||
/*
|
||||
* ALT_DRIVER_STATE_STRUCT
|
||||
*
|
||||
* --> instance Instance name.
|
||||
*
|
||||
* This macro returns the device driver state type name of the specified
|
||||
* module instance.
|
||||
*
|
||||
* Example:
|
||||
* Assume the design has an instance of an altera_avalon_uart called uart1.
|
||||
* Calling ALT_DRIVER_STATE_STRUCT(uart1) returns:
|
||||
* struct altera_avalon_uart_state_s
|
||||
*
|
||||
* Note that the ALT_DRIVER_FUNC_NAME macro is used even though "state" isn't
|
||||
* really a function but it does match the required naming convention.
|
||||
*/
|
||||
#define ALT_DRIVER_STATE_STRUCT(instance) \
|
||||
struct ALT_DRIVER_FUNC_NAME(instance, state_s)
|
||||
|
||||
/*
|
||||
* ALT_DRIVER_STATE
|
||||
*
|
||||
* --> instance Instance name.
|
||||
*
|
||||
* This macro returns the device driver state name of the specified
|
||||
* module instance.
|
||||
*
|
||||
* Example:
|
||||
* Assume the design has an instance of an altera_avalon_uart called uart1.
|
||||
* Calling ALT_DRIVER_STATE(uart1) returns uart1.
|
||||
*/
|
||||
#define ALT_DRIVER_STATE(instance) instance
|
||||
|
||||
/*
|
||||
* ALT_DRIVER_WRITE
|
||||
*
|
||||
* --> instance Instance name.
|
||||
* --> buffer Write buffer.
|
||||
* --> len Length of write buffer data.
|
||||
* --> flags Control flags (e.g. O_NONBLOCK)
|
||||
*
|
||||
* This macro calls the "write" function of the specified driver instance.
|
||||
*/
|
||||
|
||||
#define ALT_DRIVER_WRITE_EXTERNS(instance) \
|
||||
extern ALT_DRIVER_STATE_STRUCT(instance) ALT_DRIVER_STATE(instance); \
|
||||
extern int ALT_DRIVER_FUNC_NAME(instance, write) \
|
||||
(ALT_DRIVER_STATE_STRUCT(instance) *, const char *, int, int);
|
||||
|
||||
#define ALT_DRIVER_WRITE(instance, buffer, len, flags) \
|
||||
ALT_DRIVER_FUNC_NAME(instance, write)(&ALT_DRIVER_STATE(instance), buffer, len, flags)
|
||||
|
||||
|
||||
/*
|
||||
* ALT_DRIVER_READ
|
||||
*
|
||||
* --> instance Instance name.
|
||||
* <-- buffer Read buffer.
|
||||
* --> len Length of read buffer.
|
||||
* --> flags Control flags (e.g. O_NONBLOCK)
|
||||
*
|
||||
* This macro calls the "read" function of the specified driver instance.
|
||||
*/
|
||||
|
||||
#define ALT_DRIVER_READ_EXTERNS(instance) \
|
||||
extern ALT_DRIVER_STATE_STRUCT(instance) ALT_DRIVER_STATE(instance); \
|
||||
extern int ALT_DRIVER_FUNC_NAME(instance, read) \
|
||||
(ALT_DRIVER_STATE_STRUCT(instance) *, const char *, int, int);
|
||||
|
||||
#define ALT_DRIVER_READ(instance, buffer, len, flags) \
|
||||
ALT_DRIVER_FUNC_NAME(instance, read)(&ALT_DRIVER_STATE(instance), buffer, len, flags)
|
||||
|
||||
/*
|
||||
* ALT_DRIVER_IOCTL
|
||||
*
|
||||
* --> instance Instance name.
|
||||
* --> req ioctl request (e.g. TIOCSTIMEOUT)
|
||||
* --> arg Optional argument (void*)
|
||||
*
|
||||
* This macro calls the "ioctl" function of the specified driver instance
|
||||
*/
|
||||
|
||||
#define ALT_DRIVER_IOCTL_EXTERNS(instance) \
|
||||
extern ALT_DRIVER_STATE_STRUCT(instance) ALT_DRIVER_STATE(instance); \
|
||||
extern int ALT_DRIVER_FUNC_NAME(instance, ioctl) \
|
||||
(ALT_DRIVER_STATE_STRUCT(instance) *, int, void*);
|
||||
|
||||
#define ALT_DRIVER_IOCTL(instance, req, arg) \
|
||||
ALT_DRIVER_FUNC_NAME(instance, ioctl)(&ALT_DRIVER_STATE(instance), req, arg)
|
||||
|
||||
#endif /* __ALT_DRIVER_H__ */
|
|
@ -1,87 +0,0 @@
|
|||
#ifndef __ALT_ERRNO_H__
|
||||
#define __ALT_ERRNO_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* errno is defined in <errno.h> so that it uses the thread local version
|
||||
* stored in the location pointed to by "_impure_ptr". This means that the
|
||||
* accesses to errno within the HAL library can cause the entirety of
|
||||
* of the structure pointed to by "_impure_ptr" to be added to the
|
||||
* users application. This can be undesirable in very small footprint systems.
|
||||
*
|
||||
* To avoid this happening, the HAL uses the macro ALT_ERRNO, defined below,
|
||||
* to access errno, rather than accessing it directly. This macro will only
|
||||
* use the thread local version if some other code has already caused it to be
|
||||
* included into the system, otherwise it will use the global errno value.
|
||||
*
|
||||
* This causes a slight increases in code size where errno is accessed, but
|
||||
* can lead to significant overall benefits in very small systems. The
|
||||
* increase is inconsequential when compared to the size of the structure
|
||||
* pointed to by _impure_ptr.
|
||||
*
|
||||
* Note that this macro accesses __errno() using an externally declared
|
||||
* function pointer (alt_errno). This is done so that the function call uses the
|
||||
* subroutine call instruction via a register rather than an immediate address.
|
||||
* This is important in the case that the code has been linked for a high
|
||||
* address, but __errno() is not being used. In this case the weak linkage
|
||||
* would have resulted in the instruction: "call 0" which would fail to link.
|
||||
*/
|
||||
|
||||
extern int* (*alt_errno) (void);
|
||||
|
||||
/* Must define this so that values such as EBADFD are defined in errno.h. */
|
||||
#ifndef __LINUX_ERRNO_EXTENSIONS__
|
||||
#define __LINUX_ERRNO_EXTENSIONS__
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
#undef errno
|
||||
|
||||
extern int errno;
|
||||
|
||||
static ALT_INLINE int* alt_get_errno(void)
|
||||
{
|
||||
return ((alt_errno) ? alt_errno() : &errno);
|
||||
}
|
||||
|
||||
#define ALT_ERRNO *alt_get_errno()
|
||||
|
||||
#endif /* __ALT_ERRNO_H__ */
|
|
@ -1,179 +0,0 @@
|
|||
#ifndef __ALT_FLASH_H__
|
||||
#define __ALT_FLASH_H__
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2015 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* Alt_flash.h - User interface for flash code *
|
||||
* *
|
||||
* Use this interface to avoid being exposed to the internals of the device *
|
||||
* driver architecture. If you chose to use the flash driver internal *
|
||||
* structures we don't guarantee not to change them *
|
||||
* *
|
||||
* Author PRR *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "alt_flash_types.h"
|
||||
#include "alt_flash_dev.h"
|
||||
#include "sys/alt_cache.h"
|
||||
|
||||
alt_flash_fd* alt_flash_open_dev(const char* name);
|
||||
void alt_flash_close_dev(alt_flash_fd* fd );
|
||||
|
||||
/*
|
||||
* alt_flash_lock
|
||||
*
|
||||
* Locks the range of the memory sectors, which
|
||||
* protected from write and erase.
|
||||
*
|
||||
*/
|
||||
static __inline__ int __attribute__ ((always_inline)) alt_lock_flash(
|
||||
alt_flash_fd* fd, alt_u32 sectors_to_lock)
|
||||
{
|
||||
return fd->lock( fd, sectors_to_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_write_flash
|
||||
*
|
||||
* Program a buffer into flash.
|
||||
*
|
||||
* This routine erases all the affected erase blocks (if necessary)
|
||||
* and then programs the data. However it does not read the data out first
|
||||
* and preserve and none overwritten data, because this would require very
|
||||
* large buffers on the target. If you need
|
||||
* that functionality use the functions below.
|
||||
*/
|
||||
static __inline__ int __attribute__ ((always_inline)) alt_write_flash(
|
||||
alt_flash_fd* fd,
|
||||
int offset,
|
||||
const void* src_addr,
|
||||
int length )
|
||||
{
|
||||
return fd->write( fd, offset, src_addr, length );
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_read_flash
|
||||
*
|
||||
* Read a block of flash for most flashes this is just memcpy
|
||||
* it's here for completeness in case we need it for some serial flash device
|
||||
*
|
||||
*/
|
||||
static __inline__ int __attribute__ ((always_inline)) alt_read_flash(
|
||||
alt_flash_fd* fd, int offset,
|
||||
void* dest_addr, int length )
|
||||
{
|
||||
return fd->read( fd, offset, dest_addr, length );
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_get_flash_info
|
||||
*
|
||||
* Return the information on the flash sectors.
|
||||
*
|
||||
*/
|
||||
static __inline__ int __attribute__ ((always_inline)) alt_get_flash_info(
|
||||
alt_flash_fd* fd, flash_region** info,
|
||||
int* number_of_regions)
|
||||
{
|
||||
return fd->get_info( fd, info, number_of_regions);
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_erase_flash_block
|
||||
*
|
||||
* Erase a particular erase block, pass in the offset to the start of
|
||||
* the block and it's size
|
||||
*/
|
||||
static __inline__ int __attribute__ ((always_inline)) alt_erase_flash_block(
|
||||
alt_flash_fd* fd, int offset, int length)
|
||||
{
|
||||
int ret_code;
|
||||
ret_code = fd->erase_block( fd, offset );
|
||||
|
||||
/* remove dcache_flush call for FB330552
|
||||
if(!ret_code)
|
||||
alt_dcache_flush((alt_u8*)fd->base_addr + offset, length);
|
||||
*/
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_write_flash_block
|
||||
*
|
||||
* Write a particular flash block, block_offset is the offset
|
||||
* (from the base of flash) to start of the block
|
||||
* data_offset is the offset (from the base of flash)
|
||||
* where you wish to start programming
|
||||
*
|
||||
* NB this function DOES NOT check that you are only writing a single
|
||||
* block of data as that would slow down this function.
|
||||
*
|
||||
* Use alt_write_flash if you want that level of error checking.
|
||||
*/
|
||||
|
||||
static __inline__ int __attribute__ ((always_inline)) alt_write_flash_block(
|
||||
alt_flash_fd* fd, int block_offset,
|
||||
int data_offset,
|
||||
const void *data, int length)
|
||||
{
|
||||
|
||||
int ret_code;
|
||||
ret_code = fd->write_block( fd, block_offset, data_offset, data, length );
|
||||
|
||||
/* remove dcache_flush call for FB330552
|
||||
if(!ret_code)
|
||||
alt_dcache_flush((alt_u8*)fd->base_addr + data_offset, length);
|
||||
*/
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_FLASH_H__ */
|
|
@ -1,98 +0,0 @@
|
|||
#ifndef __ALT_FLASH_DEV_H__
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2015 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* Alt_flash_dev.h - Generic Flash device interfaces *
|
||||
* *
|
||||
* Author PRR *
|
||||
* *
|
||||
******************************************************************************/
|
||||
#define __ALT_FLASH_DEV_H__
|
||||
|
||||
#include "alt_flash_types.h"
|
||||
#include "sys/alt_llist.h"
|
||||
#include "priv/alt_dev_llist.h"
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
typedef struct alt_flash_dev alt_flash_dev;
|
||||
typedef alt_flash_dev alt_flash_fd;
|
||||
|
||||
static ALT_INLINE int alt_flash_device_register( alt_flash_fd* fd)
|
||||
{
|
||||
extern alt_llist alt_flash_dev_list;
|
||||
|
||||
return alt_dev_llist_insert ((alt_dev_llist*) fd, &alt_flash_dev_list);
|
||||
}
|
||||
|
||||
typedef alt_flash_dev* (*alt_flash_open)(alt_flash_dev* flash,
|
||||
const char* name );
|
||||
typedef int (*alt_flash_close)(alt_flash_dev* flash_info);
|
||||
|
||||
typedef int (*alt_flash_write)( alt_flash_dev* flash, int offset,
|
||||
const void* src_addr, int length );
|
||||
|
||||
typedef int (*alt_flash_get_flash_info)( alt_flash_dev* flash, flash_region** info,
|
||||
int* number_of_regions);
|
||||
typedef int (*alt_flash_write_block)( alt_flash_dev* flash, int block_offset,
|
||||
int data_offset, const void* data,
|
||||
int length);
|
||||
typedef int (*alt_flash_erase_block)( alt_flash_dev* flash, int offset);
|
||||
typedef int (*alt_flash_read)(alt_flash_dev* flash, int offset,
|
||||
void* dest_addr, int length );
|
||||
typedef int (*alt_flash_lock)(alt_flash_dev* flash, alt_u32 sectors_to_lock);
|
||||
|
||||
struct alt_flash_dev
|
||||
{
|
||||
alt_llist llist;
|
||||
const char* name;
|
||||
alt_flash_open open;
|
||||
alt_flash_close close;
|
||||
alt_flash_write write;
|
||||
alt_flash_read read;
|
||||
alt_flash_get_flash_info get_info;
|
||||
alt_flash_erase_block erase_block;
|
||||
alt_flash_write_block write_block;
|
||||
void* base_addr;
|
||||
int length;
|
||||
int number_of_regions;
|
||||
flash_region region_info[ALT_MAX_NUMBER_OF_FLASH_REGIONS];
|
||||
alt_flash_lock lock;
|
||||
};
|
||||
|
||||
#endif /* __ALT_FLASH_DEV_H__ */
|
|
@ -1,62 +0,0 @@
|
|||
#ifndef __ALT_FLASH_TYPES_H__
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* Alt_flash_types.h - Some generic types and defines used by the flash code *
|
||||
* *
|
||||
* Author PRR *
|
||||
* *
|
||||
******************************************************************************/
|
||||
#define __ALT_FLASH_TYPES_H__
|
||||
|
||||
#ifndef ALT_MAX_NUMBER_OF_FLASH_REGIONS
|
||||
#define ALT_MAX_NUMBER_OF_FLASH_REGIONS 8
|
||||
#endif /* ALT_MAX_NUMBER_OF_FLASH_REGIONS */
|
||||
|
||||
/*
|
||||
* Description of a single Erase region
|
||||
*/
|
||||
typedef struct flash_region
|
||||
{
|
||||
int offset;
|
||||
int region_size;
|
||||
int number_of_blocks;
|
||||
int block_size;
|
||||
}flash_region;
|
||||
|
||||
#endif /* __ALT_FLASH_TYPES_H__ */
|
|
@ -1,74 +0,0 @@
|
|||
#ifndef __ALT_LICENSE_REMINDER_UCOSII_H__
|
||||
#define __ALT_LICENSE_REMINDER_UCOSII_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define ALT_LICENSE_REMINDER_UCOSII_STRING \
|
||||
"============== Software License Reminder ===============\n" \
|
||||
"\n" \
|
||||
"uC/OS-II is provided in source form for FREE evaluation,\n" \
|
||||
"for educational use, or for peaceful research. If you\n" \
|
||||
"plan on using uC/OS-II in a commercial product you need\n" \
|
||||
"to contact Micrium to properly license its use in your\n" \
|
||||
"product. Micrium provides ALL the source code on the\n" \
|
||||
"Altera distribution for your convenience and to help you\n" \
|
||||
"experience uC/OS-II. The fact that the source is provided\n" \
|
||||
"does NOT mean that you can use it without paying a\n" \
|
||||
"licensing fee. Please help us continue to provide the\n" \
|
||||
"Embedded community with the finest software available.\n" \
|
||||
"Your honesty is greatly appreciated.\n" \
|
||||
"\n" \
|
||||
"Please contact:\n" \
|
||||
"\n" \
|
||||
"M I C R I U M\n" \
|
||||
"949 Crestview Circle\n" \
|
||||
"Weston, FL 33327-1848\n" \
|
||||
"U.S.A.\n" \
|
||||
"\n" \
|
||||
"Phone : +1 954 217 2036\n" \
|
||||
"FAX : +1 954 217 2037\n" \
|
||||
"WEB : www.micrium.com\n" \
|
||||
"E-mail: Sales@Micrium.com\n" \
|
||||
"\n" \
|
||||
"========================================================\n"
|
||||
|
||||
#define alt_license_reminder_ucosii() puts(ALT_LICENSE_REMINDER_UCOSII_STRING)
|
||||
|
||||
|
||||
#endif /* __ALT_LICENSE_REMINDER_UCOSII_H__ */
|
|
@ -1,121 +0,0 @@
|
|||
#ifndef __ALT_LIST_H__
|
||||
#define __ALT_LIST_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
/*
|
||||
* alt_llist.h defines structures and functions for use in manipulating linked
|
||||
* lists. A list is considered to be constructed from a chain of objects of
|
||||
* type alt_llist, with one object being defined to be the head element.
|
||||
*
|
||||
* A list is considered to be empty if it only contains the head element.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* alt_llist is the structure used to represent an element within a linked
|
||||
* list.
|
||||
*/
|
||||
|
||||
typedef struct alt_llist_s alt_llist;
|
||||
|
||||
struct alt_llist_s {
|
||||
alt_llist* next; /* Pointer to the next element in the list. */
|
||||
alt_llist* previous; /* Pointer to the previous element in the list. */
|
||||
};
|
||||
|
||||
/*
|
||||
* ALT_LLIST_HEAD is a macro that can be used to create the head of a new
|
||||
* linked list. This is named "head". The head element is initialised to
|
||||
* represent an empty list.
|
||||
*/
|
||||
|
||||
#define ALT_LLIST_HEAD(head) alt_llist head = {&head, &head}
|
||||
|
||||
/*
|
||||
* ALT_LLIST_ENTRY is a macro used to define an uninitialised linked list
|
||||
* entry. This is used to reserve space in structure initialisation for
|
||||
* structures that inherit form alt_llist.
|
||||
*/
|
||||
|
||||
#define ALT_LLIST_ENTRY {0, 0}
|
||||
|
||||
/*
|
||||
* alt_llist_insert() insert adds the linked list entry "entry" as the
|
||||
* first entry in the linked list "list". "list" is the list head element.
|
||||
*/
|
||||
|
||||
static ALT_INLINE void ALT_ALWAYS_INLINE alt_llist_insert(alt_llist* list,
|
||||
alt_llist* entry)
|
||||
{
|
||||
entry->previous = list;
|
||||
entry->next = list->next;
|
||||
|
||||
list->next->previous = entry;
|
||||
list->next = entry;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_llist_remove() is called to remove an element from a linked list. The
|
||||
* input argument is the element to remove.
|
||||
*/
|
||||
|
||||
static ALT_INLINE void ALT_ALWAYS_INLINE alt_llist_remove(alt_llist* entry)
|
||||
{
|
||||
entry->next->previous = entry->previous;
|
||||
entry->previous->next = entry->next;
|
||||
|
||||
/*
|
||||
* Set the entry to point to itself, so that any further calls to
|
||||
* alt_llist_remove() are harmless.
|
||||
*/
|
||||
|
||||
entry->previous = entry;
|
||||
entry->next = entry;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_LLIST_H__ */
|
|
@ -1,76 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2005 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
/*
|
||||
* This macro is used to load code/data from its load address to its
|
||||
* execution address for a given section. The section name is the input
|
||||
* argument. Note that a leading '.' is assumed in the name. For example
|
||||
* to load the section .onchip_ram, use:
|
||||
*
|
||||
* ALT_LOAD_SECTION_BY_NAME(onchip_ram);
|
||||
*
|
||||
* This requires that the apropriate linker symbols have been generated
|
||||
* for the section in question. This will be the case if you are using the
|
||||
* default linker script.
|
||||
*/
|
||||
|
||||
#define ALT_LOAD_SECTION_BY_NAME(name) \
|
||||
{ \
|
||||
extern void _alt_partition_##name##_start; \
|
||||
extern void _alt_partition_##name##_end; \
|
||||
extern void _alt_partition_##name##_load_addr; \
|
||||
\
|
||||
alt_load_section(&_alt_partition_##name##_load_addr, \
|
||||
&_alt_partition_##name##_start, \
|
||||
&_alt_partition_##name##_end); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Function used to load an individual section from flash to RAM.
|
||||
*
|
||||
* There is an implicit assumption here that the linker script will ensure
|
||||
* that all sections are word aligned.
|
||||
*
|
||||
*/
|
||||
|
||||
static void ALT_INLINE alt_load_section (alt_u32* from,
|
||||
alt_u32* to,
|
||||
alt_u32* end)
|
||||
{
|
||||
if (to != from)
|
||||
{
|
||||
while( to != end )
|
||||
{
|
||||
*to++ = *from++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,353 +0,0 @@
|
|||
/* alt_log_printf.h
|
||||
*
|
||||
* ALT_LOG is designed to provide extra logging/debugging messages from HAL
|
||||
* through a different port than stdout. It is enabled by the ALT_LOG_ENABLE
|
||||
* define, which needs to supplied at compile time. When logging is turned off,
|
||||
* code size is unaffected. Thus, this should be transparent to the user
|
||||
* when it is not actively turned on, and should not affect projects in any way.
|
||||
*
|
||||
* There are macros sprinkled within different components, such as the jtag uart
|
||||
* and timer, in the HAL code. They are always named ALT_LOG_<name>, and can be
|
||||
* safely ignored if ALT_LOG is turned off.
|
||||
*
|
||||
* To turn on ALT_LOG, ALT_LOG_ENABLE must be defined, and ALT_LOG_PORT_TYPE and
|
||||
* ALT_LOG_PORT_BASE must be set in system.h. This is done through editing
|
||||
* <project>.ptf, by editing the alt_log_port_type & alt_log_port_base settings.
|
||||
* See the documentation html file for examples.
|
||||
*
|
||||
* When it is turned on, it will output extra HAL messages to a port specified
|
||||
* in system.h. This can be a UART or JTAG UART port. By default it will
|
||||
* output boot messages, detailing every step of the boot process.
|
||||
*
|
||||
* Extra logging is designed to be enabled by flags, which are defined in
|
||||
* alt_log_printf.c. The default value is that all flags are off, so only the
|
||||
* boot up logging messages show up. ALT_LOG_FLAGS can be set to enable certain
|
||||
* groupings of flags, and that grouping is done in this file. Each flag can
|
||||
* also be overridden with a -D at compile time.
|
||||
*
|
||||
* This header file includes the necessary prototypes for using the alt_log
|
||||
* functions. It also contains all the macros that are used to remove the code
|
||||
* from alt log is turned off. Also, the macros in other HAL files are defined
|
||||
* here at the bottom. These macros all call some C function that is in
|
||||
* alt_log_printf.c.
|
||||
*
|
||||
* The logging has functions for printing in C (ALT_LOG_PRINTF) and in assembly
|
||||
* (ALT_LOG_PUTS). This was needed because the assembly printing occurs before
|
||||
* the device is initialized. The assembly function corrupts register R4-R7,
|
||||
* which are not used in the normal boot process. For this reason, do not call
|
||||
* the assembly function in C.
|
||||
*
|
||||
* author: gkwan
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ALT_LOG_PRINTF_H__
|
||||
#define __ALT_LOG_PRINTF_H__
|
||||
|
||||
#include <system.h>
|
||||
|
||||
/* Global switch to turn on logging functions */
|
||||
#ifdef ALT_LOG_ENABLE
|
||||
|
||||
/* ALT_LOG_PORT_TYPE values as defined in system.h. They are defined as
|
||||
* numbers here first becasue the C preprocessor does not handle string
|
||||
* comparisons. */
|
||||
#define ALTERA_AVALON_JTAG_UART 1
|
||||
#define ALTERA_AVALON_UART 0
|
||||
|
||||
/* If this .h file is included by an assembly file, skip over include files
|
||||
* that won't compile in assembly. */
|
||||
#ifndef ALT_ASM_SRC
|
||||
#include <stdarg.h>
|
||||
#include "sys/alt_alarm.h"
|
||||
#include "sys/alt_dev.h"
|
||||
#ifdef __ALTERA_AVALON_JTAG_UART
|
||||
#include "altera_avalon_jtag_uart.h"
|
||||
#endif
|
||||
#endif /* ALT_ASM_SRC */
|
||||
|
||||
/* These are included for the port register offsets and masks, needed
|
||||
* to write to the port. Only include if the port type is set correctly,
|
||||
* otherwise error. If alt_log is turned on and the port to output to is
|
||||
* incorrect or does not exist, then should exit. */
|
||||
#if ALT_LOG_PORT_TYPE == ALTERA_AVALON_JTAG_UART
|
||||
#ifdef __ALTERA_AVALON_JTAG_UART
|
||||
#include <altera_avalon_jtag_uart_regs.h>
|
||||
#else
|
||||
#error ALT_LOG: JTAG_UART port chosen, but no JTAG_UART in system.
|
||||
#endif
|
||||
#elif ALT_LOG_PORT_TYPE == ALTERA_AVALON_UART
|
||||
#ifdef __ALTERA_AVALON_UART
|
||||
#include <altera_avalon_uart_regs.h>
|
||||
#else
|
||||
#error ALT_LOG: UART Port chosen, but no UART in system.
|
||||
#endif
|
||||
#else
|
||||
#error ALT_LOG: alt_log_port_type declaration invalid!
|
||||
#endif
|
||||
|
||||
/* ALT_LOG_ENABLE turns on the basic printing function */
|
||||
#define ALT_LOG_PRINTF(...) do {alt_log_printf_proc(__VA_ARGS__);} while (0)
|
||||
|
||||
/* Assembly macro for printing in assembly, calls tx_log_str
|
||||
* which is in alt_log_macro.S.
|
||||
* If alt_log_boot_on_flag is 0, skips the printing */
|
||||
#define ALT_LOG_PUTS(str) movhi r4, %hiadj(alt_log_boot_on_flag) ; \
|
||||
addi r4, r4, %lo(alt_log_boot_on_flag) ; \
|
||||
ldwio r5, 0(r4) ; \
|
||||
beq r0, r5, 0f ; \
|
||||
movhi r4, %hiadj(str) ; \
|
||||
addi r4, r4, %lo(str) ; \
|
||||
call tx_log_str ; \
|
||||
0:
|
||||
|
||||
/* These defines are here to faciliate the use of one output function
|
||||
* (alt_log_txchar) to print to both the JTAG UART or the UART. Depending
|
||||
* on the port type, the status register, read mask, and output register
|
||||
* are set to the appropriate value for the port. */
|
||||
#if ALT_LOG_PORT_TYPE == ALTERA_AVALON_JTAG_UART
|
||||
#define ALT_LOG_PRINT_REG_RD IORD_ALTERA_AVALON_JTAG_UART_CONTROL
|
||||
#define ALT_LOG_PRINT_MSK ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_MSK
|
||||
#define ALT_LOG_PRINT_TXDATA_WR IOWR_ALTERA_AVALON_JTAG_UART_DATA
|
||||
#define ALT_LOG_PRINT_REG_OFFSET (ALTERA_AVALON_JTAG_UART_CONTROL_REG*0x4)
|
||||
#define ALT_LOG_PRINT_TXDATA_REG_OFFSET (ALTERA_AVALON_JTAG_UART_DATA_REG*0x4)
|
||||
#elif ALT_LOG_PORT_TYPE == ALTERA_AVALON_UART
|
||||
#define ALT_LOG_PRINT_REG_RD IORD_ALTERA_AVALON_UART_STATUS
|
||||
#define ALT_LOG_PRINT_MSK ALTERA_AVALON_UART_STATUS_TRDY_MSK
|
||||
#define ALT_LOG_PRINT_TXDATA_WR IOWR_ALTERA_AVALON_UART_TXDATA
|
||||
#define ALT_LOG_PRINT_REG_OFFSET (ALTERA_AVALON_UART_STATUS_REG*0x4)
|
||||
#define ALT_LOG_PRINT_TXDATA_REG_OFFSET (ALTERA_AVALON_UART_TXDATA_REG*0x4)
|
||||
#endif /* ALT_LOG_PORT */
|
||||
|
||||
/* Grouping of flags via ALT_LOG_FLAGS. Each specific flag can be set via
|
||||
* -D at compile time, or else they'll be set to a default value according
|
||||
* to ALT_LOG_FLAGS. ALT_LOG_FLAGS = 0 or not set is the default, where
|
||||
* only the boot messages will be printed. As ALT_LOG_FLAGS increase, they
|
||||
* increase in intrusiveness to the program, and will affect performance.
|
||||
*
|
||||
* Flag Level 1 - turns on system clock and JTAG UART startup status
|
||||
* 2 - turns on write echo and JTAG_UART alarm (periodic report)
|
||||
* 3 - turns on JTAG UART ISR logging - will slow performance
|
||||
* significantly.
|
||||
* -1 - All logging output is off, but if ALT_LOG_ENABLE is
|
||||
* defined all logging function is built and code size
|
||||
* remains constant
|
||||
*
|
||||
* Flag settings - 1 = on, 0 = off. */
|
||||
|
||||
/* This flag turns on "boot" messages for printing. This includes messages
|
||||
* during crt0.S, then alt_main, and finally alt_exit. */
|
||||
#ifndef ALT_LOG_BOOT_ON_FLAG_SETTING
|
||||
#if ALT_LOG_FLAGS == 1
|
||||
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == 2
|
||||
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == 3
|
||||
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == -1 /* silent mode */
|
||||
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x0
|
||||
#else /* default setting */
|
||||
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x1
|
||||
#endif
|
||||
#endif /* ALT_LOG_BOOT_ON_FLAG_SETTING */
|
||||
|
||||
#ifndef ALT_LOG_SYS_CLK_ON_FLAG_SETTING
|
||||
#if ALT_LOG_FLAGS == 1
|
||||
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == 2
|
||||
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == 3
|
||||
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == -1 /* silent mode */
|
||||
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x0
|
||||
#else /* default setting */
|
||||
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x0
|
||||
#endif
|
||||
#endif /* ALT_LOG_SYS_CLK_ON_FLAG_SETTING */
|
||||
|
||||
#ifndef ALT_LOG_WRITE_ON_FLAG_SETTING
|
||||
#if ALT_LOG_FLAGS == 1
|
||||
#define ALT_LOG_WRITE_ON_FLAG_SETTING 0x0
|
||||
#elif ALT_LOG_FLAGS == 2
|
||||
#define ALT_LOG_WRITE_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == 3
|
||||
#define ALT_LOG_WRITE_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == -1 /* silent mode */
|
||||
#define ALT_LOG_WRITE_ON_FLAG_SETTING 0x0
|
||||
#else /* default setting */
|
||||
#define ALT_LOG_WRITE_ON_FLAG_SETTING 0x0
|
||||
#endif
|
||||
#endif /* ALT_LOG_WRITE_ON_FLAG_SETTING */
|
||||
|
||||
#ifndef ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING
|
||||
#ifndef __ALTERA_AVALON_JTAG_UART
|
||||
#define ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING 0x0
|
||||
#elif ALT_LOG_FLAGS == 1
|
||||
#define ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING 0x0
|
||||
#elif ALT_LOG_FLAGS == 2
|
||||
#define ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == 3
|
||||
#define ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == -1 /* silent mode */
|
||||
#define ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING 0x0
|
||||
#else /* default setting */
|
||||
#define ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING 0x0
|
||||
#endif
|
||||
#endif /* ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING */
|
||||
|
||||
#ifndef ALT_LOG_JTAG_UART_STARTUP_INFO_ON_FLAG_SETTING
|
||||
#ifndef __ALTERA_AVALON_JTAG_UART
|
||||
#define ALT_LOG_JTAG_UART_STARTUP_INFO_ON_FLAG_SETTING 0x0
|
||||
#elif ALT_LOG_FLAGS == 1
|
||||
#define ALT_LOG_JTAG_UART_STARTUP_INFO_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == 2
|
||||
#define ALT_LOG_JTAG_UART_STARTUP_INFO_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == 3
|
||||
#define ALT_LOG_JTAG_UART_STARTUP_INFO_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == -1 /* silent mode */
|
||||
#define ALT_LOG_JTAG_UART_STARTUP_INFO_ON_FLAG_SETTING 0x0
|
||||
#else /* default setting */
|
||||
#define ALT_LOG_JTAG_UART_STARTUP_INFO_ON_FLAG_SETTING 0x0
|
||||
#endif
|
||||
#endif /* ALT_LOG_JTAG_UART_STARTUP_INFO_FLAG_SETTING */
|
||||
|
||||
#ifndef ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING
|
||||
#ifndef __ALTERA_AVALON_JTAG_UART
|
||||
#define ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING 0x0
|
||||
#elif ALT_LOG_FLAGS == 1
|
||||
#define ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING 0x0
|
||||
#elif ALT_LOG_FLAGS == 2
|
||||
#define ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING 0x0
|
||||
#elif ALT_LOG_FLAGS == 3
|
||||
#define ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING 0x1
|
||||
#elif ALT_LOG_FLAGS == -1 /* silent mode */
|
||||
#define ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING 0x0
|
||||
#else /* default setting */
|
||||
#define ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING 0x0
|
||||
#endif
|
||||
#endif /* ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING */
|
||||
|
||||
#ifndef ALT_ASM_SRC
|
||||
/* Function Prototypes */
|
||||
void alt_log_txchar(int c,char *uartBase);
|
||||
void alt_log_private_printf(const char *fmt,int base,va_list args);
|
||||
void alt_log_repchar(char c,int r,int base);
|
||||
int alt_log_printf_proc(const char *fmt, ... );
|
||||
void alt_log_system_clock();
|
||||
#ifdef __ALTERA_AVALON_JTAG_UART
|
||||
alt_u32 altera_avalon_jtag_uart_report_log(void * context);
|
||||
void alt_log_jtag_uart_startup_info(altera_avalon_jtag_uart_state* dev, int base);
|
||||
void alt_log_jtag_uart_print_control_reg(altera_avalon_jtag_uart_state* dev, \
|
||||
int base, const char* header);
|
||||
void alt_log_jtag_uart_isr_proc(int base, altera_avalon_jtag_uart_state* dev);
|
||||
#endif
|
||||
void alt_log_write(const void *ptr, size_t len);
|
||||
|
||||
/* extern all global variables */
|
||||
/* CASE:368514 - The boot message flag is linked into the sdata section
|
||||
* because if it is zero, it would otherwise be placed in the bss section.
|
||||
* alt_log examines this variable before the BSS is cleared in the boot-up
|
||||
* process.
|
||||
*/
|
||||
extern volatile alt_u32 alt_log_boot_on_flag __attribute__ ((section (".sdata")));
|
||||
extern volatile alt_u8 alt_log_write_on_flag;
|
||||
extern volatile alt_u8 alt_log_sys_clk_on_flag;
|
||||
extern volatile alt_u8 alt_log_jtag_uart_alarm_on_flag;
|
||||
extern volatile alt_u8 alt_log_jtag_uart_isr_on_flag;
|
||||
extern volatile alt_u8 alt_log_jtag_uart_startup_info_on_flag;
|
||||
extern volatile int alt_log_sys_clk_count;
|
||||
extern volatile int alt_system_clock_in_sec;
|
||||
extern alt_alarm alt_log_jtag_uart_alarm_1;
|
||||
#endif /* ALT_ASM_SRC */
|
||||
|
||||
|
||||
/* Below are the MACRO defines used in various HAL files. They check
|
||||
* if their specific flag is turned on; if it is, then it executes its
|
||||
* code.
|
||||
*
|
||||
* To keep this file reasonable, most of these macros calls functions,
|
||||
* which are defined in alt_log_printf.c. Look there for implementation
|
||||
* details. */
|
||||
|
||||
/* Boot Messages Logging */
|
||||
#define ALT_LOG_PRINT_BOOT(...) \
|
||||
do { if (alt_log_boot_on_flag==1) {ALT_LOG_PRINTF(__VA_ARGS__);} \
|
||||
} while (0)
|
||||
|
||||
/* JTAG UART Logging */
|
||||
/* number of ticks before alarm runs logging function */
|
||||
#ifndef ALT_LOG_JTAG_UART_TICKS_DIVISOR
|
||||
#define ALT_LOG_JTAG_UART_TICKS_DIVISOR 10
|
||||
#endif
|
||||
#ifndef ALT_LOG_JTAG_UART_TICKS
|
||||
#define ALT_LOG_JTAG_UART_TICKS \
|
||||
(alt_ticks_per_second()/ALT_LOG_JTAG_UART_TICKS_DIVISOR)
|
||||
#endif
|
||||
|
||||
/* if there's a JTAG UART defined, then enable these macros */
|
||||
#ifdef __ALTERA_AVALON_JTAG_UART
|
||||
|
||||
/* Macro in altera_avalon_jtag_uart.c, to register the alarm function.
|
||||
* Also, the startup register info is also printed here, as this is
|
||||
* called within the device driver initialization. */
|
||||
#define ALT_LOG_JTAG_UART_ALARM_REGISTER(dev, base) \
|
||||
do { if (alt_log_jtag_uart_alarm_on_flag==1) { \
|
||||
alt_alarm_start(&alt_log_jtag_uart_alarm_1, \
|
||||
ALT_LOG_JTAG_UART_TICKS, &altera_avalon_jtag_uart_report_log,\
|
||||
dev);} \
|
||||
if (alt_log_jtag_uart_startup_info_on_flag==1) {\
|
||||
alt_log_jtag_uart_startup_info(dev, base);} \
|
||||
} while (0)
|
||||
|
||||
/* JTAG UART IRQ Logging (when buffer is empty)
|
||||
* Inserted in the ISR in altera_avalon_jtag_uart.c */
|
||||
#define ALT_LOG_JTAG_UART_ISR_FUNCTION(base, dev) \
|
||||
do { alt_log_jtag_uart_isr_proc(base, dev); } while (0)
|
||||
/* else, define macros to nothing. Or else the jtag_uart specific types
|
||||
* will throw compiler errors */
|
||||
#else
|
||||
#define ALT_LOG_JTAG_UART_ALARM_REGISTER(dev, base)
|
||||
#define ALT_LOG_JTAG_UART_ISR_FUNCTION(base, dev)
|
||||
#endif
|
||||
|
||||
/* System clock logging
|
||||
* How often (in seconds) the system clock logging prints.
|
||||
* The default value is every 1 second */
|
||||
#ifndef ALT_LOG_SYS_CLK_INTERVAL_MULTIPLIER
|
||||
#define ALT_LOG_SYS_CLK_INTERVAL_MULTIPLIER 1
|
||||
#endif
|
||||
#ifndef ALT_LOG_SYS_CLK_INTERVAL
|
||||
#define ALT_LOG_SYS_CLK_INTERVAL \
|
||||
(alt_ticks_per_second()*ALT_LOG_SYS_CLK_INTERVAL_MULTIPLIER)
|
||||
#endif
|
||||
|
||||
/* System clock logging - prints a message every interval (set above)
|
||||
* to show that the system clock is alive.
|
||||
* This macro is used in altera_avalon_timer_sc.c */
|
||||
#define ALT_LOG_SYS_CLK_HEARTBEAT() \
|
||||
do { alt_log_system_clock(); } while (0)
|
||||
|
||||
/* alt_write_logging - echos a message every time write() is called,
|
||||
* displays the first ALT_LOG_WRITE_ECHO_LEN characters.
|
||||
* This macro is used in alt_write.c */
|
||||
#ifndef ALT_LOG_WRITE_ECHO_LEN
|
||||
#define ALT_LOG_WRITE_ECHO_LEN 15
|
||||
#endif
|
||||
|
||||
#define ALT_LOG_WRITE_FUNCTION(ptr,len) \
|
||||
do { alt_log_write(ptr,len); } while (0)
|
||||
|
||||
#else /* ALT_LOG_ENABLE not defined */
|
||||
|
||||
/* logging is off, set all relevant macros to null */
|
||||
#define ALT_LOG_PRINT_BOOT(...)
|
||||
#define ALT_LOG_PRINTF(...)
|
||||
#define ALT_LOG_JTAG_UART_ISR_FUNCTION(base, dev)
|
||||
#define ALT_LOG_JTAG_UART_ALARM_REGISTER(dev, base)
|
||||
#define ALT_LOG_SYS_CLK_HEARTBEAT()
|
||||
#define ALT_LOG_PUTS(str)
|
||||
#define ALT_LOG_WRITE_FUNCTION(ptr,len)
|
||||
|
||||
#endif /* ALT_LOG_ENABLE */
|
||||
|
||||
#endif /* __ALT_LOG_PRINTF_H__ */
|
|
@ -1,69 +0,0 @@
|
|||
#ifndef __ALT_SET_ARGS_H__
|
||||
#define __ALT_SET_ARGS_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* The function alt_set_args() is provided in order to define the input
|
||||
* arguments to main(). If this function is not called before main() then the
|
||||
* argument list passed to main() will be empty.
|
||||
*
|
||||
* It is expected that this function will only be used by the ihost/iclient
|
||||
* utility.
|
||||
*/
|
||||
|
||||
static inline void alt_set_args (int argc, char** argv, char** envp)
|
||||
{
|
||||
extern int alt_argc;
|
||||
extern char** alt_argv;
|
||||
extern char** alt_envp;
|
||||
|
||||
alt_argc = argc;
|
||||
alt_argv = argv;
|
||||
alt_envp = envp;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_SET_ARGS_H__ */
|
|
@ -1,64 +0,0 @@
|
|||
#ifndef __ALT_STDIO_H__
|
||||
#define __ALT_STDIO_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2015 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* Definitions for ALT stdio routines.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int alt_getchar();
|
||||
int alt_putchar(int c);
|
||||
int alt_putstr(const char* str);
|
||||
void alt_printf(const char *fmt, ...);
|
||||
#ifdef ALT_SEMIHOSTING
|
||||
int alt_putcharbuf(int c);
|
||||
int alt_putstrbuf(const char* str);
|
||||
int alt_putbufflush();
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_STDIO_H__ */
|
|
@ -1,60 +0,0 @@
|
|||
#ifndef __ALT_SYS_INIT_H__
|
||||
#define __ALT_SYS_INIT_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* The function alt_sys_init() is defined within the auto-generated file:
|
||||
* alt_sys_init.c. This function calls the initilisation macros for all
|
||||
* devices, file systems, and software components within the system.
|
||||
*
|
||||
* The list of initilisation macros to use is constructed using the PTF and
|
||||
* STF files associated with the system.
|
||||
*/
|
||||
|
||||
extern void alt_sys_init (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_SYS_INIT_H__ */
|
|
@ -1,98 +0,0 @@
|
|||
#ifndef __ALT_SYS_WRAPPERS_H__
|
||||
#define __ALT_SYS_WRAPPERS_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* This file provides the prototypes for the HAL 'UNIX style functions. The
|
||||
* names of these functions are defined in alt_syscall.h. THese are defined to
|
||||
* be the standard names when running the standalone HAL, e.g. open(), close()
|
||||
* etc., but the names may be redefined as a part of an operating system port
|
||||
* in order to avoid name clashes.
|
||||
*/
|
||||
|
||||
#include "os/alt_syscall.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
extern int ALT_CLOSE (int __fd);
|
||||
extern int ALT_EXECVE (const char *__path,
|
||||
char * const __argv[],
|
||||
char * const __envp[]);
|
||||
extern void ALT_EXIT (int __status);
|
||||
extern int ALT_FSTAT (int file, struct stat *st);
|
||||
extern int ALT_FCNTL (int file, int cmd, ...);
|
||||
extern pid_t ALT_FORK (void);
|
||||
extern pid_t ALT_GETPID (void);
|
||||
|
||||
#if defined (__GNUC__) && __GNUC__ >= 4
|
||||
extern int ALT_GETTIMEOFDAY (struct timeval *ptimeval,
|
||||
void *ptimezone);
|
||||
#else
|
||||
extern int ALT_GETTIMEOFDAY (struct timeval *ptimeval,
|
||||
struct timezone *ptimezone);
|
||||
#endif
|
||||
|
||||
extern int ALT_IOCTL (int file, int req, void* arg);
|
||||
extern int ALT_ISATTY (int file);
|
||||
extern int ALT_KILL (int pid, int sig);
|
||||
extern int ALT_LINK (const char *existing, const char *new);
|
||||
extern off_t ALT_LSEEK (int file, off_t ptr, int dir);
|
||||
extern int ALT_OPEN (const char* file, int flags, ...);
|
||||
extern int ALT_READ (int file, void *ptr, size_t len);
|
||||
extern int ALT_RENAME (char *existing, char *new);
|
||||
extern void* ALT_SBRK (ptrdiff_t incr);
|
||||
extern int ALT_SETTIMEOFDAY (const struct timeval *t,
|
||||
const struct timezone *tz);
|
||||
extern int ALT_STAT (const char *file, struct stat *st);
|
||||
extern clock_t ALT_TIMES (struct tms *buf);
|
||||
extern int ALT_UNLINK (const char *name);
|
||||
|
||||
#if defined (__GNUC__) && __GNUC__ >= 4
|
||||
int ALT_USLEEP (useconds_t us);
|
||||
#else
|
||||
unsigned int ALT_USLEEP (unsigned int us);
|
||||
#endif
|
||||
|
||||
extern int ALT_WAIT (int *status);
|
||||
extern int ALT_WRITE (int file, const void *ptr, size_t len);
|
||||
|
||||
|
||||
extern char** ALT_ENVIRON;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#endif /* __ALT_SYS_WRAPPERS_H__ */
|
|
@ -1,58 +0,0 @@
|
|||
#ifndef __ALT_TIMESTAMP_H__
|
||||
#define __ALT_TIMESTAMP_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "altera_avalon_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern int alt_timestamp_start (void);
|
||||
|
||||
extern alt_timestamp_type alt_timestamp (void);
|
||||
|
||||
extern alt_u32 alt_timestamp_freq (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALT_TIMESTAMP_H__ */
|
|
@ -1,88 +0,0 @@
|
|||
#ifndef __IOCTL_H__
|
||||
#define __IOCTL_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* The ioctl() system call be used to initiate a variety of control operations
|
||||
* on a file descriptor. For the most part this simply translates to a call to
|
||||
* the ioctl() function of the associated device driver (TIOCEXCL and
|
||||
* TIOCNXCL are notable exceptions - see ioctl.c for details).
|
||||
*
|
||||
* The interpretation of the ioctl requests are therefore device specific.
|
||||
*
|
||||
* This function is equivalent to the standard Posix ioctl() call.
|
||||
*/
|
||||
|
||||
extern int ioctl (int fd, int req, void* arg);
|
||||
|
||||
/*
|
||||
* list of ioctl calls handled by the system ioctl implementation.
|
||||
*/
|
||||
|
||||
#define TIOCEXCL 0x740d /* exclusive use of the device */
|
||||
#define TIOCNXCL 0x740e /* allow multiple use of the device */
|
||||
|
||||
/*
|
||||
* ioctl calls which can be handled by device drivers.
|
||||
*/
|
||||
|
||||
#define TIOCOUTQ 0x7472 /* get output queue size */
|
||||
#define TIOCMGET 0x741d /* get termios flags */
|
||||
#define TIOCMSET 0x741a /* set termios flags */
|
||||
|
||||
/*
|
||||
* ioctl calls specific to JTAG UART.
|
||||
*/
|
||||
|
||||
#define TIOCSTIMEOUT 0x6a01 /* Set Timeout before assuming no host present */
|
||||
#define TIOCGCONNECTED 0x6a02 /* Get indication of whether host is connected */
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __IOCTL_H__ */
|
|
@ -1,178 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* This is the termios.h file provided with newlib. The only modification has
|
||||
* been to the baud rate macro definitions, and an increase in the size of the
|
||||
* termios structure to accomodate this.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SYS_TERMIOS_H
|
||||
# define _SYS_TERMIOS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
# define _XCGETA (('x'<<8)|1)
|
||||
# define _XCSETA (('x'<<8)|2)
|
||||
# define _XCSETAW (('x'<<8)|3)
|
||||
# define _XCSETAF (('x'<<8)|4)
|
||||
# define _TCSBRK (('T'<<8)|5)
|
||||
# define _TCFLSH (('T'<<8)|7)
|
||||
# define _TCXONC (('T'<<8)|6)
|
||||
|
||||
# define TCOOFF 0
|
||||
# define TCOON 1
|
||||
# define TCIOFF 2
|
||||
# define TCION 3
|
||||
|
||||
# define TCIFLUSH 0
|
||||
# define TCOFLUSH 1
|
||||
# define TCIOFLUSH 2
|
||||
|
||||
# define NCCS 13
|
||||
|
||||
# define TCSAFLUSH _XCSETAF
|
||||
# define TCSANOW _XCSETA
|
||||
# define TCSADRAIN _XCSETAW
|
||||
# define TCSADFLUSH _XCSETAF
|
||||
|
||||
# define IGNBRK 000001
|
||||
# define BRKINT 000002
|
||||
# define IGNPAR 000004
|
||||
# define INPCK 000020
|
||||
# define ISTRIP 000040
|
||||
# define INLCR 000100
|
||||
# define IGNCR 000200
|
||||
# define ICRNL 000400
|
||||
# define IXON 002000
|
||||
# define IXOFF 010000
|
||||
|
||||
# define OPOST 000001
|
||||
# define OCRNL 000004
|
||||
# define ONLCR 000010
|
||||
# define ONOCR 000020
|
||||
# define TAB3 014000
|
||||
|
||||
# define CLOCAL 004000
|
||||
# define CREAD 000200
|
||||
# define CSIZE 000060
|
||||
# define CS5 0
|
||||
# define CS6 020
|
||||
# define CS7 040
|
||||
# define CS8 060
|
||||
# define CSTOPB 000100
|
||||
# define HUPCL 002000
|
||||
# define PARENB 000400
|
||||
# define PAODD 001000
|
||||
|
||||
#define CCTS_OFLOW 010000
|
||||
#define CRTS_IFLOW 020000
|
||||
#define CRTSCTS (CCTS_OFLOW | CRTS_IFLOW)
|
||||
|
||||
# define ECHO 0000010
|
||||
# define ECHOE 0000020
|
||||
# define ECHOK 0000040
|
||||
# define ECHONL 0000100
|
||||
# define ICANON 0000002
|
||||
# define IEXTEN 0000400 /* anybody know *what* this does?! */
|
||||
# define ISIG 0000001
|
||||
# define NOFLSH 0000200
|
||||
# define TOSTOP 0001000
|
||||
|
||||
# define VEOF 4 /* also VMIN -- thanks, AT&T */
|
||||
# define VEOL 5 /* also VTIME -- thanks again */
|
||||
# define VERASE 2
|
||||
# define VINTR 0
|
||||
# define VKILL 3
|
||||
# define VMIN 4 /* also VEOF */
|
||||
# define VQUIT 1
|
||||
# define VSUSP 10
|
||||
# define VTIME 5 /* also VEOL */
|
||||
# define VSTART 11
|
||||
# define VSTOP 12
|
||||
|
||||
# define B0 0
|
||||
# define B50 50
|
||||
# define B75 75
|
||||
# define B110 110
|
||||
# define B134 134
|
||||
# define B150 150
|
||||
# define B200 200
|
||||
# define B300 300
|
||||
# define B600 600
|
||||
# define B1200 1200
|
||||
# define B1800 1800
|
||||
# define B2400 2400
|
||||
# define B4800 4800
|
||||
# define B9600 9600
|
||||
# define B19200 19200
|
||||
# define B38400 38400
|
||||
# define B57600 57600
|
||||
# define B115200 115200
|
||||
|
||||
typedef unsigned char cc_t;
|
||||
typedef unsigned short tcflag_t;
|
||||
typedef unsigned long speed_t;
|
||||
|
||||
struct termios {
|
||||
tcflag_t c_iflag;
|
||||
tcflag_t c_oflag;
|
||||
tcflag_t c_cflag;
|
||||
tcflag_t c_lflag;
|
||||
char c_line;
|
||||
cc_t c_cc[NCCS];
|
||||
speed_t c_ispeed;
|
||||
speed_t c_ospeed;
|
||||
};
|
||||
|
||||
# ifndef _NO_MACROS
|
||||
|
||||
# define cfgetospeed(tp) ((tp)->c_ospeed)
|
||||
# define cfgetispeed(tp) ((tp)->c_ispeed)
|
||||
# define cfsetospeed(tp,s) (((tp)->c_ospeed = (s)), 0)
|
||||
# define cfsetispeed(tp,s) (((tp)->c_ispeed = (s)), 0)
|
||||
# define tcdrain(fd) _ioctl (fd, _TCSBRK, 1)
|
||||
# endif /* _NO_MACROS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_TERMIOS_H */
|
|
@ -1 +0,0 @@
|
|||
zephyr_sources(altera_common.c)
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "sys/alt_irq.h"
|
||||
#include "altera_common.h"
|
||||
|
||||
#define ALTERA_MAX_IRQ 32
|
||||
|
||||
static alt_isr_func alt_hal_isr[ALTERA_MAX_IRQ];
|
||||
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
int alt_ic_isr_register(alt_u32 ic_id, alt_u32 irq,
|
||||
alt_isr_func isr, void *isr_context, void *flags)
|
||||
|
||||
{
|
||||
if (irq <= ALTERA_MAX_IRQ)
|
||||
{
|
||||
alt_hal_isr[irq] = isr;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
int alt_irq_register(alt_u32 irq, void* context, alt_isr_func isr)
|
||||
{
|
||||
if (irq <= ALTERA_MAX_IRQ)
|
||||
{
|
||||
alt_hal_isr[irq] = isr;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void alt_handle_irq(void* base, alt_u32 id)
|
||||
{
|
||||
/* Null pointer check for handler function */
|
||||
if (!alt_hal_isr[id])
|
||||
return;
|
||||
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
alt_hal_isr[id]((void*)base);
|
||||
#else
|
||||
alt_hal_isr[id]((void*)base, id);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Add Altera HAL extern function definations here */
|
||||
|
||||
/*
|
||||
* alt_tick() should only be called by the system clock driver. This is used
|
||||
* to notify the system that the system timer period has expired.
|
||||
*/
|
||||
|
||||
void alt_tick (void)
|
||||
{
|
||||
}
|
||||
|
||||
#include "priv/alt_dev_llist.h"
|
||||
int alt_dev_llist_insert (alt_dev_llist* dev, alt_llist* list)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "priv/alt_busy_sleep.h"
|
||||
#include <kernel.h>
|
||||
unsigned int alt_busy_sleep (unsigned int us)
|
||||
{
|
||||
k_busy_wait(us);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void alt_printf(const char *fmt, ...)
|
||||
{
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,7 +0,0 @@
|
|||
zephyr_library()
|
||||
zephyr_library_compile_definitions(${COMPILER})
|
||||
zephyr_library_sources(altera_avalon_i2c.c)
|
||||
set_source_files_properties(altera_avalon_i2c.c
|
||||
PROPERTIES COMPILE_DEFINITIONS "${COMPILER}")
|
||||
set_source_files_properties(altera_avalon_i2c.c
|
||||
PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized) # altera_avalon_i2c.c warns on uninitialized
|
File diff suppressed because it is too large
Load diff
|
@ -1,150 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2016 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_AVALON_I2C_REGS_H__
|
||||
#define __ALT_AVALON_I2C_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#define IORMW(base, reg, data, mask) IOWR(base,reg,(IORD(base,reg) & (~mask)) | (data & mask))
|
||||
|
||||
#define ALT_AVALON_I2C_TFR_CMD_REG 0
|
||||
#define IOADDR_ALT_AVALON_I2C_TFR_CMD(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_TFR_CMD_REG)
|
||||
#define IORD_ALT_AVALON_I2C_TFR_CMD(base) IORD(base, ALT_AVALON_I2C_TFR_CMD_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_TFR_CMD(base, data) IOWR(base, ALT_AVALON_I2C_TFR_CMD_REG, data)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_STA_OFST (9)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_STA_MSK (1 << ALT_AVALON_I2C_TFR_CMD_STA_OFST)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_STO_OFST (8)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_STO_MSK (1 << ALT_AVALON_I2C_TFR_CMD_STO_OFST)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_AD_OFST (1)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_AD_MSK (0x7f << ALT_AVALON_I2C_TFR_CMD_AD_OFST)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_RW_D_OFST (0)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_RW_D_MSK (1 << ALT_AVALON_I2C_TFR_CMD_RW_D_OFST)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_ALL_BITS_MSK (0x3ff)
|
||||
|
||||
#define ALT_AVALON_I2C_RX_DATA_REG 1
|
||||
#define IOADDR_ALT_AVALON_I2C_RX_DATA(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_RX_DATA_REG)
|
||||
#define IORD_ALT_AVALON_I2C_RX_DATA(base) IORD(base, ALT_AVALON_I2C_RX_DATA_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_RX_DATA(base, data) IOWR(base, ALT_AVALON_I2C_RX_DATA_REG, data)
|
||||
#define ALT_AVALON_I2C_RX_DATA_RXDATA_OFST (0)
|
||||
#define ALT_AVALON_I2C_RX_DATA_RXDATA_MSK (0xff << ALT_AVALON_I2C_RX_DATA_RXDATA_OFST)
|
||||
|
||||
#define ALT_AVALON_I2C_CTRL_REG 2
|
||||
#define IOADDR_ALT_AVALON_I2C_CTRL(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_CTRL_REG)
|
||||
#define IORD_ALT_AVALON_I2C_CTRL(base) IORD(base, ALT_AVALON_I2C_CTRL_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_CTRL(base, data) IOWR(base, ALT_AVALON_I2C_CTRL_REG, data)
|
||||
#define IORMW_ALT_AVALON_I2C_CTRL(base, data, mask) IORMW(base,ALT_AVALON_I2C_CTRL_REG,data,mask)
|
||||
#define ALT_AVALON_I2C_CTRL_RX_DATA_FIFO_THD_OFST (4)
|
||||
#define ALT_AVALON_I2C_CTRL_RX_DATA_FIFO_THD_MSK (3 << ALT_AVALON_I2C_CTRL_RX_DATA_FIFO_THD_OFST)
|
||||
#define ALT_AVALON_I2C_CTRL_TFR_CMD_FIFO_THD_OFST (2)
|
||||
#define ALT_AVALON_I2C_CTRL_TFR_CMD_FIFO_THD_MSK (3 << ALT_AVALON_I2C_CTRL_TFR_CMD_FIFO_THD_OFST)
|
||||
#define ALT_AVALON_I2C_CTRL_BUS_SPEED_OFST (1)
|
||||
#define ALT_AVALON_I2C_CTRL_BUS_SPEED_MSK (1 << ALT_AVALON_I2C_CTRL_BUS_SPEED_OFST)
|
||||
#define ALT_AVALON_I2C_CTRL_EN_OFST (0)
|
||||
#define ALT_AVALON_I2C_CTRL_EN_MSK (1 << ALT_AVALON_I2C_CTRL_EN_OFST)
|
||||
|
||||
#define ALT_AVALON_I2C_ISER_REG 3
|
||||
#define IOADDR_ALT_AVALON_I2C_ISER(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_ISER_REG)
|
||||
#define IORD_ALT_AVALON_I2C_ISER(base) IORD(base, ALT_AVALON_I2C_ISER_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_ISER(base, data) IOWR(base, ALT_AVALON_I2C_ISER_REG, data)
|
||||
#define IORMW_ALT_AVALON_I2C_ISER(base, data, mask) IORMW(base,ALT_AVALON_I2C_ISER_REG,data,mask)
|
||||
#define ALT_AVALON_I2C_ISER_RX_OVER_EN_OFST (4)
|
||||
#define ALT_AVALON_I2C_ISER_RX_OVER_EN_MSK (1 << ALT_AVALON_I2C_ISER_RX_OVER_EN_OFST)
|
||||
#define ALT_AVALON_I2C_ISER_ARBLOST_DET_EN_OFST (3)
|
||||
#define ALT_AVALON_I2C_ISER_ARBLOST_DET_EN_MSK (1 << ALT_AVALON_I2C_ISER_ARBLOST_DET_EN_OFST)
|
||||
#define ALT_AVALON_I2C_ISER_NACK_DET_EN_OFST (2)
|
||||
#define ALT_AVALON_I2C_ISER_NACK_DET_EN_MSK (1 << ALT_AVALON_I2C_ISER_NACK_DET_EN_OFST)
|
||||
#define ALT_AVALON_I2C_ISER_RX_READY_EN_OFST (1)
|
||||
#define ALT_AVALON_I2C_ISER_RX_READY_EN_MSK (1 << ALT_AVALON_I2C_ISER_RX_READY_EN_OFST)
|
||||
#define ALT_AVALON_I2C_ISER_TX_READY_EN_OFST (0)
|
||||
#define ALT_AVALON_I2C_ISER_TX_READY_EN_MSK (1 << ALT_AVALON_I2C_ISER_TX_READY_EN_OFST)
|
||||
|
||||
#define ALT_AVALON_I2C_ISR_REG 4
|
||||
#define IOADDR_ALT_AVALON_I2C_ISR(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_ISR_REG)
|
||||
#define IORD_ALT_AVALON_I2C_ISR(base) IORD(base, ALT_AVALON_I2C_ISR_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_ISR(base, data) IOWR(base, ALT_AVALON_I2C_ISR_REG, data)
|
||||
#define IORMW_ALT_AVALON_I2C_ISR(base, data, mask) IORMW(base,ALT_AVALON_I2C_ISR_REG,data,mask)
|
||||
#define ALT_AVALON_I2C_ISR_RX_OVER_OFST (4)
|
||||
#define ALT_AVALON_I2C_ISR_RX_OVER_MSK (1 << ALT_AVALON_I2C_ISR_RX_OVER_OFST)
|
||||
#define ALT_AVALON_I2C_ISR_ARBLOST_DET_OFST (3)
|
||||
#define ALT_AVALON_I2C_ISR_ARBLOST_DET_MSK (1 << ALT_AVALON_I2C_ISR_ARBLOST_DET_OFST)
|
||||
#define ALT_AVALON_I2C_ISR_NACK_DET_OFST (2)
|
||||
#define ALT_AVALON_I2C_ISR_NACK_DET_MSK (1 << ALT_AVALON_I2C_ISR_NACK_DET_OFST)
|
||||
#define ALT_AVALON_I2C_ISR_RX_READY_OFST (1)
|
||||
#define ALT_AVALON_I2C_ISR_RX_READY_MSK (1 << ALT_AVALON_I2C_ISR_RX_READY_OFST)
|
||||
#define ALT_AVALON_I2C_ISR_TX_READY_OFST (0)
|
||||
#define ALT_AVALON_I2C_ISR_TX_READY_MSK (1 << ALT_AVALON_I2C_ISR_TX_READY_OFST)
|
||||
#define ALT_AVALON_I2C_ISR_ALLINTS_MSK (ALT_AVALON_I2C_ISR_RX_OVER_MSK | ALT_AVALON_I2C_ISR_ARBLOST_DET_MSK | \
|
||||
ALT_AVALON_I2C_ISR_NACK_DET_MSK | ALT_AVALON_I2C_ISR_RX_READY_MSK | \
|
||||
ALT_AVALON_I2C_ISR_TX_READY_MSK)
|
||||
#define ALT_AVALON_I2C_ISR_ALL_CLEARABLE_INTS_MSK (ALT_AVALON_I2C_ISR_RX_OVER_MSK | ALT_AVALON_I2C_ISR_ARBLOST_DET_MSK | \
|
||||
ALT_AVALON_I2C_ISR_NACK_DET_MSK)
|
||||
|
||||
#define ALT_AVALON_I2C_STATUS_REG 5
|
||||
#define IOADDR_ALT_AVALON_I2C_STATUS(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_STATUS_REG)
|
||||
#define IORD_ALT_AVALON_I2C_STATUS(base) IORD(base, ALT_AVALON_I2C_STATUS_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_STATUS(base, data) IOWR(base, ALT_AVALON_I2C_STATUS_REG, data)
|
||||
#define ALT_AVALON_I2C_STATUS_CORE_STATUS_OFST (0)
|
||||
#define ALT_AVALON_I2C_STATUS_CORE_STATUS_MSK (1 << ALT_AVALON_I2C_STATUS_CORE_STATUS_OFST)
|
||||
|
||||
#define ALT_AVALON_I2C_TFR_CMD_FIFO_LVL_REG 6
|
||||
#define IOADDR_ALT_AVALON_I2C_TFR_CMD_FIFO_LVL(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_TFR_CMD_FIFO_LVL_REG)
|
||||
#define IORD_ALT_AVALON_I2C_TFR_CMD_FIFO_LVL(base) IORD(base, ALT_AVALON_I2C_TFR_CMD_FIFO_LVL_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_TFR_CMD_FIFO_LVL(base, data) IOWR(base, ALT_AVALON_I2C_TFR_CMD_FIFO_LVL_REG, data)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_FIFO_LVL_FIFO_DEPTH_OFST (0)
|
||||
#define ALT_AVALON_I2C_TFR_CMD_FIFO_LVL_FIFO_DEPTH_MSK(cmdfifodepth) ((cmdfifodepth-1) << ALT_AVALON_I2C_TFR_CMD_FIFO_LVL_FIFO_DEPTH_OFST)
|
||||
|
||||
#define ALT_AVALON_I2C_RX_DATA_FIFO_LVL_REG 7
|
||||
#define IOADDR_ALT_AVALON_I2C_RX_DATA_FIFO_LVL(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_RX_DATA_FIFO_LVL_REG)
|
||||
#define IORD_ALT_AVALON_I2C_RX_DATA_FIFO_LVL(base) IORD(base, ALT_AVALON_I2C_RX_DATA_FIFO_LVL_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_RX_DATA_FIFO_LVL(base, data) IOWR(base, ALT_AVALON_I2C_RX_DATA_FIFO_LVL_REG, data)
|
||||
#define ALT_AVALON_I2C_RX_DATA_FIFO_LVL_FIFO_DEPTH_OFST (0)
|
||||
#define ALT_AVALON_I2C_RX_DATA_FIFO_LVL_FIFO_DEPTH_MSK(rxfifodepth) ((rxfifodepth-1) << ALT_AVALON_I2C_TFR_CMD_FIFO_LVL_FIFO_DEPTH_OFST)
|
||||
|
||||
#define ALT_AVALON_I2C_SCL_LOW_REG 8
|
||||
#define IOADDR_ALT_AVALON_I2C_SCL_LOW(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_SCL_LOW_REG)
|
||||
#define IORD_ALT_AVALON_I2C_SCL_LOW(base) IORD(base, ALT_AVALON_I2C_SCL_LOW_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_SCL_LOW(base, data) IOWR(base, ALT_AVALON_I2C_SCL_LOW_REG, data)
|
||||
#define ALT_AVALON_I2C_SCL_LOW_COUNT_PERIOD_OFST (0)
|
||||
#define ALT_AVALON_I2C_SCL_LOW_COUNT_PERIOD_MSK (0xffff << ALT_AVALON_I2C_SCL_LOW_COUNT_PERIOD_OFST)
|
||||
|
||||
#define ALT_AVALON_I2C_SCL_HIGH_REG 9
|
||||
#define IOADDR_ALT_AVALON_I2C_SCL_HIGH(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_SCL_HIGH_REG)
|
||||
#define IORD_ALT_AVALON_I2C_SCL_HIGH(base) IORD(base, ALT_AVALON_I2C_SCL_HIGH_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_SCL_HIGH(base, data) IOWR(base, ALT_AVALON_I2C_SCL_HIGH_REG, data)
|
||||
#define ALT_AVALON_I2C_SCL_HIGH_COUNT_PERIOD_OFST (0)
|
||||
#define ALT_AVALON_I2C_SCL_HIGH_COUNT_PERIOD_MSK (0xffff << ALT_AVALON_I2C_SCL_HIGH_COUNT_PERIOD_OFST)
|
||||
|
||||
#define ALT_AVALON_I2C_SDA_HOLD_REG 0xa
|
||||
#define IOADDR_ALT_AVALON_I2C_SDA_HOLD(base) __IO_CALC_ADDRESS_NATIVE(base, ALT_AVALON_I2C_SDA_HOLD_REG)
|
||||
#define IORD_ALT_AVALON_I2C_SDA_HOLD(base) IORD(base, ALT_AVALON_I2C_SDA_HOLD_REG)
|
||||
#define IOWR_ALT_AVALON_I2C_SDA_HOLD(base, data) IOWR(base, ALT_AVALON_I2C_SDA_HOLD_REG, data)
|
||||
#define ALT_AVALON_I2C_SDA_HOLD_COUNT_PERIOD_OFST (0)
|
||||
#define ALT_AVALON_I2C_SDA_HOLD_COUNT_PERIOD_MSK (0xffff << ALT_AVALON_I2C_SDA_HOLD_COUNT_PERIOD_OFST)
|
||||
|
||||
#endif /* __ALT_AVALON_I2C_REGS_H__ */
|
|
@ -1,196 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_AVALON_JTAG_UART_H__
|
||||
#define __ALT_AVALON_JTAG_UART_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "sys/alt_alarm.h"
|
||||
#include "sys/alt_warning.h"
|
||||
|
||||
#include "os/alt_sem.h"
|
||||
#include "os/alt_flag.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* If the user wants all drivers to be small rather than fast then make sure
|
||||
* this one is marked as needing to be small.
|
||||
*/
|
||||
#if defined ALT_USE_SMALL_DRIVERS && !defined ALTERA_AVALON_JTAG_UART_SMALL
|
||||
#define ALTERA_AVALON_JTAG_UART_SMALL
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If the user wants to ignore FIFO full error after timeout
|
||||
*/
|
||||
#if defined ALT_JTAG_UART_IGNORE_FIFO_FULL_ERROR && !defined ALTERA_AVALON_JTAG_UART_IGNORE_FIFO_FULL_ERROR
|
||||
#define ALTERA_AVALON_JTAG_UART_IGNORE_FIFO_FULL_ERROR
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Constants that can be overriden.
|
||||
*/
|
||||
#ifndef ALTERA_AVALON_JTAG_UART_DEFAULT_TIMEOUT
|
||||
#define ALTERA_AVALON_JTAG_UART_DEFAULT_TIMEOUT 10
|
||||
#endif
|
||||
|
||||
#ifndef ALTERA_AVALON_JTAG_UART_BUF_LEN
|
||||
#define ALTERA_AVALON_JTAG_UART_BUF_LEN 2048
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ALT_JTAG_UART_READ_RDY and ALT_JTAG_UART_WRITE_RDY are the bitmasks
|
||||
* that define uC/OS-II event flags that are releated to this device.
|
||||
*
|
||||
* ALT_JTAG_UART_READ_RDY indicates that there is read data in the buffer
|
||||
* ready to be processed. ALT_JTAG_UART_WRITE_RDY indicates that the transmitter is
|
||||
* ready for more data.
|
||||
*/
|
||||
#define ALT_JTAG_UART_READ_RDY 0x1
|
||||
#define ALT_JTAG_UART_WRITE_RDY 0x2
|
||||
#define ALT_JTAG_UART_TIMEOUT 0x4
|
||||
|
||||
/*
|
||||
* State structure definition. Each instance of the driver uses one
|
||||
* of these structures to hold its associated state.
|
||||
*/
|
||||
|
||||
typedef struct altera_avalon_jtag_uart_state_s
|
||||
{
|
||||
unsigned int base;
|
||||
|
||||
#ifndef ALTERA_AVALON_JTAG_UART_SMALL
|
||||
|
||||
unsigned int timeout; /* Timeout until host is assumed inactive */
|
||||
alt_alarm alarm;
|
||||
unsigned int irq_enable;
|
||||
unsigned int host_inactive;
|
||||
|
||||
ALT_SEM (read_lock)
|
||||
ALT_SEM (write_lock)
|
||||
ALT_FLAG_GRP (events)
|
||||
|
||||
/* The variables below are volatile because they are modified by the
|
||||
* interrupt routine. Making them volatile and reading them atomically
|
||||
* means that we don't need any large critical sections.
|
||||
*/
|
||||
volatile unsigned int rx_in;
|
||||
unsigned int rx_out;
|
||||
unsigned int tx_in;
|
||||
volatile unsigned int tx_out;
|
||||
char rx_buf[ALTERA_AVALON_JTAG_UART_BUF_LEN];
|
||||
char tx_buf[ALTERA_AVALON_JTAG_UART_BUF_LEN];
|
||||
|
||||
#endif /* !ALTERA_AVALON_JTAG_UART_SMALL */
|
||||
|
||||
} altera_avalon_jtag_uart_state;
|
||||
|
||||
/*
|
||||
* Macros used by alt_sys_init when the ALT file descriptor facility isn't used.
|
||||
*/
|
||||
|
||||
#ifdef ALTERA_AVALON_JTAG_UART_SMALL
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_STATE_INSTANCE(name, state) \
|
||||
altera_avalon_jtag_uart_state state = \
|
||||
{ \
|
||||
name##_BASE, \
|
||||
}
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_STATE_INIT(name, state)
|
||||
|
||||
#else /* !ALTERA_AVALON_JTAG_UART_SMALL */
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_STATE_INSTANCE(name, state) \
|
||||
altera_avalon_jtag_uart_state state = \
|
||||
{ \
|
||||
name##_BASE, \
|
||||
ALTERA_AVALON_JTAG_UART_DEFAULT_TIMEOUT, \
|
||||
}
|
||||
|
||||
/*
|
||||
* Externally referenced routines
|
||||
*/
|
||||
extern void altera_avalon_jtag_uart_init(altera_avalon_jtag_uart_state* sp,
|
||||
int irq_controller_id, int irq);
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_STATE_INIT(name, state) \
|
||||
{ \
|
||||
if (name##_IRQ == ALT_IRQ_NOT_CONNECTED) \
|
||||
{ \
|
||||
ALT_LINK_ERROR ("Error: Interrupt not connected for " #name ". " \
|
||||
"You have selected the interrupt driven version of " \
|
||||
"the ALTERA Avalon JTAG UART driver, but the " \
|
||||
"interrupt is not connected for this device. You can " \
|
||||
"select a polled mode driver by checking the 'small " \
|
||||
"driver' option in the HAL configuration window, or " \
|
||||
"by using the -DALTERA_AVALON_JTAG_UART_SMALL " \
|
||||
"preprocessor flag."); \
|
||||
} \
|
||||
else \
|
||||
altera_avalon_jtag_uart_init(&state, \
|
||||
name##_IRQ_INTERRUPT_CONTROLLER_ID, \
|
||||
name##_IRQ); \
|
||||
}
|
||||
|
||||
#endif /* ALTERA_AVALON_JTAG_UART_SMALL */
|
||||
|
||||
/*
|
||||
* Include in case non-direct version of driver required.
|
||||
*/
|
||||
#include "altera_avalon_jtag_uart_fd.h"
|
||||
|
||||
/*
|
||||
* Map alt_sys_init macros to direct or non-direct versions.
|
||||
*/
|
||||
#ifdef ALT_USE_DIRECT_DRIVERS
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_INSTANCE(name, state) \
|
||||
ALTERA_AVALON_JTAG_UART_STATE_INSTANCE(name, state)
|
||||
#define ALTERA_AVALON_JTAG_UART_INIT(name, state) \
|
||||
ALTERA_AVALON_JTAG_UART_STATE_INIT(name, state)
|
||||
|
||||
#else /* !ALT_USE_DIRECT_DRIVERS */
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_INSTANCE(name, dev) \
|
||||
ALTERA_AVALON_JTAG_UART_DEV_INSTANCE(name, dev)
|
||||
#define ALTERA_AVALON_JTAG_UART_INIT(name, dev) \
|
||||
ALTERA_AVALON_JTAG_UART_DEV_INIT(name, dev)
|
||||
|
||||
#endif /* ALT_USE_DIRECT_DRIVERS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_AVALON_JTAG_UART_H__ */
|
|
@ -1,123 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2007 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_AVALON_JTAG_UART_FD_H__
|
||||
#define __ALT_AVALON_JTAG_UART_FD_H__
|
||||
|
||||
#include "sys/alt_dev.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* Externally referenced routines
|
||||
*/
|
||||
extern int altera_avalon_jtag_uart_read_fd (alt_fd* fd, char* ptr, int len);
|
||||
extern int altera_avalon_jtag_uart_write_fd (alt_fd* fd, const char* ptr,
|
||||
int len);
|
||||
|
||||
/*
|
||||
* Device structure definition. This is needed by alt_sys_init in order to
|
||||
* reserve memory for the device instance.
|
||||
*/
|
||||
|
||||
typedef struct altera_avalon_jtag_uart_dev_s
|
||||
{
|
||||
alt_dev dev;
|
||||
altera_avalon_jtag_uart_state state;
|
||||
} altera_avalon_jtag_uart_dev;
|
||||
|
||||
/*
|
||||
* Macros used by alt_sys_init when the ALT file descriptor facility is used.
|
||||
*/
|
||||
|
||||
#ifdef ALTERA_AVALON_JTAG_UART_SMALL
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_DEV_INSTANCE(name, d) \
|
||||
static altera_avalon_jtag_uart_dev d = \
|
||||
{ \
|
||||
{ \
|
||||
ALT_LLIST_ENTRY, \
|
||||
name##_NAME, \
|
||||
NULL, /* open */ \
|
||||
NULL, /* close */ \
|
||||
altera_avalon_jtag_uart_read_fd, \
|
||||
altera_avalon_jtag_uart_write_fd, \
|
||||
NULL, /* lseek */ \
|
||||
NULL, /* fstat */ \
|
||||
NULL, /* ioctl */ \
|
||||
}, \
|
||||
{ \
|
||||
name##_BASE, \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_DEV_INIT(name, d) alt_dev_reg (&d.dev)
|
||||
|
||||
#else /* !ALTERA_AVALON_JTAG_UART_SMALL */
|
||||
|
||||
extern int altera_avalon_jtag_uart_close_fd(alt_fd* fd);
|
||||
extern int altera_avalon_jtag_uart_ioctl_fd (alt_fd* fd, int req, void* arg);
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_DEV_INSTANCE(name, d) \
|
||||
static altera_avalon_jtag_uart_dev d = \
|
||||
{ \
|
||||
{ \
|
||||
ALT_LLIST_ENTRY, \
|
||||
name##_NAME, \
|
||||
NULL, /* open */ \
|
||||
altera_avalon_jtag_uart_close_fd, \
|
||||
altera_avalon_jtag_uart_read_fd, \
|
||||
altera_avalon_jtag_uart_write_fd, \
|
||||
NULL, /* lseek */ \
|
||||
NULL, /* fstat */ \
|
||||
altera_avalon_jtag_uart_ioctl_fd, \
|
||||
}, \
|
||||
{ \
|
||||
name##_BASE, \
|
||||
ALTERA_AVALON_JTAG_UART_DEFAULT_TIMEOUT, \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_DEV_INIT(name, d) \
|
||||
{ \
|
||||
ALTERA_AVALON_JTAG_UART_STATE_INIT(name, d.state); \
|
||||
\
|
||||
/* make the device available to the system */ \
|
||||
alt_dev_reg(&d.dev); \
|
||||
}
|
||||
|
||||
#endif /* ALTERA_AVALON_JTAG_UART_SMALL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_AVALON_JTAG_UART_FD_H__ */
|
|
@ -1,7 +0,0 @@
|
|||
zephyr_sources(
|
||||
altera_avalon_jtag_uart_fd.c
|
||||
altera_avalon_jtag_uart_init.c
|
||||
altera_avalon_jtag_uart_ioctl.c
|
||||
altera_avalon_jtag_uart_read.c
|
||||
altera_avalon_jtag_uart_write.c
|
||||
)
|
|
@ -1,84 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2007 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "sys/alt_dev.h"
|
||||
#include "altera_avalon_jtag_uart.h"
|
||||
|
||||
extern int altera_avalon_jtag_uart_read(altera_avalon_jtag_uart_state* sp,
|
||||
char* buffer, int space, int flags);
|
||||
extern int altera_avalon_jtag_uart_write(altera_avalon_jtag_uart_state* sp,
|
||||
const char* ptr, int count, int flags);
|
||||
extern int altera_avalon_jtag_uart_ioctl(altera_avalon_jtag_uart_state* sp,
|
||||
int req, void* arg);
|
||||
extern int altera_avalon_jtag_uart_close(altera_avalon_jtag_uart_state* sp,
|
||||
int flags);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* --------------------- WRAPPERS FOR ALT FD SUPPORT --------------------- */
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
altera_avalon_jtag_uart_read_fd(alt_fd* fd, char* buffer, int space)
|
||||
{
|
||||
altera_avalon_jtag_uart_dev* dev = (altera_avalon_jtag_uart_dev*) fd->dev;
|
||||
|
||||
return altera_avalon_jtag_uart_read(&dev->state, buffer, space,
|
||||
fd->fd_flags);
|
||||
}
|
||||
|
||||
int
|
||||
altera_avalon_jtag_uart_write_fd(alt_fd* fd, const char* buffer, int space)
|
||||
{
|
||||
altera_avalon_jtag_uart_dev* dev = (altera_avalon_jtag_uart_dev*) fd->dev;
|
||||
|
||||
return altera_avalon_jtag_uart_write(&dev->state, buffer, space,
|
||||
fd->fd_flags);
|
||||
}
|
||||
|
||||
#ifndef ALTERA_AVALON_JTAG_UART_SMALL
|
||||
|
||||
int
|
||||
altera_avalon_jtag_uart_close_fd(alt_fd* fd)
|
||||
{
|
||||
altera_avalon_jtag_uart_dev* dev = (altera_avalon_jtag_uart_dev*) fd->dev;
|
||||
|
||||
return altera_avalon_jtag_uart_close(&dev->state, fd->fd_flags);
|
||||
}
|
||||
|
||||
int
|
||||
altera_avalon_jtag_uart_ioctl_fd(alt_fd* fd, int req, void* arg)
|
||||
{
|
||||
altera_avalon_jtag_uart_dev* dev = (altera_avalon_jtag_uart_dev*) fd->dev;
|
||||
|
||||
return altera_avalon_jtag_uart_ioctl(&dev->state, req, arg);
|
||||
}
|
||||
|
||||
#endif /* ALTERA_AVALON_JTAG_UART_SMALL */
|
|
@ -1,254 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2007 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sys/alt_irq.h"
|
||||
#include "sys/alt_alarm.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
#include "altera_avalon_jtag_uart_regs.h"
|
||||
#include "altera_avalon_jtag_uart.h"
|
||||
|
||||
#include "sys/alt_log_printf.h"
|
||||
|
||||
#ifndef ALTERA_AVALON_JTAG_UART_SMALL
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ------------------------- FAST DRIVER --------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
static void altera_avalon_jtag_uart_irq(void* context);
|
||||
#else
|
||||
static void altera_avalon_jtag_uart_irq(void* context, alt_u32 id);
|
||||
#endif
|
||||
static alt_u32 altera_avalon_jtag_uart_timeout(void* context);
|
||||
|
||||
/*
|
||||
* Driver initialization code. Register interrupts and start a timer
|
||||
* which we can use to check whether the host is there.
|
||||
* Return 1 on sucessful IRQ register and 0 on failure.
|
||||
*/
|
||||
|
||||
void altera_avalon_jtag_uart_init(altera_avalon_jtag_uart_state* sp,
|
||||
int irq_controller_id, int irq)
|
||||
{
|
||||
ALT_FLAG_CREATE(&sp->events, 0);
|
||||
ALT_SEM_CREATE(&sp->read_lock, 1);
|
||||
ALT_SEM_CREATE(&sp->write_lock, 1);
|
||||
|
||||
/* enable read interrupts at the device */
|
||||
sp->irq_enable = ALTERA_AVALON_JTAG_UART_CONTROL_RE_MSK;
|
||||
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_CONTROL(sp->base, sp->irq_enable);
|
||||
|
||||
/* register the interrupt handler */
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
alt_ic_isr_register(irq_controller_id, irq, altera_avalon_jtag_uart_irq,
|
||||
sp, NULL);
|
||||
#else
|
||||
alt_irq_register(irq, sp, altera_avalon_jtag_uart_irq);
|
||||
#endif
|
||||
|
||||
/* Register an alarm to go off every second to check for presence of host */
|
||||
sp->host_inactive = 0;
|
||||
|
||||
if (alt_alarm_start(&sp->alarm, alt_ticks_per_second(),
|
||||
&altera_avalon_jtag_uart_timeout, sp) < 0)
|
||||
{
|
||||
/* If we can't set the alarm then record "don't know if host present"
|
||||
* and behave as though the host is present.
|
||||
*/
|
||||
sp->timeout = INT_MAX;
|
||||
}
|
||||
|
||||
/* ALT_LOG - see altera_hal/HAL/inc/sys/alt_log_printf.h */
|
||||
ALT_LOG_JTAG_UART_ALARM_REGISTER(sp, sp->base);
|
||||
}
|
||||
|
||||
/*
|
||||
* Interrupt routine
|
||||
*/
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
static void altera_avalon_jtag_uart_irq(void* context)
|
||||
#else
|
||||
static void altera_avalon_jtag_uart_irq(void* context, alt_u32 id)
|
||||
#endif
|
||||
{
|
||||
altera_avalon_jtag_uart_state* sp = (altera_avalon_jtag_uart_state*) context;
|
||||
unsigned int base = sp->base;
|
||||
|
||||
/* ALT_LOG - see altera_hal/HAL/inc/sys/alt_log_printf.h */
|
||||
ALT_LOG_JTAG_UART_ISR_FUNCTION(base, sp);
|
||||
|
||||
for ( ; ; )
|
||||
{
|
||||
unsigned int control = IORD_ALTERA_AVALON_JTAG_UART_CONTROL(base);
|
||||
|
||||
/* Return once nothing more to do */
|
||||
if ((control & (ALTERA_AVALON_JTAG_UART_CONTROL_RI_MSK | ALTERA_AVALON_JTAG_UART_CONTROL_WI_MSK)) == 0)
|
||||
break;
|
||||
|
||||
if (control & ALTERA_AVALON_JTAG_UART_CONTROL_RI_MSK)
|
||||
{
|
||||
/* process a read irq. Start by assuming that there is data in the
|
||||
* receive FIFO (otherwise why would we have been interrupted?)
|
||||
*/
|
||||
unsigned int data = 1 << ALTERA_AVALON_JTAG_UART_DATA_RAVAIL_OFST;
|
||||
|
||||
for ( ; ; )
|
||||
{
|
||||
/* Check whether there is space in the buffer. If not then we must not
|
||||
* read any characters from the buffer as they will be lost.
|
||||
*/
|
||||
unsigned int next = (sp->rx_in + 1) % ALTERA_AVALON_JTAG_UART_BUF_LEN;
|
||||
if (next == sp->rx_out)
|
||||
break;
|
||||
|
||||
/* Try to remove a character from the FIFO and find out whether there
|
||||
* are any more characters remaining.
|
||||
*/
|
||||
data = IORD_ALTERA_AVALON_JTAG_UART_DATA(base);
|
||||
|
||||
if ((data & ALTERA_AVALON_JTAG_UART_DATA_RVALID_MSK) == 0)
|
||||
break;
|
||||
|
||||
sp->rx_buf[sp->rx_in] = (data & ALTERA_AVALON_JTAG_UART_DATA_DATA_MSK) >> ALTERA_AVALON_JTAG_UART_DATA_DATA_OFST;
|
||||
sp->rx_in = (sp->rx_in + 1) % ALTERA_AVALON_JTAG_UART_BUF_LEN;
|
||||
|
||||
/* Post an event to notify jtag_uart_read that a character has been read */
|
||||
ALT_FLAG_POST (sp->events, ALT_JTAG_UART_READ_RDY, OS_FLAG_SET);
|
||||
}
|
||||
|
||||
if (data & ALTERA_AVALON_JTAG_UART_DATA_RAVAIL_MSK)
|
||||
{
|
||||
/* If there is still data available here then the buffer is full
|
||||
* so turn off receive interrupts until some space becomes available.
|
||||
*/
|
||||
sp->irq_enable &= ~ALTERA_AVALON_JTAG_UART_CONTROL_RE_MSK;
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_CONTROL(base, sp->irq_enable);
|
||||
|
||||
/* Dummy read to ensure IRQ is cleared prior to ISR completion */
|
||||
IORD_ALTERA_AVALON_JTAG_UART_CONTROL(base);
|
||||
}
|
||||
}
|
||||
|
||||
if (control & ALTERA_AVALON_JTAG_UART_CONTROL_WI_MSK)
|
||||
{
|
||||
/* process a write irq */
|
||||
unsigned int space = (control & ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_MSK) >> ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_OFST;
|
||||
|
||||
while (space > 0 && sp->tx_out != sp->tx_in)
|
||||
{
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_DATA(base, sp->tx_buf[sp->tx_out]);
|
||||
|
||||
sp->tx_out = (sp->tx_out + 1) % ALTERA_AVALON_JTAG_UART_BUF_LEN;
|
||||
|
||||
/* Post an event to notify jtag_uart_write that a character has been written */
|
||||
ALT_FLAG_POST (sp->events, ALT_JTAG_UART_WRITE_RDY, OS_FLAG_SET);
|
||||
|
||||
space--;
|
||||
}
|
||||
|
||||
if (space > 0)
|
||||
{
|
||||
/* If we don't have any more data available then turn off the TX interrupt */
|
||||
sp->irq_enable &= ~ALTERA_AVALON_JTAG_UART_CONTROL_WE_MSK;
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_CONTROL(sp->base, sp->irq_enable);
|
||||
|
||||
/* Dummy read to ensure IRQ is cleared prior to ISR completion */
|
||||
IORD_ALTERA_AVALON_JTAG_UART_CONTROL(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Timeout routine is called every second
|
||||
*/
|
||||
|
||||
static alt_u32
|
||||
altera_avalon_jtag_uart_timeout(void* context)
|
||||
{
|
||||
altera_avalon_jtag_uart_state* sp = (altera_avalon_jtag_uart_state *) context;
|
||||
|
||||
unsigned int control = IORD_ALTERA_AVALON_JTAG_UART_CONTROL(sp->base);
|
||||
|
||||
if (control & ALTERA_AVALON_JTAG_UART_CONTROL_AC_MSK)
|
||||
{
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_CONTROL(sp->base, sp->irq_enable | ALTERA_AVALON_JTAG_UART_CONTROL_AC_MSK);
|
||||
sp->host_inactive = 0;
|
||||
}
|
||||
else if (sp->host_inactive < INT_MAX - 2) {
|
||||
sp->host_inactive++;
|
||||
|
||||
if (sp->host_inactive >= sp->timeout) {
|
||||
/* Post an event to indicate host is inactive (for jtag_uart_read */
|
||||
ALT_FLAG_POST (sp->events, ALT_JTAG_UART_TIMEOUT, OS_FLAG_SET);
|
||||
}
|
||||
}
|
||||
|
||||
return alt_ticks_per_second();
|
||||
}
|
||||
|
||||
/*
|
||||
* The close() routine is implemented to drain the JTAG UART transmit buffer
|
||||
* when not in "small" mode. This routine will wait for transimt data to be
|
||||
* emptied unless a timeout from host-activity occurs. If the driver flags
|
||||
* have been set to non-blocking mode, this routine will exit immediately if
|
||||
* any data remains. This routine should be called indirectly (i.e. though
|
||||
* the C library close() routine) so that the file descriptor associated
|
||||
* with the relevant stream (i.e. stdout) can be closed as well. This routine
|
||||
* does not manage file descriptors.
|
||||
*
|
||||
* The close routine is not implemented for the small driver; instead it will
|
||||
* map to null. This is because the small driver simply waits while characters
|
||||
* are transmitted; there is no interrupt-serviced buffer to empty
|
||||
*/
|
||||
int altera_avalon_jtag_uart_close(altera_avalon_jtag_uart_state* sp, int flags)
|
||||
{
|
||||
/*
|
||||
* Wait for all transmit data to be emptied by the JTAG UART ISR, or
|
||||
* for a host-inactivity timeout, in which case transmit data will be lost
|
||||
*/
|
||||
while ( (sp->tx_out != sp->tx_in) && (sp->host_inactive < sp->timeout) ) {
|
||||
if (flags & O_NONBLOCK) {
|
||||
return -EWOULDBLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !ALTERA_AVALON_JTAG_UART_SMALL */
|
|
@ -1,84 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sys/ioctl.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
#include "altera_avalon_jtag_uart_regs.h"
|
||||
#include "altera_avalon_jtag_uart.h"
|
||||
|
||||
#include "sys/alt_log_printf.h"
|
||||
|
||||
#ifndef ALTERA_AVALON_JTAG_UART_SMALL
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ------------------------- FAST DRIVER --------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
int
|
||||
altera_avalon_jtag_uart_ioctl(altera_avalon_jtag_uart_state* sp, int req,
|
||||
void* arg)
|
||||
{
|
||||
int rc = -ENOTTY;
|
||||
|
||||
switch (req)
|
||||
{
|
||||
case TIOCSTIMEOUT:
|
||||
/* Set the time to wait until assuming host is not connected */
|
||||
if (sp->timeout != INT_MAX)
|
||||
{
|
||||
int timeout = *((int *)arg);
|
||||
sp->timeout = (timeout >= 2 && timeout < INT_MAX) ? timeout : INT_MAX - 1;
|
||||
rc = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case TIOCGCONNECTED:
|
||||
/* Find out whether host is connected */
|
||||
if (sp->timeout != INT_MAX)
|
||||
{
|
||||
*((int *)arg) = (sp->host_inactive < sp->timeout) ? 1 : 0;
|
||||
rc = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* !ALTERA_AVALON_JTAG_UART_SMALL */
|
|
@ -1,203 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sys/alt_irq.h"
|
||||
#include "sys/alt_alarm.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
#include "altera_avalon_jtag_uart_regs.h"
|
||||
#include "altera_avalon_jtag_uart.h"
|
||||
|
||||
#include "sys/alt_log_printf.h"
|
||||
|
||||
#ifdef __ucosii__
|
||||
#include "includes.h"
|
||||
#endif /* __ucosii__ */
|
||||
|
||||
#ifdef ALTERA_AVALON_JTAG_UART_SMALL
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ----------------------- SMALL DRIVER ---------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/* Read routine. The small version blocks until it has at least one byte
|
||||
* available, it then returns as much as is immediately available without
|
||||
* waiting any more. It's performance will be very poor without
|
||||
* interrupts.
|
||||
*/
|
||||
|
||||
int
|
||||
altera_avalon_jtag_uart_read(altera_avalon_jtag_uart_state* sp,
|
||||
char* buffer, int space, int flags)
|
||||
{
|
||||
unsigned int base = sp->base;
|
||||
|
||||
char * ptr = buffer;
|
||||
char * end = buffer + space;
|
||||
|
||||
while (ptr < end)
|
||||
{
|
||||
unsigned int data = IORD_ALTERA_AVALON_JTAG_UART_DATA(base);
|
||||
|
||||
if (data & ALTERA_AVALON_JTAG_UART_DATA_RVALID_MSK)
|
||||
*ptr++ = (data & ALTERA_AVALON_JTAG_UART_DATA_DATA_MSK) >> ALTERA_AVALON_JTAG_UART_DATA_DATA_OFST;
|
||||
else if (ptr != buffer)
|
||||
break;
|
||||
else if(flags & O_NONBLOCK)
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (ptr != buffer)
|
||||
return ptr - buffer;
|
||||
else if (flags & O_NONBLOCK)
|
||||
return -EWOULDBLOCK;
|
||||
else
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
#else /* !ALTERA_AVALON_JTAG_UART_SMALL */
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ----------------------- FAST DRIVER ----------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
int
|
||||
altera_avalon_jtag_uart_read(altera_avalon_jtag_uart_state* sp,
|
||||
char * buffer, int space, int flags)
|
||||
{
|
||||
char * ptr = buffer;
|
||||
|
||||
alt_irq_context context;
|
||||
unsigned int n;
|
||||
|
||||
/*
|
||||
* When running in a multi threaded environment, obtain the "read_lock"
|
||||
* semaphore. This ensures that reading from the device is thread-safe.
|
||||
*/
|
||||
ALT_SEM_PEND (sp->read_lock, 0);
|
||||
|
||||
while (space > 0)
|
||||
{
|
||||
unsigned int in, out;
|
||||
|
||||
/* Read as much data as possible */
|
||||
do
|
||||
{
|
||||
in = sp->rx_in;
|
||||
out = sp->rx_out;
|
||||
|
||||
if (in >= out)
|
||||
n = in - out;
|
||||
else
|
||||
n = ALTERA_AVALON_JTAG_UART_BUF_LEN - out;
|
||||
|
||||
if (n == 0)
|
||||
break; /* No more data available */
|
||||
|
||||
if (n > space)
|
||||
n = space;
|
||||
|
||||
memcpy(ptr, sp->rx_buf + out, n);
|
||||
ptr += n;
|
||||
space -= n;
|
||||
|
||||
sp->rx_out = (out + n) % ALTERA_AVALON_JTAG_UART_BUF_LEN;
|
||||
}
|
||||
while (space > 0);
|
||||
|
||||
/* If we read any data then return it */
|
||||
if (ptr != buffer)
|
||||
break;
|
||||
|
||||
/* If in non-blocking mode then return error */
|
||||
if (flags & O_NONBLOCK)
|
||||
break;
|
||||
|
||||
#ifdef __ucosii__
|
||||
/* OS Present: Pend on a flag if the OS is running, otherwise spin */
|
||||
if(OSRunning == OS_TRUE) {
|
||||
/*
|
||||
* When running in a multi-threaded mode, we pend on the read event
|
||||
* flag set and timeout event flag set in the isr. This avoids wasting CPU
|
||||
* cycles waiting in this thread, when we could be doing something more
|
||||
* profitable elsewhere.
|
||||
*/
|
||||
ALT_FLAG_PEND (sp->events,
|
||||
ALT_JTAG_UART_READ_RDY | ALT_JTAG_UART_TIMEOUT,
|
||||
OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME,
|
||||
0);
|
||||
}
|
||||
else {
|
||||
/* Spin until more data arrives or until host disconnects */
|
||||
while (in == sp->rx_in && sp->host_inactive < sp->timeout)
|
||||
;
|
||||
}
|
||||
#else
|
||||
/* No OS: Always spin */
|
||||
while (in == sp->rx_in && sp->host_inactive < sp->timeout)
|
||||
;
|
||||
#endif /* __ucosii__ */
|
||||
|
||||
if (in == sp->rx_in)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now that access to the circular buffer is complete, release the read
|
||||
* semaphore so that other threads can access the buffer.
|
||||
*/
|
||||
|
||||
ALT_SEM_POST (sp->read_lock);
|
||||
|
||||
if (ptr != buffer)
|
||||
{
|
||||
/* If we read any data then there is space in the buffer so enable interrupts */
|
||||
context = alt_irq_disable_all();
|
||||
sp->irq_enable |= ALTERA_AVALON_JTAG_UART_CONTROL_RE_MSK;
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_CONTROL(sp->base, sp->irq_enable);
|
||||
alt_irq_enable_all(context);
|
||||
}
|
||||
|
||||
if (ptr != buffer)
|
||||
return ptr - buffer;
|
||||
else if (flags & O_NONBLOCK)
|
||||
return -EWOULDBLOCK;
|
||||
else
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
#endif /* ALTERA_AVALON_JTAG_UART_SMALL */
|
|
@ -1,215 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sys/alt_irq.h"
|
||||
#include "sys/alt_alarm.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
#include "altera_avalon_jtag_uart_regs.h"
|
||||
#include "altera_avalon_jtag_uart.h"
|
||||
|
||||
#include "sys/alt_log_printf.h"
|
||||
|
||||
#ifdef __ucosii__
|
||||
#include "includes.h"
|
||||
#endif /* __ucosii__ */
|
||||
|
||||
#ifdef ALTERA_AVALON_JTAG_UART_SMALL
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ------------------------ SMALL DRIVER --------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/* Write routine. The small version blocks when there is no space to write
|
||||
* into, so it's performance will be very bad if you are writing more than
|
||||
* one FIFOs worth of data. But you said you didn't want to use interrupts :-)
|
||||
*/
|
||||
|
||||
int altera_avalon_jtag_uart_write(altera_avalon_jtag_uart_state* sp,
|
||||
const char * ptr, int count, int flags)
|
||||
{
|
||||
unsigned int base = sp->base;
|
||||
|
||||
const char * end = ptr + count;
|
||||
|
||||
while (ptr < end)
|
||||
if ((IORD_ALTERA_AVALON_JTAG_UART_CONTROL(base) & ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_MSK) != 0)
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_DATA(base, *ptr++);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
#else /* !ALTERA_AVALON_JTAG_UART_SMALL */
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ------------------------- FAST DRIVER --------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
int
|
||||
altera_avalon_jtag_uart_write(altera_avalon_jtag_uart_state* sp,
|
||||
const char * ptr, int count, int flags)
|
||||
{
|
||||
/* Remove warning at optimisation level 03 by seting out to 0 */
|
||||
unsigned int in, out=0;
|
||||
unsigned int n;
|
||||
alt_irq_context context;
|
||||
|
||||
const char * start = ptr;
|
||||
|
||||
/*
|
||||
* When running in a multi threaded environment, obtain the "write_lock"
|
||||
* semaphore. This ensures that writing to the device is thread-safe.
|
||||
*/
|
||||
ALT_SEM_PEND (sp->write_lock, 0);
|
||||
|
||||
do
|
||||
{
|
||||
/* Copy as much as we can into the transmit buffer */
|
||||
while (count > 0)
|
||||
{
|
||||
/* We need a stable value of the out pointer to calculate the space available */
|
||||
in = sp->tx_in;
|
||||
out = sp->tx_out;
|
||||
|
||||
if (in < out)
|
||||
n = out - 1 - in;
|
||||
else if (out > 0)
|
||||
n = ALTERA_AVALON_JTAG_UART_BUF_LEN - in;
|
||||
else
|
||||
n = ALTERA_AVALON_JTAG_UART_BUF_LEN - 1 - in;
|
||||
|
||||
if (n == 0)
|
||||
break;
|
||||
|
||||
if (n > count)
|
||||
n = count;
|
||||
|
||||
memcpy(sp->tx_buf + in, ptr, n);
|
||||
ptr += n;
|
||||
count -= n;
|
||||
|
||||
sp->tx_in = (in + n) % ALTERA_AVALON_JTAG_UART_BUF_LEN;
|
||||
}
|
||||
|
||||
/*
|
||||
* If interrupts are disabled then we could transmit here, we only need
|
||||
* to enable interrupts if there is no space left in the FIFO
|
||||
*
|
||||
* For now kick the interrupt routine every time to make it transmit
|
||||
* the data
|
||||
*/
|
||||
context = alt_irq_disable_all();
|
||||
sp->irq_enable |= ALTERA_AVALON_JTAG_UART_CONTROL_WE_MSK;
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_CONTROL(sp->base, sp->irq_enable);
|
||||
alt_irq_enable_all(context);
|
||||
|
||||
/*
|
||||
* If there is any data left then either return now or block until
|
||||
* some has been sent
|
||||
*/
|
||||
/* consider: test whether there is anything there while doing this and delay for at most 2s. */
|
||||
if (count > 0)
|
||||
{
|
||||
if (flags & O_NONBLOCK)
|
||||
break;
|
||||
|
||||
#ifdef __ucosii__
|
||||
/* OS Present: Pend on a flag if the OS is running, otherwise spin */
|
||||
if(OSRunning == OS_TRUE) {
|
||||
/*
|
||||
* When running in a multi-threaded mode, we pend on the write event
|
||||
* flag set or the timeout flag in the isr. This avoids wasting CPU
|
||||
* cycles waiting in this thread, when we could be doing something
|
||||
* more profitable elsewhere.
|
||||
*/
|
||||
#ifdef ALTERA_AVALON_JTAG_UART_IGNORE_FIFO_FULL_ERROR
|
||||
if(!sp->host_inactive)
|
||||
#endif
|
||||
ALT_FLAG_PEND (sp->events,
|
||||
ALT_JTAG_UART_WRITE_RDY | ALT_JTAG_UART_TIMEOUT,
|
||||
OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME,
|
||||
0);
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* OS not running: Wait for data to be removed from buffer.
|
||||
* Once the interrupt routine has removed some data then we
|
||||
* will be able to insert some more.
|
||||
*/
|
||||
while (out == sp->tx_out && sp->host_inactive < sp->timeout)
|
||||
;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* No OS present: Always wait for data to be removed from buffer. Once
|
||||
* the interrupt routine has removed some data then we will be able to
|
||||
* insert some more.
|
||||
*/
|
||||
while (out == sp->tx_out && sp->host_inactive < sp->timeout)
|
||||
;
|
||||
#endif /* __ucosii__ */
|
||||
|
||||
if (sp->host_inactive)
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (count > 0);
|
||||
|
||||
/*
|
||||
* Now that access to the circular buffer is complete, release the write
|
||||
* semaphore so that other threads can access the buffer.
|
||||
*/
|
||||
ALT_SEM_POST (sp->write_lock);
|
||||
|
||||
if (ptr != start)
|
||||
return ptr - start;
|
||||
else if (flags & O_NONBLOCK)
|
||||
return -EWOULDBLOCK;
|
||||
#ifdef ALTERA_AVALON_JTAG_UART_IGNORE_FIFO_FULL_ERROR
|
||||
else if (sp->host_inactive >= sp->timeout) {
|
||||
/*
|
||||
* Reset the software FIFO, hardware FIFO could not be reset.
|
||||
* Just throw away characters without reporting error.
|
||||
*/
|
||||
sp->tx_out = sp->tx_in = 0;
|
||||
return ptr - start + count;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
return -EIO; /* Host not connected */
|
||||
}
|
||||
|
||||
#endif /* ALTERA_AVALON_JTAG_UART_SMALL */
|
|
@ -1,34 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2010 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_AVALON_JTAG_UART_LWHAL_H__
|
||||
#define __ALT_AVALON_JTAG_UART_LWHAL_H__
|
||||
|
||||
extern void altera_avalon_jtag_uart_lwhal_putchar(void *base, int character);
|
||||
|
||||
#endif /* __ALT_AVALON_JTAG_UART_LWHAL_H__ */
|
|
@ -1 +0,0 @@
|
|||
zephyr_sources(altera_avalon_jtag_uart_lwhal_putchar.c)
|
|
@ -1,54 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2010 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "altera_avalon_jtag_uart_regs.h"
|
||||
#include "altera_avalon_jtag_uart_lwhal.h"
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
/** @Function Description: Writes a single character to the JTAG UART.
|
||||
* @API Type: External
|
||||
* @param base JTAG UART base address
|
||||
* @param character Character to be written
|
||||
* @return None
|
||||
*
|
||||
*/
|
||||
void altera_avalon_jtag_uart_lwhal_putchar(void *base, int character)
|
||||
{
|
||||
do {
|
||||
if ((IORD_ALTERA_AVALON_JTAG_UART_CONTROL(base) & ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_MSK) != 0)
|
||||
{
|
||||
IOWR_ALTERA_AVALON_JTAG_UART_DATA(base, (character & 0xff));
|
||||
return;
|
||||
}
|
||||
}while(1);
|
||||
|
||||
return;
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_AVALON_JTAG_UART_REGS_H__
|
||||
#define __ALTERA_AVALON_JTAG_UART_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_DATA_REG 0
|
||||
#define IOADDR_ALTERA_AVALON_JTAG_UART_DATA(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_JTAG_UART_DATA_REG)
|
||||
#define IORD_ALTERA_AVALON_JTAG_UART_DATA(base) \
|
||||
IORD(base, ALTERA_AVALON_JTAG_UART_DATA_REG)
|
||||
#define IOWR_ALTERA_AVALON_JTAG_UART_DATA(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_JTAG_UART_DATA_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_DATA_DATA_MSK (0x000000FF)
|
||||
#define ALTERA_AVALON_JTAG_UART_DATA_DATA_OFST (0)
|
||||
#define ALTERA_AVALON_JTAG_UART_DATA_RVALID_MSK (0x00008000)
|
||||
#define ALTERA_AVALON_JTAG_UART_DATA_RVALID_OFST (15)
|
||||
#define ALTERA_AVALON_JTAG_UART_DATA_RAVAIL_MSK (0xFFFF0000)
|
||||
#define ALTERA_AVALON_JTAG_UART_DATA_RAVAIL_OFST (16)
|
||||
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_REG 1
|
||||
#define IOADDR_ALTERA_AVALON_JTAG_UART_CONTROL(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_JTAG_UART_CONTROL_REG)
|
||||
#define IORD_ALTERA_AVALON_JTAG_UART_CONTROL(base) \
|
||||
IORD(base, ALTERA_AVALON_JTAG_UART_CONTROL_REG)
|
||||
#define IOWR_ALTERA_AVALON_JTAG_UART_CONTROL(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_JTAG_UART_CONTROL_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_RE_MSK (0x00000001)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_RE_OFST (0)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_WE_MSK (0x00000002)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_WE_OFST (1)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_RI_MSK (0x00000100)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_RI_OFST (8)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_WI_MSK (0x00000200)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_WI_OFST (9)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_AC_MSK (0x00000400)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_AC_OFST (10)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_MSK (0xFFFF0000)
|
||||
#define ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_OFST (16)
|
||||
|
||||
#endif /* __ALTERA_AVALON_JTAG_UART_REGS_H__ */
|
|
@ -1,65 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_AVALON_PIO_REGS_H__
|
||||
#define __ALTERA_AVALON_PIO_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_PIO_DATA(base) __IO_CALC_ADDRESS_NATIVE(base, 0)
|
||||
#define IORD_ALTERA_AVALON_PIO_DATA(base) IORD(base, 0)
|
||||
#define IOWR_ALTERA_AVALON_PIO_DATA(base, data) IOWR(base, 0, data)
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_PIO_DIRECTION(base) __IO_CALC_ADDRESS_NATIVE(base, 1)
|
||||
#define IORD_ALTERA_AVALON_PIO_DIRECTION(base) IORD(base, 1)
|
||||
#define IOWR_ALTERA_AVALON_PIO_DIRECTION(base, data) IOWR(base, 1, data)
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_PIO_IRQ_MASK(base) __IO_CALC_ADDRESS_NATIVE(base, 2)
|
||||
#define IORD_ALTERA_AVALON_PIO_IRQ_MASK(base) IORD(base, 2)
|
||||
#define IOWR_ALTERA_AVALON_PIO_IRQ_MASK(base, data) IOWR(base, 2, data)
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_PIO_EDGE_CAP(base) __IO_CALC_ADDRESS_NATIVE(base, 3)
|
||||
#define IORD_ALTERA_AVALON_PIO_EDGE_CAP(base) IORD(base, 3)
|
||||
#define IOWR_ALTERA_AVALON_PIO_EDGE_CAP(base, data) IOWR(base, 3, data)
|
||||
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_PIO_SET_BIT(base) __IO_CALC_ADDRESS_NATIVE(base, 4)
|
||||
#define IORD_ALTERA_AVALON_PIO_SET_BITS(base) IORD(base, 4)
|
||||
#define IOWR_ALTERA_AVALON_PIO_SET_BITS(base, data) IOWR(base, 4, data)
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_PIO_CLEAR_BITS(base) __IO_CALC_ADDRESS_NATIVE(base, 5)
|
||||
#define IORD_ALTERA_AVALON_PIO_CLEAR_BITS(base) IORD(base, 5)
|
||||
#define IOWR_ALTERA_AVALON_PIO_CLEAR_BITS(base, data) IOWR(base, 5, data)
|
||||
|
||||
|
||||
|
||||
/* Defintions for direction-register operation with bi-directional PIOs */
|
||||
#define ALTERA_AVALON_PIO_DIRECTION_INPUT 0
|
||||
#define ALTERA_AVALON_PIO_DIRECTION_OUTPUT 1
|
||||
|
||||
#endif /* __ALTERA_AVALON_PIO_REGS_H__ */
|
|
@ -1,230 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2011 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_AVALON_SGDMA_H__
|
||||
#define __ALTERA_AVALON_SGDMA_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sys/alt_dev.h"
|
||||
#include "alt_types.h"
|
||||
#include "altera_avalon_sgdma_descriptor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* The function alt_find_dev() is used to search the device list "list" to
|
||||
* locate a device named "name". If a match is found, then a pointer to the
|
||||
* device is returned, otherwise NULL is returned.
|
||||
*/
|
||||
extern alt_dev* alt_find_dev (const char* name, alt_llist* list);
|
||||
|
||||
/* Callback routine type definition */
|
||||
typedef void (*alt_avalon_sgdma_callback)(void *context);
|
||||
|
||||
/* SGDMA Device Structure */
|
||||
typedef struct alt_sgdma_dev
|
||||
{
|
||||
alt_llist llist; // Device linked-list entry
|
||||
const char *name; // Name of SGDMA in SOPC System
|
||||
void *base; // Base address of SGDMA
|
||||
alt_u32 *descriptor_base; // reserved
|
||||
alt_u32 next_index; // reserved
|
||||
alt_u32 num_descriptors; // reserved
|
||||
alt_sgdma_descriptor *current_descriptor; // reserved
|
||||
alt_sgdma_descriptor *next_descriptor; // reserved
|
||||
alt_avalon_sgdma_callback callback; // Callback routine pointer
|
||||
void *callback_context; // Callback context pointer
|
||||
alt_u32 chain_control; // Value OR'd into control reg
|
||||
} alt_sgdma_dev;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Public API
|
||||
******************************************************************************/
|
||||
|
||||
/* API for "application managed" operation */
|
||||
int alt_avalon_sgdma_do_async_transfer(
|
||||
alt_sgdma_dev *dev,
|
||||
alt_sgdma_descriptor *desc);
|
||||
|
||||
alt_u8 alt_avalon_sgdma_do_sync_transfer(
|
||||
alt_sgdma_dev *dev,
|
||||
alt_sgdma_descriptor *desc);
|
||||
|
||||
void alt_avalon_sgdma_construct_mem_to_mem_desc(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length,
|
||||
int read_fixed,
|
||||
int write_fixed);
|
||||
|
||||
void alt_avalon_sgdma_construct_mem_to_mem_desc_burst(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length,
|
||||
int read_fixed,
|
||||
int write_fixed,
|
||||
int read_burst,
|
||||
int write_burst);
|
||||
|
||||
void alt_avalon_sgdma_construct_stream_to_mem_desc(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length_or_eop,
|
||||
int write_fixed);
|
||||
|
||||
void alt_avalon_sgdma_construct_stream_to_mem_desc_burst(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length_or_eop,
|
||||
int write_fixed,
|
||||
int write_burst);
|
||||
|
||||
void alt_avalon_sgdma_construct_mem_to_stream_desc(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u16 length,
|
||||
int read_fixed,
|
||||
int generate_sop,
|
||||
int generate_eop,
|
||||
alt_u8 atlantic_channel);
|
||||
|
||||
void alt_avalon_sgdma_construct_mem_to_stream_desc_burst(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u16 length,
|
||||
int read_fixed,
|
||||
int generate_sop,
|
||||
int generate_eop,
|
||||
int read_burst,
|
||||
alt_u8 atlantic_channel);
|
||||
|
||||
void alt_avalon_sgdma_register_callback(
|
||||
alt_sgdma_dev *dev,
|
||||
alt_avalon_sgdma_callback callback,
|
||||
alt_u32 chain_control,
|
||||
void *context);
|
||||
|
||||
void alt_avalon_sgdma_start(alt_sgdma_dev *dev);
|
||||
|
||||
void alt_avalon_sgdma_stop(alt_sgdma_dev *dev);
|
||||
|
||||
int alt_avalon_sgdma_check_descriptor_status(alt_sgdma_descriptor *desc);
|
||||
|
||||
alt_sgdma_dev* alt_avalon_sgdma_open (const char* name);
|
||||
|
||||
void alt_avalon_sgdma_enable_desc_poll(alt_sgdma_dev *dev, alt_u32 frequency);
|
||||
|
||||
void alt_avalon_sgdma_disable_desc_poll(alt_sgdma_dev *dev);
|
||||
|
||||
/* Private API */
|
||||
void alt_avalon_sgdma_construct_descriptor(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length_or_eop,
|
||||
int generate_eop,
|
||||
int read_fixed,
|
||||
int write_fixed_or_sop,
|
||||
alt_u8 atlantic_channel);
|
||||
|
||||
/* Private API */
|
||||
void alt_avalon_sgdma_construct_descriptor_burst(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length_or_eop,
|
||||
int generate_eop,
|
||||
int read_fixed,
|
||||
int write_fixed_or_sop,
|
||||
int read_burst,
|
||||
int write_burst,
|
||||
alt_u8 atlantic_channel);
|
||||
|
||||
void alt_avalon_sgdma_init (alt_sgdma_dev *dev, alt_u32 ic_id, alt_u32 irq);
|
||||
|
||||
/* HAL initialization macros */
|
||||
|
||||
/*
|
||||
* ALTERA_AVALON_SGDMA_INSTANCE is the macro used by alt_sys_init() to
|
||||
* allocate any per device memory that may be required.
|
||||
*/
|
||||
#define ALTERA_AVALON_SGDMA_INSTANCE(name, dev) \
|
||||
static alt_sgdma_dev dev = \
|
||||
{ \
|
||||
ALT_LLIST_ENTRY, \
|
||||
name##_NAME, \
|
||||
((void *)(name##_BASE)), \
|
||||
((alt_u32 *) 0x0), \
|
||||
((alt_u32) 0x0), \
|
||||
((alt_u32) 0x0), \
|
||||
((alt_sgdma_descriptor *) 0x0), \
|
||||
((alt_sgdma_descriptor *) 0x0), \
|
||||
((void *) 0x0), \
|
||||
((void *) 0x0), \
|
||||
((alt_u16) 0x0) \
|
||||
};
|
||||
|
||||
/*
|
||||
* The macro ALTERA_AVALON_SGDMA_INIT is called by the auto-generated function
|
||||
* alt_sys_init() to initialize a given device instance.
|
||||
*/
|
||||
#define ALTERA_AVALON_SGDMA_INIT(name, dev) \
|
||||
if (name##_IRQ == ALT_IRQ_NOT_CONNECTED) \
|
||||
{ \
|
||||
ALT_LINK_ERROR ("Error: Interrupt not connected for " #dev ". " \
|
||||
"The Altera Avalon Scatter-Gather DMA driver requires " \
|
||||
"that an interrupt is connected. Please select an IRQ " \
|
||||
"for this device in SOPC builder."); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
alt_avalon_sgdma_init(&dev, name##_IRQ_INTERRUPT_CONTROLLER_ID, \
|
||||
name##_IRQ); \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALTERA_AVALON_SGDMA_H__ */
|
|
@ -1,115 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
#ifndef __ALTERA_AVALON_SGDMA_DESCRIPTOR_H__
|
||||
#define __ALTERA_AVALON_SGDMA_DESCRIPTOR_H__
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
/* Each Scatter-gather DMA buffer descriptor spans 0x20 of memory */
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_SIZE (0x20)
|
||||
|
||||
|
||||
/*
|
||||
* Descriptor control bit masks & offsets
|
||||
*
|
||||
* Note: The control byte physically occupies bits [31:24] in memory.
|
||||
* The following bit-offsets are expressed relative to the LSB of
|
||||
* the control register bitfield.
|
||||
*/
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_GENERATE_EOP_MSK (0x1)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_GENERATE_EOP_OFST (0)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_READ_FIXED_ADDRESS_MSK (0x2)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_READ_FIXED_ADDRESS_OFST (1)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_WRITE_FIXED_ADDRESS_MSK (0x4)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_WRITE_FIXED_ADDRESS_OFST (2)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_ATLANTIC_CHANNEL_MSK (0x8)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_ATLANTIC_CHANNEL_OFST (3)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK (0x80)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_OFST (7)
|
||||
|
||||
/*
|
||||
* Descriptor status bit masks & offsets
|
||||
*
|
||||
* Note: The status byte physically occupies bits [23:16] in memory.
|
||||
* The following bit-offsets are expressed relative to the LSB of
|
||||
* the status register bitfield.
|
||||
*/
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_CRC_MSK (0x1)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_CRC_OFST (0)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_PARITY_MSK (0x2)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_PARITY_OFST (1)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_OVERFLOW_MSK (0x4)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_OVERFLOW_OFST (2)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_SYNC_MSK (0x8)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_SYNC_OFST (3)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_UEOP_MSK (0x10)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_UEOP_OFST (4)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_MEOP_MSK (0x20)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_MEOP_OFST (5)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_MSOP_MSK (0x40)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_MSOP_OFST (6)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_TERMINATED_BY_EOP_MSK (0x80)
|
||||
#define ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_TERMINATED_BY_EOP_OFST (7)
|
||||
|
||||
/*
|
||||
* To ensure that a descriptor is created without spaces
|
||||
* between the struct members, we call upon GCC's ability
|
||||
* to pack to a byte-aligned boundary.
|
||||
*/
|
||||
#define alt_avalon_sgdma_packed __attribute__ ((packed,aligned(1)))
|
||||
|
||||
/*
|
||||
* Buffer Descriptor data structure
|
||||
*
|
||||
* The SGDMA controller buffer descriptor allocates
|
||||
* 64 bits for each address. To support ANSI C, the
|
||||
* struct implementing a descriptor places 32-bits
|
||||
* of padding directly above each address; each pad must
|
||||
* be cleared when initializing a descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
alt_u32 *read_addr;
|
||||
alt_u32 read_addr_pad;
|
||||
|
||||
alt_u32 *write_addr;
|
||||
alt_u32 write_addr_pad;
|
||||
|
||||
alt_u32 *next;
|
||||
alt_u32 next_pad;
|
||||
|
||||
alt_u16 bytes_to_transfer;
|
||||
alt_u8 read_burst;
|
||||
alt_u8 write_burst;
|
||||
|
||||
alt_u16 actual_bytes_transferred;
|
||||
alt_u8 status;
|
||||
alt_u8 control;
|
||||
|
||||
} alt_avalon_sgdma_packed alt_sgdma_descriptor;
|
||||
|
||||
#endif /* __ALTERA_AVALON_SGDMA_DESCRIPTOR_H__ */
|
|
@ -1 +0,0 @@
|
|||
zephyr_sources(altera_avalon_sgdma.c)
|
|
@ -1,798 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2011 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* Altera HAL driver suitable for Nios II to drive the altera_avalon_sgdma
|
||||
* controller.
|
||||
*
|
||||
* The routines contained in this file are intended for developers who
|
||||
* wish to manage descriptors in their own application code. No facility
|
||||
* for automatic descriptor buffer management is provided. Use this API if
|
||||
* you want to:
|
||||
* - Construct your own descriptors or descriptor chains in your
|
||||
* application code
|
||||
* - Use the SGDMA controller for simple "one off" transfers or for
|
||||
* chains of transfers that you setup manually.
|
||||
*
|
||||
* Author: JRK
|
||||
*/
|
||||
|
||||
#include "io.h"
|
||||
#include "sys/alt_irq.h"
|
||||
#include "sys/alt_errno.h"
|
||||
#include "sys/alt_cache.h"
|
||||
|
||||
#include "altera_avalon_sgdma.h"
|
||||
#include "altera_avalon_sgdma_regs.h"
|
||||
|
||||
/* The list of registered SGDMA components */
|
||||
ALT_LLIST_HEAD(alt_sgdma_list);
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_do_async_transfer
|
||||
*
|
||||
* Set up and commence a non-blocking transfer of one of more
|
||||
* descriptors (or descriptor chain).
|
||||
*
|
||||
* If the SGDMA controller is busy at the time of this call, the
|
||||
* routine will immediately reutrn -EBUSY; the application can then
|
||||
* decide how to proceed without being blocked.
|
||||
*
|
||||
* If a callback routine has been previously registered with this
|
||||
* particular SGDMA controller, the transfer will be set up to
|
||||
* issue an interrupt on error, EOP, or chain completion. Otherwise,
|
||||
* no interrupt is registered, and it is the responsibility of the
|
||||
* aplication developer to check for and suitably handle errors
|
||||
* and completion.
|
||||
*
|
||||
* Arguments:
|
||||
* - *dev: Pointer to SGDMA device (instance) struct.
|
||||
* - *desc: Pointer to single (ready to run) descriptor. The descriptor
|
||||
* is expected to have its "next" descriptor field initialized either
|
||||
* to a non-ready descriptor, or to the next in a chain.
|
||||
*
|
||||
* Returns:
|
||||
* - 0 for success, or various errors defined in <errno.h>
|
||||
*/
|
||||
int alt_avalon_sgdma_do_async_transfer(
|
||||
alt_sgdma_dev *dev,
|
||||
alt_sgdma_descriptor *desc)
|
||||
{
|
||||
alt_u32 control;
|
||||
|
||||
/* Return with error immediately if controller is busy */
|
||||
if( (IORD_ALTERA_AVALON_SGDMA_STATUS(dev->base) &
|
||||
ALTERA_AVALON_SGDMA_STATUS_BUSY_MSK) ) {
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/* Clear Run */
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base,
|
||||
(IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base) &
|
||||
~ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK) );
|
||||
|
||||
/*
|
||||
* Clear any (previous) status register information
|
||||
* that might occlude our error checking later.
|
||||
*/
|
||||
IOWR_ALTERA_AVALON_SGDMA_STATUS(dev->base, 0xFF);
|
||||
|
||||
/* Point the controller at the descriptor */
|
||||
IOWR_ALTERA_AVALON_SGDMA_NEXT_DESC_POINTER(dev->base, (alt_u32) desc);
|
||||
|
||||
/*
|
||||
* If a callback routine has been previously registered which will be
|
||||
* called from the SGDMA ISR. Set up controller to:
|
||||
* - Run
|
||||
* - Stop on an error with any particular descriptor
|
||||
* - Include any control register bits registered with along with
|
||||
* the callback routine (effectively, interrupts are controlled
|
||||
* via the control bits set during callback-register time).
|
||||
*/
|
||||
if(dev->callback) {
|
||||
control = IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base);
|
||||
|
||||
control |= (dev->chain_control |
|
||||
ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK |
|
||||
ALTERA_AVALON_SGDMA_CONTROL_STOP_DMA_ER_MSK );
|
||||
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base, control);
|
||||
}
|
||||
/*
|
||||
* No callback has been registered. Set up controller to:
|
||||
* - Run
|
||||
* - Stop on an error with any particular descriptor
|
||||
* - Disable interrupt generation
|
||||
*/
|
||||
else {
|
||||
control = IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base);
|
||||
|
||||
control |= (ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK |
|
||||
ALTERA_AVALON_SGDMA_CONTROL_STOP_DMA_ER_MSK );
|
||||
control &= ~ALTERA_AVALON_SGDMA_CONTROL_IE_GLOBAL_MSK;
|
||||
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base, control);
|
||||
}
|
||||
|
||||
/*
|
||||
* Error detection/handling should be performed at the application
|
||||
* or callback level as appropriate.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_do_sync_transfer
|
||||
*
|
||||
* Send a fully formed descriptor (or list of descriptors) to SGDMA
|
||||
* for transfer. This routine will block both before transfer (if the
|
||||
* controller is busy), and until the requested transfer has completed.
|
||||
*
|
||||
* If an error is detected during the transfer it is abandoned and the
|
||||
* controller's status register contents are returned to the caller.
|
||||
*
|
||||
* Additional error information is available in the status bits of
|
||||
* each descriptor that the SGDMA processed; it is the responsibility
|
||||
* of the user's application to search through the descriptor (or list
|
||||
* of descriptors) to gather specific error information.
|
||||
*
|
||||
* Arguments:
|
||||
* - *dev: Pointer to SGDMA device (instance) struct.
|
||||
* - *desc: Pointer to single (ready to run) descriptor. The descriptor
|
||||
* is expected to have its "next" descriptor field initialized either
|
||||
* to a non-ready descriptor, or to the next in a chain.
|
||||
*
|
||||
* Returns:
|
||||
* - status: Content of SGDMA status register.
|
||||
*/
|
||||
alt_u8 alt_avalon_sgdma_do_sync_transfer(
|
||||
alt_sgdma_dev *dev,
|
||||
alt_sgdma_descriptor *desc)
|
||||
{
|
||||
alt_u8 status;
|
||||
|
||||
/* Wait for any pending transfers to complete */
|
||||
while ( (IORD_ALTERA_AVALON_SGDMA_STATUS(dev->base) &
|
||||
ALTERA_AVALON_SGDMA_STATUS_BUSY_MSK) );
|
||||
|
||||
|
||||
/* Clear Run */
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base,
|
||||
(IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base) &
|
||||
~ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK) );
|
||||
|
||||
/*
|
||||
* Clear any (previous) status register information
|
||||
* that might occlude our error checking later.
|
||||
*/
|
||||
IOWR_ALTERA_AVALON_SGDMA_STATUS(dev->base, 0xFF);
|
||||
|
||||
/* Point the controller at the descriptor */
|
||||
IOWR_ALTERA_AVALON_SGDMA_NEXT_DESC_POINTER(dev->base, (alt_u32) desc);
|
||||
|
||||
/*
|
||||
* Set up SGDMA controller to:
|
||||
* - Disable interrupt generation
|
||||
* - Run once a valid descriptor is written to controller
|
||||
* - Stop on an error with any particular descriptor
|
||||
*/
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base,
|
||||
(ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK |
|
||||
ALTERA_AVALON_SGDMA_CONTROL_STOP_DMA_ER_MSK |
|
||||
IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base)) );
|
||||
|
||||
/* Wait for the descriptor (chain) to complete */
|
||||
while ( (IORD_ALTERA_AVALON_SGDMA_STATUS(dev->base) &
|
||||
ALTERA_AVALON_SGDMA_STATUS_BUSY_MSK) );
|
||||
|
||||
/* Clear Run */
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base,
|
||||
(IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base) &
|
||||
~ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK) );
|
||||
|
||||
/* Get & clear status register contents */
|
||||
status = IORD_ALTERA_AVALON_SGDMA_STATUS(dev->base);
|
||||
IOWR_ALTERA_AVALON_SGDMA_STATUS(dev->base, 0xFF);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* SGDMA Descriptor construction routines.
|
||||
*
|
||||
* General information:
|
||||
* These routines construct a single SGDMA descriptor in the memory
|
||||
* pointed to in alt_avalon_sgdma-descriptor *desc.
|
||||
*
|
||||
* The completed descriptor is made ready to run by setting its "Owned
|
||||
* by HW" bit; once the SGDMA controller receives the descriptor (and
|
||||
* its RUN bit is asserted), the descriptor will be processed.
|
||||
*
|
||||
* The descriptor under construction's "next" value is set to the "next"
|
||||
* descriptor passed to this routine, but the "next" descriptor's "Owned
|
||||
* by HW" bit is explicitly negated; once the SGDMA completes processing of
|
||||
* *desc it will not continue to *next until it, too, is made ready. You
|
||||
* can subsequently call the appropriate descriptor construction routine
|
||||
* on *next to make it ready, too.
|
||||
*
|
||||
* You are responsible for the creation of both the descriptor under
|
||||
* constuction as well as the "next" descriptor in the chain.
|
||||
*
|
||||
* Important: descriptors must be in a memory device mastered by the SGDMA
|
||||
* controller's "chain read" and "chain write" Avalon master-ports. Care must be
|
||||
* taken to ensure that both *desc and *next point to areas of memory mastered
|
||||
* by the controller.
|
||||
*/
|
||||
|
||||
void alt_avalon_sgdma_construct_mem_to_mem_desc(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length,
|
||||
int read_fixed,
|
||||
int write_fixed)
|
||||
{
|
||||
alt_avalon_sgdma_construct_mem_to_mem_desc_burst(desc, next, read_addr,
|
||||
write_addr, length, read_fixed, write_fixed, 0, 0);
|
||||
}
|
||||
/*
|
||||
* alt_avalon_sgdma_construct_mem_to_mem_desc
|
||||
*
|
||||
* This routine constructs a single SGDMA descriptor in the memory
|
||||
* specified in alt_avalon_sgdma-descriptor *desc for an Avalon
|
||||
* memory-to-memory transfer.
|
||||
*
|
||||
* Arguments:
|
||||
* - *desc: Pointer to descriptor being constructed.
|
||||
* - *next: Pointer to "next" descriptor. This need not be a complete or
|
||||
* functional descriptor, but must be properly allocated as described above.
|
||||
* - *read_addr: First read address for the DMA transfer
|
||||
* - *write_addr: First write address for the DMA transfer
|
||||
* - length: Number of bytes for this transfer
|
||||
* - read_fixed: If non-zero, DMA will read from a fixed address.
|
||||
* - write_fixed: If non-zer, DMA will write to a fixed address.
|
||||
*/
|
||||
void alt_avalon_sgdma_construct_mem_to_mem_desc_burst(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length,
|
||||
int read_fixed,
|
||||
int write_fixed,
|
||||
int read_burst,
|
||||
int write_burst)
|
||||
{
|
||||
alt_avalon_sgdma_construct_descriptor_burst(
|
||||
desc,
|
||||
next,
|
||||
read_addr,
|
||||
write_addr,
|
||||
length,
|
||||
0, // Generate EOP: N/A in mem-to-mem mode
|
||||
read_fixed,
|
||||
write_fixed,
|
||||
read_burst,
|
||||
write_burst,
|
||||
(alt_u8) 0x0); // Atlantic channel: N/A in mem-to-mem mode
|
||||
}
|
||||
|
||||
void alt_avalon_sgdma_construct_stream_to_mem_desc(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length_or_eop,
|
||||
int write_fixed)
|
||||
{
|
||||
alt_avalon_sgdma_construct_stream_to_mem_desc_burst(desc, next, write_addr,
|
||||
length_or_eop, write_fixed, 0);
|
||||
}
|
||||
/*
|
||||
* alt_avalon_sgdma_construct_stream_to_mem_desc
|
||||
*
|
||||
* This routine constructs a single SGDMA descriptor in the memory
|
||||
* specified in alt_avalon_sgdma-descriptor *desc) for an Avalon
|
||||
* Streaming interface-to-Avalon transfer.
|
||||
*
|
||||
* The source (read) data for the transfer comes from the Avalon
|
||||
* Streaming Interface connected to the SGDMA controller's streaming
|
||||
* read-port.
|
||||
*
|
||||
* Arguments:
|
||||
* - *desc: Pointer to descriptor being constructed.
|
||||
* - *next: Pointer to "next" descriptor. This need not be a complete or
|
||||
* functional descriptor, but must be properly allocated as described above.
|
||||
* - *write_addr: First write address for the DMA transfer
|
||||
* - length_or_eop: Number of bytes for this transfer. If set to zero (0x0),
|
||||
* the transfer will continue until an EOP signal is received from the Avalon
|
||||
* Streaming interface
|
||||
* - write_fixed: If non-zero, SGDMA will write to a fixed address.
|
||||
*/
|
||||
void alt_avalon_sgdma_construct_stream_to_mem_desc_burst(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length_or_eop,
|
||||
int write_fixed,
|
||||
int write_burst)
|
||||
{
|
||||
alt_avalon_sgdma_construct_descriptor_burst(
|
||||
desc,
|
||||
next,
|
||||
(alt_u32) 0x0, // Read addr: N/A in stream-to-mem mode
|
||||
write_addr,
|
||||
length_or_eop,
|
||||
0x0, // Generate EOP: N/A in stream-to-mem mode
|
||||
0x0, // Read fixed: N/A in stream-to-mem mode
|
||||
write_fixed,
|
||||
0, // Read_burst : N/A in stream-to-mem mode
|
||||
write_burst,
|
||||
(alt_u8) 0x0); // Atlantic channel: N/A in stream-to-mem mode
|
||||
}
|
||||
|
||||
void alt_avalon_sgdma_construct_mem_to_stream_desc(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u16 length,
|
||||
int read_fixed,
|
||||
int generate_sop,
|
||||
int generate_eop,
|
||||
alt_u8 atlantic_channel)
|
||||
{
|
||||
alt_avalon_sgdma_construct_mem_to_stream_desc_burst(desc, next, read_addr,
|
||||
length, read_fixed, generate_sop, generate_eop, 0, atlantic_channel);
|
||||
|
||||
}
|
||||
/*
|
||||
* alt_avalon_sgdma_construct_mem_to_stream_desc
|
||||
*
|
||||
* This routine constructs a single SGDMA descriptor in the memory
|
||||
* specified in alt_avalon_sgdma-descriptor *desc) for an Avalon to
|
||||
* Avalon Streaming interface transfer.
|
||||
*
|
||||
* The destination (write) data for the transfer goes to the Avalon
|
||||
* Streaming Interface connected to the SGDMA controller's streaming
|
||||
* write-port.
|
||||
*
|
||||
* Arguments:
|
||||
* - *desc: Pointer to descriptor being constructed.
|
||||
* - *next: Pointer to "next" descriptor. This need not be a complete or
|
||||
* functional descriptor, but must be properly allocated as described above.
|
||||
* - *read_addr: First read address for the transfer
|
||||
* - length: Number of bytes for this transfer
|
||||
* - read_fixed: If non-zero, SGDMA will read from a fixed address.
|
||||
* - generate_sop: If non-zero, SGDMA will generate a start-of-packet (SOP)
|
||||
* on the Avalon Streaming interface when commencing the transfer.
|
||||
* - generate_eop: If non-zero, SGDMA will generate an end-of-packet (EOP)
|
||||
* on the Avalon Streaming interface when completing the transfer.
|
||||
* - atlantic_channel: 8-bit channel identification number that will be
|
||||
* passed to the Avalon Streaming interface.
|
||||
*/
|
||||
void alt_avalon_sgdma_construct_mem_to_stream_desc_burst(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u16 length,
|
||||
int read_fixed,
|
||||
int generate_sop,
|
||||
int generate_eop,
|
||||
int read_burst,
|
||||
alt_u8 atlantic_channel)
|
||||
{
|
||||
alt_avalon_sgdma_construct_descriptor_burst(
|
||||
desc,
|
||||
next,
|
||||
read_addr,
|
||||
(alt_u32) 0x0, // Write address N/A in mem-to-stream mode
|
||||
length,
|
||||
generate_eop,
|
||||
read_fixed,
|
||||
generate_sop,
|
||||
read_burst,
|
||||
0, // Write_burst : N/A in mem-to-stream mode
|
||||
atlantic_channel);
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_register_callback
|
||||
*
|
||||
* Associate a user-specifiC routine with the SGDMA interrupt handler.
|
||||
* If a callback is registered, all non-blocking SGDMA transfers will
|
||||
* enable interrupts that will cause the callback to be executed.
|
||||
* The callback runs as part of the interrupt service routine, and
|
||||
* great care must be taken to follow the guidelines for acceptable
|
||||
* interrupt service routine behavior as described in the Nios II
|
||||
* Software Developer's Handbook.
|
||||
*
|
||||
* Note: To disable callbacks after registering one, this routine
|
||||
* may be called passing 0x0 to the callback argument.
|
||||
*
|
||||
* Arguments:
|
||||
* - *dev: Pointer to SGDMA device (instance) struct.
|
||||
* - callback: Pointer to callback routine to execute at interrupt level
|
||||
* - chain_control: SGDMA control register contents. This value will be
|
||||
* OR'd together with control bits to:
|
||||
* (1) Set the the SGDMA "run" bit, and
|
||||
* (2) Stop SGDMA on any error
|
||||
* in the SGDMA control register, when an asynchronous transfer is initiated.
|
||||
* This allows you to control the conditions that will generate an interrupt
|
||||
* from SGDMA. If you want interrupts to be generated (and thus call the
|
||||
* callback routine), you MUST set one or more bits in the chain_control
|
||||
* variable that correspond to SGDMA control register interrupt enable bits
|
||||
* for interrupts to be generated, as well as the master inerrupt enable bit.
|
||||
*/
|
||||
void alt_avalon_sgdma_register_callback(
|
||||
alt_sgdma_dev *dev,
|
||||
alt_avalon_sgdma_callback callback,
|
||||
alt_u32 chain_control,
|
||||
void *context)
|
||||
{
|
||||
dev->callback = callback;
|
||||
dev->callback_context = context;
|
||||
dev->chain_control = chain_control;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_start
|
||||
*
|
||||
* Start the DMA engine. The descriptor pointed to in the controller's
|
||||
* "Next descriptor pointer" and subsequent descriptor, will be processed.
|
||||
*
|
||||
* Arguments:
|
||||
* - *dev: Pointer to SGDMA device (instance) struct.
|
||||
*/
|
||||
void alt_avalon_sgdma_start(alt_sgdma_dev *dev)
|
||||
{
|
||||
alt_u32 control;
|
||||
|
||||
control = IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base);
|
||||
control |= ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK;
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base, control);
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_stop
|
||||
*
|
||||
* Stop the DMA engine (following completion of the current buffer descriptor).
|
||||
*
|
||||
* Arguments:
|
||||
* - *dev: Pointer to SGDMA device (instance) struct
|
||||
*/
|
||||
void alt_avalon_sgdma_stop(alt_sgdma_dev *dev)
|
||||
{
|
||||
alt_u32 control;
|
||||
|
||||
control = IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base);
|
||||
control &= ~ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK;
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base, control);
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_check_descriptor_status
|
||||
*
|
||||
* This routine will report:
|
||||
* - Any errors reported by the SGDMA controller specific
|
||||
* to a particular descriptor by retirning -EIO
|
||||
* - The descriptor currently in use ("Owned by HW" bit set)
|
||||
* by returning -EINPROGRESS.
|
||||
*
|
||||
* Arguments:
|
||||
* - *desc: Pointer to descriptor to examine
|
||||
*
|
||||
* Returns:
|
||||
* - 0 if the descriptor is error-free, not "owned by hardware", or
|
||||
* a previously requested transfer has appeared to have completed
|
||||
* normally. Or, various error conditions defined in <errno.h>
|
||||
*/
|
||||
int alt_avalon_sgdma_check_descriptor_status(alt_sgdma_descriptor *desc)
|
||||
{
|
||||
/* Errors take precedence */
|
||||
if( IORD_8DIRECT(&desc->status, 0) &
|
||||
( ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_CRC_MSK |
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_PARITY_MSK |
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_OVERFLOW_MSK |
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_SYNC_MSK |
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_UEOP_MSK |
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_MEOP_MSK |
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_STATUS_E_MSOP_MSK ) ) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if( IORD_8DIRECT(&desc->control, 0) &
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK) {
|
||||
return -EINPROGRESS;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_open - Retrieve a pointer to the SGDMA
|
||||
*
|
||||
* Search the list of registered SGDMAs for one with the supplied name.
|
||||
*
|
||||
* The return value will be NULL on failure, and non-NULL otherwise.
|
||||
*
|
||||
* Arguments:
|
||||
* - *name: Character pointer to name of SGDMA peripheral as registered
|
||||
* with the HAL. For example, an SGDMA controller named "my_sgdma"
|
||||
* in SOPC Builder would be oped by asking for "/dev/my_sgdma".
|
||||
*
|
||||
* Returns:
|
||||
* - Pointer to SGDMA device instance struct, or null if the device
|
||||
* could not be opened.
|
||||
*/
|
||||
alt_sgdma_dev* alt_avalon_sgdma_open (const char* name)
|
||||
{
|
||||
alt_sgdma_dev* dev;
|
||||
|
||||
dev = (alt_sgdma_dev*) alt_find_dev (name, &alt_sgdma_list);
|
||||
|
||||
if (NULL == dev) {
|
||||
ALT_ERRNO = ENODEV;
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
||||
void alt_avalon_sgdma_construct_descriptor(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length_or_eop,
|
||||
int generate_eop,
|
||||
int read_fixed,
|
||||
int write_fixed_or_sop,
|
||||
alt_u8 atlantic_channel)
|
||||
{
|
||||
alt_avalon_sgdma_construct_descriptor_burst(desc, next, read_addr,
|
||||
write_addr, length_or_eop, generate_eop, read_fixed, write_fixed_or_sop,
|
||||
0, 0, atlantic_channel);
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_enable_desc_poll
|
||||
*
|
||||
* Enables descriptor polling mode with specified frequency. User needs to make
|
||||
* sure this feature is supported by hardware. There is no effect if hardware
|
||||
* does not support this feature.
|
||||
*
|
||||
* Arguments:
|
||||
* - *dev: Pointer to SGDMA device (instance) struct
|
||||
* - frequency: Frequency value to set. Only lower 11-bit value of frequency
|
||||
will write to control register.
|
||||
*
|
||||
* Returns:
|
||||
* - None
|
||||
*/
|
||||
void alt_avalon_sgdma_enable_desc_poll(alt_sgdma_dev *dev, alt_u32 frequency)
|
||||
{
|
||||
alt_u32 control;
|
||||
|
||||
control = IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base);
|
||||
/* Clear descriptor polling frequency */
|
||||
control &= ~ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_FREQ_MSK;
|
||||
|
||||
control |= ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_EN_MSK |
|
||||
((frequency << ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_FREQ_OFST) &
|
||||
ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_FREQ_MSK);
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base, control);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_disable_desc_poll
|
||||
*
|
||||
* Disables descriptor polling mode.
|
||||
*
|
||||
* Arguments:
|
||||
* - *dev: Pointer to SGDMA device (instance) struct
|
||||
*
|
||||
* Returns:
|
||||
* - None
|
||||
*/
|
||||
void alt_avalon_sgdma_disable_desc_poll(alt_sgdma_dev *dev)
|
||||
{
|
||||
alt_u32 control;
|
||||
|
||||
control = IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base);
|
||||
control &= ~ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_EN_MSK;
|
||||
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base, control);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Altera HAL support & Private API
|
||||
******************************************************************************/
|
||||
/*
|
||||
* alt_avalon_sgdma_construct_descriptor
|
||||
*
|
||||
* This is a genertic routine that the SGDMA mode-specific routines
|
||||
* call to populate a descriptor.
|
||||
*/
|
||||
void alt_avalon_sgdma_construct_descriptor_burst(
|
||||
alt_sgdma_descriptor *desc,
|
||||
alt_sgdma_descriptor *next,
|
||||
alt_u32 *read_addr,
|
||||
alt_u32 *write_addr,
|
||||
alt_u16 length_or_eop,
|
||||
int generate_eop,
|
||||
int read_fixed,
|
||||
int write_fixed_or_sop,
|
||||
int read_burst,
|
||||
int write_burst,
|
||||
alt_u8 atlantic_channel)
|
||||
{
|
||||
/*
|
||||
* Mark the "next" descriptor as "not" owned by hardware. This prevents
|
||||
* The SGDMA controller from continuing to process the chain. This is
|
||||
* done as a single IO write to bypass cache, without flushing
|
||||
* the entire descriptor, since only the 8-bit descriptor status must
|
||||
* be flushed.
|
||||
*/
|
||||
IOWR_8DIRECT(&next->control, 0,
|
||||
(next->control & ~ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK));
|
||||
|
||||
desc->read_addr = read_addr;
|
||||
desc->write_addr = write_addr;
|
||||
desc->next = (alt_u32 *) next;
|
||||
desc->read_addr_pad = 0x0;
|
||||
desc->write_addr_pad = 0x0;
|
||||
desc->next_pad = 0x0;
|
||||
desc->bytes_to_transfer = length_or_eop;
|
||||
desc->actual_bytes_transferred = 0;
|
||||
desc->status = 0x0;
|
||||
|
||||
/* SGDMA burst not currently supported */
|
||||
desc->read_burst = read_burst;
|
||||
desc->write_burst = write_burst;
|
||||
|
||||
/*
|
||||
* Set the descriptor control block as follows:
|
||||
* - Set "owned by hardware" bit
|
||||
* - Optionally set "generte EOP" bit
|
||||
* - Optionally set the "read from fixed address" bit
|
||||
* - Optionally set the "write to fixed address bit (which serves
|
||||
* serves as a "generate SOP" control bit in memory-to-stream mode).
|
||||
* - Set the 4-bit atlantic channel, if specified
|
||||
*
|
||||
* Note that this step is performed after all other descriptor information
|
||||
* has been filled out so that, if the controller already happens to be
|
||||
* pointing at this descriptor, it will not run (via the "owned by hardware"
|
||||
* bit) until all other descriptor information has been set up.
|
||||
*/
|
||||
desc->control = (
|
||||
(ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK) |
|
||||
(generate_eop ?
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_GENERATE_EOP_MSK : 0x0) |
|
||||
(read_fixed ?
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_READ_FIXED_ADDRESS_MSK : 0x0) |
|
||||
(write_fixed_or_sop ?
|
||||
ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_WRITE_FIXED_ADDRESS_MSK : 0x0) |
|
||||
(atlantic_channel ? ( (atlantic_channel & 0x0F) << 3) : 0)
|
||||
);
|
||||
|
||||
/*
|
||||
* Flush completed buffer out of cache. This is done rather than
|
||||
* individual cache-bypassed writes to take advantage of any
|
||||
* burst-capabilities in the memory we're writing to.
|
||||
*/
|
||||
alt_dcache_flush(desc, sizeof(alt_sgdma_descriptor));
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_irq()
|
||||
*
|
||||
* Interrupt handler for the Scatter-Gather DMA controller.
|
||||
*/
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
static void alt_avalon_sgdma_irq(void *context)
|
||||
#else
|
||||
static void alt_avalon_sgdma_irq(void *context, alt_u32 id)
|
||||
#endif
|
||||
{
|
||||
alt_sgdma_dev *dev = (alt_sgdma_dev *) context;
|
||||
alt_irq_context cpu_sr;
|
||||
|
||||
/*
|
||||
* Clear the pending interrupt request from the SGDMA controller.
|
||||
* Writing 1 to bit-31 of the control register clears the interrupt.
|
||||
* Note: This is explicitly done before calling user interrupt-handling
|
||||
* code rather than after; if user ISR code initiates another SGDMA
|
||||
* transfer which completes quickly, reading the control register after
|
||||
* the callback routine may result in a lost interrupt.
|
||||
*/
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base,
|
||||
IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base) | 0x80000000);
|
||||
|
||||
/* Dummy read to ensure IRQ is negated before the ISR returns */
|
||||
IORD_ALTERA_AVALON_SGDMA_CONTROL(dev->base);
|
||||
|
||||
/*
|
||||
* Other interrupts are explicitly disabled if callbacks
|
||||
* are registered because there is no guarantee that they are
|
||||
* preemption-safe. This allows the driver to support
|
||||
* interrupt preemption.
|
||||
*/
|
||||
if(dev->callback) {
|
||||
cpu_sr = alt_irq_disable_all();
|
||||
(dev->callback)(dev->callback_context);
|
||||
alt_irq_enable_all(cpu_sr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_sgdma_init()
|
||||
*
|
||||
* Initializes the Scatter-Gather DMA controller. This routine is called
|
||||
* from the ALTERA_AVALON_SGDMA_INIT macro and is called automatically
|
||||
* by alt_sys_init.c
|
||||
*
|
||||
* This routine disables interrupts, future descriptor processing,
|
||||
* registers a specific instance of the device with the HAL,
|
||||
* and installs an interrupt handler for the device.
|
||||
*/
|
||||
void alt_avalon_sgdma_init (alt_sgdma_dev *dev, alt_u32 ic_id, alt_u32 irq)
|
||||
{
|
||||
extern alt_llist alt_sgdma_list;
|
||||
|
||||
/*
|
||||
* Halt any current transactions (reset the device)
|
||||
* SW reset is written twice per SGDMA documentation
|
||||
*/
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base,
|
||||
ALTERA_AVALON_SGDMA_CONTROL_SOFTWARERESET_MSK);
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base,
|
||||
ALTERA_AVALON_SGDMA_CONTROL_SOFTWARERESET_MSK);
|
||||
|
||||
/*
|
||||
* Disable interrupts, halt future descriptor processing,
|
||||
* and clear status register content
|
||||
*/
|
||||
IOWR_ALTERA_AVALON_SGDMA_CONTROL(dev->base, 0x0);
|
||||
IOWR_ALTERA_AVALON_SGDMA_STATUS(dev->base, 0xFF);
|
||||
|
||||
/* Register this instance of the SGDMA controller with HAL */
|
||||
alt_dev_llist_insert((alt_dev_llist*) dev, &alt_sgdma_list);
|
||||
|
||||
/* Install IRQ handler */
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
alt_ic_isr_register(ic_id, irq, alt_avalon_sgdma_irq, dev, 0x0);
|
||||
#else
|
||||
alt_irq_register(irq, dev, alt_avalon_sgdma_irq);
|
||||
#endif
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2011 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_AVALON_SGDMA_REGS_H__
|
||||
#define __ALTERA_AVALON_SGDMA_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_SGDMA_STATUS(base) __IO_CALC_ADDRESS_DYNAMIC(base, 0)
|
||||
#define IORD_ALTERA_AVALON_SGDMA_STATUS(base) IORD(base, 0)
|
||||
#define IOWR_ALTERA_AVALON_SGDMA_STATUS(base, data) IOWR(base, 0, data)
|
||||
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_ERROR_MSK (0x1)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_ERROR_OFST (0)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_EOP_ENCOUNTERED_MSK (0x2)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_EOP_ENCOUNTERED_OFST (1)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_DESC_COMPLETED_MSK (0x4)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_DESC_COMPLETED_OFST (2)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_CHAIN_COMPLETED_MSK (0x8)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_CHAIN_COMPLETED_OFST (3)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_BUSY_MSK (0x10)
|
||||
#define ALTERA_AVALON_SGDMA_STATUS_BUSY_OFST (4)
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_SGDMA_VERSION(base) __IO_CALC_ADDRESS_DYNAMIC(base, 1)
|
||||
#define IORD_ALTERA_AVALON_SGDMA_VERSION(base) IORD(base, 1)
|
||||
#define IOWR_ALTERA_AVALON_SGDMA_VERSION(base, data) IOWR(base, 1, data)
|
||||
#define ALTERA_AVALON_SGDMA_VERSION_VERSION_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_SGDMA_VERSION_VERSION_OFST (0)
|
||||
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_SGDMA_CONTROL(base) __IO_CALC_ADDRESS_DYNAMIC(base, 4)
|
||||
#define IORD_ALTERA_AVALON_SGDMA_CONTROL(base) IORD(base, 4)
|
||||
#define IOWR_ALTERA_AVALON_SGDMA_CONTROL(base, data) IOWR(base, 4, data)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_ERROR_MSK (0x1)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_ERROR_OFST (0)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_EOP_ENCOUNTERED_MSK (0x2)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_EOP_ENCOUNTERED_OFST (1)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_DESC_COMPLETED_MSK (0x4)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_DESC_COMPLETED_OFST (2)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_CHAIN_COMPLETED_MSK (0x8)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_CHAIN_COMPLETED_OFST (3)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_GLOBAL_MSK (0x10)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_GLOBAL_OFST (4)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_RUN_MSK (0x20)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_RUN_OFST (5)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_STOP_DMA_ER_MSK (0x40)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_STOP_DMA_ER_OFST (6)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_MAX_DESC_PROCESSED_MSK (0x80)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_IE_MAX_DESC_PROCESSED_OFST (7)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_MAX_DESC_PROCESSED_MSK (0xFF00)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_MAX_DESC_PROCESSED_OFST (8)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_SOFTWARERESET_MSK (0X10000)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_SOFTWARERESET_OFST (16)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_PARK_MSK (0X20000)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_PARK_OFST (17)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_EN_MSK (0X40000)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_EN_OFST (18)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_FREQ_MSK (0x7FF00000)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_DESC_POLL_FREQ_OFST (20)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_CLEAR_INTERRUPT_MSK (0X80000000)
|
||||
#define ALTERA_AVALON_SGDMA_CONTROL_CLEAR_INTERRUPT_OFST (31)
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_SGDMA_NEXT_DESC_POINTER(base) __IO_CALC_ADDRESS_DYNAMIC(base, 8)
|
||||
#define IORD_ALTERA_AVALON_SGDMA_NEXT_DESC_POINTER(base) IORD(base, 8)
|
||||
#define IOWR_ALTERA_AVALON_SGDMA_NEXT_DESC_POINTER(base, data) IOWR(base, 8, data)
|
||||
|
||||
|
||||
#endif /* __ALTERA_AVALON_SGDMA_REGS_H__ */
|
|
@ -1,74 +0,0 @@
|
|||
#ifndef __ALT_AVALON_SPI_H__
|
||||
#define __ALT_AVALON_SPI_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
#include <stddef.h>
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* Macros used by alt_sys_init
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_SPI_INSTANCE(name, device) extern int alt_no_storage
|
||||
#define ALTERA_AVALON_SPI_INIT(name, device) while (0)
|
||||
|
||||
/*
|
||||
* Use this function to perform one SPI access on your target. 'base' should
|
||||
* be the base address of your SPI peripheral, while 'slave' indicates which
|
||||
* bit in the slave select register should be set.
|
||||
*/
|
||||
|
||||
/* If you need to make multiple accesses to the same slave then you should
|
||||
* set the merge bit in the flags for all of them except the first.
|
||||
*/
|
||||
#define ALT_AVALON_SPI_COMMAND_MERGE (0x01)
|
||||
|
||||
/*
|
||||
* If you need the slave select line to be toggled between words then you
|
||||
* should set the toggle bit in the flag.
|
||||
*/
|
||||
#define ALT_AVALON_SPI_COMMAND_TOGGLE_SS_N (0x02)
|
||||
|
||||
|
||||
int alt_avalon_spi_command(alt_u32 base, alt_u32 slave,
|
||||
alt_u32 write_length, const alt_u8 * write_data,
|
||||
alt_u32 read_length, alt_u8 * read_data,
|
||||
alt_u32 flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_AVALON_SPI_H__ */
|
|
@ -1 +0,0 @@
|
|||
zephyr_sources(altera_avalon_spi.c)
|
|
@ -1,132 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
#include "altera_avalon_spi_regs.h"
|
||||
#include "altera_avalon_spi.h"
|
||||
|
||||
/* This is a very simple routine which performs one SPI master transaction.
|
||||
* It would be possible to implement a more efficient version using interrupts
|
||||
* and sleeping threads but this is probably not worthwhile initially.
|
||||
*/
|
||||
|
||||
int alt_avalon_spi_command(alt_u32 base, alt_u32 slave,
|
||||
alt_u32 write_length, const alt_u8 * write_data,
|
||||
alt_u32 read_length, alt_u8 * read_data,
|
||||
alt_u32 flags)
|
||||
{
|
||||
const alt_u8 * write_end = write_data + write_length;
|
||||
alt_u8 * read_end = read_data + read_length;
|
||||
|
||||
alt_u32 write_zeros = read_length;
|
||||
alt_u32 read_ignore = write_length;
|
||||
alt_u32 status;
|
||||
|
||||
/* We must not send more than two bytes to the target before it has
|
||||
* returned any as otherwise it will overflow. */
|
||||
/* Unfortunately the hardware does not seem to work with credits > 1,
|
||||
* leave it at 1 for now. */
|
||||
alt_32 credits = 1;
|
||||
|
||||
/* Warning: this function is not currently safe if called in a multi-threaded
|
||||
* environment, something above must perform locking to make it safe if more
|
||||
* than one thread intends to use it.
|
||||
*/
|
||||
|
||||
IOWR_ALTERA_AVALON_SPI_SLAVE_SEL(base, 1 << slave);
|
||||
|
||||
/* Set the SSO bit (force chipselect) only if the toggle flag is not set */
|
||||
if ((flags & ALT_AVALON_SPI_COMMAND_TOGGLE_SS_N) == 0) {
|
||||
IOWR_ALTERA_AVALON_SPI_CONTROL(base, ALTERA_AVALON_SPI_CONTROL_SSO_MSK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Discard any stale data present in the RXDATA register, in case
|
||||
* previous communication was interrupted and stale data was left
|
||||
* behind.
|
||||
*/
|
||||
IORD_ALTERA_AVALON_SPI_RXDATA(base);
|
||||
|
||||
/* Keep clocking until all the data has been processed. */
|
||||
for ( ; ; )
|
||||
{
|
||||
|
||||
do
|
||||
{
|
||||
status = IORD_ALTERA_AVALON_SPI_STATUS(base);
|
||||
}
|
||||
while (((status & ALTERA_AVALON_SPI_STATUS_TRDY_MSK) == 0 || credits == 0) &&
|
||||
(status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0);
|
||||
|
||||
if ((status & ALTERA_AVALON_SPI_STATUS_TRDY_MSK) != 0 && credits > 0)
|
||||
{
|
||||
credits--;
|
||||
|
||||
if (write_data < write_end)
|
||||
IOWR_ALTERA_AVALON_SPI_TXDATA(base, *write_data++);
|
||||
else if (write_zeros > 0)
|
||||
{
|
||||
write_zeros--;
|
||||
IOWR_ALTERA_AVALON_SPI_TXDATA(base, 0);
|
||||
}
|
||||
else
|
||||
credits = -1024;
|
||||
};
|
||||
|
||||
if ((status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) != 0)
|
||||
{
|
||||
alt_u32 rxdata = IORD_ALTERA_AVALON_SPI_RXDATA(base);
|
||||
|
||||
if (read_ignore > 0)
|
||||
read_ignore--;
|
||||
else
|
||||
*read_data++ = (alt_u8)rxdata;
|
||||
credits++;
|
||||
|
||||
if (read_ignore == 0 && read_data == read_end)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Wait until the interface has finished transmitting */
|
||||
do
|
||||
{
|
||||
status = IORD_ALTERA_AVALON_SPI_STATUS(base);
|
||||
}
|
||||
while ((status & ALTERA_AVALON_SPI_STATUS_TMT_MSK) == 0);
|
||||
|
||||
/* Clear SSO (release chipselect) unless the caller is going to
|
||||
* keep using this chip
|
||||
*/
|
||||
if ((flags & ALT_AVALON_SPI_COMMAND_MERGE) == 0)
|
||||
IOWR_ALTERA_AVALON_SPI_CONTROL(base, 0);
|
||||
|
||||
return read_length;
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_AVALON_SPI_REGS_H__
|
||||
#define __ALTERA_AVALON_SPI_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#define ALTERA_AVALON_SPI_RXDATA_REG 0
|
||||
#define IOADDR_ALTERA_AVALON_SPI_RXDATA(base) __IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_SPI_RXDATA_REG)
|
||||
#define IORD_ALTERA_AVALON_SPI_RXDATA(base) IORD(base, ALTERA_AVALON_SPI_RXDATA_REG)
|
||||
#define IOWR_ALTERA_AVALON_SPI_RXDATA(base, data) IOWR(base, ALTERA_AVALON_SPI_RXDATA_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_SPI_TXDATA_REG 1
|
||||
#define IOADDR_ALTERA_AVALON_SPI_TXDATA(base) __IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_SPI_TXDATA_REG)
|
||||
#define IORD_ALTERA_AVALON_SPI_TXDATA(base) IORD(base, ALTERA_AVALON_SPI_TXDATA_REG)
|
||||
#define IOWR_ALTERA_AVALON_SPI_TXDATA(base, data) IOWR(base, ALTERA_AVALON_SPI_TXDATA_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_SPI_STATUS_REG 2
|
||||
#define IOADDR_ALTERA_AVALON_SPI_STATUS(base) __IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_SPI_STATUS_REG)
|
||||
#define IORD_ALTERA_AVALON_SPI_STATUS(base) IORD(base, ALTERA_AVALON_SPI_STATUS_REG)
|
||||
#define IOWR_ALTERA_AVALON_SPI_STATUS(base, data) IOWR(base, ALTERA_AVALON_SPI_STATUS_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_SPI_STATUS_ROE_MSK (0x8)
|
||||
#define ALTERA_AVALON_SPI_STATUS_ROE_OFST (3)
|
||||
#define ALTERA_AVALON_SPI_STATUS_TOE_MSK (0x10)
|
||||
#define ALTERA_AVALON_SPI_STATUS_TOE_OFST (4)
|
||||
#define ALTERA_AVALON_SPI_STATUS_TMT_MSK (0x20)
|
||||
#define ALTERA_AVALON_SPI_STATUS_TMT_OFST (5)
|
||||
#define ALTERA_AVALON_SPI_STATUS_TRDY_MSK (0x40)
|
||||
#define ALTERA_AVALON_SPI_STATUS_TRDY_OFST (6)
|
||||
#define ALTERA_AVALON_SPI_STATUS_RRDY_MSK (0x80)
|
||||
#define ALTERA_AVALON_SPI_STATUS_RRDY_OFST (7)
|
||||
#define ALTERA_AVALON_SPI_STATUS_E_MSK (0x100)
|
||||
#define ALTERA_AVALON_SPI_STATUS_E_OFST (8)
|
||||
|
||||
#define ALTERA_AVALON_SPI_CONTROL_REG 3
|
||||
#define IOADDR_ALTERA_AVALON_SPI_CONTROL(base) __IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_SPI_CONTROL_REG)
|
||||
#define IORD_ALTERA_AVALON_SPI_CONTROL(base) IORD(base, ALTERA_AVALON_SPI_CONTROL_REG)
|
||||
#define IOWR_ALTERA_AVALON_SPI_CONTROL(base, data) IOWR(base, ALTERA_AVALON_SPI_CONTROL_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_SPI_CONTROL_IROE_MSK (0x8)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_IROE_OFST (3)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_ITOE_MSK (0x10)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_ITOE_OFST (4)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_ITRDY_MSK (0x40)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_ITRDY_OFS (6)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_IRRDY_MSK (0x80)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_IRRDY_OFS (7)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_IE_MSK (0x100)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_IE_OFST (8)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_SSO_MSK (0x400)
|
||||
#define ALTERA_AVALON_SPI_CONTROL_SSO_OFST (10)
|
||||
|
||||
#define ALTERA_AVALON_SPI_SLAVE_SEL_REG 5
|
||||
#define IOADDR_ALTERA_AVALON_SPI_SLAVE_SEL(base) __IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_SPI_SLAVE_SEL_REG)
|
||||
#define IORD_ALTERA_AVALON_SPI_SLAVE_SEL(base) IORD(base, ALTERA_AVALON_SPI_SLAVE_SEL_REG)
|
||||
#define IOWR_ALTERA_AVALON_SPI_SLAVE_SEL(base, data) IOWR(base, ALTERA_AVALON_SPI_SLAVE_SEL_REG, data)
|
||||
|
||||
#endif /* __ALTERA_AVALON_SPI_REGS_H__ */
|
|
@ -1,58 +0,0 @@
|
|||
#ifndef __ALT_AVALON_SYSID_H__
|
||||
#define __ALT_AVALON_SYSID_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* ALTERA_AVALON_SYSID_INSTANCE is the macro used by alt_sys_init() to
|
||||
* allocate any per device memory that may be required. In this case no
|
||||
* allocation is necessary.
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_SYSID_INSTANCE(name, dev) extern int alt_no_storage
|
||||
#define ALTERA_AVALON_SYSID_INIT(name, dev) while (0)
|
||||
|
||||
#ifdef SYSID_BASE
|
||||
alt_32 alt_avalon_sysid_test(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_AVALON_SYSID_H__ */
|
|
@ -1 +0,0 @@
|
|||
zephyr_sources(altera_avalon_sysid.c)
|
|
@ -1,80 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "altera_avalon_sysid.h"
|
||||
#include "altera_avalon_sysid_regs.h"
|
||||
#include "alt_types.h"
|
||||
#include <io.h>
|
||||
|
||||
/*
|
||||
* This component is special: there's only one of it.
|
||||
* Therefore we can dispense with a bunch of complexity
|
||||
* normally associated with components, such as specialized
|
||||
* structs containing parameter info, and instead use that
|
||||
* info by name directly out of system.h. A downside of this
|
||||
* approach is that each time the system is regenerated, and
|
||||
* system.h changes, this file must be recompiled. Fortunately
|
||||
* this file is, and is likely to remain, quite small.
|
||||
*/
|
||||
#include "system.h"
|
||||
|
||||
#ifdef SYSID_BASE
|
||||
/*
|
||||
* return values:
|
||||
* 0 if the hardware and software appear to be in sync
|
||||
* 1 if software appears to be older than hardware
|
||||
* -1 if hardware appears to be older than software
|
||||
*/
|
||||
|
||||
alt_32 alt_avalon_sysid_test(void)
|
||||
{
|
||||
/* Read the hardware-tag, aka value0, from the hardware. */
|
||||
alt_u32 hardware_id = IORD_ALTERA_AVALON_SYSID_ID(SYSID_BASE);
|
||||
|
||||
/* Read the time-of-generation, aka value1, from the hardware register. */
|
||||
alt_u32 hardware_timestamp = IORD_ALTERA_AVALON_SYSID_TIMESTAMP(SYSID_BASE);
|
||||
|
||||
/* Return 0 if the hardware and software appear to be in sync. */
|
||||
if ((SYSID_TIMESTAMP == hardware_timestamp) && (SYSID_ID == hardware_id))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 1 if software appears to be older than hardware (that is,
|
||||
* the value returned by the hardware is larger than that recorded by
|
||||
* the generator function).
|
||||
* If the hardware time happens to match the generator program's value
|
||||
* (but the hardware tag, value0, doesn't match or 0 would have been
|
||||
* returned above), return an arbitrary value, let's say -1.
|
||||
*/
|
||||
return ((alt_32)(hardware_timestamp - SYSID_TIMESTAMP)) > 0 ? 1 : -1;
|
||||
}
|
||||
#endif
|
|
@ -1,37 +0,0 @@
|
|||
# *******************************************************************************
|
||||
# * *
|
||||
# * License Agreement *
|
||||
# * *
|
||||
# * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
# * All rights reserved. *
|
||||
# * *
|
||||
# * Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
# * copy of this software and associated documentation files (the "Software"), *
|
||||
# * to deal in the Software without restriction, including without limitation *
|
||||
# * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
# * and/or sell copies of the Software, and to permit persons to whom the *
|
||||
# * Software is furnished to do so, subject to the following conditions: *
|
||||
# * *
|
||||
# * The above copyright notice and this permission notice shall be included in *
|
||||
# * all copies or substantial portions of the Software. *
|
||||
# * *
|
||||
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
# * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
# * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
# * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
# * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
# * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
# * DEALINGS IN THE SOFTWARE. *
|
||||
# * *
|
||||
# * *
|
||||
# * Altera does not recommend, suggest or require that this reference design *
|
||||
# * file be used in conjunction or combination with any other product. *
|
||||
# *******************************************************************************
|
||||
|
||||
# List all source files supplied by this component.
|
||||
|
||||
C_LIB_SRCS += altera_avalon_sysid.c
|
||||
|
||||
ASM_LIB_SRCS +=
|
||||
|
||||
INCLUDE_PATH +=
|
|
@ -1,40 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_AVALON_SYSID_REGS_H__
|
||||
#define __ALTERA_AVALON_SYSID_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_SYSID_ID(base) __IO_CALC_ADDRESS_NATIVE(base, 0)
|
||||
#define IORD_ALTERA_AVALON_SYSID_ID(base) IORD(base, 0)
|
||||
|
||||
#define IOADDR_ALTERA_AVALON_SYSID_TIMESTAMP(base) __IO_CALC_ADDRESS_NATIVE(base, 1)
|
||||
#define IORD_ALTERA_AVALON_SYSID_TIMESTAMP(base) IORD(base, 1)
|
||||
|
||||
#endif /* __ALTERA_AVALON_SYSID_REGS_H__ */
|
|
@ -1,191 +0,0 @@
|
|||
#ifndef __ALT_AVALON_TIMER_H__
|
||||
#define __ALT_AVALON_TIMER_H__
|
||||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "sys/alt_dev.h"
|
||||
#include "sys/alt_warning.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#define __ALT_COUNTER_SIZE(name) name##_COUNTER_SIZE
|
||||
#define _ALT_COUNTER_SIZE(name) __ALT_COUNTER_SIZE(name)
|
||||
|
||||
#define ALT_SYS_CLK_COUNTER_SIZE _ALT_COUNTER_SIZE(ALT_SYS_CLK)
|
||||
#define ALT_TIMESTAMP_COUNTER_SIZE _ALT_COUNTER_SIZE(ALT_TIMESTAMP_CLK)
|
||||
|
||||
#if (ALT_SYS_CLK_COUNTER_SIZE == 64)
|
||||
#define alt_sysclk_type alt_u64
|
||||
#else
|
||||
#define alt_sysclk_type alt_u32
|
||||
#endif
|
||||
|
||||
#if (ALT_TIMESTAMP_COUNTER_SIZE == 64)
|
||||
#define alt_timestamp_type alt_u64
|
||||
#else
|
||||
#define alt_timestamp_type alt_u32
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The function alt_avalon_timer_sc_init() is the initialisation function for
|
||||
* the system clock. It registers the timers interrupt handler, and then calls
|
||||
* the system clock regestration function, alt_sysclk_init().
|
||||
*/
|
||||
|
||||
extern void alt_avalon_timer_sc_init (void* base, alt_u32 irq_controller_id,
|
||||
alt_u32 irq, alt_u32 freq);
|
||||
|
||||
/*
|
||||
* Variables used to store the timestamp parameters, when the device is to be
|
||||
* accessed using the high resolution timestamp driver.
|
||||
*/
|
||||
|
||||
extern void* altera_avalon_timer_ts_base;
|
||||
extern alt_u32 altera_avalon_timer_ts_freq;
|
||||
|
||||
/*
|
||||
* ALTERA_AVALON_TIMER_INSTANCE is the macro used by alt_sys_init() to
|
||||
* allocate any per device memory that may be required. In this case no
|
||||
* allocation is necessary.
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_TIMER_INSTANCE(name, dev) extern int alt_no_storage
|
||||
|
||||
/*
|
||||
* Macro used to calculate the timer interrupt frequency. Although this is
|
||||
* somewhat fearsome, when compiled with -O2 it will be resolved at compile
|
||||
* time to a constant value.
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_TIMER_FREQ(freq, period, units) \
|
||||
strcmp (units, "us") ? \
|
||||
(strcmp (units, "ms") ? \
|
||||
(strcmp (units, "s") ? \
|
||||
((freq + (period - 1))/period) \
|
||||
: 1) \
|
||||
: (1000 + (period - 1))/period) \
|
||||
: ((1000000 + (period - 1))/period)
|
||||
|
||||
/*
|
||||
* Construct macros which contain the base address of the system clock and the
|
||||
* timestamp device. These are used below to determine which driver to use for
|
||||
* a given timer.
|
||||
*/
|
||||
|
||||
#define __ALT_CLK_BASE(name) name##_BASE
|
||||
#define _ALT_CLK_BASE(name) __ALT_CLK_BASE(name)
|
||||
|
||||
#define ALT_SYS_CLK_BASE _ALT_CLK_BASE(ALT_SYS_CLK)
|
||||
#define ALT_TIMESTAMP_CLK_BASE _ALT_CLK_BASE(ALT_TIMESTAMP_CLK)
|
||||
|
||||
/*
|
||||
* If there is no system clock, then the above macro will result in
|
||||
* ALT_SYS_CLK_BASE being set to none_BASE. We therefore need to provide an
|
||||
* invalid value for this, so that no timer is wrongly identified as the system
|
||||
* clock.
|
||||
*/
|
||||
|
||||
#define none_BASE 0xffffffff
|
||||
|
||||
/*
|
||||
* ALTERA_AVALON_TIMER_INIT is the macro used by alt_sys_init() to provide
|
||||
* the run time initialisation of the device. In this case this translates to
|
||||
* a call to alt_avalon_timer_sc_init() if the device is the system clock, i.e.
|
||||
* if it has the name "sysclk".
|
||||
*
|
||||
* If the device is not the system clock, then it is used to provide the
|
||||
* timestamp facility.
|
||||
*
|
||||
* To ensure as much as possible is evaluated at compile time, rather than
|
||||
* compare the name of the device to "/dev/sysclk" using strcmp(), the base
|
||||
* address of the device is compared to SYSCLK_BASE to determine whether it's
|
||||
* the system clock. Since the base address of a device must be unique, these
|
||||
* two aproaches are equivalent.
|
||||
*
|
||||
* This macro performs a sanity check to ensure that the interrupt has been
|
||||
* connected for this device. If not, then an apropriate error message is
|
||||
* generated at build time.
|
||||
*/
|
||||
|
||||
|
||||
#define ALTERA_AVALON_TIMER_INIT(name, dev) \
|
||||
if (name##_BASE == ALT_SYS_CLK_BASE) \
|
||||
{ \
|
||||
if (name##_IRQ == ALT_IRQ_NOT_CONNECTED) \
|
||||
{ \
|
||||
ALT_LINK_ERROR ("Error: Interrupt not connected for " #dev ". " \
|
||||
"The system clock driver requires an interrupt to be " \
|
||||
"connected. Please select an IRQ for this device in " \
|
||||
"SOPC builder."); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
alt_avalon_timer_sc_init((void*) name##_BASE, \
|
||||
name##_IRQ_INTERRUPT_CONTROLLER_ID, \
|
||||
name##_IRQ, \
|
||||
ALTERA_AVALON_TIMER_FREQ(name##_FREQ, \
|
||||
name##_PERIOD, \
|
||||
name##_PERIOD_UNITS));\
|
||||
} \
|
||||
} \
|
||||
else if (name##_BASE == ALT_TIMESTAMP_CLK_BASE) \
|
||||
{ \
|
||||
if (name##_SNAPSHOT) \
|
||||
{ \
|
||||
altera_avalon_timer_ts_base = (void*) name##_BASE; \
|
||||
altera_avalon_timer_ts_freq = name##_FREQ; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ALT_LINK_ERROR ("Error: Snapshot register not available for " \
|
||||
#dev ". " \
|
||||
"The timestamp driver requires the snapshot register " \
|
||||
"to be readable. Please enable this register for this " \
|
||||
"device in SOPC builder."); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_AVALON_TIMER_H__ */
|
|
@ -1,5 +0,0 @@
|
|||
zephyr_sources(
|
||||
altera_avalon_timer_sc.c
|
||||
altera_avalon_timer_ts.c
|
||||
altera_avalon_timer_vars.c
|
||||
)
|
|
@ -1,108 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "sys/alt_alarm.h"
|
||||
#include "sys/alt_irq.h"
|
||||
|
||||
#include "altera_avalon_timer.h"
|
||||
#include "altera_avalon_timer_regs.h"
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "sys/alt_log_printf.h"
|
||||
|
||||
/*
|
||||
* alt_avalon_timer_sc_irq() is the interrupt handler used for the system
|
||||
* clock. This is called periodically when a timer interrupt occurs. The
|
||||
* function first clears the interrupt condition, and then calls the
|
||||
* alt_tick() function to notify the system that a timer tick has occurred.
|
||||
*
|
||||
* alt_tick() increments the system tick count, and updates any registered
|
||||
* alarms, see alt_tick.c for further details.
|
||||
*/
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
static void alt_avalon_timer_sc_irq (void* base)
|
||||
#else
|
||||
static void alt_avalon_timer_sc_irq (void* base, alt_u32 id)
|
||||
#endif
|
||||
{
|
||||
alt_irq_context cpu_sr;
|
||||
|
||||
/* clear the interrupt */
|
||||
IOWR_ALTERA_AVALON_TIMER_STATUS (base, 0);
|
||||
|
||||
/*
|
||||
* Dummy read to ensure IRQ is negated before the ISR returns.
|
||||
* The control register is read because reading the status
|
||||
* register has side-effects per the register map documentation.
|
||||
*/
|
||||
IORD_ALTERA_AVALON_TIMER_CONTROL (base);
|
||||
|
||||
/* ALT_LOG - see altera_hal/HAL/inc/sys/alt_log_printf.h */
|
||||
ALT_LOG_SYS_CLK_HEARTBEAT();
|
||||
|
||||
/*
|
||||
* Notify the system of a clock tick. disable interrupts
|
||||
* during this time to safely support ISR preemption
|
||||
*/
|
||||
cpu_sr = alt_irq_disable_all();
|
||||
alt_tick ();
|
||||
alt_irq_enable_all(cpu_sr);
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_avalon_timer_sc_init() is called to initialise the timer that will be
|
||||
* used to provide the periodic system clock. This is called from the
|
||||
* auto-generated alt_sys_init() function.
|
||||
*/
|
||||
|
||||
void alt_avalon_timer_sc_init (void* base, alt_u32 irq_controller_id,
|
||||
alt_u32 irq, alt_u32 freq)
|
||||
{
|
||||
/* set the system clock frequency */
|
||||
|
||||
alt_sysclk_init (freq);
|
||||
|
||||
/* set to free running mode */
|
||||
|
||||
IOWR_ALTERA_AVALON_TIMER_CONTROL (base,
|
||||
ALTERA_AVALON_TIMER_CONTROL_ITO_MSK |
|
||||
ALTERA_AVALON_TIMER_CONTROL_CONT_MSK |
|
||||
ALTERA_AVALON_TIMER_CONTROL_START_MSK);
|
||||
|
||||
/* register the interrupt handler, and enable the interrupt */
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
alt_ic_isr_register(irq_controller_id, irq, alt_avalon_timer_sc_irq,
|
||||
base, NULL);
|
||||
#else
|
||||
alt_irq_register (irq, base, alt_avalon_timer_sc_irq);
|
||||
#endif
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "sys/alt_timestamp.h"
|
||||
|
||||
#include "altera_avalon_timer.h"
|
||||
#include "altera_avalon_timer_regs.h"
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
/*
|
||||
* These functions are only available if a timestamp device has been selected
|
||||
* for this system.
|
||||
*/
|
||||
|
||||
#if (ALT_TIMESTAMP_CLK_BASE != none_BASE)
|
||||
|
||||
/*
|
||||
* The function alt_timestamp_start() can be called at application level to
|
||||
* initialise the timestamp facility. In this case the period register is
|
||||
* set to full scale, i.e. 0xffffffff, and then started running. Note that
|
||||
* the period register may not be writable, depending on the hardware
|
||||
* configuration, in which case this function does not reset the period.
|
||||
*
|
||||
* The timer is not run in continuous mode, so that the user can detect timer
|
||||
* roll-over, i.e. alt_timestamp() returns 0.
|
||||
*
|
||||
* The return value of this function is 0 upon sucess and -1 if in timestamp
|
||||
* device has not been registered.
|
||||
*/
|
||||
|
||||
int alt_timestamp_start(void)
|
||||
{
|
||||
void* base = altera_avalon_timer_ts_base;
|
||||
|
||||
if (!altera_avalon_timer_ts_freq)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ALT_TIMESTAMP_COUNTER_SIZE == 64) {
|
||||
IOWR_ALTERA_AVALON_TIMER_CONTROL (base,ALTERA_AVALON_TIMER_CONTROL_STOP_MSK);
|
||||
IOWR_ALTERA_AVALON_TIMER_PERIOD_0 (base, 0xFFFF);
|
||||
IOWR_ALTERA_AVALON_TIMER_PERIOD_1 (base, 0xFFFF);;
|
||||
IOWR_ALTERA_AVALON_TIMER_PERIOD_2 (base, 0xFFFF);
|
||||
IOWR_ALTERA_AVALON_TIMER_PERIOD_3 (base, 0xFFFF);
|
||||
IOWR_ALTERA_AVALON_TIMER_CONTROL (base, ALTERA_AVALON_TIMER_CONTROL_START_MSK);
|
||||
} else {
|
||||
IOWR_ALTERA_AVALON_TIMER_CONTROL (base,ALTERA_AVALON_TIMER_CONTROL_STOP_MSK);
|
||||
IOWR_ALTERA_AVALON_TIMER_PERIODL (base, 0xFFFF);
|
||||
IOWR_ALTERA_AVALON_TIMER_PERIODH (base, 0xFFFF);
|
||||
IOWR_ALTERA_AVALON_TIMER_CONTROL (base, ALTERA_AVALON_TIMER_CONTROL_START_MSK);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* alt_timestamp() returns the current timestamp count. In the event that
|
||||
* the timer has run full period, or there is no timestamp available, this
|
||||
* function return -1.
|
||||
*
|
||||
* The returned timestamp counts up from the last time the period register
|
||||
* was reset.
|
||||
*/
|
||||
|
||||
alt_timestamp_type alt_timestamp(void)
|
||||
{
|
||||
|
||||
void* base = altera_avalon_timer_ts_base;
|
||||
|
||||
if (!altera_avalon_timer_ts_freq)
|
||||
{
|
||||
#if (ALT_TIMESTAMP_COUNTER_SIZE == 64)
|
||||
return 0xFFFFFFFFFFFFFFFFULL;
|
||||
#else
|
||||
return 0xFFFFFFFF;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (ALT_TIMESTAMP_COUNTER_SIZE == 64)
|
||||
IOWR_ALTERA_AVALON_TIMER_SNAP_0 (base, 0);
|
||||
alt_timestamp_type snap_0 = IORD_ALTERA_AVALON_TIMER_SNAP_0(base) & ALTERA_AVALON_TIMER_SNAP_0_MSK;
|
||||
alt_timestamp_type snap_1 = IORD_ALTERA_AVALON_TIMER_SNAP_1(base) & ALTERA_AVALON_TIMER_SNAP_1_MSK;
|
||||
alt_timestamp_type snap_2 = IORD_ALTERA_AVALON_TIMER_SNAP_2(base) & ALTERA_AVALON_TIMER_SNAP_2_MSK;
|
||||
alt_timestamp_type snap_3 = IORD_ALTERA_AVALON_TIMER_SNAP_3(base) & ALTERA_AVALON_TIMER_SNAP_3_MSK;
|
||||
|
||||
return (0xFFFFFFFFFFFFFFFFULL - ( (snap_3 << 48) | (snap_2 << 32) | (snap_1 << 16) | (snap_0) ));
|
||||
#else
|
||||
IOWR_ALTERA_AVALON_TIMER_SNAPL (base, 0);
|
||||
alt_timestamp_type lower = IORD_ALTERA_AVALON_TIMER_SNAPL(base) & ALTERA_AVALON_TIMER_SNAPL_MSK;
|
||||
alt_timestamp_type upper = IORD_ALTERA_AVALON_TIMER_SNAPH(base) & ALTERA_AVALON_TIMER_SNAPH_MSK;
|
||||
|
||||
return (0xFFFFFFFF - ((upper << 16) | lower));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the number of timestamp ticks per second. This will be 0 if no
|
||||
* timestamp device has been registered.
|
||||
*/
|
||||
|
||||
alt_u32 alt_timestamp_freq(void)
|
||||
{
|
||||
return altera_avalon_timer_ts_freq;
|
||||
}
|
||||
|
||||
#endif /* timestamp available */
|
|
@ -1,43 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
* Altera does not recommend, suggest or require that this reference design *
|
||||
* file be used in conjunction or combination with any other product. *
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "altera_avalon_timer.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
/*
|
||||
* Variables used to store the timestamp parameters. These are initialised
|
||||
* from alt_sys_init() using the ALTERA_AVALON_TIMER_INIT macro
|
||||
* defined in altera_avalon_timer.h.
|
||||
*/
|
||||
|
||||
void* altera_avalon_timer_ts_base = (void*) 0;
|
||||
alt_u32 altera_avalon_timer_ts_freq = 0;
|
|
@ -1,200 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_AVALON_TIMER_REGS_H__
|
||||
#define __ALTERA_AVALON_TIMER_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
/* STATUS register */
|
||||
#define ALTERA_AVALON_TIMER_STATUS_REG 0
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_STATUS(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_STATUS_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_STATUS(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_STATUS_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_STATUS(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_STATUS_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_STATUS_TO_MSK (0x1)
|
||||
#define ALTERA_AVALON_TIMER_STATUS_TO_OFST (0)
|
||||
#define ALTERA_AVALON_TIMER_STATUS_RUN_MSK (0x2)
|
||||
#define ALTERA_AVALON_TIMER_STATUS_RUN_OFST (1)
|
||||
|
||||
/* CONTROL register */
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_REG 1
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_CONTROL(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_CONTROL_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_CONTROL(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_CONTROL_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_CONTROL(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_CONTROL_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_ITO_MSK (0x1)
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_ITO_OFST (0)
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_CONT_MSK (0x2)
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_CONT_OFST (1)
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_START_MSK (0x4)
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_START_OFST (2)
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_STOP_MSK (0x8)
|
||||
#define ALTERA_AVALON_TIMER_CONTROL_STOP_OFST (3)
|
||||
|
||||
/* Period and SnapShot Register for COUNTER_SIZE = 32 */
|
||||
/*----------------------------------------------------*/
|
||||
/* PERIODL register */
|
||||
#define ALTERA_AVALON_TIMER_PERIODL_REG 2
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_PERIODL(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIODL_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_PERIODL(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_PERIODL_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_PERIODL(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_PERIODL_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_PERIODL_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_PERIODL_OFST (0)
|
||||
|
||||
/* PERIODH register */
|
||||
#define ALTERA_AVALON_TIMER_PERIODH_REG 3
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_PERIODH(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIODH_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_PERIODH(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_PERIODH_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_PERIODH(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_PERIODH_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_PERIODH_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_PERIODH_OFST (0)
|
||||
|
||||
/* SNAPL register */
|
||||
#define ALTERA_AVALON_TIMER_SNAPL_REG 4
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_SNAPL(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAPL_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_SNAPL(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_SNAPL_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_SNAPL(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_SNAPL_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_SNAPL_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_SNAPL_OFST (0)
|
||||
|
||||
/* SNAPH register */
|
||||
#define ALTERA_AVALON_TIMER_SNAPH_REG 5
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_SNAPH(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAPH_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_SNAPH(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_SNAPH_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_SNAPH(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_SNAPH_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_SNAPH_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_SNAPH_OFST (0)
|
||||
|
||||
/* Period and SnapShot Register for COUNTER_SIZE = 64 */
|
||||
/*----------------------------------------------------*/
|
||||
/* PERIOD_0 register */
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_0_REG 2
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_PERIOD_0(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIOD_0_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_PERIOD_0(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_PERIOD_0_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_PERIOD_0(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_PERIOD_0_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_0_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_0_OFST (0)
|
||||
|
||||
/* PERIOD_1 register */
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_1_REG 3
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_PERIOD_1(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIOD_1_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_PERIOD_1(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_PERIOD_1_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_PERIOD_1(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_PERIOD_1_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_1_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_1_OFST (0)
|
||||
|
||||
/* PERIOD_2 register */
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_2_REG 4
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_PERIOD_2(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIOD_2_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_PERIOD_2(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_PERIOD_2_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_PERIOD_2(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_PERIOD_2_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_2_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_2_OFST (0)
|
||||
|
||||
/* PERIOD_3 register */
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_3_REG 5
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_PERIOD_3(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIOD_3_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_PERIOD_3(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_PERIOD_3_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_PERIOD_3(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_PERIOD_3_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_3_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_PERIOD_3_OFST (0)
|
||||
|
||||
/* SNAP_0 register */
|
||||
#define ALTERA_AVALON_TIMER_SNAP_0_REG 6
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_SNAP_0(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAP_0_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_SNAP_0(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_SNAP_0_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_SNAP_0(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_SNAP_0_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_SNAP_0_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_SNAP_0_OFST (0)
|
||||
|
||||
/* SNAP_1 register */
|
||||
#define ALTERA_AVALON_TIMER_SNAP_1_REG 7
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_SNAP_1(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAP_1_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_SNAP_1(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_SNAP_1_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_SNAP_1(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_SNAP_1_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_SNAP_1_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_SNAP_1_OFST (0)
|
||||
|
||||
/* SNAP_2 register */
|
||||
#define ALTERA_AVALON_TIMER_SNAP_2_REG 8
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_SNAP_2(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAP_2_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_SNAP_2(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_SNAP_2_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_SNAP_2(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_SNAP_2_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_SNAP_2_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_SNAP_2_OFST (0)
|
||||
|
||||
/* SNAP_3 register */
|
||||
#define ALTERA_AVALON_TIMER_SNAP_3_REG 9
|
||||
#define IOADDR_ALTERA_AVALON_TIMER_SNAP_3(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAP_3_REG)
|
||||
#define IORD_ALTERA_AVALON_TIMER_SNAP_3(base) \
|
||||
IORD(base, ALTERA_AVALON_TIMER_SNAP_3_REG)
|
||||
#define IOWR_ALTERA_AVALON_TIMER_SNAP_3(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_TIMER_SNAP_3_REG, data)
|
||||
#define ALTERA_AVALON_TIMER_SNAP_3_MSK (0xFFFF)
|
||||
#define ALTERA_AVALON_TIMER_SNAP_3_OFST (0)
|
||||
|
||||
#endif /* __ALTERA_AVALON_TIMER_REGS_H__ */
|
|
@ -1,317 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_AVALON_UART_H__
|
||||
#define __ALT_AVALON_UART_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/termios.h>
|
||||
|
||||
#include "sys/alt_warning.h"
|
||||
|
||||
#include "os/alt_sem.h"
|
||||
#include "os/alt_flag.h"
|
||||
#include "alt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if defined(ALT_USE_SMALL_DRIVERS) || defined(ALTERA_AVALON_UART_SMALL)
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
*********************** SMALL DRIVER **********************************
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* State structure definition. Each instance of the driver uses one
|
||||
* of these structures to hold its associated state.
|
||||
*/
|
||||
|
||||
typedef struct altera_avalon_uart_state_s
|
||||
{
|
||||
unsigned int base;
|
||||
} altera_avalon_uart_state;
|
||||
|
||||
/*
|
||||
* The macro ALTERA_AVALON_UART_STATE_INSTANCE is used by the
|
||||
* auto-generated file alt_sys_init.c to create an instance of this
|
||||
* device driver state.
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_UART_STATE_INSTANCE(name, state) \
|
||||
altera_avalon_uart_state state = \
|
||||
{ \
|
||||
name##_BASE \
|
||||
}
|
||||
|
||||
/*
|
||||
* The macro ALTERA_AVALON_UART_STATE_INIT is used by the auto-generated file
|
||||
* alt_sys_init.c to initialize an instance of the device driver state.
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_UART_STATE_INIT(name, state)
|
||||
|
||||
#else /* fast driver */
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*********************** FAST DRIVER **********************************
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* ALT_AVALON_UART_READ_RDY and ALT_AVALON_UART_WRITE_RDY are the bitmasks
|
||||
* that define uC/OS-II event flags that are releated to this device.
|
||||
*
|
||||
* ALT_AVALON_UART_READY_RDY indicates that there is read data in the buffer
|
||||
* ready to be processed. ALT_UART_WRITE_RDY indicates that the transmitter is
|
||||
* ready for more data.
|
||||
*/
|
||||
|
||||
#define ALT_UART_READ_RDY 0x1
|
||||
#define ALT_UART_WRITE_RDY 0x2
|
||||
|
||||
/*
|
||||
* ALT_AVALON_UART_BUF_LEN is the length of the circular buffers used to hold
|
||||
* pending transmit and receive data. This value must be a power of two.
|
||||
*/
|
||||
|
||||
#define ALT_AVALON_UART_BUF_LEN (64)
|
||||
|
||||
/*
|
||||
* ALT_AVALON_UART_BUF_MSK is used as an internal convenience for detecting
|
||||
* the end of the arrays used to implement the transmit and receive buffers.
|
||||
*/
|
||||
|
||||
#define ALT_AVALON_UART_BUF_MSK (ALT_AVALON_UART_BUF_LEN - 1)
|
||||
|
||||
/*
|
||||
* This is somewhat of an ugly hack, but we need some mechanism for
|
||||
* representing the non-standard 9 bit mode provided by this UART. In this
|
||||
* case we abscond with the 5 bit mode setting. The value CS5 is defined in
|
||||
* termios.h.
|
||||
*/
|
||||
|
||||
#define CS9 CS5
|
||||
|
||||
/*
|
||||
* The value ALT_AVALON_UART_FB is a value set in the devices flag field to
|
||||
* indicate that the device has a fixed baud rate; i.e. if this flag is set
|
||||
* software can not control the baud rate of the device.
|
||||
*/
|
||||
|
||||
#define ALT_AVALON_UART_FB 0x1
|
||||
|
||||
/*
|
||||
* The value ALT_AVALON_UART_FC is a value set in the device flag field to
|
||||
* indicate the the device is using flow control, i.e. the driver must
|
||||
* throttle on transmit if the nCTS pin is low.
|
||||
*/
|
||||
|
||||
#define ALT_AVALON_UART_FC 0x2
|
||||
|
||||
/*
|
||||
* The altera_avalon_uart_state structure is used to hold device specific data.
|
||||
* This includes the transmit and receive buffers.
|
||||
*
|
||||
* An instance of this structure is created in the auto-generated
|
||||
* alt_sys_init.c file for each UART listed in the systems PTF file. This is
|
||||
* done using the ALTERA_AVALON_UART_STATE_INSTANCE macro given below.
|
||||
*/
|
||||
|
||||
typedef struct altera_avalon_uart_state_s
|
||||
{
|
||||
void* base; /* The base address of the device */
|
||||
alt_u32 ctrl; /* Shadow value of the control register */
|
||||
volatile alt_u32 rx_start; /* Start of the pending receive data */
|
||||
volatile alt_u32 rx_end; /* End of the pending receive data */
|
||||
volatile alt_u32 tx_start; /* Start of the pending transmit data */
|
||||
volatile alt_u32 tx_end; /* End of the pending transmit data */
|
||||
#ifdef ALTERA_AVALON_UART_USE_IOCTL
|
||||
struct termios termios; /* Current device configuration */
|
||||
alt_u32 freq; /* Current baud rate */
|
||||
#endif
|
||||
alt_u32 flags; /* Configuation flags */
|
||||
ALT_FLAG_GRP (events) /* Event flags used for
|
||||
* foreground/background in mult-threaded
|
||||
* mode */
|
||||
ALT_SEM (read_lock) /* Semaphore used to control access to the
|
||||
* read buffer in multi-threaded mode */
|
||||
ALT_SEM (write_lock) /* Semaphore used to control access to the
|
||||
* write buffer in multi-threaded mode */
|
||||
volatile alt_u8 rx_buf[ALT_AVALON_UART_BUF_LEN]; /* The receive buffer */
|
||||
volatile alt_u8 tx_buf[ALT_AVALON_UART_BUF_LEN]; /* The transmit buffer */
|
||||
} altera_avalon_uart_state;
|
||||
|
||||
/*
|
||||
* Conditionally define the data structures used to process ioctl requests.
|
||||
* The following macros are defined for use in creating a device instance:
|
||||
*
|
||||
* ALTERA_AVALON_UART_TERMIOS - Initialise the termios structure used to
|
||||
* describe the UART configuration.
|
||||
* ALTERA_AVALON_UART_FREQ - Initialise the 'freq' field of the device
|
||||
* structure, if the field exists.
|
||||
* ALTERA_AVALON_UART_IOCTL - Initialise the 'ioctl' field of the device
|
||||
* callback structure, if ioctls are enabled.
|
||||
*/
|
||||
|
||||
#ifdef ALTERA_AVALON_UART_USE_IOCTL
|
||||
|
||||
#define ALTERA_AVALON_UART_TERMIOS(stop_bits, \
|
||||
parity, \
|
||||
odd_parity, \
|
||||
data_bits, \
|
||||
ctsrts, \
|
||||
baud) \
|
||||
{ \
|
||||
0, \
|
||||
0, \
|
||||
((stop_bits == 2) ? CSTOPB: 0) | \
|
||||
((parity) ? PARENB: 0) | \
|
||||
((odd_parity) ? PAODD: 0) | \
|
||||
((data_bits == 7) ? CS7: (data_bits == 9) ? CS9: CS8) | \
|
||||
((ctsrts) ? CRTSCTS : 0), \
|
||||
0, \
|
||||
0, \
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \
|
||||
baud, \
|
||||
baud \
|
||||
},
|
||||
#define ALTERA_AVALON_UART_FREQ(name) name##_FREQ,
|
||||
|
||||
#else /* !ALTERA_AVALON_UART_USE_IOCTL */
|
||||
|
||||
#define ALTERA_AVALON_UART_TERMIOS(stop_bits, \
|
||||
parity, \
|
||||
odd_parity, \
|
||||
data_bits, \
|
||||
ctsrts, \
|
||||
baud)
|
||||
#define ALTERA_AVALON_UART_FREQ(name)
|
||||
|
||||
#endif /* ALTERA_AVALON_UART_USE_IOCTL */
|
||||
|
||||
/*
|
||||
* The macro ALTERA_AVALON_UART_INSTANCE is used by the auto-generated file
|
||||
* alt_sys_init.c to create an instance of this device driver state.
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_UART_STATE_INSTANCE(name, state) \
|
||||
altera_avalon_uart_state state = \
|
||||
{ \
|
||||
(void*) name##_BASE, \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
ALTERA_AVALON_UART_TERMIOS(name##_STOP_BITS, \
|
||||
(name##_PARITY == 'N'), \
|
||||
(name##_PARITY == 'O'), \
|
||||
name##_DATA_BITS, \
|
||||
name##_USE_CTS_RTS, \
|
||||
name##_BAUD) \
|
||||
ALTERA_AVALON_UART_FREQ(name) \
|
||||
(name##_FIXED_BAUD ? ALT_AVALON_UART_FB : 0) | \
|
||||
(name##_USE_CTS_RTS ? ALT_AVALON_UART_FC : 0) \
|
||||
}
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_init() is called by the auto-generated function
|
||||
* alt_sys_init() for each UART in the system. This is done using the
|
||||
* ALTERA_AVALON_UART_INIT macro given below.
|
||||
*
|
||||
* This function is responsible for performing all the run time initilisation
|
||||
* for a device instance, i.e. registering the interrupt handler, and
|
||||
* regestering the device with the system.
|
||||
*/
|
||||
extern void altera_avalon_uart_init(altera_avalon_uart_state* sp,
|
||||
alt_u32 irq_controller_id, alt_u32 irq);
|
||||
|
||||
/*
|
||||
* The macro ALTERA_AVALON_UART_STATE_INIT is used by the auto-generated file
|
||||
* alt_sys_init.c to initialize an instance of the device driver state.
|
||||
*
|
||||
* This macro performs a sanity check to ensure that the interrupt has been
|
||||
* connected for this device. If not, then an apropriate error message is
|
||||
* generated at build time.
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_UART_STATE_INIT(name, state) \
|
||||
if (name##_IRQ == ALT_IRQ_NOT_CONNECTED) \
|
||||
{ \
|
||||
ALT_LINK_ERROR ("Error: Interrupt not connected for " #name ". " \
|
||||
"You have selected the interrupt driven version of " \
|
||||
"the ALTERA Avalon UART driver, but the interrupt is " \
|
||||
"not connected for this device. You can select a " \
|
||||
"polled mode driver by checking the 'small driver' " \
|
||||
"option in the HAL configuration window, or by " \
|
||||
"using the -DALTERA_AVALON_UART_SMALL preprocessor " \
|
||||
"flag."); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
altera_avalon_uart_init(&state, name##_IRQ_INTERRUPT_CONTROLLER_ID, \
|
||||
name##_IRQ); \
|
||||
}
|
||||
|
||||
#endif /* small driver */
|
||||
|
||||
/*
|
||||
* Include in case non-direct version of driver required.
|
||||
*/
|
||||
#include "altera_avalon_uart_fd.h"
|
||||
|
||||
/*
|
||||
* Map alt_sys_init macros to direct or non-direct versions.
|
||||
*/
|
||||
#ifdef ALT_USE_DIRECT_DRIVERS
|
||||
|
||||
#define ALTERA_AVALON_UART_INSTANCE(name, state) \
|
||||
ALTERA_AVALON_UART_STATE_INSTANCE(name, state)
|
||||
#define ALTERA_AVALON_UART_INIT(name, state) \
|
||||
ALTERA_AVALON_UART_STATE_INIT(name, state)
|
||||
|
||||
#else /* !ALT_USE_DIRECT_DRIVERS */
|
||||
|
||||
#define ALTERA_AVALON_UART_INSTANCE(name, dev) \
|
||||
ALTERA_AVALON_UART_DEV_INSTANCE(name, dev)
|
||||
#define ALTERA_AVALON_UART_INIT(name, dev) \
|
||||
ALTERA_AVALON_UART_DEV_INIT(name, dev)
|
||||
|
||||
#endif /* ALT_USE_DIRECT_DRIVERS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_AVALON_UART_H__ */
|
|
@ -1,141 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2007 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_AVALON_UART_FD_H__
|
||||
#define __ALT_AVALON_UART_FD_H__
|
||||
|
||||
#include "sys/alt_dev.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* Externally referenced routines
|
||||
*/
|
||||
extern int altera_avalon_uart_read_fd (alt_fd* fd, char* ptr, int len);
|
||||
extern int altera_avalon_uart_write_fd (alt_fd* fd, const char* ptr,
|
||||
int len);
|
||||
|
||||
/*
|
||||
* Device structure definition. This is needed by alt_sys_init in order to
|
||||
* reserve memory for the device instance.
|
||||
*/
|
||||
typedef struct altera_avalon_uart_dev_s
|
||||
{
|
||||
alt_dev dev;
|
||||
altera_avalon_uart_state state;
|
||||
} altera_avalon_uart_dev;
|
||||
|
||||
#if defined(ALT_USE_SMALL_DRIVERS) || defined(ALTERA_AVALON_UART_SMALL)
|
||||
|
||||
/*
|
||||
* Macros used by alt_sys_init when the ALT file descriptor facility is used.
|
||||
*/
|
||||
|
||||
#define ALTERA_AVALON_UART_DEV_INSTANCE(name, d) \
|
||||
static altera_avalon_uart_dev d = \
|
||||
{ \
|
||||
{ \
|
||||
ALT_LLIST_ENTRY, \
|
||||
name##_NAME, \
|
||||
NULL, /* open */ \
|
||||
NULL, /* close */ \
|
||||
altera_avalon_uart_read_fd, \
|
||||
altera_avalon_uart_write_fd, \
|
||||
NULL, /* lseek */ \
|
||||
NULL, /* fstat */ \
|
||||
NULL, /* ioctl */ \
|
||||
}, \
|
||||
{ \
|
||||
name##_BASE, \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ALTERA_AVALON_UART_DEV_INIT(name, d) alt_dev_reg (&d.dev)
|
||||
|
||||
#else /* use fast version of the driver */
|
||||
|
||||
extern int altera_avalon_uart_ioctl_fd (alt_fd* fd, int req, void* arg);
|
||||
extern int altera_avalon_uart_close_fd(alt_fd* fd);
|
||||
|
||||
#ifdef ALTERA_AVALON_UART_USE_IOCTL
|
||||
#define ALTERA_AVALON_UART_IOCTL_FD altera_avalon_uart_ioctl_fd
|
||||
#else
|
||||
#define ALTERA_AVALON_UART_IOCTL_FD NULL
|
||||
#endif
|
||||
|
||||
#define ALTERA_AVALON_UART_DEV_INSTANCE(name, d) \
|
||||
static altera_avalon_uart_dev d = \
|
||||
{ \
|
||||
{ \
|
||||
ALT_LLIST_ENTRY, \
|
||||
name##_NAME, \
|
||||
NULL, /* open */ \
|
||||
altera_avalon_uart_close_fd, \
|
||||
altera_avalon_uart_read_fd, \
|
||||
altera_avalon_uart_write_fd, \
|
||||
NULL, /* lseek */ \
|
||||
NULL, /* fstat */ \
|
||||
ALTERA_AVALON_UART_IOCTL_FD, \
|
||||
}, \
|
||||
{ \
|
||||
(void*) name##_BASE, \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
ALTERA_AVALON_UART_TERMIOS(name##_STOP_BITS, \
|
||||
(name##_PARITY == 'N'), \
|
||||
(name##_PARITY == 'O'), \
|
||||
name##_DATA_BITS, \
|
||||
name##_USE_CTS_RTS, \
|
||||
name##_BAUD) \
|
||||
ALTERA_AVALON_UART_FREQ(name) \
|
||||
(name##_FIXED_BAUD ? ALT_AVALON_UART_FB : 0) | \
|
||||
(name##_USE_CTS_RTS ? ALT_AVALON_UART_FC : 0) \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ALTERA_AVALON_UART_DEV_INIT(name, d) \
|
||||
{ \
|
||||
ALTERA_AVALON_UART_STATE_INIT(name, d.state); \
|
||||
\
|
||||
/* make the device available to the system */ \
|
||||
alt_dev_reg(&d.dev); \
|
||||
}
|
||||
|
||||
#endif /* fast driver */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_AVALON_UART_FD_H__ */
|
|
@ -1,7 +0,0 @@
|
|||
zephyr_sources(
|
||||
altera_avalon_uart_fd.c
|
||||
altera_avalon_uart_init.c
|
||||
altera_avalon_uart_ioctl.c
|
||||
altera_avalon_uart_read.c
|
||||
altera_avalon_uart_write.c
|
||||
)
|
|
@ -1,98 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2007 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "sys/alt_dev.h"
|
||||
#include "altera_avalon_uart.h"
|
||||
|
||||
extern int altera_avalon_uart_read(altera_avalon_uart_state* sp,
|
||||
char* buffer, int space, int flags);
|
||||
extern int altera_avalon_uart_write(altera_avalon_uart_state* sp,
|
||||
const char* ptr, int count, int flags);
|
||||
extern int altera_avalon_uart_ioctl(altera_avalon_uart_state* sp,
|
||||
int req, void* arg);
|
||||
extern int altera_avalon_uart_close(altera_avalon_uart_state* sp, int flags);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* --------------------- WRAPPERS FOR ALT FD SUPPORT --------------------- */
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
altera_avalon_uart_read_fd(alt_fd* fd, char* buffer, int space)
|
||||
{
|
||||
altera_avalon_uart_dev* dev = (altera_avalon_uart_dev*) fd->dev;
|
||||
|
||||
return altera_avalon_uart_read(&dev->state, buffer, space,
|
||||
fd->fd_flags);
|
||||
}
|
||||
|
||||
int
|
||||
altera_avalon_uart_write_fd(alt_fd* fd, const char* buffer, int space)
|
||||
{
|
||||
altera_avalon_uart_dev* dev = (altera_avalon_uart_dev*) fd->dev;
|
||||
|
||||
return altera_avalon_uart_write(&dev->state, buffer, space,
|
||||
fd->fd_flags);
|
||||
}
|
||||
|
||||
#if !defined(ALT_USE_SMALL_DRIVERS) && !defined(ALTERA_AVALON_UART_SMALL)
|
||||
|
||||
/*
|
||||
* Fast driver
|
||||
*/
|
||||
|
||||
/*
|
||||
* To reduce the code footprint of this driver, the ioctl() function is not
|
||||
* included by default. If you wish to use the ioctl features provided
|
||||
* below, you can do so by adding the option : -DALTERA_AVALON_UART_USE_IOCTL
|
||||
* to CPPFLAGS in the Makefile (or through the Eclipse IDE).
|
||||
*/
|
||||
|
||||
#ifdef ALTERA_AVALON_UART_USE_IOCTL
|
||||
|
||||
int
|
||||
altera_avalon_uart_ioctl_fd(alt_fd* fd, int req, void* arg)
|
||||
{
|
||||
altera_avalon_uart_dev* dev = (altera_avalon_uart_dev*) fd->dev;
|
||||
|
||||
return altera_avalon_uart_ioctl(&dev->state, req, arg);
|
||||
}
|
||||
|
||||
#endif /* ALTERA_AVALON_UART_USE_IOCTL */
|
||||
|
||||
int
|
||||
altera_avalon_uart_close_fd(alt_fd* fd)
|
||||
{
|
||||
altera_avalon_uart_dev* dev = (altera_avalon_uart_dev*) fd->dev;
|
||||
|
||||
return altera_avalon_uart_close(&dev->state, fd->fd_flags);
|
||||
}
|
||||
|
||||
#endif /* fast driver */
|
|
@ -1,310 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2009 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "sys/alt_dev.h"
|
||||
#include "sys/alt_irq.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "sys/alt_errno.h"
|
||||
|
||||
#include "altera_avalon_uart.h"
|
||||
#include "altera_avalon_uart_regs.h"
|
||||
|
||||
#if !defined(ALT_USE_SMALL_DRIVERS) && !defined(ALTERA_AVALON_UART_SMALL)
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ------------------------- FAST DRIVER --------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_init() is called by the auto-generated function
|
||||
* alt_sys_init() in order to initialize a particular instance of this device.
|
||||
* It is responsible for configuring the device and associated software
|
||||
* constructs.
|
||||
*/
|
||||
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
static void altera_avalon_uart_irq(void* context);
|
||||
#else
|
||||
static void altera_avalon_uart_irq(void* context, alt_u32 id);
|
||||
#endif
|
||||
|
||||
static void altera_avalon_uart_rxirq(altera_avalon_uart_state* sp,
|
||||
alt_u32 status);
|
||||
static void altera_avalon_uart_txirq(altera_avalon_uart_state* sp,
|
||||
alt_u32 status);
|
||||
|
||||
void
|
||||
altera_avalon_uart_init(altera_avalon_uart_state* sp,
|
||||
alt_u32 irq_controller_id, alt_u32 irq)
|
||||
{
|
||||
void* base = sp->base;
|
||||
int error;
|
||||
|
||||
/*
|
||||
* Initialise the read and write flags and the semaphores used to
|
||||
* protect access to the circular buffers when running in a multi-threaded
|
||||
* environment.
|
||||
*/
|
||||
error = ALT_FLAG_CREATE (&sp->events, 0) ||
|
||||
ALT_SEM_CREATE (&sp->read_lock, 1) ||
|
||||
ALT_SEM_CREATE (&sp->write_lock, 1);
|
||||
|
||||
if (!error)
|
||||
{
|
||||
/* enable interrupts at the device */
|
||||
sp->ctrl = ALTERA_AVALON_UART_CONTROL_RTS_MSK |
|
||||
ALTERA_AVALON_UART_CONTROL_RRDY_MSK |
|
||||
ALTERA_AVALON_UART_CONTROL_DCTS_MSK;
|
||||
|
||||
IOWR_ALTERA_AVALON_UART_CONTROL(base, sp->ctrl);
|
||||
|
||||
/* register the interrupt handler */
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
alt_ic_isr_register(irq_controller_id, irq, altera_avalon_uart_irq, sp,
|
||||
0x0);
|
||||
#else
|
||||
alt_irq_register (irq, sp, altera_avalon_uart_irq);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_irq() is the interrupt handler registered at
|
||||
* configuration time for processing UART interrupts. It vectors
|
||||
* interrupt requests to either altera_avalon_uart_rxirq() (for incoming
|
||||
* data), or altera_avalon_uart_txirq() (for outgoing data).
|
||||
*/
|
||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
||||
static void altera_avalon_uart_irq(void* context)
|
||||
#else
|
||||
static void altera_avalon_uart_irq(void* context, alt_u32 id)
|
||||
#endif
|
||||
{
|
||||
alt_u32 status;
|
||||
|
||||
altera_avalon_uart_state* sp = (altera_avalon_uart_state*) context;
|
||||
void* base = sp->base;
|
||||
|
||||
/*
|
||||
* Read the status register in order to determine the cause of the
|
||||
* interrupt.
|
||||
*/
|
||||
|
||||
status = IORD_ALTERA_AVALON_UART_STATUS(base);
|
||||
|
||||
/* Clear any error flags set at the device */
|
||||
IOWR_ALTERA_AVALON_UART_STATUS(base, 0);
|
||||
|
||||
/* Dummy read to ensure IRQ is negated before ISR returns */
|
||||
IORD_ALTERA_AVALON_UART_STATUS(base);
|
||||
|
||||
/* process a read irq */
|
||||
if (status & ALTERA_AVALON_UART_STATUS_RRDY_MSK)
|
||||
{
|
||||
altera_avalon_uart_rxirq(sp, status);
|
||||
}
|
||||
|
||||
/* process a write irq */
|
||||
if (status & (ALTERA_AVALON_UART_STATUS_TRDY_MSK |
|
||||
ALTERA_AVALON_UART_STATUS_DCTS_MSK))
|
||||
{
|
||||
altera_avalon_uart_txirq(sp, status);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_rxirq() is called by altera_avalon_uart_irq() to
|
||||
* process a receive interrupt. It transfers the incoming character into
|
||||
* the receive circular buffer, and sets the apropriate flags to indicate
|
||||
* that there is data ready to be processed.
|
||||
*/
|
||||
static void
|
||||
altera_avalon_uart_rxirq(altera_avalon_uart_state* sp, alt_u32 status)
|
||||
{
|
||||
alt_u32 next;
|
||||
|
||||
/* If there was an error, discard the data */
|
||||
|
||||
if (status & (ALTERA_AVALON_UART_STATUS_PE_MSK |
|
||||
ALTERA_AVALON_UART_STATUS_FE_MSK))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* In a multi-threaded environment, set the read event flag to indicate
|
||||
* that there is data ready. This is only done if the circular buffer was
|
||||
* previously empty.
|
||||
*/
|
||||
|
||||
if (sp->rx_end == sp->rx_start)
|
||||
{
|
||||
ALT_FLAG_POST (sp->events, ALT_UART_READ_RDY, OS_FLAG_SET);
|
||||
}
|
||||
|
||||
/* Determine which slot to use next in the circular buffer */
|
||||
|
||||
next = (sp->rx_end + 1) & ALT_AVALON_UART_BUF_MSK;
|
||||
|
||||
/* Transfer data from the device to the circular buffer */
|
||||
|
||||
sp->rx_buf[sp->rx_end] = IORD_ALTERA_AVALON_UART_RXDATA(sp->base);
|
||||
|
||||
sp->rx_end = next;
|
||||
|
||||
next = (sp->rx_end + 1) & ALT_AVALON_UART_BUF_MSK;
|
||||
|
||||
/*
|
||||
* If the cicular buffer was full, disable interrupts. Interrupts will be
|
||||
* re-enabled when data is removed from the buffer.
|
||||
*/
|
||||
|
||||
if (next == sp->rx_start)
|
||||
{
|
||||
sp->ctrl &= ~ALTERA_AVALON_UART_CONTROL_RRDY_MSK;
|
||||
IOWR_ALTERA_AVALON_UART_CONTROL(sp->base, sp->ctrl);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_txirq() is called by altera_avalon_uart_irq() to
|
||||
* process a transmit interrupt. It transfers data from the transmit
|
||||
* buffer to the device, and sets the apropriate flags to indicate that
|
||||
* there is data ready to be processed.
|
||||
*/
|
||||
static void
|
||||
altera_avalon_uart_txirq(altera_avalon_uart_state* sp, alt_u32 status)
|
||||
{
|
||||
/* Transfer data if there is some ready to be transfered */
|
||||
|
||||
if (sp->tx_start != sp->tx_end)
|
||||
{
|
||||
/*
|
||||
* If the device is using flow control (i.e. RTS/CTS), then the
|
||||
* transmitter is required to throttle if CTS is high.
|
||||
*/
|
||||
|
||||
if (!(sp->flags & ALT_AVALON_UART_FC) ||
|
||||
(status & ALTERA_AVALON_UART_STATUS_CTS_MSK))
|
||||
{
|
||||
|
||||
/*
|
||||
* In a multi-threaded environment, set the write event flag to indicate
|
||||
* that there is space in the circular buffer. This is only done if the
|
||||
* buffer was previously empty.
|
||||
*/
|
||||
|
||||
if (sp->tx_start == ((sp->tx_end + 1) & ALT_AVALON_UART_BUF_MSK))
|
||||
{
|
||||
ALT_FLAG_POST (sp->events,
|
||||
ALT_UART_WRITE_RDY,
|
||||
OS_FLAG_SET);
|
||||
}
|
||||
|
||||
/* Write the data to the device */
|
||||
|
||||
IOWR_ALTERA_AVALON_UART_TXDATA(sp->base, sp->tx_buf[sp->tx_start]);
|
||||
|
||||
sp->tx_start = (++sp->tx_start) & ALT_AVALON_UART_BUF_MSK;
|
||||
|
||||
/*
|
||||
* In case the tranmit interrupt had previously been disabled by
|
||||
* detecting a low value on CTS, it is reenabled here.
|
||||
*/
|
||||
|
||||
sp->ctrl |= ALTERA_AVALON_UART_CONTROL_TRDY_MSK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* CTS is low and we are using flow control, so disable the transmit
|
||||
* interrupt while we wait for CTS to go high again. This will be
|
||||
* detected using the DCTS interrupt.
|
||||
*
|
||||
* There is a race condition here. "status" may indicate that
|
||||
* CTS is low, but it actually went high before DCTS was cleared on
|
||||
* the last write to the status register. To avoid this resulting in
|
||||
* deadlock, it's necessary to re-check the status register here
|
||||
* before throttling.
|
||||
*/
|
||||
|
||||
status = IORD_ALTERA_AVALON_UART_STATUS(sp->base);
|
||||
|
||||
if (!(status & ALTERA_AVALON_UART_STATUS_CTS_MSK))
|
||||
{
|
||||
sp->ctrl &= ~ALTERA_AVALON_UART_CONTROL_TRDY_MSK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the circular buffer is empty, disable the interrupt. This will be
|
||||
* re-enabled when new data is placed in the buffer.
|
||||
*/
|
||||
|
||||
if (sp->tx_start == sp->tx_end)
|
||||
{
|
||||
sp->ctrl &= ~(ALTERA_AVALON_UART_CONTROL_TRDY_MSK |
|
||||
ALTERA_AVALON_UART_CONTROL_DCTS_MSK);
|
||||
}
|
||||
|
||||
IOWR_ALTERA_AVALON_UART_CONTROL(sp->base, sp->ctrl);
|
||||
}
|
||||
|
||||
/*
|
||||
* The close() routine is implemented to drain the UART transmit buffer
|
||||
* when not in "small" mode. This routine will wait for transimt data to be
|
||||
* emptied unless the driver flags have been set to non-blocking mode.
|
||||
* This routine should be called indirectly (i.e. though the C library
|
||||
* close() routine) so that the file descriptor associated with the relevant
|
||||
* stream (i.e. stdout) can be closed as well. This routine does not manage
|
||||
* file descriptors.
|
||||
*
|
||||
* The close routine is not implemented for the small driver; instead it will
|
||||
* map to null. This is because the small driver simply waits while characters
|
||||
* are transmitted; there is no interrupt-serviced buffer to empty
|
||||
*/
|
||||
int altera_avalon_uart_close(altera_avalon_uart_state* sp, int flags)
|
||||
{
|
||||
/*
|
||||
* Wait for all transmit data to be emptied by the UART ISR.
|
||||
*/
|
||||
while (sp->tx_start != sp->tx_end) {
|
||||
if (flags & O_NONBLOCK) {
|
||||
return -EWOULDBLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* fast driver */
|
|
@ -1,151 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sys/alt_irq.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "sys/alt_errno.h"
|
||||
|
||||
#include "altera_avalon_uart_regs.h"
|
||||
#include "altera_avalon_uart.h"
|
||||
|
||||
|
||||
#if !defined(ALT_USE_SMALL_DRIVERS) && !defined(ALTERA_AVALON_UART_SMALL)
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ------------------------- FAST DRIVER --------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* To reduce the code footprint of this driver, the ioctl() function is not
|
||||
* included by default. If you wish to use the ioctl features provided
|
||||
* below, you can do so by adding the option : -DALTERA_AVALON_UART_USE_IOCTL
|
||||
* to CPPFLAGS in the Makefile (or through the Eclipse IDE).
|
||||
*/
|
||||
|
||||
#ifdef ALTERA_AVALON_UART_USE_IOCTL
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_ioctl() is called by the system ioctl() function to handle
|
||||
* ioctl requests for the UART. The only ioctl requests supported are TIOCMGET
|
||||
* and TIOCMSET.
|
||||
*
|
||||
* TIOCMGET returns a termios structure that describes the current device
|
||||
* configuration.
|
||||
*
|
||||
* TIOCMSET sets the device (if possible) to match the requested configuration.
|
||||
* The requested configuration is described using a termios structure passed
|
||||
* through the input argument "arg".
|
||||
*/
|
||||
|
||||
static int altera_avalon_uart_tiocmget(altera_avalon_uart_state* sp,
|
||||
struct termios* term);
|
||||
static int altera_avalon_uart_tiocmset(altera_avalon_uart_state* sp,
|
||||
struct termios* term);
|
||||
|
||||
int
|
||||
altera_avalon_uart_ioctl(altera_avalon_uart_state* sp, int req, void* arg)
|
||||
{
|
||||
int rc = -ENOTTY;
|
||||
|
||||
switch (req)
|
||||
{
|
||||
case TIOCMGET:
|
||||
rc = altera_avalon_uart_tiocmget(sp, (struct termios*) arg);
|
||||
break;
|
||||
case TIOCMSET:
|
||||
rc = altera_avalon_uart_tiocmset(sp, (struct termios*) arg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_tiocmget() is used by altera_avalon_uart_ioctl() to fill
|
||||
* in the input termios structure with the current device configuration.
|
||||
*
|
||||
* See termios.h for further details on the contents of the termios structure.
|
||||
*/
|
||||
|
||||
static int
|
||||
altera_avalon_uart_tiocmget(altera_avalon_uart_state* sp,
|
||||
struct termios* term)
|
||||
{
|
||||
memcpy (term, &sp->termios, sizeof (struct termios));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_tiocmset() is used by altera_avalon_uart_ioctl() to
|
||||
* configure the device according to the settings in the input termios
|
||||
* structure. In practice the only configuration that can be changed is the
|
||||
* baud rate, and then only if the hardware is configured to have a writable
|
||||
* baud register.
|
||||
*/
|
||||
|
||||
static int
|
||||
altera_avalon_uart_tiocmset(altera_avalon_uart_state* sp,
|
||||
struct termios* term)
|
||||
{
|
||||
speed_t speed;
|
||||
|
||||
speed = sp->termios.c_ispeed;
|
||||
|
||||
/* Update the settings if the hardware supports it */
|
||||
|
||||
if (!(sp->flags & ALT_AVALON_UART_FB))
|
||||
{
|
||||
sp->termios.c_ispeed = sp->termios.c_ospeed = term->c_ispeed;
|
||||
}
|
||||
/*
|
||||
* If the request was for an unsupported setting, return an error.
|
||||
*/
|
||||
|
||||
if (memcmp(term, &sp->termios, sizeof (struct termios)))
|
||||
{
|
||||
sp->termios.c_ispeed = sp->termios.c_ospeed = speed;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/*
|
||||
* Otherwise, update the hardware.
|
||||
*/
|
||||
|
||||
IOWR_ALTERA_AVALON_UART_DIVISOR(sp->base,
|
||||
((sp->freq/sp->termios.c_ispeed) - 1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* ALTERA_AVALON_UART_USE_IOCTL */
|
||||
|
||||
#endif /* fast driver */
|
|
@ -1,238 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "sys/alt_irq.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "sys/alt_errno.h"
|
||||
|
||||
#include "altera_avalon_uart.h"
|
||||
#include "altera_avalon_uart_regs.h"
|
||||
|
||||
#if defined(ALT_USE_SMALL_DRIVERS) || defined(ALTERA_AVALON_UART_SMALL)
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ----------------------- SMALL DRIVER ---------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_read() is called by the system read() function in order to
|
||||
* read a block of data from the UART. "len" is the maximum length of the data
|
||||
* to read, and "ptr" indicates the destination address. "fd" is the file
|
||||
* descriptor for the device to be read from.
|
||||
*
|
||||
* Permission checks are made before the call to altera_avalon_uart_read(), so
|
||||
* we know that the file descriptor has been opened with the correct permissions
|
||||
* for this operation.
|
||||
*
|
||||
* The return value is the number of bytes actually read.
|
||||
*
|
||||
* This implementation polls the device waiting for characters. At most it can
|
||||
* only return one character, regardless of how many are requested. If the
|
||||
* device is being accessed in non-blocking mode then it is possible for this
|
||||
* function to return without reading any characters. In this case errno is
|
||||
* set to EWOULDBLOCK.
|
||||
*/
|
||||
|
||||
int
|
||||
altera_avalon_uart_read(altera_avalon_uart_state* sp, char* ptr, int len,
|
||||
int flags)
|
||||
{
|
||||
int block;
|
||||
unsigned int status;
|
||||
|
||||
block = !(flags & O_NONBLOCK);
|
||||
|
||||
do
|
||||
{
|
||||
status = IORD_ALTERA_AVALON_UART_STATUS(sp->base);
|
||||
|
||||
/* clear any error flags */
|
||||
|
||||
IOWR_ALTERA_AVALON_UART_STATUS(sp->base, 0);
|
||||
|
||||
if (status & ALTERA_AVALON_UART_CONTROL_RRDY_MSK)
|
||||
{
|
||||
ptr[0] = IORD_ALTERA_AVALON_UART_RXDATA(sp->base);
|
||||
|
||||
if (!(status & (ALTERA_AVALON_UART_STATUS_PE_MSK |
|
||||
ALTERA_AVALON_UART_STATUS_FE_MSK)))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (block);
|
||||
|
||||
ALT_ERRNO = EWOULDBLOCK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ----------------------- FAST DRIVER ----------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_read() is called by the system read() function in order to
|
||||
* read a block of data from the UART. "len" is the maximum length of the data
|
||||
* to read, and "ptr" indicates the destination address. "sp" is the state
|
||||
* pointer for the device to be read from.
|
||||
*
|
||||
* Permission checks are made before the call to altera_avalon_uart_read(), so
|
||||
* we know that the file descriptor has been opened with the correct permissions
|
||||
* for this operation.
|
||||
*
|
||||
* The return value is the number of bytes actually read.
|
||||
*
|
||||
* This function does not communicate with the device directly. Instead data is
|
||||
* transfered from a circular buffer. The interrupt handler is then responsible
|
||||
* for copying data from the device into this buffer.
|
||||
*/
|
||||
|
||||
int
|
||||
altera_avalon_uart_read(altera_avalon_uart_state* sp, char* ptr, int len,
|
||||
int flags)
|
||||
{
|
||||
alt_irq_context context;
|
||||
int block;
|
||||
alt_u8 read_would_block = 0;
|
||||
int count = 0;
|
||||
|
||||
/*
|
||||
* Construct a flag to indicate whether the device is being accessed in
|
||||
* blocking or non-blocking mode.
|
||||
*/
|
||||
|
||||
block = !(flags & O_NONBLOCK);
|
||||
|
||||
/*
|
||||
* When running in a multi threaded environment, obtain the "read_lock"
|
||||
* semaphore. This ensures that reading from the device is thread-safe.
|
||||
*/
|
||||
|
||||
ALT_SEM_PEND (sp->read_lock, 0);
|
||||
|
||||
/*
|
||||
* Loop, copying data from the circular buffer to the destination address
|
||||
* supplied in "ptr". This loop is terminated when the required number of
|
||||
* bytes have been read. If the circular buffer is empty, and no data has
|
||||
* been read, then the loop will block (when in blocking mode).
|
||||
*
|
||||
* If the circular buffer is empty, and some data has already been
|
||||
* transferred, or the device is being accessed in non-blocking mode, then
|
||||
* the loop terminates without necessarily reading all the requested data.
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
/*
|
||||
* Read the required amount of data, until the circular buffer runs
|
||||
* empty
|
||||
*/
|
||||
|
||||
while ((count < len) && (sp->rx_start != sp->rx_end))
|
||||
{
|
||||
count++;
|
||||
*ptr++ = sp->rx_buf[sp->rx_start];
|
||||
|
||||
sp->rx_start = (sp->rx_start+1) & ALT_AVALON_UART_BUF_MSK;
|
||||
}
|
||||
|
||||
/*
|
||||
* If no data has been transferred, the circular buffer is empty, and
|
||||
* this is not a non-blocking access, block waiting for data to arrive.
|
||||
*/
|
||||
|
||||
if (!count && (sp->rx_start == sp->rx_end))
|
||||
{
|
||||
if (!block)
|
||||
{
|
||||
/* Set errno to indicate the reason we're not returning any data */
|
||||
|
||||
ALT_ERRNO = EWOULDBLOCK;
|
||||
read_would_block = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Block waiting for some data to arrive */
|
||||
|
||||
/* First, ensure read interrupts are enabled to avoid deadlock */
|
||||
|
||||
context = alt_irq_disable_all ();
|
||||
sp->ctrl |= ALTERA_AVALON_UART_CONTROL_RRDY_MSK;
|
||||
IOWR_ALTERA_AVALON_UART_CONTROL(sp->base, sp->ctrl);
|
||||
alt_irq_enable_all (context);
|
||||
|
||||
/*
|
||||
* When running in a multi-threaded mode, we pend on the read event
|
||||
* flag set in the interrupt service routine. This avoids wasting CPU
|
||||
* cycles waiting in this thread, when we could be doing something more
|
||||
* profitable elsewhere.
|
||||
*/
|
||||
|
||||
ALT_FLAG_PEND (sp->events,
|
||||
ALT_UART_READ_RDY,
|
||||
OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME,
|
||||
0);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!count && len);
|
||||
|
||||
/*
|
||||
* Now that access to the circular buffer is complete, release the read
|
||||
* semaphore so that other threads can access the buffer.
|
||||
*/
|
||||
|
||||
ALT_SEM_POST (sp->read_lock);
|
||||
|
||||
/*
|
||||
* Ensure that interrupts are enabled, so that the circular buffer can
|
||||
* re-fill.
|
||||
*/
|
||||
|
||||
context = alt_irq_disable_all ();
|
||||
sp->ctrl |= ALTERA_AVALON_UART_CONTROL_RRDY_MSK;
|
||||
IOWR_ALTERA_AVALON_UART_CONTROL(sp->base, sp->ctrl);
|
||||
alt_irq_enable_all (context);
|
||||
|
||||
/* Return the number of bytes read */
|
||||
if(read_would_block) {
|
||||
return -EWOULDBLOCK;
|
||||
}
|
||||
else {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* fast driver */
|
|
@ -1,230 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "sys/alt_dev.h"
|
||||
#include "sys/alt_irq.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "sys/alt_errno.h"
|
||||
|
||||
#include "altera_avalon_uart_regs.h"
|
||||
#include "altera_avalon_uart.h"
|
||||
|
||||
#if defined(ALT_USE_SMALL_DRIVERS) || defined(ALTERA_AVALON_UART_SMALL)
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ------------------------ SMALL DRIVER --------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_write() is called by the system write() function in
|
||||
* order to write a block of data to the UART.
|
||||
* "len" is the length of the data to write,
|
||||
* and "ptr" indicates the source address. "fd" is the file descriptor for the
|
||||
* device to be read from.
|
||||
*
|
||||
* Permission checks are made before the call to altera_avalon_uart_write(), so
|
||||
* we know that the file descriptor has been opened with the correct permissions
|
||||
* for this operation.
|
||||
*
|
||||
* The return value is the number of bytes actually written.
|
||||
*
|
||||
* This function will block on the devices transmit register, until all
|
||||
* characters have been transmitted. This is unless the device is being
|
||||
* accessed in non-blocking mode. In this case this function will return as
|
||||
* soon as the device reports that it is not ready to transmit.
|
||||
*
|
||||
* Since this is the small footprint version of the UART driver, the value of
|
||||
* CTS is ignored.
|
||||
*/
|
||||
|
||||
int
|
||||
altera_avalon_uart_write(altera_avalon_uart_state* sp, const char* ptr, int len,
|
||||
int flags)
|
||||
{
|
||||
int block;
|
||||
unsigned int status;
|
||||
int count;
|
||||
|
||||
block = !(flags & O_NONBLOCK);
|
||||
count = len;
|
||||
|
||||
do
|
||||
{
|
||||
status = IORD_ALTERA_AVALON_UART_STATUS(sp->base);
|
||||
|
||||
if (status & ALTERA_AVALON_UART_STATUS_TRDY_MSK)
|
||||
{
|
||||
IOWR_ALTERA_AVALON_UART_TXDATA(sp->base, *ptr++);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
while (block && count);
|
||||
|
||||
if (count)
|
||||
{
|
||||
ALT_ERRNO = EWOULDBLOCK;
|
||||
}
|
||||
|
||||
return (len - count);
|
||||
}
|
||||
|
||||
#else /* Using the "fast" version of the driver */
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/* ------------------------- FAST DRIVER --------------------- */
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* altera_avalon_uart_write() is called by the system write() function in order
|
||||
* to write a block of data to the UART. "len" is the length of the data to
|
||||
* write, and "ptr" indicates the source address. "sp" is the state pointer
|
||||
* for the device to be written to.
|
||||
*
|
||||
* Permission checks are made before the call to altera_avalon_uart_write(), so
|
||||
* we know that the file descriptor has been opened with the correct permissions
|
||||
* for this operation.
|
||||
*
|
||||
* The return value is the number of bytes actually written.
|
||||
*
|
||||
* This function does not communicate with the device directly. Instead data is
|
||||
* transfered to a circular buffer. The interrupt handler is then responsible
|
||||
* for copying data from this buffer into the device.
|
||||
*/
|
||||
|
||||
int
|
||||
altera_avalon_uart_write(altera_avalon_uart_state* sp, const char* ptr, int len,
|
||||
int flags)
|
||||
{
|
||||
alt_irq_context context;
|
||||
int no_block;
|
||||
alt_u32 next;
|
||||
int count = len;
|
||||
|
||||
/*
|
||||
* Construct a flag to indicate whether the device is being accessed in
|
||||
* blocking or non-blocking mode.
|
||||
*/
|
||||
|
||||
no_block = (flags & O_NONBLOCK);
|
||||
|
||||
/*
|
||||
* When running in a multi threaded environment, obtain the "write_lock"
|
||||
* semaphore. This ensures that writing to the device is thread-safe.
|
||||
*/
|
||||
|
||||
ALT_SEM_PEND (sp->write_lock, 0);
|
||||
|
||||
/*
|
||||
* Loop transferring data from the input buffer to the transmit circular
|
||||
* buffer. The loop is terminated once all the data has been transferred,
|
||||
* or, (if in non-blocking mode) the buffer becomes full.
|
||||
*/
|
||||
|
||||
while (count)
|
||||
{
|
||||
/* Determine the next slot in the buffer to access */
|
||||
|
||||
next = (sp->tx_end + 1) & ALT_AVALON_UART_BUF_MSK;
|
||||
|
||||
/* block waiting for space if necessary */
|
||||
|
||||
if (next == sp->tx_start)
|
||||
{
|
||||
if (no_block)
|
||||
{
|
||||
/* Set errno to indicate why this function returned early */
|
||||
|
||||
ALT_ERRNO = EWOULDBLOCK;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Block waiting for space in the circular buffer */
|
||||
|
||||
/* First, ensure transmit interrupts are enabled to avoid deadlock */
|
||||
|
||||
context = alt_irq_disable_all ();
|
||||
sp->ctrl |= (ALTERA_AVALON_UART_CONTROL_TRDY_MSK |
|
||||
ALTERA_AVALON_UART_CONTROL_DCTS_MSK);
|
||||
IOWR_ALTERA_AVALON_UART_CONTROL(sp->base, sp->ctrl);
|
||||
alt_irq_enable_all (context);
|
||||
|
||||
/* wait for space to come free */
|
||||
|
||||
do
|
||||
{
|
||||
/*
|
||||
* When running in a multi-threaded mode, we pend on the write event
|
||||
* flag set in the interrupt service routine. This avoids wasting CPU
|
||||
* cycles waiting in this thread, when we could be doing something
|
||||
* more profitable elsewhere.
|
||||
*/
|
||||
|
||||
ALT_FLAG_PEND (sp->events,
|
||||
ALT_UART_WRITE_RDY,
|
||||
OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME,
|
||||
0);
|
||||
}
|
||||
while ((next == sp->tx_start));
|
||||
}
|
||||
}
|
||||
|
||||
count--;
|
||||
|
||||
/* Add the next character to the transmit buffer */
|
||||
|
||||
sp->tx_buf[sp->tx_end] = *ptr++;
|
||||
sp->tx_end = next;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now that access to the circular buffer is complete, release the write
|
||||
* semaphore so that other threads can access the buffer.
|
||||
*/
|
||||
|
||||
ALT_SEM_POST (sp->write_lock);
|
||||
|
||||
/*
|
||||
* Ensure that interrupts are enabled, so that the circular buffer can
|
||||
* drain.
|
||||
*/
|
||||
|
||||
context = alt_irq_disable_all ();
|
||||
sp->ctrl |= ALTERA_AVALON_UART_CONTROL_TRDY_MSK |
|
||||
ALTERA_AVALON_UART_CONTROL_DCTS_MSK;
|
||||
IOWR_ALTERA_AVALON_UART_CONTROL(sp->base, sp->ctrl);
|
||||
alt_irq_enable_all (context);
|
||||
|
||||
/* return the number of bytes written */
|
||||
|
||||
return (len - count);
|
||||
}
|
||||
|
||||
#endif /* fast driver */
|
|
@ -1,34 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2010 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_AVALON_UART_LWHAL_H__
|
||||
#define __ALT_AVALON_UART_LWHAL_H__
|
||||
|
||||
extern void altera_avalon_uart_lwhal_putchar(void *base, int character);
|
||||
|
||||
#endif /* __ALT_AVALON_UART_LWHAL_H__ */
|
|
@ -1 +0,0 @@
|
|||
zephyr_sources(altera_avalon_uart_lwhal_putchar.c)
|
|
@ -1,55 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2010 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "altera_avalon_uart_regs.h"
|
||||
#include "altera_avalon_uart_lwhal.h"
|
||||
|
||||
|
||||
/** @Function Description: Writes a single character to the UART.
|
||||
* @API Type: External
|
||||
* @param base UART base address
|
||||
* @param character Character to be written
|
||||
* @return None
|
||||
*
|
||||
*/
|
||||
void altera_avalon_uart_lwhal_putchar(void *base, int character)
|
||||
{
|
||||
unsigned int status;
|
||||
|
||||
do {
|
||||
status = IORD_ALTERA_AVALON_UART_STATUS(base);
|
||||
|
||||
if (status & ALTERA_AVALON_UART_STATUS_TRDY_MSK)
|
||||
{
|
||||
IOWR_ALTERA_AVALON_UART_TXDATA(base, (character & 0xff));
|
||||
return;
|
||||
}
|
||||
}while (1);
|
||||
|
||||
return;
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_AVALON_UART_REGS_H__
|
||||
#define __ALTERA_AVALON_UART_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#define ALTERA_AVALON_UART_RXDATA_REG 0
|
||||
#define IOADDR_ALTERA_AVALON_UART_RXDATA(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_UART_RXDATA_REG)
|
||||
#define IORD_ALTERA_AVALON_UART_RXDATA(base) \
|
||||
IORD(base, ALTERA_AVALON_UART_RXDATA_REG)
|
||||
#define IOWR_ALTERA_AVALON_UART_RXDATA(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_UART_RXDATA_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_UART_TXDATA_REG 1
|
||||
#define IOADDR_ALTERA_AVALON_UART_TXDATA(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_UART_TXDATA_REG)
|
||||
#define IORD_ALTERA_AVALON_UART_TXDATA(base) \
|
||||
IORD(base, ALTERA_AVALON_UART_TXDATA_REG)
|
||||
#define IOWR_ALTERA_AVALON_UART_TXDATA(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_UART_TXDATA_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_UART_STATUS_REG 2
|
||||
#define IOADDR_ALTERA_AVALON_UART_STATUS(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_UART_STATUS_REG)
|
||||
#define IORD_ALTERA_AVALON_UART_STATUS(base) \
|
||||
IORD(base, ALTERA_AVALON_UART_STATUS_REG)
|
||||
#define IOWR_ALTERA_AVALON_UART_STATUS(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_UART_STATUS_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_UART_STATUS_PE_MSK (0x1)
|
||||
#define ALTERA_AVALON_UART_STATUS_PE_OFST (0)
|
||||
#define ALTERA_AVALON_UART_STATUS_FE_MSK (0x2)
|
||||
#define ALTERA_AVALON_UART_STATUS_FE_OFST (1)
|
||||
#define ALTERA_AVALON_UART_STATUS_BRK_MSK (0x4)
|
||||
#define ALTERA_AVALON_UART_STATUS_BRK_OFST (2)
|
||||
#define ALTERA_AVALON_UART_STATUS_ROE_MSK (0x8)
|
||||
#define ALTERA_AVALON_UART_STATUS_ROE_OFST (3)
|
||||
#define ALTERA_AVALON_UART_STATUS_TOE_MSK (0x10)
|
||||
#define ALTERA_AVALON_UART_STATUS_TOE_OFST (4)
|
||||
#define ALTERA_AVALON_UART_STATUS_TMT_MSK (0x20)
|
||||
#define ALTERA_AVALON_UART_STATUS_TMT_OFST (5)
|
||||
#define ALTERA_AVALON_UART_STATUS_TRDY_MSK (0x40)
|
||||
#define ALTERA_AVALON_UART_STATUS_TRDY_OFST (6)
|
||||
#define ALTERA_AVALON_UART_STATUS_RRDY_MSK (0x80)
|
||||
#define ALTERA_AVALON_UART_STATUS_RRDY_OFST (7)
|
||||
#define ALTERA_AVALON_UART_STATUS_E_MSK (0x100)
|
||||
#define ALTERA_AVALON_UART_STATUS_E_OFST (8)
|
||||
#define ALTERA_AVALON_UART_STATUS_DCTS_MSK (0x400)
|
||||
#define ALTERA_AVALON_UART_STATUS_DCTS_OFST (10)
|
||||
#define ALTERA_AVALON_UART_STATUS_CTS_MSK (0x800)
|
||||
#define ALTERA_AVALON_UART_STATUS_CTS_OFST (11)
|
||||
#define ALTERA_AVALON_UART_STATUS_EOP_MSK (0x1000)
|
||||
#define ALTERA_AVALON_UART_STATUS_EOP_OFST (12)
|
||||
|
||||
#define ALTERA_AVALON_UART_CONTROL_REG 3
|
||||
#define IOADDR_ALTERA_AVALON_UART_CONTROL(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_UART_CONTROL_REG)
|
||||
#define IORD_ALTERA_AVALON_UART_CONTROL(base) \
|
||||
IORD(base, ALTERA_AVALON_UART_CONTROL_REG)
|
||||
#define IOWR_ALTERA_AVALON_UART_CONTROL(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_UART_CONTROL_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_UART_CONTROL_PE_MSK (0x1)
|
||||
#define ALTERA_AVALON_UART_CONTROL_PE_OFST (0)
|
||||
#define ALTERA_AVALON_UART_CONTROL_FE_MSK (0x2)
|
||||
#define ALTERA_AVALON_UART_CONTROL_FE_OFST (1)
|
||||
#define ALTERA_AVALON_UART_CONTROL_BRK_MSK (0x4)
|
||||
#define ALTERA_AVALON_UART_CONTROL_BRK_OFST (2)
|
||||
#define ALTERA_AVALON_UART_CONTROL_ROE_MSK (0x8)
|
||||
#define ALTERA_AVALON_UART_CONTROL_ROE_OFST (3)
|
||||
#define ALTERA_AVALON_UART_CONTROL_TOE_MSK (0x10)
|
||||
#define ALTERA_AVALON_UART_CONTROL_TOE_OFST (4)
|
||||
#define ALTERA_AVALON_UART_CONTROL_TMT_MSK (0x20)
|
||||
#define ALTERA_AVALON_UART_CONTROL_TMT_OFST (5)
|
||||
#define ALTERA_AVALON_UART_CONTROL_TRDY_MSK (0x40)
|
||||
#define ALTERA_AVALON_UART_CONTROL_TRDY_OFST (6)
|
||||
#define ALTERA_AVALON_UART_CONTROL_RRDY_MSK (0x80)
|
||||
#define ALTERA_AVALON_UART_CONTROL_RRDY_OFST (7)
|
||||
#define ALTERA_AVALON_UART_CONTROL_E_MSK (0x100)
|
||||
#define ALTERA_AVALON_UART_CONTROL_E_OFST (8)
|
||||
#define ALTERA_AVALON_UART_CONTROL_DCTS_MSK (0x400)
|
||||
#define ALTERA_AVALON_UART_CONTROL_DCTS_OFST (10)
|
||||
#define ALTERA_AVALON_UART_CONTROL_RTS_MSK (0x800)
|
||||
#define ALTERA_AVALON_UART_CONTROL_RTS_OFST (11)
|
||||
#define ALTERA_AVALON_UART_CONTROL_EOP_MSK (0x1000)
|
||||
#define ALTERA_AVALON_UART_CONTROL_EOP_OFST (12)
|
||||
|
||||
#define ALTERA_AVALON_UART_DIVISOR_REG 4
|
||||
#define IOADDR_ALTERA_AVALON_UART_DIVISOR(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_UART_DIVISOR_REG)
|
||||
#define IORD_ALTERA_AVALON_UART_DIVISOR(base) \
|
||||
IORD(base, ALTERA_AVALON_UART_DIVISOR_REG)
|
||||
#define IOWR_ALTERA_AVALON_UART_DIVISOR(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_UART_DIVISOR_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_UART_EOP_REG 5
|
||||
#define IOADDR_ALTERA_AVALON_UART_EOP(base) \
|
||||
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_UART_EOP_REG)
|
||||
#define IORD_ALTERA_AVALON_UART_EOP(base) \
|
||||
IORD(base, ALTERA_AVALON_UART_EOP_REG)
|
||||
#define IOWR_ALTERA_AVALON_UART_EOP(base, data) \
|
||||
IOWR(base, ALTERA_AVALON_UART_EOP_REG, data)
|
||||
|
||||
#define ALTERA_AVALON_UART_EOP_MSK (0xFF)
|
||||
#define ALTERA_AVALON_UART_EOP_OFST (0)
|
||||
|
||||
#endif /* __ALTERA_AVALON_UART_REGS_H__ */
|
|
@ -1,124 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2015 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_EPCQ_CONTROLLER_H__
|
||||
#define __ALT_EPCQ_CONTROLLER_H__
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "sys/alt_flash_dev.h"
|
||||
#include "sys/alt_llist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* Description of the EPCQ controller
|
||||
*/
|
||||
typedef struct alt_epcq_controller_dev
|
||||
{
|
||||
alt_flash_dev dev;
|
||||
|
||||
alt_u32 data_base; /** base address of data slave */
|
||||
alt_u32 data_end; /** end address of data slave (not inclusive) */
|
||||
alt_u32 csr_base; /** base address of CSR slave */
|
||||
alt_u32 size_in_bytes; /** size of memory in bytes */
|
||||
alt_u32 is_epcs; /** 1 if device is an EPCS device */
|
||||
alt_u32 number_of_sectors; /** number of flash sectors */
|
||||
alt_u32 sector_size; /** size of each flash sector */
|
||||
alt_u32 page_size; /** page size */
|
||||
alt_u32 silicon_id; /** ID of silicon used with EPCQ IP */
|
||||
} alt_epcq_controller_dev;
|
||||
|
||||
/**
|
||||
* Macros used by alt_sys_init.c to create data storage for driver instance
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_AVL_MEM_AVL_CSR_INSTANCE(epcq_name, avl_mem, avl_csr, epcq_dev) \
|
||||
static alt_epcq_controller_dev epcq_dev = \
|
||||
{ \
|
||||
.dev = { \
|
||||
.llist = ALT_LLIST_ENTRY, \
|
||||
.name = avl_mem##_NAME, \
|
||||
.write = alt_epcq_controller_write, \
|
||||
.read = alt_epcq_controller_read, \
|
||||
.get_info = alt_epcq_controller_get_info, \
|
||||
.erase_block = alt_epcq_controller_erase_block, \
|
||||
.write_block = alt_epcq_controller_write_block, \
|
||||
.base_addr = ((void*)(avl_mem##_BASE)), \
|
||||
.length = ((int)(avl_mem##_SPAN)), \
|
||||
.lock = alt_epcq_controller_lock , \
|
||||
}, \
|
||||
.data_base = ((alt_u32)(avl_mem##_BASE)), \
|
||||
.data_end = ((alt_u32)(avl_mem##_BASE) + (alt_u32)(avl_mem##_SPAN)), \
|
||||
.csr_base = ((alt_u32)(avl_csr##_BASE)), \
|
||||
.size_in_bytes = ((alt_u32)(avl_mem##_SPAN)), \
|
||||
.is_epcs = ((alt_u32)(avl_mem##_IS_EPCS)), \
|
||||
.number_of_sectors = ((alt_u32)(avl_mem##_NUMBER_OF_SECTORS)), \
|
||||
.sector_size = ((alt_u32)(avl_mem##_SECTOR_SIZE)), \
|
||||
.page_size = ((alt_u32)(avl_mem##_PAGE_SIZE)) , \
|
||||
}
|
||||
|
||||
/*
|
||||
Public API
|
||||
|
||||
Refer to Using Flash Devices in the
|
||||
Developing Programs Using the Hardware Abstraction Layer chapter
|
||||
of the Nios II Software Developer's Handbook.
|
||||
|
||||
*/
|
||||
int alt_epcq_controller_read(alt_flash_dev *flash_info, int offset, void *dest_addr, int length);
|
||||
|
||||
int alt_epcq_controller_get_info(alt_flash_fd *fd, flash_region **info, int *number_of_regions);
|
||||
|
||||
int alt_epcq_controller_erase_block(alt_flash_dev *flash_info, int block_offset);
|
||||
|
||||
int alt_epcq_controller_write_block(alt_flash_dev *flash_info, int block_offset, int data_offset, const void *data, int length);
|
||||
|
||||
int alt_epcq_controller_write(alt_flash_dev *flash_info, int offset, const void *src_addr, int length);
|
||||
|
||||
int alt_epcq_controller_lock(alt_flash_dev *flash_info, alt_u32 sectors_to_lock);
|
||||
|
||||
|
||||
/*
|
||||
* Initialization function
|
||||
*/
|
||||
extern alt_32 altera_epcq_controller_init(alt_epcq_controller_dev *dev);
|
||||
|
||||
/*
|
||||
* alt_sys_init.c will call this macro automatically initialize the driver instance
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_INIT(name, dev) \
|
||||
altera_epcq_controller_init(&dev);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALT_EPCQ_CONTROLLER_H__ */
|
|
@ -1 +0,0 @@
|
|||
zephyr_sources(altera_epcq_controller.c)
|
|
@ -1,793 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2015 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include "sys/param.h"
|
||||
#include "alt_types.h"
|
||||
#include "altera_epcq_controller_regs.h"
|
||||
#include "altera_epcq_controller.h"
|
||||
#include "priv/alt_busy_sleep.h"
|
||||
#include "sys/alt_debug.h"
|
||||
#include "sys/alt_cache.h"
|
||||
|
||||
|
||||
ALT_INLINE alt_32 static alt_epcq_validate_read_write_arguments(alt_epcq_controller_dev *flash_info,alt_u32 offset, alt_u32 length);
|
||||
alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_flash_info);
|
||||
|
||||
/*
|
||||
* Public API
|
||||
*
|
||||
* Refer to “Using Flash Devices” in the
|
||||
* Developing Programs Using the Hardware Abstraction Layer chapter
|
||||
* of the Nios II Software Developer’s Handbook.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* alt_epcq_controller_lock
|
||||
*
|
||||
* Locks the range of the memory sectors, which
|
||||
* protected from write and erase.
|
||||
*
|
||||
* Arguments:
|
||||
* - *flash_info: Pointer to general flash device structure.
|
||||
* - sectors_to_lock: Block protection bits in EPCQ ==> Bit4 | Bit3 | Bit2 | Bit1 | Bit0
|
||||
* TB | BP3 | BP2 | BP1 | BP0
|
||||
* For details of setting sectors protection, please refer to EPCQ datasheet.
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments
|
||||
* -ETIME -> Time out and skipping the looping after 0.7 sec.
|
||||
* -ENOLCK -> Sectors lock failed.
|
||||
**/
|
||||
int alt_epcq_controller_lock(alt_flash_dev *flash_info, alt_u32 sectors_to_lock)
|
||||
{
|
||||
alt_u32 mem_op_value = 0; /* value to write to EPCQ_MEM_OP register */
|
||||
alt_epcq_controller_dev* epcq_flash_info = NULL;
|
||||
alt_u32 result = 0;
|
||||
alt_32 status = 0;
|
||||
|
||||
/* return -EINVAL if flash_info is NULL */
|
||||
if(NULL == flash_info || 0 > sectors_to_lock)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
epcq_flash_info = (alt_epcq_controller_dev*)flash_info;
|
||||
|
||||
/* sector value should occupy bits 17:8 */
|
||||
mem_op_value = sectors_to_lock << 8;
|
||||
|
||||
/* sector protect commands 0b11 occupies lower 2 bits */
|
||||
mem_op_value |= ALTERA_EPCQ_CONTROLLER_MEM_OP_SECTOR_PROTECT_CMD;
|
||||
|
||||
/* write sector protect command to EPCQ_MEM_OP register to protect sectors */
|
||||
IOWR_ALTERA_EPCQ_CONTROLLER_MEM_OP(epcq_flash_info->csr_base, mem_op_value);
|
||||
|
||||
/* poll write in progress to make sure no operation is in progress */
|
||||
status = alt_epcq_poll_for_write_in_progress(epcq_flash_info);
|
||||
if(status != 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
status = IORD_ALTERA_EPCQ_CONTROLLER_STATUS(epcq_flash_info->csr_base);
|
||||
result |= (status >> 2) & 0x07; /* extract out BP3 - BP0 */
|
||||
result |= (status >> 3) & 0x08; /* extract out BP4 */
|
||||
result |= (status >> 1) & 0x10; /* extract out TOP/BOTTOM bit */
|
||||
|
||||
if(result != sectors_to_lock)
|
||||
{
|
||||
return -ENOLCK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* alt_epcq_controller_get_info
|
||||
*
|
||||
* Pass the table of erase blocks to the user. This flash will return a single
|
||||
* flash_region that gives the number and size of sectors for the device used.
|
||||
*
|
||||
* Arguments:
|
||||
* - *fd: Pointer to general flash device structure.
|
||||
* - **info: Pointer to flash region
|
||||
* - *number_of_regions: Pointer to number of regions
|
||||
*
|
||||
* For details of setting sectors protection, please refer to EPCQ datasheet.
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments
|
||||
* -EIO -> Could be hardware problem.
|
||||
**/
|
||||
int alt_epcq_controller_get_info
|
||||
(
|
||||
alt_flash_fd *fd, /** flash device descriptor */
|
||||
flash_region **info, /** pointer to flash_region will be stored here */
|
||||
int *number_of_regions /** number of regions will be stored here */
|
||||
)
|
||||
{
|
||||
alt_flash_dev* flash = NULL;
|
||||
|
||||
/* return -EINVAL if fd,info and number_of_regions are NULL */
|
||||
if(NULL == fd || NULL == info || NULL == number_of_regions)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
flash = (alt_flash_dev*)fd;
|
||||
|
||||
*number_of_regions = flash->number_of_regions;
|
||||
|
||||
if (!flash->number_of_regions)
|
||||
{
|
||||
return -EIO;
|
||||
}
|
||||
else
|
||||
{
|
||||
*info = &flash->region_info[0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* alt_epcq_controller_erase_block
|
||||
*
|
||||
* This function erases a single flash sector.
|
||||
*
|
||||
* Arguments:
|
||||
* - *flash_info: Pointer to EPCQ flash device structure.
|
||||
* - block_offset: byte-addressed offset, from start of flash, of the sector to be erased
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments
|
||||
* -EIO -> write failed, sector might be protected
|
||||
**/
|
||||
int alt_epcq_controller_erase_block(alt_flash_dev *flash_info, int block_offset)
|
||||
{
|
||||
alt_32 ret_code = 0;
|
||||
alt_u32 mem_op_value = 0; /* value to write to EPCQ_MEM_OP register */
|
||||
alt_epcq_controller_dev* epcq_flash_info = NULL;
|
||||
alt_u32 sector_number = 0;
|
||||
|
||||
/* return -EINVAL if flash_info is NULL */
|
||||
if(NULL == flash_info)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
epcq_flash_info = (alt_epcq_controller_dev*)flash_info;
|
||||
|
||||
/*
|
||||
* Sanity checks that block_offset is within the flash memory span and that the
|
||||
* block offset is sector aligned.
|
||||
*
|
||||
*/
|
||||
if((block_offset < 0)
|
||||
|| (block_offset >= epcq_flash_info->size_in_bytes)
|
||||
|| (block_offset & (epcq_flash_info->sector_size - 1)) != 0)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* calculate current sector/block number */
|
||||
sector_number = (block_offset/(epcq_flash_info->sector_size));
|
||||
|
||||
/* sector value should occupy bits 23:8 */
|
||||
mem_op_value = (sector_number << 8) & ALTERA_EPCQ_CONTROLLER_MEM_OP_SECTOR_VALUE_MASK;
|
||||
|
||||
/* sector erase commands 0b10 occupies lower 2 bits */
|
||||
mem_op_value |= ALTERA_EPCQ_CONTROLLER_MEM_OP_SECTOR_ERASE_CMD;
|
||||
|
||||
/* write sector erase command to EPCQ_MEM_OP register to erase sector "sector_number" */
|
||||
IOWR_ALTERA_EPCQ_CONTROLLER_MEM_OP(epcq_flash_info->csr_base, mem_op_value);
|
||||
|
||||
/* check whether erase triggered a illegal erase interrupt */
|
||||
if((IORD_ALTERA_EPCQ_CONTROLLER_ISR(epcq_flash_info->csr_base) &
|
||||
ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_ERASE_MASK) ==
|
||||
ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_ERASE_ACTIVE)
|
||||
{
|
||||
/* clear register */
|
||||
/* EPCQ_ISR access is write one to clear (W1C) */
|
||||
IOWR_ALTERA_EPCQ_CONTROLLER_ISR(epcq_flash_info->csr_base,
|
||||
ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_ERASE_MASK );
|
||||
return -EIO; /* erase failed, sector might be protected */
|
||||
}
|
||||
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* alt_epcq_controller_write_block
|
||||
*
|
||||
* This function writes one block/sector of data to flash. The length of the write can NOT
|
||||
* spill into the adjacent sector.
|
||||
*
|
||||
* It assumes that someone has already erased the appropriate sector(s).
|
||||
*
|
||||
* Arguments:
|
||||
* - *flash_info: Pointer to EPCQ flash device structure.
|
||||
* - block_offset: byte-addressed offset, from the start of flash, of the sector to written to
|
||||
* - data-offset: Byte offset (unaligned access) of write into flash memory.
|
||||
* For best performance, word(32 bits - aligned access) offset of write is recommended.
|
||||
* - *src_addr: source buffer
|
||||
* - length: size of writing
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments
|
||||
* -EIO -> write failed, sector might be protected
|
||||
**/
|
||||
int alt_epcq_controller_write_block
|
||||
(
|
||||
alt_flash_dev *flash_info, /** flash device info */
|
||||
int block_offset, /** sector/block offset in byte addressing */
|
||||
int data_offset, /** offset of write from base address */
|
||||
const void *data, /** data to be written */
|
||||
int length /** bytes of data to be written, >0 */
|
||||
)
|
||||
{
|
||||
alt_u32 buffer_offset = 0; /** offset into data buffer to get write data */
|
||||
alt_u32 remaining_length = length; /** length left to write */
|
||||
alt_u32 write_offset = data_offset; /** offset into flash to write too */
|
||||
|
||||
alt_epcq_controller_dev *epcq_flash_info = (alt_epcq_controller_dev*)flash_info;
|
||||
|
||||
/*
|
||||
* Sanity checks that data offset is not larger then a sector, that block offset is
|
||||
* sector aligned and within the valid flash memory range and a write doesn't spill into
|
||||
* the adjacent flash sector.
|
||||
*/
|
||||
if(block_offset < 0
|
||||
|| data_offset < 0
|
||||
|| NULL == flash_info
|
||||
|| NULL == data
|
||||
|| data_offset >= epcq_flash_info->size_in_bytes
|
||||
|| block_offset >= epcq_flash_info->size_in_bytes
|
||||
|| length > (epcq_flash_info->sector_size - (data_offset - block_offset))
|
||||
|| length < 0
|
||||
|| (block_offset & (epcq_flash_info->sector_size - 1)) != 0)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do writes one 32-bit word at a time.
|
||||
* We need to make sure that we pad the first few bytes so they're word aligned if they are
|
||||
* not already.
|
||||
*/
|
||||
while (remaining_length > 0)
|
||||
{
|
||||
alt_u32 word_to_write = 0xFFFFFFFF; /** initialize word to write to blank word */
|
||||
alt_u32 padding = 0; /** bytes to pad the next word that is written */
|
||||
alt_u32 bytes_to_copy = sizeof(alt_u32); /** number of bytes from source to copy */
|
||||
|
||||
/*
|
||||
* we need to make sure the write is word aligned
|
||||
* this should only be true at most 1 time
|
||||
*/
|
||||
if (0 != (write_offset & (sizeof(alt_u32) - 1)))
|
||||
{
|
||||
/*
|
||||
* data is not word aligned
|
||||
* calculate padding bytes need to add before start of a data offset
|
||||
*/
|
||||
padding = write_offset & (sizeof(alt_u32) - 1);
|
||||
|
||||
/* update variables to account for padding being added */
|
||||
bytes_to_copy -= padding;
|
||||
|
||||
if(bytes_to_copy > remaining_length)
|
||||
{
|
||||
bytes_to_copy = remaining_length;
|
||||
}
|
||||
|
||||
write_offset = write_offset - padding;
|
||||
if(0 != (write_offset & (sizeof(alt_u32) - 1)))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bytes_to_copy > remaining_length)
|
||||
{
|
||||
bytes_to_copy = remaining_length;
|
||||
}
|
||||
}
|
||||
|
||||
/* prepare the word to be written */
|
||||
memcpy((((void*)&word_to_write)) + padding, ((void*)data) + buffer_offset, bytes_to_copy);
|
||||
|
||||
/* update offset and length variables */
|
||||
buffer_offset += bytes_to_copy;
|
||||
remaining_length -= bytes_to_copy;
|
||||
|
||||
/* write to flash 32 bits at a time */
|
||||
IOWR_32DIRECT(epcq_flash_info->data_base, write_offset, word_to_write);
|
||||
|
||||
/* check whether write triggered a illegal write interrupt */
|
||||
if((IORD_ALTERA_EPCQ_CONTROLLER_ISR(epcq_flash_info->csr_base) &
|
||||
ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_WRITE_MASK) ==
|
||||
ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_WRITE_ACTIVE)
|
||||
{
|
||||
/* clear register */
|
||||
IOWR_ALTERA_EPCQ_CONTROLLER_ISR(epcq_flash_info->csr_base,
|
||||
ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_WRITE_MASK );
|
||||
return -EIO; /** write failed, sector might be protected */
|
||||
}
|
||||
|
||||
/* update current offset */
|
||||
write_offset = write_offset + sizeof(alt_u32);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* alt_epcq_controller_write
|
||||
*
|
||||
* Program the data into the flash at the selected address.
|
||||
*
|
||||
* The different between this function and alt_epcq_controller_write_block function
|
||||
* is that this function (alt_epcq_controller_write) will automatically erase a block as needed
|
||||
* Arguments:
|
||||
* - *flash_info: Pointer to EPCQ flash device structure.
|
||||
* - offset: Byte offset (unaligned access) of write to flash memory. For best performance,
|
||||
* word(32 bits - aligned access) offset of write is recommended.
|
||||
* - *src_addr: source buffer
|
||||
* - length: size of writing
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments
|
||||
* -EIO -> write failed, sector might be protected
|
||||
*
|
||||
**/
|
||||
int alt_epcq_controller_write(
|
||||
alt_flash_dev *flash_info, /** device info */
|
||||
int offset, /** offset of write from base address */
|
||||
const void *src_addr, /** source buffer */
|
||||
int length /** size of writing */
|
||||
)
|
||||
{
|
||||
alt_32 ret_code = 0;
|
||||
|
||||
alt_epcq_controller_dev *epcq_flash_info = NULL;
|
||||
|
||||
alt_u32 write_offset = offset; /** address of next byte to write */
|
||||
alt_u32 remaining_length = length; /** length of write data left to be written */
|
||||
alt_u32 buffer_offset = 0; /** offset into source buffer to get write data */
|
||||
alt_u32 i = 0;
|
||||
|
||||
/* return -EINVAL if flash_info and src_addr are NULL */
|
||||
if(NULL == flash_info || NULL == src_addr)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
epcq_flash_info = (alt_epcq_controller_dev*)flash_info;
|
||||
|
||||
/* make sure the write parameters are within the bounds of the flash */
|
||||
ret_code = alt_epcq_validate_read_write_arguments(epcq_flash_info, offset, length);
|
||||
|
||||
if(0 != ret_code)
|
||||
{
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/*
|
||||
* This loop erases and writes data one sector at a time. We check for write completion
|
||||
* before starting the next sector.
|
||||
*/
|
||||
for(i = offset/epcq_flash_info->sector_size ; i < epcq_flash_info->number_of_sectors; i++)
|
||||
{
|
||||
alt_u32 block_offset = 0; /** block offset in byte addressing */
|
||||
alt_u32 offset_within_current_sector = 0; /** offset into current sector to write */
|
||||
alt_u32 length_to_write = 0; /** length to write to current sector */
|
||||
|
||||
if(0 >= remaining_length)
|
||||
{
|
||||
break; /* out of data to write */
|
||||
}
|
||||
|
||||
/* calculate current sector/block offset in byte addressing */
|
||||
block_offset = write_offset & ~(epcq_flash_info->sector_size - 1);
|
||||
|
||||
/* calculate offset into sector/block if there is one */
|
||||
if(block_offset != write_offset)
|
||||
{
|
||||
offset_within_current_sector = write_offset - block_offset;
|
||||
}
|
||||
|
||||
/* erase sector */
|
||||
ret_code = alt_epcq_controller_erase_block(flash_info, block_offset);
|
||||
|
||||
if(0 != ret_code)
|
||||
{
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/* calculate the byte size of data to be written in a sector */
|
||||
length_to_write = MIN(epcq_flash_info->sector_size - offset_within_current_sector,
|
||||
remaining_length);
|
||||
|
||||
/* write data to erased block */
|
||||
ret_code = alt_epcq_controller_write_block(flash_info, block_offset, write_offset,
|
||||
src_addr + buffer_offset, length_to_write);
|
||||
|
||||
|
||||
if(0 != ret_code)
|
||||
{
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/* update remaining length and buffer_offset pointer */
|
||||
remaining_length -= length_to_write;
|
||||
buffer_offset += length_to_write;
|
||||
write_offset += length_to_write;
|
||||
}
|
||||
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* alt_epcq_controller_read
|
||||
*
|
||||
* There's no real need to use this function as opposed to using memcpy directly. It does
|
||||
* do some sanity checks on the bounds of the read.
|
||||
*
|
||||
* Arguments:
|
||||
* - *flash_info: Pointer to general flash device structure.
|
||||
* - offset: offset read from flash memory.
|
||||
* - *dest_addr: destination buffer
|
||||
* - length: size of reading
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments
|
||||
**/
|
||||
int alt_epcq_controller_read
|
||||
(
|
||||
alt_flash_dev *flash_info, /** device info */
|
||||
int offset, /** offset of read from base address */
|
||||
void *dest_addr, /** destination buffer */
|
||||
int length /** size of read */
|
||||
)
|
||||
{
|
||||
alt_32 ret_code = 0;
|
||||
alt_epcq_controller_dev *epcq_flash_info = NULL;
|
||||
|
||||
/* return -EINVAL if flash_info and dest_addr are NULL */
|
||||
if(NULL == flash_info || NULL == dest_addr)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
epcq_flash_info = (alt_epcq_controller_dev*)flash_info;
|
||||
|
||||
/* validate arguments */
|
||||
ret_code = alt_epcq_validate_read_write_arguments(epcq_flash_info, offset, length);
|
||||
|
||||
/* copy data from flash to destination address */
|
||||
if(0 == ret_code)
|
||||
{
|
||||
memcpy(dest_addr, (alt_u8*)epcq_flash_info->data_base + offset, length);
|
||||
}
|
||||
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* altera_epcq_controller_init
|
||||
*
|
||||
* alt_sys_init.c will call this function automatically through macro
|
||||
*
|
||||
* Information in system.h is checked against expected values that are determined by the silicon_id.
|
||||
* If the information doesn't match then this system is configured incorrectly. Most likely the wrong
|
||||
* type of EPCS or EPCQ device was selected when instantiating the soft IP.
|
||||
*
|
||||
* Arguments:
|
||||
* - *flash: Pointer to EPCQ flash device structure.
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments.
|
||||
* -ENODEV -> System is configured incorrectly.
|
||||
**/
|
||||
alt_32 altera_epcq_controller_init(alt_epcq_controller_dev *flash)
|
||||
{
|
||||
alt_u32 silicon_id = 0;
|
||||
alt_u32 size_in_bytes = 0;
|
||||
alt_u32 number_of_sectors = 0;
|
||||
|
||||
/* return -EINVAL if flash is NULL */
|
||||
if(NULL == flash)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* return -ENODEV if CSR slave is not attached */
|
||||
if(NULL == (void *)flash->csr_base)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* If flash is an EPCQ device, we read the EPCQ_RD_RDID register for the ID
|
||||
* If flash is an EPCS device, we read the EPCQ_RD_SID register for the ID
|
||||
*
|
||||
* Whether or not the flash is a EPCQ or EPCS is indicated in the system.h. The system.h gets
|
||||
* this value from the hw.tcl of the IP. If this value is set incorrectly, then things will go
|
||||
* badly.
|
||||
*
|
||||
* In both cases, we can determine the number of sectors, which we can use
|
||||
* to calculate a size. We compare that size to the system.h value to make sure
|
||||
* the EPCQ soft IP was configured correctly.
|
||||
*/
|
||||
if(0 == flash->is_epcs)
|
||||
{
|
||||
/* If we're an EPCQ, we read EPCQ_RD_RDID for the silicon ID */
|
||||
silicon_id = IORD_ALTERA_EPCQ_CONTROLLER_RDID(flash->csr_base);
|
||||
silicon_id &= ALTERA_EPCQ_CONTROLLER_RDID_MASK;
|
||||
|
||||
/* Determine which EPCQ device so we can figure out the number of sectors */
|
||||
/* EPCQ share the same ID for the same capacity*/
|
||||
switch(silicon_id)
|
||||
{
|
||||
case ALTERA_EPCQ_CONTROLLER_RDID_EPCQ16:
|
||||
{
|
||||
number_of_sectors = 32;
|
||||
break;
|
||||
}
|
||||
case ALTERA_EPCQ_CONTROLLER_RDID_EPCQ32:
|
||||
{
|
||||
number_of_sectors = 64;
|
||||
break;
|
||||
}
|
||||
case ALTERA_EPCQ_CONTROLLER_RDID_EPCQ64:
|
||||
{
|
||||
number_of_sectors = 128;
|
||||
break;
|
||||
}
|
||||
case ALTERA_EPCQ_CONTROLLER_RDID_EPCQ128:
|
||||
{
|
||||
number_of_sectors = 256;
|
||||
break;
|
||||
}
|
||||
case ALTERA_EPCQ_CONTROLLER_RDID_EPCQ256:
|
||||
{
|
||||
number_of_sectors = 512;
|
||||
break;
|
||||
}
|
||||
case ALTERA_EPCQ_CONTROLLER_RDID_EPCQ512:
|
||||
{
|
||||
number_of_sectors = 1024;
|
||||
break;
|
||||
}
|
||||
case ALTERA_EPCQ_CONTROLLER_RDID_EPCQ1024:
|
||||
{
|
||||
number_of_sectors = 2048;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* If we're an EPCS, we read EPCQ_RD_SID for the silicon ID */
|
||||
silicon_id = IORD_ALTERA_EPCQ_CONTROLLER_SID(flash->csr_base);
|
||||
silicon_id &= ALTERA_EPCQ_CONTROLLER_SID_MASK;
|
||||
|
||||
/* Determine which EPCS device so we can figure out various properties */
|
||||
switch(silicon_id)
|
||||
{
|
||||
case ALTERA_EPCQ_CONTROLLER_SID_EPCS16:
|
||||
{
|
||||
number_of_sectors = 32;
|
||||
break;
|
||||
}
|
||||
case ALTERA_EPCQ_CONTROLLER_SID_EPCS64:
|
||||
{
|
||||
number_of_sectors = 128;
|
||||
break;
|
||||
}
|
||||
case ALTERA_EPCQ_CONTROLLER_SID_EPCS128:
|
||||
{
|
||||
number_of_sectors = 256;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate size of flash based on number of sectors */
|
||||
size_in_bytes = number_of_sectors * flash->sector_size;
|
||||
|
||||
/*
|
||||
* Make sure calculated size is the same size given in system.h
|
||||
* Also check number of sectors is the same number given in system.h
|
||||
* Otherwise the EPCQ IP was not configured correctly
|
||||
*/
|
||||
if( size_in_bytes != flash->size_in_bytes ||
|
||||
number_of_sectors != flash->number_of_sectors)
|
||||
{
|
||||
flash->dev.number_of_regions = 0;
|
||||
return -ENODEV;
|
||||
}
|
||||
else
|
||||
{
|
||||
flash->silicon_id = silicon_id;
|
||||
flash->number_of_sectors = number_of_sectors;
|
||||
|
||||
/*
|
||||
* populate fields of region_info required to conform to HAL API
|
||||
* create 1 region that composed of "number_of_sectors" blocks
|
||||
*/
|
||||
flash->dev.number_of_regions = 1;
|
||||
flash->dev.region_info[0].offset = 0;
|
||||
flash->dev.region_info[0].region_size = size_in_bytes;
|
||||
flash->dev.region_info[0].number_of_blocks = number_of_sectors;
|
||||
flash->dev.region_info[0].block_size = flash->sector_size;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Register this device as a valid flash device type
|
||||
*
|
||||
* Only register the device if it's configured correctly.
|
||||
*/
|
||||
alt_flash_device_register(&(flash->dev));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Private API
|
||||
*
|
||||
* Helper functions used by Public API functions.
|
||||
*
|
||||
* Arguments:
|
||||
* - *flash_info: Pointer to EPCQ flash device structure.
|
||||
* - offset: Offset of read/write from base address.
|
||||
* - length: Length of read/write in bytes.
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments
|
||||
*/
|
||||
/**
|
||||
* Used to check that arguments to a read or write are valid
|
||||
*/
|
||||
ALT_INLINE alt_32 static alt_epcq_validate_read_write_arguments
|
||||
(
|
||||
alt_epcq_controller_dev *flash_info, /** device info */
|
||||
alt_u32 offset, /** offset of read/write */
|
||||
alt_u32 length /** length of read/write */
|
||||
)
|
||||
{
|
||||
alt_epcq_controller_dev *epcq_flash_info = NULL;
|
||||
alt_u32 start_address = 0;
|
||||
alt_32 end_address = 0;
|
||||
|
||||
/* return -EINVAL if flash_info is NULL */
|
||||
if(NULL == flash_info)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
epcq_flash_info = (alt_epcq_controller_dev*)flash_info;
|
||||
|
||||
start_address = epcq_flash_info->data_base + offset; /** first address of read or write */
|
||||
end_address = start_address + length; /** last address of read or write (not inclusive) */
|
||||
|
||||
/* make sure start and end address is less then the end address of the flash */
|
||||
if(
|
||||
start_address >= epcq_flash_info->data_end ||
|
||||
end_address > epcq_flash_info->data_end ||
|
||||
offset < 0 ||
|
||||
length < 0
|
||||
)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Private function that polls write in progress bit EPCQ_RD_STATUS.
|
||||
*
|
||||
* Write in progress will be set if any of the following operations are in progress:
|
||||
* -WRITE STATUS REGISTER
|
||||
* -WRITE NONVOLATILE CONFIGURATION REGISTER
|
||||
* -PROGRAM
|
||||
* -ERASE
|
||||
*
|
||||
* Assumes EPCQ was configured correctly.
|
||||
*
|
||||
* If ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE is set, the function will time out after
|
||||
* a period of time determined by that value.
|
||||
*
|
||||
* Arguments:
|
||||
* - *epcq_flash_info: Pointer to EPCQ flash device structure.
|
||||
*
|
||||
* Returns:
|
||||
* 0 -> success
|
||||
* -EINVAL -> Invalid arguments
|
||||
* -ETIME -> Time out and skipping the looping after 0.7 sec.
|
||||
*/
|
||||
alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_flash_info)
|
||||
{
|
||||
/* we'll want to implement timeout if a timeout value is specified */
|
||||
#if ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE > 0
|
||||
alt_u32 timeout = ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE;
|
||||
alt_u16 counter = 0;
|
||||
#endif
|
||||
|
||||
/* return -EINVAL if epcq_flash_info is NULL */
|
||||
if(NULL == epcq_flash_info)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* while Write in Progress bit is set, we wait */
|
||||
while((IORD_ALTERA_EPCQ_CONTROLLER_STATUS(epcq_flash_info->csr_base) &
|
||||
ALTERA_EPCQ_CONTROLLER_STATUS_WIP_MASK) ==
|
||||
ALTERA_EPCQ_CONTROLLER_STATUS_WIP_BUSY)
|
||||
{
|
||||
alt_busy_sleep(1); /* delay 1us */
|
||||
#if ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE > 0
|
||||
if(timeout <= counter )
|
||||
{
|
||||
return -ETIME;
|
||||
}
|
||||
|
||||
counter++;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,258 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2014 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_EPCQ_CONTROLLER_REGS_H__
|
||||
#define __ALTERA_EPCQ_CONTROLLER_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
/*
|
||||
* EPCQ_RD_STATUS register offset
|
||||
*
|
||||
* The EPCQ_RD_STATUS register contains information from the read status
|
||||
* register operation. A full description of the register can be found in the
|
||||
* data sheet,
|
||||
*
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_STATUS_REG (0x0)
|
||||
|
||||
/*
|
||||
* EPCQ_RD_STATUS register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_EPCQ_CONTROLLER_STATUS(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_EPCQ_CONTROLLER_STATUS_REG)
|
||||
|
||||
#define IORD_ALTERA_EPCQ_CONTROLLER_STATUS(base) \
|
||||
IORD_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_STATUS_REG)
|
||||
|
||||
#define IOWR_ALTERA_EPCQ_CONTROLLER_STATUS(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_STATUS_REG, data)
|
||||
|
||||
/*
|
||||
* EPCQ_RD_STATUS register description macros
|
||||
*/
|
||||
|
||||
/** Write in progress bit */
|
||||
#define ALTERA_EPCQ_CONTROLLER_STATUS_WIP_MASK (0x00000001)
|
||||
#define ALTERA_EPCQ_CONTROLLER_STATUS_WIP_AVAILABLE (0x00000000)
|
||||
#define ALTERA_EPCQ_CONTROLLER_STATUS_WIP_BUSY (0x00000001)
|
||||
/** When to time out a poll of the write in progress bit */
|
||||
/* 0.7 sec time out */
|
||||
#define ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE 700000
|
||||
|
||||
/*
|
||||
* EPCQ_RD_SID register offset
|
||||
*
|
||||
* The EPCQ_RD_SID register contains the information from the read silicon ID
|
||||
* operation and can be used to determine what type of EPCS device we have.
|
||||
* Only support in EPCS16 and EPCS64.
|
||||
*
|
||||
* This register is valid only if the device is an EPCS.
|
||||
*
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_SID_REG (0x4)
|
||||
|
||||
/*
|
||||
* EPCQ_RD_SID register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_EPCQ_CONTROLLER_SID(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_EPCQ_CONTROLLER_SID_REG)
|
||||
|
||||
#define IORD_ALTERA_EPCQ_CONTROLLER_SID(base) \
|
||||
IORD_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_SID_REG)
|
||||
|
||||
#define IOWR_ALTERA_EPCQ_CONTROLLER_SID(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_SID_REG, data)
|
||||
|
||||
/*
|
||||
* EPCQ_RD_SID register description macros
|
||||
*
|
||||
* Specific device values obtained from Table 14 of:
|
||||
* "Serial Configuration (EPCS) Devices Datasheet"
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_SID_MASK (0x000000FF)
|
||||
#define ALTERA_EPCQ_CONTROLLER_SID_EPCS16 (0x00000014)
|
||||
#define ALTERA_EPCQ_CONTROLLER_SID_EPCS64 (0x00000016)
|
||||
#define ALTERA_EPCQ_CONTROLLER_SID_EPCS128 (0x00000018)
|
||||
|
||||
/*
|
||||
* EPCQ_RD_RDID register offset
|
||||
*
|
||||
* The EPCQ_RD_RDID register contains the information from the read memory
|
||||
* capacity operation and can be used to determine what type of EPCQ device
|
||||
* we have.
|
||||
*
|
||||
* This register is only valid if the device is an EPCQ.
|
||||
*
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_REG (0x8)
|
||||
|
||||
/*
|
||||
* EPCQ_RD_RDID register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_EPCQ_CONTROLLER_RDID(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_EPCQ_CONTROLLER_RDID_REG)
|
||||
|
||||
#define IORD_ALTERA_EPCQ_CONTROLLER_RDID(base) \
|
||||
IORD_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_RDID_REG)
|
||||
|
||||
#define IOWR_ALTERA_EPCQ_CONTROLLER_RDID(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_RDID_REG, data)
|
||||
|
||||
/*
|
||||
* EPCQ_RD_RDID register description macros
|
||||
*
|
||||
* Specific device values obtained from Table 28 of:
|
||||
* "Quad-Serial Configuration (EPCQ (www.altera.com/literature/hb/cfg/cfg_cf52012.pdf))
|
||||
* Devices Datasheet"
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_MASK (0x000000FF)
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_EPCQ16 (0x00000015)
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_EPCQ32 (0x00000016)
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_EPCQ64 (0x00000017)
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_EPCQ128 (0x00000018)
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_EPCQ256 (0x00000019)
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_EPCQ512 (0x00000020)
|
||||
#define ALTERA_EPCQ_CONTROLLER_RDID_EPCQ1024 (0x00000021)
|
||||
|
||||
/*
|
||||
* EPCQ_MEM_OP register offset
|
||||
*
|
||||
* The EPCQ_MEM_OP register is used to do memory protect and erase operations
|
||||
*
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_MEM_OP_REG (0xC)
|
||||
|
||||
/*
|
||||
* EPCQ_MEM_OP register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_EPCQ_CONTROLLER_MEM_OP(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_EPCQ_CONTROLLER_MEM_OP_REG)
|
||||
|
||||
#define IORD_ALTERA_EPCQ_CONTROLLER_MEM_OP(base) \
|
||||
IORD_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_MEM_OP_REG)
|
||||
|
||||
#define IOWR_ALTERA_EPCQ_CONTROLLER_MEM_OP(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_MEM_OP_REG, data)
|
||||
|
||||
/*
|
||||
* EPCQ_MEM_OP register description macros
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_MEM_OP_CMD_MASK (0x00000003)
|
||||
#define ALTERA_EPCQ_CONTROLLER_MEM_OP_BULK_ERASE_CMD (0x00000001)
|
||||
#define ALTERA_EPCQ_CONTROLLER_MEM_OP_SECTOR_ERASE_CMD (0x00000002)
|
||||
#define ALTERA_EPCQ_CONTROLLER_MEM_OP_SECTOR_PROTECT_CMD (0x00000003)
|
||||
|
||||
/** see datasheet for sector values */
|
||||
#define ALTERA_EPCQ_CONTROLLER_MEM_OP_SECTOR_VALUE_MASK (0x00FFFF00)
|
||||
|
||||
/*
|
||||
* EPCQ_ISR register offset
|
||||
*
|
||||
* The EPCQ_ISR register is used to determine whether an invalid write or erase
|
||||
* operation triggered an interrupt
|
||||
*
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_ISR_REG (0x10)
|
||||
|
||||
/*
|
||||
* EPCQ_ISR register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_EPCQ_CONTROLLER_ISR(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_EPCQ_CONTROLLER_ISR_REG)
|
||||
|
||||
#define IORD_ALTERA_EPCQ_CONTROLLER_ISR(base) \
|
||||
IORD_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_ISR_REG)
|
||||
|
||||
#define IOWR_ALTERA_EPCQ_CONTROLLER_ISR(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_ISR_REG, data)
|
||||
|
||||
/*
|
||||
* EPCQ_ISR register description macros
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_ERASE_MASK (0x00000001)
|
||||
#define ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_ERASE_ACTIVE (0x00000001)
|
||||
|
||||
#define ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_WRITE_MASK (0x00000002)
|
||||
#define ALTERA_EPCQ_CONTROLLER_ISR_ILLEGAL_WRITE_ACTIVE (0x00000002)
|
||||
|
||||
|
||||
/*
|
||||
* EPCQ_IMR register offset
|
||||
*
|
||||
* The EPCQ_IMR register is used to mask the invalid erase or the invalid write
|
||||
* interrupts.
|
||||
*
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_IMR_REG (0x14)
|
||||
|
||||
/*
|
||||
* EPCQ_IMR register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_EPCQ_CONTROLLER_IMR(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_EPCQ_CONTROLLER_IMR_REG)
|
||||
|
||||
#define IORD_ALTERA_EPCQ_CONTROLLER_IMR(base) \
|
||||
IORD_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_IMR_REG)
|
||||
|
||||
#define IOWR_ALTERA_EPCQ_CONTROLLER_IMR(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_EPCQ_CONTROLLER_IMR_REG, data)
|
||||
|
||||
/*
|
||||
* EPCQ_IMR register description macros
|
||||
*/
|
||||
#define ALTERA_EPCQ_CONTROLLER_IMR_ILLEGAL_ERASE_MASK (0x00000001)
|
||||
#define ALTERA_EPCQ_CONTROLLER_IMR_ILLEGAL_ERASE_ENABLED (0x00000001)
|
||||
|
||||
#define ALTERA_EPCQ_CONTROLLER_IMR_ILLEGAL_WRITE_MASK (0x00000002)
|
||||
#define ALTERA_EPCQ_CONTROLLER_IMR_ILLEGAL_WRITE_ENABLED (0x00000002)
|
||||
|
||||
/*
|
||||
* EPCQ_CHIP_SELECT register offset
|
||||
*
|
||||
* The EPCQ_CHIP_SELECT register is used to issue chip select
|
||||
*/
|
||||
#define ALTERA_EPCQ_CHIP_SELECT_REG (0x18)
|
||||
|
||||
/*
|
||||
* EPCQ_CHIP_SELECT register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_EPCQ_CHIP_SELECT(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_EPCQ_CHIP_SELECT_REG)
|
||||
|
||||
#define IOWR_ALTERA_EPCQ_CHIP_SELECT(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_EPCQ_CHIP_SELECT_REG, data)
|
||||
|
||||
/*
|
||||
* EPCQ_CHIP_SELECT register description macros
|
||||
*/
|
||||
#define ALTERA_EPCQ_CHIP1_SELECT (0x00000001)
|
||||
#define ALTERA_EPCQ_CHIP2_SELECT (0x00000002)
|
||||
#define ALTERA_EPCQ_CHIP3_SELECT (0x00000003)
|
||||
|
||||
#endif /* __ALTERA_EPCQ_CONTROLLER_REGS_H__ */
|
|
@ -1,129 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2015 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALT_QSPI_CONTROLLER2_H__
|
||||
#define __ALT_QSPI_CONTROLLER2_H__
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "sys/alt_flash_dev.h"
|
||||
#include "sys/alt_llist.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Description of the QSPI controller
|
||||
*/
|
||||
typedef struct alt_qspi_controller2_dev
|
||||
{
|
||||
alt_flash_dev dev;
|
||||
|
||||
|
||||
alt_u32 data_base; /** base address of data slave */
|
||||
alt_u32 data_end; /** end address of data slave (not inclusive) */
|
||||
alt_u32 csr_base; /** base address of CSR slave */
|
||||
alt_u32 size_in_bytes; /** size of memory in bytes */
|
||||
alt_u32 is_epcs; /** 1 if device is an EPCS device */
|
||||
alt_u32 number_of_sectors; /** number of flash sectors */
|
||||
alt_u32 sector_size; /** size of each flash sector */
|
||||
alt_u32 page_size; /** page size */
|
||||
alt_u32 silicon_id; /** ID of silicon used with EPCQ/QSPI IP */
|
||||
} alt_qspi_controller2_dev;
|
||||
|
||||
|
||||
/**
|
||||
* Macros used by alt_sys_init.c to create data storage for driver instance
|
||||
*/
|
||||
|
||||
#define ALTERA_GENERIC_QUAD_SPI_CONTROLLER2_AVL_MEM_AVL_CSR_INSTANCE(qspi_name, avl_mem, avl_csr, qspi_dev) \
|
||||
static alt_qspi_controller2_dev qspi_dev = \
|
||||
{ \
|
||||
.dev = { \
|
||||
.llist = ALT_LLIST_ENTRY, \
|
||||
.name = avl_mem##_NAME, \
|
||||
.write = alt_qspi_controller2_write, \
|
||||
.read = alt_qspi_controller2_read, \
|
||||
.get_info = alt_qspi_controller2_get_info, \
|
||||
.erase_block = alt_qspi_controller2_erase_block, \
|
||||
.write_block = alt_qspi_controller2_write_block, \
|
||||
.base_addr = ((void*)(avl_mem##_BASE)), \
|
||||
.length = ((int)(avl_mem##_SPAN)), \
|
||||
.lock = alt_qspi_controller2_lock , \
|
||||
}, \
|
||||
.data_base = ((alt_u32)(avl_mem##_BASE)), \
|
||||
.data_end = ((alt_u32)(avl_mem##_BASE) + (alt_u32)(avl_mem##_SPAN)), \
|
||||
.csr_base = ((alt_u32)(avl_csr##_BASE)), \
|
||||
.size_in_bytes = ((alt_u32)(avl_mem##_SPAN)), \
|
||||
.is_epcs = ((alt_u32)(avl_mem##_IS_EPCS)), \
|
||||
.number_of_sectors = ((alt_u32)(avl_mem##_NUMBER_OF_SECTORS)), \
|
||||
.sector_size = ((alt_u32)(avl_mem##_SECTOR_SIZE)), \
|
||||
.page_size = ((alt_u32)(avl_mem##_PAGE_SIZE)) , \
|
||||
}
|
||||
|
||||
/*
|
||||
Public API
|
||||
Refer to Using Flash Devices in the
|
||||
Developing Programs Using the Hardware Abstraction Layer chapter
|
||||
of the Nios II Software Developer's Handbook.
|
||||
*/
|
||||
|
||||
int alt_qspi_controller2_read(alt_flash_dev *flash_info, int offset, void *dest_addr, int length);
|
||||
|
||||
int alt_qspi_controller2_get_info(alt_flash_fd *fd, flash_region **info, int *number_of_regions);
|
||||
|
||||
int alt_qspi_controller2_erase_block(alt_flash_dev *flash_info, int block_offset);
|
||||
|
||||
int alt_qspi_controller2_write_block(alt_flash_dev *flash_info, int block_offset, int data_offset, const void *data, int length);
|
||||
|
||||
int alt_qspi_controller2_write(alt_flash_dev *flash_info, int offset, const void *src_addr, int length);
|
||||
|
||||
int alt_qspi_controller2_lock(alt_flash_dev *flash_info, alt_u32 sectors_to_lock);
|
||||
|
||||
|
||||
/*
|
||||
* Initialization function
|
||||
*/
|
||||
extern alt_32 altera_qspi_controller2_init(alt_qspi_controller2_dev *dev);
|
||||
|
||||
/*
|
||||
* alt_sys_init.c will call this macro automatically initialize the driver instance
|
||||
*/
|
||||
|
||||
#define ALTERA_GENERIC_QUAD_SPI_CONTROLLER2_INIT(name, dev) \
|
||||
altera_qspi_controller2_init(&dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __ALT_QSPI_CONTROLLER2_H__ */
|
File diff suppressed because it is too large
Load diff
|
@ -1,258 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2014 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_QSPI_CONTROLLER2_REGS_H__
|
||||
#define __ALTERA_QSPI_CONTROLLER2_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
|
||||
/*
|
||||
* QSPI_RD_STATUS register offset
|
||||
*
|
||||
* The QSPI_RD_STATUS register contains information from the read status
|
||||
* register operation. A full description of the register can be found in the
|
||||
* data sheet,
|
||||
*
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_STATUS_REG (0x0)
|
||||
|
||||
/*
|
||||
* QSPI_RD_STATUS register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_QSPI_CONTROLLER2_STATUS(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_QSPI_CONTROLLER2_STATUS_REG)
|
||||
|
||||
#define IORD_ALTERA_QSPI_CONTROLLER2_STATUS(base) \
|
||||
IORD_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_STATUS_REG)
|
||||
|
||||
#define IOWR_ALTERA_QSPI_CONTROLLER2_STATUS(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_STATUS_REG, data)
|
||||
|
||||
/*
|
||||
* QSPI_RD_STATUS register description macros
|
||||
*/
|
||||
|
||||
/** Write in progress bit */
|
||||
#define ALTERA_QSPI_CONTROLLER2_STATUS_WIP_MASK (0x00000001)
|
||||
#define ALTERA_QSPI_CONTROLLER2_STATUS_WIP_AVAILABLE (0x00000000)
|
||||
#define ALTERA_QSPI_CONTROLLER2_STATUS_WIP_BUSY (0x00000001)
|
||||
/** When to time out a poll of the write in progress bit */
|
||||
/* 0.7 sec time out */
|
||||
#define ALTERA_QSPI_CONTROLLER2_1US_TIMEOUT_VALUE 700000
|
||||
|
||||
/*
|
||||
* QSPI_RD_SID register offset
|
||||
*
|
||||
* The QSPI_RD_SID register contains the information from the read silicon ID
|
||||
* operation and can be used to determine what type of EPCS device we have.
|
||||
* Only support in EPCS16 and EPCS64.
|
||||
*
|
||||
* This register is valid only if the device is an EPCS.
|
||||
*
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_SID_REG (0x4)
|
||||
|
||||
/*
|
||||
* QSPI_RD_SID register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_QSPI_CONTROLLER2_SID(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_QSPI_CONTROLLER2_SID_REG)
|
||||
|
||||
#define IORD_ALTERA_QSPI_CONTROLLER2_SID(base) \
|
||||
IORD_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_SID_REG)
|
||||
|
||||
#define IOWR_ALTERA_QSPI_CONTROLLER2_SID(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_SID_REG, data)
|
||||
|
||||
/*
|
||||
* QSPI_RD_SID register description macros
|
||||
*
|
||||
* Specific device values obtained from Table 14 of:
|
||||
* "Serial Configuration (EPCS) Devices Datasheet"
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_SID_MASK (0x000000FF)
|
||||
#define ALTERA_QSPI_CONTROLLER2_SID_EPCS16 (0x00000014)
|
||||
#define ALTERA_QSPI_CONTROLLER2_SID_EPCS64 (0x00000016)
|
||||
#define ALTERA_QSPI_CONTROLLER2_SID_EPCS128 (0x00000018)
|
||||
|
||||
/*
|
||||
* QSPI_RD_RDID register offset
|
||||
*
|
||||
* The QSPI_RD_RDID register contains the information from the read memory
|
||||
* capacity operation and can be used to determine what type of EPCQ/QSPI device
|
||||
* we have.
|
||||
*
|
||||
* This register is only valid if the device is an EPCQ/QSPI.
|
||||
*
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_REG (0x8)
|
||||
|
||||
/*
|
||||
* QSPI_RD_RDID register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_QSPI_CONTROLLER2_RDID(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_QSPI_CONTROLLER2_RDID_REG)
|
||||
|
||||
#define IORD_ALTERA_QSPI_CONTROLLER2_RDID(base) \
|
||||
IORD_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_RDID_REG)
|
||||
|
||||
#define IOWR_ALTERA_QSPI_CONTROLLER2_RDID(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_RDID_REG, data)
|
||||
|
||||
/*
|
||||
* QSPI_RD_RDID register description macros
|
||||
*
|
||||
* Specific device values obtained from Table 28 of:
|
||||
* "Quad-Serial Configuration (EPCQ/QSPI? (www.altera.com/literature/hb/cfg/cfg_cf52012.pdf))
|
||||
* Devices Datasheet"
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_MASK (0x000000FF)
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_QSPI16 (0x00000015)
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_QSPI32 (0x00000016)
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_QSPI64 (0x00000017)
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_QSPI128 (0x00000018)
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_QSPI256 (0x00000019)
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_QSPI512 (0x00000020)
|
||||
#define ALTERA_QSPI_CONTROLLER2_RDID_QSPI1024 (0x00000021)
|
||||
|
||||
/*
|
||||
* QSPI_MEM_OP register offset
|
||||
*
|
||||
* The QSPI_MEM_OP register is used to do memory protect and erase operations
|
||||
*
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_MEM_OP_REG (0xC)
|
||||
|
||||
/*
|
||||
* QSPI_MEM_OP register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_QSPI_CONTROLLER2_MEM_OP(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_QSPI_CONTROLLER2_MEM_OP_REG)
|
||||
|
||||
#define IORD_ALTERA_QSPI_CONTROLLER2_MEM_OP(base) \
|
||||
IORD_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_MEM_OP_REG)
|
||||
|
||||
#define IOWR_ALTERA_QSPI_CONTROLLER2_MEM_OP(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_MEM_OP_REG, data)
|
||||
|
||||
/*
|
||||
* QSPI_MEM_OP register description macros
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_MEM_OP_CMD_MASK (0x00000003)
|
||||
#define ALTERA_QSPI_CONTROLLER2_MEM_OP_BULK_ERASE_CMD (0x00000001)
|
||||
#define ALTERA_QSPI_CONTROLLER2_MEM_OP_SECTOR_ERASE_CMD (0x00000002)
|
||||
#define ALTERA_QSPI_CONTROLLER2_MEM_OP_SECTOR_PROTECT_CMD (0x00000003)
|
||||
|
||||
/** see datasheet for sector values */
|
||||
#define ALTERA_QSPI_CONTROLLER2_MEM_OP_SECTOR_VALUE_MASK (0x00FFFF00)
|
||||
|
||||
/*
|
||||
* QSPI_ISR register offset
|
||||
*
|
||||
* The QSPI_ISR register is used to determine whether an invalid write or erase
|
||||
* operation triggered an interrupt
|
||||
*
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_ISR_REG (0x10)
|
||||
|
||||
/*
|
||||
* QSPI_ISR register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_QSPI_CONTROLLER2_ISR(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_QSPI_CONTROLLER2_ISR_REG)
|
||||
|
||||
#define IORD_ALTERA_QSPI_CONTROLLER2_ISR(base) \
|
||||
IORD_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_ISR_REG)
|
||||
|
||||
#define IOWR_ALTERA_QSPI_CONTROLLER2_ISR(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_ISR_REG, data)
|
||||
|
||||
/*
|
||||
* QSPI_ISR register description macros
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_ISR_ILLEGAL_ERASE_MASK (0x00000001)
|
||||
#define ALTERA_QSPI_CONTROLLER2_ISR_ILLEGAL_ERASE_ACTIVE (0x00000001)
|
||||
|
||||
#define ALTERA_QSPI_CONTROLLER2_ISR_ILLEGAL_WRITE_MASK (0x00000002)
|
||||
#define ALTERA_QSPI_CONTROLLER2_ISR_ILLEGAL_WRITE_ACTIVE (0x00000002)
|
||||
|
||||
|
||||
/*
|
||||
* QSPI_IMR register offset
|
||||
*
|
||||
* The QSPI_IMR register is used to mask the invalid erase or the invalid write
|
||||
* interrupts.
|
||||
*
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_IMR_REG (0x14)
|
||||
|
||||
/*
|
||||
* QSPI_IMR register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_QSPI_CONTROLLER2_IMR(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_QSPI_CONTROLLER2_IMR_REG)
|
||||
|
||||
#define IORD_ALTERA_QSPI_CONTROLLER2_IMR(base) \
|
||||
IORD_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_IMR_REG)
|
||||
|
||||
#define IOWR_ALTERA_QSPI_CONTROLLER2_IMR(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_QSPI_CONTROLLER2_IMR_REG, data)
|
||||
|
||||
/*
|
||||
* QSPI_IMR register description macros
|
||||
*/
|
||||
#define ALTERA_QSPI_CONTROLLER2_IMR_ILLEGAL_ERASE_MASK (0x00000001)
|
||||
#define ALTERA_QSPI_CONTROLLER2_IMR_ILLEGAL_ERASE_ENABLED (0x00000001)
|
||||
|
||||
#define ALTERA_QSPI_CONTROLLER2_IMR_ILLEGAL_WRITE_MASK (0x00000002)
|
||||
#define ALTERA_QSPI_CONTROLLER2_IMR_ILLEGAL_WRITE_ENABLED (0x00000002)
|
||||
|
||||
/*
|
||||
* QSPI_CHIP_SELECT register offset
|
||||
*
|
||||
* The QSPI_CHIP_SELECT register is used to issue chip select
|
||||
*/
|
||||
#define ALTERA_QSPI_CHIP_SELECT_REG (0x18)
|
||||
|
||||
/*
|
||||
* QSPI_CHIP_SELECT register access macros
|
||||
*/
|
||||
#define IOADDR_ALTERA_QSPI_CHIP_SELECT(base) \
|
||||
__IO_CALC_ADDRESS_DYNAMIC(base, ALTERA_QSPI_CHIP_SELECT_REG)
|
||||
|
||||
#define IOWR_ALTERA_QSPI_CHIP_SELECT(base, data) \
|
||||
IOWR_32DIRECT(base, ALTERA_QSPI_CHIP_SELECT_REG, data)
|
||||
|
||||
/*
|
||||
* QSPI_CHIP_SELECT register description macros
|
||||
*/
|
||||
#define ALTERA_QSPI_CHIP1_SELECT (0x00000001)
|
||||
#define ALTERA_QSPI_CHIP2_SELECT (0x00000002)
|
||||
#define ALTERA_QSPI_CHIP3_SELECT (0x00000003)
|
||||
|
||||
#endif /* __ALTERA_QSPI_CONTROLLER2_REGS_H__ */
|
|
@ -1,501 +0,0 @@
|
|||
/******************************************************************************
|
||||
* *
|
||||
* License Agreement *
|
||||
* *
|
||||
* Copyright (c) 2014 Altera Corporation, San Jose, California, USA. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
* copy of this software and associated documentation files (the "Software"), *
|
||||
* to deal in the Software without restriction, including without limitation *
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
* and/or sell copies of the Software, and to permit persons to whom the *
|
||||
* Software is furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in *
|
||||
* all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
* DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ALTERA_MSGDMA_H__
|
||||
#define __ALTERA_MSGDMA_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sys/alt_dev.h"
|
||||
#include "alt_types.h"
|
||||
#include "altera_msgdma_csr_regs.h"
|
||||
#include "altera_msgdma_descriptor_regs.h"
|
||||
#include "altera_msgdma_response_regs.h"
|
||||
#include "altera_msgdma_prefetcher_regs.h"
|
||||
#include "os/alt_sem.h"
|
||||
#include "os/alt_flag.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* Helper struct to have easy access to hi/low values from a 64 bit value.
|
||||
* Useful when having to write prefetcher/descriptor 64 bit addresses.
|
||||
*/
|
||||
typedef union {
|
||||
alt_u64 u64;
|
||||
alt_u32 u32[2];
|
||||
} msgdma_addr64;
|
||||
|
||||
/*
|
||||
* To ensure that a descriptor is created without spaces between the structure
|
||||
* members, we call upon GCC's ability to pack to a byte-aligned boundary.
|
||||
* Additionally, msgdma requires the descriptors to be aligned to a 16 byte
|
||||
* boundary.
|
||||
*/
|
||||
#define alt_msgdma_standard_descriptor_packed \
|
||||
__attribute__ ((packed, aligned(16)))
|
||||
#define alt_msgdma_extended_descriptor_packed \
|
||||
__attribute__ ((packed, aligned(32)))
|
||||
#define alt_msgdma_prefetcher_standard_descriptor_packed \
|
||||
__attribute__ ((packed, aligned(32)))
|
||||
#define alt_msgdma_prefetcher_extended_descriptor_packed \
|
||||
__attribute__ ((packed, aligned(64)))
|
||||
#define alt_msgdma_response_packed __attribute__ ((packed, aligned(4)))
|
||||
|
||||
/*
|
||||
* The function alt_find_dev() is used to search the device list "list" to
|
||||
* locate a device named "name". If a match is found, then a pointer to the
|
||||
* device is returned, otherwise NULL is returned.
|
||||
*/
|
||||
extern alt_dev* alt_find_dev (const char* name, alt_llist* list);
|
||||
|
||||
/* Callback routine type definition */
|
||||
typedef void (*alt_msgdma_callback)(void *context);
|
||||
|
||||
/* use this structure if you haven't enabled the enhanced features */
|
||||
typedef struct {
|
||||
alt_u32 *read_address;
|
||||
alt_u32 *write_address;
|
||||
alt_u32 transfer_length;
|
||||
alt_u32 control;
|
||||
} alt_msgdma_standard_descriptor_packed alt_msgdma_standard_descriptor;
|
||||
|
||||
/* use this structure if you have enabled the enhanced features (only the
|
||||
* elements enabled in hardware will be used)
|
||||
*/
|
||||
typedef struct {
|
||||
alt_u32 *read_address_low;
|
||||
alt_u32 *write_address_low;
|
||||
alt_u32 transfer_length;
|
||||
alt_u16 sequence_number;
|
||||
alt_u8 read_burst_count;
|
||||
alt_u8 write_burst_count;
|
||||
alt_u16 read_stride;
|
||||
alt_u16 write_stride;
|
||||
alt_u32 *read_address_high;
|
||||
alt_u32 *write_address_high;
|
||||
alt_u32 control;
|
||||
} alt_msgdma_extended_descriptor_packed alt_msgdma_extended_descriptor;
|
||||
|
||||
|
||||
/* Prefetcher Descriptors need to be different than standard dispatcher
|
||||
* descriptors use this structure if you haven't enabled the enhanced
|
||||
* features
|
||||
*/
|
||||
typedef struct {
|
||||
alt_u32 read_address;
|
||||
alt_u32 write_address;
|
||||
alt_u32 transfer_length;
|
||||
alt_u32 next_desc_ptr;
|
||||
alt_u32 bytes_transfered;
|
||||
alt_u16 status;
|
||||
alt_u16 _pad1_rsvd;
|
||||
alt_u32 _pad2_rsvd;
|
||||
alt_u32 control;
|
||||
} alt_msgdma_prefetcher_standard_descriptor_packed alt_msgdma_prefetcher_standard_descriptor;
|
||||
|
||||
/* use this structure if you have enabled the enhanced features (only the elements
|
||||
enabled in hardware will be used) */
|
||||
typedef struct {
|
||||
alt_u32 read_address_low;
|
||||
alt_u32 write_address_low;
|
||||
alt_u32 transfer_length;
|
||||
alt_u32 next_desc_ptr_low;
|
||||
alt_u32 bytes_transfered;
|
||||
alt_u16 status;
|
||||
alt_u16 _pad1_rsvd;
|
||||
alt_u32 _pad2_rsvd;
|
||||
alt_u16 sequence_number;
|
||||
alt_u8 read_burst_count;
|
||||
alt_u8 write_burst_count;
|
||||
alt_u16 read_stride;
|
||||
alt_u16 write_stride;
|
||||
alt_u32 read_address_high;
|
||||
alt_u32 write_address_high;
|
||||
alt_u32 next_desc_ptr_high;
|
||||
alt_u32 _pad3_rsvd[3];
|
||||
alt_u32 control;
|
||||
} alt_msgdma_prefetcher_extended_descriptor_packed alt_msgdma_prefetcher_extended_descriptor;
|
||||
|
||||
|
||||
/* msgdma device structure */
|
||||
typedef struct alt_msgdma_dev
|
||||
{
|
||||
/* Device linked-list entry */
|
||||
alt_llist llist;
|
||||
/* Name of msgdma in Qsys system */
|
||||
const char *name;
|
||||
/* Base address of control and status register */
|
||||
alt_u32 *csr_base;
|
||||
/* Base address of the descriptor slave port */
|
||||
alt_u32 *descriptor_base;
|
||||
/* Base address of the response register */
|
||||
alt_u32 *response_base;
|
||||
/* Base address of the prefetcher register */
|
||||
alt_u32 *prefetcher_base;
|
||||
/* device IRQ controller ID */
|
||||
alt_u32 irq_controller_ID;
|
||||
/* device IRQ ID */
|
||||
alt_u32 irq_ID;
|
||||
/* FIFO size to store descriptor count,
|
||||
{ 8, 16, 32, 64,default:128, 256, 512, 1024 } */
|
||||
alt_u32 descriptor_fifo_depth;
|
||||
/* FIFO size to store response count */
|
||||
alt_u32 response_fifo_depth;
|
||||
/* Callback routine pointer */
|
||||
alt_msgdma_callback callback;
|
||||
/* Callback context pointer */
|
||||
void *callback_context;
|
||||
/* user define control setting during interrupt registering*/
|
||||
alt_u32 control;
|
||||
/* Enable burst transfer */
|
||||
alt_u8 burst_enable;
|
||||
/* Enable burst wrapping */
|
||||
alt_u8 burst_wrapping_support;
|
||||
/* Depth of the internal data path FIFO*/
|
||||
alt_u32 data_fifo_depth;
|
||||
/* Data path Width. This parameter affect both read
|
||||
master and write master data width */
|
||||
alt_u32 data_width;
|
||||
/* Maximum burst count*/
|
||||
alt_u32 max_burst_count;
|
||||
/* Maximum transfer length*/
|
||||
alt_u32 max_byte;
|
||||
/* Maximum stride count */
|
||||
alt_u64 max_stride;
|
||||
/* Enable dynamic burst programming*/
|
||||
alt_u8 programmable_burst_enable;
|
||||
/* Enable stride addressing */
|
||||
alt_u8 stride_enable;
|
||||
/* Supported transaction type */
|
||||
const char *transfer_type;
|
||||
/* Extended feature support enable "1"-enable "0"-disable */
|
||||
alt_u8 enhanced_features;
|
||||
/* Enable response port "0"-memory-mapped, "1"-streaming, "2"-disable */
|
||||
alt_u8 response_port;
|
||||
/* Prefetcher enabled "0"-disabled, "1"-enabled*/
|
||||
alt_u8 prefetcher_enable;
|
||||
/* Semaphore used to control access registers
|
||||
in multi-threaded mode */
|
||||
ALT_SEM (regs_lock)
|
||||
} alt_msgdma_dev;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Public API
|
||||
******************************************************************************/
|
||||
alt_msgdma_dev* alt_msgdma_open (const char* name);
|
||||
|
||||
void alt_msgdma_register_callback(
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_callback callback,
|
||||
alt_u32 control,
|
||||
void *context);
|
||||
|
||||
int alt_msgdma_standard_descriptor_async_transfer(
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_standard_descriptor *desc);
|
||||
|
||||
int alt_msgdma_extended_descriptor_async_transfer(
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_extended_descriptor *desc);
|
||||
|
||||
int alt_msgdma_construct_standard_mm_to_mm_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_standard_descriptor *descriptor,
|
||||
alt_u32 *read_address,
|
||||
alt_u32 *write_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control);
|
||||
|
||||
int alt_msgdma_construct_standard_st_to_mm_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_standard_descriptor *descriptor,
|
||||
alt_u32 *write_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control);
|
||||
|
||||
int alt_msgdma_construct_standard_mm_to_st_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_standard_descriptor *descriptor,
|
||||
alt_u32 *read_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control);
|
||||
|
||||
int alt_msgdma_construct_extended_st_to_mm_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_extended_descriptor *descriptor,
|
||||
alt_u32 *write_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control,
|
||||
alt_u16 sequence_number,
|
||||
alt_u8 write_burst_count,
|
||||
alt_u16 write_stride);
|
||||
|
||||
int alt_msgdma_construct_extended_mm_to_st_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_extended_descriptor *descriptor,
|
||||
alt_u32 *read_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control,
|
||||
alt_u16 sequence_number,
|
||||
alt_u8 read_burst_count,
|
||||
alt_u16 read_stride);
|
||||
|
||||
int alt_msgdma_construct_extended_mm_to_mm_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_extended_descriptor *descriptor,
|
||||
alt_u32 *read_address,
|
||||
alt_u32 *write_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control,
|
||||
alt_u16 sequence_number,
|
||||
alt_u8 read_burst_count,
|
||||
alt_u8 write_burst_count,
|
||||
alt_u16 read_stride,
|
||||
alt_u16 write_stride);
|
||||
|
||||
int alt_msgdma_standard_descriptor_sync_transfer(
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_standard_descriptor *desc);
|
||||
|
||||
int alt_msgdma_extended_descriptor_sync_transfer(
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_extended_descriptor *desc);
|
||||
|
||||
int alt_msgdma_standard_descriptor_sync_transfer(
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_standard_descriptor *desc);
|
||||
|
||||
/***************** MSGDMA PREFETCHER PUBLIC APIs ******************/
|
||||
int alt_msgdma_construct_prefetcher_standard_mm_to_mm_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_prefetcher_standard_descriptor *descriptor,
|
||||
alt_u32 read_address,
|
||||
alt_u32 write_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control);
|
||||
|
||||
int alt_msgdma_construct_prefetcher_standard_st_to_mm_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_prefetcher_standard_descriptor *descriptor,
|
||||
alt_u32 write_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control);
|
||||
|
||||
int alt_msgdma_construct_prefetcher_standard_mm_to_st_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_prefetcher_standard_descriptor *descriptor,
|
||||
alt_u32 read_address,
|
||||
alt_u32 length,
|
||||
alt_u32 control);
|
||||
|
||||
int alt_msgdma_construct_prefetcher_extended_st_to_mm_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_prefetcher_extended_descriptor *descriptor,
|
||||
alt_u32 write_address_high,
|
||||
alt_u32 write_address_low,
|
||||
alt_u32 length,
|
||||
alt_u32 control,
|
||||
alt_u16 sequence_number,
|
||||
alt_u8 write_burst_count,
|
||||
alt_u16 write_stride);
|
||||
|
||||
int alt_msgdma_construct_prefetcher_extended_mm_to_st_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_prefetcher_extended_descriptor *descriptor,
|
||||
alt_u32 read_address_high,
|
||||
alt_u32 read_address_low,
|
||||
alt_u32 length,
|
||||
alt_u32 control,
|
||||
alt_u16 sequence_number,
|
||||
alt_u8 read_burst_count,
|
||||
alt_u16 read_stride);
|
||||
|
||||
int alt_msgdma_construct_prefetcher_extended_mm_to_mm_descriptor (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_prefetcher_extended_descriptor *descriptor,
|
||||
alt_u32 read_address_high,
|
||||
alt_u32 read_address_low,
|
||||
alt_u32 write_address_high,
|
||||
alt_u32 write_address_low,
|
||||
alt_u32 length,
|
||||
alt_u32 control,
|
||||
alt_u16 sequence_number,
|
||||
alt_u8 read_burst_count,
|
||||
alt_u8 write_burst_count,
|
||||
alt_u16 read_stride,
|
||||
alt_u16 write_stride);
|
||||
|
||||
int alt_msgdma_prefetcher_add_standard_desc_to_list (
|
||||
alt_msgdma_prefetcher_standard_descriptor** list,
|
||||
alt_msgdma_prefetcher_standard_descriptor* descriptor);
|
||||
|
||||
int alt_msgdma_prefetcher_add_extended_desc_to_list (
|
||||
alt_msgdma_prefetcher_extended_descriptor** list,
|
||||
alt_msgdma_prefetcher_extended_descriptor* descriptor);
|
||||
|
||||
int alt_msgdma_start_prefetcher_with_std_desc_list (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_prefetcher_standard_descriptor *list,
|
||||
alt_u8 park_mode_en,
|
||||
alt_u8 poll_en);
|
||||
|
||||
int alt_msgdma_start_prefetcher_with_extd_desc_list (
|
||||
alt_msgdma_dev *dev,
|
||||
alt_msgdma_prefetcher_extended_descriptor *list,
|
||||
alt_u8 park_mode_en,
|
||||
alt_u8 poll_en);
|
||||
|
||||
int alt_msgdma_prefetcher_set_std_list_own_by_hw_bits (
|
||||
alt_msgdma_prefetcher_standard_descriptor *list);
|
||||
int alt_msgdma_prefetcher_set_extd_list_own_by_hw_bits (
|
||||
alt_msgdma_prefetcher_extended_descriptor *list);
|
||||
|
||||
void alt_msgdma_init (alt_msgdma_dev *dev, alt_u32 ic_id, alt_u32 irq);
|
||||
|
||||
/* HAL initialization macros */
|
||||
|
||||
/*Depth of internal data path FIFO.STRIDE_ENABLE
|
||||
* ALTERA_MSGDMA_INSTANCE is the macro used by alt_sys_init() to
|
||||
* allocate any per device memory that may be required.
|
||||
*/
|
||||
#define ALTERA_MSGDMA_CSR_DESCRIPTOR_SLAVE_RESPONSE_INSTANCE(name, csr_if, desc_if, resp_if, dev) \
|
||||
static alt_msgdma_dev dev = \
|
||||
{ \
|
||||
ALT_LLIST_ENTRY, \
|
||||
name##_CSR_NAME, \
|
||||
((alt_u32 *)(csr_if##_BASE)), \
|
||||
((alt_u32 *)(desc_if##_BASE)), \
|
||||
((alt_u32 *)(resp_if##_BASE)), \
|
||||
((alt_u32 *)(0)), \
|
||||
((alt_u32 )name##_CSR_IRQ_INTERRUPT_CONTROLLER_ID), \
|
||||
((alt_u32 )name##_CSR_IRQ), \
|
||||
((alt_u32 )desc_if##_DESCRIPTOR_FIFO_DEPTH), \
|
||||
((alt_u32 )resp_if##_DESCRIPTOR_FIFO_DEPTH * 2), \
|
||||
((void *) 0x0), \
|
||||
((void *) 0x0), \
|
||||
((alt_u32) 0x0), \
|
||||
((alt_u8) csr_if##_BURST_ENABLE), \
|
||||
((alt_u8) csr_if##_BURST_WRAPPING_SUPPORT), \
|
||||
((alt_u32) csr_if##_DATA_FIFO_DEPTH), \
|
||||
((alt_u32) csr_if##_DATA_WIDTH), \
|
||||
((alt_u32) csr_if##_MAX_BURST_COUNT), \
|
||||
((alt_u32) csr_if##_MAX_BYTE), \
|
||||
((alt_u64) csr_if##_MAX_STRIDE), \
|
||||
((alt_u8) csr_if##_PROGRAMMABLE_BURST_ENABLE), \
|
||||
((alt_u8) csr_if##_STRIDE_ENABLE), \
|
||||
csr_if##_TRANSFER_TYPE, \
|
||||
((alt_u8) csr_if##_ENHANCED_FEATURES), \
|
||||
((alt_u8) csr_if##_RESPONSE_PORT), \
|
||||
((alt_u8) csr_if##_PREFETCHER_ENABLE) \
|
||||
};
|
||||
|
||||
#define ALTERA_MSGDMA_CSR_DESCRIPTOR_SLAVE_INSTANCE(name, csr_if, desc_if, dev) \
|
||||
static alt_msgdma_dev dev = \
|
||||
{ \
|
||||
ALT_LLIST_ENTRY, \
|
||||
name##_CSR_NAME, \
|
||||
((alt_u32 *)(csr_if##_BASE)), \
|
||||
((alt_u32 *)(desc_if##_BASE)), \
|
||||
((alt_u32 *)(0)), \
|
||||
((alt_u32 *)(0)), \
|
||||
((alt_u32 )name##_CSR_IRQ_INTERRUPT_CONTROLLER_ID), \
|
||||
((alt_u32 )name##_CSR_IRQ), \
|
||||
((alt_u32 )desc_if##_DESCRIPTOR_FIFO_DEPTH), \
|
||||
((alt_u32) 0x0), \
|
||||
((void *) 0x0), \
|
||||
((void *) 0x0), \
|
||||
((alt_u32) 0x0), \
|
||||
((alt_u8) csr_if##_BURST_ENABLE), \
|
||||
((alt_u8) csr_if##_BURST_WRAPPING_SUPPORT), \
|
||||
((alt_u32) csr_if##_DATA_FIFO_DEPTH), \
|
||||
((alt_u32) csr_if##_DATA_WIDTH), \
|
||||
((alt_u32) csr_if##_MAX_BURST_COUNT), \
|
||||
((alt_u32) csr_if##_MAX_BYTE), \
|
||||
((alt_u64) csr_if##_MAX_STRIDE), \
|
||||
((alt_u8) csr_if##_PROGRAMMABLE_BURST_ENABLE), \
|
||||
((alt_u8) csr_if##_STRIDE_ENABLE), \
|
||||
csr_if##_TRANSFER_TYPE, \
|
||||
((alt_u8) csr_if##_ENHANCED_FEATURES), \
|
||||
((alt_u8) csr_if##_RESPONSE_PORT), \
|
||||
((alt_u8) csr_if##_PREFETCHER_ENABLE) \
|
||||
};
|
||||
|
||||
/*
|
||||
* New Interface for Prefetcher 15/6/2015.
|
||||
*/
|
||||
#define ALTERA_MSGDMA_CSR_PREFETCHER_CSR_INSTANCE(name, csr_if, pref_if, dev) \
|
||||
static alt_msgdma_dev dev = \
|
||||
{ \
|
||||
ALT_LLIST_ENTRY, \
|
||||
name##_CSR_NAME, \
|
||||
((alt_u32 *)(csr_if##_BASE)), \
|
||||
((alt_u32 *)(0)), \
|
||||
((alt_u32 *)(0)), \
|
||||
((alt_u32 *)(pref_if##_BASE)), \
|
||||
((alt_u32 )name##_PREFETCHER_CSR_IRQ_INTERRUPT_CONTROLLER_ID), \
|
||||
((alt_u32 )name##_PREFETCHER_CSR_IRQ), \
|
||||
((alt_u32 )(0)), \
|
||||
((alt_u32) 0x0), \
|
||||
((void *) 0x0), \
|
||||
((void *) 0x0), \
|
||||
((alt_u32) 0x0), \
|
||||
((alt_u8) csr_if##_BURST_ENABLE), \
|
||||
((alt_u8) csr_if##_BURST_WRAPPING_SUPPORT), \
|
||||
((alt_u32) csr_if##_DATA_FIFO_DEPTH), \
|
||||
((alt_u32) csr_if##_DATA_WIDTH), \
|
||||
((alt_u32) csr_if##_MAX_BURST_COUNT), \
|
||||
((alt_u32) csr_if##_MAX_BYTE), \
|
||||
((alt_u64) csr_if##_MAX_STRIDE), \
|
||||
((alt_u8) csr_if##_PROGRAMMABLE_BURST_ENABLE), \
|
||||
((alt_u8) csr_if##_STRIDE_ENABLE), \
|
||||
csr_if##_TRANSFER_TYPE, \
|
||||
((alt_u8) csr_if##_ENHANCED_FEATURES), \
|
||||
((alt_u8) csr_if##_RESPONSE_PORT), \
|
||||
((alt_u8) csr_if##_PREFETCHER_ENABLE) \
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The macro ALTERA_MSGDMA_INIT is called by the auto-generated function
|
||||
* alt_sys_init() to initialize a given device instance.
|
||||
*/
|
||||
#define ALTERA_MSGDMA_INIT(name, dev) \
|
||||
alt_msgdma_init(&dev, dev.irq_controller_ID, dev.irq_ID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ALTERA_MSGDMA_H__ */
|
|
@ -1 +0,0 @@
|
|||
zephyr_sources(altera_msgdma.c)
|
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue