src/main.c
/**
 * Initialize ports, timers and ISRs.
 */
Initialize ports, timers and ISRs.
Initialize ports timers and ISRs .
void init(void) {
	hsk_can_msg msgBoot;
	hsk_boot_extClock(CLK);
	IO_PORT_OUT_INIT(P3, -1, IO_PORT_STRENGTH_WEAK, IO_PORT_DRAIN_DISABLE, -1, 0);
	switch(hsk_flash_init(&persist, sizeof(persist), PERSIST_VERSION)) {
	case FLASH_PWR_FIRST:
		hsk_flash_write();
		break;
	case FLASH_PWR_RESET:
		persist.reset++;
		break;
	case FLASH_PWR_ON:
		persist.boot++;
		persist.reset = 0;
		hsk_flash_write();
		break;
	}
	IO_PORT_OUT_SET(P3, -1, -1, persist.boot);
	hsk_timer0_setup(1000, &tick0);
	hsk_timer0_enable();
	hsk_adc_init(ADC_RESOLUTION_10, 5);
	hsk_adc_open(7, &adc7);
	hsk_adc_enable();
	hsk_can_init(CAN1_IO, CAN1_BAUD);
	hsk_can_disable(CAN0);
	hsk_can_enable(CAN1);
	hsk_pwm_init(PWM_63, 10); 
	hsk_pwm_init(PWM_62, 10000); 
	hsk_pwm_enable();
	hsk_pwm_port_open(PWM_OUT_63_P37);
	hsk_pwm_port_open(PWM_OUT_62_P04);
	hsk_pwm_channel_set(PWM_62, 100, 5);
	hsk_pwc_init(4);
	hsk_pwc_port_open(PWC_CC0_P40, 2);
	hsk_pwc_channel_edgeMode(PWC_CC0, PWC_EDGE_BOTH);
	hsk_pwc_enable();
	EA = 1;
	hsk_adc_warmup();
	hsk_wdt_init(3000);
	hsk_wdt_enable();
	msgBoot = hsk_can_msg_create(0x7f0, 0, 2);
	hsk_can_msg_connect(msgBoot, CAN1);
	hsk_can_msg_setData(msgBoot, &persist.boot);
	hsk_can_msg_send(msgBoot);
}
void init ( void ) { hsk_can_msg msgBoot ; hsk_boot_extClock ( CLK ) ; IO_PORT_OUT_INIT ( P3 , -1 , IO_PORT_STRENGTH_WEAK , IO_PORT_DRAIN_DISABLE , -1 , 0 ) ; switch ( hsk_flash_init ( & persist , sizeof ( persist ) , PERSIST_VERSION ) ) { case FLASH_PWR_FIRST : hsk_flash_write ( ) ; break ; case FLASH_PWR_RESET : persist . reset ++ ; break ; case FLASH_PWR_ON : persist . boot ++ ; persist . reset = 0 ; hsk_flash_write ( ) ; break ; } IO_PORT_OUT_SET ( P3 , -1 , -1 , persist . boot ) ; hsk_timer0_setup ( 1000 , & tick0 ) ; hsk_timer0_enable ( ) ; hsk_adc_init ( ADC_RESOLUTION_10 , 5 ) ; hsk_adc_open ( 7 , & adc7 ) ; hsk_adc_enable ( ) ; hsk_can_init ( CAN1_IO , CAN1_BAUD ) ; hsk_can_disable ( CAN0 ) ; hsk_can_enable ( CAN1 ) ; hsk_pwm_init ( PWM_63 , 10 ) ; hsk_pwm_init ( PWM_62 , 10000 ) ; hsk_pwm_enable ( ) ; hsk_pwm_port_open ( PWM_OUT_63_P37 ) ; hsk_pwm_port_open ( PWM_OUT_62_P04 ) ; hsk_pwm_channel_set ( PWM_62 , 100 , 5 ) ; hsk_pwc_init ( 4 ) ; hsk_pwc_port_open ( PWC_CC0_P40 , 2 ) ; hsk_pwc_channel_edgeMode ( PWC_CC0 , PWC_EDGE_BOTH ) ; hsk_pwc_enable ( ) ; EA = 1 ; hsk_adc_warmup ( ) ; hsk_wdt_init ( 3000 ) ; hsk_wdt_enable ( ) ; msgBoot = hsk_can_msg_create ( 0x7f0 , 0 , 2 ) ; hsk_can_msg_connect ( msgBoot , CAN1 ) ; hsk_can_msg_setData ( msgBoot , & persist . boot ) ; hsk_can_msg_send ( msgBoot ) ; }
Initialize ports, timers and ISRs.
Initialize ports timers and ISRs .
/* Activate external clock. */ /*
	 * Boot/reset detection.
	 */ /* Init stuff if needed. */ /* Activate timer 0. */ /* Activate ADC */ /* Activate CAN. */ /* Activate PWM at 46.875kHz - exactly 10bit precision. */ //	hsk_pwm_init(468750);
 //	hsk_pwm_init(PWM_60, 1200); /* 120Hz */
 /* 1Hz */ /* 1kHz */ //hsk_pwm_port_open(PWM_OUT_60_P30);
 //hsk_pwm_port_open(PWM_OUT_60_P31);
 //hsk_pwm_outChannel_dir(PWM_COUT60, 0);
 //hsk_pwm_outChannel_dir(PWM_COUT60, 0);
 /* Activate PWC with a 4ms window. */ //P3_DIR |= 0x30;
 //P3_DATA |= 0x10;
 //P3_DIR = -1;
 /* Service watchdog every 20ms, so wait for 30ms. */