Beispiel #1
0
/*
	Configure UART0.
 */
void init_uart(void)
{
    memset(rec_buffer, 0, BUFFER_SIZE);
    memset(trans_buffer, 0, BUFFER_SIZE);

    // Set the alternate function on port A
    // Enable UART0 TxD0/RxD0 pins (bits 4 & 5)
    PAAFH &= ~(PORTA_UART_TXD | PORTA_UART_RXD);
    PAAFL |= PORTA_UART_TXD | PORTA_UART_RXD;

    // Set the baud rate
    // BRG = freq/( baud * 16)
    U0BR = FREQ/((unsigned long)DEFAULT_BAUD * 16UL);
    baudrate = DEFAULT_BAUD;

    // U0 control
    // Transmit enable, Receive Enable, No Parity, 1 Stop
    U0CTL0 = UART_RXD_EN | UART_TXD_EN;
    U0CTL1 = 0;

    //set nominal priority
    IRQ0ENH |= UART_IRQ_EN;
    IRQ0ENL &= ~UART_IRQ_EN;

    PAIMUX &= ~UART_IRQ_EN;		//Port A (0) for interrupts
    PAIEDGE &= ~UART_IRQ_EN;	//negedge (0) interrupt

    SET_VECTOR(UART0_RX, uart_receive);
    SET_VECTOR(UART0_TX, uart_transfer);
}
Beispiel #2
0
void hw_time_init() {
    // Setup timer 0 (millis)
    // TEN: 0, TPOL: 0, PRES: 0 (1), TMODE: 1 (cont.)
    T0CTL = 0x01;
    // T0CTL = 0x39;

    // Begin timer at 0
    T0H = 0;
    T0L = 0;

    // End timer at 1843 (1 kHz)
    T0RH = 0x48;
    T0RL = 0x00;

    // Enable TIMER0 interrupt
    IRQ0 |= 0x20;

    // Set priority to HIGH
    IRQ0ENH |= 0x20;
    IRQ0ENL |= 0x20;

    // Enable timer0
    T0CTL |= 0x80;

    _millis = 0;
    _nextFrame = 0;
    _LEDflag = 0;


    // Setup timer 1 (game loop)
    // TEN: 0, TPOL: 0, PRES: 7 (128), TMODE: 1 (cont.)
    T1CTL = 0x39;

    // Begin timer at 0
    T1H = 0;
    T1L = 0;

    // End timer at 4777 (30 Hz)
    T1RH = 0x12;
    T1RL = 0xA9;

    // Enable TIMER0 interrupt
    IRQ0 |= 0x40;

    // Set priority to LOW
    IRQ0ENH &= ~0x40;
    IRQ0ENL |= 0x40;

    // Enable timer1
    T1CTL |= 0x80;

    SET_VECTOR(TIMER0, ISR_T0);
    SET_VECTOR(TIMER1, ISR_T1);
    EI();

    _millis = 0;
    _nextFrame = 0;
    _LEDflag = 0;
}
BOOL
xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
{
    UCHAR           cfg = 0;

    if( ucDataBits != 8 )
    {
        return FALSE;
    }

    switch ( eParity )
    {
    case MB_PAR_NONE:
        break;

    case MB_PAR_ODD:
        cfg |= UART_PARITY_ODD;
        break;

    case MB_PAR_EVEN:
        cfg |= UART_PARITY_EVEN;
        break;

    default:
        return FALSE;
    }

    /* Baud Rate -> U0BR = (CLOCK/(16*BAUD) */
    U0BRH = CLOCK / ( 16 * ulBaudRate ) >> 8;
    U0BRL = CLOCK / ( 16 * ulBaudRate ) & 0x00FF;

    /* Enable Alternate Function of UART Pins */
    PAAF |= PORTA_UART_RXD | PORTA_UART_TXD;

    /* Disable Interrupts */
    DI(  );

    /* Configure Stop Bits, Parity and Enable Rx/Tx */
    U0CTL0 = cfg | RX_ENABLE | TX_ENABLE;
    U0CTL1 = 0x00;

    /* Low Priority Rx/Tx Interrupts */
    IRQ0ENH &= ~UART0_TXD_INT_EN_H & ~UART0_RXD_INT_EN_H;

    vMBPortSerialEnable( FALSE, FALSE );

    /* Set Rx/Tx Interruption Vectors */
    SET_VECTOR( UART0_RX, prvvUARTRxISR );
    SET_VECTOR( UART0_TX, prvvUARTTxReadyISR );

    /* Enable Interrupts */
    EI(  );

    return TRUE;
}
Beispiel #4
0
/* ----------------------- Start implementation -----------------------------*/
BOOL
xMBPortTimersInit( USHORT usTim1Timerout50us )
{
    /* Configure Timer 0 (One Shot, Prescale = 1, Disabled) 
     *
     * Timer Control #00000000b
     *                 || ||_|_______ One Shot
     * Disabled = 0  __||_|_____________/1 Prescale                                 
     * */
    T0CTL1 = 0x00;

    T0H = 0x00;
    T0L = 0x00;

    /* Time = (reload x prescale)/CLOCK
     * reload = (Time*CLOCK)/prescale
     * 50us = CLOCK/20000
     * reload = usTim1Timerout50us*(CLOCK/20000)
     */
    T0CPH = ( usTim1Timerout50us * ( CLOCK / 20000 ) ) >> 8;
    T0CPL = ( usTim1Timerout50us * ( CLOCK / 20000 ) ) & 0x00FF;

    IRQ0ENH |= 0x20;
    IRQ0ENL |= 0x20;            /* Enable Timer0 High Priority */

    /* Set Interrupt Vector */
    SET_VECTOR( TIMER0, prvvTIMERExpiredISR );

    return TRUE;
}
Beispiel #5
0
void init_timer(int mode)
{
	timer_state = mode;

	T0CTL1 |= TIMER_DISABLE;
    T0CTL1 = TIMER_MODE_CONTINUOUS + TIMER_PRESCALE_128;

    // Initial counter value
    T0HL = 0x00;

	if(timer_state == TIMER_4MS) {
		// Timer reload
    	//   reload = clock / prescale * timeout  
   	 	T0R = (get_osc_clock() / 128) * INTERVAL_4MS_FLOAT;
	}
	else if(timer_state == TIMER_1MS) {
		T0R = (get_osc_clock() / 128) * INTERVAL_1MS_FLOAT;
	}
	//default timer is 2ms
	else {
		T0R = (get_osc_clock() / 128) * INTERVAL_2MS_FLOAT;
	}

	// Enable Timer0 interrupt
    IRQ0EN |= IRQ_Timer0;

	T0CTL1 |= TIMER_ENABLE;

	SET_VECTOR(TIMER0, timer_isr);
}
Beispiel #6
0
void led_init()
{
	PEADDR = 0x02;		//set alternative function (port E)
	PECTL = 0x00;
	PEADDR = 0x01;		//set datadirection to output (port E)
	PECTL = 0x00;

	PGADDR = 0x02;		//set alternative function (port G)
	PGCTL = 0x00;
	PGADDR = 0x01;		//set datadirection to output (port G)
	PGCTL = 0x00;

	T0CTL = 0x01;		//Disable Timer0 and set it to continous mode
	T0CTL |= 0x38;		//Set the prescale value
	
	T0H = 0x00;		
	T0L = 0x01;			//reset timer

	T0RH = 0x00;
//	T0RH = 0x02;
	T0RL = 0xD0;		//set reload value (0.5 ms)

	IRQ0ENH &= 0xDF;
	IRQ0ENL |= 0x20;	 //enable Timer0 interrupt, and set low priority

	T0CTL |= 0x80;		//enable Timer0
	EI();				//enable interrupts

	SET_VECTOR(TIMER0, drawtimer);		//set timer interrupt function

	led_clear();		//clear the LEDs
	led_onall();	
}
Beispiel #7
0
void timer1_setup(int difficulty)
{
	T1CTL = 0x01;	//Disable Timer1 and set it to continous mode
	T1CTL |= 0x38;	//Set the prescale value
	
	T1H = 0x00;		//...
	T1L = 0x01;		//reset timer

	

	if(difficulty > 0xFF)	//set timer reload value
	{
	    T1RH = difficulty - 0xFF;
	    T1RL = 0xFF;
	}
	else
	{
	    T1RH = 0x00;
	    T1RL = difficulty;
	} 

	

	IRQ0ENH |= 0x40; 	//enable Timer1 interrupt, and set nominal priority
	IRQ0ENL &= 0xBF;

	SET_VECTOR(TIMER1, timer1int);

	T1CTL |= 0x80;		//enable Timer1
	EI();				//enable interrupts
}
Beispiel #8
0
/*
 * vector_init(vector, vector_init_list)
 *
 * This routine sets up the m88k vector table for the running processor.
 * It is called with a very little stack, and interrupts disabled,
 * so don't call any other functions!
 *	XXX clean this - nivas
 */
