Skip to content

Commit

Permalink
Merge pull request #29 from Luos-io/rc-2.0.0
Browse files Browse the repository at this point in the history
Rc 2.0.0
  • Loading branch information
JeromeGalan authored Sep 21, 2021
2 parents e70663e + e07fb2f commit c44b059
Show file tree
Hide file tree
Showing 22 changed files with 1,254 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ assignees: nicolas-rabault
A clear and concise description of what the bug is.

**Network configuration**
- Add the routing table or list the nodes and their modules
- Add the routing table or list the nodes and their services
- Power input configuration

**How to reproduce the bug**
Expand Down
199 changes: 198 additions & 1 deletion ATSAMD21/luos_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

//MCU dependencies this HAL is for family Atmel ATSAMD21 you can find

#ifdef SELFTEST
#include "selftest.h"
#endif
/*******************************************************************************
* Definitions
******************************************************************************/
Expand Down Expand Up @@ -606,6 +609,9 @@ void PINOUT_IRQHANDLER()
}
}
}
#ifdef SELFTEST
selftest_SetPtpFlag();
#endif
}
/******************************************************************************
* @brief Set PTP for Detection on branch
Expand Down Expand Up @@ -781,7 +787,7 @@ void LuosHAL_FlashWriteLuosMemoryInfo(uint32_t addr, uint16_t size, uint8_t *dat
/* Set address and command */
NVMCTRL_REGS->NVMCTRL_ADDR = addr >> 1;

NVMCTRL_REGS->NVMCTRL_CTRLA = NVMCTRL_CTRLA_CMD_WP_Val | NVMCTRL_CTRLA_CMDEX_KEY;
NVMCTRL_REGS->NVMCTRL_CTRLA = NVMCTRL_CTRLA_CMD_WP | NVMCTRL_CTRLA_CMDEX_KEY;
}
/******************************************************************************
* @brief read information from page where Luos keep permanente information
Expand All @@ -792,3 +798,194 @@ void LuosHAL_FlashReadLuosMemoryInfo(uint32_t addr, uint16_t size, uint8_t *data
{
memcpy(data, (void *)(addr), size);
}

/******************************************************************************
* @brief Set boot mode in shared flash memory
* @param
* @return
******************************************************************************/
void LuosHAL_SetMode(uint8_t mode)
{
uint32_t data_to_write = ~BOOT_MODE_MASK | (mode << BOOT_MODE_OFFSET);
uint32_t address = SHARED_MEMORY_ADDRESS;
uint32_t *paddress = (uint32_t *)address;

// erase shared mem sector
NVMCTRL_REGS->NVMCTRL_ADDR = address >> 1;
NVMCTRL_REGS->NVMCTRL_CTRLA = NVMCTRL_CTRLA_CMD_ER_Val | NVMCTRL_CTRLA_CMDEX_KEY;

// write 32 bits data into 64B page buffer
*paddress = data_to_write;

/* Set address and command */
NVMCTRL_REGS->NVMCTRL_ADDR = address >> 1;
NVMCTRL_REGS->NVMCTRL_CTRLA = NVMCTRL_CTRLA_CMD_WP | NVMCTRL_CTRLA_CMDEX_KEY;
}

/******************************************************************************
* @brief Save node ID in shared flash memory
* @param Address, node_id
* @return
******************************************************************************/
void LuosHAL_SaveNodeID(uint16_t node_id)
{
uint32_t address = SHARED_MEMORY_ADDRESS;
uint32_t *paddress = (uint32_t *)address;
uint32_t saved_data = *paddress;
uint32_t data_tmp = ~NODE_ID_MASK | (node_id << NODE_ID_OFFSET);
uint32_t data_to_write = saved_data & data_tmp;

// erase shared mem sector
NVMCTRL_REGS->NVMCTRL_ADDR = address >> 1;
NVMCTRL_REGS->NVMCTRL_CTRLA = NVMCTRL_CTRLA_CMD_ER_Val | NVMCTRL_CTRLA_CMDEX_KEY;

// write 32 bits data into 64B page buffer
*paddress = data_to_write;

/* Set address and command */
NVMCTRL_REGS->NVMCTRL_ADDR = address >> 1;
NVMCTRL_REGS->NVMCTRL_CTRLA = NVMCTRL_CTRLA_CMD_WP | NVMCTRL_CTRLA_CMDEX_KEY;
}

/******************************************************************************
* @brief software reboot the microprocessor
* @param
* @return
******************************************************************************/
void LuosHAL_Reboot(void)
{
// DeInit RCC and HAL

// reset systick
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;

// reset in bootloader mode
NVIC_SystemReset();
}

#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)
{
uint32_t JumpAddress = *(__IO uint32_t *)(app_addr + 4);
pFunction Jump = (pFunction)JumpAddress;

__disable_irq();

SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;

SCB->VTOR = app_addr;

__set_MSP(*(__IO uint32_t *)app_addr);
Jump();
}

/******************************************************************************
* @brief Return bootloader mode saved in flash
* @param
* @return
******************************************************************************/
uint8_t LuosHAL_GetMode(void)
{
uint32_t *p_start = (uint32_t *)SHARED_MEMORY_ADDRESS;
uint32_t data = (*p_start & BOOT_MODE_MASK) >> BOOT_MODE_OFFSET;

return (uint8_t)data;
}

