Skip to content
This repository was archived by the owner on Dec 24, 2024. It is now read-only.

Commit 4026526

Browse files
committed
eda: introduce Cgo-based EDA driver
1 parent f5c1e73 commit 4026526

File tree

12 files changed

+3201
-0
lines changed

12 files changed

+3201
-0
lines changed

eda/alt_types.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef __ALT_TYPES_H__
2+
#define __ALT_TYPES_H__
3+
4+
/******************************************************************************
5+
* *
6+
* License Agreement *
7+
* *
8+
* Copyright (c) 2009 Altera Corporation, San Jose, California, USA. *
9+
* All rights reserved. *
10+
* *
11+
* Permission is hereby granted, free of charge, to any person obtaining a *
12+
* copy of this software and associated documentation files (the "Software"), *
13+
* to deal in the Software without restriction, including without limitation *
14+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
15+
* and/or sell copies of the Software, and to permit persons to whom the *
16+
* Software is furnished to do so, subject to the following conditions: *
17+
* *
18+
* The above copyright notice and this permission notice shall be included in *
19+
* all copies or substantial portions of the Software. *
20+
* *
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
22+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
23+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
24+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
25+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
26+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
27+
* DEALINGS IN THE SOFTWARE. *
28+
* *
29+
* This agreement shall be governed in all respects by the laws of the State *
30+
* of California and by the laws of the United States of America. *
31+
* *
32+
* Altera does not recommend, suggest or require that this reference design *
33+
* file be used in conjunction or combination with any other product. *
34+
******************************************************************************/
35+
36+
/*
37+
* Don't declare these typedefs if this file is included by assembly source.
38+
*/
39+
#ifndef ALT_ASM_SRC
40+
typedef signed char alt_8;
41+
typedef unsigned char alt_u8;
42+
typedef signed short alt_16;
43+
typedef unsigned short alt_u16;
44+
typedef signed long alt_32;
45+
typedef unsigned long alt_u32;
46+
typedef long long alt_64;
47+
typedef unsigned long long alt_u64;
48+
#endif
49+
50+
#define ALT_INLINE __inline__
51+
#define ALT_ALWAYS_INLINE __attribute__((always_inline))
52+
#define ALT_WEAK __attribute__((weak))
53+
54+
#endif /* __ALT_TYPES_H__ */

