示例#1
0
/**
 * CAN test main function
 *
 * @return Nothing really...
 */
int main(void)
{
	int timer;
	uint8_t data[1];

	mcu_init();
	led_init();
	sys_tick_init();
	can_setup();

	timer = sys_tick_get_timer();

	data[0] = 10;

	while (true) {
		if (sys_tick_check_timer(timer, 10000)) {
			data[0]++;
			timer = sys_tick_get_timer();
#ifdef CAN__SEND
#ifdef CAN_ADDR
			can_trans(CAN_ADDR, data, 1);
#else
			can_trans(CAN__DEFAULT_ADDR, data, 1);
#endif
#endif
		}
	}
}
示例#2
0
int main()
{
  	uart_config_t uart_conf;

	DISABLE_IRQ();

	hal_clk_init();
	sys_tick_init();
	I2cInit( &I2c, I2C_SCL, I2C_SDA );

	uart_conf.baud = 9600;
	uart_conf.word_length = 8;
	uart_conf.parity = NONE;
	uart_conf.stop_bits = 1;
	uart_init(&uart_conf);

	ENABLE_IRQ();

    app_init();
	
	DISABLE_IRQ();
	led_init();
 
	 
	while(1){
        /** polling all events */
        app_evt();
        led_evt();
	}
}
示例#3
0
文件: sys.c 项目: othane/mos
// setup the basic components of any system
void sys_init(void)
{
	sys_clk_init();
	sys_interrupt_init();
	sys_tick_init();
	sys_temp_init();
	sys_log_init();
}
示例#4
0
bool HAL_STM32M0::init(void)
{
#ifdef HAL_SYS_TICK
	SysTick_Config(SystemCoreClock / SYSCLOCK_PERIOD);
    sys_tick_init();
#endif
    return true;
}
示例#5
0
/**
 * Main function of the motor controller.
 */
int main(void)
{
	int demo_counter;
	int demo_dir;

	system_init();
	led_init();
	debug_pins_init();
	gprot_init();
	usart_init();
	sys_tick_init();
	cpu_load_process_init();
	comm_process_init();
	sensor_process_init();
	//adc_init();
	pwm_init();
	comm_tim_init();
	control_process_init();
	bemf_hd_init();

	demo_counter = 500;
	demo_dir = 1;
	demo = false;

	while (true) {
		run_cpu_load_process();

/*
		if (adc_new_data_trigger) {
			adc_new_data_trigger = false;
			run_sensor_process();
		}
*/

		if (*comm_process_trigger) {
			*comm_process_trigger = false;
			run_comm_process();
		}

		run_control_process();

		if (demo) {
			if (demo_counter == 0) {
				demo_counter = 300;
				pwm_val += demo_dir;
				if (pwm_val > 2000) {
					demo_dir = -1;
				}

				if (pwm_val < 500) {
					demo_dir = 1;
				}
			} else {
				demo_counter--;
			}
		}
	}
}
示例#6
0
void main()
{
	uint32_t timestamp;
	sx1276_config_t sx1276_config;

	DISABLE_IRQ();

	hal_clk_init();
	sys_tick_init();

	ENABLE_IRQ();

    led_init();
	sx1276_init(LORA, NULL);

	sx1276_config.frequency = 433400000;
	sx1276_config.spread_factor = SX1276_SF7;
	sx1276_config.bandwidth = SX1276_BW_125K;
	sx1276_config.coding_rate = SX1276_CR1;
	sx1276_config.crc_mode = SX1276_CRC_ON;
	sx1276_config.header_mode = SX1276_HEADER_ENABLE;
	sx1276_config.payload_len = 0;		// Set in HEADER disable mode
	sx1276_config.tx_power = 20;
	sx1276_config.tx_preamble_len = 12;
	sx1276_config.rx_preamble_len = 12;
	sx1276_set_config(&sx1276_config);

    /** Enter HF/LF test mode */
    if(sx1276_config.frequency < SX1276_LF_FREQ_MAX){
        sx1276_write( 0x01, 0x88 );
    }else{
        sx1276_write( 0x01, 0x80 );
    }
    sx1276_write( 0x3D, 0xA1 );
    sx1276_write( 0x36, 0x01 );
    sx1276_write( 0x1e, 0x08 );

    /** Enable TX to enter continuous wave transmitting mode */
    sx1276_send(NULL, 0, 0);

    /** Get system tick */
    timestamp = millis();

	while(1){
		/** Blink LED every 1s*/
        if( millis() - timestamp > 1000){
			timestamp = millis();
            led_blink(LED0, 100);
		}

        /** LED event polling */
        led_evt();
	}
}
/**
 * Sys Tick soft timer test main function
 */
