Versuch 2 Software funktioniert

This commit is contained in:
brandlfl78731
2024-11-20 10:33:56 +01:00
parent 00fd3908d8
commit 03a4e64337
155 changed files with 21664 additions and 5 deletions
@@ -0,0 +1,199 @@
/******************************************************************************
* *
* 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. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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_hooks.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;
volatile 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__ */
@@ -0,0 +1,125 @@
/******************************************************************************
* *
* 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. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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__ */
@@ -0,0 +1,73 @@
/******************************************************************************
* *
* 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 agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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__ */
@@ -0,0 +1,67 @@
/******************************************************************************
* *
* 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 agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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__ */
@@ -0,0 +1,60 @@
#ifndef __ALT_AVALON_SYSID_QSYS_H__
#define __ALT_AVALON_SYSID_QSYS_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 agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
* 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_QSYS_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_QSYS_INSTANCE(name, dev) extern int alt_no_storage
#define ALTERA_AVALON_SYSID_QSYS_INIT(name, dev) while (0)
#ifdef SYSID_BASE
alt_32 alt_avalon_sysid_qsys_test(void);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __ALT_AVALON_SYSID_QSYS_H__ */
@@ -0,0 +1,42 @@
/******************************************************************************
* *
* 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 agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#ifndef __ALTERA_AVALON_SYSID_QSYS_REGS_H__
#define __ALTERA_AVALON_SYSID_QSYS_REGS_H__
#include <io.h>
#define IOADDR_ALTERA_AVALON_SYSID_QSYS_ID(base) __IO_CALC_ADDRESS_NATIVE(base, 0)
#define IORD_ALTERA_AVALON_SYSID_QSYS_ID(base) IORD(base, 0)
#define IOADDR_ALTERA_AVALON_SYSID_QSYS_TIMESTAMP(base) __IO_CALC_ADDRESS_NATIVE(base, 1)
#define IORD_ALTERA_AVALON_SYSID_QSYS_TIMESTAMP(base) IORD(base, 1)
#endif /* __ALTERA_AVALON_SYSID_QSYS_REGS_H__ */
@@ -0,0 +1,86 @@
/******************************************************************************
* *
* 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. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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 */
@@ -0,0 +1,263 @@
/******************************************************************************
* *
* 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. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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;
unsigned int postflag=0;
/* 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, ALT_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;
/* indicate that the ALT_FLAG_POST routine must be called */
postflag=1;
space--;
}
if (postflag)
{
/* Post an event to notify jtag_uart_write that a character has been written */
ALT_FLAG_POST (sp->events, ALT_JTAG_UART_WRITE_RDY, ALT_FLAG_SET);
}
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, ALT_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 */
@@ -0,0 +1,86 @@
/******************************************************************************
* *
* 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. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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 */
@@ -0,0 +1,201 @@
/******************************************************************************
* *
* 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. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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 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 __rtos__
/* OS Present: Pend on a flag if the OS is running, otherwise spin */
if(ALT_OS_IS_RUNNING()) {
/*
* 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,
ALT_FLAG_WAIT_SET_ANY_WITH_CONSUME,
ALT_FLAG_WAIT_MAX_TIMEOUT);
}
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 */
@@ -0,0 +1,213 @@
/******************************************************************************
* *
* 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. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#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 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 __rtos__
/* OS Present: Pend on a flag if the OS is running, otherwise spin */
if(ALT_OS_IS_RUNNING()) {
/*
* 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,
ALT_FLAG_WAIT_SET_ANY_WITH_CONSUME,
ALT_FLAG_WAIT_MAX_TIMEOUT);
}
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 */
@@ -0,0 +1,82 @@
/******************************************************************************
* *
* 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 agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
* 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_qsys.h"
#include "altera_avalon_sysid_qsys_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_qsys_test(void)
{
/* Read the hardware-tag, aka value0, from the hardware. */
alt_u32 hardware_id = IORD_ALTERA_AVALON_SYSID_QSYS_ID(SYSID_BASE);
/* Read the time-of-generation, aka value1, from the hardware register. */
alt_u32 hardware_timestamp = IORD_ALTERA_AVALON_SYSID_QSYS_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