Skip to content

Commit

Permalink
Add a browser platform support
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Jan 22, 2024
1 parent 60bd8e9 commit fccc1fb
Show file tree
Hide file tree
Showing 16 changed files with 909 additions and 0 deletions.
53 changes: 53 additions & 0 deletions engine/HAL/BROWSER/hal_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python
# This sript is used to modify the platformio build environment to use cheerp instead

import os
import platform
# Local env
Import("env")
# Global env, use it if you call this script from a library.json file
genv = DefaultEnvironment()

# Get the cheerp bin folder
cheerp_bin_path = None
if platform.system() == 'Windows':
cheerp_bin_path = 'c:/cheerp/bin'
if platform.system() == 'Linux':
cheerp_bin_path = '/opt/cheerp/bin'
if platform.system() == 'Darwin':
cheerp_bin_path = '/Applications/cheerp/bin'

if platform.system() == 'Darwin':
# Create a symlink to Cheerp clang++ in gcc
try:
os.symlink(cheerp_bin_path + '/clang++', cheerp_bin_path + '/gcc')
except FileExistsError:
pass

# Create a symlink to Cheerp clang++ in g++
try:
os.symlink(cheerp_bin_path + '/clang++', cheerp_bin_path + '/g++')
except FileExistsError:
pass

# Add the cheerp fake gcc path at the beginning of the PATH environment variable than platformio will use it by default
current_path = os.environ.get('PATH', '')
os.environ['PATH'] = f"{cheerp_bin_path}{os.pathsep}{current_path}"

# Print the path used when calling gcc
print("GCC used by platformio is :" + os.popen("which gcc").read())

for e in [env, genv]:
# Add the cheerp-wasm target to the compiler flags
e.Append(CCFLAGS=["--target=cheerp-wasm"])

# Add the cheerp-wasm target to the linker flags
e.Append(LINKFLAGS=["--target=cheerp-wasm"])

# Replace the ar and ranlib commands with the appropriate llvm-ar command
e.Replace(AR=cheerp_bin_path + "/llvm-ar",
RANLIB=cheerp_bin_path + "/llvm-ar s")

# Replace the output filename with the appropriate extension
e.Replace(PROGNAME="program.bc")

253 changes: 253 additions & 0 deletions engine/HAL/BROWSER/luos_hal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
/******************************************************************************
* @file luosHAL
* @brief Luos Hardware Abstration Layer. Describe Low layer fonction
* @Family x86/Linux/Mac
* @author Luos
* @version 0.0.0
******************************************************************************/
#include "luos_hal.h"

#include <stdio.h>
#include <time.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>

pthread_mutex_t mutex_msg_alloc = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex_luos = PTHREAD_MUTEX_INITIALIZER;

/*******************************************************************************
* Function
******************************************************************************/
static void LuosHAL_SystickInit(void);
static void LuosHAL_FlashInit(void);
static void LuosHAL_FlashEraseLuosMemoryInfo(void);

/////////////////////////Luos Library Needed function///////////////////////////

/******************************************************************************
* @brief Luos HAL general initialisation
* @param None
* @return None
******************************************************************************/
void LuosHAL_Init(void)
{
{
// Systick Initialization
LuosHAL_SystickInit();

// Flash Initialization
LuosHAL_FlashInit();

// start timestamp
LuosHAL_StartTimestamp();
}
}

/******************************************************************************
* @brief Luos HAL general disable IRQ
* @param None
* @return None
******************************************************************************/
void LuosHAL_SetIrqState(bool Enable)
{
}

/******************************************************************************
* @brief Luos HAL general systick tick at 1ms initialize
* @param None
* @return tick Counter
******************************************************************************/
static void LuosHAL_SystickInit(void)
{
}

