Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gene
xmc4500-relax-linux
Commits
e41b8db8
Commit
e41b8db8
authored
Dec 18, 2016
by
Christian Eichler
Browse files
Implement and use wrapper functions usb_*
parent
14b8e467
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
e41b8db8
...
...
@@ -59,6 +59,9 @@ The **bch** supports the following requests:
*
`eic`
: enable instruction cache
*
`bch`
: run benchmark
Building the
**bch**
system requires a prior execution of GenE to generate
the file containing the actual benchmark (
`gene.o`
).
Usage: Communicate with the System
----------------------------------
...
...
src/main.c
View file @
e41b8db8
...
...
@@ -29,18 +29,18 @@ void _init() {}
/* Clock configuration */
XMC_SCU_CLOCK_CONFIG_t
clock_config
=
{
.
syspll_config
.
p_div
=
2
,
.
syspll_config
.
n_div
=
80
,
.
syspll_config
.
k_div
=
4
,
.
syspll_config
.
mode
=
XMC_SCU_CLOCK_SYSPLL_MODE_NORMAL
,
.
syspll_config
.
p_div
=
2
,
.
syspll_config
.
n_div
=
80
,
.
syspll_config
.
k_div
=
4
,
.
syspll_config
.
mode
=
XMC_SCU_CLOCK_SYSPLL_MODE_NORMAL
,
.
syspll_config
.
clksrc
=
XMC_SCU_CLOCK_SYSPLLCLKSRC_OSCHP
,
.
enable_oschp
=
true
,
.
calibration_mode
=
XMC_SCU_CLOCK_FOFI_CALIBRATION_MODE_FACTORY
,
.
fsys_clksrc
=
XMC_SCU_CLOCK_SYSCLKSRC_PLL
,
.
fsys_clkdiv
=
1
,
.
fcpu_clkdiv
=
1
,
.
fccu_clkdiv
=
1
,
.
fperipheral_clkdiv
=
1
.
enable_oschp
=
true
,
.
calibration_mode
=
XMC_SCU_CLOCK_FOFI_CALIBRATION_MODE_FACTORY
,
.
fsys_clksrc
=
XMC_SCU_CLOCK_SYSCLKSRC_PLL
,
.
fsys_clkdiv
=
1
,
.
fcpu_clkdiv
=
1
,
.
fccu_clkdiv
=
1
,
.
fperipheral_clkdiv
=
1
};
...
...
@@ -62,6 +62,7 @@ void SystemCoreClockSetup(void)
void
gene_main
(
uint32_t
);
void
gene_init
(
void
);
/*** Begin: Interrupt Handlers ***/
IHANDLER
void
PendSV_Handler
()
{
P1_1_set
();
while
(
1
)
{}
}
IHANDLER
void
SysTick_Handler
()
{
P1_1_set
();
while
(
1
)
{}
}
IHANDLER
void
SVC_Handler
()
{
P1_1_set
();
while
(
1
)
{}
}
...
...
@@ -70,6 +71,8 @@ IHANDLER void NMI_Handler() { P1_1_set(); while(1) {} }
IHANDLER
void
MemManage_Handler
()
{
P1_1_set
();
while
(
1
)
{}
}
IHANDLER
void
UsageFault_Handler
()
{
P1_1_set
();
while
(
1
)
{}
}
IHANDLER
void
BusFault_Handler
()
{
P1_1_set
();
while
(
1
)
{}
}
/*** End: Interrupt Handlers ***/
static
void
uint64_to_string
(
char
*
buf
,
uint64_t
value
)
{
if
(
0
==
value
)
{
...
...
@@ -85,18 +88,39 @@ static void uint64_to_string(char *buf, uint64_t value) {
}
}
/*** Begin: USB helper functions ***/
static
void
usb_send
(
const
char
*
str
)
{
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
str
);
}
static
void
usb_send2
(
const
char
*
str1
,
const
char
*
str2
)
{
usb_send
(
str1
);
usb_send
(
str2
);
}
static
void
usb_send3
(
const
char
*
str1
,
const
char
*
str2
,
const
char
*
str3
)
{
usb_send
(
str1
);
usb_send
(
str2
);
usb_send
(
str3
);
}
static
void
usb_flush
()
{
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
}
/*** End: USB helper functions ***/
#ifndef ID_SYSTEM
static
void
command_bch
(
char
*
arg
)
{
errno
=
0
;
unsigned
long
long
val
=
strtoull
(
arg
,
NULL
,
10
);
if
(
0
!=
errno
||
val
>
(
unsigned
long
long
)
UINT32_MAX
)
{
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"e:ov
\n
"
);
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
usb_send
(
"e:ov
\n
"
);
usb_flush
(
);
return
;
}
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:start
\r
"
);
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
usb_send
(
"o:start
\r
"
);
usb_flush
(
);
P1_0_toggle
();
uint32_t
old_basepri
=
__get_BASEPRI
();
...
...
@@ -117,30 +141,29 @@ static void command_bch(char *arg) {
__set_BASEPRI
(
old_basepri
);
P1_0_toggle
();
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:end "
);
usb_send
(
"o:end "
);
CDC_Device_USBTask
(
&
VirtualSerial_CDC_Interface
);
char
buf
[
64
]
=
{
0
};
uint64_to_string
(
buf
,
cycles
);
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
buf
);
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"
\n
"
);
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
usb_send2
(
buf
,
"
\n
"
);
usb_flush
();
CDC_Device_USBTask
(
&
VirtualSerial_CDC_Interface
);
}
static
void
command_dic
(
char
*
arg
)
{
XMC_PREFETCH_DisableInstructionBuffer
();
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o
\n
"
);
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
usb_send
(
"o
\n
"
);
usb_flush
(
);
CDC_Device_USBTask
(
&
VirtualSerial_CDC_Interface
);
}
static
void
command_eic
(
char
*
arg
)
{
XMC_PREFETCH_EnableInstructionBuffer
();
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o
\n
"
);
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
usb_send
(
"o
\n
"
);
usb_flush
(
);
CDC_Device_USBTask
(
&
VirtualSerial_CDC_Interface
);
}
...
...
@@ -159,53 +182,39 @@ static void command_inf(char *arg) {
// send FREQUENCY
char
buf
[
128
]
=
{
0
};
uint64_to_string
(
buf
,
SystemCoreClock
);
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:freq "
);
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
buf
);
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"
\r
"
);
usb_send3
(
"o:freq "
,
buf
,
"
\r
"
);
// send PFLASH
{
char
buf
[
128
]
=
{
0
};
uint64_to_string
(
buf
,
(
FLASH0
->
FCON
&
(
uint32_t
)
FLASH_FCON_WSPFLASH_Msk
)
>>
FLASH_FCON_WSPFLASH_Pos
);
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:wspflash "
);
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
buf
);
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"
\r
"
);
usb_send3
(
"o:wspflash "
,
buf
,
"
\r
"
);
}
// send DWT status
switch
(
DWT
->
CTRL
&
0xFF000000
)
{
case
0x40000000
:
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:4wt
\r
"
);
break
;
case
0x4F000000
:
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:4w
\r
"
);
break
;
case
0x10000000
:
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:1wt
\r
"
);
break
;
case
0x1F000000
:
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:1w
\r
"
);
break
;
case
0x00000000
:
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:0
\r
"
);
break
;
default:
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"e:v
\r
"
);
break
;
case
0x40000000
:
usb_send
(
"o:4wt
\r
"
);
break
;
case
0x4F000000
:
usb_send
(
"o:4w
\r
"
);
break
;
case
0x10000000
:
usb_send
(
"o:1wt
\r
"
);
break
;
case
0x1F000000
:
usb_send
(
"o:1w
\r
"
);
break
;
case
0x00000000
:
usb_send
(
"o:0
\r
"
);
break
;
default:
usb_send
(
"e:v
\r
"
);
break
;
}
#ifndef ID_SYSTEM
if
(
timer_has_overflow_detection
())
{
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:ov e
\r
"
);
}
else
{
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:ov d
\r
"
);
}
usb_send
(
timer_has_overflow_detection
()
?
"o:ov e
\r
"
:
"o:ov d
\r
"
);
#endif
/* ifndef ID_SYSTEM */
usb_send
((
PREF
->
PCON
&
PREF_PCON_IBYP_Msk
)
?
"o:ic d
\n
"
:
"o:ic e
\n
"
);
if
(
PREF
->
PCON
&
PREF_PCON_IBYP_Msk
)
{
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:ic d
\n
"
);
}
else
{
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"o:ic e
\n
"
);
}
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
usb_flush
();
CDC_Device_USBTask
(
&
VirtualSerial_CDC_Interface
);
}
void
*
__aeabi_memset
(
void
*
s
,
int
c
,
size_t
n
){
size_t
i
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
((
char
*
)
s
)[
i
]
=
(
char
)
c
;
}
return
s
;
void
*
__aeabi_memset
(
void
*
s
,
int
c
,
size_t
n
)
{
for
(
size_t
i
=
0
;
i
<
n
;
i
++
)
{
((
char
*
)
s
)[
i
]
=
(
char
)
c
;
}
return
s
;
}
int
main
(
void
)
{
...
...
@@ -217,11 +226,8 @@ int main(void) {
P1_1_set_driver_strength
(
STRONG
);
#define BUFFER_SIZE 32
char
buffer
[
BUFFER_SIZE
+
1
];
buffer
[
BUFFER_SIZE
]
=
'\0'
;
uint8_t
pos
=
0
;
char
buffer
[
BUFFER_SIZE
+
1
]
=
{
0
};
// enable monitor debugging
CoreDebug
->
DHCSR
=
0xA05F
<<
CoreDebug_DHCSR_DBGKEY_Pos
;
...
...
@@ -270,8 +276,8 @@ int main(void) {
#undef COMMAND
if
(
!
handled
)
{
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"e:uc
\n
"
);
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
usb_send
(
"e:uc
\n
"
);
usb_flush
(
);
}
pos
=
0
;
...
...
@@ -283,8 +289,8 @@ int main(void) {
buffer
[
pos
]
=
byte
;
++
pos
;
}
else
{
CDC_Device_SendString
(
&
VirtualSerial_CDC_Interface
,
"e:OVERFLOW IN COMMAND BUFFER
\n
"
);
CDC_Device_Flush
(
&
VirtualSerial_CDC_Interface
);
usb_send
(
"e:ov
\n
"
);
usb_flush
(
);
pos
=
0
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment