Commit 9228e8fa authored by Federico Vaga's avatar Federico Vaga Committed by Federico Vaga

sw:rt: move common.h function in general header

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@vaga.pv.it>
parent 35d684a3
......@@ -10,7 +10,7 @@
#include <stdint.h>
#include <string.h>
#include "mockturtle-rt-common.h"
#include "mockturtle-rt.h"
int putchar(int c)
{
......
/**
* @defgroup library-utilities Common Utilities
* @{
* @ingroup library
* @brief Common utilities
* @copyright (C) 2013-2016 CERN (www.cern.ch)
* @author Federico Vaga <federico.vaga@cern.ch>
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef __TRTL_RT_COMMON_H
#define __TRTL_RT_COMMON_H
#include <stdint.h>
#include <stdio.h>
#include <hw/mockturtle_addresses.h>
#include "hw/mockturtle_cpu_lr.h"
#include <mockturtle.h>
#include "mockturtle-rt-serial.h"
/**
* Read a 32bit word value from the given address
* @param[in] addr source address
* @return the value fromt the register
*/
static inline uint32_t readl(void *addr)
{
return *(volatile uint32_t *) (addr);
}
/**
* Write a 32bit word value to the given address
* @param[in] value value to write
* @param[in] addr destination address
*/
static inline void writel(uint32_t value, void *addr)
{
*(volatile uint32_t *) (addr) = value;
}
/**
* Read a 32bit word value from the Dedicated Peripheral address space
* @param[in] reg register offset within the Dedicated Peripheral
* @return the value fromt the register
*/
static inline uint32_t dp_readl(uint32_t reg)
{
return readl(TRTL_ADDR_DP(reg));
}
/**
* Write a 32bit word value to the Dedicated Peripheral address space
* @param[in] value value to write
* @param[in] reg register offset within the Dedicated Peripheral
*/
static inline void dp_writel(uint32_t value, uint32_t reg)
{
writel(value, TRTL_ADDR_DP(reg));
}
/**
* Read 32bit word value from the CPU Local Registers address space
* @param[in] reg register offset within the Local Registers
* @return the value fromt the register
*/
static inline uint32_t lr_readl(uint32_t reg)
{
return readl(TRTL_ADDR_LR(reg));
}
/**
* Write 32bit word value to the CPU Local Registers address space
* @param[in] value value to write
* @param[in] reg register offset within the Local Registers
*/
static inline void lr_writel(uint32_t value, uint32_t reg)
{
writel(value, TRTL_ADDR_LR(reg));
}
/**
* Set a bit in the CPU GPIO Register
* @param[in] pin GPIO pin to set
*/
static inline void gpio_set(int pin)
{
lr_writel ((1 << pin), MT_CPU_LR_REG_GPIO_SET);
}
/**
* Clear a bit in the CPU GPIO Register
* @param[in] pin GPIO pin to clear
*/
static inline void gpio_clear(int pin)
{
lr_writel ((1 << pin), MT_CPU_LR_REG_GPIO_CLEAR);
}
/**
* Wait n cycles
* @todo: use Timing Unit, compute it accoring to CPU frequency
* @param[in] n number of cycles to wait
*/
static inline void delay(int n)
{
int i;
for(i = 0; i < n; i++)
asm volatile("nop");
}
/**
* It returns a pointer to the config ROM
*/
static inline const struct trtl_config_rom *trtl_config_rom_get(void)
{
return (const struct trtl_config_rom *)(TRTL_ADDR_CONFIG_ROM_BASE);
}
/**
* It generates a notification signal (IRQ) to ask the HOST CPU
* to take some action.
*/
static inline void trtl_notify_send(enum trtl_cpu_notification id)
{
lr_writel(1, MT_CPU_LR_REG_NTF_INT);
}
/**
* It returns the core ID on which the firmware is running
* @return the core ID
*/
static inline uint32_t trtl_get_core_id(void)
{
return lr_readl(0);
}
#endif
/**@}*/
......@@ -18,5 +18,136 @@
#include "mockturtle-rt-smem.h"
#include "mockturtle-rt-serial.h"
/**
* Read a 32bit word value from the given address
* @param[in] addr source address
* @return the value fromt the register
*/
static inline uint32_t readl(void *addr)
{
return *(volatile uint32_t *) (addr);
}
/**
* Write a 32bit word value to the given address
* @param[in] value value to write
* @param[in] addr destination address
*/
static inline void writel(uint32_t value, void *addr)
{
*(volatile uint32_t *) (addr) = value;
}
/**
* Read a 32bit word value from the Dedicated Peripheral address space
* @param[in] reg register offset within the Dedicated Peripheral
* @return the value fromt the register
*/
static inline uint32_t dp_readl(uint32_t reg)
{
return readl(TRTL_ADDR_DP(reg));
}
/**
* Write a 32bit word value to the Dedicated Peripheral address space
* @param[in] value value to write
* @param[in] reg register offset within the Dedicated Peripheral
*/
static inline void dp_writel(uint32_t value, uint32_t reg)
{
writel(value, TRTL_ADDR_DP(reg));
}
/**
* Read 32bit word value from the CPU Local Registers address space
* @param[in] reg register offset within the Local Registers
* @return the value fromt the register
*/
static inline uint32_t lr_readl(uint32_t reg)
{
return readl(TRTL_ADDR_LR(reg));
}
/**
* Write 32bit word value to the CPU Local Registers address space
* @param[in] value value to write
* @param[in] reg register offset within the Local Registers
*/
static inline void lr_writel(uint32_t value, uint32_t reg)
{
writel(value, TRTL_ADDR_LR(reg));
}
/**
* Set a bit in the CPU GPIO Register
* @param[in] pin GPIO pin to set
*/
static inline void gpio_set(int pin)
{
lr_writel ((1 << pin), MT_CPU_LR_REG_GPIO_SET);
}
/**
* Clear a bit in the CPU GPIO Register
* @param[in] pin GPIO pin to clear
*/
static inline void gpio_clear(int pin)
{
lr_writel ((1 << pin), MT_CPU_LR_REG_GPIO_CLEAR);
}
/**
* Wait n cycles
* @todo: use Timing Unit, compute it accoring to CPU frequency
* @param[in] n number of cycles to wait
*/
static inline void delay(int n)
{
int i;
for(i = 0; i < n; i++)
asm volatile("nop");
}
/**
* It returns a pointer to the config ROM
* @return pointer to the configuration ROM
*/
static inline const struct trtl_config_rom *trtl_config_rom_get(void)
{
return (const struct trtl_config_rom *)(TRTL_ADDR_CONFIG_ROM_BASE);
}
/**
* It generates a notification signal (IRQ) to ask the HOST CPU
* to take some action.
* @param[in] id CPU notification identifier
*/
static inline void trtl_notify_send(enum trtl_cpu_notification id)
{
lr_writel(1, MT_CPU_LR_REG_HOST_INT);
}
/**
* It returns the core ID on which the firmware is running
* @return the core ID
* @todo implement me
*/
static inline uint32_t trtl_get_core_id(void)
{
return lr_readl(0);
}
#endif
/**@}*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment