signal current_task_state : work.task.State; | signal current_task_state : work.task.State; | ||||
signal next_task_state : work.task.State; | signal next_task_state : work.task.State; | ||||
signal index : integer range 0 to work.task.STREAM_LEN; | signal index : integer range 0 to work.task.STREAM_LEN; | ||||
signal fpuDone : std_logic; | |||||
signal START : std_logic; | |||||
type AddState is ( | |||||
ADD_IDLE, | |||||
ADD_SET_SIGNALS, | |||||
ADD_RUNNING, | |||||
ADD_DONE | |||||
); | |||||
signal current_add_state : AddState; | |||||
signal next_add_state : AddState; | |||||
begin | begin | ||||
f1:ENTITY work.float_add PORT MAP(CLK => CLK, RESET => RESET, START => START, A => signal_a_readdata, B => signal_b_readdata, done => fpuDone, sum => signal_writedata); | |||||
task_state_transitions : process ( current_task_state, task_start, index ) is | task_state_transitions : process ( current_task_state, task_start, index ) is | ||||
begin | begin | ||||
next_task_state <= current_task_state; | next_task_state <= current_task_state; | ||||
case next_task_state is | case next_task_state is | ||||
when work.task.TASK_IDLE => | when work.task.TASK_IDLE => | ||||
index <= 0; | index <= 0; | ||||
signal_write <= '0'; | |||||
when work.task.TASK_RUNNING => | when work.task.TASK_RUNNING => | ||||
index <= index + 1; | |||||
signal_write <= '1'; | |||||
signal_writedata <= ( others => '0' ); | |||||
if(current_add_state = ADD_DONE) then | |||||
index <= index + 1; | |||||
end if; | |||||
when work.task.TASK_DONE => | when work.task.TASK_DONE => | ||||
index <= 0; | index <= 0; | ||||
signal_write <= '0'; | |||||
end case; | end case; | ||||
end if; | end if; | ||||
end process sync; | end process sync; | ||||
task_state <= current_task_state; | task_state <= current_task_state; | ||||
add_state_transitions : process ( current_add_state, fpuDone, current_task_state) | |||||
begin | |||||
next_add_state <= current_add_state; | |||||
case current_add_state is | |||||
when ADD_IDLE => | |||||
if(current_task_state = work.task.TASK_RUNNING) then | |||||
next_add_state <= ADD_SET_SIGNALS; | |||||
end if; | |||||
when ADD_SET_SIGNALS => | |||||
next_add_state <= ADD_RUNNING; | |||||
when ADD_RUNNING => | |||||
if(fpuDone = '1') then | |||||
next_add_state <= ADD_DONE; | |||||
end if; | |||||
when ADD_DONE => | |||||
next_add_state <= ADD_IDLE; | |||||
end case; | |||||
end process add_state_transitions; | |||||
add : process (clk, reset) is | |||||
begin | |||||
if ( reset = '1' ) then | |||||
current_add_state <= ADD_IDLE; | |||||
elsif ( rising_edge( clk ) ) then | |||||
current_add_state <= next_add_state; | |||||
case next_add_state is | |||||
when ADD_IDLE => | |||||
START <= '0'; | |||||
signal_write <= '0'; | |||||
when ADD_SET_SIGNALS => | |||||
signal_a_read <= '1'; | |||||
signal_b_read <= '1'; | |||||
when ADD_RUNNING => | |||||
signal_a_read <= '0'; | |||||
signal_b_read <= '0'; | |||||
START <= '1'; | |||||
when ADD_DONE => | |||||
START <= '0'; | |||||
signal_write <= '1'; | |||||
end case; | |||||
end if; | |||||
end process add; | |||||
end architecture rtl; | end architecture rtl; |
signal current_task_state : work.task.State; | signal current_task_state : work.task.State; | ||||
signal next_task_state : work.task.State; | signal next_task_state : work.task.State; | ||||
signal index : integer range 0 to work.task.STREAM_LEN; | signal index : integer range 0 to work.task.STREAM_LEN; | ||||
signal angle_calc : signed(31 downto 0); | |||||
signal angle_busy : std_logic; | |||||
signal angle_valid : std_logic; | |||||
signal angle_result : signed(31 downto 0); | |||||
signal START : std_logic; | |||||
signal angle_amplitude : reg32.word; | |||||
type angle_matrix is ARRAY(natural range<>) of signed; | |||||
signal angle_lut : angle_matrix (31 downto 0) (31 downto 0); | |||||
angle_lut(0) <= "0"; | |||||
angle_lut(1) <= "138547331"; | |||||
angle_lut(2) <= "277094662"; | |||||
angle_lut(3) <= "415641993"; | |||||
angle_lut(4) <= "554189324"; | |||||
angle_lut(5) <= "692736655"; | |||||
angle_lut(6) <= "831283986"; | |||||
angle_lut(7) <= "969831317"; | |||||
angle_lut(8) <= "1108378649"; | |||||
angle_lut(9) <= "1246925980"; | |||||
angle_lut(10) <= "1385473311"; | |||||
angle_lut(11) <= "1524020642"; | |||||
angle_lut(12) <= "1662567973"; | |||||
angle_lut(13) <= "1801115304"; | |||||
angle_lut(14) <= "1939662635"; | |||||
angle_lut(15) <= "2078209966"; | |||||
angle_lut(16) <= "2216757298"; | |||||
angle_lut(17) <= "2355304629"; | |||||
angle_lut(18) <= "2493851960"; | |||||
angle_lut(19) <= "2632399291"; | |||||
angle_lut(20) <= "2770946622"; | |||||
angle_lut(21) <= "2909493953"; | |||||
angle_lut(22) <= "3048041284"; | |||||
angle_lut(23) <= "3186588615"; | |||||
angle_lut(24) <= "3325135947"; | |||||
angle_lut(25) <= "3463683278"; | |||||
angle_lut(26) <= "3602230609"; | |||||
angle_lut(27) <= "3740777940"; | |||||
angle_lut(28) <= "3879325271"; | |||||
angle_lut(29) <= "4017872602"; | |||||
angle_lut(30) <= "4156419933"; | |||||
angle_lut(31) <= "4294967265"; | |||||
type AngleState is ( | |||||
ANGLE_IDLE, | |||||
ANGLE_SET_SIGNALS, | |||||
ANGLE_RUNNING, | |||||
ANGLE_DONE | |||||
); | |||||
signal current_angle_state : AngleState; | |||||
signal next_angle_state : AngleState; | |||||
begin | begin | ||||
f1:ENTITY work.float_sine PORT MAP(CLK => CLK, RESET => RESET, data_valid => START, angle =>angle_calc, busy => angle_busy, result_valid => angle_valid, sine => angle_result); | |||||
task_state_transitions : process ( current_task_state, task_start, index ) is | task_state_transitions : process ( current_task_state, task_start, index ) is | ||||
begin | begin | ||||
next_task_state <= current_task_state; | next_task_state <= current_task_state; | ||||
end case; | end case; | ||||
end process task_state_transitions; | end process task_state_transitions; | ||||
sync : process ( clk, reset ) is | |||||
sync : process ( clk, reset ) is | |||||
begin | begin | ||||
if ( reset = '1' ) then | if ( reset = '1' ) then | ||||
current_task_state <= work.task.TASK_IDLE; | current_task_state <= work.task.TASK_IDLE; | ||||
case next_task_state is | case next_task_state is | ||||
when work.task.TASK_IDLE => | when work.task.TASK_IDLE => | ||||
index <= 0; | index <= 0; | ||||
signal_write <= '0'; | |||||
when work.task.TASK_RUNNING => | when work.task.TASK_RUNNING => | ||||
index <= index + 1; | |||||
signal_write <= '1'; | |||||
signal_writedata <= ( others => '0' ); | |||||
if(current_angle_state = ANGLE_DONE) then | |||||
index <= index + 1; | |||||
end if; | |||||
when work.task.TASK_DONE => | when work.task.TASK_DONE => | ||||
index <= 0; | index <= 0; | ||||
signal_write <= '0'; | |||||
end case; | end case; | ||||
end if; | end if; | ||||
end process sync; | end process sync; | ||||
end process sync; | |||||
task_state <= current_task_state; | task_state <= current_task_state; | ||||
angle_state_transitions : process ( current_angle_state, angle_valid, current_angle_state) | |||||
begin | |||||
next_angle_state <= current_angle_state; | |||||
case current_angle_state is | |||||
when ANGLE_IDLE => | |||||
if(current_angle_state = work.task.TASK_RUNNING) then | |||||
next_angle_state <= ANGLE_SET_SIGNALS; | |||||
end if; | |||||
when ANGLE_SET_SIGNALS => | |||||
next_angle_state <= ANGLE_RUNNING; | |||||
when ANGLE_RUNNING => | |||||
if(angle_valid = '1') then | |||||
next_angle_state <= ANGLE_DONE; | |||||
end if; | |||||
when ANGLE_DONE => | |||||
next_angle_state <= angle_IDLE; | |||||
end case; | |||||
end process angle_state_transitions; | |||||
angle_calc : process (clk, reset) is | |||||
begin | |||||
if ( reset = '1' ) then | |||||
current_angle_state <= ANGLE_IDLE; | |||||
elsif ( rising_edge( clk ) ) then | |||||
current_ANGLE_state <= next_angle_state; | |||||
case next_angle_state is | |||||
when ANGLE_IDLE => | |||||
START <= '0'; | |||||
signal_write <= '0'; | |||||
when ANGLE_SET_SIGNALS => | |||||
angle = i | |||||
when ANGLE_RUNNING => | |||||
START <= '1'; | |||||
when ANGLE_DONE => | |||||
START <= '0'; | |||||
signal_write <= '1'; | |||||
end case; | |||||
end if; | |||||
end process add; | |||||
end architecture rtl; | end architecture rtl; |
int task_add_run( void * task ) { | int task_add_run( void * task ) { | ||||
// TODO | // TODO | ||||
add_config* config = (add_config*) task; | |||||
for(uint32_t i = 0; i < DATA_CHANNEL_DEPTH; i++) | |||||
{ | |||||
float a, b; | |||||
float_word c; | |||||
data_channel_read(config->sources[0], (uint32_t*)&a); | |||||
data_channel_read(config->sources[1], (uint32_t*)&b); | |||||
c.value = a + b; | |||||
data_channel_write(config->sink, c.word); | |||||
} | |||||
return 0; | return 0; | ||||
} | } | ||||
#ifndef __ALT_TYPES_H__ | |||||
#define __ALT_TYPES_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. * | |||||
******************************************************************************/ | |||||
/* | |||||
* Don't declare these typedefs if this file is included by assembly source. | |||||
*/ | |||||
#ifndef ALT_ASM_SRC | |||||
typedef signed char alt_8; | |||||
typedef unsigned char alt_u8; | |||||
typedef signed short alt_16; | |||||
typedef unsigned short alt_u16; | |||||
typedef signed long alt_32; | |||||
typedef unsigned long alt_u32; | |||||
typedef long long alt_64; | |||||
typedef unsigned long long alt_u64; | |||||
#endif | |||||
#define ALT_INLINE __inline__ | |||||
#define ALT_ALWAYS_INLINE __attribute__ ((always_inline)) | |||||
#define ALT_WEAK __attribute__((weak)) | |||||
#endif /* __ALT_TYPES_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 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* Support for the Nios II internal interrupt controller. | |||||
*/ | |||||
#ifndef __ALT_NIOS2_GEN2_IRQ_H__ | |||||
#define __ALT_NIOS2_GEN2_IRQ_H__ | |||||
#ifdef __cplusplus | |||||
extern "C" | |||||
{ | |||||
#endif /* __cplusplus */ | |||||
/* | |||||
* The macro ALTERA_NIOS2_GEN2_IRQ_INSTANCE is used by the alt_irq_init() | |||||
* function in the auto-generated file alt_sys_init.c to create an | |||||
* instance of this interrupt controller device driver state if this | |||||
* module contains an interrupt controller. | |||||
* Only one instance of a Nios II is allowed so this macro is just empty. | |||||
*/ | |||||
#define ALTERA_NIOS2_GEN2_IRQ_INSTANCE(name, state) | |||||
/* | |||||
* altera_nios2_gen2_irq_init() is called by the auto-generated function | |||||
* alt_irq_init() once for the Nios II if it contains an interrupt controller. | |||||
* The altera_nios2_gen2_irq_init() routine is called using the | |||||
* ALTERA_NIOS2_GEN2_IRQ_INIT macro given below. | |||||
* | |||||
* This function initializes the internal interrupt controller | |||||
* so is not called if the Nios II contains an external interrupt | |||||
* controller port (because the internal interrupt controller | |||||
* is removed if this port is present). | |||||
*/ | |||||
extern void altera_nios2_gen2_irq_init( void ); | |||||
/* | |||||
* The macro ALTERA_NIOS2_GEN2_IRQ_INIT is used by the alt_irq_init() routine | |||||
* in the auto-generated file alt_sys_init.c to initialize an instance | |||||
* of the interrupt controller device driver state. | |||||
*/ | |||||
#define ALTERA_NIOS2_GEN2_IRQ_INIT(name, state) altera_nios2_gen2_irq_init() | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif /* __cplusplus */ | |||||
#endif /* __ALT_NIOS2_ULTRA_IRQ_H__ */ | |||||
#ifndef __IO_H__ | |||||
#define __IO_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. * | |||||
******************************************************************************/ | |||||
/* IO Header file for Nios II Toolchain */ | |||||
#include "alt_types.h" | |||||
#ifdef __cplusplus | |||||
extern "C" | |||||
{ | |||||
#endif /* __cplusplus */ | |||||
#ifndef SYSTEM_BUS_WIDTH | |||||
#define SYSTEM_BUS_WIDTH 32 | |||||
#endif | |||||
/* Dynamic bus access functions */ | |||||
#define __IO_CALC_ADDRESS_DYNAMIC(BASE, OFFSET) \ | |||||
((void *)(((alt_u8*)BASE) + (OFFSET))) | |||||
#define IORD_32DIRECT(BASE, OFFSET) \ | |||||
__builtin_ldwio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))) | |||||
#define IORD_16DIRECT(BASE, OFFSET) \ | |||||
__builtin_ldhuio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))) | |||||
#define IORD_8DIRECT(BASE, OFFSET) \ | |||||
__builtin_ldbuio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))) | |||||
#define IOWR_32DIRECT(BASE, OFFSET, DATA) \ | |||||
__builtin_stwio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)), (DATA)) | |||||
#define IOWR_16DIRECT(BASE, OFFSET, DATA) \ | |||||
__builtin_sthio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)), (DATA)) | |||||
#define IOWR_8DIRECT(BASE, OFFSET, DATA) \ | |||||
__builtin_stbio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)), (DATA)) | |||||
/* Native bus access functions */ | |||||
#define __IO_CALC_ADDRESS_NATIVE(BASE, REGNUM) \ | |||||
((void *)(((alt_u8*)BASE) + ((REGNUM) * (SYSTEM_BUS_WIDTH/8)))) | |||||
#define IORD(BASE, REGNUM) \ | |||||
__builtin_ldwio (__IO_CALC_ADDRESS_NATIVE ((BASE), (REGNUM))) | |||||
#define IOWR(BASE, REGNUM, DATA) \ | |||||
__builtin_stwio (__IO_CALC_ADDRESS_NATIVE ((BASE), (REGNUM)), (DATA)) | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
#endif /* __IO_H__ */ |
#ifndef __NIOS2_H__ | |||||
#define __NIOS2_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. * | |||||
* * | |||||
* 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* This header provides processor specific macros for accessing the Nios2 | |||||
* control registers. | |||||
*/ | |||||
#ifdef __cplusplus | |||||
extern "C" | |||||
{ | |||||
#endif /* __cplusplus */ | |||||
/* | |||||
* Number of available IRQs in internal interrupt controller. | |||||
*/ | |||||
#define NIOS2_NIRQ 32 | |||||
/* | |||||
* Macros for accessing select Nios II general-purpose registers. | |||||
*/ | |||||
/* ET (Exception Temporary) register */ | |||||
#define NIOS2_READ_ET(et) \ | |||||
do { __asm ("mov %0, et" : "=r" (et) ); } while (0) | |||||
#define NIOS2_WRITE_ET(et) \ | |||||
do { __asm volatile ("mov et, %z0" : : "rM" (et)); } while (0) | |||||
/* SP (Stack Pointer) register */ | |||||
#define NIOS2_READ_SP(sp) \ | |||||
do { __asm ("mov %0, sp" : "=r" (sp) ); } while (0) | |||||
/* | |||||
* Macros for useful processor instructions. | |||||
*/ | |||||
#define NIOS2_BREAK() \ | |||||
do { __asm volatile ("break"); } while (0) | |||||
#define NIOS2_REPORT_STACK_OVERFLOW() \ | |||||
do { __asm volatile("break 3"); } while (0) | |||||
/* | |||||
* Macros for accessing Nios II control registers. | |||||
*/ | |||||
#define NIOS2_READ_STATUS(dest) \ | |||||
do { dest = __builtin_rdctl(0); } while (0) | |||||
#define NIOS2_WRITE_STATUS(src) \ | |||||
do { __builtin_wrctl(0, src); } while (0) | |||||
#define NIOS2_READ_ESTATUS(dest) \ | |||||
do { dest = __builtin_rdctl(1); } while (0) | |||||
#define NIOS2_READ_BSTATUS(dest) \ | |||||
do { dest = __builtin_rdctl(2); } while (0) | |||||
#define NIOS2_READ_IENABLE(dest) \ | |||||
do { dest = __builtin_rdctl(3); } while (0) | |||||
#define NIOS2_WRITE_IENABLE(src) \ | |||||
do { __builtin_wrctl(3, src); } while (0) | |||||
#define NIOS2_READ_IPENDING(dest) \ | |||||
do { dest = __builtin_rdctl(4); } while (0) | |||||
#define NIOS2_READ_CPUID(dest) \ | |||||
do { dest = __builtin_rdctl(5); } while (0) | |||||
#define NIOS2_READ_EXCEPTION(dest) \ | |||||
do { dest = __builtin_rdctl(7); } while (0) | |||||
#define NIOS2_READ_PTEADDR(dest) \ | |||||
do { dest = __builtin_rdctl(8); } while (0) | |||||
#define NIOS2_WRITE_PTEADDR(src) \ | |||||
do { __builtin_wrctl(8, src); } while (0) | |||||
#define NIOS2_READ_TLBACC(dest) \ | |||||
do { dest = __builtin_rdctl(9); } while (0) | |||||
#define NIOS2_WRITE_TLBACC(src) \ | |||||
do { __builtin_wrctl(9, src); } while (0) | |||||
#define NIOS2_READ_TLBMISC(dest) \ | |||||
do { dest = __builtin_rdctl(10); } while (0) | |||||
#define NIOS2_WRITE_TLBMISC(src) \ | |||||
do { __builtin_wrctl(10, src); } while (0) | |||||
#define NIOS2_READ_ECCINJ(dest) \ | |||||
do { dest = __builtin_rdctl(11); } while (0) | |||||
#define NIOS2_WRITE_ECCINJ(src) \ | |||||
do { __builtin_wrctl(11, src); } while (0) | |||||
#define NIOS2_READ_BADADDR(dest) \ | |||||
do { dest = __builtin_rdctl(12); } while (0) | |||||
#define NIOS2_WRITE_CONFIG(src) \ | |||||
do { __builtin_wrctl(13, src); } while (0) | |||||
#define NIOS2_READ_CONFIG(dest) \ | |||||
do { dest = __builtin_rdctl(13); } while (0) | |||||
#define NIOS2_WRITE_MPUBASE(src) \ | |||||
do { __builtin_wrctl(14, src); } while (0) | |||||
#define NIOS2_READ_MPUBASE(dest) \ | |||||
do { dest = __builtin_rdctl(14); } while (0) | |||||
#define NIOS2_WRITE_MPUACC(src) \ | |||||
do { __builtin_wrctl(15, src); } while (0) | |||||
#define NIOS2_READ_MPUACC(dest) \ | |||||
do { dest = __builtin_rdctl(15); } while (0) | |||||
/* | |||||
* Nios II control registers that are always present | |||||
*/ | |||||
#define NIOS2_STATUS status | |||||
#define NIOS2_ESTATUS estatus | |||||
#define NIOS2_BSTATUS bstatus | |||||
#define NIOS2_IENABLE ienable | |||||
#define NIOS2_IPENDING ipending | |||||
#define NIOS2_CPUID cpuid | |||||
/* | |||||
* Bit masks & offsets for Nios II control registers. | |||||
* The presence and size of a field is sometimes dependent on the Nios II | |||||
* configuration. Bit masks for every possible field and the maximum size of | |||||
* that field are defined. | |||||
* | |||||
* All bit-masks are expressed relative to the position | |||||
* of the data with a register. To read data that is LSB- | |||||
* aligned, the register read data should be masked, then | |||||
* right-shifted by the designated "OFST" macro value. The | |||||
* opposite should be used for register writes when starting | |||||
* with LSB-aligned data. | |||||
*/ | |||||
/* STATUS, ESTATUS, BSTATUS, and SSTATUS registers */ | |||||
#define NIOS2_STATUS_PIE_MSK (0x00000001) | |||||
#define NIOS2_STATUS_PIE_OFST (0) | |||||
#define NIOS2_STATUS_U_MSK (0x00000002) | |||||
#define NIOS2_STATUS_U_OFST (1) | |||||
#define NIOS2_STATUS_EH_MSK (0x00000004) | |||||
#define NIOS2_STATUS_EH_OFST (2) | |||||
#define NIOS2_STATUS_IH_MSK (0x00000008) | |||||
#define NIOS2_STATUS_IH_OFST (3) | |||||
#define NIOS2_STATUS_IL_MSK (0x000003f0) | |||||
#define NIOS2_STATUS_IL_OFST (4) | |||||
#define NIOS2_STATUS_CRS_MSK (0x0000fc00) | |||||
#define NIOS2_STATUS_CRS_OFST (10) | |||||
#define NIOS2_STATUS_PRS_MSK (0x003f0000) | |||||
#define NIOS2_STATUS_PRS_OFST (16) | |||||
#define NIOS2_STATUS_NMI_MSK (0x00400000) | |||||
#define NIOS2_STATUS_NMI_OFST (22) | |||||
#define NIOS2_STATUS_RSIE_MSK (0x00800000) | |||||
#define NIOS2_STATUS_RSIE_OFST (23) | |||||
#define NIOS2_STATUS_SRS_MSK (0x80000000) | |||||
#define NIOS2_STATUS_SRS_OFST (31) | |||||
/* EXCEPTION register */ | |||||
#define NIOS2_EXCEPTION_REG_CAUSE_MASK (0x0000007c) | |||||
#define NIOS2_EXCEPTION_REG_CAUSE_OFST (2) | |||||
#define NIOS2_EXCEPTION_REG_ECCFTL_MASK (0x80000000) | |||||
#define NIOS2_EXCEPTION_REG_ECCFTL_OFST (31) | |||||
/* PTEADDR (Page Table Entry Address) register */ | |||||
#define NIOS2_PTEADDR_REG_VPN_OFST 2 | |||||
#define NIOS2_PTEADDR_REG_VPN_MASK 0x3ffffc | |||||
#define NIOS2_PTEADDR_REG_PTBASE_OFST 22 | |||||
#define NIOS2_PTEADDR_REG_PTBASE_MASK 0xffc00000 | |||||
/* TLBACC (TLB Access) register */ | |||||
#define NIOS2_TLBACC_REG_PFN_OFST 0 | |||||
#define NIOS2_TLBACC_REG_PFN_MASK 0xfffff | |||||
#define NIOS2_TLBACC_REG_G_OFST 20 | |||||
#define NIOS2_TLBACC_REG_G_MASK 0x100000 | |||||
#define NIOS2_TLBACC_REG_X_OFST 21 | |||||
#define NIOS2_TLBACC_REG_X_MASK 0x200000 | |||||
#define NIOS2_TLBACC_REG_W_OFST 22 | |||||
#define NIOS2_TLBACC_REG_W_MASK 0x400000 | |||||
#define NIOS2_TLBACC_REG_R_OFST 23 | |||||
#define NIOS2_TLBACC_REG_R_MASK 0x800000 | |||||
#define NIOS2_TLBACC_REG_C_OFST 24 | |||||
#define NIOS2_TLBACC_REG_C_MASK 0x1000000 | |||||
#define NIOS2_TLBACC_REG_IG_OFST 25 | |||||
#define NIOS2_TLBACC_REG_IG_MASK 0xfe000000 | |||||
/* TLBMISC (TLB Miscellaneous) register */ | |||||
#define NIOS2_TLBMISC_REG_D_OFST 0 | |||||
#define NIOS2_TLBMISC_REG_D_MASK 0x1 | |||||
#define NIOS2_TLBMISC_REG_PERM_OFST 1 | |||||
#define NIOS2_TLBMISC_REG_PERM_MASK 0x2 | |||||
#define NIOS2_TLBMISC_REG_BAD_OFST 2 | |||||
#define NIOS2_TLBMISC_REG_BAD_MASK 0x4 | |||||
#define NIOS2_TLBMISC_REG_DBL_OFST 3 | |||||
#define NIOS2_TLBMISC_REG_DBL_MASK 0x8 | |||||
#define NIOS2_TLBMISC_REG_PID_OFST 4 | |||||
#define NIOS2_TLBMISC_REG_PID_MASK 0x3fff0 | |||||
#define NIOS2_TLBMISC_REG_WE_OFST 18 | |||||
#define NIOS2_TLBMISC_REG_WE_MASK 0x40000 | |||||
#define NIOS2_TLBMISC_REG_RD_OFST 19 | |||||
#define NIOS2_TLBMISC_REG_RD_MASK 0x80000 | |||||
#define NIOS2_TLBMISC_REG_WAY_OFST 20 | |||||
#define NIOS2_TLBMISC_REG_WAY_MASK 0xf00000 | |||||
#define NIOS2_TLBMISC_REG_EE_OFST 24 | |||||
#define NIOS2_TLBMISC_REG_EE_MASK 0x1000000 | |||||
/* ECCINJ (ECC Inject) register */ | |||||
#define NIOS2_ECCINJ_REG_RF_OFST 0 | |||||
#define NIOS2_ECCINJ_REG_RF_MASK 0x3 | |||||
#define NIOS2_ECCINJ_REG_ICTAG_OFST 2 | |||||
#define NIOS2_ECCINJ_REG_ICTAG_MASK 0xc | |||||
#define NIOS2_ECCINJ_REG_ICDAT_OFST 4 | |||||
#define NIOS2_ECCINJ_REG_ICDAT_MASK 0x30 | |||||
#define NIOS2_ECCINJ_REG_DCTAG_OFST 6 | |||||
#define NIOS2_ECCINJ_REG_DCTAG_MASK 0xc0 | |||||
#define NIOS2_ECCINJ_REG_DCDAT_OFST 8 | |||||
#define NIOS2_ECCINJ_REG_DCDAT_MASK 0x300 | |||||
#define NIOS2_ECCINJ_REG_TLB_OFST 10 | |||||
#define NIOS2_ECCINJ_REG_TLB_MASK 0xc00 | |||||
#define NIOS2_ECCINJ_REG_DTCM0_OFST 12 | |||||
#define NIOS2_ECCINJ_REG_DTCM0_MASK 0x3000 | |||||
#define NIOS2_ECCINJ_REG_DTCM1_OFST 14 | |||||
#define NIOS2_ECCINJ_REG_DTCM1_MASK 0xc000 | |||||
#define NIOS2_ECCINJ_REG_DTCM2_OFST 16 | |||||
#define NIOS2_ECCINJ_REG_DTCM2_MASK 0x30000 | |||||
#define NIOS2_ECCINJ_REG_DTCM3_OFST 18 | |||||
#define NIOS2_ECCINJ_REG_DTCM3_MASK 0xc0000 | |||||
/* CONFIG register */ | |||||
#define NIOS2_CONFIG_REG_PE_MASK (0x00000001) | |||||
#define NIOS2_CONFIG_REG_PE_OFST (0) | |||||
#define NIOS2_CONFIG_REG_ANI_MASK (0x00000002) | |||||
#define NIOS2_CONFIG_REG_ANI_OFST (1) | |||||
#define NIOS2_CONFIG_REG_ECCEN_MASK (0x00000004) | |||||
#define NIOS2_CONFIG_REG_ECCEN_OFST (2) | |||||
#define NIOS2_CONFIG_REG_ECCEXC_MASK (0x00000008) | |||||
#define NIOS2_CONFIG_REG_ECCEXC_OFST (3) | |||||
/* MPUBASE (MPU Base Address) Register */ | |||||
#define NIOS2_MPUBASE_D_MASK (0x00000001) | |||||
#define NIOS2_MPUBASE_D_OFST (0) | |||||
#define NIOS2_MPUBASE_INDEX_MASK (0x0000003e) | |||||
#define NIOS2_MPUBASE_INDEX_OFST (1) | |||||
#define NIOS2_MPUBASE_BASE_ADDR_MASK (0xffffffc0) | |||||
#define NIOS2_MPUBASE_BASE_ADDR_OFST (6) | |||||
/* MPUACC (MPU Access) Register */ | |||||
#define NIOS2_MPUACC_LIMIT_MASK (0xffffffc0) | |||||
#define NIOS2_MPUACC_LIMIT_OFST (6) | |||||
#define NIOS2_MPUACC_MASK_MASK (0xffffffc0) | |||||
#define NIOS2_MPUACC_MASK_OFST (6) | |||||
#define NIOS2_MPUACC_C_MASK (0x00000020) | |||||
#define NIOS2_MPUACC_C_OFST (5) | |||||
#define NIOS2_MPUACC_PERM_MASK (0x0000001c) | |||||
#define NIOS2_MPUACC_PERM_OFST (2) | |||||
#define NIOS2_MPUACC_RD_MASK (0x00000002) | |||||
#define NIOS2_MPUACC_RD_OFST (1) | |||||
#define NIOS2_MPUACC_WR_MASK (0x00000001) | |||||
#define NIOS2_MPUACC_WR_OFST (0) | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif /* __cplusplus */ | |||||
#endif /* __NIOS2_H__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* 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__ */ |
#ifndef __ALT_PRIV_ALARM_H__ | |||||
#define __ALT_PRIV_ALARM_H__ | |||||
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2017,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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. * | |||||
* * | |||||
******************************************************************************/ | |||||
#include "alt_types.h" | |||||
/* | |||||
* This header provides the internal definitions 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_u64 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. | |||||
*/ | |||||
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_u64 _alt_nticks; | |||||
/* The list of registered alarms. */ | |||||
extern alt_llist alt_alarm_list; | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
#endif /* __ALT_PRIV_ALARM_H__ */ |
#ifndef __ALT_BUSY_SLEEP_H | |||||
#define __ALT_BUSY_SLEEP_H | |||||
/* | |||||
* 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 function alt_busy_sleep provides a busy loop implementation of usleep. | |||||
* This is used to provide usleep for the standalone HAL, or when the timer is | |||||
* unavailable in uC/OS-II. | |||||
*/ | |||||
extern unsigned int alt_busy_sleep (unsigned int us); | |||||
#endif /* __ALT_BUSY_SLEEP_H */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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 "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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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_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_ */ |
#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 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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 |
#ifndef __ALT_LEGACY_IRQ_H__ | |||||
#define __ALT_LEGACY_IRQ_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 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* This file provides prototypes and inline implementations of certain routines | |||||
* used by the legacy interrupt API. Do not include this in your driver or | |||||
* application source files, use "sys/alt_irq.h" instead to access the proper | |||||
* public API. | |||||
*/ | |||||
#include <errno.h> | |||||
#include "system.h" | |||||
#ifndef NIOS2_EIC_PRESENT | |||||
#include "nios2.h" | |||||
#include "alt_types.h" | |||||
#include "sys/alt_irq.h" | |||||
#ifdef __cplusplus | |||||
extern "C" | |||||
{ | |||||
#endif /* __cplusplus */ | |||||
/* | |||||
* alt_irq_register() can be used to register an interrupt handler. If the | |||||
* function is succesful, then the requested interrupt will be enabled upon | |||||
* return. | |||||
*/ | |||||
extern int alt_irq_register (alt_u32 id, | |||||
void* context, | |||||
alt_isr_func handler); | |||||
/* | |||||
* alt_irq_disable() disables the individual interrupt indicated by "id". | |||||
*/ | |||||
static ALT_INLINE int ALT_ALWAYS_INLINE alt_irq_disable (alt_u32 id) | |||||
{ | |||||
alt_irq_context status; | |||||
extern volatile alt_u32 alt_irq_active; | |||||
status = alt_irq_disable_all (); | |||||
alt_irq_active &= ~(1 << id); | |||||
NIOS2_WRITE_IENABLE (alt_irq_active); | |||||
alt_irq_enable_all(status); | |||||
return 0; | |||||
} | |||||
/* | |||||
* alt_irq_enable() enables the individual interrupt indicated by "id". | |||||
*/ | |||||
static ALT_INLINE int ALT_ALWAYS_INLINE alt_irq_enable (alt_u32 id) | |||||
{ | |||||
alt_irq_context status; | |||||
extern volatile alt_u32 alt_irq_active; | |||||
status = alt_irq_disable_all (); | |||||
alt_irq_active |= (1 << id); | |||||
NIOS2_WRITE_IENABLE (alt_irq_active); | |||||
alt_irq_enable_all(status); | |||||
return 0; | |||||
} | |||||
#ifndef ALT_EXCEPTION_STACK | |||||
/* | |||||
* alt_irq_initerruptable() should only be called from within an ISR. It is used | |||||
* to allow higer priority interrupts to interrupt the current ISR. The input | |||||
* argument, "priority", is the priority, i.e. interrupt number of the current | |||||
* interrupt. | |||||
* | |||||
* If this function is called, then the ISR is required to make a call to | |||||
* alt_irq_non_interruptible() before returning. The input argument to | |||||
* alt_irq_non_interruptible() is the return value from alt_irq_interruptible(). | |||||
* | |||||
* Care should be taken when using this pair of functions, since they increasing | |||||
* the system overhead associated with interrupt handling. | |||||
* | |||||
* If you are using an exception stack then nested interrupts won't work, so | |||||
* these functions are not available in that case. | |||||
*/ | |||||
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_irq_interruptible (alt_u32 priority) | |||||
{ | |||||
extern volatile alt_u32 alt_priority_mask; | |||||
extern volatile alt_u32 alt_irq_active; | |||||
alt_u32 old_priority; | |||||
old_priority = alt_priority_mask; | |||||
alt_priority_mask = (1 << priority) - 1; | |||||
NIOS2_WRITE_IENABLE (alt_irq_active & alt_priority_mask); | |||||
NIOS2_WRITE_STATUS (1); | |||||
return old_priority; | |||||
} | |||||
/* | |||||
* See Comments above for alt_irq_interruptible() for an explanation of the use of this | |||||
* function. | |||||
*/ | |||||
static ALT_INLINE void ALT_ALWAYS_INLINE alt_irq_non_interruptible (alt_u32 mask) | |||||
{ | |||||
extern volatile alt_u32 alt_priority_mask; | |||||
extern volatile alt_u32 alt_irq_active; | |||||
NIOS2_WRITE_STATUS (0); | |||||
alt_priority_mask = mask; | |||||
NIOS2_WRITE_IENABLE (mask & alt_irq_active); | |||||
} | |||||
#endif /* ALT_EXCEPTION_STACK */ | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif /* __cplusplus */ | |||||
#endif /* NIOS2_EIC_PRESENT */ | |||||
#endif /* __ALT_LEGACY_IRQ_H__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
/****************************************************************************** | |||||
* * | |||||
* 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 NIOS2_GMON_DATA_H | |||||
#define NIOS2_GMON_DATA_H | |||||
#define GMON_DATA_SIG 0 | |||||
#define GMON_DATA_WORDS 1 | |||||
#define GMON_DATA_PROFILE_DATA 2 | |||||
#define GMON_DATA_PROFILE_LOWPC 3 | |||||
#define GMON_DATA_PROFILE_HIGHPC 4 | |||||
#define GMON_DATA_PROFILE_BUCKET 5 | |||||
#define GMON_DATA_PROFILE_RATE 6 | |||||
#define GMON_DATA_MCOUNT_START 7 | |||||
#define GMON_DATA_MCOUNT_LIMIT 8 | |||||
#define GMON_DATA_SIZE 9 | |||||
extern unsigned int alt_gmon_data[GMON_DATA_SIZE]; | |||||
#endif |
#ifndef __ALT_ALARM_H__ | |||||
#define __ALT_ALARM_H__ | |||||
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2017,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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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); | |||||
/* | |||||
* 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_u64 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); | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
#endif /* __ALT_ALARM_H__ */ |
#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. * | |||||
* * | |||||
* 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 <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__ */ |
#ifndef __ALT_DEBUG_H__ | |||||
#define __ALT_DEBUG_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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* The ALT_DEVUG_ASSERT macro can be used to generate a debugger break | |||||
* from within software. The break is generated if "condition" evaluates to | |||||
* false. | |||||
*/ | |||||
#define ALT_DEBUG_ASSERT(condition) if (!condition) \ | |||||
{ \ | |||||
__asm__ volatile ("break"); \ | |||||
} | |||||
#endif /* __ALT_DEBUG_H__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/* | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. */ | |||||
#define __LINUX_ERRNO_EXTENSIONS__ | |||||
#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__ */ |
#ifndef __ALT_EXCEPTIONS_H__ | |||||
#define __ALT_EXCEPTIONS_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. * | |||||
* * | |||||
* 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 "system.h" | |||||
#ifdef __cplusplus | |||||
extern "C" | |||||
{ | |||||
#endif /* __cplusplus */ | |||||
/* | |||||
* This file defines instruction-generated exception handling and registry | |||||
* API, exception type enumeration, and handler return value enumeration for | |||||
* Nios II. | |||||
*/ | |||||
/* | |||||
* The following enumeration describes the value in the CPU EXCEPTION | |||||
* register CAUSE bit field. | |||||
*/ | |||||
enum alt_exception_cause_e { | |||||
/* | |||||
* This value is passed to an exception handler's cause argument if | |||||
* "extra exceptions" information (EXECPTION) register is not | |||||
* present in the processor hardware configuration. | |||||
*/ | |||||
NIOS2_EXCEPTION_CAUSE_NOT_PRESENT = -1, | |||||
/* | |||||
* Real values | |||||
*/ | |||||
NIOS2_EXCEPTION_RESET = 0, | |||||
NIOS2_EXCEPTION_CPU_ONLY_RESET_REQUEST = 1, | |||||
NIOS2_EXCEPTION_INTERRUPT = 2, | |||||
NIOS2_EXCEPTION_TRAP_INST = 3, | |||||
NIOS2_EXCEPTION_UNIMPLEMENTED_INST = 4, | |||||
NIOS2_EXCEPTION_ILLEGAL_INST = 5, | |||||
NIOS2_EXCEPTION_MISALIGNED_DATA_ADDR = 6, | |||||
NIOS2_EXCEPTION_MISALIGNED_TARGET_PC = 7, | |||||
NIOS2_EXCEPTION_DIVISION_ERROR = 8, | |||||
NIOS2_EXCEPTION_SUPERVISOR_ONLY_INST_ADDR = 9, | |||||
NIOS2_EXCEPTION_SUPERVISOR_ONLY_INST = 10, | |||||
NIOS2_EXCEPTION_SUPERVISOR_ONLY_DATA_ADDR = 11, | |||||
NIOS2_EXCEPTION_TLB_MISS = 12, | |||||
NIOS2_EXCEPTION_TLB_EXECUTE_PERM_VIOLATION = 13, | |||||
NIOS2_EXCEPTION_TLB_READ_PERM_VIOLATION = 14, | |||||
NIOS2_EXCEPTION_TLB_WRITE_PERM_VIOLATION = 15, | |||||
NIOS2_EXCEPTION_MPU_INST_REGION_VIOLATION = 16, | |||||
NIOS2_EXCEPTION_MPU_DATA_REGION_VIOLATION = 17, | |||||
NIOS2_EXCEPTION_ECC_TLB_ERR = 18, | |||||
NIOS2_EXCEPTION_ECC_FETCH_ERR = 19, | |||||
NIOS2_EXCEPTION_ECC_REGISTER_FILE_ERR = 20, | |||||
NIOS2_EXCEPTION_ECC_DATA_ERR = 21, | |||||
NIOS2_EXCEPTION_ECC_DATA_CACHE_WRITEBACK_ERR = 22 | |||||
}; | |||||
typedef enum alt_exception_cause_e alt_exception_cause; | |||||
/* | |||||
* These define valid return values for a user-defined instruction-generated | |||||
* exception handler. The handler should return one of these to indicate | |||||
* whether to re-issue the instruction that triggered the exception, or to | |||||
* skip it. | |||||
*/ | |||||
enum alt_exception_result_e { | |||||
NIOS2_EXCEPTION_RETURN_REISSUE_INST = 0, | |||||
NIOS2_EXCEPTION_RETURN_SKIP_INST = 1 | |||||
}; | |||||
typedef enum alt_exception_result_e alt_exception_result; | |||||
/* | |||||
* alt_instruction_exception_register() can be used to register an exception | |||||
* handler for instruction-generated exceptions that are not handled by the | |||||
* built-in exception handler (i.e. for interrupts). | |||||
* | |||||
* The registry API is optionally enabled through the "Enable | |||||
* Instruction-related Exception API" HAL BSP setting, which will | |||||
* define the macro below. | |||||
*/ | |||||
#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API | |||||
void alt_instruction_exception_register ( | |||||
alt_exception_result (*exception_handler)( | |||||
alt_exception_cause cause, | |||||
alt_u32 exception_pc, | |||||
alt_u32 bad_addr) ); | |||||
#endif /*ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API */ | |||||
/* | |||||
* alt_exception_cause_generated_bad_addr() indicates whether a particular | |||||
* exception cause value was from an exception-type that generated a valid | |||||
* address in the BADADDR register. The contents of BADADDR is passed to | |||||
* a user-registered exception handler in all cases, whether valid or not. | |||||
* This routine should be called to validate the bad_addr argument to | |||||
* your exception handler. | |||||
* | |||||
* Note that this routine will return false (0) for causes | |||||
* NIOS2_EXCEPTION_TLB_MISS and NIOS2_EXCEPTION_ECC_TLB_ERR. | |||||
* You must read the TLBMISC.D field to determine if BADADDR | |||||
* is valid for these (valid if TLBMISC.D = 1). | |||||
*/ | |||||
int alt_exception_cause_generated_bad_addr(alt_exception_cause cause); | |||||
/* | |||||
* alt_ecc_fatal_exception_register() is called to register a handler to | |||||
* service likely fatal ECC error exceptions. Likely the handler will | |||||
* assume that correct execution of the running software is not possible | |||||
* and re-initialize the processor (e.g. jump to reset address). | |||||
* | |||||
* Passing null (0x0) in the handler argument will disable a previously- | |||||
* registered handler. | |||||
* | |||||
* Note that if no handler is registered, just normal exception processing | |||||
* occurs on a likely fatal ECC exception and the exception processing | |||||
* code might trigger an infinite exception loop. | |||||
* | |||||
* Note that the handler isn't a C function: it must be written in | |||||
* assembly-code because it doesn't support C language calling conventions | |||||
* and it can't return. | |||||
* | |||||
* The handler code must be carefully written to avoid triggering | |||||
* another fatal ECC exception and creating an infinite exception loop. | |||||
* The handler must avoid reading registers in case the fatal ECC | |||||
* error is a register file ECC error. | |||||
* If a data cache is present, the handler must avoid instructions that | |||||
* access the data cache in case the fatal ECC error is a data cache | |||||
* related ECC error. This includes cacheable load, cacheable store, | |||||
* non-cacheable store (because it looks in the data cache to update the | |||||
* data cache if it hits), and all data cache management instructions except | |||||
* for INITD. | |||||
*/ | |||||
void alt_ecc_fatal_exception_register(alt_u32 handler); | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif /* __cplusplus */ | |||||
#endif /* __ALT_EXCEPTIONS_H__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#ifndef __ALT_IRQ_H__ | |||||
#define __ALT_IRQ_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 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* alt_irq.h is the Nios II specific implementation of the interrupt controller | |||||
* interface. | |||||
* | |||||
* Nios II includes optional support for an external interrupt controller. | |||||
* When an external controller is present, the "Enhanced" interrupt API | |||||
* must be used to manage individual interrupts. The enhanced API also | |||||
* supports the processor's internal interrupt controller. Certain API | |||||
* members are accessible from either the "legacy" or "enhanced" interrpt | |||||
* API. | |||||
* | |||||
* Regardless of which API is in use, this file should be included by | |||||
* application code and device drivers that register ISRs or manage interrpts. | |||||
*/ | |||||
#include <errno.h> | |||||
#include "nios2.h" | |||||
#include "alt_types.h" | |||||
#include "system.h" | |||||
#ifdef __cplusplus | |||||
extern "C" | |||||
{ | |||||
#endif /* __cplusplus */ | |||||
/* | |||||
* Macros used by alt_irq_enabled | |||||
*/ | |||||
#define ALT_IRQ_ENABLED 1 | |||||
#define ALT_IRQ_DISABLED 0 | |||||
/* | |||||
* Number of available interrupts in internal interrupt controller. | |||||
*/ | |||||
#define ALT_NIRQ NIOS2_NIRQ | |||||
/* | |||||
* Used by alt_irq_disable_all() and alt_irq_enable_all(). | |||||
*/ | |||||
typedef int alt_irq_context; | |||||
/* ISR Prototype */ | |||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT | |||||
typedef void (*alt_isr_func)(void* isr_context); | |||||
#else | |||||
typedef void (*alt_isr_func)(void* isr_context, alt_u32 id); | |||||
#endif | |||||
/* | |||||
* The following protypes and routines are supported by both | |||||
* the enhanced and legacy interrupt APIs | |||||
*/ | |||||
/* | |||||
* alt_irq_enabled can be called to determine if the processor's global | |||||
* interrupt enable is asserted. The return value is zero if interrupts | |||||
* are disabled, and non-zero otherwise. | |||||
* | |||||
* Whether the internal or external interrupt controller is present, | |||||
* individual interrupts may still be disabled. Use the other API to query | |||||
* a specific interrupt. | |||||
*/ | |||||
static ALT_INLINE int ALT_ALWAYS_INLINE alt_irq_enabled (void) | |||||
{ | |||||
int status; | |||||
NIOS2_READ_STATUS (status); | |||||
return status & NIOS2_STATUS_PIE_MSK; | |||||
} | |||||
/* | |||||
* alt_irq_disable_all() | |||||
* | |||||
* This routine inhibits all interrupts by negating the status register PIE | |||||
* bit. It returns the previous contents of the CPU status register (IRQ | |||||
* context) which can be used to restore the status register PIE bit to its | |||||
* state before this routine was called. | |||||
*/ | |||||
static ALT_INLINE alt_irq_context ALT_ALWAYS_INLINE | |||||
alt_irq_disable_all (void) | |||||
{ | |||||
alt_irq_context context; | |||||
NIOS2_READ_STATUS (context); | |||||
NIOS2_WRITE_STATUS (context & ~NIOS2_STATUS_PIE_MSK); | |||||
return context; | |||||
} | |||||
/* | |||||
* alt_irq_enable_all() | |||||
* | |||||
* Enable all interrupts that were previously disabled by alt_irq_disable_all() | |||||
* | |||||
* This routine accepts a context to restore the CPU status register PIE bit | |||||
* to the state prior to a call to alt_irq_disable_all(). | |||||
* In the case of nested calls to alt_irq_disable_all()/alt_irq_enable_all(), | |||||
* this means that alt_irq_enable_all() does not necessarily re-enable | |||||
* interrupts. | |||||
* | |||||
* This routine will perform a read-modify-write sequence to restore only | |||||
* status.PIE if the processor is configured with options that add additional | |||||
* writeable status register bits. These include the MMU, MPU, the enhanced | |||||
* interrupt controller port, and shadow registers. Otherwise, as a performance | |||||
* enhancement, status is overwritten with the prior context. | |||||
*/ | |||||
static ALT_INLINE void ALT_ALWAYS_INLINE | |||||
alt_irq_enable_all (alt_irq_context context) | |||||
{ | |||||
#if (NIOS2_NUM_OF_SHADOW_REG_SETS > 0) || (defined NIOS2_EIC_PRESENT) || \ | |||||
(defined NIOS2_MMU_PRESENT) || (defined NIOS2_MPU_PRESENT) | |||||
alt_irq_context status; | |||||
NIOS2_READ_STATUS (status); | |||||
status &= ~NIOS2_STATUS_PIE_MSK; | |||||
status |= (context & NIOS2_STATUS_PIE_MSK); | |||||
NIOS2_WRITE_STATUS (status); | |||||
#else | |||||
NIOS2_WRITE_STATUS (context); | |||||
#endif | |||||
} | |||||
/* | |||||
* The function alt_irq_init() is defined within the auto-generated file | |||||
* alt_sys_init.c. This function calls the initilization macros for all | |||||
* interrupt controllers in the system at config time, before any other | |||||
* non-interrupt controller driver is initialized. | |||||
* | |||||
* The "base" parameter is ignored and only present for backwards-compatibility. | |||||
* It is recommended that NULL is passed in for the "base" parameter. | |||||
*/ | |||||
extern void alt_irq_init (const void* base); | |||||
/* | |||||
* alt_irq_cpu_enable_interrupts() enables the CPU to start taking interrupts. | |||||
*/ | |||||
static ALT_INLINE void ALT_ALWAYS_INLINE | |||||
alt_irq_cpu_enable_interrupts (void) | |||||
{ | |||||
NIOS2_WRITE_STATUS(NIOS2_STATUS_PIE_MSK | |||||
#if defined(NIOS2_EIC_PRESENT) && (NIOS2_NUM_OF_SHADOW_REG_SETS > 0) | |||||
| NIOS2_STATUS_RSIE_MSK | |||||
#endif | |||||
); | |||||
} | |||||
/* | |||||
* Prototypes for the enhanced interrupt API. | |||||
*/ | |||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT | |||||
/* | |||||
* alt_ic_isr_register() can be used to register an interrupt handler. If the | |||||
* function is succesful, then the requested interrupt will be enabled upon | |||||
* return. | |||||
*/ | |||||
extern int alt_ic_isr_register(alt_u32 ic_id, | |||||
alt_u32 irq, | |||||
alt_isr_func isr, | |||||
void *isr_context, | |||||
void *flags); | |||||
/* | |||||
* alt_ic_irq_enable() and alt_ic_irq_disable() enable/disable a specific | |||||
* interrupt by using IRQ port and interrupt controller instance. | |||||
*/ | |||||
int alt_ic_irq_enable (alt_u32 ic_id, alt_u32 irq); | |||||
int alt_ic_irq_disable(alt_u32 ic_id, alt_u32 irq); | |||||
/* | |||||
* alt_ic_irq_enabled() indicates whether a specific interrupt, as | |||||
* specified by IRQ port and interrupt controller instance is enabled. | |||||
*/ | |||||
alt_u32 alt_ic_irq_enabled(alt_u32 ic_id, alt_u32 irq); | |||||
#else | |||||
/* | |||||
* Prototypes for the legacy interrupt API. | |||||
*/ | |||||
#include "priv/alt_legacy_irq.h" | |||||
#endif | |||||
/* | |||||
* alt_irq_pending() returns a bit list of the current pending interrupts. | |||||
* This is used by alt_irq_handler() to determine which registered interrupt | |||||
* handlers should be called. | |||||
* | |||||
* This routine is only available for the Nios II internal interrupt | |||||
* controller. | |||||
*/ | |||||
#ifndef NIOS2_EIC_PRESENT | |||||
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_irq_pending (void) | |||||
{ | |||||
alt_u32 active; | |||||
NIOS2_READ_IPENDING (active); | |||||
return active; | |||||
} | |||||
#endif | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif /* __cplusplus */ | |||||
#endif /* __ALT_IRQ_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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* This file pulls in the IRQ entry assembler and C code, which is only | |||||
* required if there are any interruptes in the system. | |||||
*/ | |||||
__asm__( "\n\t.globl alt_irq_entry" ); | |||||
__asm__( "\n\t.globl alt_irq_handler" ); | |||||
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ | |||||
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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" | |||||
/* | |||||
* 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++; | |||||
} | |||||
} | |||||
} |
/* 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__ */ | |||||
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#ifndef __ALT_SIM_H__ | |||||
#define __ALT_SIM_H__ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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 "system.h" | |||||
#include "alt_types.h" | |||||
/* | |||||
* Instructions that might mean something special to a simulator. | |||||
* These have no special effect on real hardware (they are just nops). | |||||
*/ | |||||
#define ALT_SIM_FAIL() \ | |||||
do { __asm volatile ("cmpltui r0, r0, 0xabc1"); } while (0) | |||||
#define ALT_SIM_PASS() \ | |||||
do { __asm volatile ("cmpltui r0, r0, 0xabc2"); } while (0) | |||||
#define ALT_SIM_IN_TOP_OF_HOT_LOOP() \ | |||||
do { __asm volatile ("cmpltui r0, r0, 0xabc3"); } while (0) | |||||
/* | |||||
* Routine called on exit. | |||||
*/ | |||||
static ALT_INLINE ALT_ALWAYS_INLINE void alt_sim_halt(int exit_code) | |||||
{ | |||||
register int r2 asm ("r2") = exit_code; | |||||
#if defined(NIOS2_HAS_DEBUG_STUB) && (defined(ALT_BREAK_ON_EXIT) || defined(ALT_PROVIDE_GMON)) | |||||
register int r3 asm ("r3") = (1 << 2); | |||||
#ifdef ALT_PROVIDE_GMON | |||||
extern unsigned int alt_gmon_data[]; | |||||
register int r4 asm ("r4") = (int)alt_gmon_data; | |||||
r3 |= (1 << 4); | |||||
#define ALT_GMON_DATA ,"r"(r4) | |||||
#else | |||||
#define ALT_GMON_DATA | |||||
#endif /* ALT_PROVIDE_GMON */ | |||||
if (r2) { | |||||
ALT_SIM_FAIL(); | |||||
} else { | |||||
ALT_SIM_PASS(); | |||||
} | |||||
__asm__ volatile ("\n0:\n\taddi %0,%0, -1\n\tbgt %0,zero,0b" : : "r" (ALT_CPU_FREQ/100) ); /* Delay for >30ms */ | |||||
__asm__ volatile ("break 2" : : "r"(r2), "r"(r3) ALT_GMON_DATA ); | |||||
#else /* !DEBUG_STUB */ | |||||
if (r2) { | |||||
ALT_SIM_FAIL(); | |||||
} else { | |||||
ALT_SIM_PASS(); | |||||
} | |||||
#endif /* DEBUG_STUB */ | |||||
} | |||||
#define ALT_SIM_HALT(exit_code) \ | |||||
alt_sim_halt(exit_code) | |||||
#endif /* __ALT_SIM_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. * | |||||
* * | |||||
* 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_STACK_H__ | |||||
#define __ALT_STACK_H__ | |||||
/* | |||||
* alt_stack.h is the nios2 specific implementation of functions used by the | |||||
* stack overflow code. | |||||
*/ | |||||
#include "nios2.h" | |||||
#include "alt_types.h" | |||||
#ifdef __cplusplus | |||||
extern "C" | |||||
{ | |||||
#endif /* __cplusplus */ | |||||
extern char * alt_stack_limit_value; | |||||
#ifdef ALT_EXCEPTION_STACK | |||||
extern char __alt_exception_stack_pointer[]; /* set by the linker */ | |||||
#endif /* ALT_EXCEPTION_STACK */ | |||||
/* | |||||
* alt_stack_limit can be called to determine the current value of the stack | |||||
* limit register. | |||||
*/ | |||||
static ALT_INLINE char * ALT_ALWAYS_INLINE alt_stack_limit (void) | |||||
{ | |||||
char * limit; | |||||
NIOS2_READ_ET(limit); | |||||
return limit; | |||||
} | |||||
/* | |||||
* alt_stack_pointer can be called to determine the current value of the stack | |||||
* pointer register. | |||||
*/ | |||||
static ALT_INLINE char * ALT_ALWAYS_INLINE alt_stack_pointer (void) | |||||
{ | |||||
char * pointer; | |||||
NIOS2_READ_SP(pointer); | |||||
return pointer; | |||||
} | |||||
#ifdef ALT_EXCEPTION_STACK | |||||
/* | |||||
* alt_exception_stack_pointer returns the normal stack pointer from | |||||
* where it is stored on the exception stack (uppermost 4 bytes). This | |||||
* is really only useful during exception processing, and is only | |||||
* available if a separate exception stack has been configured. | |||||
*/ | |||||
static ALT_INLINE char * ALT_ALWAYS_INLINE alt_exception_stack_pointer (void) | |||||
{ | |||||
return (char *) *(alt_u32 *)(__alt_exception_stack_pointer - sizeof(alt_u32)); | |||||
} | |||||
#endif /* ALT_EXCEPTION_STACK */ | |||||
/* | |||||
* alt_set_stack_limit can be called to update the current value of the stack | |||||
* limit register. | |||||
*/ | |||||
static ALT_INLINE void ALT_ALWAYS_INLINE alt_set_stack_limit (char * limit) | |||||
{ | |||||
alt_stack_limit_value = limit; | |||||
NIOS2_WRITE_ET(limit); | |||||
} | |||||
/* | |||||
* alt_report_stack_overflow reports that a stack overflow happened. | |||||
*/ | |||||
static ALT_INLINE void ALT_ALWAYS_INLINE alt_report_stack_overflow (void) | |||||
{ | |||||
NIOS2_REPORT_STACK_OVERFLOW(); | |||||
} | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif /* __cplusplus */ | |||||
#endif /* __ALT_STACK_H__ */ | |||||
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#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 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* 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__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
#ifndef __WARNING_H__ | |||||
#define __WARNING_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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* alt_warning.h provides macro definitions that can be used to generate link | |||||
* time warnings. | |||||
*/ | |||||
#ifdef __cplusplus | |||||
extern "C" | |||||
{ | |||||
#endif /* __cplusplus */ | |||||
/* | |||||
* The symbol "__alt_invalid" is used to force a link error. There should be | |||||
* no corresponding implementation of this function. | |||||
*/ | |||||
extern void __alt_invalid (void); | |||||
#define ALT_LINK_WARNING(symbol, msg) \ | |||||
__asm__(".ifndef __evoke_link_warning_" #symbol \ | |||||
"\n\t .section .gnu.warning." #symbol \ | |||||
"\n__evoke_link_warning_" #symbol ":\n\t .string \x22" msg "\x22 \n\t .previous" \ | |||||
"\n .endif"); | |||||
/* A canned warning for sysdeps/stub functions. */ | |||||
#define ALT_STUB_WARNING(name) \ | |||||
ALT_LINK_WARNING (name, \ | |||||
"warning: " #name " is not implemented and will always fail") | |||||
#define ALT_OBSOLETE_FUNCTION_WARNING(name) \ | |||||
ALT_LINK_WARNING (name, \ | |||||
"warning: " #name " is a deprecated function") | |||||
#define ALT_LINK_ERROR(msg) \ | |||||
ALT_LINK_WARNING (__alt_invalid, msg); \ | |||||
__alt_invalid() | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
#endif /* __WARNING_H__ */ |
#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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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__ */ |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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 */ | |||||
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2017,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. * | |||||
* * | |||||
* 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 <errno.h> | |||||
#include "sys/alt_alarm.h" | |||||
#include "sys/alt_irq.h" | |||||
/* | |||||
* alt_alarm_start is called to register an alarm with the system. The | |||||
* "alarm" structure passed as an input argument does not need to be | |||||
* initialised by the user. This is done within this function. | |||||
* | |||||
* The remaining input arguments are: | |||||
* | |||||
* nticks - The time to elapse until the alarm executes. This is specified in | |||||
* system clock ticks. | |||||
* callback - The function to run when the indicated time has elapsed. | |||||
* context - An opaque value, passed to the callback function. | |||||
* | |||||
* Care should be taken when defining the callback function since it is | |||||
* likely to execute in interrupt context. In particular, this mean that | |||||
* library calls like printf() should not be made, since they can result in | |||||
* deadlock. | |||||
* | |||||
* The interval to be used for the next callback is the return | |||||
* value from the callback function. A return value of zero indicates that the | |||||
* alarm should be unregistered. | |||||
* | |||||
* alt_alarm_start() will fail if the timer facility has not been enabled | |||||
* (i.e. there is no system clock). Failure is indicated by a negative return | |||||
* value. | |||||
*/ | |||||
int alt_alarm_start (alt_alarm* alarm, alt_u32 nticks, | |||||
alt_u32 (*callback) (void* context), | |||||
void* context) | |||||
{ | |||||
alt_irq_context irq_context; | |||||
alt_u64 current_nticks = 0; | |||||
if (alt_ticks_per_second ()) | |||||
{ | |||||
if (alarm) | |||||
{ | |||||
alarm->callback = callback; | |||||
alarm->context = context; | |||||
irq_context = alt_irq_disable_all (); | |||||
current_nticks = alt_nticks(); | |||||
alarm->time = (alt_u64)nticks + current_nticks + 1; | |||||
alt_llist_insert (&alt_alarm_list, &alarm->llist); | |||||
alt_irq_enable_all (irq_context); | |||||
return 0; | |||||
} | |||||
else | |||||
{ | |||||
return -EINVAL; | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
return -ENOTSUP; | |||||
} | |||||
} |
/* | |||||
* Copyright (c) 2003-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. | |||||
* | |||||
* alt_busy_sleep.c - Microsecond delay routine which uses a calibrated busy | |||||
* loop to perform the delay. This is used to implement | |||||
* usleep for both uC/OS-II and the standalone HAL. | |||||
* | |||||
* Author PRR | |||||
* | |||||
* Calibrated delay with no timer required | |||||
* | |||||
* The ASM instructions in the routine are equivalent to | |||||
* | |||||
* for (i=0;i<us*(ALT_CPU_FREQ/3);i++); | |||||
* | |||||
* and takes three cycles each time around the loop | |||||
* | |||||
*/ | |||||
#include <limits.h> | |||||
#include <string.h> | |||||
#include "system.h" | |||||
#include "alt_types.h" | |||||
#include "priv/alt_busy_sleep.h" | |||||
unsigned int alt_busy_sleep (unsigned int us) | |||||
{ | |||||
/* | |||||
* Only delay if ALT_SIM_OPTIMIZE is not defined; i.e., if software | |||||
* is built targetting ModelSim RTL simulation, the delay will be | |||||
* skipped to speed up simulation. | |||||
*/ | |||||
#ifndef ALT_SIM_OPTIMIZE | |||||
int i; | |||||
int big_loops; | |||||
alt_u32 cycles_per_loop; | |||||
if (!strcmp(NIOS2_CPU_IMPLEMENTATION,"tiny")) | |||||
{ | |||||
cycles_per_loop = 9; | |||||
} | |||||
else | |||||
{ | |||||
cycles_per_loop = 3; | |||||
} | |||||
big_loops = us / (INT_MAX/ | |||||
(ALT_CPU_FREQ/(cycles_per_loop * 1000000))); | |||||
if (big_loops) | |||||
{ | |||||
for(i=0;i<big_loops;i++) | |||||
{ | |||||
/* | |||||
* Do NOT Try to single step the asm statement below | |||||
* (single step will never return) | |||||
* Step out of this function or set a breakpoint after the asm statements | |||||
*/ | |||||
__asm__ volatile ( | |||||
"\n0:" | |||||
"\n\taddi %0,%0, -1" | |||||
"\n\tbne %0,zero,0b" | |||||
"\n1:" | |||||
"\n\t.pushsection .debug_alt_sim_info" | |||||
"\n\t.int 4, 0, 0b, 1b" | |||||
"\n\t.popsection" | |||||
:: "r" (INT_MAX)); | |||||
us -= (INT_MAX/(ALT_CPU_FREQ/ | |||||
(cycles_per_loop * 1000000))); | |||||
} | |||||
/* | |||||
* Do NOT Try to single step the asm statement below | |||||
* (single step will never return) | |||||
* Step out of this function or set a breakpoint after the asm statements | |||||
*/ | |||||
__asm__ volatile ( | |||||
"\n0:" | |||||
"\n\taddi %0,%0, -1" | |||||
"\n\tbne %0,zero,0b" | |||||
"\n1:" | |||||
"\n\t.pushsection .debug_alt_sim_info" | |||||
"\n\t.int 4, 0, 0b, 1b" | |||||
"\n\t.popsection" | |||||
:: "r" (us*(ALT_CPU_FREQ/(cycles_per_loop * 1000000)))); | |||||
} | |||||
else | |||||
{ | |||||
/* | |||||
* Do NOT Try to single step the asm statement below | |||||
* (single step will never return) | |||||
* Step out of this function or set a breakpoint after the asm statements | |||||
*/ | |||||
__asm__ volatile ( | |||||
"\n0:" | |||||
"\n\taddi %0,%0, -1" | |||||
"\n\tbgt %0,zero,0b" | |||||
"\n1:" | |||||
"\n\t.pushsection .debug_alt_sim_info" | |||||
"\n\t.int 4, 0, 0b, 1b" | |||||
"\n\t.popsection" | |||||
:: "r" (us*(ALT_CPU_FREQ/(cycles_per_loop * 1000000)))); | |||||
} | |||||
#endif /* #ifndef ALT_SIM_OPTIMIZE */ | |||||
return 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. * | |||||
* * | |||||
* 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 <unistd.h> | |||||
#include "sys/alt_errno.h" | |||||
#include "sys/alt_warning.h" | |||||
#include "priv/alt_file.h" | |||||
#include "os/alt_syscall.h" | |||||
#ifdef ALT_USE_DIRECT_DRIVERS | |||||
int ALT_CLOSE (int fildes) | |||||
{ | |||||
/* Generate a link time warning, should this function ever be called. */ | |||||
ALT_STUB_WARNING(close); | |||||
/* Indicate an error */ | |||||
ALT_ERRNO = ENOSYS; | |||||
return -1; | |||||
} | |||||
#else /* !ALT_USE_DIRECT_DRIVERS */ | |||||
/* | |||||
* close() is called by an application to release a file descriptor. If the | |||||
* associated file system/device has a close() callback function registered | |||||
* then this called. The file descriptor is then marked as free. | |||||
* | |||||
* ALT_CLOSE is mapped onto the close() system call in alt_syscall.h | |||||
*/ | |||||
int ALT_CLOSE (int fildes) | |||||
{ | |||||
alt_fd* fd; | |||||
int rval; | |||||
/* | |||||
* A common error case is that when the file descriptor was created, the call | |||||
* to open() failed resulting in a negative file descriptor. This is trapped | |||||
* below so that we don't try and process an invalid file descriptor. | |||||
*/ | |||||
fd = (fildes < 0) ? NULL : &alt_fd_list[fildes]; | |||||
if (fd) | |||||
{ | |||||
/* | |||||
* If the associated file system/device has a close function, call it so | |||||
* that any necessary cleanup code can run. | |||||
*/ | |||||
rval = (fd->dev->close) ? fd->dev->close(fd) : 0; | |||||
/* Free the file descriptor structure and return. */ | |||||
alt_release_fd (fildes); | |||||
if (rval < 0) | |||||
{ | |||||
ALT_ERRNO = -rval; | |||||
return -1; | |||||
} | |||||
return 0; | |||||
} | |||||
else | |||||
{ | |||||
ALT_ERRNO = EBADFD; | |||||
return -1; | |||||
} | |||||
} | |||||
#endif /* ALT_USE_DIRECT_DRIVERS */ |
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2003-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. * | |||||
* * | |||||
* 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 "nios2.h" | |||||
#include "system.h" | |||||
#include "alt_types.h" | |||||
#include "sys/alt_cache.h" | |||||
#define ALT_FLUSH_DATA(i) __asm__ volatile ("flushda (%0)" :: "r" (i)); | |||||
/* | |||||
* 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. | |||||
*/ | |||||
void alt_dcache_flush (void* start, alt_u32 len) | |||||
{ | |||||
#if NIOS2_DCACHE_SIZE > 0 | |||||
char* i; | |||||
char* end = ((char*) start) + len; | |||||
for (i = start; i < end; i+= NIOS2_DCACHE_LINE_SIZE) | |||||
{ | |||||
ALT_FLUSH_DATA(i); | |||||
} | |||||
/* | |||||
* For an unaligned flush request, we've got one more line left. | |||||
* Note that this is dependent on NIOS2_DCACHE_LINE_SIZE to be a | |||||
* multiple of 2 (which it always is). | |||||
*/ | |||||
if (((alt_u32) start) & (NIOS2_DCACHE_LINE_SIZE - 1)) | |||||
{ | |||||
ALT_FLUSH_DATA(i); | |||||
} | |||||
#endif /* NIOS2_DCACHE_SIZE > 0 */ | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2003-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. * | |||||
* * | |||||
* 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 "nios2.h" | |||||
#include "system.h" | |||||
#include "alt_types.h" | |||||
#include "sys/alt_cache.h" | |||||
/* | |||||
* alt_dcache_flush_all() is called to flush the entire data cache. | |||||
*/ | |||||
void alt_dcache_flush_all (void) | |||||
{ | |||||
#if NIOS2_DCACHE_SIZE > 0 | |||||
char* i; | |||||
for (i = (char*) 0; i < (char*) NIOS2_DCACHE_SIZE; i+= NIOS2_DCACHE_LINE_SIZE) | |||||
{ | |||||
__asm__ volatile ("flushd (%0)" :: "r" (i)); | |||||
} | |||||
#endif /* NIOS2_DCACHE_SIZE > 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. * | |||||
* * | |||||
* 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 "nios2.h" | |||||
#include "system.h" | |||||
#include "alt_types.h" | |||||
#include "sys/alt_cache.h" | |||||
#define ALT_FLUSH_DATA_NO_WRITEBACK(i) \ | |||||
__asm__ volatile ("initda (%0)" :: "r" (i)); | |||||
/* | |||||
* alt_dcache_flush_no_writeback() 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. | |||||
* Make sure you really want this behavior. If you aren't 100% sure, | |||||
* use the alt_dcache_flush() routine instead. | |||||
*/ | |||||
void alt_dcache_flush_no_writeback (void* start, alt_u32 len) | |||||
{ | |||||
char* i; | |||||
char* end = ((char*) start) + len; | |||||
for (i = start; i < end; i+= NIOS2_DCACHE_LINE_SIZE) | |||||
{ | |||||
ALT_FLUSH_DATA_NO_WRITEBACK(i); | |||||
} | |||||
/* | |||||
* For an unaligned flush request, we've got one more line left. | |||||
* Note that this is dependent on NIOS2_DCACHE_LINE_SIZE to be a | |||||
* multiple of 2 (which it always is). | |||||
*/ | |||||
if (((alt_u32) start) & (NIOS2_DCACHE_LINE_SIZE - 1)) | |||||
{ | |||||
ALT_FLUSH_DATA_NO_WRITEBACK(i); | |||||
} | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <stddef.h> | |||||
#include <stdio.h> | |||||
#include <unistd.h> | |||||
#include <fcntl.h> | |||||
#include <errno.h> | |||||
#include "sys/alt_dev.h" | |||||
#include "priv/alt_file.h" | |||||
#include "alt_types.h" | |||||
#include "system.h" | |||||
/* | |||||
* This file contains the data constructs used to control access to device and | |||||
* filesytems. | |||||
*/ | |||||
/* | |||||
* "alt_fs_list" is the head of a linked list of registered filesystems. It is | |||||
* initialised as an empty list. New entries can be added using the | |||||
* alt_fs_reg() function. | |||||
*/ | |||||
ALT_LLIST_HEAD(alt_fs_list); | |||||
/* | |||||
* "alt_dev_list" is the head of a linked list of registered devices. It is | |||||
* configured at startup to include a single device, "alt_dev_null". This | |||||
* device is discussed below. | |||||
*/ | |||||
extern alt_dev alt_dev_null; /* forward declaration */ | |||||
alt_llist alt_dev_list = {&alt_dev_null.llist, &alt_dev_null.llist}; | |||||
/* | |||||
* alt_dev_null_write() is the implementation of the write() function used | |||||
* by the alt_dev_null device. It simple discards all data passed to it, and | |||||
* indicates that the data has been successfully transmitted. | |||||
*/ | |||||
static int alt_dev_null_write (alt_fd* fd, const char* ptr, int len) | |||||
{ | |||||
return len; | |||||
} | |||||
/* | |||||
* "alt_dev_null" is used to allow output to be redirected to nowhere. It is | |||||
* the only device registered before the call to alt_sys_init(). At startup | |||||
* stin, stdout & stderr are all directed towards this device so that library | |||||
* calls like printf() will be safe but inefectual. | |||||
*/ | |||||
alt_dev alt_dev_null = { | |||||
{ | |||||
&alt_dev_list, | |||||
&alt_dev_list | |||||
}, | |||||
"/dev/null", | |||||
NULL, /* open */ | |||||
NULL, /* close */ | |||||
NULL, /* write */ | |||||
alt_dev_null_write, /* write */ | |||||
NULL, /* lseek */ | |||||
NULL, /* fstat */ | |||||
NULL /* ioctl */ | |||||
}; | |||||
/* | |||||
* "alt_fd_list_lock" is a semaphore used to control access to the file | |||||
* descriptor list. This is used to ensure that access to the list is thread | |||||
* safe. | |||||
*/ | |||||
ALT_SEM(alt_fd_list_lock) | |||||
/* | |||||
* "alt_max_fd" is used to make access to the file descriptor list more | |||||
* efficent. It is set to be the value of the highest allocated file | |||||
* descriptor. This saves having to search the entire pool of unallocated | |||||
* file descriptors when looking for a match. | |||||
*/ | |||||
alt_32 alt_max_fd = -1; | |||||
/* | |||||
* "alt_fd_list" is the file descriptor pool. The first three entries in the | |||||
* array are configured as standard in, standard out, and standard error. These | |||||
* are all initialised so that accesses are directed to the alt_dev_null | |||||
* device. The remaining file descriptors are initialised as unallocated. | |||||
* | |||||
* The maximum number of file descriptors within the system is specified by the | |||||
* user defined macro "ALT_MAX_FD". This is defined in "system.h", which is | |||||
* auto-genereated using the projects PTF and STF files. | |||||
*/ | |||||
alt_fd alt_fd_list[ALT_MAX_FD] = | |||||
{ | |||||
{ | |||||
&alt_dev_null, /* standard in */ | |||||
0, | |||||
0 | |||||
}, | |||||
{ | |||||
&alt_dev_null, /* standard out */ | |||||
0, | |||||
0 | |||||
}, | |||||
{ | |||||
&alt_dev_null, /* standard error */ | |||||
0, | |||||
0 | |||||
} | |||||
/* all other elements are set to zero */ | |||||
}; |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "priv/alt_dev_llist.h" | |||||
#include "sys/alt_errno.h" | |||||
/* | |||||
* | |||||
*/ | |||||
int alt_dev_llist_insert (alt_dev_llist* dev, alt_llist* list) | |||||
{ | |||||
/* | |||||
* check that the device exists, and that it has a valid name. | |||||
*/ | |||||
if (!dev || !dev->name) | |||||
{ | |||||
ALT_ERRNO = EINVAL; | |||||
return -EINVAL; | |||||
} | |||||
/* | |||||
* register the device. | |||||
*/ | |||||
alt_llist_insert(list, &dev->llist); | |||||
return 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. * | |||||
* * | |||||
* 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 "sys/alt_dma.h" | |||||
#include "sys/alt_errno.h" | |||||
#include "priv/alt_file.h" | |||||
/* | |||||
* The list of registered DMA receive channels. | |||||
*/ | |||||
ALT_LLIST_HEAD(alt_dma_rxchan_list); | |||||
/* | |||||
* 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. | |||||
*/ | |||||
alt_dma_rxchan alt_dma_rxchan_open (const char* name) | |||||
{ | |||||
alt_dma_rxchan dev; | |||||
dev = (alt_dma_rxchan) alt_find_dev (name, &alt_dma_rxchan_list); | |||||
if (!dev) | |||||
{ | |||||
ALT_ERRNO = ENODEV; | |||||
} | |||||
return dev; | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "sys/alt_dma.h" | |||||
#include "sys/alt_errno.h" | |||||
#include "priv/alt_file.h" | |||||
/* | |||||
* The list of registered receive channels. | |||||
*/ | |||||
ALT_LLIST_HEAD(alt_dma_txchan_list); | |||||
/* | |||||
* 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. | |||||
*/ | |||||
alt_dma_txchan alt_dma_txchan_open (const char* name) | |||||
{ | |||||
alt_dma_txchan dev; | |||||
dev = (alt_dma_txchan) alt_find_dev (name, &alt_dma_txchan_list); | |||||
if (!dev) | |||||
{ | |||||
ALT_ERRNO = ENODEV; | |||||
} | |||||
return dev; | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT IT DIRECTLY. * | |||||
* * | |||||
* Overriding HAL Functions * | |||||
* * | |||||
* To provide your own implementation of a HAL function, include the file in * | |||||
* your Nios II IDE application project. When building the executable, the * | |||||
* Nios II IDE finds your function first, and uses it in place of the HAL * | |||||
* version. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* | |||||
*/ | |||||
typedef void (*constructor) (void); | |||||
extern constructor __CTOR_LIST__[]; | |||||
extern constructor __CTOR_END__[]; | |||||
/* | |||||
* Run the C++ static constructors. | |||||
*/ | |||||
void _do_ctors(void) | |||||
{ | |||||
constructor* ctor; | |||||
for (ctor = &__CTOR_END__[-1]; ctor >= __CTOR_LIST__; ctor--) | |||||
(*ctor) (); | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT IT DIRECTLY. * | |||||
* * | |||||
* Overriding HAL Functions * | |||||
* * | |||||
* To provide your own implementation of a HAL function, include the file in * | |||||
* your Nios II IDE application project. When building the executable, the * | |||||
* Nios II IDE finds your function first, and uses it in place of the HAL * | |||||
* version. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* | |||||
*/ | |||||
typedef void (*destructor) (void); | |||||
extern destructor __DTOR_LIST__[]; | |||||
extern destructor __DTOR_END__[]; | |||||
/* | |||||
* Run the C++ static destructors. | |||||
*/ | |||||
void _do_dtors(void) | |||||
{ | |||||
destructor* dtor; | |||||
for (dtor = &__DTOR_END__[-1]; dtor >= __DTOR_LIST__; dtor--) | |||||
(*dtor) (); | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2013 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* This is the code called at the beginning of the exception handler | |||||
* to detect a likely fatal ECC error exception and then jump to | |||||
* user-provided code to handle it. | |||||
* | |||||
* This code is pulled in from a .globl in alt_ecc_fatal_exception.c. | |||||
* This scheme is used so that if a handler is never registered, then this | |||||
* code will not appear in the generated executable, thereby improving | |||||
* code footprint. | |||||
* | |||||
* This code is located in its own section that the linker script | |||||
* explicitly mentions and ensures it gets linked at the beginning | |||||
* of the exception handler. | |||||
*/ | |||||
/* | |||||
* Pull in the exception handler register save code. | |||||
*/ | |||||
.globl alt_exception | |||||
.section .exceptions.entry.ecc_fatal, "xa" | |||||
/* | |||||
* This might be handling an unrecoverable ECC error exception | |||||
* in the register file and/or data cache. | |||||
* Must avoid reading registers or performing load/store instructions | |||||
* before this is determined because they could trigger another | |||||
* unrecoverable ECC error exception and create an infinite loop. | |||||
* | |||||
* The EXCEPTION register is always present when ECC is present. | |||||
* Bit 31 of this register indicates that there was an unrecoverable | |||||
* ECC error exception in the register file and/or data cache. | |||||
* Test this (using blt to check sign bit) to determine if this is | |||||
* what we are dealing with. Otherwise, just do normal processing. | |||||
* | |||||
* Jump to an application-provided routine to handle this condition. | |||||
* Pass in the return address in the et register in case this code | |||||
* can clean up the ECC error and then return here (unlikely). | |||||
* | |||||
* Runtime stack checking can't be enabled when ECC is present | |||||
* because they both want to use the et register. | |||||
*/ | |||||
rdctl et, exception | |||||
bge et, r0, alt_exception_not_ecc_fatal /* Not ECCFTL if bit 31 is 0 */ | |||||
/* | |||||
* Load ECC fatal handler pointer into et register. | |||||
* Using a ldwio is safe because it completely bypasses the data cache. | |||||
*/ | |||||
movhi et, %hi(alt_exception_ecc_fatal_handler) | |||||
ori et, et, %lo(alt_exception_ecc_fatal_handler) | |||||
ldwio et, 0(et) | |||||
/* | |||||
* If ECC fatal handler pointer is not 0, assume a handler | |||||
* has been provided by the application. | |||||
*/ | |||||
beq et, r0, alt_exception_not_ecc_fatal | |||||
/* | |||||
* The et register contains the address of the ECC fatal handler. | |||||
* Jump to this address to invoke the handler. | |||||
*/ | |||||
jmp et | |||||
/* | |||||
* An ECC fatal handler can jump to this label if it able | |||||
* to recover from the fatal error (rare) and wants to continue | |||||
* with normal exception processing. | |||||
*/ | |||||
.globl alt_exception_not_ecc_fatal | |||||
alt_exception_not_ecc_fatal: |
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2013 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 "io.h" | |||||
#include "sys/alt_exceptions.h" | |||||
#include "sys/alt_cache.h" | |||||
/* | |||||
* This file implements support for calling a user-registered handler | |||||
* when a likely fatal ECC error exception occurs. | |||||
*/ | |||||
/* | |||||
* Global variable containing address to jump to when likely fatal | |||||
* ECC error exception occurs. | |||||
*/ | |||||
alt_u32 alt_exception_ecc_fatal_handler = 0x0; | |||||
/* | |||||
* Pull in the exception entry assembly code. This will not be linked in | |||||
* unless this object is linked into the executable (i.e. only if | |||||
* alt_ecc_fatal_exception_register() is called). | |||||
*/ | |||||
__asm__( "\n\t.globl alt_exception" ); | |||||
/* | |||||
* alt_ecc_fatal_exception_register() is called to register a handler to | |||||
* service likely fatal ECC error exceptions. | |||||
* | |||||
* Passing null (0x0) in the handler argument will disable a previously- | |||||
* registered handler. | |||||
* | |||||
* Note that if no handler is registered, just normal exception processing | |||||
* occurs on a likely fatal ECC exception and the exception processing | |||||
* code might trigger an infinite exception loop. | |||||
*/ | |||||
void | |||||
alt_ecc_fatal_exception_register(alt_u32 handler) | |||||
{ | |||||
alt_exception_ecc_fatal_handler = handler; | |||||
/* | |||||
* Flush this from the cache. Required because the exception handler uses ldwio | |||||
* to read this value to avoid trigger another data cache ECC error exception. | |||||
*/ | |||||
alt_dcache_flush(&alt_exception_ecc_fatal_handler, sizeof(alt_exception_ecc_fatal_handler)); | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <reent.h> | |||||
/* | |||||
* These are the empty env lock/unlock stubs required by newlib. These are | |||||
* used to make accesses to environment variables thread safe. The default HAL | |||||
* configuration is single threaded, so there is nothing to do here. Note that | |||||
* this requires that environment variables are never manipulated by an interrupt | |||||
* service routine. | |||||
*/ | |||||
void __env_lock ( struct _reent *_r ) | |||||
{ | |||||
} | |||||
/* | |||||
* | |||||
*/ | |||||
void __env_unlock ( struct _reent *_r ) | |||||
{ | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "os/alt_syscall.h" | |||||
/* | |||||
* These are the environment variables passed to the C code. By default there | |||||
* are no variables registered. An application can manipulate this list using | |||||
* getenv() and setenv(). | |||||
*/ | |||||
char *__env[1] = { 0 }; | |||||
char **ALT_ENVIRON = __env; |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/* | |||||
* This file defines the alt_errno global variable. See comments in | |||||
* alt_errno.h for the use of this variable. | |||||
*/ | |||||
#include "sys/alt_errno.h" | |||||
#include "alt_types.h" | |||||
extern int ALT_WEAK *__errno (void); | |||||
int* (*alt_errno) (void) = __errno; |
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2003-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. * | |||||
* * | |||||
* 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 "system.h" | |||||
/* | |||||
* This is the exception entry point code, which saves all the caller saved | |||||
* registers and then handles the appropriate exception. It should be pulled | |||||
* in using a .globl from all the exception handler routines. This scheme is | |||||
* used so that if an interrupt is never registered, then this code will not | |||||
* appear in the generated executable, thereby improving code footprint. | |||||
* | |||||
* If an external interrpt controller (EIC) is present, it will supply an | |||||
* interrupt vector address to the processor when an interrupt occurs. For | |||||
* The Altera Vectored Interrupt Controller (VIC) driver will establish a | |||||
* vector table and the processor will jump directly to the appropriate | |||||
* table entry, funnel routine, and then user ISR. This will bypass this code | |||||
* in entirety. This code might still be linked into a system with an EIC, | |||||
* but would then be used only for non-interrupt exceptions. | |||||
*/ | |||||
/* | |||||
* Explicitly allow the use of r1 (the assembler temporary register) | |||||
* within this code. This register is normally reserved for the use of | |||||
* the assembler. | |||||
*/ | |||||
.set noat | |||||
/* | |||||
* The top and bottom of the exception stack. | |||||
*/ | |||||
#ifdef ALT_EXCEPTION_STACK | |||||
.globl __alt_exception_stack_pointer | |||||
#ifdef ALT_STACK_CHECK | |||||
.globl __alt_exception_stack_limit | |||||
/* | |||||
* Store the value of the stack limit after interrupt somewhere. | |||||
*/ | |||||
.globl alt_exception_old_stack_limit | |||||
#endif /* ALT_STACK_CHECK */ | |||||
#endif /* ALT_EXCEPTION_STACK */ | |||||
/* | |||||
* The code at alt_exception is located at the Nios II exception | |||||
* handler address. | |||||
*/ | |||||
.section .exceptions.entry.label, "xa" | |||||
.globl alt_exception | |||||
.type alt_exception, @function | |||||
alt_exception: | |||||
/* | |||||
* The code for detecting a likely fatal ECC exception is | |||||
* linked here before the normal exception handler code if required. | |||||
* This is handled by the linker script and putting that code | |||||
* in the .exceptions.entry.ecc_fatal section. | |||||
*/ | |||||
/* | |||||
* Now start the normal exception handler code. | |||||
*/ | |||||
.section .exceptions.entry, "xa" | |||||
#ifdef ALT_EXCEPTION_STACK | |||||
#ifdef ALT_STACK_CHECK | |||||
/* | |||||
* When runtime stack checking is enabled, the et register | |||||
* contains the stack limit. Save this in memory before | |||||
* overwriting the et register. | |||||
*/ | |||||
stw et, %gprel(alt_exception_old_stack_limit)(gp) | |||||
#endif /* ALT_STACK_CHECK */ | |||||
/* | |||||
* Switch to the exception stack and save the current stack pointer | |||||
* in memory. Uses the et register as a scratch register. | |||||
*/ | |||||
movhi et, %hi(__alt_exception_stack_pointer - 80) | |||||
ori et, et, %lo(__alt_exception_stack_pointer - 80) | |||||
stw sp, 76(et) | |||||
mov sp, et | |||||
#ifdef ALT_STACK_CHECK | |||||
/* | |||||
* Restore the stack limit from memory to the et register. | |||||
*/ | |||||
movhi et, %hi(__alt_exception_stack_limit) | |||||
ori et, et, %lo(__alt_exception_stack_limit) | |||||
stw et, %gprel(alt_stack_limit_value)(gp) | |||||
#endif /* ALT_STACK_CHECK */ | |||||
#else /* ALT_EXCEPTION_STACK disabled */ | |||||
/* | |||||
* Reserve space on normal stack for registers about to be pushed. | |||||
*/ | |||||
addi sp, sp, -76 | |||||
#ifdef ALT_STACK_CHECK | |||||
/* Ensure stack didn't just overflow. */ | |||||
bltu sp, et, .Lstack_overflow | |||||
#endif /* ALT_STACK_CHECK */ | |||||
#endif /* ALT_EXCEPTION_STACK */ | |||||
/* | |||||
* Process an exception. For all exceptions we must preserve all | |||||
* caller saved registers on the stack (See the Nios II ABI | |||||
* documentation for details). | |||||
* | |||||
* Leave a gap in the stack frame at 4(sp) for the muldiv handler to | |||||
* store zero into. | |||||
*/ | |||||
stw ra, 0(sp) | |||||
stw r1, 8(sp) | |||||
stw r2, 12(sp) | |||||
stw r3, 16(sp) | |||||
stw r4, 20(sp) | |||||
stw r5, 24(sp) | |||||
stw r6, 28(sp) | |||||
stw r7, 32(sp) | |||||
rdctl r5, estatus /* Read early to avoid usage stall */ | |||||
stw r8, 36(sp) | |||||
stw r9, 40(sp) | |||||
stw r10, 44(sp) | |||||
stw r11, 48(sp) | |||||
stw r12, 52(sp) | |||||
stw r13, 56(sp) | |||||
stw r14, 60(sp) | |||||
stw r15, 64(sp) | |||||
/* | |||||
* ea-4 contains the address of the instruction being executed | |||||
* when the exception occured. For interrupt exceptions, we will | |||||
* will be re-issue the isntruction. Store it in 72(sp) | |||||
*/ | |||||
stw r5, 68(sp) /* estatus */ | |||||
addi r15, ea, -4 /* instruction that caused exception */ | |||||
stw r15, 72(sp) | |||||
/* | |||||
* The interrupt testing code (.exceptions.irqtest) will be | |||||
* linked here. If the Internal Interrupt Controller (IIC) is | |||||
* present (an EIC is not present), the presense of an interrupt | |||||
* is determined by examining CPU control registers or an interrupt | |||||
* custom instruction, if present. | |||||
* | |||||
* If the IIC is used and an interrupt is active, the code linked | |||||
* here will call the HAL IRQ handler (alt_irq_handler()) which | |||||
* successively calls registered interrupt handler(s) until no | |||||
* interrupts remain pending. It then jumps to .exceptions.exit. If | |||||
* there is no interrupt then it continues to .exception.notirq, below. | |||||
*/ | |||||
.section .exceptions.notirq, "xa" | |||||
/* | |||||
* Prepare to service unimplemtned instructions or traps, | |||||
* each of which is optionally inked into section .exceptions.soft, | |||||
* which will preceed .exceptions.unknown below. | |||||
* | |||||
* Unlike interrupts, we want to skip the exception-causing instructon | |||||
* upon completion, so we write ea (address of instruction *after* | |||||
* the one where the exception occured) into 72(sp). The actual | |||||
* instruction that caused the exception is written in r2, which these | |||||
* handlers will utilize. | |||||
*/ | |||||
stw ea, 72(sp) /* EA is PC+4 so will skip over instruction causing exception */ | |||||
#ifdef NIOS2_CDX_PRESENT | |||||
mov.n r4, ea /* EA contains PC+4 of instruction that caused the exception */ | |||||
subi.n r4, r4, 4 /* Calculate PC */ | |||||
ldhu.n r2, 0(r4) /* Load least-significant 16 bits of instruction */ | |||||
andi r5, r2, 0x7 /* Mask off all bits except the 3 most-significant bits of OP field */ | |||||
/* | |||||
* These instructions compare the MSB 3 bits of OP to 0x1, 0x3, and 0x5 | |||||
* which is where all the 16-bit instructions live. | |||||
*/ | |||||
subi.n r5, r5, 1 | |||||
beqz.n r5, .Lunknown_16bit | |||||
subi.n r5, r5, 2 | |||||
beqz.n r5, .Lunknown_16bit | |||||
subi.n r5, r5, 2 | |||||
beqz.n r5, .Lunknown_16bit | |||||
.Lunknown_32bit: | |||||
stw ea, 72(sp) /* EA is PC+4 so will skip over instruction causing exception */ | |||||
/* Load most-significant 16 bits of instruction */ | |||||
ldhu.n r3, 2(r4) | |||||
slli.n r3, r3, 16 | |||||
or.n r2, r2, r3 /* 32-bit instruction value that caused exception */ | |||||
br.n .Lunknown_inst_loaded | |||||
.Lunknown_16bit: | |||||
addi.n r4, r4, 2 /* Need PC+2 to skip over instruction causing exception */ | |||||
stw r4, 72(sp) | |||||
#else /* CDX is not Enabled and all instructions are 32bits */ | |||||
ldw r2, -4(ea) /* Instruction value that caused exception */ | |||||
#endif | |||||
.Lunknown_inst_loaded: | |||||
/* | |||||
* Other exception handling code, if enabled, will be linked here. | |||||
* This includes unimplemted (multiply/divide) instruction support | |||||
* (a BSP generaton option), and a trap handler (that would typically | |||||
* be augmented with user-specific code). These are not linked in by | |||||
* default. | |||||
*/ | |||||
/* | |||||
* In the context of linker sections, "unknown" are all exceptions | |||||
* not handled by the built-in handlers above (interupt, and trap or | |||||
* unimplemented instruction decoding, if enabled). | |||||
* | |||||
* Advanced exception types can be serviced by registering a handler. | |||||
* To do so, enable the "Enable Instruction-related Exception API" HAL | |||||
* BSP setting. If this setting is disabled, this handler code will | |||||
* either break (if the debug core is present) or enter an infinite | |||||
* loop because we don't how how to handle the exception. | |||||
*/ | |||||
.section .exceptions.unknown | |||||
#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API | |||||
/* | |||||
* The C-based HAL routine alt_instruction_exception_entry() will | |||||
* attempt to service the exception by calling a user-registered | |||||
* exception handler using alt_instruction_exception_register(). | |||||
* If no handler was registered it will either break (if the | |||||
* debugger is present) or go into an infinite loop since the | |||||
* handling behavior is undefined; in that case we will not return here. | |||||
*/ | |||||
/* Load exception-causing address as first argument (r4) */ | |||||
addi r4, ea, -4 | |||||
/* Call the instruction-exception entry */ | |||||
call alt_instruction_exception_entry | |||||
/* | |||||
* If alt_instruction_exception_entry() returned, the exception was | |||||
* serviced by a user-registered routine. Its return code (now in r2) | |||||
* indicates whether to re-issue or skip the exception-causing | |||||
* instruction | |||||
* | |||||
* Return code was 0: Skip. The instruction after the exception is | |||||
* already stored in 72(sp). | |||||
*/ | |||||
bne r2, r0, .Lexception_exit | |||||
/* | |||||
* Otherwise, modify 72(sp) to re-issue the instruction that caused the | |||||
* exception. | |||||
*/ | |||||
addi r15, ea, -4 /* instruction that caused exception */ | |||||
stw r15, 72(sp) | |||||
#else /* ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API disabled */ | |||||
/* | |||||
* We got here because an instruction-related exception occured, but the | |||||
* handler API was not compiled in. We do not presume to know how to | |||||
* handle it. If the debugger is present, break, otherwise hang. | |||||
* | |||||
* If you get here then one of the following could have happened: | |||||
* | |||||
* - An instruction-generated exception occured, and the processor | |||||
* does not have the extra exceptions feature enabled, or you | |||||
* have not registered a handler using | |||||
* alt_instruction_exception_register() | |||||
* | |||||
* Some examples of instruction-generated exceptions and why they | |||||
* might occur: | |||||
* | |||||
* - Your program could have been compiled for a full-featured | |||||
* Nios II core, but it is running on a smaller core, and | |||||
* instruction emulation has been disabled by defining | |||||
* ALT_NO_INSTRUCTION_EMULATION. | |||||
* | |||||
* You can work around the problem by re-enabling instruction | |||||
* emulation, or you can figure out why your program is being | |||||
* compiled for a system other than the one that it is running on. | |||||
* | |||||
* - Your program has executed a trap instruction, but has not | |||||
* implemented a handler for this instruction. | |||||
* | |||||
* - Your program has executed an illegal instruction (one which is | |||||
* not defined in the instruction set). | |||||
* | |||||
* - Your processor includes an MMU or MPU, and you have enabled it | |||||
* before registering an exception handler to service exceptions it | |||||
* generates. | |||||
* | |||||
* The problem could also be hardware related: | |||||
* - If your hardware is broken and is generating spurious interrupts | |||||
* (a peripheral which negates its interrupt output before its | |||||
* interrupt handler has been executed will cause spurious | |||||
* interrupts) | |||||
*/ | |||||
alt_exception_unknown: | |||||
#ifdef NIOS2_HAS_DEBUG_STUB | |||||
/* | |||||
* Either tell the user now (if there is a debugger attached) or go into | |||||
* the debug monitor which will loop until a debugger is attached. | |||||
*/ | |||||
break | |||||
#else /* NIOS2_HAS_DEBUG_STUB disabled */ | |||||
/* | |||||
* If there is no debug stub, an infinite loop is more useful. | |||||
*/ | |||||
br alt_exception_unknown | |||||
#endif /* NIOS2_HAS_DEBUG_STUB */ | |||||
#endif /* ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API */ | |||||
.section .exceptions.exit.label | |||||
.Lexception_exit: | |||||
.section .exceptions.exit, "xa" | |||||
/* | |||||
* Restore the saved registers, so that all general purpose registers | |||||
* have been restored to their state at the time the interrupt occured. | |||||
*/ | |||||
ldw r5, 68(sp) | |||||
ldw ea, 72(sp) /* This becomes the PC once eret is executed */ | |||||
ldw ra, 0(sp) | |||||
wrctl estatus, r5 | |||||
ldw r1, 8(sp) | |||||
ldw r2, 12(sp) | |||||
ldw r3, 16(sp) | |||||
ldw r4, 20(sp) | |||||
ldw r5, 24(sp) | |||||
ldw r6, 28(sp) | |||||
ldw r7, 32(sp) | |||||
#if defined(ALT_EXCEPTION_STACK) && defined(ALT_STACK_CHECK) | |||||
ldw et, %gprel(alt_exception_old_stack_limit)(gp) | |||||
#endif | |||||
ldw r8, 36(sp) | |||||
ldw r9, 40(sp) | |||||
ldw r10, 44(sp) | |||||
ldw r11, 48(sp) | |||||
ldw r12, 52(sp) | |||||
ldw r13, 56(sp) | |||||
ldw r14, 60(sp) | |||||
ldw r15, 64(sp) | |||||
#ifdef ALT_EXCEPTION_STACK | |||||
#ifdef ALT_STACK_CHECK | |||||
stw et, %gprel(alt_stack_limit_value)(gp) | |||||
stw zero, %gprel(alt_exception_old_stack_limit)(gp) | |||||
#endif /* ALT_STACK_CHECK */ | |||||
ldw sp, 76(sp) | |||||
#else /* ALT_EXCEPTION_STACK disabled */ | |||||
addi sp, sp, 76 | |||||
#endif /* ALT_EXCEPTION_STACK */ | |||||
/* | |||||
* Return to the interrupted instruction. | |||||
*/ | |||||
eret | |||||
#ifdef ALT_STACK_CHECK | |||||
.Lstack_overflow: | |||||
break 3 | |||||
#endif /* ALT_STACK_CHECK */ | |||||
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2003-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. * | |||||
* * | |||||
* 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* This is the software multiply/divide handler for Nios2. | |||||
*/ | |||||
/* | |||||
* Provide a label which can be used to pull this file in. | |||||
*/ | |||||
.section .exceptions.start | |||||
.globl alt_exception_muldiv | |||||
alt_exception_muldiv: | |||||
/* | |||||
* Pull in the entry/exit code. | |||||
*/ | |||||
.globl alt_exception | |||||
.section .exceptions.soft, "xa" | |||||
/* INSTRUCTION EMULATION | |||||
* --------------------- | |||||
* | |||||
* Nios II processors generate exceptions for unimplemented instructions. | |||||
* The routines below emulate these instructions. Depending on the | |||||
* processor core, the only instructions that might need to be emulated | |||||
* are div, divu, mul, muli, mulxss, mulxsu, and mulxuu. | |||||
* | |||||
* The emulations match the instructions, except for the following | |||||
* limitations: | |||||
* | |||||
* 1) The emulation routines do not emulate the use of the exception | |||||
* temporary register (et) as a source operand because the exception | |||||
* handler already has modified it. | |||||
* | |||||
* 2) The routines do not emulate the use of the stack pointer (sp) or the | |||||
* exception return address register (ea) as a destination because | |||||
* modifying these registers crashes the exception handler or the | |||||
* interrupted routine. | |||||
* | |||||
* 3) To save code size, the routines do not emulate the use of the | |||||
* breakpoint registers (ba and bt) as operands. | |||||
* | |||||
* Detailed Design | |||||
* --------------- | |||||
* | |||||
* The emulation routines expect the contents of integer registers r0-r31 | |||||
* to be on the stack at addresses sp, 4(sp), 8(sp), ... 124(sp). The | |||||
* routines retrieve source operands from the stack and modify the | |||||
* destination register's value on the stack prior to the end of the | |||||
* exception handler. Then all registers except the destination register | |||||
* are restored to their previous values. | |||||
* | |||||
* The instruction that causes the exception is found at address -4(ea). | |||||
* The instruction's OP and OPX fields identify the operation to be | |||||
* performed. | |||||
* | |||||
* One instruction, muli, is an I-type instruction that is identified by | |||||
* an OP field of 0x24. | |||||
* | |||||
* muli AAAAA,BBBBB,IIIIIIIIIIIIIIII,-0x24- | |||||
* 27 22 6 0 <-- LSB of field | |||||
* | |||||
* The remaining emulated instructions are R-type and have an OP field | |||||
* of 0x3a. Their OPX fields identify them. | |||||
* | |||||
* R-type AAAAA,BBBBB,CCCCC,XXXXXX,NNNNN,-0x3a- | |||||
* 27 22 17 11 6 0 <-- LSB of field | |||||
* | |||||
* | |||||
*/ | |||||
/* | |||||
* Split the instruction into its fields. We need 4*A, 4*B, and 4*C as | |||||
* offsets to the stack pointer for access to the stored register values. | |||||
*/ | |||||
/* r2 = AAAAA,BBBBB,IIIIIIIIIIIIIIII,PPPPPP */ | |||||
roli r3, r2, 7 /* r3 = BBB,IIIIIIIIIIIIIIII,PPPPPP,AAAAA,BB */ | |||||
roli r4, r3, 3 /* r4 = IIIIIIIIIIIIIIII,PPPPPP,AAAAA,BBBBB */ | |||||
roli r6, r4, 2 /* r6 = IIIIIIIIIIIIII,PPPPPP,AAAAA,BBBBB,II */ | |||||
srai r4, r4, 16 /* r4 = (sign-extended) IMM16 */ | |||||
xori r6, r6, 0x42 /* r6 = CCC,XXXXXX,NNNNN,PPPPPP,AAAAA,bBBBB,cC */ | |||||
roli r7, r6, 5 /* r7 = XXXX,NNNNN,PPPPPP,AAAAA,bBBBB,cCCCC,XX */ | |||||
andi r5, r2, 0x3f /* r5 = 00000000000000000000000000,PPPPPP */ | |||||
xori r3, r3, 0x40 | |||||
andi r3, r3, 0x7c /* r3 = 0000000000000000000000000,aAAAA,00 */ | |||||
andi r6, r6, 0x7c /* r6 = 0000000000000000000000000,bBBBB,00 */ | |||||
andi r7, r7, 0x7c /* r7 = 0000000000000000000000000,cCCCC,00 */ | |||||
/* Now either | |||||
* r5 = OP | |||||
* r3 = 4*(A^16) | |||||
* r4 = IMM16 (sign extended) | |||||
* r6 = 4*(B^16) | |||||
* r7 = 4*(C^16) | |||||
* or | |||||
* r5 = OP | |||||
*/ | |||||
/* | |||||
* Save everything on the stack to make it easy for the emulation routines | |||||
* to retrieve the source register operands. The exception entry code has | |||||
* already saved some of this so we don't need to do it all again. | |||||
*/ | |||||
addi sp, sp, -60 | |||||
stw zero, 64(sp) /* Save zero on stack to avoid special case for r0. */ | |||||
/* Register at and r2-r15 have already been saved. */ | |||||
stw r16, 0(sp) | |||||
stw r17, 4(sp) | |||||
stw r18, 8(sp) | |||||
stw r19, 12(sp) | |||||
stw r20, 16(sp) | |||||
stw r21, 20(sp) | |||||
stw r22, 24(sp) | |||||
stw r23, 28(sp) | |||||
/* et @ 32 - Has already been changed.*/ | |||||
/* bt @ 36 - Usually isn't an operand. */ | |||||
stw gp, 40(sp) | |||||
stw sp, 44(sp) | |||||
stw fp, 48(sp) | |||||
/* ea @ 52 - Don't bother to save - it's already been changed */ | |||||
/* ba @ 56 - Breakpoint register usually isn't an operand */ | |||||
/* ra @ 60 - Has already been saved */ | |||||
/* | |||||
* Prepare for either multiplication or division loop. | |||||
* They both loop 32 times. | |||||
*/ | |||||
movi r14, 32 | |||||
/* | |||||
* Get the operands. | |||||
* | |||||
* It is necessary to check for muli because it uses an I-type instruction | |||||
* format, while the other instructions are have an R-type format. | |||||
*/ | |||||
add r3, r3, sp /* r3 = address of A-operand. */ | |||||
ldw r3, 0(r3) /* r3 = A-operand. */ | |||||
movi r15, 0x24 /* muli opcode (I-type instruction format) */ | |||||
beq r5, r15, .Lmul_immed /* muli doesn't use the B register as a source */ | |||||
add r6, r6, sp /* r6 = address of B-operand. */ | |||||
ldw r6, 0(r6) /* r6 = B-operand. */ | |||||
/* r4 = SSSSSSSSSSSSSSSS,-----IMM16------ */ | |||||
/* IMM16 not needed, align OPX portion */ | |||||
/* r4 = SSSSSSSSSSSSSSSS,CCCCC,-OPX--,00000 */ | |||||
srli r4, r4, 5 /* r4 = 00000,SSSSSSSSSSSSSSSS,CCCCC,-OPX-- */ | |||||
andi r4, r4, 0x3f /* r4 = 00000000000000000000000000,-OPX-- */ | |||||
/* Now | |||||
* r5 = OP | |||||
* r3 = src1 | |||||
* r6 = src2 | |||||
* r4 = OPX (no longer can be muli) | |||||
* r7 = 4*(C^16) | |||||
* r14 = loop counter | |||||
*/ | |||||
/* ILLEGAL-INSTRUCTION EXCEPTION | |||||
* ----------------------------- | |||||
* | |||||
* This code is for Nios II cores that generate exceptions when attempting | |||||
* to execute illegal instructions. Nios II cores that support an | |||||
* illegal-instruction exception are identified by the presence of the | |||||
* macro definition NIOS2_HAS_ILLEGAL_INSTRUCTION_EXCEPTION in system.h . | |||||
* | |||||
* Remember that illegal instructions are different than unimplemented | |||||
* instructions. Illegal instructions are instruction encodings that | |||||
* have not been defined by the Nios II ISA. Unimplemented instructions | |||||
* are legal instructions that must be emulated by some Nios II cores. | |||||
* | |||||
* If we get here, all instructions except multiplies and divides | |||||
* are illegal. | |||||
* | |||||
* This code assumes that OP is not muli (because muli was tested above). | |||||
* All other multiplies and divides are legal. Anything else is illegal. | |||||
*/ | |||||
movi r8, 0x3a /* OP for R-type mul* and div* */ | |||||
bne r5, r8, .Lnot_muldiv | |||||
/* r15 already is 0x24 */ /* OPX of divu */ | |||||
beq r4, r15, .Ldivide | |||||
movi r15,0x27 /* OPX of mul */ | |||||
beq r4, r15, .Lmultiply | |||||
movi r15,0x07 /* OPX of mulxuu */ | |||||
beq r4, r15, .Lmultiply | |||||
movi r15,0x17 /* OPX of mulxsu */ | |||||
beq r4, r15, .Lmultiply | |||||
movi r15,0x1f /* OPX of mulxss */ | |||||
beq r4, r15, .Lmultiply | |||||
movi r15,0x25 /* OPX of div */ | |||||
bne r4, r15, .Lnot_muldiv | |||||
/* DIVISION | |||||
* | |||||
* Divide an unsigned dividend by an unsigned divisor using | |||||
* a shift-and-subtract algorithm. The example below shows | |||||
* 43 div 7 = 6 for 8-bit integers. This classic algorithm uses a | |||||
* single register to store both the dividend and the quotient, | |||||
* allowing both values to be shifted with a single instruction. | |||||
* | |||||
* remainder dividend:quotient | |||||
* --------- ----------------- | |||||
* initialize 00000000 00101011: | |||||
* shift 00000000 0101011:_ | |||||
* remainder >= divisor? no 00000000 0101011:0 | |||||
* shift 00000000 101011:0_ | |||||
* remainder >= divisor? no 00000000 101011:00 | |||||
* shift 00000001 01011:00_ | |||||
* remainder >= divisor? no 00000001 01011:000 | |||||
* shift 00000010 1011:000_ | |||||
* remainder >= divisor? no 00000010 1011:0000 | |||||
* shift 00000101 011:0000_ | |||||
* remainder >= divisor? no 00000101 011:00000 | |||||
* shift 00001010 11:00000_ | |||||
* remainder >= divisor? yes 00001010 11:000001 | |||||
* remainder -= divisor - 00000111 | |||||
* ---------- | |||||
* 00000011 11:000001 | |||||
* shift 00000111 1:000001_ | |||||
* remainder >= divisor? yes 00000111 1:0000011 | |||||
* remainder -= divisor - 00000111 | |||||
* ---------- | |||||
* 00000000 1:0000011 | |||||
* shift 00000001 :0000011_ | |||||
* remainder >= divisor? no 00000001 :00000110 | |||||
* | |||||
* The quotient is 00000110. | |||||
*/ | |||||
.Ldivide: | |||||
/* | |||||
* Prepare for division by assuming the result | |||||
* is unsigned, and storing its "sign" as 0. | |||||
*/ | |||||
movi r17, 0 | |||||
/* Which division opcode? */ | |||||
xori r15, r4, 0x25 /* OPX of div */ | |||||
bne r15, zero, .Lunsigned_division | |||||
/* | |||||
* OPX is div. Determine and store the sign of the quotient. | |||||
* Then take the absolute value of both operands. | |||||
*/ | |||||
xor r17, r3, r6 /* MSB contains sign of quotient */ | |||||
bge r3, zero, 0f | |||||
sub r3, zero, r3 /* -r3 */ | |||||
0: | |||||
bge r6, zero, 0f | |||||
sub r6, zero, r6 /* -r6 */ | |||||
0: | |||||
.Lunsigned_division: | |||||
/* Initialize the unsigned-division loop. */ | |||||
movi r13, 0 /* remainder = 0 */ | |||||
/* Now | |||||
* r3 = dividend : quotient | |||||
* r4 = 0x25 for div, 0x24 for divu | |||||
* r6 = divisor | |||||
* r13 = remainder | |||||
* r14 = loop counter (already initialized to 32) | |||||
* r17 = MSB contains sign of quotient | |||||
*/ | |||||
/* | |||||
* for (count = 32; count > 0; --count) | |||||
* { | |||||
*/ | |||||
.Ldivide_loop: | |||||
/* | |||||
* Division: | |||||
* | |||||
* (remainder:dividend:quotient) <<= 1; | |||||
*/ | |||||
slli r13, r13, 1 | |||||
cmplt r15, r3, zero /* r15 = MSB of r3 */ | |||||
or r13, r13, r15 | |||||
slli r3, r3, 1 | |||||
/* | |||||
* if (remainder >= divisor) | |||||
* { | |||||
* set LSB of quotient | |||||
* remainder -= divisor; | |||||
* } | |||||
*/ | |||||
bltu r13, r6, .Ldiv_skip | |||||
ori r3, r3, 1 | |||||
sub r13, r13, r6 | |||||
.Ldiv_skip: | |||||
/* | |||||
* } | |||||
*/ | |||||
subi r14, r14, 1 | |||||
bne r14, zero, .Ldivide_loop | |||||
mov r9, r3 | |||||
/* Now | |||||
* r9 = quotient | |||||
* r4 = 0x25 for div, 0x24 for divu | |||||
* r7 = 4*(C^16) | |||||
* r17 = MSB contains sign of quotient | |||||
*/ | |||||
/* | |||||
* Conditionally negate signed quotient. If quotient is unsigned, | |||||
* the sign already is initialized to 0. | |||||
*/ | |||||
bge r17, zero, .Lstore_result | |||||
sub r9, zero, r9 /* -r9 */ | |||||
br .Lstore_result | |||||
/* MULTIPLICATION | |||||
* | |||||
* A "product" is the number that one gets by summing a "multiplicand" | |||||
* several times. The "multiplier" specifies the number of copies of the | |||||
* multiplicand that are summed. | |||||
* | |||||
* Actual multiplication algorithms don't use repeated addition, however. | |||||
* Shift-and-add algorithms get the same answer as repeated addition, and | |||||
* they are faster. To compute the lower half of a product (pppp below) | |||||
* one shifts the product left before adding in each of the partial products | |||||
* (a * mmmm) through (d * mmmm). | |||||
* | |||||
* To compute the upper half of a product (PPPP below), one adds in the | |||||
* partial products (d * mmmm) through (a * mmmm), each time following the | |||||
* add by a right shift of the product. | |||||
* | |||||
* mmmm | |||||
* * abcd | |||||
* ------ | |||||
* #### = d * mmmm | |||||
* #### = c * mmmm | |||||
* #### = b * mmmm | |||||
* #### = a * mmmm | |||||
* -------- | |||||
* PPPPpppp | |||||
* | |||||
* The example above shows 4 partial products. Computing actual Nios II | |||||
* products requires 32 partials. | |||||
* | |||||
* It is possible to compute the result of mulxsu from the result of mulxuu | |||||
* because the only difference between the results of these two opcodes is | |||||
* the value of the partial product associated with the sign bit of rA. | |||||
* | |||||
* mulxsu = mulxuu - ((rA < 0) ? rB : 0); | |||||
* | |||||
* It is possible to compute the result of mulxss from the result of mulxsu | |||||
* because the only difference between the results of these two opcodes is | |||||
* the value of the partial product associated with the sign bit of rB. | |||||
* | |||||
* mulxss = mulxsu - ((rB < 0) ? rA : 0); | |||||
* | |||||
*/ | |||||
.Lmul_immed: | |||||
/* Opcode is muli. Change it into mul for remainder of algorithm. */ | |||||
mov r7, r6 /* Field B is dest register, not field C. */ | |||||
mov r6, r4 /* Field IMM16 is src2, not field B. */ | |||||
movi r4, 0x27 /* OPX of mul is 0x27 */ | |||||
.Lmultiply: | |||||
/* Initialize the multiplication loop. */ | |||||
movi r9, 0 /* mul_product = 0 */ | |||||
movi r10, 0 /* mulxuu_product = 0 */ | |||||
mov r11, r6 /* save original multiplier for mulxsu and mulxss */ | |||||
mov r12, r6 /* mulxuu_multiplier (will be shifted) */ | |||||
movi r16, 1 /* used to create "rori B,A,1" from "ror B,A,r16" */ | |||||
/* Now | |||||
* r3 = multiplicand | |||||
* r6 = mul_multiplier | |||||
* r7 = 4 * dest_register (used later as offset to sp) | |||||
* r9 = mul_product | |||||
* r10 = mulxuu_product | |||||
* r11 = original multiplier | |||||
* r12 = mulxuu_multiplier | |||||
* r14 = loop counter (already initialized) | |||||
* r15 = temp | |||||
* r16 = 1 | |||||
*/ | |||||
/* | |||||
* for (count = 32; count > 0; --count) | |||||
* { | |||||
*/ | |||||
.Lmultiply_loop: | |||||
/* | |||||
* mul_product <<= 1; | |||||
* lsb = multiplier & 1; | |||||
*/ | |||||
slli r9, r9, 1 | |||||
andi r15, r12, 1 | |||||
/* | |||||
* if (lsb == 1) | |||||
* { | |||||
* mulxuu_product += multiplicand; | |||||
* } | |||||
*/ | |||||
beq r15, zero, .Lmulx_skip | |||||
add r10, r10, r3 | |||||
cmpltu r15, r10, r3 /* Save the carry from the MSB of mulxuu_product. */ | |||||
ror r15, r15, r16 /* r15 = 0x80000000 on carry, or else 0x00000000 */ | |||||
.Lmulx_skip: | |||||
/* | |||||
* if (MSB of mul_multiplier == 1) | |||||
* { | |||||
* mul_product += multiplicand; | |||||
* } | |||||
*/ | |||||
bge r6, zero, .Lmul_skip | |||||
add r9, r9, r3 | |||||
.Lmul_skip: | |||||
/* | |||||
* mulxuu_product >>= 1; logical shift | |||||
* mul_multiplier <<= 1; done with MSB | |||||
* mulx_multiplier >>= 1; done with LSB | |||||
*/ | |||||
srli r10, r10, 1 | |||||
or r10, r10, r15 /* OR in the saved carry bit. */ | |||||
slli r6, r6, 1 | |||||
srli r12, r12, 1 | |||||
/* | |||||
* } | |||||
*/ | |||||
subi r14, r14, 1 | |||||
bne r14, zero, .Lmultiply_loop | |||||
/* | |||||
* Multiply emulation loop done. | |||||
*/ | |||||
/* Now | |||||
* r3 = multiplicand | |||||
* r4 = OPX | |||||
* r7 = 4 * dest_register (used later as offset to sp) | |||||
* r9 = mul_product | |||||
* r10 = mulxuu_product | |||||
* r11 = original multiplier | |||||
* r15 = temp | |||||
*/ | |||||
/* | |||||
* Select/compute the result based on OPX. | |||||
*/ | |||||
/* OPX == mul? Then store. */ | |||||
xori r15, r4, 0x27 | |||||
beq r15, zero, .Lstore_result | |||||
/* It's one of the mulx.. opcodes. Move over the result. */ | |||||
mov r9, r10 | |||||
/* OPX == mulxuu? Then store. */ | |||||
xori r15, r4, 0x07 | |||||
beq r15, zero, .Lstore_result | |||||
/* Compute mulxsu | |||||
* | |||||
* mulxsu = mulxuu - ((rA < 0) ? rB : 0); | |||||
*/ | |||||
bge r3, zero, .Lmulxsu_skip | |||||
sub r9, r9, r11 | |||||
.Lmulxsu_skip: | |||||
/* OPX == mulxsu? Then store. */ | |||||
xori r15, r4, 0x17 | |||||
beq r15, zero, .Lstore_result | |||||
/* Compute mulxss | |||||
* | |||||
* mulxss = mulxsu - ((rB < 0) ? rA : 0); | |||||
*/ | |||||
bge r11, zero, .Lmulxss_skip | |||||
sub r9, r9, r3 | |||||
.Lmulxss_skip: | |||||
/* At this point, assume that OPX is mulxss, so store */ | |||||
.Lstore_result: | |||||
add r7, r7, sp | |||||
stw r9, 0(r7) | |||||
ldw r16, 0(sp) | |||||
ldw r17, 4(sp) | |||||
ldw r18, 8(sp) | |||||
ldw r19, 12(sp) | |||||
ldw r20, 16(sp) | |||||
ldw r21, 20(sp) | |||||
ldw r22, 24(sp) | |||||
ldw r23, 28(sp) | |||||
/* bt @ 32 - Breakpoint register usually isn't an operand. */ | |||||
/* et @ 36 - Don't corrupt et. */ | |||||
/* gp @ 40 - Don't corrupt gp. */ | |||||
/* sp @ 44 - Don't corrupt sp. */ | |||||
ldw fp, 48(sp) | |||||
/* ea @ 52 - Don't corrupt ea. */ | |||||
/* ba @ 56 - Breakpoint register usually isn't an operand. */ | |||||
addi sp, sp, 60 | |||||
br .Lexception_exit | |||||
.Lnot_muldiv: | |||||
addi sp, sp, 60 | |||||
.section .exceptions.exit.label | |||||
.Lexception_exit: | |||||
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2003-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. * | |||||
* * | |||||
* 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
/* | |||||
* This is the trap exception handler for Nios2. | |||||
*/ | |||||
/* | |||||
* Provide a label which can be used to pull this file in. | |||||
*/ | |||||
.section .exceptions.start | |||||
.globl alt_exception_trap | |||||
alt_exception_trap: | |||||
/* | |||||
* Pull in the entry/exit code. | |||||
*/ | |||||
.globl alt_exception | |||||
.section .exceptions.soft, "xa" | |||||
.Ltrap_handler: | |||||
/* | |||||
* Did a trap instruction cause the exception? | |||||
* | |||||
* The instruction which the exception occurred on has been loaded | |||||
* into r2 by code in alt_exception_entry.S | |||||
* | |||||
*/ | |||||
#ifdef ALT_CPU_CPU_ARCH_NIOS2_R2 | |||||
movhi r3,0xb41d /* upper half of trap opcode */ | |||||
ori r3,r3,0x0020 /* lower half of trap opcode */ | |||||
beq r2,r3,.Lis_trap | |||||
#ifdef NIOS2_CDX_PRESENT | |||||
mov r3,r2 | |||||
andhi r3,r3,0xffff | |||||
ori r3,r3,0xd009 /* trap.n opcode */ | |||||
beq r2,r3,.Lis_trap | |||||
#endif | |||||
br .Lnot_trap | |||||
#else | |||||
movhi r3,0x003b /* upper half of trap opcode */ | |||||
ori r3,r3,0x683a /* lower half of trap opcode */ | |||||
bne r2,r3,.Lnot_trap | |||||
#endif | |||||
.Lis_trap: | |||||
/* | |||||
* There is no trap handler defined here, and so executing a trap | |||||
* instruction causes a software break. If you provide a trap handler, | |||||
* then you must replace the break instruction below with your handler. | |||||
* Your handler must preserve ea and the usual callee saved registers. | |||||
*/ | |||||
break | |||||
br .Lexception_exit | |||||
.Lnot_trap: | |||||
.section .exceptions.exit.label | |||||
.Lexception_exit: | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "sys/alt_errno.h" | |||||
#include "sys/alt_warning.h" | |||||
#include "os/alt_syscall.h" | |||||
/* | |||||
* execve() is used by newlib to launch new processes. This is unsupported in | |||||
* the HAL environment. However a "do-nothing" implementation is still | |||||
* provied for newlib compatability. | |||||
* | |||||
* ALT_EXECVE is mapped onto the execve() system call in alt_syscall.h | |||||
*/ | |||||
int ALT_EXECVE (char *name, char ** argv, char** env) | |||||
{ | |||||
/* Generate a link time warning, should this function ever be called. */ | |||||
ALT_STUB_WARNING(execve); | |||||
/* Indicate an error */ | |||||
ALT_ERRNO = ENOSYS; | |||||
return -1; | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "sys/alt_irq.h" | |||||
#include "sys/alt_sim.h" | |||||
#include "os/alt_hooks.h" | |||||
#include "os/alt_syscall.h" | |||||
#include "alt_types.h" | |||||
#include "sys/alt_log_printf.h" | |||||
/* | |||||
* _exit() is called by exit() in order to terminate the current process. | |||||
* Typically this is called when main() completes. It should never return. | |||||
* Since there is nowhere to go once this process completes, this | |||||
* implementation simply blocks forever. | |||||
* | |||||
* Note that interrupts are not disabled so that execution outside of this | |||||
* thread is allowed to continue. | |||||
* | |||||
* ALT_EXIT is mapped onto the _exit() system call in alt_syscall.h | |||||
*/ | |||||
void ALT_EXIT (int exit_code) | |||||
{ | |||||
/* ALT_LOG - please see HAL/inc/alt_log_printf.h for details */ | |||||
ALT_LOG_PRINT_BOOT("[alt_exit.c] Entering _exit() function.\r\n"); | |||||
ALT_LOG_PRINT_BOOT("[alt_exit.c] Exit code from main was %d.\r\n",exit_code); | |||||
/* Stop all other threads */ | |||||
ALT_LOG_PRINT_BOOT("[alt_exit.c] Calling ALT_OS_STOP().\r\n"); | |||||
ALT_OS_STOP(); | |||||
/* Provide notification to the simulator that we've stopped */ | |||||
ALT_LOG_PRINT_BOOT("[alt_exit.c] Calling ALT_SIM_HALT().\r\n"); | |||||
ALT_SIM_HALT(exit_code); | |||||
/* spin forever, since there's no where to go back to */ | |||||
ALT_LOG_PRINT_BOOT("[alt_exit.c] Spinning forever.\r\n"); | |||||
while (1); | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <unistd.h> | |||||
#include <fcntl.h> | |||||
#include <stdio.h> | |||||
#include <stdarg.h> | |||||
#include "sys/alt_errno.h" | |||||
#include "priv/alt_file.h" | |||||
#include "alt_types.h" | |||||
#include "os/alt_syscall.h" | |||||
#define ALT_FCNTL_FLAGS_MASK ((alt_u32) (O_APPEND | O_NONBLOCK)) | |||||
/* | |||||
* fcntl() is a limited implementation of the standard fcntl() system call. | |||||
* It can be used to change the state of the flags associated with an open | |||||
* file descriptor. Normally these flags are set during the call to | |||||
* open(). It is anticipated that the main use of this function will be to | |||||
* change the state of a device from blocking to non-blocking (where this is | |||||
* supported). | |||||
* | |||||
* The input argument "fd" is the file descriptor to be manipulated. "cmd" | |||||
* is the command to execute. This can be either F_GETFL (return the | |||||
* current value of the flags) or F_SETFL (set the value of the flags). | |||||
* | |||||
* If "cmd" is F_SETFL then the argument "arg" is the new value of flags, | |||||
* otherwise "arg" is ignored. Only the flags: O_APPEND and O_NONBLOCK | |||||
* can be updated by a call to fcntl(). All other flags remain | |||||
* unchanged. | |||||
* | |||||
* ALT_FCNTL is mapped onto the fcntl() system call in alt_syscall.h | |||||
*/ | |||||
int ALT_FCNTL (int file, int cmd, ...) | |||||
{ | |||||
alt_fd* fd; | |||||
long flags; | |||||
va_list argp; | |||||
/* | |||||
* A common error case is that when the file descriptor was created, the call | |||||
* to open() failed resulting in a negative file descriptor. This is trapped | |||||
* below so that we don't try and process an invalid file descriptor. | |||||
*/ | |||||
fd = (file < 0) ? NULL : &alt_fd_list[file]; | |||||
if (fd) | |||||
{ | |||||
switch (cmd) | |||||
{ | |||||
case F_GETFL: | |||||
return fd->fd_flags & ~((alt_u32) ALT_FD_FLAGS_MASK); | |||||
case F_SETFL: | |||||
va_start(argp, cmd); | |||||
flags = va_arg(argp, long); | |||||
fd->fd_flags &= ~ALT_FCNTL_FLAGS_MASK; | |||||
fd->fd_flags |= (flags & ALT_FCNTL_FLAGS_MASK); | |||||
va_end(argp); | |||||
return 0; | |||||
default: | |||||
ALT_ERRNO = EINVAL; | |||||
return -1; | |||||
} | |||||
} | |||||
ALT_ERRNO = EBADFD; | |||||
return -1; | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <errno.h> | |||||
#include "priv/alt_file.h" | |||||
/* | |||||
* alt_fd_lock() is called as a consequence of an ioctl call to gain exclusive | |||||
* access to a device, i.e.: | |||||
* | |||||
* ioctl (fd, TIOCEXCL, NULL); | |||||
* | |||||
* If there are no other open file descriptors which reference the same | |||||
* device, then alt_fd_lock() will grant the lock. Further calls to open() | |||||
* for this device will fail until the lock is released. | |||||
* | |||||
* This is done by calling close() for this file descriptor, or by calling: | |||||
* | |||||
* ioctl (fd, TIOCNXCL, NULL); | |||||
* | |||||
* The return value is zero for success, or negative in the case of failure. | |||||
*/ | |||||
int alt_fd_lock (alt_fd* fd) | |||||
{ | |||||
int i; | |||||
int rc = 0; | |||||
ALT_SEM_PEND(alt_fd_list_lock, 0); | |||||
for (i = 0; i < alt_max_fd; i++) | |||||
{ | |||||
if ((&alt_fd_list[i] != fd) && (alt_fd_list[i].dev == fd->dev)) | |||||
{ | |||||
rc = -EACCES; | |||||
goto alt_fd_lock_exit; | |||||
} | |||||
} | |||||
fd->fd_flags |= ALT_FD_EXCL; | |||||
alt_fd_lock_exit: | |||||
ALT_SEM_POST(alt_fd_list_lock); | |||||
return rc; | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <errno.h> | |||||
#include "priv/alt_file.h" | |||||
/* | |||||
* alt_fd_unlock() is the inverse of alt_fd_lock(). It is called as a | |||||
* consequence of a TIOCNXCL ioctl request, e.g: | |||||
* | |||||
* ioctl (fd, TIOCNXCL, NULL); | |||||
* | |||||
* It enables multiple file descriptors to exist for the same device. This | |||||
* is normally the case, but it may have been disabled by a previous call to | |||||
* alt_fd_lock(). | |||||
* | |||||
* Return zero on sucess, and a negative value on failure. | |||||
* | |||||
* The current implementation always succeeds. | |||||
*/ | |||||
int alt_fd_unlock (alt_fd* fd) | |||||
{ | |||||
fd->fd_flags &= ~ALT_FD_EXCL; | |||||
return 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. * | |||||
* * | |||||
* 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 <stddef.h> | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include "sys/alt_dev.h" | |||||
#include "priv/alt_file.h" | |||||
#include "alt_types.h" | |||||
/* | |||||
* alt_find_dev() is used by open() in order to locate a previously registered | |||||
* device with the name "name". The input argument "llist" is a pointer to the | |||||
* head of the device list to search. | |||||
* | |||||
* The return value is a pointer to the matching device, or NULL if there is | |||||
* no match. | |||||
* | |||||
* "name" must be an exact match for the devices registered name for a match to | |||||
* be found. | |||||
*/ | |||||
alt_dev* alt_find_dev(const char* name, alt_llist* llist) | |||||
{ | |||||
alt_dev* next = (alt_dev*) llist->next; | |||||
alt_32 len; | |||||
len = strlen(name) + 1; | |||||
/* | |||||
* Check each list entry in turn, until a match is found, or we reach the | |||||
* end of the list (i.e. next winds up pointing back to the list head). | |||||
*/ | |||||
while (next != (alt_dev*) llist) | |||||
{ | |||||
/* | |||||
* memcmp() is used here rather than strcmp() in order to reduce the size | |||||
* of the executable. | |||||
*/ | |||||
if (!memcmp (next->name, name, len)) | |||||
{ | |||||
/* match found */ | |||||
return next; | |||||
} | |||||
next = (alt_dev*) next->llist.next; | |||||
} | |||||
/* No match found */ | |||||
return NULL; | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <stddef.h> | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include "sys/alt_dev.h" | |||||
#include "priv/alt_file.h" | |||||
#include "alt_types.h" | |||||
/* | |||||
* alt_find_file() is used by open() in order to locate a previously registered | |||||
* filesystem that owns that mount point that contains the file named "name". | |||||
* | |||||
* The return value is a pointer to the matching filesystem, or NULL if there is | |||||
* no match. | |||||
* | |||||
* A match is considered to have been found if the filesystem name followed by | |||||
* either '/' or '\0' is the prefix of the filename. For example the filename: | |||||
* "/myfilesystem/junk.txt" would match: "/myfilesystem", but not: "/myfile". | |||||
*/ | |||||
alt_dev* alt_find_file (const char* name) | |||||
{ | |||||
alt_dev* next = (alt_dev*) alt_fs_list.next; | |||||
alt_32 len; | |||||
/* | |||||
* Check each list entry in turn, until a match is found, or we reach the | |||||
* end of the list (i.e. next winds up pointing back to the list head). | |||||
*/ | |||||
while (next != (alt_dev*) &alt_fs_list) | |||||
{ | |||||
len = strlen(next->name); | |||||
if (next->name[len-1] == '/') | |||||
{ | |||||
len -= 1; | |||||
} | |||||
if (((name[len] == '/') || (name[len] == '\0')) && | |||||
!memcmp (next->name, name, len)) | |||||
{ | |||||
/* match found */ | |||||
return next; | |||||
} | |||||
next = (alt_dev*) next->llist.next; | |||||
} | |||||
/* No match found */ | |||||
return NULL; | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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. * | |||||
******************************************************************************/ | |||||
/****************************************************************************** | |||||
* * | |||||
* Alt_flash.c - Functions to register a flash device to the "generic" flash * | |||||
* interface * | |||||
* * | |||||
* Author PRR * | |||||
* * | |||||
******************************************************************************/ | |||||
#include <errno.h> | |||||
#include "sys/alt_llist.h" | |||||
#include "sys/alt_flash_dev.h" | |||||
#include "priv/alt_file.h" | |||||
ALT_LLIST_HEAD(alt_flash_dev_list); | |||||
alt_flash_fd* alt_flash_open_dev(const char* name) | |||||
{ | |||||
alt_flash_dev* dev = (alt_flash_dev*)alt_find_dev(name, &alt_flash_dev_list); | |||||
if ((dev) && dev->open) | |||||
{ | |||||
return dev->open(dev, name); | |||||
} | |||||
return dev; | |||||
} | |||||
void alt_flash_close_dev(alt_flash_fd* fd) | |||||
{ | |||||
if (fd && fd->close) | |||||
{ | |||||
fd->close(fd); | |||||
} | |||||
return; | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "sys/alt_warning.h" | |||||
#include "sys/alt_errno.h" | |||||
#include "os/alt_syscall.h" | |||||
/* | |||||
* The fork() system call is used by newlib to create a duplicate copy of the | |||||
* curent process. This is unsupported in the HAL environment. However a | |||||
* "do-nothing" implementation is still provied for newlib compatability. | |||||
* | |||||
* ALT_FORK is mapped onto the fork() system call in alt_syscall.h | |||||
*/ | |||||
int ALT_FORK (void) | |||||
{ | |||||
/* Generate a link time warning, should this function ever be called. */ | |||||
ALT_STUB_WARNING(fork); | |||||
/* Indicate an error */ | |||||
ALT_ERRNO = ENOSYS; | |||||
return -1; | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <errno.h> | |||||
#include "sys/alt_dev.h" | |||||
#include "priv/alt_file.h" | |||||
/* | |||||
* The alt_fs_reg() function is used to register a file system. Once registered | |||||
* a device can be accessed using the standard posix calls: open(), read(), | |||||
* write() etc. | |||||
* | |||||
* System behaviour is undefined in the event that a file system is registered | |||||
* with a name that conflicts with an existing device or file system. | |||||
* | |||||
* alt_fs_reg() is not thread safe in the sense that there should be no other | |||||
* thread using the file system list at the time that alt_dev_reg() is called. In | |||||
* practice this means that alt_fs_reg() should only be called while operating | |||||
* in a single threaded mode. The expectation is that it will only be called | |||||
* by the file system initilisation functions invoked by alt_sys_init(), which in | |||||
* turn should only be called by the single threaded C startup code. | |||||
* | |||||
* A return value of zero indicates success. A negative return value indicates | |||||
* failure. | |||||
*/ | |||||
int alt_fs_reg (alt_dev* dev) | |||||
{ | |||||
/* | |||||
* check that the device has a name. | |||||
*/ | |||||
if (!dev->name) | |||||
{ | |||||
return -ENODEV; | |||||
} | |||||
/* | |||||
* register the file system. | |||||
*/ | |||||
alt_llist_insert(&alt_fs_list, &dev->llist); | |||||
return 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. * | |||||
* * | |||||
* 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 <stddef.h> | |||||
#include <sys/stat.h> | |||||
#include "sys/alt_dev.h" | |||||
#include "sys/alt_warning.h" | |||||
#include "sys/alt_errno.h" | |||||
#include "priv/alt_file.h" | |||||
#include "os/alt_syscall.h" | |||||
/* | |||||
* The fstat() system call is used to obtain information about the capabilities | |||||
* of an open file descriptor. By default file descriptors are marked as | |||||
* being character devices. If a device or file system wishes to advertise | |||||
* alternative capabilities then they can register an fstat() function within | |||||
* their associated alt_dev structure. This will be called to fill in the | |||||
* entries in the imput "st" structure. | |||||
* | |||||
* This function is provided for compatability with newlib. | |||||
* | |||||
* ALT_FSTAT is mapped onto the fstat() system call in alt_syscall.h | |||||
*/ | |||||
#ifdef ALT_USE_DIRECT_DRIVERS | |||||
#include "system.h" | |||||
/* | |||||
* Provide minimal version that just describes all file descriptors | |||||
* as character devices for provided stdio devices. | |||||
*/ | |||||
int ALT_FSTAT (int file, struct stat *st) | |||||
{ | |||||
switch (file) { | |||||
#ifdef ALT_STDIN_PRESENT | |||||
case 0: /* stdin file descriptor */ | |||||
#endif /* ALT_STDIN_PRESENT */ | |||||
#ifdef ALT_STDOUT_PRESENT | |||||
case 1: /* stdout file descriptor */ | |||||
#endif /* ALT_STDOUT_PRESENT */ | |||||
#ifdef ALT_STDERR_PRESENT | |||||
case 2: /* stderr file descriptor */ | |||||
#endif /* ALT_STDERR_PRESENT */ | |||||
st->st_mode = _IFCHR; | |||||
return 0; | |||||
default: | |||||
return -1; | |||||
} | |||||
#if !defined(ALT_STDIN_PRESENT) && !defined(ALT_STDOUT_PRESENT) && !defined(ALT_STDERR_PRESENT) | |||||
/* Generate a link time warning, should this function ever be called. */ | |||||
ALT_STUB_WARNING(fstat); | |||||
#endif | |||||
} | |||||
#else /* !ALT_USE_DIRECT_DRIVERS */ | |||||
int ALT_FSTAT (int file, struct stat *st) | |||||
{ | |||||
alt_fd* fd; | |||||
/* | |||||
* A common error case is that when the file descriptor was created, the call | |||||
* to open() failed resulting in a negative file descriptor. This is trapped | |||||
* below so that we don't try and process an invalid file descriptor. | |||||
*/ | |||||
fd = (file < 0) ? NULL : &alt_fd_list[file]; | |||||
if (fd) | |||||
{ | |||||
/* Call the drivers fstat() function to fill out the "st" structure. */ | |||||
if (fd->dev->fstat) | |||||
{ | |||||
return fd->dev->fstat(fd, st); | |||||
} | |||||
/* | |||||
* If no function is provided, mark the fd as belonging to a character | |||||
* device. | |||||
*/ | |||||
else | |||||
{ | |||||
st->st_mode = _IFCHR; | |||||
return 0; | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
ALT_ERRNO = EBADFD; | |||||
return -1; | |||||
} | |||||
} | |||||
#endif /* ALT_USE_DIRECT_DRIVERS */ |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <stddef.h> | |||||
#include <stdio.h> | |||||
#include <errno.h> | |||||
#include "sys/alt_dev.h" | |||||
#include "priv/alt_file.h" | |||||
#include "alt_types.h" | |||||
#include "system.h" | |||||
/* | |||||
* alt_get_fd() is called to allocate a new file descriptor from the file | |||||
* descriptor pool. If a file descriptor is succesfully allocated, it is | |||||
* configured to refer to device "dev". | |||||
* | |||||
* The return value is the index of the file descriptor structure (i.e. | |||||
* the offset of the file descriptor within the file descriptor array). A | |||||
* negative value indicates failure. | |||||
*/ | |||||
int alt_get_fd (alt_dev* dev) | |||||
{ | |||||
alt_32 i; | |||||
int rc = -EMFILE; | |||||
/* | |||||
* Take the alt_fd_list_lock semaphore in order to avoid races when | |||||
* accessing the file descriptor pool. | |||||
*/ | |||||
ALT_SEM_PEND(alt_fd_list_lock, 0); | |||||
/* | |||||
* Search through the list of file descriptors, and allocate the first | |||||
* free descriptor that's found. | |||||
* | |||||
* If a free descriptor is found, then the value of "alt_max_fd" is | |||||
* updated accordingly. "alt_max_fd" is a 'highwater mark' which | |||||
* indicates the highest file descriptor ever allocated. This is used to | |||||
* improve efficency when searching the file descriptor list, and | |||||
* therefore reduce contention on the alt_fd_list_lock semaphore. | |||||
*/ | |||||
for (i = 0; i < ALT_MAX_FD; i++) | |||||
{ | |||||
if (!alt_fd_list[i].dev) | |||||
{ | |||||
alt_fd_list[i].dev = dev; | |||||
if (i > alt_max_fd) | |||||
{ | |||||
alt_max_fd = i; | |||||
} | |||||
rc = i; | |||||
goto alt_get_fd_exit; | |||||
} | |||||
} | |||||
alt_get_fd_exit: | |||||
/* | |||||
* Release the alt_fd_list_lock semaphore now that we are done with the | |||||
* file descriptor pool. | |||||
*/ | |||||
ALT_SEM_POST(alt_fd_list_lock); | |||||
return rc; | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <stdio.h> | |||||
#ifdef ALT_USE_DIRECT_DRIVERS | |||||
#include "system.h" | |||||
#include "sys/alt_driver.h" | |||||
#include "sys/alt_stdio.h" | |||||
#include "priv/alt_file.h" | |||||
#include "unistd.h" | |||||
#endif | |||||
#ifdef ALT_SEMIHOSTING | |||||
#include "sys/alt_stdio.h" | |||||
#include "unistd.h" | |||||
#endif | |||||
/* | |||||
* Uses the ALT_DRIVER_READ() macro to call directly to driver if available. | |||||
* Otherwise, uses newlib provided getchar() routine. | |||||
*/ | |||||
int | |||||
alt_getchar(void) | |||||
{ | |||||
#ifdef ALT_SEMIHOSTING | |||||
char c; | |||||
read(STDIN_FILENO,&c,1); | |||||
return c; | |||||
#else | |||||
#ifdef ALT_USE_DIRECT_DRIVERS | |||||
ALT_DRIVER_READ_EXTERNS(ALT_STDIN_DEV); | |||||
char c; | |||||
if (ALT_DRIVER_READ(ALT_STDIN_DEV, &c, 1, alt_fd_list[STDIN_FILENO].fd_flags) <= 0) { | |||||
return -1; | |||||
} | |||||
return c; | |||||
#else | |||||
return getchar(); | |||||
#endif | |||||
#endif | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "os/alt_syscall.h" | |||||
/* | |||||
* The getpid() system call is used by newlib to obtain the current process | |||||
* id. Since there is only ever a single process in the HAL environment, | |||||
* this just returns a constant. | |||||
* | |||||
* ALT_GETPID is mapped onto the getpid() system call in alt_syscall.h | |||||
*/ | |||||
int ALT_GETPID (void) | |||||
{ | |||||
return 0; | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2017,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. * | |||||
* * | |||||
* 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 <sys/time.h> | |||||
#include <sys/times.h> | |||||
#include <errno.h> | |||||
#include "sys/alt_alarm.h" | |||||
#include "alt_types.h" | |||||
#include "os/alt_syscall.h" | |||||
/* | |||||
* Macro defining the number of micoseconds in a second. | |||||
*/ | |||||
#define ALT_US (1000000) | |||||
/* | |||||
* "alt_timezone" and "alt_resettime" are the values of the the reset time and | |||||
* time zone set through the last call to settimeofday(). By default they are | |||||
* zero initialised. | |||||
*/ | |||||
struct timezone alt_timezone = {0, 0}; | |||||
struct timeval alt_resettime = {0, 0}; | |||||
/* | |||||
* gettimeofday() can be called to obtain a time structure which indicates the | |||||
* current "wall clock" time. This is calculated using the elapsed number of | |||||
* system clock ticks, and the value of "alt_resettime" and "alt_timezone" set | |||||
* through the last call to settimeofday(). | |||||
* | |||||
* Warning: if this function is called concurrently with a call to | |||||
* settimeofday(), the value returned by gettimeofday() will be unreliable. | |||||
* | |||||
* ALT_GETTIMEOFDAY is mapped onto the gettimeofday() system call in | |||||
* alt_syscall.h | |||||
*/ | |||||
#if defined (__GNUC__) && (__GNUC__ >= 4) | |||||
int ALT_GETTIMEOFDAY (struct timeval *ptimeval, void *ptimezone_vptr) | |||||
{ | |||||
struct timezone *ptimezone = (struct timezone*)ptimezone_vptr; | |||||
#else | |||||
int ALT_GETTIMEOFDAY (struct timeval *ptimeval, struct timezone *ptimezone) | |||||
{ | |||||
#endif | |||||
alt_u64 nticks = alt_nticks (); | |||||
alt_u32 tick_rate = alt_ticks_per_second (); | |||||
/* | |||||
* Check to see if the system clock is running. This is indicated by a | |||||
* non-zero system clock rate. If the system clock is not running, an error | |||||
* is generated and the contents of "ptimeval" and "ptimezone" are not | |||||
* updated. | |||||
*/ | |||||
if (tick_rate) | |||||
{ | |||||
ptimeval->tv_sec = alt_resettime.tv_sec + nticks/tick_rate; | |||||
ptimeval->tv_usec = alt_resettime.tv_usec + | |||||
(alt_u32)((nticks*(ALT_US/tick_rate))%ALT_US); | |||||
while(ptimeval->tv_usec < 0) { | |||||
if (ptimeval->tv_sec <= 0) | |||||
{ | |||||
ptimeval->tv_sec = 0; | |||||
ptimeval->tv_usec = 0; | |||||
break; | |||||
} | |||||
else | |||||
{ | |||||
ptimeval->tv_sec--; | |||||
ptimeval->tv_usec += ALT_US; | |||||
} | |||||
} | |||||
while(ptimeval->tv_usec >= ALT_US) { | |||||
ptimeval->tv_sec++; | |||||
ptimeval->tv_usec -= ALT_US; | |||||
} | |||||
if (ptimezone) | |||||
{ | |||||
ptimezone->tz_minuteswest = alt_timezone.tz_minuteswest; | |||||
ptimezone->tz_dsttime = alt_timezone.tz_dsttime; | |||||
} | |||||
return 0; | |||||
} | |||||
return -ENOTSUP; | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2003-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. * | |||||
* * | |||||
* 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 <assert.h> | |||||
#include <string.h> | |||||
#include <unistd.h> | |||||
#include "priv/nios2_gmon_data.h" | |||||
#include "sys/alt_irq.h" | |||||
#include "sys/alt_alarm.h" | |||||
/* Macros */ | |||||
/* How large should the bins be which we use to generate the histogram */ | |||||
#define PCSAMPLE_BYTES_PER_BUCKET 32 | |||||
#define NIOS2_READ_EA(dest) __asm__ ("mov %0, ea" : "=r" (dest)) | |||||
/* The compiler inserts calls to mcount() at the start of | |||||
* every function call. The structure mcount_fn_arc records t | |||||
* he return address of the function called (in from_pc) | |||||
* and the return address of the mcount function | |||||
* (in self_pc). The number of times this arc is executed is | |||||
* recorded in the field count. | |||||
*/ | |||||
struct mcount_fn_arc | |||||
{ | |||||
struct mcount_fn_arc * next; | |||||
void * from_pc; | |||||
unsigned int count; | |||||
}; | |||||
/* We need to maintain a list of pointers to the heads of each adjacency | |||||
* list so that we can find them when writing out the gmon.out file. Since | |||||
* we don't know at the start of program execution how many functions will | |||||
* be called we use a list structure to do this. | |||||
*/ | |||||
struct mcount_fn_entry | |||||
{ | |||||
struct mcount_fn_entry * next; | |||||
void * self_pc; | |||||
struct mcount_fn_arc * arc_head; | |||||
}; | |||||
/* function prototypes */ | |||||
void __mcount_record(void * self_pc, void * from_pc, struct mcount_fn_entry * fn_entry, struct mcount_fn_entry * * fn_head) __attribute__ ((no_instrument_function)); | |||||
static __inline__ void * mcount_allocate(unsigned int size) __attribute__ ((no_instrument_function)); | |||||
static int nios2_pcsample_init(void) __attribute__ ((no_instrument_function)); | |||||
static alt_u32 nios2_pcsample(void* alarm) __attribute__ ((no_instrument_function)); | |||||
/* global variables */ | |||||
/* stext and etext are defined in the linker script */ | |||||
extern char stext[]; | |||||
extern char etext[]; | |||||
/* Is the PC sampling stuff enabled yet? */ | |||||
static int pcsample_need_init = 1; | |||||
#define HASH_BUCKETS 64 /* Must be a power of 2 */ | |||||
/* This points to the list of adjacency list pointers. */ | |||||
struct mcount_fn_entry * __mcount_fn_head[HASH_BUCKETS]; | |||||
/* pointer to the in-memory buffer containing the histogram */ | |||||
static unsigned short* s_pcsamples = 0; | |||||
/* the address of the start and end of text section */ | |||||
static const unsigned int s_low_pc = (unsigned int)stext; | |||||
static const unsigned int s_high_pc = (unsigned int)etext; | |||||
/* the alarm structure to register for pc sampling */ | |||||
static alt_alarm s_nios2_pcsample_alarm; | |||||
unsigned int alt_gmon_data[GMON_DATA_SIZE] = | |||||
{ | |||||
0x6e6f6d67, /* "gmon" */ | |||||
GMON_DATA_SIZE, | |||||
0, | |||||
(unsigned int)stext, | |||||
(unsigned int)etext, | |||||
PCSAMPLE_BYTES_PER_BUCKET, | |||||
0, | |||||
(unsigned int)__mcount_fn_head, | |||||
(unsigned int)(__mcount_fn_head + HASH_BUCKETS) | |||||
}; | |||||
/* This holds the current slab of memory we're allocating out of */ | |||||
static char * mcount_slab_ptr = 0; | |||||
static int mcount_slab_size = 0; | |||||
#define MCOUNT_SLAB_INCREMENT 1020 | |||||
/* | |||||
* We can't use malloc to allocate memory because that's too complicated, and | |||||
* can't be called at interrupt time. Use the lower level allocator instead | |||||
* because that's interrupt safe (and because we never free anything). | |||||
* | |||||
* For speed, we allocate a block of data at once. | |||||
*/ | |||||
static __inline__ void * mcount_allocate(unsigned int size) | |||||
{ | |||||
void * data; | |||||
if (size > mcount_slab_size) | |||||
{ | |||||
mcount_slab_ptr = sbrk(MCOUNT_SLAB_INCREMENT); | |||||
mcount_slab_size = MCOUNT_SLAB_INCREMENT; | |||||
} | |||||
data = mcount_slab_ptr; | |||||
mcount_slab_ptr += size; | |||||
mcount_slab_size -= size; | |||||
return data; | |||||
} | |||||
/* | |||||
* Add the arc with the values of frompc and topc given to the graph. | |||||
* This function might be called at interrupt time so must be able to | |||||
* cope with reentrancy. | |||||
* | |||||
* The fast case, where we have already allocated a function arc, has been | |||||
* handled by the assmebler code. | |||||
*/ | |||||
void __mcount_record(void * self_pc, void * from_pc, struct mcount_fn_entry * fn_entry, struct mcount_fn_entry * * fn_head) | |||||
{ | |||||
alt_irq_context context; | |||||
struct mcount_fn_arc * arc_entry; | |||||
/* Keep trying to start up the PC sampler until it is running. | |||||
* (It can't start until the timer is going). | |||||
*/ | |||||
if (pcsample_need_init) | |||||
{ | |||||
pcsample_need_init = 0; | |||||
pcsample_need_init = nios2_pcsample_init(); | |||||
} | |||||
/* | |||||
* We must disable interrupts around the allocation and the list update to | |||||
* prevent corruption if the instrumented function is re-entrant. | |||||
* | |||||
* It's safe for the code above to be stepping through the chain and be | |||||
* interrupted by this code modifying it - there is an edge case which will | |||||
* leave two copies of the same arc on the list (both with count=1), but | |||||
* this is dealt with on the host. | |||||
*/ | |||||
context = alt_irq_disable_all(); | |||||
if (fn_entry == NULL) | |||||
{ | |||||
/* Add it to the list of functions we must output later. */ | |||||
fn_entry = (struct mcount_fn_entry *)mcount_allocate(sizeof(struct mcount_fn_entry)); | |||||
fn_entry->self_pc = self_pc; | |||||
fn_entry->arc_head = NULL; | |||||
fn_entry->next = *fn_head; | |||||
*fn_head = fn_entry; | |||||
} | |||||
/* We will need a new list entry - if there was a list entry before | |||||
* then the assembler code would have handled it. */ | |||||
arc_entry = (struct mcount_fn_arc *)mcount_allocate(sizeof(struct mcount_fn_arc)); | |||||
arc_entry->from_pc = from_pc; | |||||
arc_entry->count = 1; | |||||
arc_entry->next = fn_entry->arc_head; | |||||
fn_entry->arc_head = arc_entry; | |||||
alt_irq_enable_all(context); | |||||
} | |||||
/* | |||||
* nios2_pcsample_init starts profiling. | |||||
* It is called the first time mcount is called, and on subsequent calls to | |||||
* mcount until it returns zero. It initializes the pc histogram and turns on | |||||
* timer driven pc sampling. | |||||
*/ | |||||
static int nios2_pcsample_init(void) | |||||
{ | |||||
unsigned int pcsamples_size; | |||||
/* We sample the PC every tick */ | |||||
unsigned int prof_rate = alt_ticks_per_second(); | |||||
if (prof_rate == 0) | |||||
return 1; | |||||
/* allocate the histogram buffer s_pcsamples */ | |||||
pcsamples_size = (s_high_pc - s_low_pc)/PCSAMPLE_BYTES_PER_BUCKET; | |||||
s_pcsamples = (unsigned short*)sbrk(pcsamples_size * sizeof(unsigned short)); | |||||
if (s_pcsamples != 0) | |||||
{ | |||||
/* initialize the buffer to zero */ | |||||
memset(s_pcsamples, 0, pcsamples_size * sizeof(unsigned short)); | |||||
alt_gmon_data[GMON_DATA_PROFILE_DATA] = (int)s_pcsamples; | |||||
alt_gmon_data[GMON_DATA_PROFILE_RATE] = prof_rate; | |||||
/* Sample every tick (it's cheap) */ | |||||
alt_alarm_start(&s_nios2_pcsample_alarm, 1, nios2_pcsample, 0); | |||||
} | |||||
return 0; | |||||
} | |||||
/* | |||||
* Sample the PC value and store it in the histogram | |||||
*/ | |||||
static alt_u32 nios2_pcsample(void* context) | |||||
{ | |||||
unsigned int pc=0; | |||||
unsigned int bucket; | |||||
/* read the exception return address - this will be | |||||
* inaccurate if there are nested interrupts but we | |||||
* assume that this is rare and the inaccuracy will | |||||
* not be great */ | |||||
NIOS2_READ_EA(pc); | |||||
/* | |||||
* If we're within the profilable range then increment the relevant | |||||
* bucket in the histogram | |||||
*/ | |||||
if (pc >= s_low_pc && pc < s_high_pc && s_pcsamples != 0) | |||||
{ | |||||
bucket = (pc - s_low_pc)/PCSAMPLE_BYTES_PER_BUCKET; | |||||
s_pcsamples[bucket]++; | |||||
} | |||||
/* Sample every tick */ | |||||
return 1; | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
#include "nios2.h" | |||||
#include "system.h" | |||||
#include "alt_types.h" | |||||
#include "sys/alt_cache.h" | |||||
/* | |||||
* alt_icache_flush() is called to flush the instruction cache for a memory | |||||
* region of length "len" bytes, starting at address "start". | |||||
*/ | |||||
void alt_icache_flush (void* start, alt_u32 len) | |||||
{ | |||||
#if NIOS2_ICACHE_SIZE > 0 | |||||
char* i; | |||||
char* end; | |||||
/* | |||||
* This is the most we would ever need to flush. | |||||
*/ | |||||
if (len > NIOS2_ICACHE_SIZE) | |||||
{ | |||||
len = NIOS2_ICACHE_SIZE; | |||||
} | |||||
end = ((char*) start) + len; | |||||
for (i = start; i < end; i+= NIOS2_ICACHE_LINE_SIZE) | |||||
{ | |||||
__asm__ volatile ("flushi %0" :: "r" (i)); | |||||
} | |||||
/* | |||||
* For an unaligned flush request, we've got one more line left. | |||||
* Note that this is dependent on NIOS2_ICACHE_LINE_SIZE to be a | |||||
* multiple of 2 (which it always is). | |||||
*/ | |||||
if (((alt_u32) start) & (NIOS2_ICACHE_LINE_SIZE - 1)) | |||||
{ | |||||
__asm__ volatile ("flushi %0" :: "r" (i)); | |||||
} | |||||
/* | |||||
* Having flushed the cache, flush any stale instructions in the | |||||
* pipeline | |||||
*/ | |||||
__asm__ volatile ("flushp"); | |||||
#endif /* NIOS2_ICACHE_SIZE > 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. * | |||||
* * | |||||
* 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 "nios2.h" | |||||
#include "system.h" | |||||
#include "alt_types.h" | |||||
#include "sys/alt_cache.h" | |||||
/* | |||||
* alt_icache_flush_all() is called to flush the entire instruction cache. | |||||
*/ | |||||
void alt_icache_flush_all (void) | |||||
{ | |||||
#if NIOS2_ICACHE_SIZE > 0 | |||||
alt_icache_flush (0, NIOS2_ICACHE_SIZE); | |||||
#endif | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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 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 "system.h" | |||||
/* | |||||
* This file implements the HAL Enhanced interrupt API for Nios II processors | |||||
* with an internal interrupt controller (IIC). For most routines, this serves | |||||
* as a wrapper layer over the legacy interrupt API (which must be used with | |||||
* the IIC only). | |||||
* | |||||
* Use of the enhanced API is recommended so that application and device | |||||
* drivers are compatible with a Nios II system configured with an external | |||||
* interrupt controller (EIC), or IIC. This will afford maximum portability. | |||||
* | |||||
* If an EIC is present, the EIC device driver must provide these routines, | |||||
* because their operation will be specific to that EIC type. | |||||
*/ | |||||
#ifndef NIOS2_EIC_PRESENT | |||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT | |||||
#include "sys/alt_irq.h" | |||||
#include "priv/alt_iic_isr_register.h" | |||||
#include "priv/alt_legacy_irq.h" | |||||
/** @Function Description: This function registers an interrupt handler. | |||||
* If the function is succesful, then the requested interrupt will be enabled upon | |||||
* return. Registering a NULL handler will disable the interrupt. | |||||
* @API Type: External | |||||
* @param ic_id Ignored. | |||||
* @param irq IRQ number | |||||
* @return 0 if successful, else error (-1) | |||||
*/ | |||||
int alt_ic_isr_register(alt_u32 ic_id, alt_u32 irq, alt_isr_func isr, | |||||
void *isr_context, void *flags) | |||||
{ | |||||
return alt_iic_isr_register(ic_id, irq, isr, isr_context, flags); | |||||
} | |||||
/** @Function Description: This function enables a single interrupt. | |||||
* @API Type: External | |||||
* @param ic_id Ignored. | |||||
* @param irq IRQ number | |||||
* @return 0 if successful, else error (-1) | |||||
*/ | |||||
int alt_ic_irq_enable (alt_u32 ic_id, alt_u32 irq) | |||||
{ | |||||
return alt_irq_enable(irq); | |||||
} | |||||
/** @Function Description: This function disables a single interrupt. | |||||
* @API Type: External | |||||
* @param ic_id Ignored. | |||||
* @param irq IRQ number | |||||
* @return 0 if successful, else error (-1) | |||||
*/ | |||||
int alt_ic_irq_disable(alt_u32 ic_id, alt_u32 irq) | |||||
{ | |||||
return alt_irq_disable(irq); | |||||
} | |||||
/** @Function Description: This function to determine if corresponding | |||||
* interrupt is enabled. | |||||
* @API Type: External | |||||
* @param ic_id Ignored. | |||||
* @param irq IRQ number | |||||
* @return Zero if corresponding interrupt is disabled and | |||||
* non-zero otherwise. | |||||
*/ | |||||
alt_u32 alt_ic_irq_enabled(alt_u32 ic_id, alt_u32 irq) | |||||
{ | |||||
alt_u32 irq_enabled; | |||||
NIOS2_READ_IENABLE(irq_enabled); | |||||
return (irq_enabled & (1 << irq)) ? 1: 0; | |||||
} | |||||
#endif /* ALT_ENHANCED_INTERRUPT_API_PRESENT */ | |||||
#endif /* NIOS2_EIC_PRESENT */ |
/****************************************************************************** | |||||
* * | |||||
* 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 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 <errno.h> | |||||
#include "system.h" | |||||
/* | |||||
* Provides an interrupt registry mechanism for the any CPUs internal interrupt | |||||
* controller (IIC) when the enhanced interrupt API is active. | |||||
*/ | |||||
#ifndef ALT_CPU_EIC_PRESENT | |||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT | |||||
#include "alt_types.h" | |||||
#include "sys/alt_irq.h" | |||||
#include "priv/alt_iic_isr_register.h" | |||||
/* | |||||
* The header, alt_irq_entry.h, contains the exception entry point, and is | |||||
* provided by the processor component. It is included here, so that the code | |||||
* will be added to the executable only if alt_irq_register() is present, i.e. | |||||
* if no interrupts are registered - there's no need to provide any | |||||
* interrupt handling. | |||||
*/ | |||||
#include "sys/alt_irq_entry.h" | |||||
/* | |||||
* The header, alt_irq_table.h contains a table describing which function | |||||
* handles each interrupt. | |||||
*/ | |||||
#include "priv/alt_irq_table.h" | |||||
/** @Function Description: This function registers an interrupt handler. | |||||
* If the function is succesful, then the requested interrupt will be enabled | |||||
* upon return. Registering a NULL handler will disable the interrupt. | |||||
* | |||||
* @API Type: External | |||||
* @param ic_id Interrupt controller ID | |||||
* @param irq IRQ ID number | |||||
* @param isr Pointer to interrupt service routine | |||||
* @param isr_context Opaque pointer passed to ISR | |||||
* @param flags | |||||
* @return 0 if successful, else error (-1) | |||||
*/ | |||||
int alt_iic_isr_register(alt_u32 ic_id, alt_u32 irq, alt_isr_func isr, | |||||
void *isr_context, void *flags) | |||||
{ | |||||
int rc = -EINVAL; | |||||
int id = irq; /* IRQ interpreted as the interrupt ID. */ | |||||
alt_irq_context status; | |||||
if (id < ALT_NIRQ) | |||||
{ | |||||
/* | |||||
* interrupts are disabled while the handler tables are updated to ensure | |||||
* that an interrupt doesn't occur while the tables are in an inconsistant | |||||
* state. | |||||
*/ | |||||
status = alt_irq_disable_all(); | |||||
alt_irq[id].handler = isr; | |||||
alt_irq[id].context = isr_context; | |||||
rc = (isr) ? alt_ic_irq_enable(ic_id, id) : alt_ic_irq_disable(ic_id, id); | |||||
alt_irq_enable_all(status); | |||||
} | |||||
return rc; | |||||
} | |||||
#endif /* ALT_ENHANCED_INTERRUPT_API_PRESENT */ | |||||
#endif /* ALT_CPU_EIC_PRESENT */ |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "sys/alt_exceptions.h" | |||||
#include "nios2.h" | |||||
#include "alt_types.h" | |||||
#include "system.h" | |||||
/* | |||||
* This file implements support for calling user-registered handlers for | |||||
* instruction-generated exceptions. This handler could also be reached | |||||
* in the event of a spurious interrupt. | |||||
* | |||||
* The handler code is optionally enabled through the "Enable | |||||
* Instruction-related Exception API" HAL BSP setting, which will | |||||
* define the macro below. | |||||
*/ | |||||
#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API | |||||
/* Function pointer to exception callback routine */ | |||||
alt_exception_result (*alt_instruction_exception_handler) | |||||
(alt_exception_cause, alt_u32, alt_u32) = 0x0; | |||||
/* Link entry routine to .exceptions section */ | |||||
int alt_instruction_exception_entry (alt_u32 exception_pc) | |||||
__attribute__ ((section (".exceptions"))); | |||||
/* | |||||
* This is the entry point for instruction-generated exceptions handling. | |||||
* This routine will be called by alt_exceptions_entry.S, after it determines | |||||
* that an exception could not be handled by handlers that preceed that | |||||
* of instruction-generated exceptions (such as interrupts). | |||||
* | |||||
* For this to function properly, you must register an exception handler | |||||
* using alt_instruction_exception_register(). This routine will call | |||||
* that handler if it has been registered. Absent a handler, it will | |||||
* break break or hang as discussed below. | |||||
*/ | |||||
int | |||||
alt_instruction_exception_entry (alt_u32 exception_pc) | |||||
{ | |||||
alt_u32 cause, badaddr; | |||||
/* | |||||
* If the processor hardware has the optional EXCEPTIONS & BADADDR registers, | |||||
* read them and pass their content to the user handler. These are always | |||||
* present if the MMU or MPU is enabled, and optionally for other advanced | |||||
* exception types via the "Extra exceptions information" setting in the | |||||
* processor (hardware) configuration. | |||||
* | |||||
* If these registers are not present, the cause field will be set to | |||||
* NIOS2_EXCEPTION_CAUSE_NOT_PRESENT. Your handling routine should | |||||
* check the validity of the cause argument before proceeding. | |||||
*/ | |||||
#ifdef NIOS2_HAS_EXTRA_EXCEPTION_INFO | |||||
/* Get exception cause & "badaddr" */ | |||||
NIOS2_READ_EXCEPTION(cause); | |||||
cause = ( (cause & NIOS2_EXCEPTION_REG_CAUSE_MASK) >> | |||||
NIOS2_EXCEPTION_REG_CAUSE_OFST ); | |||||
NIOS2_READ_BADADDR(badaddr); | |||||
#else | |||||
cause = NIOS2_EXCEPTION_CAUSE_NOT_PRESENT; | |||||
badaddr = 0; | |||||
#endif /* NIOS2_HAS_EXTRA_EXCEPTION_INFO */ | |||||
if(alt_instruction_exception_handler) { | |||||
/* | |||||
* Call handler. Its return value indicates whether the exception-causing | |||||
* instruction should be re-issued. The code that called us, | |||||
* alt_eceptions_entry.S, will look at this value and adjust the ea | |||||
* register as necessary | |||||
*/ | |||||
return alt_instruction_exception_handler(cause, exception_pc, badaddr); | |||||
} | |||||
/* | |||||
* We got here because an instruction-generated exception occured, but no | |||||
* handler is present. We do not presume to know how to handle it. If the | |||||
* debugger is present, break, otherwise hang. | |||||
* | |||||
* If you've reached here in the debugger, consider examining the | |||||
* EXCEPTIONS register cause bit-field, which was read into the 'cause' | |||||
* variable above, and compare it against the exceptions-type enumeration | |||||
* in alt_exceptions.h. This register is availabe if the MMU or MPU is | |||||
* present, or if the "Extra exceptions information" hardware option is | |||||
* selected. | |||||
* | |||||
* If you get here then one of the following could have happened: | |||||
* | |||||
* - An instruction-generated exception occured, and the processor | |||||
* does not have the extra exceptions feature enabled, or you | |||||
* have not registered a handler using | |||||
* alt_instruction_exception_register() | |||||
* | |||||
* Some examples of instruction-generated exceptions and why they | |||||
* might occur: | |||||
* | |||||
* - Your program could have been compiled for a full-featured | |||||
* Nios II core, but it is running on a smaller core, and | |||||
* instruction emulation has been disabled by defining | |||||
* ALT_NO_INSTRUCTION_EMULATION. | |||||
* | |||||
* You can work around the problem by re-enabling instruction | |||||
* emulation, or you can figure out why your program is being | |||||
* compiled for a system other than the one that it is running on. | |||||
* | |||||
* - Your program has executed a trap instruction, but has not | |||||
* implemented a handler for this instruction. | |||||
* | |||||
* - Your program has executed an illegal instruction (one which is | |||||
* not defined in the instruction set). | |||||
* | |||||
* - Your processor includes an MMU or MPU, and you have enabled it | |||||
* before registering an exception handler to service exceptions it | |||||
* generates. | |||||
* | |||||
* The problem could also be hardware related: | |||||
* - If your hardware is broken and is generating spurious interrupts | |||||
* (a peripheral which negates its interrupt output before its | |||||
* interrupt handler has been executed will cause spurious interrupts) | |||||
*/ | |||||
else { | |||||
#ifdef NIOS2_HAS_DEBUG_STUB | |||||
NIOS2_BREAK(); | |||||
#else | |||||
while(1) | |||||
; | |||||
#endif /* NIOS2_HAS_DEBUG_STUB */ | |||||
} | |||||
/* We should not get here. Remove compiler warning. */ | |||||
return NIOS2_EXCEPTION_RETURN_REISSUE_INST; | |||||
} | |||||
#endif /* ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API */ | |||||
/* | |||||
* This routine indicates whether a particular exception cause will have | |||||
* set a valid address into the BADADDR register, which is included | |||||
* in the arguments to a user-registered instruction-generated exception | |||||
* handler. Many exception types do not set valid contents in BADADDR; | |||||
* this is a convenience routine to easily test the validity of that | |||||
* argument in your handler. | |||||
* | |||||
* Note that this routine will return false (0) for causes | |||||
* NIOS2_EXCEPTION_TLB_MISS and NIOS2_EXCEPTION_ECC_TLB_ERR. | |||||
* You must read the TLBMISC.D field to determine if BADADDR | |||||
* is valid for these (valid if TLBMISC.D = 1). | |||||
* | |||||
* Arguments: | |||||
* cause: The 5-bit exception cause field of the EXCEPTIONS register, | |||||
* shifted to the LSB position. You may pass the 'cause' argument | |||||
* in a handler you registered directy to this routine. | |||||
* | |||||
* Return: 1: BADADDR (bad_addr argument to handler) is valid | |||||
* 0: BADADDR is not valid | |||||
*/ | |||||
int | |||||
alt_exception_cause_generated_bad_addr(alt_exception_cause cause) | |||||
{ | |||||
switch (cause) { | |||||
case NIOS2_EXCEPTION_SUPERVISOR_ONLY_DATA_ADDR: | |||||
case NIOS2_EXCEPTION_MISALIGNED_DATA_ADDR: | |||||
case NIOS2_EXCEPTION_MISALIGNED_TARGET_PC: | |||||
case NIOS2_EXCEPTION_TLB_READ_PERM_VIOLATION: | |||||
case NIOS2_EXCEPTION_TLB_WRITE_PERM_VIOLATION: | |||||
case NIOS2_EXCEPTION_MPU_DATA_REGION_VIOLATION: | |||||
case NIOS2_EXCEPTION_ECC_DATA_ERR: | |||||
return 1; | |||||
case NIOS2_EXCEPTION_TLB_MISS: | |||||
case NIOS2_EXCEPTION_ECC_TLB_ERR: | |||||
return 0; | |||||
default: | |||||
return 0; | |||||
} | |||||
} |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 "sys/alt_exceptions.h" | |||||
#include "alt_types.h" | |||||
#include "system.h" | |||||
/* | |||||
* This file implements support for calling user-registered handlers for | |||||
* instruction-generated exceptions. | |||||
* | |||||
* The registry API is optionally enabled through the "Enable | |||||
* Instruction-related Exception API" HAL BSP setting, which will | |||||
* define the macro below. | |||||
*/ | |||||
#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API | |||||
/* | |||||
* The header, alt_exception_handler_registry.h contains a struct describing | |||||
* the registered exception handler | |||||
*/ | |||||
#include "priv/alt_exception_handler_registry.h" | |||||
/* | |||||
* Pull in the exception entry assembly code. This will not be linked in | |||||
* unless this object is linked into the executable (i.e. only if | |||||
* alt_instruction_exception_register() is called). | |||||
*/ | |||||
__asm__( "\n\t.globl alt_exception" ); | |||||
/* | |||||
* alt_instruction_exception_register() is called to register a handler to | |||||
* service instruction-generated exceptions that are not handled by the | |||||
* default exception handler code (interrupts, and optionally unimplemented | |||||
* instructions and traps). | |||||
* | |||||
* Passing null (0x0) in the handler argument will disable a previously- | |||||
* registered handler. | |||||
* | |||||
* Note that if no handler is registered, exceptions that are not processed | |||||
* using the built-in handler (interrupts, and optionally unimplemented | |||||
* instructions and traps) are treated as unknown exceptions, resulting | |||||
* in either a break or an infinite loop. | |||||
*/ | |||||
void alt_instruction_exception_register ( | |||||
alt_exception_result (*exception_handler)( | |||||
alt_exception_cause cause, | |||||
alt_u32 exception_pc, | |||||
alt_u32 bad_addr) ) | |||||
{ | |||||
alt_instruction_exception_handler = exception_handler; | |||||
} | |||||
#endif /* ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API */ |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <stddef.h> | |||||
#include <stdio.h> | |||||
#include <unistd.h> | |||||
#include <fcntl.h> | |||||
#include "sys/alt_dev.h" | |||||
#include "priv/alt_file.h" | |||||
/* | |||||
* alt_open_fd() is similar to open() in that it is used to obtain a file | |||||
* descriptor for the file named "name". The "flags" and "mode" arguments are | |||||
* identical to the "flags" and "mode" arguments of open(). | |||||
* | |||||
* The distinction between the two functions is that the file descriptor | |||||
* structure to use is passed in as an argument, rather than allocated from the | |||||
* list of free file descriptors. | |||||
* | |||||
* This is used by alt_io_redirect() to redirect the stdin, stdout and stderr | |||||
* file descriptors to point to new devices. | |||||
* | |||||
* If the device can not be succesfully opened, then the input file descriptor | |||||
* remains unchanged. | |||||
*/ | |||||
static void alt_open_fd(alt_fd* fd, const char* name, int flags, int mode) | |||||
{ | |||||
int old; | |||||
old = open (name, flags, mode); | |||||
if (old >= 0) | |||||
{ | |||||
fd->dev = alt_fd_list[old].dev; | |||||
fd->priv = alt_fd_list[old].priv; | |||||
fd->fd_flags = alt_fd_list[old].fd_flags; | |||||
alt_release_fd (old); | |||||
} | |||||
} | |||||
/* | |||||
* alt_io_redirect() is called once the device/filesystem lists have been | |||||
* initialised, but before main(). Its function is to redirect standard in, | |||||
* standard out and standard error so that they point to the devices selected by | |||||
* the user (as defined in system.h). | |||||
* | |||||
* Prior to the call to this function, io is directed towards /dev/null. If | |||||
* i/o can not be redirected to the requested device, for example if the device | |||||
* does not exist, then it remains directed at /dev/null. | |||||
*/ | |||||
void alt_io_redirect(const char* stdout_dev, | |||||
const char* stdin_dev, | |||||
const char* stderr_dev) | |||||
{ | |||||
/* Redirect the channels */ | |||||
alt_open_fd (&alt_fd_list[STDOUT_FILENO], stdout_dev, O_WRONLY, 0777); | |||||
alt_open_fd (&alt_fd_list[STDIN_FILENO], stdin_dev, O_RDONLY, 0777); | |||||
alt_open_fd (&alt_fd_list[STDERR_FILENO], stderr_dev, O_WRONLY, 0777); | |||||
} | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* Altera does not recommend, suggest or require that this reference design * | |||||
* file be used in conjunction or combination with any other product. * | |||||
******************************************************************************/ | |||||
#include <stddef.h> | |||||
#include "sys/ioctl.h" | |||||
#include "sys/alt_errno.h" | |||||
#include "sys/alt_warning.h" | |||||
#include "priv/alt_file.h" | |||||
#include "os/alt_syscall.h" | |||||
/* | |||||
* The ioctl() system call is provided so that application code can manipulate | |||||
* the i/o capabilities of a device in device specific ways. This is identical | |||||
* to the standard posix ioctl() function. | |||||
* | |||||
* In general this implementation simply vectors ioctl requests to the | |||||
* apropriate drivers ioctl function (as registered in the drivers alt_dev | |||||
* structure). | |||||
* | |||||
* However in the case of devices (as oposed to filesystem), the TIOCEXCL and | |||||
* TIOCNXCL requests are handled without reference to the driver. These | |||||
* requests are used to lock/release a device for exclusive access. | |||||
* | |||||
* Handling these requests centrally eases the task of device driver | |||||
* development. | |||||
* | |||||
* ALT_IOCTL is mapped onto the ioctl() system call in alt_syscall.h | |||||
*/ | |||||
#ifdef ALT_USE_DIRECT_DRIVERS | |||||
#include "system.h" | |||||
#include "sys/alt_driver.h" | |||||
/* | |||||
* Provide minimal version that calls ioctl routine of provided stdio devices. | |||||
*/ | |||||
int ALT_IOCTL (int file, int req, void* arg) | |||||
{ | |||||
#ifdef ALT_STDIN_PRESENT | |||||
ALT_DRIVER_IOCTL_EXTERNS(ALT_STDIN_DEV); | |||||
#endif | |||||
#ifdef ALT_STDOUT_PRESENT | |||||
ALT_DRIVER_IOCTL_EXTERNS(ALT_STDOUT_DEV); | |||||
#endif | |||||
#ifdef ALT_STDERR_PRESENT | |||||
ALT_DRIVER_IOCTL_EXTERNS(ALT_STDERR_DEV); | |||||
#endif | |||||
#if !defined(ALT_STDIN_PRESENT) && !defined(ALT_STDOUT_PRESENT) && !defined(ALT_STDERR_PRESENT) | |||||
/* Generate a link time warning, should this function ever be called. */ | |||||
ALT_STUB_WARNING(ioctl); | |||||
#endif | |||||
switch (file) { | |||||
#ifdef ALT_STDIN_PRESENT | |||||
case 0: /* stdin file descriptor */ | |||||
return ALT_DRIVER_IOCTL(ALT_STDIN_DEV, req, arg); | |||||
#endif /* ALT_STDIN_PRESENT */ | |||||
#ifdef ALT_STDOUT_PRESENT | |||||
case 1: /* stdout file descriptor */ | |||||
return ALT_DRIVER_IOCTL(ALT_STDOUT_DEV, req, arg); | |||||
#endif /* ALT_STDOUT_PRESENT */ | |||||
#ifdef ALT_STDERR_PRESENT | |||||
case 2: /* stderr file descriptor */ | |||||
return ALT_DRIVER_IOCTL(ALT_STDERR_DEV, req, arg); | |||||
#endif /* ALT_STDERR_PRESENT */ | |||||
default: | |||||
ALT_ERRNO = EBADFD; | |||||
return -1; | |||||
} | |||||
} | |||||
#else /* !ALT_USE_DIRECT_DRIVERS */ | |||||
int ALT_IOCTL (int file, int req, void* arg) | |||||
{ | |||||
alt_fd* fd; | |||||
int rc; | |||||
/* | |||||
* A common error case is that when the file descriptor was created, the call | |||||
* to open() failed resulting in a negative file descriptor. This is trapped | |||||
* below so that we don't try and process an invalid file descriptor. | |||||
*/ | |||||
fd = (file < 0) ? NULL : &alt_fd_list[file]; | |||||
if (fd) | |||||
{ | |||||
/* | |||||
* In the case of device drivers (not file systems) handle the TIOCEXCL | |||||
* and TIOCNXCL requests as special cases. | |||||
*/ | |||||
if (fd->fd_flags & ALT_FD_DEV) | |||||
{ | |||||
if (req == TIOCEXCL) | |||||
{ | |||||
rc = alt_fd_lock (fd); | |||||
goto ioctl_done; | |||||
} | |||||
else if (req == TIOCNXCL) | |||||
{ | |||||
rc = alt_fd_unlock (fd); | |||||
goto ioctl_done; | |||||
} | |||||
} | |||||
/* | |||||
* If the driver provides an ioctl() function, call that to handle the | |||||
* request, otherwise set the return code to indicate that the request | |||||
* could not be processed. | |||||
*/ | |||||
if (fd->dev->ioctl) | |||||
{ | |||||
rc = fd->dev->ioctl(fd, req, arg); | |||||
} | |||||
else | |||||
{ | |||||
rc = -ENOTTY; | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
rc = -EBADFD; | |||||
} | |||||
ioctl_done: | |||||
if (rc < 0) | |||||
{ | |||||
ALT_ERRNO = -rc; | |||||
} | |||||
return rc; | |||||
} | |||||
#endif /* ALT_USE_DIRECT_DRIVERS */ |
/****************************************************************************** | |||||
* * | |||||
* License Agreement * | |||||
* * | |||||
* Copyright (c) 2003-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. * | |||||
* * | |||||
* 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 "system.h" | |||||
/* | |||||
* This is the interrupt exception entry point code, which saves all the | |||||
* registers and calls the interrupt handler. It should be pulled in using | |||||
* a .globl from alt_irq_register.c. This scheme is used so that if an | |||||
* interrupt is never registered, then this code will not appear in the | |||||
* generated executable, thereby improving code footprint. | |||||
*/ | |||||
/* | |||||
* Explicitly allow the use of r1 (the assembler temporary register) | |||||
* within this code. This register is normally reserved for the use of | |||||
* the compiler. | |||||
*/ | |||||
.set noat | |||||
/* | |||||
* Pull in the exception handler register save code. | |||||
*/ | |||||
.globl alt_exception | |||||
.globl alt_irq_entry | |||||
.section .exceptions.entry.label, "xa" | |||||
alt_irq_entry: | |||||
/* | |||||
* Section .exceptions.entry is in alt_exception_entry.S | |||||
* This saves all the caller saved registers and reads estatus into r5 | |||||
*/ | |||||
.section .exceptions.irqtest, "xa" | |||||
#ifdef ALT_CI_INTERRUPT_VECTOR_N | |||||
/* | |||||
* Use the interrupt vector custom instruction if present to accelerate | |||||
* this code. | |||||
* If the interrupt vector custom instruction returns a negative | |||||
* value, there are no interrupts active (estatus.pie is 0 | |||||
* or ipending is 0) so assume it is a software exception. | |||||
*/ | |||||
custom ALT_CI_INTERRUPT_VECTOR_N, r4, r0, r0 | |||||
blt r4, r0, .Lnot_irq | |||||
#else | |||||
/* | |||||
* Test to see if the exception was a software exception or caused | |||||
* by an external interrupt, and vector accordingly. | |||||
*/ | |||||
rdctl r4, ipending | |||||
andi r2, r5, 1 | |||||
beq r2, zero, .Lnot_irq | |||||
beq r4, zero, .Lnot_irq | |||||
#endif /* ALT_CI_INTERRUPT_VECTOR_N */ | |||||
.section .exceptions.irqhandler, "xa" | |||||
/* | |||||
* Now that all necessary registers have been preserved, call | |||||
* alt_irq_handler() to process the interrupts. | |||||
*/ | |||||
call alt_irq_handler | |||||
.section .exceptions.irqreturn, "xa" | |||||
br .Lexception_exit | |||||
.section .exceptions.notirq.label, "xa" | |||||
.Lnot_irq: | |||||
/* | |||||
* Section .exceptions.exit is in alt_exception_entry.S | |||||
* This restores all the caller saved registers | |||||
*/ | |||||
.section .exceptions.exit.label | |||||
.Lexception_exit: | |||||
/****************************************************************************** | |||||
* * | |||||
* 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 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 <errno.h> | |||||
#include "system.h" | |||||
/* | |||||
* This interrupt handler only works with an internal interrupt controller | |||||
* (IIC). Processors with an external interrupt controller (EIC) use an | |||||
* implementation provided by an EIC driver. | |||||
*/ | |||||
#ifndef ALT_CPU_EIC_PRESENT | |||||
#include "sys/alt_irq.h" | |||||
#include "os/alt_hooks.h" | |||||
#include "alt_types.h" | |||||
/* | |||||
* 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. | |||||
*/ | |||||
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]; | |||||
/* | |||||
* alt_irq_handler() is called by the interrupt exception handler in order to | |||||
* process any outstanding interrupts. | |||||
* | |||||
* It is defined here since it is linked in using weak linkage. | |||||
* This means that if there is never a call to alt_irq_register() (above) then | |||||
* this function will not get linked in to the executable. This is acceptable | |||||
* since if no handler is ever registered, then an interrupt can never occur. | |||||
* | |||||
* If Nios II interrupt vector custom instruction exists, use it to accelerate | |||||
* the dispatch of interrupt handlers. The Nios II interrupt vector custom | |||||
* instruction is present if the macro ALT_CI_INTERRUPT_VECTOR defined. | |||||
*/ | |||||
void alt_irq_handler (void) __attribute__ ((section (".exceptions"))); | |||||
void alt_irq_handler (void) | |||||
{ | |||||
#ifdef ALT_CI_INTERRUPT_VECTOR | |||||
alt_32 offset; | |||||
char* alt_irq_base = (char*)alt_irq; | |||||
#else | |||||
alt_u32 active; | |||||
alt_u32 mask; | |||||
alt_u32 i; | |||||
#endif /* ALT_CI_INTERRUPT_VECTOR */ | |||||
/* | |||||
* Notify the operating system that we are at interrupt level. | |||||
*/ | |||||
ALT_OS_INT_ENTER(); | |||||
#ifdef ALT_CI_INTERRUPT_VECTOR | |||||
/* | |||||
* Call the interrupt vector custom instruction using the | |||||
* ALT_CI_INTERRUPT_VECTOR macro. | |||||
* It returns the offset into the vector table of the lowest-valued pending | |||||
* interrupt (corresponds to highest priority) or a negative value if none. | |||||
* The custom instruction assumes that each table entry is eight bytes. | |||||
*/ | |||||
while ((offset = ALT_CI_INTERRUPT_VECTOR) >= 0) { | |||||
struct ALT_IRQ_HANDLER* handler_entry = | |||||
(struct ALT_IRQ_HANDLER*)(alt_irq_base + offset); | |||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT | |||||
handler_entry->handler(handler_entry->context); | |||||
#else | |||||
handler_entry->handler(handler_entry->context, offset >> 3); | |||||
#endif | |||||
} | |||||
#else /* ALT_CI_INTERRUPT_VECTOR */ | |||||
/* | |||||
* Obtain from the interrupt controller a bit list of pending interrupts, | |||||
* and then process the highest priority interrupt. This process loops, | |||||
* loading the active interrupt list on each pass until alt_irq_pending() | |||||
* return zero. | |||||
* | |||||
* The maximum interrupt latency for the highest priority interrupt is | |||||
* reduced by finding out which interrupts are pending as late as possible. | |||||
* Consider the case where the high priority interupt is asserted during | |||||
* the interrupt entry sequence for a lower priority interrupt to see why | |||||
* this is the case. | |||||
*/ | |||||
active = alt_irq_pending (); | |||||
do | |||||
{ | |||||
i = 0; | |||||
mask = 1; | |||||
/* | |||||
* Test each bit in turn looking for an active interrupt. Once one is | |||||
* found, the interrupt handler asigned by a call to alt_irq_register() is | |||||
* called to clear the interrupt condition. | |||||
*/ | |||||
do | |||||
{ | |||||
if (active & mask) | |||||
{ | |||||
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT | |||||
alt_irq[i].handler(alt_irq[i].context); | |||||
#else | |||||
alt_irq[i].handler(alt_irq[i].context, i); | |||||
#endif | |||||
break; | |||||
} | |||||
mask <<= 1; | |||||
i++; | |||||
} while (1); | |||||
active = alt_irq_pending (); | |||||
} while (active); | |||||
#endif /* ALT_CI_INTERRUPT_VECTOR */ | |||||
/* | |||||
* Notify the operating system that interrupt processing is complete. | |||||
*/ | |||||
ALT_OS_INT_EXIT(); | |||||
} | |||||
#endif /* ALT_CPU_EIC_PRESENT */ |
/****************************************************************************** | |||||
* * | |||||
* 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 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 <errno.h> | |||||
#include "system.h" | |||||
/* | |||||
* This interrupt registry mechanism works with the Nios II internal interrupt | |||||
* controller (IIC) only. Systems with an external interrupt controller (EIC), | |||||
* or those with the IIC who are using the enhanced interrupt API will | |||||
* utilize the alt_ic_isr_register() routine to register an interrupt. | |||||
*/ | |||||
#ifndef NIOS2_EIC_PRESENT | |||||
#include "sys/alt_irq.h" | |||||
#include "priv/alt_legacy_irq.h" | |||||
#include "os/alt_hooks.h" | |||||
#include "alt_types.h" | |||||
/* | |||||
* The header, alt_irq_entry.h, contains the exception entry point, and is | |||||
* provided by the processor component. It is included here, so that the code | |||||
* will be added to the executable only if alt_irq_register() is present, i.e. | |||||
* if no interrupts are registered - there's no need to provide any | |||||
* interrupt handling. | |||||
*/ | |||||
#include "sys/alt_irq_entry.h" | |||||
/* | |||||
* The header, alt_irq_table.h contains a table describing which function | |||||
* handles each interrupt. | |||||
*/ | |||||
#include "priv/alt_irq_table.h" | |||||
/* | |||||
* alt_irq_handler() is called to register an interrupt handler. If the | |||||
* function is succesful, then the requested interrupt will be enabled upon | |||||
* return. Registering a NULL handler will disable the interrupt. | |||||
* | |||||
* The return value is 0 if the interrupt handler was registered and the | |||||
* interrupt was enabled, otherwise it is negative. | |||||
*/ | |||||
int alt_irq_register (alt_u32 id, | |||||
void* context, | |||||
alt_isr_func handler) | |||||
{ | |||||
int rc = -EINVAL; | |||||
alt_irq_context status; | |||||
if (id < ALT_NIRQ) | |||||
{ | |||||
/* | |||||
* interrupts are disabled while the handler tables are updated to ensure | |||||
* that an interrupt doesn't occur while the tables are in an inconsistant | |||||
* state. | |||||
*/ | |||||
status = alt_irq_disable_all (); | |||||
alt_irq[id].handler = handler; | |||||
alt_irq[id].context = context; | |||||
rc = (handler) ? alt_irq_enable (id): alt_irq_disable (id); | |||||
alt_irq_enable_all(status); | |||||
} | |||||
return rc; | |||||
} | |||||
#endif /* NIOS2_EIC_PRESENT */ | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
******************************************************************************/ | |||||
#include "alt_types.h" | |||||
#include "system.h" | |||||
/* | |||||
* These global variables are used to save the current list of enabled | |||||
* interrupts. See alt_irq.h for further details. | |||||
*/ | |||||
volatile alt_u32 alt_irq_active = 0; | |||||
#ifndef ALT_EXCEPTION_STACK | |||||
volatile alt_u32 alt_priority_mask = (alt_u32) -1; | |||||
#endif | |||||
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* Altera does not recommend, suggest or require that this reference design * | |||||
* file be used in conjunction or combination with any other product. * | |||||
******************************************************************************/ | |||||
#include <stddef.h> | |||||
#include <sys/stat.h> | |||||
#include "sys/alt_dev.h" | |||||
#include "sys/alt_errno.h" | |||||
#include "sys/alt_warning.h" | |||||
#include "priv/alt_file.h" | |||||
#include "os/alt_syscall.h" | |||||
#ifdef ALT_USE_DIRECT_DRIVERS | |||||
#include "system.h" | |||||
/* | |||||
* Provide minimal version that just describes all file descriptors | |||||
* as tty devices for provided stdio devices. | |||||
*/ | |||||
int ALT_ISATTY (int file) | |||||
{ | |||||
switch (file) { | |||||
#ifdef ALT_STDIN_PRESENT | |||||
case 0: /* stdin file descriptor */ | |||||
#endif /* ALT_STDIN_PRESENT */ | |||||
#ifdef ALT_STDOUT_PRESENT | |||||
case 1: /* stdout file descriptor */ | |||||
#endif /* ALT_STDOUT_PRESENT */ | |||||
#ifdef ALT_STDERR_PRESENT | |||||
case 2: /* stderr file descriptor */ | |||||
#endif /* ALT_STDERR_PRESENT */ | |||||
return 1; | |||||
default: | |||||
return 0; | |||||
} | |||||
#if !defined(ALT_STDIN_PRESENT) && !defined(ALT_STDOUT_PRESENT) && !defined(ALT_STDERR_PRESENT) | |||||
/* Generate a link time warning, should this function ever be called. */ | |||||
ALT_STUB_WARNING(isatty); | |||||
#endif | |||||
} | |||||
#else /* !ALT_USE_DIRECT_DRIVERS */ | |||||
/* | |||||
* isatty() can be used to determine whether the input file descriptor "file" | |||||
* refers to a terminal device or not. If it is a terminal device then the | |||||
* return value is one, otherwise it is zero. | |||||
* | |||||
* ALT_ISATTY is mapped onto the isatty() system call in alt_syscall.h | |||||
*/ | |||||
int ALT_ISATTY (int file) | |||||
{ | |||||
alt_fd* fd; | |||||
struct stat stat; | |||||
/* | |||||
* A common error case is that when the file descriptor was created, the call | |||||
* to open() failed resulting in a negative file descriptor. This is trapped | |||||
* below so that we don't try and process an invalid file descriptor. | |||||
*/ | |||||
fd = (file < 0) ? NULL : &alt_fd_list[file]; | |||||
if (fd) | |||||
{ | |||||
/* | |||||
* If a device driver does not provide an fstat() function, then it is | |||||
* treated as a terminal device by default. | |||||
*/ | |||||
if (!fd->dev->fstat) | |||||
{ | |||||
return 1; | |||||
} | |||||
/* | |||||
* If a driver does provide an implementation of the fstat() function, then | |||||
* this is called so that the device can identify itself. | |||||
*/ | |||||
else | |||||
{ | |||||
fstat (file, &stat); | |||||
return (stat.st_mode == _IFCHR) ? 1 : 0; | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
ALT_ERRNO = EBADFD; | |||||
return 0; | |||||
} | |||||
} | |||||
#endif /* ALT_USE_DIRECT_DRIVERS */ |
/****************************************************************************** | |||||
* * | |||||
* 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. * | |||||
* * | |||||
* 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 <signal.h> | |||||
#include <unistd.h> | |||||
#include "sys/alt_errno.h" | |||||
#include "os/alt_syscall.h" | |||||
/* | |||||
* kill() is used by newlib in order to send signals to processes. Since there | |||||
* is only a single process in the HAL, the only valid values for pid are | |||||
* either the current process id, or the broadcast values, i.e. pid must be | |||||
* less than or equal to zero. | |||||
* | |||||
* ALT_KILL is mapped onto the kill() system call in alt_syscall.h | |||||
*/ | |||||
int ALT_KILL (int pid, int sig) | |||||
{ | |||||
int status = 0; | |||||
if (pid <= 0) | |||||
{ | |||||
switch (sig) | |||||
{ | |||||
case 0: | |||||
/* The null signal is used to check that a pid is valid. */ | |||||
break; | |||||
case SIGABRT: | |||||
case SIGALRM: | |||||
case SIGFPE: | |||||
case SIGILL: | |||||
case SIGKILL: | |||||
case SIGPIPE: | |||||
case SIGQUIT: | |||||
case SIGSEGV: | |||||
case SIGTERM: | |||||
case SIGUSR1: | |||||
case SIGUSR2: | |||||
case SIGBUS: | |||||
case SIGPOLL: | |||||
case SIGPROF: | |||||
case SIGSYS: | |||||
case SIGTRAP: | |||||
case SIGVTALRM: | |||||
case SIGXCPU: | |||||
case SIGXFSZ: | |||||
/* | |||||
* The Posix standard defines the default behaviour for all these signals | |||||
* as being eqivalent to a call to _exit(). No mechanism is provided to | |||||
* change this behaviour. | |||||
*/ | |||||
_exit(0); | |||||
case SIGCHLD: | |||||
case SIGURG: | |||||
/* | |||||
* The Posix standard defines these signals to be ignored by default. No | |||||
* mechanism is provided to change this behaviour. | |||||
*/ | |||||
break; | |||||
default: | |||||
/* Tried to send an unsupported signal */ | |||||
status = EINVAL; | |||||
} | |||||
} | |||||
else if (pid > 0) | |||||
{ | |||||
/* Attempted to signal a non-existant process */ | |||||
status = ESRCH; | |||||
} | |||||
if (status) | |||||
{ | |||||
ALT_ERRNO = status; | |||||
return -1; | |||||
} | |||||
return 0; | |||||
} |