diff --git a/engine/HAL/BROWSER/hal_script.py b/engine/HAL/BROWSER/hal_script.py new file mode 100644 index 000000000..0aad8b622 --- /dev/null +++ b/engine/HAL/BROWSER/hal_script.py @@ -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") + diff --git a/engine/HAL/BROWSER/luos_hal.c b/engine/HAL/BROWSER/luos_hal.c new file mode 100644 index 000000000..3771e3873 --- /dev/null +++ b/engine/HAL/BROWSER/luos_hal.c @@ -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 +#include +#include +#include +#include + +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 diff --git a/engine/HAL/BROWSER/luos_hal.h b/engine/HAL/BROWSER/luos_hal.h new file mode 100644 index 000000000..048a0b86f --- /dev/null +++ b/engine/HAL/BROWSER/luos_hal.h @@ -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 +#include +#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_ */ diff --git a/engine/HAL/BROWSER/luos_hal_config.h b/engine/HAL/BROWSER/luos_hal_config.h new file mode 100644 index 000000000..f2b7929ff --- /dev/null +++ b/engine/HAL/BROWSER/luos_hal_config.h @@ -0,0 +1,74 @@ +/****************************************************************************** + * @file luosHAL_Config + * @brief This file allow you to configure LuosHAL according to your design + * this is the default configuration created by Luos team for this MCU Family + * Do not modify this file if you want to ovewrite change define in you project + * @Family x86 + * @author Luos + * @version 0.0.0 + ******************************************************************************/ +#ifndef _LUOSHAL_CONFIG_H_ +#define _LUOSHAL_CONFIG_H_ + +#ifndef MCUFREQ + #define MCUFREQ 100000000 // MCU frequence +#endif + +/******************************************************************************* + * DEFINE STUB FLASH FOR X86 + ******************************************************************************/ +#ifndef FLASH_PAGE_SIZE + #define FLASH_PAGE_SIZE 0x100 +#endif +#ifndef FLASH_PAGE_NUMBER + #define FLASH_PAGE_NUMBER 8 +#endif +static uint32_t stub_flash_x86[FLASH_PAGE_NUMBER][FLASH_PAGE_SIZE]; +static uint32_t *last_page_stub_flash_x86 = &stub_flash_x86[FLASH_PAGE_NUMBER - 1][FLASH_PAGE_SIZE]; + +/******************************************************************************* + * DEFINE THREAD MUTEX LOCKING AND UNLOCKING FUNCTIONS + ******************************************************************************/ +#include +extern pthread_mutex_t mutex_msg_alloc; +extern pthread_mutex_t mutex_luos; + +#ifndef MSGALLOC_MUTEX_LOCK + #define MSGALLOC_MUTEX_LOCK pthread_mutex_lock(&mutex_msg_alloc); +#endif +#ifndef MSGALLOC_MUTEX_UNLOCK + #define MSGALLOC_MUTEX_UNLOCK pthread_mutex_unlock(&mutex_msg_alloc); +#endif + +#ifndef LUOS_MUTEX_LOCK + #define LUOS_MUTEX_LOCK pthread_mutex_lock(&mutex_luos); +#endif +#ifndef LUOS_MUTEX_UNLOCK + #define LUOS_MUTEX_UNLOCK pthread_mutex_unlock(&mutex_luos); +#endif +/******************************************************************************* + * FLASH CONFIG + ******************************************************************************/ +#ifndef PAGE_SIZE + #define PAGE_SIZE (uint32_t) FLASH_PAGE_SIZE +#endif +#ifndef ADDRESS_LAST_PAGE_FLASH + #define ADDRESS_LAST_PAGE_FLASH (uint32_t) last_page_stub_flash_x86 +#endif + +/******************************************************************************* + * BOOTLOADER CONFIG + ******************************************************************************/ +#define FLASH_END FLASH_SIZE - 1 + +#ifndef END_ERASE_BOOTLOADER + #define END_ERASE_BOOTLOADER (uint32_t)0x08020000 +#endif +#ifndef SHARED_MEMORY_ADDRESS + #define SHARED_MEMORY_ADDRESS (uint32_t)0x0801F800 +#endif +#ifndef APP_ADDRESS + #define APP_ADDRESS (uint32_t)0x0800C800 +#endif + +#endif /* _LUOSHAL_CONFIG_H_ */ diff --git a/examples/projects/browser/led/README.md b/examples/projects/browser/led/README.md new file mode 100644 index 000000000..bcdcb1452 --- /dev/null +++ b/examples/projects/browser/led/README.md @@ -0,0 +1,38 @@ +Luos logo + +![](https://github.com/Luos-io/luos_engine/actions/workflows/build.yml/badge.svg) +[![](https://img.shields.io/github/license/Luos-io/Luos)](https://github.com/Luos-io/luos_engine/blob/master/LICENSE) + +[![](https://img.shields.io/badge/Luos-Documentation-34A3B4)](https://www.luos.io/docs/) +[![](http://certified.luos.io)](https://luos.io) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/luos/library/luos_engine.svg)](https://registry.platformio.org/libraries/luos_engine/luos_engine) + +[![](https://img.shields.io/discord/902486791658041364?label=Discord&logo=discord&style=social)](http://bit.ly/JoinLuosDiscord) +[![](https://img.shields.io/reddit/subreddit-subscribers/Luos?style=social)](https://www.reddit.com/r/Luos) +[![](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Unleash%20electronic%20devices%20as%20microservices%20thanks%20to%20Luos&https://luos.io&via=Luos_io&hashtags=embeddedsystems,electronics,microservices,api) +[![](https://img.shields.io/badge/LinkedIn-Share-0077B5?style=social&logo=linkedin)](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fgithub.com%2Fluos-io) + +# Led project example :bulb: + +This project demonstrate how to make and use a simple button through Luos. Feel free to use electronics and code example as you want. + +## How to compile the code :computer: + +1. Install [Sheerp](https://labs.leaningtech.com/cheerp/installation/windows-macos) +2. Download and install [Platformio](https://platformio.org/platformio-ide) +3. Open this folder into Platformio +4. Build (Platformio will do the rest) + +## How to open the electronic design :electric_plug: + +You can open [a working example electronic design](https://github.com/Luos-io/luos_engine/tree/main/examples/hardware) with Kicad. This design use Luos_components library for more information to install and use it read [our doc](https://www.luos.io/docs/). + +## Linked driver + +This project is linked to the [Button driver](../../Drivers/button). + +## Don't hesitate to read [our documentation](https://www.luos.io/docs/), or to post your questions/issues on the [Luos' Forum](https://community.luos.io). :books: + +[![](https://img.shields.io/discourse/topics?server=https%3A%2F%2Fcommunity.luos.io&logo=Discourse)](https://community.luos.io) +[![](https://img.shields.io/badge/Luos-Documentation-34A3B4)](https://www.luos.io/docs/) +[![](https://img.shields.io/badge/LinkedIn-Follow%20us-0077B5?style=flat&logo=linkedin)](https://www.linkedin.com/company/luos) diff --git a/examples/projects/browser/led/lib/Led/README.md b/examples/projects/browser/led/lib/Led/README.md new file mode 100644 index 000000000..12168b996 --- /dev/null +++ b/examples/projects/browser/led/lib/Led/README.md @@ -0,0 +1,18 @@ +Luos logo + +[![](http://certified.luos.io)](https://luos.io) +[![](https://img.shields.io/github/license/Luos-io/Examples)]( +https://github.com/Luos-io/Examples/blob/master/LICENSE) + +[![](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Unleash%20electronic%20devices%20as%20microservices%20thanks%20to%20Luos&https://luos.io&via=Luos_io&hashtags=embeddedsystems,electronics,microservices,api) +[![](https://img.shields.io/badge/LinkedIn-Share-0077B5?style=social&logo=linkedin)](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fgithub.com%2Fluos-io) + +# LED driver +Driver for using an RGB LED in your projects with Luos. + +# Link project +This driver is linked to the [LED project](../../Projects/Led). + +[![](https://img.shields.io/discourse/topics?server=https%3A%2F%2Fcommunity.luos.io&logo=Discourse)](https://community.luos.io) +[![](https://img.shields.io/badge/Luos-Documentation-34A3B4)](https://www.luos.io/docs/) +[![](https://img.shields.io/badge/LinkedIn-Follow%20us-0077B5?style=flat&logo=linkedin)](https://www.linkedin.com/company/luos) diff --git a/examples/projects/browser/led/lib/Led/led.c b/examples/projects/browser/led/lib/Led/led.c new file mode 100644 index 000000000..5b7fa2ff6 --- /dev/null +++ b/examples/projects/browser/led/lib/Led/led.c @@ -0,0 +1,129 @@ +/****************************************************************************** + * @file Led + * @brief driver example a simple Led + * @author Luos + * @version 0.0.0 + ******************************************************************************/ +#include +#include +#ifdef _WIN32 + #include +#else + #include +#endif +#include "led.h" +#include + +/******************************************************************************* + * Definitions + ******************************************************************************/ + +/******************************************************************************* + * Variables + ******************************************************************************/ +uint8_t Led_last_state = 0; +const char led_ON[768] = " \\ | /\n" + " ___________________________.-.________________\n" + " / - |***| - /;\n" + " / ________________ - |***| - //\n" + " / / /; [` - ') //\n" + " / / MCU // `---' //\n" + " / / // | | //\n" + " / /______________ // //\n" + " / '---------------' //\n" + " / //\n" + "/_____________________________________________//\n" + "`---------------------------------------------'\n"; + +const char led_OFF[768] = "\n" + " ___________________________.-.________________\n" + " / | | /;\n" + " / ________________ | | //\n" + " / / /; [` - ') //\n" + " / / MCU // `---' //\n" + " / / // | | //\n" + " / /______________ // //\n" + " / '---------------' //\n" + " / //\n" + "/_____________________________________________//\n" + "`---------------------------------------------'\n"; + +/******************************************************************************* + * Function + ******************************************************************************/ +static void Led_MsgHandler(service_t *service, const msg_t *msg); + +void clear_screen(void) +{ +#ifdef _WIN32 + system("cls"); +#else + // Assume POSIX + system("clear"); +#endif +} + +/****************************************************************************** + * @brief init must be call in project init + * @param None + * @return None + ******************************************************************************/ +void Led_Init(void) +{ + revision_t revision = {.major = 1, .minor = 0, .build = 0}; + Luos_CreateService(Led_MsgHandler, STATE_TYPE, "led", revision); + clear_screen(); + printf("LED service running.\n\n"); + printf(led_OFF); +} + +/****************************************************************************** + * @brief loop must be call in project loop + * @param None + * @return None + ******************************************************************************/ +void Led_Loop(void) {} + +/****************************************************************************** + * @brief Msg manager callback when a msg receive for this service + * @param service destination + * @param Msg receive + * @return None + ******************************************************************************/ +static void Led_MsgHandler(service_t *service, const msg_t *msg) +{ + if (msg->header.cmd == IO_STATE) + { + if (msg->data[0] != Led_last_state) + { + Led_last_state = msg->data[0]; + clear_screen(); + printf("LED service running.\n\n"); + if (Led_last_state == LED_OFF) + { + printf(led_OFF); + } + else if (Led_last_state == LED_ON) + { + printf(led_ON); + } + else + { + printf("[UNKWNOWN STATE] LED can only be ON or OFF...\n"); + } + } + else if (msg->data[0] == LED_ON) + { + + clear_screen(); + printf("LED service running. => LED is already ON\n\n"); + printf(led_ON); + } + else if (msg->data[0] == LED_OFF) + { + clear_screen(); + printf("LED service running. => LED is already OFF\n\n"); + printf(led_OFF); + } + } +} diff --git a/examples/projects/browser/led/lib/Led/led.h b/examples/projects/browser/led/lib/Led/led.h new file mode 100644 index 000000000..5efb98688 --- /dev/null +++ b/examples/projects/browser/led/lib/Led/led.h @@ -0,0 +1,28 @@ +/****************************************************************************** + * @file Led + * @brief driver example a simple Led + * @author Luos + * @version 0.0.0 + ******************************************************************************/ +#ifndef LED_H +#define LED_H + +#include "luos_engine.h" + +/******************************************************************************* + * Definitions + ******************************************************************************/ +#define LED_OFF 0 +#define LED_ON 1 + +/******************************************************************************* + * Variables + ******************************************************************************/ + +/******************************************************************************* + * Function + ******************************************************************************/ +void Led_Init(void); +void Led_Loop(void); + +#endif /* LED_H */ diff --git a/examples/projects/browser/led/lib/Led/library.json b/examples/projects/browser/led/lib/Led/library.json new file mode 100644 index 000000000..53d03f7ca --- /dev/null +++ b/examples/projects/browser/led/lib/Led/library.json @@ -0,0 +1,14 @@ +{ + "name": "led", + "keywords": "robus,network,microservice,luos,operating system,os,embedded,communication,container,ST", + "description": "a simple button driver", + "version": "0.7.0", + "authors": { + "name": "Luos", + "url": "https://luos.io" + }, + "licence": "MIT", + "dependencies": { + "luos_engine": "^3.1.0" + } +} diff --git a/examples/projects/browser/led/node_config.h b/examples/projects/browser/led/node_config.h new file mode 100644 index 000000000..721108be8 --- /dev/null +++ b/examples/projects/browser/led/node_config.h @@ -0,0 +1,96 @@ +/****************************************************************************** + * @file node_config.h + * @brief This file allow you to use standard preprocessor definitions to + * configure your project, Luos and Luos HAL libraries + * + * # Introduction + * This file is for the luos user. You may here configure your project and + * define your custom Luos service and custom Luos command for your product + * + * Luos libraries offer a minimal standard configuration to optimize + * memory usage. In some case you have to modify standard value to fit + * with your need concerning among of data transiting through the network + * or network speed for example + * + * Luos libraries can be use with a lot a MCU family. Luos compagny give you + * a default configuration, for specific MCU family, in robus_hal_config.h. + * This configuration can be modify here to fit with you design by + * preprocessor definitions of MCU Hardware needs + * + * # Usage + * This file should be place a the root folder of your project and include + * where build flag preprocessor definitions are define in your IDE + * -include node_config.h + * + * @author Luos + * @version 0.0.0 + ******************************************************************************/ +#ifndef _NODE_CONFIG_H_ +#define _NODE_CONFIG_H_ + +/******************************************************************************* + * PROJECT DEFINITION + *******************************************************************************/ + +/******************************************************************************* + * LUOS LIBRARY DEFINITION + ******************************************************************************* + * Define | Default Value | Description + * :---------------------|------------------------------------------------------ + * MAX_LOCAL_SERVICE_NUMBER | 5 | Service number in the node + * MAX_NODE_NUMBER. | 20 | Node number in the device + * MSG_BUFFER_SIZE | 3*SIZE_MSG_MAX (405 Bytes) | Size in byte of the Luos buffer TX and RX + * MAX_MSG_NB | 2*MAX_LOCAL_SERVICE_NUMBER | Message number in Luos buffer + * NBR_PORT | 2 | PTP Branch number Max 8 + * NBR_RETRY | 10 | Send Retry number in case of NACK or collision + ******************************************************************************/ +#define MAX_LOCAL_SERVICE_NUMBER 1 +#define MAX_LOCAL_PROFILE_NUMBER 1 +#define MAX_MSG_NB 10 + +/******************************************************************************* + * LUOS HAL LIBRARY DEFINITION +******************************************************************************* + * Define | Description + * :-----------------------|----------------------------------------------- + * MCUFREQ | Put your the MCU frequency (value in Hz) + * TIMERDIV | Timer divider clock (see your clock configuration) + * USE_CRC_HW | define to 0 if there is no Module CRC in your MCU + * USE_TX_IT | define to 1 to not use DMA transfers for Luos Tx + * + * PORT_CLOCK_ENABLE | Enable clock for port + * PTPx | A,B,C,D etc. PTP Branch Pin/Port/IRQ + * TX_LOCK_DETECT | Disable by default use if not busy flag in USART Pin/Port/IRQ + * RX_EN | Rx enable for driver RS485 always on Pin/Port + * TX_EN | Tx enable for driver RS485 Pin/Port + * COM_TX | Tx USART Com Pin/Port/Alternate + * COM_RX | Rx USART Com Pin/Port/Alternate + * PINOUT_IRQHANDLER | Callback function for Pin IRQ handler + + * ROBUS_COM_CLOCK_ENABLE | Enable clock for USART + * ROBUS_COM | USART number + * ROBUS_COM_IRQ | USART IRQ number + * ROBUS_COM_IRQHANDLER | Callback function for USART IRQ handler + + * ROBUS_DMA_CLOCK_ENABLE | Enable clock for DMA + * ROBUS_DMA | DMA number + * ROBUS_DMA_CHANNEL | DMA channel (depending on MCU DMA may need special config) + + * ROBUS_TIMER_CLOCK_ENABLE | Enable clock for Timer + * ROBUS_TIMER | Timer number + * ROBUS_TIMER_IRQ | Timer IRQ number + * ROBUS_TIMER_IRQHANDLER | Callback function for Timer IRQ handler +******************************************************************************/ + +/******************************************************************************* + * FLASH CONFIGURATION FOR APP WITH BOOTLOADER + ******************************************************************************** + * Define | Default Value | Description + * :---------------------|------------------------------------------------------ + * BOOT_START_ADDRESS | FLASH_BASE = 0x8000000 | Start address of Bootloader in flash + * SHARED_MEMORY_ADDRESS | 0x0800C000 | Start address of shared memory to save boot flag + * APP_START_ADDRESS | 0x0800C800 | Start address of application with bootloader + * APP_END_ADDRESS | FLASH_BANK1_END=0x0801FFFF | End address of application with bootloader + ******************************************************************************/ + +#endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/browser/led/platformio.ini b/examples/projects/browser/led/platformio.ini new file mode 100644 index 000000000..17e899950 --- /dev/null +++ b/examples/projects/browser/led/platformio.ini @@ -0,0 +1,28 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html +[platformio] + +[env:browser] +lib_ldf_mode =off +lib_extra_dirs = + $PROJECT_DIR/../../../../../ + $PROJECT_DIR/../../../../network/ +platform = native +lib_deps = + Led + ws_network + luos_engine@^3.1.0 +build_unflags = -Os +build_flags = + -I inc + -include node_config.h + -O3 + -D LUOSHAL=BROWSER + -D WSHAL=BROWSER diff --git a/examples/projects/browser/led/src/main.c b/examples/projects/browser/led/src/main.c new file mode 100644 index 000000000..623636771 --- /dev/null +++ b/examples/projects/browser/led/src/main.c @@ -0,0 +1,16 @@ +#include "luos_engine.h" +// #include "ws_network.h" +#include "led.h" + +int main(void) +{ + Luos_Init(); + // Ws_Init(); + Led_Init(); + while (1) + { + Luos_Loop(); + // Ws_Loop(); + Led_Loop(); + } +} diff --git a/network/ws_network/HAL/ARDUINO/hal_script.py b/network/ws_network/HAL/ARDUINO/hal_script.py new file mode 100644 index 000000000..bdcb3594b --- /dev/null +++ b/network/ws_network/HAL/ARDUINO/hal_script.py @@ -0,0 +1,8 @@ +# Import("env") +# platform = env.PioPlatform() +# libs=env.GetProjectOption("lib_deps") +# libs.append("u0078867/Arduino-Websocket-Fast@^1.0.0") +# print(libs) +# env_section = "env:" + env["PIOENV"] +# platform.config.set(env_section, "lib_deps", libs) +# print("ending hal_script.py") diff --git a/network/ws_network/HAL/BROWSER/ws_hal.c b/network/ws_network/HAL/BROWSER/ws_hal.c new file mode 100644 index 000000000..171b87ef0 --- /dev/null +++ b/network/ws_network/HAL/BROWSER/ws_hal.c @@ -0,0 +1,60 @@ +/****************************************************************************** + * @file robusHAL + * @brief Robus Hardware Abstration Layer. Describe Low layer fonction + * @Family x86/Linux/Mac + * @author Luos + * @version 0.0.0 + ******************************************************************************/ +#include "ws_hal.h" +#include "_ws_network.h" +#include "luos_utils.h" + +/******************************************************************************* + * Definitions + ******************************************************************************/ + +/******************************************************************************* + * Variables + ******************************************************************************/ + +static const char *s_url = WS_NETWORK_BROKER_ADDR; + +/******************************************************************************* + * Function + ******************************************************************************/ + +/////////////////////////Luos Library Needed function/////////////////////////// + +/****************************************************************************** + * @brief Luos HAL general initialisation + * @param None + * @return None + ******************************************************************************/ +void WsHAL_Init(void) +{ + + // Create a client WebSocket instance to s_url +} + +/****************************************************************************** + * @brief Luos HAL general loop + * @param None + * @return None + ******************************************************************************/ +void WsHAL_Loop(void) +{ + // Get the messages and put them on the reception function + // Ws_Reception(uint8_t *msg, (uint32_t)messageSize); + // If you have a callback you can create a callback instead of this function and call it here +} + +/****************************************************************************** + * @brief Transmit data + * @param data to send + * @param size of data to send + * @return None + ******************************************************************************/ +void WsHAL_Send(const uint8_t *data, uint16_t size) +{ + // Send data to the websocket in binary mode +} diff --git a/network/ws_network/HAL/BROWSER/ws_hal.h b/network/ws_network/HAL/BROWSER/ws_hal.h new file mode 100644 index 000000000..255bd800b --- /dev/null +++ b/network/ws_network/HAL/BROWSER/ws_hal.h @@ -0,0 +1,23 @@ +/****************************************************************************** + * @file ws_hal + * @brief Websocket Hardware Abstration Layer. Describe Low layer fonctions + * @author Luos + * @version 0.0.0 + ******************************************************************************/ +#ifndef _WSHAL_H_ +#define _WSHAL_H_ + +#include + +/******************************************************************************* + * Variables + ******************************************************************************/ + +/******************************************************************************* + * Function + ******************************************************************************/ +void WsHAL_Init(void); // Init the Websocket communication +void WsHAL_Loop(void); // Do your loop stuff if needed +void WsHAL_Send(const uint8_t *data, uint16_t size); // Send data + +#endif /* _WSHAL_H_ */ diff --git a/network/ws_network/HAL/BROWSER/ws_hal_config.h b/network/ws_network/HAL/BROWSER/ws_hal_config.h new file mode 100644 index 000000000..75d858273 --- /dev/null +++ b/network/ws_network/HAL/BROWSER/ws_hal_config.h @@ -0,0 +1,12 @@ +/****************************************************************************** + * @file ws_HAL_config + * @brief This file allow you to configure ws HAL according to your system + * this is the default configuration created by Luos team for this target + * Do not modify this file if you want to ovewrite change define it in your project node_config.h + * @author Luos + * @version 0.0.0 + ******************************************************************************/ +#ifndef _WS_CONFIG_H_ +#define _WS_CONFIG_H_ + +#endif /* _WS_CONFIG_H_ */