eda/altera_avalon_fifo_regs.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/******************************************************************************
2+
* *
3+
* License Agreement *
4+
* *
5+
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA. *
6+
* All rights reserved. *
7+
* *
8+
* Permission is hereby granted, free of charge, to any person obtaining a *
9+
* copy of this software and associated documentation files (the "Software"), *
10+
* to deal in the Software without restriction, including without limitation *
11+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
12+
* and/or sell copies of the Software, and to permit persons to whom the *
13+
* Software is furnished to do so, subject to the following conditions: *
14+
* *
15+
* The above copyright notice and this permission notice shall be included in *
16+
* all copies or substantial portions of the Software. *
17+
* *
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
23+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
24+
* DEALINGS IN THE SOFTWARE. *
25+
* *
26+
* This agreement shall be governed in all respects by the laws of the State *
27+
* of California and by the laws of the United States of America. *
28+
* *
29+
******************************************************************************/
30+
31+
#ifndef __ALTERA_AVALON_FIFO_REGS_H__
32+
#define __ALTERA_AVALON_FIFO_REGS_H__
33+
34+
#include <io.h>
35+
36+
#define ALTERA_AVALON_FIFO_OTHER_INFO_REG 1
37+
#define ALTERA_AVALON_FIFO_DATA_REG 0
38+
39+
#define ALTERA_AVALON_FIFO_LEVEL_REG 0
40+
#define ALTERA_AVALON_FIFO_STATUS_REG 1
41+
#define ALTERA_AVALON_FIFO_EVENT_REG 2
42+
#define ALTERA_AVALON_FIFO_IENABLE_REG 3
43+
#define ALTERA_AVALON_FIFO_ALMOSTFULL_REG 4
44+
#define ALTERA_AVALON_FIFO_ALMOSTEMPTY_REG 5
45+
46+
// Read slave
47+
#define IORD_ALTERA_AVALON_FIFO_DATA(base) \
48+
IORD(base, ALTERA_AVALON_FIFO_DATA_REG)
49+
50+
#define IORD_ALTERA_AVALON_FIFO_OTHER_INFO(base) \
51+
IORD(base, ALTERA_AVALON_FIFO_OTHER_INFO_REG)
52+
53+
// Write slave
54+
#define IOWR_ALTERA_AVALON_FIFO_DATA(base, data) \
55+
IOWR(base, ALTERA_AVALON_FIFO_DATA_REG, data)
56+
57+
#define IOWR_ALTERA_AVALON_FIFO_OTHER_INFO(base, data) \
58+
IOWR(base, ALTERA_AVALON_FIFO_OTHER_INFO_REG, data)
59+
60+
// Control slave
61+
#define IORD_ALTERA_AVALON_FIFO_LEVEL(base) \
62+
IORD(base, ALTERA_AVALON_FIFO_LEVEL_REG)
63+
64+
#define IORD_ALTERA_AVALON_FIFO_STATUS(base) \
65+
IORD(base, ALTERA_AVALON_FIFO_STATUS_REG)
66+
67+
#define IORD_ALTERA_AVALON_FIFO_EVENT(base) \
68+
IORD(base, ALTERA_AVALON_FIFO_EVENT_REG)
69+
70+
#define IORD_ALTERA_AVALON_FIFO_IENABLE(base) \
71+
IORD(base, ALTERA_AVALON_FIFO_IENABLE_REG)
72+
73+
#define IORD_ALTERA_AVALON_FIFO_ALMOSTFULL(base) \
74+
IORD(base, ALTERA_AVALON_FIFO_ALMOSTFULL_REG)
75+
76+
#define IORD_ALTERA_AVALON_FIFO_ALMOSTEMPTY(base) \
77+
IORD(base, ALTERA_AVALON_FIFO_ALMOSTEMPTY_REG)
78+
79+
#define IOWR_ALTERA_AVALON_FIFO_EVENT(base, data) \
80+
IOWR(base, ALTERA_AVALON_FIFO_EVENT_REG, data)
81+
82+
#define IOWR_ALTERA_AVALON_FIFO_IENABLE(base, data) \
83+
IOWR(base, ALTERA_AVALON_FIFO_IENABLE_REG, data)
84+
85+
#define IOWR_ALTERA_AVALON_FIFO_ALMOSTFULL(base, data) \
86+
IOWR(base, ALTERA_AVALON_FIFO_ALMOSTFULL_REG, data)
87+
88+
#define IOWR_ALTERA_AVALON_FIFO_ALMOSTEMPTY(base, data) \
89+
IOWR(base, ALTERA_AVALON_FIFO_ALMOSTEMPTY_REG, data)
90+
91+
#define ALTERA_AVALON_FIFO_EVENT_F_MSK (0x01)
92+
#define ALTERA_AVALON_FIFO_EVENT_E_MSK (0x02)
93+
#define ALTERA_AVALON_FIFO_EVENT_AF_MSK (0x04)
94+
#define ALTERA_AVALON_FIFO_EVENT_AE_MSK (0x08)
95+
#define ALTERA_AVALON_FIFO_EVENT_OVF_MSK (0x10)
96+
#define ALTERA_AVALON_FIFO_EVENT_UDF_MSK (0x20)
97+
#define ALTERA_AVALON_FIFO_EVENT_ALL (0x3F)
98+
99+
#define ALTERA_AVALON_FIFO_STATUS_F_MSK (0x01)
100+
#define ALTERA_AVALON_FIFO_STATUS_E_MSK (0x02)
101+
#define ALTERA_AVALON_FIFO_STATUS_AF_MSK (0x04)
102+
#define ALTERA_AVALON_FIFO_STATUS_AE_MSK (0x08)
103+
#define ALTERA_AVALON_FIFO_STATUS_OVF_MSK (0x10)
104+
#define ALTERA_AVALON_FIFO_STATUS_UDF_MSK (0x20)
105+
#define ALTERA_AVALON_FIFO_STATUS_ALL (0x3F)
106+
107+
#define ALTERA_AVALON_FIFO_IENABLE_F_MSK (0x01)
108+
#define ALTERA_AVALON_FIFO_IENABLE_E_MSK (0x02)
109+
#define ALTERA_AVALON_FIFO_IENABLE_AF_MSK (0x04)
110+
#define ALTERA_AVALON_FIFO_IENABLE_AE_MSK (0x08)
111+
#define ALTERA_AVALON_FIFO_IENABLE_OVF_MSK (0x10)
112+
#define ALTERA_AVALON_FIFO_IENABLE_UDF_MSK (0x20)
113+
#define ALTERA_AVALON_FIFO_IENABLE_ALL (0x3F)
114+
115+
#endif /* __ALTERA_AVALON_FIFO_REGS_H__ */