void
vector_init(m88k_exception_vector_area *vector, unsigned *vector_init_list)
{
	unsigned num;
	unsigned vec;
	extern void bugtrap(void);
	extern void m88110_bugtrap(void);

	for (num = 0; (vec = vector_init_list[num]) != END_OF_VECTOR_LIST;
	    num++) {
		if (vec != UNKNOWN_HANDLER)
			SET_VECTOR(num, vec);
	}

	for (; num <= SIGSYS_MAX; num++)
		SET_VECTOR(num, sigsys);

	for (; num <= SIGTRAP_MAX; num++)
		SET_VECTOR(num, sigtrap);

	SET_VECTOR(450, syscall_handler);
	SET_VECTOR(504, stepbpt);
	SET_VECTOR(511, userbpt);

	/* GCC will by default produce explicit trap 503 for division by zero */
	SET_VECTOR(503, vector_init_list[T_ZERODIV]);
}
static cell_t GetVectorVectors(IPluginContext *pContext, const cell_t *params)
{
	cell_t *vec_addr;

	pContext->LocalToPhysAddr(params[1], &vec_addr);

	Vector vec(sp_ctof(vec_addr[0]), sp_ctof(vec_addr[1]), sp_ctof(vec_addr[2]));
	Vector right, up;

	VectorVectors(vec, right, up);

	cell_t *addr_right, *addr_up;
	pContext->LocalToPhysAddr(params[2], &addr_right);
	pContext->LocalToPhysAddr(params[3], &addr_up);

	SET_VECTOR(addr_right, right);
	SET_VECTOR(addr_up, up);

	return 1;
}
Beispiel #10
0
Datei: uart0.c Projekt: knivd/16z
void uart0_init(unsigned long baudrate) {
	unsigned long b=SYS_CLK/(16*baudrate);
	PADD|=0x30; PAAFL|=0x30; PAAFH&=~0x30;
	U0CTL0=0x00;
	U0BR=(unsigned short)b;
	U0MDSTAT=0x00;	
	U0CTL1=0x00;	
	U0CTL0=0xc0;
	SET_VECTOR(UART0_RX,uart0_rx);
	IRQ0EN&=~0x1010; IRQ0ENH|=0x10;	// enable reception interrupts (only) with normal priority
}
static cell_t GetAngleVectors(IPluginContext *pContext, const cell_t *params)
{
	cell_t *ang_addr;

	pContext->LocalToPhysAddr(params[1], &ang_addr);

	QAngle angle(sp_ctof(ang_addr[0]), sp_ctof(ang_addr[1]), sp_ctof(ang_addr[2]));
	Vector fwd, right, up;

	AngleVectors(angle, &fwd, &right, &up);

	cell_t *addr_fwd, *addr_right, *addr_up;
	pContext->LocalToPhysAddr(params[2], &addr_fwd);
	pContext->LocalToPhysAddr(params[3], &addr_right);
	pContext->LocalToPhysAddr(params[4], &addr_up);

	SET_VECTOR(addr_fwd, fwd);
	SET_VECTOR(addr_right, right);
	SET_VECTOR(addr_up, up);

	return 1;
}
Beispiel #12
0
void hw_sound_init() {
	_soundIndex = 0;
	_musicIndex = 0;
	_fxMode = 0;
	_soundId = 0;
	_musicId = 0;

	// Setup timer 2 (sound generator)
	// TEN: 0, TPOL: 0, PRES: 7 (128), TMODE: 3 (PWM)
	T2CTL = 0x3B;

	// Reset
	T2H = 0;
	T2L = 0;

	// Reload at 327 (440 Hz)
	T2RH   = 0x01;
	T2RL   = 0x47;

	// 50% duty cycle at 440 Hz
	T2PWMH = 0x00;
	T2PWML = 0xA3;

	// Enable alternate function
	PCAF |= 0x80;

	// Setup timer3
	// TEN: 0, TPOL: 0, PRES: 7 (128), TMODE: 1 (cont)
	T3CTL |= 0x39;

	// Reset
	T3H = 0;
	T3L = 0;

	// Reload at (16 Hz)
	T3RH   = 0x23;
	T3RL   = 0x28;

	// Enable timer3 interrupt
	IRQ2 |= 0x80;

	// Set priority to HIGH
	IRQ2ENH |= 0x80;
	IRQ2ENL |= 0x80;

	// Enable timer3
	T3CTL |= 0x80;

	SET_VECTOR(TIMER3, ISR_T3);
	EI();
}
static cell_t NormalizeVector(IPluginContext *pContext, const cell_t *params)
{
	cell_t *addr;

	pContext->LocalToPhysAddr(params[1], &addr);

	Vector source(sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2]));
	float length = VectorNormalize(source);

	pContext->LocalToPhysAddr(params[2], &addr);
	SET_VECTOR(addr, source);

	return sp_ftoc(length);
}
void setTimer(){
	DI();
	T0CTL = 0x01;
	T0H = 0x00;
	T0L = 0x01;
	T0RH = 0x48; //0x05
	T0RL = 0x00; //0xA0
	SET_VECTOR(TIMER0, timer0int);
	IRQ0ENH |= 0x20;
	IRQ0ENL |= 0x20;
	T0CTL |= 0x80;

	EI();
}
Beispiel #15
0
void timer_init(int hz) {
    int i;

    for (i = 0; i < MAX_CALLBACKS; i++) {
        timer_callbacks[i].isvalid = 0;
    }


    /*
     * SAMPLE CODE FROM INSTRUCTOR
     *
     * Good enough for generating an interrupt every 1 ms
     */

    SET_VECTOR(TIMER0,timer_isr); // Assign interrupt vector 
    EI();
    
    // Disable timer (why?)
    T0CTL1 |= 0x7f;         
    
    // Set timer0 control 0 and 1 
    T0CTL1 = 0x39;                // 0011_1001 0=disable
                                  //   0=tpol, 111=prescale, 001=mode
    T0CTL0 = 0x00;                // 0=mode, 00=ticonfig, 0=cascade, 
                                  //   000=pwmd, 0=incap

    // Initial counter value
    T0L = 0x01;                   
    T0H = 0x00;

    // Set timer reload value
    //   reload = clock / prescale * timeout  
    //   desired timeout is 0.001 seconds
    T0R = hz / 128 * 0.001;

    // Enable Timer0 interrupt (nominal priority)
    //IRQ0ENL |= 0x20;
    IRQ0ENH |= 0x20;

    // Configure the Output pin (so we can see it on scope)
    PADD &= ~0x02;
    PAAF |= 0x02;

    // Enable Timer0
    T0CTL1 |= 0x80;
}
static cell_t GetVectorCrossProduct(IPluginContext *pContext, const cell_t *params)
{
	cell_t *addr1, *addr2, *set;

	pContext->LocalToPhysAddr(params[1], &addr1);
	pContext->LocalToPhysAddr(params[2], &addr2);
	pContext->LocalToPhysAddr(params[3], &set);

	Vector vec1(sp_ctof(addr1[0]), sp_ctof(addr1[1]), sp_ctof(addr1[2]));
	Vector vec2(sp_ctof(addr2[0]), sp_ctof(addr2[1]), sp_ctof(addr2[2]));

	Vector vec3 = vec1.Cross(vec2);

	SET_VECTOR(set, vec3);

	return 1;
}
static cell_t GetVectorAngles(IPluginContext *pContext, const cell_t *params)
{
	cell_t *vec_addr;

	pContext->LocalToPhysAddr(params[1], &vec_addr);

	Vector vec(sp_ctof(vec_addr[0]), sp_ctof(vec_addr[1]), sp_ctof(vec_addr[2]));
	QAngle angle;

	VectorAngles(vec, angle);

	cell_t *ang_addr;
	pContext->LocalToPhysAddr(params[2], &ang_addr);

	SET_VECTOR(ang_addr, angle);

	return 1;
}
Beispiel #18
0
/*
	Initialize the millisecond timer.
 */
