/*
 *  ターゲットシステム依存の初期化
 */
void
sys_initialize()
{
    int i;

    init_vector();			/* SRAMのリマップ。LPC2388共通 */

    init_clock();			/* PLLの設定。システム固有 */

    init_uart0();			/* UART0の初期化。システム固有 */

    init_IRQ();				/* VICを初期化する。LPC2388共通 */

    		/* 必要なペリフェラルの電源を入れる(システム固有) */
			/* なお、UART0とTIMER3はLPC2388共通で必要 */
	PCONP |= 0x00800008;	/* bit3:UART0, bit23:TIMER3 */

			/* UART0のピンを設定 (LPC2388共通) */
	PINSEL0 &= ~0xF0;			/* bit 4-7だけをクリア */
	PINSEL0 |= 0x50;			/* UART入出力を割り当て */

    /*
     *  ARMのベクタテーブルへ割込みハンドラを登録(どのARMv4システムでも要求される)
     */
    arm_install_handler(IRQ_Number,IRQ_Handler);

    /*
     * Memory Acceleration Moduleの設定 ( NXP社 UM10211 chapter 7 )
     * Flashメモリのプリフェッチを使ってプログラム実行を高速化する
     */
    MAMCR = 0;		/* 念のためMAMをオフにする */
    MAMTIM = 4;		/* UM10211によれば、60MHz以上で動作するときは4に設定する */
    MAMCR = 2;		/* MAM機能をオンにする */

}
Exemple #2
0
void umain(void)
{
	struct uart_res *port0 = get_port_entry(0);
#ifdef DEBUG_LEDS
	lights(2);
#endif /* DEBUG_LEDS */

	init_uart0(port0);

	while(1) {
		serial_printf(0, "%c,%c,%c,%c\n", '-', '+', '*', '/');
		serial_printf(0, "%s\n", __func__);
		serial_printf(0, "%p\n", umain);
		serial_printf(0, "%#X\n", (u32)umain);
		serial_printf(0, "%#o\n", 1234);
		serial_printf(0, "%#+6.4x\n", 12345678);
		serial_printf(0, "%#+5.8s\n", "hello world...");
		serial_printf(0, "%#x\n", 0x1234567);
		serial_printf(0, "-> %s %d\n", "i'm:", 618);
	}

#ifdef DEBUG_LEDS
	lights(3);
#endif /* DEBUG_LEDS */
}
Exemple #3
0
int main ()
{
	
	init_uart0();
	uart0_tx (0xFF);
	
	while (1)
	{
		
	}
}
void GUIDEMO_Touch(void) {
	
  #define ID_KEYBOARD  1
  #define ID_TESTCAL   2
  #define ID_CALIBRATE 3
  int i, r;
  int XSize = LCD_GetXSize();
  int YSize = LCD_GetYSize();
  int XMid = XSize / 2;
  int YMid = YSize / 2;
  //GUIDEMO_NotifyStartNext();
  GUIDEMO_HideInfoWin();
  
  do {
    GUI_RECT rText;/*= {0, 80, XSize, 120};*/
    BUTTON_Handle ahButton[3];
    rText.x0=0;
    rText.y0=50;
    rText.x1=XSize;
    rText.y1=90;
    GUI_SetBkColor(GUI_BLUE);
    GUI_Clear();
    GUI_DrawBitmap(&bmMicriumLogo, (XSize - 1 - bmMicriumLogo.XSize) / 2, 15);
    GUI_SetFont(&GUI_Font16B_1);
    GUI_DispStringInRect("µC/GUI Touch screen demo", &rText, GUI_TA_HCENTER | GUI_TA_VCENTER);
    ahButton[0] =  BUTTON_Create( XMid - 50, YMid - 30, 100, 50, ID_CALIBRATE,BUTTON_CF_SHOW );
    ahButton[1] =  BUTTON_Create( XMid - 90, YMid + 30, 80, 30, ID_KEYBOARD, BUTTON_CF_SHOW );
    ahButton[2] =  BUTTON_Create( XMid + 10, YMid + 30, 80, 30, ID_TESTCAL,BUTTON_CF_SHOW );
    BUTTON_SetText (ahButton[0], "Calibrate");
    BUTTON_SetBkColor(ahButton[0], 0, GUI_RED);
    BUTTON_SetText (ahButton[1], "Keyboard");
    BUTTON_SetText (ahButton[2], "Test calibration");
    BUTTON_SetFont(ahButton[0], &GUI_FontComic18B_ASCII);
    r = GUIDEMO_WaitKey();
    if (r==0) {
      r = ID_KEYBOARD;
      BUTTON_SetState(ahButton[1],BUTTON_STATE_PRESSED);
      GUIDEMO_Delay(500);
    }
    for (i=0; i< countof(ahButton); i++) {
      BUTTON_Delete(ahButton[i]);
    }
    switch (r) {
    case ID_KEYBOARD:  init_uart0(); send_press_key(); break;
    case ID_CALIBRATE: _ExecCalibration(); break;
    case ID_TESTCAL:   _TestCalibration(); break;
    }
  } while (r && (r!='n') && (r!='N'));
}
static void setupHardware(void) {
    // TODO: Put hardware configuration and initialisation in here
    disable_global_int();
    clk_system_init();
    init_leds();
    //init_pot();
    init_buttons();
    init_spi();
    init_lcd_write_task();
    init_uart0();
    init_joystick();
     
    enable_global_int();
     
 
    // Warning: If you do not initialize the hardware clock, the timings will be inaccurate
}
Exemple #6
0
int
_write(int fd, char *ptr, int len)
{
  int rv = len;

  if (!initted)
    init_uart0 ();

  while (len != 0)
    {
      if (*ptr == '\n')
	tputc ('\r');
      tputc (*ptr);
      ptr ++;
      len --;
    }
  return rv;
}
int main()
{
    init_uart0();
    init_timer();
    put_string("\r\n\r\n\r\n\r\nInitialising...\r\n\r\n");
    char dest = 'D';
    char message[1000] = "Hello World!";
    //Above message is 107 characters
    put_number(strlen(message));
    put_string(" character long message reads:\r\n");
    put_string(message);

    int error = SendData(dest, message);
    if (error) put_string("Error sending message");

    while(1);
    return 0;
}
Exemple #8
0
int main() {
    uchar buffer,i,lastkey = 0;

    // Fetch password from EEPROM and send it
    eeprom_read_block(messageBuffer, stored_password, sizeof(messageBuffer));
    messagePtr = 0;
    messageState = STATE_SEND;

    for(i=0; i<sizeof(keyboard_report); i++) // clear report initially
        ((uchar *)&keyboard_report)[i] = 0;

    wdt_enable(WDTO_1S); // enable 1s watchdog timer
    init_uart0();
    usbInit();

    usbDeviceDisconnect(); // enforce re-enumeration
    for(i = 0; i<250; i++) { // wait 500 ms
        wdt_reset(); // keep the watchdog happy
        _delay_ms(2);
    }
    usbDeviceConnect();

//    TCCR0B |= (1 << CS01); // timer 0 at clk/8 will generate randomness

    sei(); // Enable interrupts after re-enumeration

    while(1) {
        wdt_reset(); // keep the watchdog happy
        usbPoll();
        buffer = UDR0;
        lastkey = buffer;
        // characters are sent when messageState == STATE_SEND and after receiving
        // the initial LED state from PC (good way to wait until device is recognized)
        if(usbInterruptIsReady() && messageState == STATE_SEND) {
            messageState = buildReport(lastkey);
            usbSetInterrupt((void *)&keyboard_report, sizeof(keyboard_report));
        }
    }

    return 0;
}
Exemple #9
0
int
_write(int fd, char *ptr, int len)
{
  int rv = len;

  if (_open_present && fd > 2)
    return _SYS_write (fd, ptr, len);

  if (!initted)
    init_uart0 ();

  while (len != 0)
    {
      if (*ptr == '\n')
	tputc ('\r');
      tputc (*ptr);
      ptr ++;
      len --;
    }
  return rv;
}
Exemple #10
0
/*
 * 主函数, 该程序主要测试中断系统的基本初始化
 * 使用UART RX中断实现CONSOLE程序,并完成了 LED ON, LED OFF, BEEP ON,BEEP OFF的功能
 */