int main(void){
	uint32_t timer;

	mcu_init();
	led_init();
	sys_tick_init();

	(void)sys_tick_timer_register(sys_tick_timer_callback, 1000000);

	while (true) {
		timer = sys_tick_get_timer();
		while (!sys_tick_check_timer(timer, 50000)) {
			__asm("nop");
		}
		TOGGLE(LED_GREEN);
	}
}
示例#8
0
void main()
{
	uint32_t timestamp;

	DISABLE_IRQ();

	hal_clk_init();
	sys_tick_init();

	ENABLE_IRQ();

    sx1276_init(FSK, NULL);

    //Frequency 433.4MHz
    sx1276_fsk_set_frf(433400000);
    //Fdev 25KHz
    sx1276_fsk_set_fdev(25000);
    //Bitrate 10KHz
    sx1276_fsk_set_bitrate(10000);
    //Set RxBw depends on bitrate and fdev
    sx1276_set_rxbw(25000, 10000);

    sx1276_write(0x10,0xFF);

    //Disable AGC, set G1
    sx1276_write(0x0C,0x20);
    sx1276_write(0x0D,0x00);

    sx1276_fsk_rx_test_mode();

    timestamp = millis();

	while(1){
		if( millis() - timestamp > 1000){
			timestamp = millis();
            led_blink(LED0,100);
		}
        led_evt();
	}
}
示例#9
0
void board_init(void)
{
	interrupt_init();
	sys_tick_init();
	pendSV_init();
}
示例#10
0
int main(void) {
    // TODO disable JTAG

    // update the SystemCoreClock variable
    SystemCoreClockUpdate();

    // set interrupt priority config to use all 4 bits for pre-empting
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

    // enable the CCM RAM and the GPIO's
    RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN;

#if MICROPY_HW_HAS_SDCARD
    {
        // configure SDIO pins to be high to start with (apparently makes it more robust)
        // FIXME this is not making them high, it just makes them outputs...
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOC, &GPIO_InitStructure);

        // Configure PD.02 CMD line
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_Init(GPIOD, &GPIO_InitStructure);
    }
#endif
#if defined(NETDUINO_PLUS_2)
    {
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

#if MICROPY_HW_HAS_SDCARD
        // Turn on the power enable for the sdcard (PB1)
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET);
#endif

        // Turn on the power for the 5V on the expansion header (PB2)
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET);
    }
#endif

    // basic sub-system init
    sys_tick_init();
    pendsv_init();
    led_init();

#if MICROPY_HW_ENABLE_RTC
    rtc_init();
#endif

    // turn on LED to indicate bootup
    led_state(PYB_LED_G1, 1);

    // more sub-system init
#if MICROPY_HW_HAS_SDCARD
    sdcard_init();
#endif
    storage_init();

    // uncomment these 2 lines if you want REPL on USART_6 (or another usart) as well as on USB VCP
    //pyb_usart_global_debug = PYB_USART_YA;
    //usart_init(pyb_usart_global_debug, 115200);

    int first_soft_reset = true;

soft_reset:

    // GC init
    gc_init(&_heap_start, &_heap_end);

    // Micro Python init
    qstr_init();
    mp_init();
    mp_obj_list_init(mp_sys_path, 0);
    mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_));
    mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_lib));
    mp_obj_list_init(mp_sys_argv, 0);

    exti_init();

