/
usb_xmem.h
67 lines (52 loc) · 2.31 KB
/
usb_xmem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Copyright (c) 2015 NewAE Technology Inc. All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USB_XMEM_H_
#define USB_XMEM_H_
#include <stdint.h>
typedef enum fpga_lockstatus_e {fpga_unlocked = 0, fpga_generic, fpga_blockin, fpga_streamin, fpga_blockout, fpga_ctrlmem, fpga_usblocked} fpga_lockstatus_t;
// Try to get the FPGA lock. Returns 1 if it's ours and 0 if we cannot proceed.
// lockstatus: the lock we're trying to apply
// interrupts_on: should interrupts be enabled
int FPGA_setlock(fpga_lockstatus_t lockstatus);
// Release the lock.
void FPGA_releaselock(void);
// Check the lock status. Useful in the USB stack
fpga_lockstatus_t FPGA_lockstatus(void);
// Useful functions for entering/exiting critical sections
int try_enter_cs(void);
void exit_cs(void);
// Read 4 bytes into a single uint32_t
uint32_t unsafe_readuint32(uint16_t fpgaaddr);
uint32_t safe_readuint32(uint16_t fpgaaddr);
// Read a number of bytes into a byte array
void unsafe_readbytes(uint16_t fpgaaddr, uint8_t* data, int numBytes);
void safe_readbytes(uint16_t fpgaaddr, uint8_t* data, int numBytes);
// Write a number of bytes to the FPGA
void unsafe_writebytes(uint16_t fpgaaddr, uint8_t* data, int numBytes);
void FPGA_setaddr(uint32_t addr);
void smc_fasttiming(void);
void smc_normaltiming(void);
/* Access pointer for FPGA Interface */
#define PSRAM_BASE_ADDRESS (0x60000000)
extern uint8_t volatile *xram;
extern uint16_t volatile *xram16;
typedef enum {
bep_emem=0,
bep_fpgabitstream=10,
bep_fpgabitstreamspi=20
} blockep_usage_t;
extern blockep_usage_t blockendpoint_usage;
//#define FPGA_ADDR_PINS (PIO_PB0 | PIO_PB1 | PIO_PB2 | PIO_PB3 | PIO_PB4 | PIO_PB5 | PIO_PB7 | PIO_PB8 )
//#define FPGA_ADDR_PORT PIOB
#endif /* USB_XMEM_H_ */