int main (void)
{
	led_init ();
	beep_init() ;
	init_uart0 ();

	VIC2VECTADDR.VIC2VECTADDR23 = (unsigned int)adc_irq_handler;
	//通道0
	ADC.ADCMUX = 0 ;
				  //12BIT      预分频              分频值             读转换模式
	ADC.ADCCON = (1 << 16) | (1 << 14) | (65 << 6) | (0 << 1);

	VIC2INTERRUPT.VIC2INTENABLE = VIC2INTERRUPT.VIC2INTENABLE | (1 << 23);

	while (1){
		ADC.ADCCON = ADC.ADCCON | (1 << 0);
		while (flag == 0);
		flag = 0;
		adval = adval * 3300 / 4096;
		printf ("vol = %d mv\r\n", adval);
	}
	return 0 ;
}
Exemple #11
0
/**
 *	Initialize UART - platform dependent
 */
void init_uart(void)
{
	init_uart0((int)9600, UART_BITS_8, UART_STOP_BIT_1, UART_PARIT_OFF, 0 );
}
Exemple #12
0
void init_device() {
    PCONP_bit.PCUART0 = 0;
    PCONP_bit.PCPWM1 = 0;
    PCONP_bit.PCI2C0 = 0;
    PCONP_bit.PCSSP1 = 0;
    PCONP_bit.PCAN1 = 0;
    PCONP_bit.PCAN2 = 0;
    PCONP_bit.PCI2C1 = 0;
    PCONP_bit.PCSSP0 = 0;
    PCONP_bit.PCTIM2 = 0;
    PCONP_bit.PCTIM3 = 0;
    PCONP_bit.PCUART2 = 0;
    PCONP_bit.PCI2C2 = 0;
    PCONP_bit.PCI2S = 0;
    PCONP_bit.PCGPDMA = 0;
    PCONP_bit.PCENET = 0;

    init_timer0();
    init_at25df();
    init_led();
    init_updater();
    init_tasks();
    init_app_settings();
    create_ring_buff(pointerRingBuff, ring_buff, sizeof(ring_buff));

    init_uart0(57600, 3);
    INT_UART0RX_ON;

    init_irq();

    // Testing main pin (for locked mode)
    if (FIO2PIN_bit.P2_10 == 0) {
        return;
    }

    // Fork
    if (is_need_update() == TRUE_T) {
        DEBUG_PRINTF("BL:enable_update_task()\n\r");
        enable_update_task();
    } else {
        if (*((uint32_t *)(IAP_MAIN_SECT_ADDR + SHIFT_FW_VALID_FLG)) != IAP_VALID_DATA) {
            DEBUG_PRINTF("BL:repair_flash_iap()\n\r");
            repair_flash_iap();
        }

        uint32_t success_count = 0;
        const uint32_t fw_size = *((uint32_t *)(IAP_MAIN_SECT_ADDR + SHIFT_FW_SIZE_ADDR));
        const uint32_t fw_crc = *((uint32_t *)(IAP_MAIN_SECT_ADDR + SHIFT_FW_CRC_ADDR));

        DEBUG_PRINTF("BL:fw_size=0x%8x, fw_crc=0x%8x\n\r", fw_size, fw_crc);
        for (uint32_t i = 0; i < 3; i++) {
            uint8_t * pFw = (uint8_t *)FW_START_ADDRESS;
            uint32_t crc = 0;

            for (uint32_t k = 0; k < fw_size; k++) {
                crc += (uint32_t)(*pFw++);
            }

            crc = 0UL - crc;
            DEBUG_PRINTF("BL:compute crc=0x%8x\n\r", crc);
            if (fw_crc == crc) {
                success_count++;
                break;
            }
        }

        if (success_count > 0 && fw_crc) {
            DEBUG_PRINTF("BL:run_main_firmware()\n\r");
            waite_tx_all_uart0();
            run_main_firmware();
        }
    }
}
Exemple #13
0
void init_uart(void)
{
    init_uart0();
    init_uart1();
}
Exemple #14
0
int main
	(
	void
	)
	{
	init_uart0();
	
	/* For 2 MHz crystal use this hack */
	//BAUD0L_REG = 12;
	
	trigger_setup();
	
    //OSCCAL only needed for internal oscillator mode, doesn't hurt anyway
#ifdef OSCCAL
	OSCCAL = OSCCAL_UARTGOOD;	
	_delay_ms(500);
#else
    #ifdef VARYING_CLOCK
        #error "VARYING_CLOCK requested but target does not have OSCCAL register"
    #endif
#endif

 	/* Uncomment this to get a HELLO message for debug */
	/*
	output_ch_0('h');
	output_ch_0('e');
	output_ch_0('l');
	output_ch_0('l');
	output_ch_0('o');
	output_ch_0('\n');
	*/
			
	/* Super-Crappy Protocol works like this:
	
	Send kKEY
	Send pPLAINTEXT
	*** Encryption Occurs ***
	receive rRESPONSE
	
	e.g.:
	
    kE8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA\n
	p014BAF2278A69D331D5180103643E99A\n
	r6743C3D1519AB4F2CD9A78AB09A511BD\n
    */
		
	char c;
	int ptr = 0;
    
	//Initial key
	aes_indep_init();
	aes_indep_key(tmp);

	char state = 0;
	 
#ifdef VARYING_CLOCK
	uint8_t newosc;
#endif
	 
	while(1){
	
		c = input_ch_0();
		
		if (c == 'x') {
			ptr = 0;
			state = IDLE;
			continue;		
		}
		
		if (c == 'k') {
			ptr = 0;
			state = KEY;			
			continue;
		}
		
		else if (c == 'p') {
			ptr = 0;
			state = PLAIN;
			continue;
		}
		
		
		else if (state == KEY) {
			if ((c == '\n') || (c == '\r')) {
				asciibuf[ptr] = 0;
				hex_decode(asciibuf, ptr, tmp);
				aes_indep_key(tmp);
				state = IDLE;
			} else {
				asciibuf[ptr++] = c;
			}
		}
		
		else if (state == PLAIN) {
			if ((c == '\n') || (c == '\r')) {
				asciibuf[ptr] = 0;
				hex_decode(asciibuf, ptr, pt);

				/* Do Encryption */	

				//The following is used for varying the clock
#ifdef VARYING_CLOCK
				_delay_ms(25);
				
#ifdef OSCCAL_CENTER
				newosc = (rand() & OSCCAL_VARY);
				OSCCAL = OSCCAL_CENTER + (int8_t)((int8_t)(OSCCAL_VARY/2) - (int8_t)newosc);
#else
                OSCCAL = rand() & OSCMAX;
#endif
                
				_delay_ms(1);
#endif
				
				trigger_high();
				aes_indep_enc(pt); /* encrypting the data block */
				trigger_low();
				
#ifdef VARYING_CLOCK
				OSCCAL = OSCCAL_UARTGOOD;
				_delay_ms(100);
#endif
                
				/* Print Results */
				hex_print(pt, 16, asciibuf);
				
				output_ch_0('r');
				for(int i = 0; i < 32; i++){
					output_ch_0(asciibuf[i]);
				}
				output_ch_0('\n');
				
				state = IDLE;
			} else {
                if (ptr >= BUFLEN){
                    state = IDLE;
                } else {
                    asciibuf[ptr++] = c;
                }
			}
		}
	}
		
	return 1;
	}