#if MICROPY_HW_HAS_SWITCH
    switch_init();
#endif

#if MICROPY_HW_HAS_LCD
    // LCD init (just creates class, init hardware by calling LCD())
    lcd_init();
#endif

#if MICROPY_HW_ENABLE_SERVO
    // servo
    servo_init();
#endif

#if MICROPY_HW_ENABLE_TIMER
    // timer
    timer_init();
#endif

#if MICROPY_HW_ENABLE_RNG
    // RNG
    RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
    RNG_Cmd(ENABLE);
#endif

    pin_map_init();

    // add some functions to the builtin Python namespace
    mp_store_name(MP_QSTR_help, mp_make_function_n(0, pyb_help));
    mp_store_name(MP_QSTR_open, mp_make_function_n(2, pyb_io_open));

    // load the pyb module
    mp_module_register(MP_QSTR_pyb, (mp_obj_t)&pyb_module);

    // check if user switch held (initiates reset of filesystem)
    bool reset_filesystem = false;
#if MICROPY_HW_HAS_SWITCH
    if (switch_get()) {
        reset_filesystem = true;
        for (int i = 0; i < 50; i++) {
            if (!switch_get()) {
                reset_filesystem = false;
                break;
            }
            sys_tick_delay_ms(10);
        }
    }
#endif
    // local filesystem init
    {
        // try to mount the flash
        FRESULT res = f_mount(&fatfs0, "0:", 1);
        if (!reset_filesystem && res == FR_OK) {
            // mount sucessful
        } else if (reset_filesystem || res == FR_NO_FILESYSTEM) {
            // no filesystem, so create a fresh one
            // TODO doesn't seem to work correctly when reset_filesystem is true...

            // LED on to indicate creation of LFS
            led_state(PYB_LED_R2, 1);
            uint32_t stc = sys_tick_counter;

            res = f_mkfs("0:", 0, 0);
            if (res == FR_OK) {
                // success creating fresh LFS
            } else {
                __fatal_error("could not create LFS");
            }

            // create src directory
            res = f_mkdir("0:/src");
            // ignore result from mkdir

            // create empty main.py
            FIL fp;
            f_open(&fp, "0:/src/main.py", FA_WRITE | FA_CREATE_ALWAYS);
            UINT n;
            f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n);
            // TODO check we could write n bytes
            f_close(&fp);

            // keep LED on for at least 200ms
            sys_tick_wait_at_least(stc, 200);
            led_state(PYB_LED_R2, 0);
        } else {
            __fatal_error("could not access LFS");
        }
    }

    // make sure we have a /boot.py
    {
        FILINFO fno;
        FRESULT res = f_stat("0:/boot.py", &fno);
        if (res == FR_OK) {
            if (fno.fattrib & AM_DIR) {
                // exists as a directory
                // TODO handle this case
                // see http://elm-chan.org/fsw/ff/img/app2.c for a "rm -rf" implementation
            } else {
                // exists as a file, good!
            }
        } else {
            // doesn't exist, create fresh file

            // LED on to indicate creation of boot.py
            led_state(PYB_LED_R2, 1);
            uint32_t stc = sys_tick_counter;

            FIL fp;
            f_open(&fp, "0:/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
            UINT n;
            f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n);
            // TODO check we could write n bytes
            f_close(&fp);

            // keep LED on for at least 200ms
            sys_tick_wait_at_least(stc, 200);
            led_state(PYB_LED_R2, 0);
        }
    }

    // run /boot.py
    if (!pyexec_file("0:/boot.py")) {
        flash_error(4);
    }

    if (first_soft_reset) {
#if MICROPY_HW_HAS_MMA7660
        // MMA accel: init and reset address to zero
        accel_init();
#endif
    }

    // turn boot-up LED off
    led_state(PYB_LED_G1, 0);

