Browse Source

convert the irrigation project to sysinits...

minor improvement to make sysinit_run a constructor, so don't need
to manually call it anymore...

This required updating the linker script for the l1 part to include
the linkerset section..
main
John-Mark Gurney 5 months ago
parent
commit
e70b76111f
11 changed files with 64 additions and 48 deletions
  1. +6
    -1
      Makefile
  2. +3
    -10
      board.c
  3. +4
    -0
      board/strobe_l1_rng_init.c
  4. +12
    -12
      irr_main.c
  5. +25
    -5
      main.c
  6. +7
    -1
      mk/boards.mk
  7. +0
    -2
      rs485hid/rs485gw.c
  8. +0
    -2
      rs485hid/rs485hid.c
  9. +6
    -0
      stm32/l151ccux/STM32L151CCUX_FLASH.ld
  10. +0
    -14
      stm32/l151ccux/stm32l1xx_it.c
  11. +1
    -1
      sysinit.c

+ 6
- 1
Makefile View File

@@ -38,10 +38,11 @@ PROGS = lora.gw lora.irr

SRCS.lora.gw = main.c
SRCS.lora.gw+= $(SRCS.NODE151)
SRCS.lora.gw+= $(SRCS.USB_CDC)
SRCS.lora.gw+= $(SRCS.USB)

SRCS.lora.irr = irr_main.c
SRCS.lora.irr+= comms.c
SRCS.lora.irr+= strobe_rng_init.c
SRCS.lora.irr+= $(STROBE_SRCS)
SRCS.lora.irr+= $(SRCS.NODE151)

@@ -52,6 +53,10 @@ CFLAGS+= -I$(.OBJDIR) # for shared_key.h

WITH_STROBE=yes

# XXX - bsd.mkopt.mk only allows an option to have one upstream, I want
# more.
WITH_HAL_INIT=yes

WITH_SX1276=yes

WITH_NODE151=yes


+ 3
- 10
board.c View File

@@ -44,6 +44,8 @@
#endif
#include "board.h"

#include <sysinit.h>

#include <usb_device.h>

/*!
@@ -123,8 +125,6 @@ void BoardInitMcu( void )
{
if( McuInitialized == false )
{
HAL_Init( );

#if 0
// LEDs
GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
@@ -193,8 +193,6 @@ void BoardInitMcu( void )
SystemClockReConfig( );
}

MX_USB_DEVICE_Init();

AdcInit( &Adc, PB_15 ); // Just initialize ADC

/* setup routing */
@@ -233,6 +231,7 @@ void BoardInitMcu( void )
#endif
}
}
SYSINIT_VF(initmcu, SI_SUB_HAL, SI_ORDER_SECOND, BoardInitMcu);

void BoardResetMcu( void )
{
@@ -476,12 +475,6 @@ void SystemClockReConfig( void )
}
}

void SysTick_Handler( void )
{
HAL_IncTick( );
HAL_SYSTICK_IRQHandler( );
}

uint8_t GetBoardPowerSource( void )
{
if( UsbIsConnected == false )


strobe_rng_init.c → board/strobe_l1_rng_init.c View File

@@ -33,6 +33,8 @@

#include <unistd.h>

#include <sysinit.h>

#define nitems(x) (sizeof(x) / sizeof *(x))
#define DEFINE_RNG_SAVE 1
#if DEFINE_RNG_SAVE
@@ -58,6 +60,7 @@ strobe_rng_init(void)
strobe_seed_prng(sbrk(0), 2*1024);

}
SYSINIT_VF(rng_init, SI_SUB_HAL, SI_ORDER_LAST, strobe_rng_init);

void
strobe_rng_save(void)
@@ -85,3 +88,4 @@ strobe_rng_save(void)

__set_PRIMASK(primask);
}
SYSINIT_VF(rng_save, SI_SUB_LAST, SI_ORDER_LAST, strobe_rng_save);

+ 12
- 12
irr_main.c View File

@@ -38,6 +38,8 @@
#include <strobe_rng_init.h>
#include <comms.h>

#include <sysinit.h>

enum {
CMD_TERMINATE = 1,
CMD_WAITFOR = 2,
@@ -134,6 +136,7 @@ radio_seed_rng(void)
}
#endif
}
SYSINIT_VF(radio_seed_rng, SI_SUB_STANDARD, SI_ORDER_ANY, radio_seed_rng);

static void
analog_seed_rng(void)
@@ -155,6 +158,7 @@ analog_seed_rng(void)
}
#endif
}
SYSINIT_VF(analog_seed_rng, SI_SUB_STANDARD, SI_ORDER_ANY, analog_seed_rng);

static inline uint32_t
letoh_32(uint8_t *v)
@@ -206,6 +210,7 @@ setup_gpio()
set_chan(i, chans[i].init);
}
}
SYSINIT_VF(setup_gpio, SI_SUB_HAL, SI_ORDER_LAST, setup_gpio);

static struct sched {
uint32_t cmd;
@@ -339,23 +344,18 @@ procmsg(struct pktbuf inbuf, struct pktbuf *outbuf)
outbuf->pktlen = 1;
}

