Line 1... |
Line 1... |
// #################################################################################################
|
// #################################################################################################
|
// # << NEORV32: neorv32_cpu.c - CPU Core Functions HW Driver >> #
|
// # << NEORV32: neorv32_cpu.c - CPU Core Functions HW Driver >> #
|
// # ********************************************************************************************* #
|
// # ********************************************************************************************* #
|
// # BSD 3-Clause License #
|
// # BSD 3-Clause License #
|
// # #
|
// # #
|
// # Copyright (c) 2021, Stephan Nolting. All rights reserved. #
|
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. #
|
// # #
|
// # #
|
// # Redistribution and use in source and binary forms, with or without modification, are #
|
// # Redistribution and use in source and binary forms, with or without modification, are #
|
// # permitted provided that the following conditions are met: #
|
// # permitted provided that the following conditions are met: #
|
// # #
|
// # #
|
// # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
// # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
Line 146... |
Line 146... |
**************************************************************************/
|
**************************************************************************/
|
uint64_t neorv32_cpu_get_cycle(void) {
|
uint64_t neorv32_cpu_get_cycle(void) {
|
|
|
union {
|
union {
|
uint64_t uint64;
|
uint64_t uint64;
|
uint32_t uint32[sizeof(uint64_t)/2];
|
uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
|
} cycles;
|
} cycles;
|
|
|
register uint32_t tmp1, tmp2, tmp3;
|
register uint32_t tmp1, tmp2, tmp3;
|
while(1) {
|
while(1) {
|
tmp1 = neorv32_cpu_csr_read(CSR_CYCLEH);
|
tmp1 = neorv32_cpu_csr_read(CSR_CYCLEH);
|
Line 175... |
Line 175... |
**************************************************************************/
|
**************************************************************************/
|
void neorv32_cpu_set_mcycle(uint64_t value) {
|
void neorv32_cpu_set_mcycle(uint64_t value) {
|
|
|
union {
|
union {
|
uint64_t uint64;
|
uint64_t uint64;
|
uint32_t uint32[sizeof(uint64_t)/2];
|
uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
|
} cycles;
|
} cycles;
|
|
|
cycles.uint64 = value;
|
cycles.uint64 = value;
|
|
|
neorv32_cpu_csr_write(CSR_MCYCLE, 0);
|
neorv32_cpu_csr_write(CSR_MCYCLE, 0);
|
Line 197... |
Line 197... |
**************************************************************************/
|
**************************************************************************/
|
uint64_t neorv32_cpu_get_instret(void) {
|
uint64_t neorv32_cpu_get_instret(void) {
|
|
|
union {
|
union {
|
uint64_t uint64;
|
uint64_t uint64;
|
uint32_t uint32[sizeof(uint64_t)/2];
|
uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
|
} cycles;
|
} cycles;
|
|
|
register uint32_t tmp1, tmp2, tmp3;
|
register uint32_t tmp1, tmp2, tmp3;
|
while(1) {
|
while(1) {
|
tmp1 = neorv32_cpu_csr_read(CSR_INSTRETH);
|
tmp1 = neorv32_cpu_csr_read(CSR_INSTRETH);
|
Line 226... |
Line 226... |
**************************************************************************/
|
**************************************************************************/
|
void neorv32_cpu_set_minstret(uint64_t value) {
|
void neorv32_cpu_set_minstret(uint64_t value) {
|
|
|
union {
|
union {
|
uint64_t uint64;
|
uint64_t uint64;
|
uint32_t uint32[sizeof(uint64_t)/2];
|
uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
|
} cycles;
|
} cycles;
|
|
|
cycles.uint64 = value;
|
cycles.uint64 = value;
|
|
|
neorv32_cpu_csr_write(CSR_MINSTRET, 0);
|
neorv32_cpu_csr_write(CSR_MINSTRET, 0);
|
Line 248... |
Line 248... |
**************************************************************************/
|
**************************************************************************/
|
uint64_t neorv32_cpu_get_systime(void) {
|
uint64_t neorv32_cpu_get_systime(void) {
|
|
|
union {
|
union {
|
uint64_t uint64;
|
uint64_t uint64;
|
uint32_t uint32[sizeof(uint64_t)/2];
|
uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
|
} cycles;
|
} cycles;
|
|
|
register uint32_t tmp1, tmp2, tmp3;
|
register uint32_t tmp1, tmp2, tmp3;
|
while(1) {
|
while(1) {
|
tmp1 = neorv32_cpu_csr_read(CSR_TIMEH);
|
tmp1 = neorv32_cpu_csr_read(CSR_TIMEH);
|