Exemplo n.º 1
0
//===========================================================================
void UART_RX_TEST(void){

	unsigned char	MyRx[1];	//Small Array...for UART Receive, etc
	int i;
 	
	// CLEAR the Array...
		for(i = 0; i<1; i++) 
		{
			MyRx[i] = 0x20;	// 0x20 = "Space" => Clear Array
		} 
	 
	
	// ===== START UART RX TEST... =====
		_flgUartFin = 0;
		uart_stop();
		uart_startReceive(MyRx, 1, _funcUartFin);	// RX!
		while(_flgUartFin != 1){
			main_clrWDT();	
			//LED5_pin ^= 1;	//waiting for data...
		}
		
 		//If data in RX Buffer...echo it out the TX port
		if(MyRx[0] != 0x20){			
			//Echo the Received Data
			_flgUartFin = 0;
			uart_stop();
			uart_startSend(MyRx, 1, _funcUartFin);	// TX!
			while(_flgUartFin != 1){
				main_clrWDT(); 
			}
		} 
	// ===== END UART RX TEST =====
		
}
Exemplo n.º 2
0
void task_powerdown_init()
{
	//Lower F_CPU
	ClockSetSource(x2MHz);
	//disable other oscilators
	OSC.CTRL = 0b00000001;

	buttons_deinit();

	uart_stop();
	_delay_ms(10);

	turnoff_subsystems();

	uart_low_speed();
	_delay_ms(10);

	DEBUG(" *** POWER DOWN INIT ***\n");

	test_memory();

	//we do not want to enter sleep
	powerdown_loop_break = false;
	powerdown_lock.Lock();

	task_timer_setup(false);

	SD_EN_OFF;

	DEBUG("Using low speed uart\n");
}
Exemplo n.º 3
0
void gui_set_advanced_action(uint8_t index)
{
	switch(index)
	{
	case(0):
		config.connectivity.usb_mode = !config.connectivity.usb_mode;
		eeprom_busy_wait();
		eeprom_update_byte(&config_ee.connectivity.usb_mode, config.connectivity.usb_mode);
	break;

	case(1):
		config.connectivity.uart_function = (config.connectivity.uart_function + 1) % NUMBER_OF_UART_FORWARD;
		eeprom_busy_wait();
		eeprom_update_byte(&config_ee.connectivity.uart_function, config.connectivity.uart_function);
		uart_stop();
		uart_init();
	break;

	case(2):
		if (!storage_card_in())
		{
			gui_showmessage_P(PSTR("No SD card!"));

			return;
		}
		gui_dialog_set_P(PSTR("Warning"), PSTR("This will erase\nall data from SD\ncard! Continue?"), GUI_STYLE_YESNO, gui_set_advanced_format_cb);
		gui_switch_task(GUI_DIALOG);
	break;

	case(3):
		gui_switch_task(GUI_SET_CALIB);
	break;
	}
}
Exemplo n.º 4
0
/**
 * @brief   Deactivates the UART peripheral.
 *
 * @param[in] uartp     pointer to the @p UARTDriver object
 *
 * @notapi
 */