int
main()
void
radio_init(void)
{

strobe_rng_init();

BoardInitMcu();

Radio.Init(&revents);
}

analog_seed_rng();

radio_seed_rng();

strobe_rng_save();
SYSINIT_VF(radio_init, SI_SUB_HAL, SI_ORDER_MIDDLE, radio_init);

setup_gpio();
int
main()
{

/* turn on LED */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);


+ 25
- 5
main.c View File

@@ -24,6 +24,7 @@
*
*/

#include <usb_device.h>
#include <usbd_cdc_if.h>

#include <string.h>
@@ -37,6 +38,20 @@
/* lora-irr headers */
#include <misc.h>

#include <sysinit.h>

/* Start up USB */
SYSINIT_VF(usb_cdc, SI_SUB_USB, SI_ORDER_MIDDLE, MX_USB_DEVICE_Init);

/* XXX - where's a better place? */
extern PCD_HandleTypeDef hpcd_USB_FS;

void
USB_LP_IRQHandler(void)
{

HAL_PCD_IRQHandler(&hpcd_USB_FS);
}

char *
findeol(char *pos, size_t len)
@@ -187,16 +202,21 @@ process_line(char *start, char *end)
fflush(vcp_usb);
}

void
radio_init(void)
{

Radio.Init(&revents);
}

SYSINIT_VF(radio_init, SI_SUB_STANDARD, SI_ORDER_ANY, radio_init);

int
main(void)
{

debug_printf("starting...\n");

BoardInitMcu();

Radio.Init(&revents);

/* turn on LED */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);

@@ -210,7 +230,7 @@ main(void)
* STM32 Core USB library:
* https://github.com/STMicroelectronics/STM32CubeL1/issues/10
*/
DelayMs(50);
DelayMs(100);
usb_printf("starting...\r\n");

#endif


+ 7
- 1
mk/boards.mk View File

@@ -40,6 +40,11 @@ STROBE_SRCS+= strobe.c \
STROBE_SRCS+= strobe_f1_rng_init.c
.endif

.if ${MK_STROBE} == "yes" && ${MK_NODE151} == "yes"
.PATH: $(SRCTOP)/board
STROBE_SRCS+= strobe_l1_rng_init.c
.endif

# LoRamac (SX1276) radio code
.if ${MK_SX1276} == "yes"
LORAMAC_SRC = $(SRCTOP)/loramac/src
@@ -98,6 +103,7 @@ ARMTARGET?= -mcpu=cortex-m3 -mthumb
LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld

SRCS+= \
hal_generic.c \
startup_stm32l151ccux.s \
stm32l1xx_hal.c \
stm32l1xx_hal_adc.c \
@@ -174,7 +180,7 @@ SRCS.USB+= \
.endif

.if ${MK_USB} == "yes" && ${MK_NODE151} == "yes"
# note that the Node151 does not need the USB reset hack in si_usb.c
SRCS.USB_CDC+= \
si_usb.c \
stm32l1xx_ll_usb.c
.endif

+ 0
- 2
rs485hid/rs485gw.c View File

@@ -227,8 +227,6 @@ int
main(void)
{

sysinit_run();

debug_printf("starting...\n");

#if 0


+ 0
- 2
rs485hid/rs485hid.c View File

@@ -413,8 +413,6 @@ main()

debug_printf("starting...");

sysinit_run();

#if 0
/* turn on LED */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);


+ 6
- 0
stm32/l151ccux/STM32L151CCUX_FLASH.ld View File

@@ -3,6 +3,9 @@
**
** File : LinkerScript.ld
**

XXX

** Author : Auto-generated by STM32CubeIDE
**
** Abstract : Linker script for STM32L151CCUx Device from stm32l1 series
@@ -101,6 +104,9 @@ SECTIONS
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
__start_set_sysinit_set = .;
KEEP(*(set_sysinit_set)) /* sysinit linker sets */
__stop_set_sysinit_set = .;
} >FLASH

.ARM.extab : {


+ 0
- 14
stm32/l151ccux/stm32l1xx_it.c View File

@@ -184,20 +184,6 @@ void PendSV_Handler(void)
/* please refer to the startup file (startup_stm32l1xx.s). */
/******************************************************************************/

/**
* @brief This function handles USB low priority interrupt.
*/
void USB_LP_IRQHandler(void)
{
/* USER CODE BEGIN USB_LP_IRQn 0 */

/* USER CODE END USB_LP_IRQn 0 */
HAL_PCD_IRQHandler(&hpcd_USB_FS);
/* USER CODE BEGIN USB_LP_IRQn 1 */

/* USER CODE END USB_LP_IRQn 1 */
}

/**
* @brief This function handles TIM4 global interrupt.
*/


+ 1
- 1
sysinit.c View File

@@ -31,7 +31,7 @@

SET_DECLARE(sysinit_set, struct sysinit);

void
void __attribute__ ((constructor))
sysinit_run(void)
{
const int cnt = SET_COUNT(sysinit_set);


Loading…
Cancel
Save