예제 #1
0
파일: timer.c 프로젝트: nesl/sos-2x
/**
 * @brief timer hardware routine
 */
void timer_hardware_init(uint8_t interval, uint8_t scale){

    HAS_CRITICAL_SECTION;
	unsigned long timer_value;
	timer_value = ((0x10000L*(16*1000)-((interval)*(CCLK)))/(16*1000));
    ENTER_CRITICAL_SECTION();
	IRQ_HANDLER_TABLE[INT_TIMER0] = timer0_interrupt_handler;
	set_wbit(ILC, ILC_ILC16 & ILC_INT_LV1); /* interrupt level of
                       ||            ||          IRQ number 16 (timer0)  is set as 1
                   IRQ number  interrupt level  */

    //! Initialize and start hardware timer
	set_timer(timer_value);

    LEAVE_CRITICAL_SECTION();
	// enable timer by writing '1' in TMEN[0] register
    put_wvalue(TMEN, 0x01);

    //! Call the SOS timer init function
    timer_init();
}
예제 #2
0
void init_i2c(void)
{
  //Set secondary function for PB4 and PB5  => I2C bus : SCL + SDA
  set_wbit(PORTSEL1,0x05000000);

  //I2C peripheral select
  set_hbit(I2CCTL,I2CCTL_I2CMEN);

  //I2C slave address
  put_hvalue(I2CSADR,0x0000);

  //I2C bus speed
  put_hvalue(I2CBC,0x0028);   //100kHz @32MHz
    //I2CBC = (APB_CLK)/( I2C bus speed x 8)

  //I2C control register
  put_hvalue(I2CCTL,0x0080);
    //I2CCS=0
    //enable I2C module
    //selects standard mode 100kHz

}
예제 #3
0
파일: uart_hal.c 프로젝트: nesl/sos-2x
void uart_hardware_init(void)
{
    //HAS_CRITICAL_SECTION;
    //ENTER_CRITICAL_SECTION();
    //LEAVE_CRITICAL_SECTION();

	if(uart_initialized == false) {
    set_hbit(GPCTL,GPCTL_UART);
    put_hvalue(GPPMB,0);		// disable SIO bits 6 and 7
   	put_hvalue(GPPOB,0);
    put_hvalue(GPPMA,0x0002);	// RX is input (A0), TX is output (A1)
   	put_hvalue(GPPOA,0);

    put_value(UARTIER,0);		// no interrupts
    put_value(UARTLCR,0x80);	// enable access to divisor latch
    put_value(UARTDLM,0);
    put_value(UARTDLL,0x3E);	// 57600 baud
    put_value(UARTLCR,0x03);
    put_value(UARTFCR,0xC7);	// 14 byte trigger, cleared and buffered (auto set to normal FCR mode)
    put_value(UARTMCR,0);
    put_value(UARTIER,0x01);	// RX

    IRQ_HANDLER_TABLE[INT_UART]=uart_interrupt_handler;
	set_wbit(ILC1,ILC1_ILR9 & ILC1_INT_LV3);

	set_hbit(GPPMC, UART_EN); 									// set PIOC6(UART_EN) to output
	set_hbit(GPPMC, UART_FORCEOFF); 									// set PIOC7(FORCEOFF) to output

    set_hbit(GPCTL,GPCTL_UART);
    put_hvalue(GPPMA,0x0002);	// RX is input (A0), TX is output (A1)
   	put_hvalue(GPPOA,0);
	clr_hbit(GPPOC,UART_EN);
	set_hbit(GPPOC,UART_FORCEOFF);	// this also drives FORCEON -- they are tied together

	uart_initialized = true;
	}
}
예제 #4
0
파일: timer.c 프로젝트: nesl/sos-2x
void enable_timer(void)
{
	set_wbit(ILC, ILC_ILC16);
}