/******************************************************************************
* @brief Get node id saved in flash memory
* @param Address
* @return node_id
******************************************************************************/
uint16_t LuosHAL_GetNodeID(void)
{
uint32_t *p_start = (uint32_t *)SHARED_MEMORY_ADDRESS;
uint32_t data = *p_start & NODE_ID_MASK;
uint16_t node_id = (uint16_t)(data >> NODE_ID_OFFSET);

return node_id;
}

/******************************************************************************
* @brief erase sectors in flash memory
* @param Address, size
* @return
******************************************************************************/
void LuosHAL_EraseMemory(uint32_t address, uint16_t size)
{
uint32_t erase_address = APP_ADDRESS;
const uint32_t row_size = 256;

for (erase_address = APP_ADDRESS; erase_address < FLASH_END; erase_address += row_size)
{
// wait if NVM controller is busy
while ((NVMCTRL_REGS->NVMCTRL_INTFLAG & NVMCTRL_INTFLAG_READY_Msk) == 0)
;
// erase row
NVMCTRL_REGS->NVMCTRL_ADDR = erase_address >> 1;
NVMCTRL_REGS->NVMCTRL_CTRLA = NVMCTRL_CTRLA_CMD_ER_Val | NVMCTRL_CTRLA_CMDEX_KEY;
// wait during erase
while ((NVMCTRL_REGS->NVMCTRL_INTFLAG & NVMCTRL_INTFLAG_READY_Msk) == 0)
;
}
}

/******************************************************************************
* @brief Save node ID in shared flash memory
* @param Address, node_id
* @return
******************************************************************************/
void LuosHAL_ProgramFlash(uint32_t address, uint16_t size, uint8_t *data)
{
uint32_t *paddress = (uint32_t *)address;
uint32_t data_index = 0;
uint8_t page_index = 0;

// wait if NVM controller is busy
while ((NVMCTRL_REGS->NVMCTRL_INTFLAG & NVMCTRL_INTFLAG_READY_Msk) == 0)
;

while (data_index < size)
{
// set addr in NVM register
NVMCTRL_REGS->NVMCTRL_ADDR = (uint32_t)&data[data_index] >> 1;
// fill page buffer with data bytes
for (page_index = 0; page_index < 16; page_index++)
{
// break if all data had been written
if (data_index >= size)
break;
// write data
*paddress = *(uint32_t *)&data[data_index];
// update address
paddress += 1;
data_index += 4;
}
// Set address and command
NVMCTRL_REGS->NVMCTRL_CTRLA = NVMCTRL_CTRLA_CMD_WP | NVMCTRL_CTRLA_CMDEX_KEY;
// wait during programming
while ((NVMCTRL_REGS->NVMCTRL_INTFLAG & NVMCTRL_INTFLAG_READY_Msk) == 0)
;
}
}
#endif
19 changes: 19 additions & 0 deletions ATSAMD21/luos_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
******************************************************************************/
#define LUOS_UUID ((uint32_t *)0x1FFFF7AC)

#define BOOT_MODE_MASK 0x000000FF
#define BOOT_MODE_OFFSET 0
#define NODE_ID_MASK 0x00FFFF00
#define NODE_ID_OFFSET 8

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

Expand Down Expand Up @@ -44,4 +49,18 @@ void LuosHAL_ComputeCRC(uint8_t *data, uint8_t *crc);
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

#endif /* _LUOSHAL_H_ */
8 changes: 8 additions & 0 deletions ATSAMD21/luos_hal_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,12 @@
#define ADDRESS_LAST_PAGE_FLASH FLASH_SIZE - (16 * PAGE_SIZE)
#endif

/*******************************************************************************
* BOOTLOADER CONFIG
******************************************************************************/
#define FLASH_END FLASH_SIZE - 1

#define SHARED_MEMORY_ADDRESS 0x0000A000
#define APP_ADDRESS 0x0000A200

#endif /* _LUOSHAL_CONFIG_H_ */
9 changes: 6 additions & 3 deletions ATSAMD21_ARDUINO/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@
#define TX_EN_PIN g_APinDescription[1].ulPin
#define TX_EN_PORT g_APinDescription[1].ulPort

#define PTPB_PIN g_APinDescription[4].ulPin
#define PTPB_PORT g_APinDescription[4].ulPort
#define PTPB_IRQ g_APinDescription[4].ulExtInt //see EXTINT
#define PTPA_PIN g_APinDescription[6].ulPin
#define PTPA_PORT g_APinDescription[6].ulPort
#define PTPA_IRQ g_APinDescription[6].ulExtInt //see EXTINT
#define PTPB_PIN g_APinDescription[7].ulPin
#define PTPB_PORT g_APinDescription[7].ulPort
#define PTPB_IRQ g_APinDescription[7].ulExtInt //see EXTINT

#endif

Expand Down
76 changes: 76 additions & 0 deletions ATSAMD21_ARDUINO/luos_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,79 @@ void LuosHAL_FlashReadLuosMemoryInfo(uint32_t addr, uint16_t size, uint8_t *data
{
memcpy(data, (void *)(addr), 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 Get node id saved in flash memory
* @param Address
* @return node_id
******************************************************************************/
uint16_t LuosHAL_GetNodeID(void)
{
}

/******************************************************************************
* @brief Save node ID in shared flash memory
* @param Address, node_id
* @return
******************************************************************************/
void LuosHAL_ProgramFlash(uint32_t address, uint8_t page, uint16_t size, uint8_t *data)
{
}

/******************************************************************************
* @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)
{
}
#endif
Loading

0 comments on commit c44b059

Please sign in to comment.