static void init_led_draw_timer(void)
{
	T0CTL1 |= TIMER_DISABLE;

    T0CTL1 = TIMER_MODE_CONTINUOUS + TIMER_PRESCALE_128;

    // Initial counter value
    T0HL = 0x00;

    // Timer reload
    //   reload = clock / prescale * timeout  
    T0R = CLOCK / 128 * DRAW_TIME;

	// Enable Timer0 interrupt
    IRQ0EN = IRQ_Timer0;

	T0CTL1 |= TIMER_ENABLE;

	SET_VECTOR(TIMER0, draw_timer_isr);
}
void LEDInit(){
	PEDD = 0x00;
	PGDD = 0x00;	
	DI();
	T1CTL = 0x01; // Prescale value er 1, ingen division
	T1H = 0x00;
	T1L = 0x01;
	T1RH = 0x24; // Reload værdi er 9216  = 2400
	T1RL = 0x00;
	SET_VECTOR(TIMER1, timer1int);
	IRQ0ENL |= 0x40; //Sætter priority lav
	T1CTL |= 0x80; //Starter timeren
	EI();
	done = 0;
	counter = 0;
	numberShifts = 0;
	shift = 0;
	unitnr = 0;
	kolonnenr = 0;
	//string[] = "";
}
Beispiel #20
0
void init_midi_out(void)
{
	//set port D5 alternate function 1
	PDAFH &= ~PORTD_TXD1_AF;  //Set bit 5 to 0
	PDAFL |= PORTD_TXD1_AF;   //Set bit 5 to 1

	//set the UART baudrate
	U1BR = FREQ / (MIDI_BAUDRATE * 16UL);

	//enable the UART for transmit
	U1CTL0 = UART1_TXD_EN;    //Set bit 7 to 1
	U1CTL1 = 0;

	//set nominal interrupt priority
	IRQ2ENH |= UART1_IRQ_EN;  //Set bit 5 to 1
	IRQ2ENL &= ~UART1_IRQ_EN; //Set bit 5 to 0

	PAIMUX |= UART1_IRQ_EN;	  //Port D5 (1) for interrupts
	PAIEDGE &= ~UART1_IRQ_EN; //Port D5, negedge (0) interrupt

	//set the TXD1 interrupt vector
	SET_VECTOR(UART1_TX, midi_out_transfer);
}
Beispiel #21
0
/**
 * @param timer The timer to configure
 * @param subcount_max The number the timer/counter should count to before "firing"
 */