/******************************************************************************
* @brief Luos HAL general systick tick at 1ms
* @param None
* @return tick Counter
******************************************************************************/
uint32_t LuosHAL_GetSystick(void)
{
struct timespec time;
uint32_t ms; // Milliseconds
time_t s; // Seconds
#ifdef linux
clock_gettime(CLOCK_BOOTTIME, &time);
#else
clock_gettime(CLOCK_MONOTONIC, &time);
#endif
s = time.tv_sec;
ms = round(time.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds
if (ms > 999)
{
s++;
ms = 0;
}
ms += s * 1000;
return ms;
}

/******************************************************************************
* @brief Luos GetTimestamp
* @param None
* @return uint64_t
******************************************************************************/
uint64_t LuosHAL_GetTimestamp(void)
{
struct timespec time;
#ifdef linux
clock_gettime(CLOCK_BOOTTIME, &time);
#else
clock_gettime(CLOCK_MONOTONIC, &time);
#endif
volatile uint64_t timestamp = time.tv_nsec + time.tv_sec * 1000000000;
return timestamp;
}

/******************************************************************************
* @brief Luos start Timestamp
* @param None
* @return None
******************************************************************************/
void LuosHAL_StartTimestamp(void)
{
}

/******************************************************************************
* @brief Luos stop Timestamp
* @param None
* @return None
******************************************************************************/
void LuosHAL_StopTimestamp(void)
{
}

/******************************************************************************
* @brief Flash Initialisation
* @param None
* @return None
******************************************************************************/
static void LuosHAL_FlashInit(void)
{
for (uint16_t i = 0; i < FLASH_PAGE_NUMBER; i++)
{
for (uint16_t j = 0; j < FLASH_PAGE_SIZE; j++)
{
stub_flash_x86[i][j] = 0;
}
}
}

/******************************************************************************
* @brief Erase flash page where Luos keep permanente information
* @param None
* @return None
******************************************************************************/
static void LuosHAL_FlashEraseLuosMemoryInfo(void)
{
}

/******************************************************************************
* @brief Write flash page where Luos keep permanente information
* @param Address page / size to write / pointer to data to write
* @return
******************************************************************************/
void LuosHAL_FlashWriteLuosMemoryInfo(uint32_t addr, uint16_t size, uint8_t *data)
{
}

/******************************************************************************
* @brief read information from page where Luos keep permanente information
* @param Address info / size to read / pointer callback data to read
* @return
******************************************************************************/
void LuosHAL_FlashReadLuosMemoryInfo(uint32_t addr, uint16_t size, uint8_t *data)
{
memset(data, 0xFF, size);
}

/******************************************************************************
* @brief Set boot mode in shared flash memory
* @param
* @return
******************************************************************************/
void LuosHAL_SetMode(uint8_t mode)
{
}

/******************************************************************************
* @brief Save node ID in shared flash memory
* @param Address, node_id
* @return
******************************************************************************/
void LuosHAL_SaveNodeID(uint16_t node_id)
{
}

/******************************************************************************
* @brief software reboot the microprocessor
* @param
* @return
******************************************************************************/
void LuosHAL_Reboot(void)
{
}

#ifdef BOOTLOADER_CONFIG
/******************************************************************************
* @brief DeInit Bootloader peripherals
* @param
* @return
******************************************************************************/
void LuosHAL_DeInit(void)
{
}

/******************************************************************************
* @brief DeInit Bootloader peripherals
* @param
* @return
******************************************************************************/
typedef void (*pFunction)(void); /*!< Function pointer definition */

void LuosHAL_JumpToApp(uint32_t app_addr)
{
}

/******************************************************************************
* @brief Return bootloader mode saved in flash
* @param
* @return
******************************************************************************/
uint8_t LuosHAL_GetMode(void)
{
}

/******************************************************************************
* @brief Get node id saved in flash memory
* @param Address
* @return node_id
******************************************************************************/
uint16_t LuosHAL_GetNodeID(void)
{
}

/******************************************************************************
* @brief erase sectors in flash memory
* @param Address, size
* @return
******************************************************************************/
void LuosHAL_EraseMemory(uint32_t address, uint16_t size)
{
}

/******************************************************************************
* @brief Save binary data in shared flash memory
* @param Address, size, data[]
* @return
******************************************************************************/
void LuosHAL_ProgramFlash(uint32_t address, uint16_t size, uint8_t *data)
{
}
#endif
59 changes: 59 additions & 0 deletions engine/HAL/BROWSER/luos_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/******************************************************************************
* @file luosHAL
* @brief Luos Hardware Abstration Layer. Describe Low layer fonction
* @Family x86/Linux/Mac
* @author Luos
* @version 0.0.0
******************************************************************************/
#ifndef _LUOSHAL_H_
#define _LUOSHAL_H_

#include <stdint.h>
#include <stdbool.h>
#include "luos_hal_config.h"

/*******************************************************************************
* Definitions
******************************************************************************/
#ifndef _CRITICAL
#define _CRITICAL
#endif

#define LUOS_UUID ((uint32_t *)0x00000001)

#define ADDRESS_ALIASES_FLASH ADDRESS_LAST_PAGE_FLASH
#define ADDRESS_BOOT_FLAG_FLASH (ADDRESS_LAST_PAGE_FLASH + PAGE_SIZE) - 4

/*******************************************************************************
* Variables
******************************************************************************/

/*******************************************************************************
* Function
******************************************************************************/
void LuosHAL_Init(void);
void LuosHAL_SetIrqState(bool Enable);
uint32_t LuosHAL_GetSystick(void);
void LuosHAL_FlashWriteLuosMemoryInfo(uint32_t addr, uint16_t size, uint8_t *data);
void LuosHAL_FlashReadLuosMemoryInfo(uint32_t addr, uint16_t size, uint8_t *data);

// bootloader functions
void LuosHAL_SetMode(uint8_t mode);
void LuosHAL_Reboot(void);
void LuosHAL_SaveNodeID(uint16_t);

#ifdef BOOTLOADER_CONFIG
void LuosHAL_DeInit(void);
void LuosHAL_JumpToApp(uint32_t);
uint8_t LuosHAL_GetMode(void);
uint16_t LuosHAL_GetNodeID(void);
void LuosHAL_EraseMemory(uint32_t, uint16_t);
void LuosHAL_ProgramFlash(uint32_t, uint16_t, uint8_t *);
#endif

// timestamp functions
uint64_t LuosHAL_GetTimestamp(void);
void LuosHAL_StartTimestamp(void);
void LuosHAL_StopTimestamp(void);

#endif /* _LUOSHAL_H_ */
Loading

0 comments on commit fccc1fb

Please sign in to comment.