CC=arm-none-eabi-gcc AR=arm-none-eabi-ar ########################################### vpath %.c targets/cmsis/TARGET_STM/TARGET_STM32F4 targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_DEV_BRIDGE SRCS = stm32f4xx_hal.c \ stm32f4xx_hal_adc.c \ stm32f4xx_hal_adc_ex.c \ stm32f4xx_hal_can.c \ stm32f4xx_hal_cec.c \ stm32f4xx_hal_cortex.c \ stm32f4xx_hal_crc.c \ stm32f4xx_hal_cryp.c \ stm32f4xx_hal_cryp_ex.c \ stm32f4xx_hal_dac.c \ stm32f4xx_hal_dac_ex.c \ stm32f4xx_hal_dcmi.c \ stm32f4xx_hal_dcmi_ex.c \ stm32f4xx_hal_dma2d.c \ stm32f4xx_hal_dma.c \ stm32f4xx_hal_dma_ex.c \ stm32f4xx_hal_dsi.c \ stm32f4xx_hal_eth.c \ stm32f4xx_hal_flash.c \ stm32f4xx_hal_flash_ex.c \ stm32f4xx_hal_flash_ramfunc.c \ stm32f4xx_hal_fmpi2c.c \ stm32f4xx_hal_fmpi2c_ex.c \ stm32f4xx_hal_gpio.c \ stm32f4xx_hal_hash.c \ stm32f4xx_hal_hash_ex.c \ stm32f4xx_hal_hcd.c \ stm32f4xx_hal_i2c.c \ stm32f4xx_hal_i2c_ex.c \ stm32f4xx_hal_i2s.c \ stm32f4xx_hal_i2s_ex.c \ stm32f4xx_hal_irda.c \ stm32f4xx_hal_iwdg.c \ stm32f4xx_hal_lptim.c \ stm32f4xx_hal_ltdc.c \ stm32f4xx_hal_ltdc_ex.c \ stm32f4xx_hal_msp_template.c \ stm32f4xx_hal_nand.c \ stm32f4xx_hal_nor.c \ stm32f4xx_hal_pccard.c \ stm32f4xx_hal_pcd.c \ stm32f4xx_hal_pcd_ex.c \ stm32f4xx_hal_pwr.c \ stm32f4xx_hal_pwr_ex.c \ stm32f4xx_hal_qspi.c \ stm32f4xx_hal_rcc.c \ stm32f4xx_hal_rcc_ex.c \ stm32f4xx_hal_rng.c \ stm32f4xx_hal_rtc.c \ stm32f4xx_hal_rtc_ex.c \ stm32f4xx_hal_sai.c \ stm32f4xx_hal_sai_ex.c \ stm32f4xx_hal_sd.c \ stm32f4xx_hal_sdram.c \ stm32f4xx_hal_smartcard.c \ stm32f4xx_hal_spdifrx.c \ stm32f4xx_hal_spi.c \ stm32f4xx_hal_sram.c \ stm32f4xx_hal_tim.c \ stm32f4xx_hal_tim_ex.c \ stm32f4xx_hal_uart.c \ stm32f4xx_hal_usart.c \ stm32f4xx_hal_wwdg.c \ stm32f4xx_ll_fmc.c \ stm32f4xx_ll_fsmc.c \ stm32f4xx_ll_sdmmc.c \ stm32f4xx_ll_usb.c \ cmsis_nvic.c \ hal_tick.c OBJS = $(SRCS:.c=.o) all: libstmf4.a libstmf4.a: $(OBJS) $(AR) -r $@ $(OBJS) clean: rm -f $(OBJS) libstmf4.a x-test.c?h=ice40mkm&id=a5850b450733141f320a817c523b85dff49f52eb'>commitdiff
path: root/projects/rtos-test/mutex-test.c
blob: 402f9ba7269870af523d3ed787639d5471dc6c46 (plain) (tree)







































                                                      
#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");
}