void hal_timer_configure(char timer, int subcount_max)
{
	DI(); // Disable interrupts globally

	switch (timer) {
	case HAL_TIMER_0:
		//Enable cont. mode, set prescale to 0x80
		T0CTL |= 0x39; 
		T0H = 0x00; //Set high order bits of preset
		T0L = 0x01; //Set low order bits of preset

		// We set the reload value to 0x48 (72) giving us a 
		// timer on 0.5 ms
		T0RH = 0x00; //Set high order bits of reload value
		T0RL = 0x48; //Set low order bits of reload value

		//Set IRQ priority to low
		IRQ0ENH &= ~0x20;
		IRQ0ENL |= 0x20;

		timer0_state.subcount_max = subcount_max;

		SET_VECTOR(TIMER0, timer0_irq_handler); //Map irq handler
		break;
	case HAL_TIMER_1:
		T1CTL |= 0x39; 
		T1H = 0x00;
		T1L = 0x01;
		T1RH = 0x00;
		T1RL = 0x24;
		IRQ0ENH &= ~0x40;
		IRQ0ENL |= 0x40;
		timer1_state.subcount_max = subcount_max;
		SET_VECTOR(TIMER1, timer1_irq_handler);
		break;
	case HAL_TIMER_2:
		T1CTL |= 0x39; 
		T1H = 0x00;
		T1L = 0x01;
		T1RH = 0x00;
		T1RL = 0x48;
		IRQ0ENH &= ~0x80;
		IRQ0ENL |= 0x80;
		timer2_state.subcount_max = subcount_max;
		SET_VECTOR(TIMER2, timer2_irq_handler);
		break;
	case HAL_TIMER_3:
		T3CTL |= 0x39; 
		T3H = 0x00;
		T3L = 0x01;
		T3RH = 0x00;
		T3RL = 0x48;
		IRQ2ENH &= ~0x80;
		IRQ2ENL |= 0x80;
		timer2_state.subcount_max = subcount_max;
		SET_VECTOR(TIMER3, timer3_irq_handler);
		break;
	default:
		break;
	}
	EI(); // Enable interrupts globally
}
Beispiel #22
0
#include "light.hpp"