#if MICROPY_HW_HAS_SDCARD
    // if an SD card is present then mount it on 1:/
    if (sdcard_is_present()) {
        FRESULT res = f_mount(&fatfs1, "1:", 1);
        if (res != FR_OK) {
            printf("[SD] could not mount SD card\n");
        } else {
            if (first_soft_reset) {
                // use SD card as medium for the USB MSD
                usbd_storage_select_medium(USBD_STORAGE_MEDIUM_SDCARD);
            }
        }
    }
#endif

#ifdef USE_HOST_MODE
    // USB host
    pyb_usb_host_init();
#elif defined(USE_DEVICE_MODE)
    // USB device
    pyb_usb_dev_init(PYB_USB_DEV_VCP_MSC);
#endif

    // run main script
    {
        vstr_t *vstr = vstr_new();
        vstr_add_str(vstr, "0:/");
        if (pyb_config_source_dir == MP_OBJ_NULL) {
            vstr_add_str(vstr, "src");
        } else {
            vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_source_dir));
        }
        vstr_add_char(vstr, '/');
        if (pyb_config_main == MP_OBJ_NULL) {
            vstr_add_str(vstr, "main.py");
        } else {
            vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_main));
        }
        if (!pyexec_file(vstr_str(vstr))) {
            flash_error(3);
        }
        vstr_free(vstr);
    }


#if MICROPY_HW_HAS_MMA7660
    // HID example
    if (0) {
        uint8_t data[4];
        data[0] = 0;
        data[1] = 1;
        data[2] = -2;
        data[3] = 0;
        for (;;) {
        #if MICROPY_HW_HAS_SWITCH
            if (switch_get()) {
                data[0] = 0x01; // 0x04 is middle, 0x02 is right
            } else {
                data[0] = 0x00;
            }
        #else
            data[0] = 0x00;
        #endif
            accel_start(0x4c /* ACCEL_ADDR */, 1);
            accel_send_byte(0);
            accel_restart(0x4c /* ACCEL_ADDR */, 0);
            for (int i = 0; i <= 1; i++) {
                int v = accel_read_ack() & 0x3f;
                if (v & 0x20) {
                    v |= ~0x1f;
                }
                data[1 + i] = v;
            }
            accel_read_nack();
            usb_hid_send_report(data);
            sys_tick_delay_ms(15);
        }
    }
#endif

#if MICROPY_HW_HAS_WLAN
    // wifi
    pyb_wlan_init();
    pyb_wlan_start();
#endif

    pyexec_repl();

    printf("PYB: sync filesystems\n");
    storage_flush();

    printf("PYB: soft reboot\n");

    first_soft_reset = false;
    goto soft_reset;
}
示例#11
0
/**
 * Main function of the motor controller.
 */
int main(void)
{
	int demo_counter;
	int demo_dir;

	system_init();
	led_init();
	debug_pins_init();
	gprot_init();
	usart_init();
	sys_tick_init();
	cpu_load_process_init();
	comm_process_init();
	sensor_process_init();
	adc_init();
	pwm_init();
	comm_tim_init();
	control_process_init();
	bemf_hd_init();

	demo_counter = 500;
	demo_dir = 1;
	demo = false;
	int flag = 0;

	while (true) {
		run_cpu_load_process();

		if(flag%1000000 == 0)
		{
			//gpc_send_string("Hello World, I am ALIVE\n", strlen("Hello World, I am ALIVE\n"));
			DEBUG("HELLO WORLD\n");
			flag++;
		}
		else
		{
			flag++;
		}
		if (*comm_process_trigger) {
			*comm_process_trigger = false;
			run_comm_process();
		}

		run_control_process();
		
		if (*sensor_process_trigger) {
			*sensor_process_trigger = false;
			run_sensor_process();
		}

		//TOGGLE(LED_BLUE);

		if (demo) {
			if (demo_counter == 0) {
				demo_counter = 300;
				pwm_val += demo_dir;
				if (pwm_val > 300) {
					demo_dir = -1;
				}

				if (pwm_val < 100) {
					demo_dir = 1;
				}
			} else {
				demo_counter--;
			}
		}
	}
}