void uart_lld_stop(UARTDriver *uartp) {

  if (uartp->state == UART_READY) {
    uart_stop(uartp);
    udmaChannelRelease(uartp->dmarxnr);
    udmaChannelRelease(uartp->dmatxnr);

#if TIVA_UART_USE_UART0
    if (&UARTD1 == uartp) {
      HWREG(SYSCTL_RCGCUART) &= ~(1 << 0);
      return;
    }
#endif
#if TIVA_UART_USE_UART1
    if (&UARTD2 == uartp) {
      HWREG(SYSCTL_RCGCUART) &= ~(1 << 1);
      return;
    }
#endif
#if TIVA_UART_USE_UART2
    if (&UARTD3 == uartp) {
      HWREG(SYSCTL_RCGCUART) &= ~(1 << 2);
      return;
    }
#endif
#if TIVA_UART_USE_UART3
    if (&UARTD4 == uartp) {
      HWREG(SYSCTL_RCGCUART) &= ~(1 << 3);
      return;
    }
#endif
#if TIVA_UART_USE_UART4
    if (&UARTD5 == uartp) {
      HWREG(SYSCTL_RCGCUART) &= ~(1 << 4);
      return;
    }
#endif
#if TIVA_UART_USE_UART5
    if (&UARTD6 == uartp) {
      HWREG(SYSCTL_RCGCUART) &= ~(1 << 5);
      return;
    }
#endif
#if TIVA_UART_USE_UART6
    if (&UARTD7 == uartp) {
      HWREG(SYSCTL_RCGCUART) &= ~(1 << 6);
      return;
    }
#endif
#if TIVA_UART_USE_UART7
    if (&UARTD8 == uartp) {
      HWREG(SYSCTL_RCGCUART) &= ~(1 << 7);
      return;
    }
#endif
  }
}
Exemplo n.º 5
0
void task_powerdown_loop()
{
	//do not go to the Power down when there is another lock pending (button, buzzer)
	if ((task_sleep_lock == 1 && powerdown_lock.Active()) && powerdown_loop_break == false)
	{
		uart_stop();

		powerdown_sleep();

		uart_low_speed();
	}
}
Exemplo n.º 6
0
int main(void){

	for(uint8_t y = 0; y < 8; y++){
		for(uint8_t x = 0; x < 8; x++){
			img_buffer.raw_data[y][x][0] = 0x00;	// R
			img_buffer.raw_data[y][x][1] = 0x00;	// G
			img_buffer.raw_data[y][x][2] = 0x00;	// B
		}
	}

	matrix_init();
	uart_init(BAUDRATE);
	sei();
	_delay_ms(1);	// some start up delay;


	while(1){
		uart_async_run();	// receive picture data via UART
		if(sleep_flag){		// if this is true, the display should go to sleep
			sleep_flag = 0x00;
			// stop / disable peripherals
			cli();	// disable interrupts
			matrix_stop();
			uart_stop();

			// Wait for PC5 to go low before enabling interrupt
			while(PINC & (1 << PC5));

			// enable external pin change interrupt on PC5 (p_out): PCINT13
			// DEBUG: do not enable interrupt => sleep forever
			PCMSK1 |= (1<<PCINT13);	// set interrupt mask for PC5
			PCICR |= (1<<PCIE1);	// enable pin change interrupt 1

			// go to sleep
			set_sleep_mode(SLEEP_MODE_STANDBY);
			sleep_enable();
			sei();
			sleep_cpu();
			sleep_disable();

			// wake up
			cli();	// disable interrupts
			PCICR = 0x00;	// disable pin change interrupt
			PCMSK1 = 0x00;

			// restart peripherals
			matrix_restart();
			uart_init(BAUDRATE);
			sei();	// reenable interrupts
		}
	}
}
Exemplo n.º 7
0
void task_powerdown_stop()
{
	//Reinit all devices
	DEBUG("Restarting all devices\n");

	uart_stop();
	Setup();

	task_timer_setup();
	DEBUG("Restoring full speed uart\n");

	powerdown_lock.Unlock();
}
Exemplo n.º 8
0
//===========================================================================
//TX LOOP that works with LaPi GUI
void TX_Loop(void){

		uart_PortSet();
		_flgUartFin = 0;
		uart_stop();
		
		uart_startSend(PING, 8, _funcUartFin); // Send, "PING!"
		while(_flgUartFin != 1){
			NOP1000();
			main_clrWDT();
		}

}//End TX_Loop Function...
Exemplo n.º 9
0
void gui_set_system_action(uint8_t index)
{
	switch(index)
	{
	case(0):
		gui_switch_task(GUI_SET_TIME);
	break;

	case(1):
		gui_switch_task(GUI_SET_DISPLAY);
	break;

	case(2):
		gui_switch_task(GUI_SET_AUDIO);
	break;

	case(3):
		config.connectivity.usb_mode = !config.connectivity.usb_mode;
		eeprom_busy_wait();
		eeprom_update_byte(&config_ee.connectivity.usb_mode, config.connectivity.usb_mode);
	break;

	case(4):
		gui_value_conf_P(PSTR("Auto power-off"), GUI_VAL_NUMBER_DISABLE, PSTR("%0.0f min"), config.system.auto_power_off, 0, 120, 1, gui_set_system_auto_power_off_cb);
		gui_switch_task(GUI_SET_VAL);
	break;

	case(5):
		config.connectivity.uart_function = (config.connectivity.uart_function + 1) % NUMBER_OF_UART_FORWARD;
		eeprom_busy_wait();
		eeprom_update_byte(&config_ee.connectivity.uart_function, config.connectivity.uart_function);
		uart_stop();
		uart_init();
	break;

	case(6):
		if (!storage_card_in())
		{
			gui_showmessage_P(PSTR("No SD card!"));

			return;
		}
		gui_dialog_set_P(PSTR("Warning"), PSTR("This will erase\nall data from SD\ncard! Continue?"), GUI_STYLE_OKCANCEL, gui_set_system_format_cb);
		gui_switch_task(GUI_DIALOG);
	break;
	}
}
Exemplo n.º 10
0
//===========================================================================
//Simple function to demonstrate Serial LCD
void UART_TX_TEST (void)
{
	// ===== START UART TX TEST... =====
		unsigned char UARTStartupMessage[26] = {"ML610Q111 UART - TX Demo: "};
		
		//CLEAR Parallax LCD Display!
		_flgUartFin = 0;
		uart_stop();
		uart_startSend(UARTStartupMessage, 26, _funcUartFin);
		while(_flgUartFin != 1){
			main_clrWDT(); 
		}
			
	// ===== END UART TX TEST =====  
	

}
Exemplo n.º 11
0
//===========================================================================
//RX LOOP that works with LaPi GUI
void RX_Loop(void){
int i;		// -32,768 to 32767
int count;		// -32,768 to 32767

		main_clrWDT();
		
		//Reset RecWorld for UART Recieve
		for (i=0;i<22;i++)
		{
			RecWorld[i] = 0;	
		}
		
		//Begin UART Recieve
		_flgUartFin = 0;
		uart_stop();
		uart_startReceive(RecWorld, 21, _funcUartFin);
		while(_flgUartFin != 1){
			NOP1000();
			main_clrWDT();
		}
		
		//Check UART Recieve String for "INP"
		//if ACK Sent, Return "UART Connected"
		//FOR When COM port is opened on PC
		if(RecWorld[0] == 0x41){			//if RECWORLD == "INP"
			if(RecWorld[1] == 0x43){
				if(RecWorld[2] == 0x4B){
					_flgUartFin = 0;
					uart_stop();
					uart_startSend(AckMCUConn, 22, _funcUartFin);
					while(_flgUartFin != 1){
						NOP1000();
						main_clrWDT();
					}
				
				}
			}
		}
		
		//Check UART Recieve String for "INP"
		if(RecWorld[0] == 0x49){			//if RECWORLD == "INP"
			if(RecWorld[1] == 0x4E){
				if(RecWorld[2] == 0x50){
				
					for(count = 4; count < 12; count++)
					{ 
						RecWorld[count] -= 0x30;
						if(RecWorld[count] != (0x01||0x00)){
							RecWorld[count] = 0;
						}
					}
					
					//Set PORTC to Input or Output based on PC application
					PC7DIR = RecWorld[4];
					PC6DIR = RecWorld[5];
					PC5DIR = RecWorld[6];
					PC4DIR = RecWorld[7];
					PC3DIR = RecWorld[8];
					PC2DIR = RecWorld[9];
					PC1DIR = RecWorld[10];
					PC0DIR = RecWorld[11];
					
					//Format I/O Direction into output string
					InputStatus[4]  = PC7DIR + 0x30;
					InputStatus[5]  = PC6DIR + 0x30;
					InputStatus[6]  = PC5DIR + 0x30;
					InputStatus[7]  = PC4DIR + 0x30;
					InputStatus[8]  = PC3DIR + 0x30;
					InputStatus[9]  = PC2DIR + 0x30;
					InputStatus[10] = PC1DIR + 0x30;
					InputStatus[11] = PC0DIR + 0x30;
					
					//Format I/O Level into output string
					InputStatus[13] = PC7D + 0x30;
					InputStatus[14] = PC6D + 0x30;
					InputStatus[15] = PC5D + 0x30;
					InputStatus[16] = PC4D + 0x30;
					InputStatus[17] = PC3D + 0x30;
					InputStatus[18] = PC2D + 0x30;
					InputStatus[19] = PC1D + 0x30;
					InputStatus[20] = PC0D + 0x30;
					
					//Send the InputStatus String
					//	"INP_[PC7DIR][PC6DIR]...[PC0DIR]_[PC7D]{PC6D]...[PC0D]"
					_flgUartFin = 0;
					uart_stop();
					uart_startSend(InputStatus, 23, _funcUartFin);
					while(_flgUartFin != 1){
						NOP1000();
						main_clrWDT();
					}
					
					//Send the Acknoledgement String
					_flgUartFin = 0;
					uart_stop();
					uart_startSend(InputRec, 14, _funcUartFin);
					while(_flgUartFin != 1){
						NOP1000();
						main_clrWDT();
					}
				}
			}
		}
		
		//Check UART Recieve String for "OUT"
		if(RecWorld[0] == 0x4F){			//if RECWORLD == "OUT"
			if(RecWorld[1] == 0x55){
				if(RecWorld[2] == 0x54){
				
					for(count = 4; count < 21; count++)
					{ 
						RecWorld[count] -= 0x30;
						if(RecWorld[count] != (0x01||0x00)){
							RecWorld[count] = 0;
						}
					}
					//Set I/O Pin Direction based on PC App
					PC7DIR = RecWorld[4];
					PC6DIR = RecWorld[5];
					PC5DIR = RecWorld[6];
					PC4DIR = RecWorld[7];
					PC3DIR = RecWorld[8];
					PC2DIR = RecWorld[9];
					PC1DIR = RecWorld[10];
					PC0DIR = RecWorld[11];
					
					//Set I/O Pin Direction based on PC App
					PC7D = RecWorld[13];
					PC6D = RecWorld[14];
					PC5D = RecWorld[15];
					PC4D = RecWorld[16];
					PC3D = RecWorld[17];
					PC2D = RecWorld[18];
					PC1D = RecWorld[19];
					PC0D = RecWorld[20];
					
					//Return GPIO pin state within the acknoledgement string
					OutputRec[13] = PC7D + 0x30;
					OutputRec[14] = PC6D + 0x30;
					OutputRec[15] = PC5D + 0x30;
					OutputRec[16] = PC4D + 0x30;
					OutputRec[17] = PC3D + 0x30;
					OutputRec[18] = PC2D + 0x30;
					OutputRec[19] = PC1D + 0x30;
					OutputRec[20] = PC0D + 0x30;
					
					_flgUartFin = 0;
					uart_stop();
					uart_startSend(OutputRec, 23, _funcUartFin);
					while(_flgUartFin != 1){
						NOP1000();
						main_clrWDT();
					}
				}
			}
		}

}//End RX_Loop Function...
Exemplo n.º 12
0
//===========================================================================
//	Initialize Micro to Desired State...
//===========================================================================
static void Initialization(void){

	//Initialize Peripherals	
		//BLKCON2 Control Bits...Manually Set 4/12/2013
			DSIO0 = 1; // 0=> Enables Synchronous Serial Port 0 (initial value).
			DUA0  = 0; // 0=> Enables the operation of UART0 (initial value).
			DUA1  = 1; // 0=> Enables Uart1 (initial value). 
			DI2C1 = 1; // 0=> Enables I2C bus Interface (Slave) (initial value).
			DI2C0 = 1; // 0=> Enables I2C bus Interface (Master) (initial value).	
	
		BLKCON4 = 0x00; // 0=> Enables SA-ADC
		BLKCON6 = 0x00; // (1=disables; 0=enables) the operation of Timers 8, 9, A, E, F.
		BLKCON7 = 0x00; // (1=disables; 0=enables) the operation of PWW (PWMC, PWMD, PWME, PWMF

	// Port Initialize
		PortA_Low();	//Initialize all 3 Ports of Port A to GPIO-Low
		PortB_Low();	//Initialize all 8 Ports of Port B to GPIO-Low
		PortC_Low();	//Initialize all 8 Ports of Port C to GPIO-Low
		PortD_Low();	//Initialize all 6 Ports of Port D to GPIO-Low

	//Setup PIR Sensor Input on C.0
		//Step 1: Set Pin Direction...
		//PC0DIR = 1;			// PortC Bit0 set Direction to INPUT...
		//Step 2: Set Pin I/O Type...
		//PC0C1  = 0;			// PortC Bit0 set Type to HIGH-IMPEDANCE INPUT...
		//PC0C0  = 0;	
		//Step 3: Set Pin Purpose...
		//PC0MD1  = 0;		// PortC Bit0 set Purpose to GENERAL PURPOSE Input/Output...
		//PC0MD0  = 0;

	// PWM...	
		//PinB0_PWM();	// Set up PWM Pin on B.0...


	// Comparator...	
		//analog_comparator();

	// Set Oscillator Rate...Must Have.
     		SetOSC();

    
	// TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
	// TIMER SETUP...

	Setup_Timer_8:
	// Reset TIMER DATA REGISTER...
		TM8D    = 0;	//Timer 8 DATA Register

	// Reset TIMER CLOCK REGISTER...
		TM8C    = 0;	//Timer 8 CLOCK Register

	// TIMER-8 Control...
	//   CONTROL-0 Register:
		// Operation Clock for Timer...
		T8C1 = 0;	// 01 = HTBCLK  
		T8C0 = 1;
		// Count Mode...
		T89M16 = 0;	// 0=8-Bit Mode; 1=16bit Mode...
		//One-Shot or Normal Mode...
		T8OST = 0;	// 0=Normal; 1=One-Shot...
	//   CONTROL-1 Register:
		// RUN Mode...
		T8RUN = 0;	//0=STOP; 1=START...

	// TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT


	
	// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	// INTERRUPT SETUP...
		irq_di();	// Disable Interrupts
		irq_init();	// Initialize Interrupts (All Off and NO Requests)

		// INTERRUPT ENABLE REGISTERS...
		//  IE0 = VOLTAGE LEVEL SUPERVISOR Int.
		//  IE1 = EXTERNAL Ints on B1, B0, A2, A1, & A0
		//  IE2 = SUCCESSIVE APPROXIMATION Int.
		//  IE3 = TIMERS 8 & 9 Ints.
		//  IE4 = UART & COMPARATOR Ints.
		//  IE5 = TIMERS A, B, E & F Ints.
		//  IE6 = PWMC &  128Hz & 32Hz TBC Ints.
		//  IE7 = 16Hz & 2Hz TBC Ints.
		IE0 = IE1 = IE2 = IE3 = IE4 = IE5 = IE6 = IE7 = 0;

		// INTERRUPT REQUEST REGISTERS...
		//  IRQ0 = WDT & VLS Int Requests
		//  IRQ1 = EXTERNAL Int Requests
		//  IRQ2 = SUCCESSIVE APPROXIMATION Int Requests
		//  IRQ3 = TIMERS 8 & 9 Int Requests 
		//  IRQ4 = UART & COMPARATOR Int Requests 
		//  IRQ5 = TIMERS A, B, E & F Int Requests 
		//  IRQ6 = PWMC &  128Hz & 32Hz TBC Int Requests 
		//  IRQ7 = 16Hz & 2Hz TBC Int Requests 
		IRQ0 = IRQ1 = IRQ2 = IRQ3 = IRQ4 = IRQ5 = IRQ6 = IRQ7 = 0;


		E2H = 0; 	// E2H is the Enable flag for 2Hz TBC Interrupt (1=ENABLED)
		
		
		//(void)irq_setHdr( (unsigned char)IRQ_NO_I2C0INT, _intI2c );
		//(void)irq_setHdr( (unsigned char)IRQ_NO_UA1INT, _intUart );
		(void)irq_setHdr( (unsigned char)IRQ_NO_UA0INT, _intUart );

		EUA0 = 1; // EUA0 is the enable flag for the UART0 interrupt (1=ENABLED)
		irq_ei(); // Enable Interrupts
	// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII


	// WDT...
	WDTMOD = 0x03; 	// 0x03=overflow 8sec...
	main_clrWDT(); 	// Clear WDT
	
	//Add EOL characters to strings
		HelloWorld[12] 	= 0x0D;
		HelloWorld[13] 	= 0x0A;
		InputStatus[21] 	= 0x0D;
		InputStatus[22] 	= 0x0A;
		InputRec[12] 	= 0x0D;
		InputRec[13] 	= 0x0A;
		OutputRec[21] 	= 0x0D;
		OutputRec[22] 	= 0x0A;
		AckMCUConn[20] 	= 0x0D;
		AckMCUConn[21] 	= 0x0A;
	
	//UART Initialization...
		(void)uart_init( (unsigned char)UART_CS_HSCLK,		/* Generator       */
				     (unsigned short)HSCLK_KHZ,		/* HSCLK frequency */
				     &_uartSetParam );				/* Param... 	 */
		uart_PortSet();
		_flgUartFin = 0;
		uart_stop();
		
		uart_startSend(HelloWorld, 14, _funcUartFin); // Send, "Hello World!"
		while(_flgUartFin != 1){
			NOP1000();
			main_clrWDT();
		}
}
Exemplo n.º 13
0
//===========================================================================
//	Initialize Micro to Desired State...
//===========================================================================
static void Initialization(void){

	//Initialize Peripherals	
		//BLKCON2 Control Bits...Manually Set 4/12/2013
			DSIO0 = 1; // 0=> Enables Synchronous Serial Port 0 
			DUA0  = 0; // 0=> Enables the operation of UART0 
			DUA1  = 1; // 0=> Enables Uart1 
			DI2C1 = 1; // 0=> Enables I2C bus Interface (Slave) 
			DI2C0 = 0; // 0=> Enables I2C bus Interface (Master)	
	
		BLKCON4 = 0x00; // SA-ADC: 0=> Enables ; 0xFF=> Disables
		BLKCON6 = 0x00; // Timers 8, 9, A, E, F : 0=> Enables ; 0xFF=> Disables
		BLKCON7 = 0x00; // PWM (PWMC, PWMD, PWME, PWMF : 0=> Enables ; 0xFF=> Disables

	// Port Initialize...
		PortA_Low();	//Initialize all 3 Ports of Q111 Port A to GPIO-Low
		PortB_Low();	//Initialize all 8 Ports of Q111 Port B to GPIO-Low
		PortC_Low();	//Initialize all 4 Ports of Q111 Port C to GPIO-Low

	// UART INIT...	
		//uart_0_Init();
				
				
	// ===== Set Oscillator Rate =====
     	SetOSC(); 	//8MHz

	// ===== PWM ================================================================
	//
	//	NOTE: Possible conflict of B.0 with RX pin from UART0
	//	
	//	PinB0_PWM();		// Set up PWM peripheral (Pin on B.0)
	//===========================================================================	
		
	// ===== Comparator =====	
		//analog_comparator();	//Set up anaolg comparator peripheral


/* 	// ===== SET SPECIFIC DESIRED PINS AS INPUTS =====
		//Setup PIR Sensor Input on B.4
			//Step 1: Set Pin Direction...
				PB4DIR = 1;			// PortB Bit4 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PB4C1  = 0;			// PortB Bit4 set Type to HIGH-IMPEDANCE INPUT...
				PB4C0  = 0;	
			//Step 3: Set Pin Purpose...
				PB4MD1  = 0;		// PortB Bit4 set Purpose to GENERAL PURPOSE Input/Output...
				PB4MD0  = 0;

		//Setup HALL Sensor Input on B.3
			//Step 1: Set Pin Direction...
				PB3DIR = 1;			// PortB Bit3 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PB3C1  = 0;			// PortB Bit3 set Type to HIGH-IMPEDANCE INPUT...
				PB3C0  = 0;	
			//Step 3: Set Pin Purpose...
				PB3MD1  = 0;		// PortB Bit3 set Purpose to GENERAL PURPOSE Input/Output...
				PB3MD0  = 0;

		//Setup ACCELEROMETER X-SIGNAL Sensor Input on A.2
			//Step 1: Set Pin Direction...
				PA2DIR = 1;			// PortA Bit2 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PA2C1  = 0;			// PortA Bit2 set Type to HIGH-IMPEDANCE INPUT...
				PA2C0  = 0;	
			//Step 3: Set Pin Purpose...
				PA2MD1  = 0;		// PortA Bit2 set Purpose to GENERAL PURPOSE Input/Output...
				PA2MD0  = 0;
		
		//Setup ACCELEROMETER Y-SIGNAL Sensor Input on A.1
			//Step 1: Set Pin Direction...
				PA1DIR = 1;			// PortA Bit1 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PA1C1  = 0;			// PortA Bit1 set Type to HIGH-IMPEDANCE INPUT...
				PA1C0  = 0;	
			//Step 3: Set Pin Purpose...
				PA1MD1  = 0;		// PortA Bit1 set Purpose to GENERAL PURPOSE Input/Output...
				PA1MD0  = 0;

		//Setup ACCELEROMETER Temperature-SIGNAL Sensor Input on A.0
			//Step 1: Set Pin Direction...
				PA0DIR = 1;			// PortA Bit0 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PA0C1  = 0;			// PortA Bit0 set Type to HIGH-IMPEDANCE INPUT...
				PA0C0  = 0;	
			//Step 3: Set Pin Purpose...
				PA0MD1  = 0;		// PortA Bit0 set Purpose to GENERAL PURPOSE Input/Output...
				PA0MD0  = 0; */

	//================== STANDBY CONTROL REGISTER===================================
	//
	// SBYCON is a 2-bit special function register to control operating mode of MCU
	//		STP   :   HLT
	// 		BIT 1 :  BIT 0
	//  	 0         0     => Program RUN mode (initial value)
	//  	 0         1     => HALT mode
	//  	 1         0     => STOP mode
	//  	 1         1     => (Prohibited)
	// See ML610Q111/ML610Q112 User Manual - Section 4: MCU Control Function
	//	SBYCON = 0;		// Program RUN mode
	//==============================================================================

	//================== VOLTAGE LEVEL SUPERVISOR REGISTER =========================
	// 
	// The Q11x mcu's have two channels of VOLTAGE LEVEL SUPERVISORs
	// Accuracy is ±3%
	//
	// The threshold voltages of VLS0 (VDD fall) : 2.85V (Typ. )
	//								  (VDD rise) : 2.92V (Typ. )
	//
	// The threshold voltages of VLS1 (VDD fall) : 4 types selectable 3.3V/ 3.6V/ 3.9V/ 4.2V (Typ.)
	// The VLS0 can be used as the low voltage level detector reset.
	// 
	// See ML610Q111/ML610Q112 User Manual - Section 22: Voltage Level Supervisor
	//
	//==============================================================================

   	// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	// INTERRUPT SETUP...
		//	The ML610Q1xx mcu's have 31 hardware interrupt sources 
		//		 7 External Interrupt Sources
		//		24 Internal Interrupt Sources 
		// EXAMPLE: WDT; VLS; EXTERNAL INT Pins (6); SPI; ADC; I2C (Slave); I2C (Master);
		//			TIMERS (6); UART; Comparators (2); PWM's ((4); TBC (4)		
	
		irq_di();	// Disable Interrupts
		//irq_init();	// Initialize Interrupts (All Off and NO Requests)
			//====================================================================
			//FOR NOTES ONLY...This is all taken care of in "irq_init()"
				// INTERRUPT ENABLE REGISTERS...
				//  IE0 = VOLTAGE LEVEL SUPERVISOR Int.
				//  IE1 = EXTERNAL Ints on B3, B2, B1, B0, A2, A1, & A0
				//  IE2 = SPI, A/D, I2C Slave & I2C Master Int.
				//  IE3 = TIMERS 8 & 9 Ints.
				//  IE4 = UART & COMPARATOR Ints.
				//  IE5 = TIMERS A, B, E & F Ints.
				//  IE6 = PWMC, PWMD, PWME, PWMF & 128Hz & 32Hz TBC Ints.
				//  IE7 = 16Hz & 2Hz TBC Ints.
				//IE0 = IE1 = IE2 = IE3 = IE4 = IE5 = IE6 = IE7 = 0;
				//--------------------------------------------------------------
				// INTERRUPT REQUEST FLAG REGISTERS...
				//  IRQ0 = WDT & VLS Int Requests
				//  IRQ1 = EXTERNAL Int Requests
				//  IRQ2 = SPI, A/D, I2C Slave & I2C Master Int Requests
				//  IRQ3 = TIMERS 8 & 9 Int Requests 
				//  IRQ4 = UART & COMPARATOR Int Requests 
				//  IRQ5 = TIMERS A, B, E & F Int Requests 
				//  IRQ6 = PWMC &  128Hz & 32Hz TBC Int Requests 
				//  IRQ7 = 16Hz & 2Hz TBC Int Requests 
				//IRQ0 = IRQ1 = IRQ2 = IRQ3 = IRQ4 = IRQ5 = IRQ6 = IRQ7 = 0;
			//====================================================================

			// INTERRUPT ENABLE REGISTERS...
				IE0 = IE1 = IE2 = IE3 = IE4 = IE5 = IE6 = IE7 = 0;


			// INTERRUPT REQUEST REGISTERS...
				IRQ0 = IRQ1 = IRQ2 = IRQ3 = IRQ4 = IRQ5 = IRQ6 = IRQ7 = 0;

 			//------------- SET UP UART Interrupts Handler -------------------------------------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_UA0INT, _intUart );
					EUA0 = 1; 	// EUA0 is the enable flag for the UART0 interrupt (1=ENABLED)
					QUA0 = 0;	// Request Flag for the UART_0 	INTERRUPT (1=REQUEST, 0-NO-REQUEST)
			//----------------------------------------------------------------------------------------
			
 			//------------- SET UP I2C MASTER Interrupts Handler -------------------------------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_I2CMINT, _intI2c );
					EI2CM = 1; // EI2CM is the enable flag for the I2C MASTER interrupt (1=ENABLED)
					QI2CM = 0;
			//----------------------------------------------------------------------------------------
			
			//------------- SET UP ADC Interrupts Handler --------------------------------------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_SADINT, _intADC );
					ESAD = 1; // ESAD is the enable flag for the ADC interrupt (1=ENABLED)
					QSAD = 0; // Request Flag for the ADC INTERRUPT (1=REQUEST, 0-NO-REQUEST)
			//----------------------------------------------------------------------------------------
			
			//------------- SET UP  xHz TBC Interrupt (Options: 128Hz, 32Hz, 16Hz, 2Hz) --------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_T2HINT, TBC_ISR );  //Clear interrupt request flag
					E2H = 1;	  // Enable x Hz TBC Interrupt (1=ENABLED)
					Q2H = 0;	  // Request flag for the TIME BASE COUNTER 2Hz Interrupt
			// -----			
			//------------- TBC...Set Ratio: : 1:1 => 1_1 --------------------------------------------
				(void)tb_setHtbdiv( (unsigned char)TB_HTD_1_1 ); //Set the ratio of dividing frequency of the time base counter
			//---------------------------------------------------------------------------------------- 
			
 			//------------- SET UP TIMER 8/9 Interrupt to increment timers every ~X ms ---------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_TM9INT, TMR89_ISR );  //Clear interrupt request flag
					ETM8 = 1;	  	// Enable timer 8 Interrupt (1=ENABLED
					ETM9 = 1;	  	// Enable timer 9 Interrupt (1=ENABLED)
					QTM8 = 0;		// Timer 8 IRQ request flag; 1=REQUEST
					QTM9 = 0;		// Timer 9 IRQ request flag; 1=REQUEST
					T8CS0 = 1;		// 111 => Select PLLCLK
					T8CS1 = 1;
					T8CS2 = 1;
					T9CS0 = 1;		// 111 => Select PLLCLK
					T9CS1 = 1;
					T9CS2 = 1; 
					tm_init(TM_CH_NO_89);
					tm_set89Data(8192);				//A value of 1023 should yield 125us interrupts at 8.192 MHz
					tm_set89Source(TM_CS_HTBCLK);
					tm_start89();
					T89M16 = 1;		//1 => sets 16-bit timer mode
				
					HTD3 = 1;	//High-Speed Time Base Counter Divide Register: 1111 = 9182kHz
					HTD2 = 1;
					HTD1 = 1;
					HTD0 = 1; 
			//----------------------------------------------------------------------------------------

			
 			//------------- SET UP TIMER A/B Interrupt to increment timers every ~X ms ---------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_TMBINT, TMRAB_ISR );  //Clear interrupt request flag
					ETMA = 1;	  	// Enable timer 8 Interrupt (1=ENABLED
					ETMB = 1;	  	// Enable timer 9 Interrupt (1=ENABLED)
					QTMA = 0;		// timer 8 IRQ request flag; 1=REQUEST
					QTMB = 0;		// timer 9 IRQ request flag; 1=REQUEST
					TACS0 = 1;		// 111 => Select PLLCLK
					TACS1 = 1;
					TACS2 = 1;
					TBCS0 = 1;		// 111 => Select PLLCLK
					TBCS1 = 1;
					TBCS2 = 1; 
					tm_init(TM_CH_NO_AB);
					tm_setABData(8192);				//A value of 1023 should yield 125us interrupts at 8.192 MHz
					tm_setABSource(TM_CS_HTBCLK);
					tm_startAB();
					TABM16 = 1;		//1 => sets 16-bit timer mode
				
					HTD3 = 1;	//High-Speed Time Base Counter Divide Register: 1111 = 9182kHz
					HTD2 = 1;
					HTD1 = 1;
					HTD0 = 1; 
			//----------------------------------------------------------------------------------------

			
			//------------- SET UP TIMER E/F Interrupt to increment timers every ~X ms ---------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_TMFINT, TMREF_ISR );  //Clear interrupt request flag
					ETME = 1;	  	// Enable timer E Interrupt (1=ENABLED
					ETMF = 1;	  	// Enable timer F Interrupt (1=ENABLED)
					QTME = 0;		// Timer E IRQ request flag; 1=REQUEST
					QTMF = 0;		// Timer F IRQ request flag; 1=REQUEST
					TECS0 = 1;		// 111 => Select PLLCLK
					TECS1 = 1;
					TECS2 = 1;
					TFCS0 = 1;		// 111 => Select PLLCLK
					TFCS1 = 1;
					TFCS2 = 1;
					tm_init(TM_CH_NO_EF);
					tm_setEFData(8192);				//A value of 1023 should yield 125us interrupts at 8.192 MHz
					tm_setEFSource(TM_CS_HTBCLK);
					tm_startEF();
					TEFM16 = 1;		//1 => sets 16-bit timer mode
				
					HTD3 = 1;	//High-Speed Time Base Counter Divide Register: 1111 = 9182kHz
					HTD2 = 1;
					HTD1 = 1;
					HTD0 = 1; 
			//----------------------------------------------------------------------------------------
			
			//------------- SET UP B.3 as an input, and prepare to use as an external interrupt ------
					PB3DIR = 1;
					PB3C1 = 0;
					PB3C0 = 0;
					PB3MD1 = 0;
					PB3MD0 = 0;
					PB3E1 = 1;
					PB3E0 = 0;		//PBnE0-1 are used to choose the Rising-Edge Mode for this interrupt
					PB3SM = 0;
			// -----
			//------------- SET UP EXTERNAL INTERRUPT on B.3 -----------------------------------------
			//Options include following pins: A.0; A.1; A.2. B.0; B.1; B.2 & B.3
			(void)irq_setHdr( (unsigned char)IRQ_NO_PB3INT, ExtInt_ISR );  //Clear interrupt request flag
					EPB3 = 0;	// 1=> Enables Interrupt
					QPB3 = 0;	// EXT IRQ request flag; 1=REQUEST	
			//----------------------------------------------------------------------------------------   
	
			
	irq_ei(); // Enable Interrupts
	// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII  

	// ===== SET UP WATCH DOG TIMER =============================================
		WDTMOD = 0x03; 	// 0x03=overflow 8sec...
		main_clrWDT(); 	// Clear WDT   
	//===========================================================================
	
	
	// ===== UART Initialization ================================================
	//
	//	Pin PB0 of mcu => RX  
	// 	Pin PB1 of mcu => TX 
	// 
		(void)uart_init( (unsigned char)UART_CS_HSCLK,	// Generator       				
				 (unsigned short)HSCLK_KHZ,				// HSCLK frequency 				
				 &_uartSetParam );						// Parameters from Structure    
		uart_PortSet();									// Set UART Port Pins
		_flgUartFin = 0;
		uart_stop();

	//	
	//===========================================================================

	// ===== I2C Initialization =================================================
	//	(void)i2c_init(I2C_MOD_FST, (unsigned short)HSCLK_KHZ, I2C_SYN_ON);
	//	I20SYN = 1;		//Enable Clock Stretching	
	//===========================================================================



		
		
}//End Initialization
Exemplo n.º 14
0
Arquivo: console.c Projeto: wuwx/simba
int console_stop(void)
{
    return (uart_stop(&module.console.uart));
}