void PointLight::init(ParamList &params) {

    #define SET_VECTOR(_name) _name = params[#_name];
    SET_VECTOR(ambient)
    SET_VECTOR(diffuse)
    SET_VECTOR(specular)
    SET_VECTOR(attenuation)

}
Beispiel #23
0
void init_cpu(void) {
	DI();
	
	//PA0: RELOAD/DBG. Input, external 10k pullup.
	//PA1: INHIBIT. Output.
	//PA2: 38KHz. T1OUT, output.
	//PA3: LAZERMOD. Input.
	//PA4: RXD. UART, input.
	//PA5: TXD. UART, output.
	
	//Set up Port A.
	PADD = 0x19;	//00011001
	PAAF = 0x34;	//00110100
	PAAFS1 = 0x04;	//00000100
	PAAFS2 = 0x00;	//00000000
	//PAPUE = 0x10;	//00010000
	
	//Set up UART for 2000 baud, 8 data bits, 1 start bit, 2 stop bits, interrupt driven, no parity.
	//Set baud rate
	U0BRH = 0x00;
	U0BRL = 0xAD;
	//Set up interrupt
	SET_VECTOR(UART0_RX_IVECT, isr_uartrx);
	SET_VECTOR(UART0_TX_IVECT, isr_uarttx);
	IRQ0ENH |= 0x18;
	IRQ0ENL |= 0x18;
	IRQ0 &= ~0x18;
	//Enable transmitter and receiver, disable parity, 2 stop bits.
	U0CTL0 = 0xC2; 	//11000010
	//Enable interrupts on received data
	U0CTL1 = 0x00;	//00000000
	
	//Set up Timer0 to be an 8KHz heartbeat interrupt.
	//Disable timer, set mode to Continuous, set prescale to 1:1
	T0CTL1 = 0x01;	//00000001
	T0CTL0 = 0x00;	//00000000
	//Reset count
	T0H = 0x00; T0L = 0x01;
	//Set the reload value
	//T0RH = 0x05; T0RL = 0x5F;
	T0RH = 0x02; T0RL = 0xB3;
	//Set the interrupt vector and priority
	SET_VECTOR(TIMER0, isr_timer0);
	IRQ0ENH |= 0x20;
	IRQ0ENL |= 0x20;
	//Enable timer
	T0CTL1 |= 0x80;
	
	//Set up Timer1 to be 38KHz, 50% duty cycle PWM.
	//Turn off timer, set mode to single PWM, set prescale to 1:1, set initial logic level to 1
	T1CTL1 = 0x43;	//01000011
	T1CTL0 = 0x00;	//00000000
	//Reset count
	T1H = 0x00; T1L = 0x01;
	//Set PWM value(Duty cycle)
	T1PWMH = 0x00; T1PWML = 0x48;
	//Set the reload value(Period)
	T1RH = 0x00; T1RL = 0x90;
	//Enable timer
	T1CTL1 |= 0x80;
	
	//Turn off the inhibit line
	PAOUT &= 0xFD;
	
	//lastIO = PAIN;
	//tempIO = PAIN;
	
	EI();
}