eda/c_device.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2021 The go-lpc Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package eda
6+
7+
/** TO DO LIST
8+
*
9+
* change HR_id numbering (1 to 8 instead of 0 to 7) (+ processing script)
10+
* change trigger_id numbering (start 1) (+ processing script)
11+
*
12+
*/
13+
14+
//#cgo CFLAGS: -g -Wall -std=c99 -D_GNU_SOURCE=1 -I/build/soc_eds/ip/altera/hps/altera_hps/hwlib/include -I.
15+
//#cgo LDFLAGS arm: -pthread -static
16+
//
17+
//#include <stdlib.h>
18+
//#include <string.h>
19+
//#include <stdint.h>
20+
//#include "device.h"
21+
import "C"
22+
23+
import (
24+
"fmt"
25+
26+
"github.com/go-lpc/mim/conddb"
27+
)
28+
29+
type cdevice struct {
30+
ctx *C.Device_t
31+
}
32+
33+
var _ device = (*cdevice)(nil)
34+
35+
func newCDevice(devmem, odir, devshm, cfgdir string, opts ...Option) (*cdevice, error) {
36+
ctx := C.new_device()
37+
if ctx == nil {
38+
return nil, fmt.Errorf("ceda: could not create EDA device")
39+
}
40+
41+
return &cdevice{ctx}, nil
42+
}
43+
44+
func (dev *cdevice) Close() error {
45+
if dev.ctx == nil {
46+
return nil
47+
}
48+
C.device_free(dev.ctx)
49+
dev.ctx = nil
50+
return nil
51+
}
52+
53+
func (dev *cdevice) Boot(cfg []BootConfig) error {
54+
panic("not implemented")
55+
}
56+
57+
func (dev *cdevice) ConfigureDIF(addr string, dif uint8, asics []conddb.ASIC) error {
58+
panic("not implemented")
59+
}
60+
61+
func (dev *cdevice) Initialize() error {
62+
rc := C.device_initialize(dev.ctx)
63+
if rc != 0 {
64+
return fmt.Errorf("ceda: could not initialize EDA device rc=%d", rc)
65+
}
66+
return nil
67+
}
68+
69+
func (dev *cdevice) Start(run uint32) error {
70+
rc := C.device_start(dev.ctx, C.uint32_t(run))
71+
if rc != 0 {
72+
return fmt.Errorf("ceda: could not start EDA device: rc=%d", rc)
73+
}
74+
return nil
75+
}
76+
77+
func (dev *cdevice) Stop() error {
78+
rc := C.device_stop(dev.ctx)
79+
if rc != 0 {
80+
return fmt.Errorf("ceda: could not stop EDA device: rc=%d", rc)
81+
}
82+
return nil
83+
}

0 commit comments

Comments
 (0)