From 1175ff63f2a8c4762692551403862f9f0789aef8 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Tue, 2 May 2017 17:10:02 -0400 Subject: Merge branch 'init_cleanup' into no-rtos Clean up Makefiles and initialization code. --- projects/board-test/Makefile | 5 ++- projects/board-test/fmc-perf.c | 15 -------- projects/board-test/fmc-probe.c | 20 ----------- projects/board-test/fmc-test.c | 7 ++-- projects/board-test/led-test.c | 1 - projects/board-test/rtc-test.c | 70 ++++++++++++++++++------------------- projects/board-test/short-test.c | 1 - projects/board-test/uart-test.c | 1 - projects/bootloader/Makefile | 1 - projects/bootloader/bootloader.c | 8 ++--- projects/cli-test/Makefile | 1 - projects/cli-test/mgmt-test.c | 12 ------- projects/cli-test/test_sdram.c | 1 - projects/hsm/Makefile | 14 ++++---- projects/hsm/hsm.c | 4 --- projects/hsm/mgmt-misc.c | 6 ++-- projects/libhal-test/Makefile | 3 -- projects/libhal-test/main.c | 11 ------ projects/rtos-test/Makefile | 22 ------------ projects/rtos-test/mutex-test.c | 40 --------------------- projects/rtos-test/semaphore-test.c | 34 ------------------ projects/rtos-test/thread-test.c | 24 ------------- 22 files changed, 55 insertions(+), 246 deletions(-) delete mode 100644 projects/rtos-test/Makefile delete mode 100644 projects/rtos-test/mutex-test.c delete mode 100644 projects/rtos-test/semaphore-test.c delete mode 100644 projects/rtos-test/thread-test.c (limited to 'projects') diff --git a/projects/board-test/Makefile b/projects/board-test/Makefile index bb6a8cf..45e75fc 100644 --- a/projects/board-test/Makefile +++ b/projects/board-test/Makefile @@ -1,4 +1,7 @@ -TEST = led-test short-test uart-test fmc-test fmc-perf fmc-probe rtc-test spiflash-perf keystore-perf +TEST = led-test short-test uart-test fmc-test fmc-perf fmc-probe +ifeq (${BOARD},TARGET_CRYPTECH_ALPHA) +TEST += rtc-test spiflash-perf keystore-perf +endif all: $(TEST:=.elf) diff --git a/projects/board-test/fmc-perf.c b/projects/board-test/fmc-perf.c index 0c753a7..5ed47ec 100644 --- a/projects/board-test/fmc-perf.c +++ b/projects/board-test/fmc-perf.c @@ -1,7 +1,6 @@ /* * Test read/write performance of the fmc bus */ -#include "stm32f4xx_hal.h" #include "stm-init.h" #include "stm-led.h" #include "stm-fmc.h" @@ -99,23 +98,9 @@ static void test_write(void) int main(void) { stm_init(); - - uart_send_string("Keep calm for Novena boot...\r\n"); - - // Blink blue LED for six seconds to not upset the Novena at boot. - led_on(LED_BLUE); - for (int i = 0; i < 12; i++) { - HAL_Delay(500); - led_toggle(LED_BLUE); - } - led_off(LED_BLUE); - // initialize rng MX_RNG_Init(); - // prepare fmc interface - fmc_init(); - sanity(); time_check("read ", test_read()); diff --git a/projects/board-test/fmc-probe.c b/projects/board-test/fmc-probe.c index 55d3521..5f7fdb5 100644 --- a/projects/board-test/fmc-probe.c +++ b/projects/board-test/fmc-probe.c @@ -2,7 +2,6 @@ * in other cases, it will be the core name and version strings. */ -#include "stm32f4xx_hal.h" #include "stm-init.h" #include "stm-led.h" #include "stm-fmc.h" @@ -32,27 +31,8 @@ static uint32_t read0(uint32_t addr) int main(void) { - int i; - stm_init(); - - uart_send_string("Keep calm for Novena boot...\r\n"); - - // Blink blue LED for six seconds to not upset the Novena at boot. - led_on(LED_BLUE); - for (i = 0; i < 12; i++) { - HAL_Delay(500); - led_toggle(LED_BLUE); - } - - // prepare fmc interface - fmc_init(); - - // turn on green led, turn off other leds led_on(LED_GREEN); - led_off(LED_YELLOW); - led_off(LED_RED); - led_off(LED_BLUE); for (uint32_t addr = 0; addr < 0x00080000; addr += 4) { uint32_t data = read0(addr); diff --git a/projects/board-test/fmc-test.c b/projects/board-test/fmc-test.c index bc5a768..c6a37e6 100644 --- a/projects/board-test/fmc-test.c +++ b/projects/board-test/fmc-test.c @@ -34,11 +34,11 @@ //------------------------------------------------------------------------------ // Headers //------------------------------------------------------------------------------ -#include "stm32f4xx_hal.h" #include "stm-init.h" #include "stm-led.h" #include "stm-fmc.h" #include "stm-uart.h" +#include "stm-fpgacfg.h" //------------------------------------------------------------------------------ // Defines @@ -88,7 +88,7 @@ int main(void) uart_send_string("Keep calm for FPGA bitstream loading...\r\n"); - // Blink blue LED until the FPGA reports it has loaded it's bitstream + // Blink blue LED until the FPGA reports it has loaded its bitstream led_on(LED_BLUE); while (! fpgacfg_check_done()) { for (i = 0; i < 4; i++) { @@ -100,9 +100,6 @@ int main(void) // initialize rng MX_RNG_Init(); - // prepare fmc interface - fmc_init(); - // turn on green led, turn off other leds led_on(LED_GREEN); led_off(LED_YELLOW); diff --git a/projects/board-test/led-test.c b/projects/board-test/led-test.c index 7e72788..2ec7c9d 100644 --- a/projects/board-test/led-test.c +++ b/projects/board-test/led-test.c @@ -1,7 +1,6 @@ /* * Blink the four LEDs on the rev01 board in a pattern. */ -#include "stm32f4xx_hal.h" #include "stm-init.h" #include "stm-led.h" diff --git a/projects/board-test/rtc-test.c b/projects/board-test/rtc-test.c index b8a7511..f1c2db1 100644 --- a/projects/board-test/rtc-test.c +++ b/projects/board-test/rtc-test.c @@ -8,7 +8,6 @@ */ #include -#include "stm32f4xx_hal.h" #include "stm-init.h" #include "stm-led.h" #include "stm-uart.h" @@ -23,18 +22,18 @@ uint32_t i; uint32_t device_ready(uint16_t i2c_addr) { - uart_send_string2(STM_UART_MGMT, "Checking readiness of 0x"); - uart_send_number2(STM_UART_MGMT, i2c_addr, 4, 16); - uart_send_string2(STM_UART_MGMT, "..."); + uart_send_string("Checking readiness of 0x"); + uart_send_hex(i2c_addr, 4); + uart_send_string("..."); if (rtc_device_ready(i2c_addr) == HAL_OK) { - uart_send_string2(STM_UART_MGMT, "OK\r\n"); + uart_send_string("OK\r\n"); return 1; } - uart_send_string2(STM_UART_MGMT, "Not ready (0x"); - uart_send_number2(STM_UART_MGMT, i, 4, 16); - uart_send_string2(STM_UART_MGMT, ")\r\n"); + uart_send_string("Not ready (0x"); + uart_send_hex(i, 4); + uart_send_string(")\r\n"); return 0; } @@ -44,34 +43,34 @@ void send_byte(const uint16_t i2c_addr, const uint8_t value) { uint8_t ch = value; - uart_send_string2(STM_UART_MGMT, "Sending "); - uart_send_number2(STM_UART_MGMT, ch, 2, 16); - uart_send_string2(STM_UART_MGMT, " to 0x"); - uart_send_number2(STM_UART_MGMT, i2c_addr, 4, 16); - uart_send_string2(STM_UART_MGMT, "..."); + uart_send_string("Sending "); + uart_send_hex(ch, 2); + uart_send_string(" to 0x"); + uart_send_hex(i2c_addr, 4); + uart_send_string("..."); if (rtc_send_byte(i2c_addr, ch, 1000) != HAL_OK) { - uart_send_string2(STM_UART_MGMT, "Timeout\r\n"); + uart_send_string("Timeout\r\n"); Error_Handler(); } - uart_send_string2(STM_UART_MGMT, "OK\r\n"); + uart_send_string("OK\r\n"); } void read_bytes (uint8_t *buf, const uint16_t i2c_addr, const uint8_t len) { - uart_send_string2(STM_UART_MGMT, "Reading "); - uart_send_number2(STM_UART_MGMT, len, 3, 10); - uart_send_string2(STM_UART_MGMT, " bytes from 0x"); - uart_send_number2(STM_UART_MGMT, i2c_addr, 4, 16); - uart_send_string2(STM_UART_MGMT, "..."); + uart_send_string("Reading "); + uart_send_integer(len, 1); + uart_send_string(" bytes from 0x"); + uart_send_hex(i2c_addr, 4); + uart_send_string("..."); if (rtc_read_bytes(i2c_addr, buf, len, 1000) != HAL_OK) { - uart_send_string2(STM_UART_MGMT, "Timeout\r\n"); + uart_send_string("Timeout\r\n"); Error_Handler(); } - uart_send_string2(STM_UART_MGMT, "OK\r\n"); + uart_send_string("OK\r\n"); } void request_data(uint8_t *buf, const uint16_t i2c_addr, const uint8_t offset, const uint8_t bytes) @@ -85,8 +84,8 @@ void print_time() request_data(buf, RTC_RTC_ADDR, RTC_TIME_OFFSET, RTC_TIME_BYTES); for (i = 0; i < RTC_TIME_BYTES; i++) { - uart_send_number2(STM_UART_MGMT, buf[i], 2, 16); - uart_send_string2(STM_UART_MGMT, " "); + uart_send_hex(buf[i], 2); + uart_send_string(" "); } } @@ -94,37 +93,37 @@ void dump_sram() { request_data(buf, RTC_RTC_ADDR, 0x0, RTC_SRAM_TOTAL_BYTES); - uart_send_string2(STM_UART_MGMT, "SRAM contents:\r\n"); + uart_send_string("SRAM contents:\r\n"); uart_send_hexdump(STM_UART_MGMT, buf, 0, RTC_SRAM_TOTAL_BYTES); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string("\r\n"); } void dump_eeprom() { request_data(buf, RTC_EEPROM_ADDR, 0x0, RTC_EEPROM_TOTAL_BYTES); - uart_send_string2(STM_UART_MGMT, "EEPROM contents:\r\n"); + uart_send_string("EEPROM contents:\r\n"); uart_send_hexdump(STM_UART_MGMT, buf, 0, RTC_EEPROM_TOTAL_BYTES); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string("\r\n"); request_data(buf, RTC_EEPROM_ADDR, RTC_EEPROM_EUI48_OFFSET, RTC_EEPROM_EUI48_BYTES); - uart_send_string2(STM_UART_MGMT, "EEPROM EUI-48:\r\n"); + uart_send_string("EEPROM EUI-48:\r\n"); uart_send_hexdump(STM_UART_MGMT, buf, RTC_EEPROM_EUI48_OFFSET, RTC_EEPROM_EUI48_BYTES); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string("\r\n"); } void enable_oscillator() { - uart_send_string2(STM_UART_MGMT, "Enabling oscillator...\r\n"); + uart_send_string("Enabling oscillator...\r\n"); if (rtc_enable_oscillator() != HAL_OK) { - uart_send_string2(STM_UART_MGMT, "Timeout\r\n"); + uart_send_string("Timeout\r\n"); Error_Handler(); } - uart_send_string2(STM_UART_MGMT, "OK\r\n"); + uart_send_string("OK\r\n"); } @@ -132,7 +131,8 @@ int main() { stm_init(); - uart_send_string2(STM_UART_MGMT, "\r\n\r\n*** Init done\r\n"); + uart_set_default(STM_UART_MGMT); + uart_send_string("\r\n\r\n*** Init done\r\n"); dump_sram(); dump_eeprom(); @@ -148,7 +148,7 @@ main() print_time(buf); - uart_send_string2(STM_UART_MGMT, "\r\n\r\n"); + uart_send_string("\r\n\r\n"); HAL_GPIO_TogglePin(LED_PORT, LED_GREEN); DELAY(); diff --git a/projects/board-test/short-test.c b/projects/board-test/short-test.c index 27b8e7a..db0251b 100644 --- a/projects/board-test/short-test.c +++ b/projects/board-test/short-test.c @@ -5,7 +5,6 @@ * Toggles the BLUE LED slowly and the RED LED for every * character sent. */ -#include "stm32f4xx_hal.h" #include "stm-init.h" #include "stm-led.h" #include "stm-uart.h" diff --git a/projects/board-test/uart-test.c b/projects/board-test/uart-test.c index be06863..9a56dee 100644 --- a/projects/board-test/uart-test.c +++ b/projects/board-test/uart-test.c @@ -6,7 +6,6 @@ * Toggles the BLUE LED slowly and the GREEN LED for every * character sent. */ -#include "stm32f4xx_hal.h" #include "stm-init.h" #include "stm-led.h" #include "stm-uart.h" diff --git a/projects/bootloader/Makefile b/projects/bootloader/Makefile index fe96982..6c1012f 100644 --- a/projects/bootloader/Makefile +++ b/projects/bootloader/Makefile @@ -7,7 +7,6 @@ BOARD_OBJS = \ $(TOPLEVEL)/stm-fmc.o \ $(TOPLEVEL)/stm-uart.o \ $(TOPLEVEL)/spiflash_n25q128.o \ - $(TOPLEVEL)/stm-fpgacfg.o \ $(TOPLEVEL)/stm-keystore.o \ $(TOPLEVEL)/stm-flash.o \ $(TOPLEVEL)/syscalls.o \ diff --git a/projects/bootloader/bootloader.c b/projects/bootloader/bootloader.c index 683a498..c0f981f 100644 --- a/projects/bootloader/bootloader.c +++ b/projects/bootloader/bootloader.c @@ -38,7 +38,9 @@ #include "stm-fmc.h" #include "dfu.h" -#undef HAL_Delay +/* stub these out to avoid linker error */ +void fpgacfg_init(void) { } +void sdram_init(void) { } /* Linker symbols are strange in C. Make regular pointers for sanity. */ __IO uint32_t *dfu_control = &CRYPTECH_DFU_CONTROL; @@ -91,13 +93,11 @@ int should_dfu() /* Sleep for specified number of seconds -- used after bad PIN. */ void hal_sleep(const unsigned seconds) { HAL_Delay(seconds * 1000); } -int -main() +int main(void) { int status; stm_init(); - fmc_init(); uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\nThis is the bootloader speaking..."); diff --git a/projects/cli-test/Makefile b/projects/cli-test/Makefile index 189a15d..e01b243 100644 --- a/projects/cli-test/Makefile +++ b/projects/cli-test/Makefile @@ -14,7 +14,6 @@ OBJS = \ test_sdram.o CFLAGS += -I$(LIBCLI_SRC) -I$(LIBHAL_SRC) -CFLAGS += -I$(RTOS_DIR)/rtos -I$(RTOS_DIR)/rtx/TARGET_CORTEX_M LIBS += $(LIBCLI_BLD)/libcli.a $(LIBHAL_BLD)/libhal.a $(LIBTFM_BLD)/libtfm.a diff --git a/projects/cli-test/mgmt-test.c b/projects/cli-test/mgmt-test.c index 59f0b6e..1a22996 100644 --- a/projects/cli-test/mgmt-test.c +++ b/projects/cli-test/mgmt-test.c @@ -50,7 +50,6 @@ static int cmd_test_sdram(struct cli_def *cli, const char *command, char *argv[], int argc) { // run external memory initialization sequence - HAL_StatusTypeDef status; int ok, num_cycles = 1, i, test_completed; if (argc == 1) { @@ -59,13 +58,6 @@ static int cmd_test_sdram(struct cli_def *cli, const char *command, char *argv[] if (num_cycles < 1) num_cycles = 1; } - cli_print(cli, "Initializing SDRAM"); - status = sdram_init(); - if (status != HAL_OK) { - cli_print(cli, "Failed initializing SDRAM: %i", (int) status); - return CLI_OK; - } - for (i = 1; i <= num_cycles; i++) { cli_print(cli, "Starting SDRAM test (%i/%i)", i, num_cycles); test_completed = 0; @@ -136,10 +128,6 @@ static int cmd_test_fmc(struct cli_def *cli, const char *command, char *argv[], } } - // prepare fmc interface - cli_print(cli, "Initializing FMC interface"); - fmc_init(); - // turn on green led, turn off other leds led_on(LED_GREEN); led_off(LED_YELLOW); diff --git a/projects/cli-test/test_sdram.c b/projects/cli-test/test_sdram.c index e720667..4961b94 100644 --- a/projects/cli-test/test_sdram.c +++ b/projects/cli-test/test_sdram.c @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stm32f4xx_hal.h" #include "stm-led.h" #include "stm-sdram.h" #include "test_sdram.h" diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index 59bad25..927c9f1 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -2,13 +2,13 @@ PROJ = hsm # objs in addition to $(PROJ).o OBJS = mgmt-cli.o \ - mgmt-firmware.c \ - mgmt-bootloader.c \ - mgmt-fpga.c \ - mgmt-keystore.c \ - mgmt-masterkey.c \ - mgmt-misc.c \ - mgmt-task.c \ + mgmt-firmware.o \ + mgmt-bootloader.o \ + mgmt-fpga.o \ + mgmt-keystore.o \ + mgmt-masterkey.o \ + mgmt-misc.o \ + mgmt-task.o \ log.o BOARD_OBJS += $(TOPLEVEL)/task.o diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c index 55c41db..8a8f441 100644 --- a/projects/hsm/hsm.c +++ b/projects/hsm/hsm.c @@ -397,11 +397,7 @@ int main(void) { stm_init(); uart_set_default(STM_UART_MGMT); - led_on(LED_GREEN); - /* Prepare FMC interface. */ - fmc_init(); - sdram_init(); if (hal_rpc_server_init() != LIBHAL_OK) Error_Handler(); diff --git a/projects/hsm/mgmt-misc.c b/projects/hsm/mgmt-misc.c index 1861304..ccd032b 100644 --- a/projects/hsm/mgmt-misc.c +++ b/projects/hsm/mgmt-misc.c @@ -60,7 +60,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal cli_print(cli, "OK, write size (4 bytes), data in %li byte chunks, CRC-32 (4 bytes)", (uint32_t) n); - if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 1000) != CMSIS_HAL_OK) { + if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 2000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -75,7 +75,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal if (filesize < n) n = filesize; - if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 1000) != CMSIS_HAL_OK) { + if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 2000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -96,7 +96,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal my_crc = hal_crc32_finalize(my_crc); cli_print(cli, "Send CRC-32"); - uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 1000); + uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 2000); cli_print(cli, "CRC-32 0x%x, calculated CRC 0x%x", (unsigned int) crc, (unsigned int) my_crc); if (crc == my_crc) { cli_print(cli, "CRC checksum MATCHED"); diff --git a/projects/libhal-test/Makefile b/projects/libhal-test/Makefile index 7aa8d3e..1a2106e 100644 --- a/projects/libhal-test/Makefile +++ b/projects/libhal-test/Makefile @@ -17,9 +17,6 @@ vpath %.c $(LIBHAL_SRC)/tests $(LIBHAL_SRC)/utils $(OBJCOPY) -O binary $*.elf $*.bin $(SIZE) $*.elf -# don't automatically delete objects, to avoid a lot of unnecessary rebuilding -.SECONDARY: $(BOARD_OBJS) $(LIBC_OBJS) - clean: rm -f *.o *.mo rm -f *.elf diff --git a/projects/libhal-test/main.c b/projects/libhal-test/main.c index a40871b..fff8c38 100644 --- a/projects/libhal-test/main.c +++ b/projects/libhal-test/main.c @@ -43,18 +43,7 @@ extern void __main(void); int main(void) { stm_init(); - -#ifdef TARGET_CRYPTECH_DEV_BRIDGE - // Blink blue LED for six seconds to not upset the Novena at boot. - led_on(LED_BLUE); - for (int i = 0; i < 12; i++) { - HAL_Delay(500); - led_toggle(LED_BLUE); - } - led_off(LED_BLUE); -#endif led_on(LED_GREEN); - fmc_init(); __main(); diff --git a/projects/rtos-test/Makefile b/projects/rtos-test/Makefile deleted file mode 100644 index 9e58a41..0000000 --- a/projects/rtos-test/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -TEST = thread-test semaphore-test mutex-test - -CFLAGS += -I$(RTOS_DIR)/rtos -I$(RTOS_DIR)/rtx/TARGET_CORTEX_M - -LIBS += $(RTOS_DIR)/librtos.a - -all: $(TEST:=.elf) - -%.elf: %.o $(BOARD_OBJS) $(LIBS) - $(CC) $(CFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map - $(OBJCOPY) -O ihex $*.elf $*.hex - $(OBJCOPY) -O binary $*.elf $*.bin - $(OBJDUMP) -St $*.elf >$*.lst - $(SIZE) $*.elf - -clean: - rm -f *.o - rm -f *.elf - rm -f *.hex - rm -f *.bin - rm -f *.map - rm -f *.lst diff --git a/projects/rtos-test/mutex-test.c b/projects/rtos-test/mutex-test.c deleted file mode 100644 index 402f9ba..0000000 --- a/projects/rtos-test/mutex-test.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "cmsis_os.h" - -#include "stm-init.h" -#include "stm-uart.h" - -osMutexId stdio_mutex; -osMutexDef(stdio_mutex); - -void notify(const char* name, int state) { - osMutexWait(stdio_mutex, osWaitForever); - //printf("%s: %d\n\r", name, state); - uart_send_string(name); - uart_send_string(": "); - uart_send_integer(state, 1); - uart_send_string("\r\n"); - osMutexRelease(stdio_mutex); -} - -void test_thread(void const *args) { - while (1) { - notify((const char*)args, 0); osDelay(1000); - notify((const char*)args, 1); osDelay(1000); - } -} - -void t2(void const *argument) {test_thread("Th 2");} -osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE); - -void t3(void const *argument) {test_thread("Th 3");} -osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE); - -int main() { - stm_init(); - stdio_mutex = osMutexCreate(osMutex(stdio_mutex)); - - osThreadCreate(osThread(t2), NULL); - osThreadCreate(osThread(t3), NULL); - - test_thread((void *)"Th 1"); -} diff --git a/projects/rtos-test/semaphore-test.c b/projects/rtos-test/semaphore-test.c deleted file mode 100644 index 3a3b5de..0000000 --- a/projects/rtos-test/semaphore-test.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "cmsis_os.h" - -#include "stm-init.h" -#include "stm-uart.h" - -osSemaphoreId two_slots; -osSemaphoreDef(two_slots); - -void test_thread(void const *name) { - while (1) { - osSemaphoreWait(two_slots, osWaitForever); - //printf("%s\n\r", (const char*)name); - uart_send_string((const char*)name); - uart_send_string("\r\n"); - osDelay(1000); - osSemaphoreRelease(two_slots); - } -} - -void t2(void const *argument) {test_thread("Th 2");} -osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE); - -void t3(void const *argument) {test_thread("Th 3");} -osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE); - -int main (void) { - stm_init(); - two_slots = osSemaphoreCreate(osSemaphore(two_slots), 2); - - osThreadCreate(osThread(t2), NULL); - osThreadCreate(osThread(t3), NULL); - - test_thread((void *)"Th 1"); -} diff --git a/projects/rtos-test/thread-test.c b/projects/rtos-test/thread-test.c deleted file mode 100644 index 8b31a26..0000000 --- a/projects/rtos-test/thread-test.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "cmsis_os.h" - -#include "stm-init.h" -#include "stm-led.h" - -void led2_thread(void const *args) -{ - while (1) { - led_toggle(LED_BLUE); - osDelay(1000); - } -} -osThreadDef(led2_thread, osPriorityNormal, DEFAULT_STACK_SIZE); - -int main() -{ - stm_init(); - osThreadCreate(osThread(led2_thread), NULL); - - while (1) { - led_toggle(LED_GREEN); - osDelay(500); - } -} -- cgit v1.2.3