Exemplo n.º 1
0
void notmain ( void ) {
    uart_init();
    hexstring(0x12345678);
    hexstring(GETPC());
    timer_init();

    /*
     * 132 byte packet.  All fields are 1 byte except for the 128 byte data
     * payload.
     * 		+-----+------+----------+--....----+-----+
     * 		| SOH | blk# | 255-blk# | ..data.. | cksum |
     * 		+-----+------+----------+--....----+-----+
     * Protocol:
     * 	- first block# = 1.
     *  - CRC is over the whole packet
     *  - after all packets sent, sender transmits a single EOT (must ACK).
     */
    unsigned char block = 1;
    unsigned addr = ARMBASE;
    while (1) {
        unsigned char b;

        // We received an EOT, send an ACK, jump to beginning of code
        if((b = getbyte()) == EOT) {
            uart_send(ACK);
            BRANCHTO(ARMBASE);
            return; // NOTREACHED
        }

        /*
         * if first byte is not SOH, or second byte is not the
         * expected block number or the third byte is not its
         * negation, send a nak for a resend of this block.
         */
        if(b != SOH
                || getbyte() != block
                || getbyte() != (0xFF - block)) {
            uart_send(NAK);
            continue;
        }

        // get the data bytes
        int i;
        unsigned char cksum;
        for(cksum = i = 0; i < PAYLOAD_SIZE; i++) {
            cksum += (b = getbyte());
            PUT8(addr+i, b);
        }

        // Checksum failed: NAK the block
        if(getbyte() != cksum)
            uart_send(NAK);
        // Commit our addr pointer and go to next block.
        else {
            uart_send(ACK);
            addr += PAYLOAD_SIZE;
            block++;
        }
    }
}
Exemplo n.º 2
0
void keyscan()
{
    P2=0xfe;
    temp=P2;
    temp=temp&0xf0;
    while(temp!=0xf0)
    {
      delay(5);
      temp=P2;
      temp=temp&0xf0;
      while(temp!=0xf0)
      {
       	temp=P2;
      	switch(temp)
       {
        case 0xee: uart_send(4);
         break;
        case 0xde: uart_send(4);
         break;
        case 0xbe: uart_send(4);
         break;
        case 0x7e: uart_send(4);
         break;
       }
      while(temp!=0xf0)
       {
        temp=P2;
        temp=temp&0xf0;
       }
      }
     }
}
Exemplo n.º 3
0
/** @brief Run the application.
 */
static void boot(void)
{
#ifdef ENABLE_UART
  // extra null bytes to make sure the status is properly sent
  uart_send(0);
  uart_send(0);
  // wait for the last byte
  while( !(UCSRxA & ((1<<UDREx)|(1<<TXCx))) ) ;
  UCSRxB = 0; // disable
#endif
#ifdef ENABLE_I2C_SLAVE
  TWCR = 0;
  TWAR = 0;
#endif

  /* interruptions not used, moving interrupt vector not needed
  IVCR = (1<<IVCE);
  IVCR = (0<<IVSEL);
   */

#ifdef BOOT_CODE
  do{ BOOT_CODE }while(0);
#endif
  run_app();
}
Exemplo n.º 4
0
//------------------------------------------------------------------------
void notmain ( void )
{
    //unsigned int ra;

    switch_to_80Mhz();

    uart_init();
    hexstring(0x87654321);
    hexstring(0x12345678);

    //Cortex-M4 systick timer init
    PUT32(STCTRL,0x00000004);
    PUT32(STRELOAD,1000000-1);
    PUT32(STCURRENT,0); //value is a dont care
    PUT32(STCTRL,0x00000005);

    while(1)
    {
        uart_send(0x55);
        dowait();
        uart_send(0x56);
        dowait();
    }

}
Exemplo n.º 5
0
void bootmain(void)
{
	uart_send('Y');
	uart_send('\n');

	while(1)
	return;
}
void sserial_sendbyte(byte bt)
{
	uart_send(sserial_portindex,bt);sserial_crc16=_crc16_update(sserial_crc16,bt);
	if (bt==0x98)
	{
		uart_send(sserial_portindex,0);
	}
}
Exemplo n.º 7
0
void uart_drawline(uint8_t length, const uint8_t space){
	if(space){uart_send('\r');uart_send('\n');}
	while(length){
		length--;
		uart_send('-');
	}
	if(space){uart_send('\r');uart_send('\n');}
}
Exemplo n.º 8
0
void uart_send_word_i(uint8_t i, uint16_t w, const char *s){
	char print[5];
	itoa(i, print, 10);
	uart_puts(print); uart_send('.');
	uart_puts(s); uart_send(' ');
	itoa(w, print, 10);
	uart_puts(print); uart_send(' ');
}
Exemplo n.º 9
0
int
uart_put(char c, FILE *stream)
{
	if (c == '\n')
		uart_send('\r');
	uart_send(c);
	return 0;
}
void request_feedback(unsigned char num)				//send command to request the current position of servo
{	
	//servo channel should start with 0b01XX XXXX
	//therefore needs to change to 0x41-0x60
		num=num|0b01000000;
		
			uart_send('@');  							//First byte is the start byte: '@' or 0x40
			uart_send(num);								//Second byte is the requsting servo channle 0x41-0x60
}
Exemplo n.º 11
0
/*
 *  システムログの低レベル出力のための文字出力
 */
void
target_fput_log(char c)
{
    // Port 1 is always used for low level ouput (e.g. LOG_EMERG)
	if (c == '\n') {
		while(!uart_send(&UART1, '\r'));
	}
	while(!uart_send(&UART1, c));
}
Exemplo n.º 12
0
void puts_unsafe(const char *string)
{
    const char *cur = string;
    for (; *cur; ++cur)
    {
        uart_send(*cur);
    }
    uart_send(CR);
    uart_send(LF);
}
Exemplo n.º 13
0
void sserial_send_response ()
{
	sserial_send_start(sserial_portindex);
	uart_send(sserial_portindex,0);
	uart_send(sserial_portindex,0);
	uart_send(sserial_portindex,0x98);
	uart_send(sserial_portindex,0x03);
	sserial_crc16=0xFFFF;
	sserial_sendbyte(sserial_address>>8);
	sserial_sendbyte(sserial_address&255);
	sserial_sendbyte(sserial_response.result);
	for (unsigned int i=0; i< sserial_response.datalength; i++)
	{
		sserial_sendbyte(sserial_response.data[i]);
	}
	uint16_t crc=sserial_crc16;
	sserial_sendbyte(crc>>8);
	sserial_sendbyte(crc&255);
	uart_send(sserial_portindex,0x98);
	uart_send(sserial_portindex,0x04);
	uart_send(sserial_portindex,0);
	uart_send(sserial_portindex,0);
	uart_send(sserial_portindex,0);
	sserial_send_end(sserial_portindex);
}
Exemplo n.º 14
0
void print_ch(u8 ch)
{
	if (ch == '\n') {
		uart_send('\r');
		uart_send('\n');
	} else if (ch == '\r') {
		uart_send('\r');
		uart_send('\n');
	} else {
		uart_send(ch);
	}
}
Exemplo n.º 15
0
/**
  * @file   void uart_configuration(void)
  * @brief  ÅäÖô°¿Ú
  * @param  None
  * @retval None
  */
ErrorStatus debug_msg(u8 *pFile, u16 ulLine)
{
    u16 unFileSize = 0;
    u8 aLineBuf[16] = {0};
    u8 aLineString[16] = {0};
    u8 ucLineSize = 0;
    u16 ulTemp = 0;
    u8 i = 0;

    if(NULL == pFile)
    {
        return ERROR;
    }
    /*! ¼ÆËã__FILE__×Ö·û´®³¤¶È */
    while('\0' != *(pFile+unFileSize))
    {
        unFileSize++;
    }
    /*! ´®¿ÚÊä³öÎļþÃû³Æ */
    uart_send(UART_NUM_1, pFile, unFileSize);

    /*! ½«__LINE__ת»»Îª×Ö·û´® */
    aLineString[0] = ' ';
    if(ulLine < 1)
    {
        ucLineSize = 1;
        aLineString[1] = '0';
        aLineString[2] = '\r';
        aLineString[3] = '\n';
    }
    else
    {
        ucLineSize = 0;
        ulTemp = ulLine;
        while(ulTemp != 0)
        {
            aLineBuf[ucLineSize] = ulTemp % 10 + '0';
            ulTemp = ulTemp / 10;
            ucLineSize++;
        }
        /*! ×Ö·û´®·´Ë³Ðò */
        for(i=0; i<ucLineSize; i++)
        {
            aLineString[i+1] = aLineBuf[ucLineSize-i-1];
        }
        aLineString[ucLineSize+1] = '\r'; /*!< ×Ö·û´®½áβ */
        aLineString[ucLineSize+2] = '\n';
    }
    /*! ´®¿ÚÊä³öÐкżӻ»ÐÐ */
    uart_send(UART_NUM_1, aLineString, ucLineSize+3);

    return SUCCESS;
}
Exemplo n.º 16
0
int notmain ( void )
{    /* 0x10009000 UART0.  */

    unsigned int rx;
    for(rx=0;rx<8;rx++)
    {
        PUT32(UART0BASE+0x00,0x30+(rx&7));
    }
    uart_send(0x0D);
    uart_send(0x0A);
    hexstring(GETPC());
    return(0);
}
Exemplo n.º 17
0
bool send_address(uint8_t address, uint8_t write)
{
    int c = 0;
begin:
    uart_send("START");
    // Set the START flag
    
    SEND_AND_WAIT(1, 1 << TWSTA);
    
    if (TW_STATUS != TW_START && TW_STATUS != TW_REP_START) {
        DUMP_ERROR();
        return false;
    }
    
    if (write == TW_WRITE) {
        uart_send("SLA+W");
    } else {
        uart_send("SLA+R");
    }
    
    // Write the address + write byte
    TWDR = (address << 1) | write;
    SEND_AND_WAIT(1, 0);
    
    uint8_t ack;
    uint8_t nack;
    if (write == TW_WRITE) {
        ack = TW_MT_SLA_ACK;
        nack = TW_MT_SLA_NACK;
    } else {
        ack = TW_MR_SLA_ACK;
        nack = TW_MR_SLA_NACK;
    }
    
    if (TW_STATUS == nack) {
        c++;
        if (c > 3) {
            DUMP_ERROR();
            return false;
        } else {
            goto begin;
        }
    } else if (TW_STATUS != ack) {
        DUMP_ERROR();
        return false;
    }
    
    return true;
}
void
pn532_uart_wakeup (const nfc_device_spec_t nds)
{
  byte_t  abtRx[RX_BUFFER_LEN];
  size_t  szRx = PN53x_NORMAL_FRAME_OVERHEAD + 2;
  /** PN532C106 wakeup. */
  /** High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
  /** After the preamble we request the PN532C106 chip to switch to "normal" mode (SAM is not used) */
  const byte_t pncmd_pn532c106_wakeup_preamble[] = 
    { 0x55, 0x55, 0x00, 0x00, 0x00, 
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, 0x00 }; // Here we send a SAMConfiguration command (Normal mode, the SAM is not used; this is the default mode)
#ifdef DEBUG
  PRINT_HEX ("TX", pncmd_pn532c106_wakeup_preamble, sizeof (pncmd_pn532c106_wakeup_preamble));
#endif
  uart_send ((serial_port) nds, pncmd_pn532c106_wakeup_preamble, sizeof (pncmd_pn532c106_wakeup_preamble));

  pn532_uart_wait_for_ack(nds);

  if (0 == uart_receive ((serial_port) nds, abtRx, &szRx)) {
#ifdef DEBUG
    PRINT_HEX ("RX", abtRx, szRx);
#endif
  } else {
    ERR ("Unable to wakeup the PN532.");
  }
}
Exemplo n.º 19
0
void
arygon_firmware(nfc_device *pnd, char *str)
{
  const uint8_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' };
  uint8_t abtRx[16];
  size_t szRx = sizeof(abtRx);


  int res = uart_send(DRIVER_DATA(pnd)->port, arygon_firmware_version_cmd, sizeof(arygon_firmware_version_cmd), 0);
  if (res != 0) {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Unable to send ARYGON firmware command.");
    return;
  }
  res = uart_receive(DRIVER_DATA(pnd)->port, abtRx, szRx, 0, 0);
  if (res != 0) {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Unable to retrieve ARYGON firmware version.");
    return;
  }

  if (0 == memcmp(abtRx, arygon_error_none, 6)) {
    uint8_t *p = abtRx + 6;
    unsigned int szData;
    sscanf((const char *)p, "%02x%9s", &szData, p);
    if (szData > 9)
      szData = 9;
    memcpy(str, p, szData);
    *(str + szData) = '\0';
  }
}
void send_cmd(unsigned char num, unsigned int data, unsigned char ramp)		//send 4 bytes of command to control servo's position and speed
{
	unsigned char higher_byte=0, lower_byte=0;
	
	//position value from 0-1463 are greater than a byte
	//so needs two bytes to send
	higher_byte=(data>>6)&0x003f;	//higher byte = 0b00xxxxxx
	lower_byte=data&0x003f;			//lower byte  = 0b00xxxxxx

	
			uart_send(num);								//First byte is the servo channel 0x41-0x60
			uart_send(higher_byte);						//second byte is the higher byte of position 0b00xxxxxx
			uart_send(lower_byte);						//third byte is the lower byte of position 0b00xxxxxx
			uart_send(ramp);							//fourth byte is the speed value from 0-63 

}
Exemplo n.º 21
0
/*============================================================================*/
void uart_handshake_init(void)
{
    /* switch to meta port */
    mtk_serial_set_current_uart(CFG_UART_META);

    /* if meta and log ports are SAME, need to re-init meta port with
     * different baudrate and disable log output during handshake to avoid
     * influence.
     */
    if (CFG_UART_META == CFG_UART_LOG) {
        /* to prevent sync error with PC */
	    gpt_busy_wait_us(160);
	    /* init to meta baudrate */
        mtk_uart_init(UART_SRC_CLK_FRQ, CFG_META_BAUDRATE);
        /* disable log so that log message will be kept in log buffer */
        log_buf_ctrl(0);
        log_ctrl(0);
    }

    /* send meta ready to tool via meta port first then let meta port to listen
     * meta response in the background to reduce the handshake wait time later.
     */
    uart_send((u8*)HSHK_COM_READY, strlen(HSHK_COM_READY));
    mtk_serial_set_current_uart(CFG_UART_LOG);

    g_meta_ready_start_time = get_timer(0);
}
Exemplo n.º 22
0
void protocol_step()
{
	if (protocol_next_step > task_get_ms_tick())
		return;

	char buffer[128];

	switch (config.connectivity.protocol)
	{
		case(PROTOCOL_DIGIFLY):
			protocol_digifly_step(buffer);
		break;

		case(PROTOCOL_LK8EX1):
			protocol_lk8ex1_step(buffer);
		break;

		case(PROTOCOL_BLUEFLY):
			protocol_bluefly_step(buffer);
		break;

		case(PROTOCOL_FLYNET):
			protocol_flynet_step(buffer);
		break;
	}

	//XXX:outputs
	if (config.connectivity.uart_function > UART_FORWARD_OFF)
		uart_send(buffer);

	bt_send(buffer);
//	DEBUG("%s", buffer);
}
Exemplo n.º 23
0
//-------------------------------------------------------------------
static void hexstrings ( unsigned int d )
{
    unsigned int rb;
    unsigned int rc;

    rb=32;
    while(1)
    {
        rb-=4;
        rc=(d>>rb)&0xF;
        if(rc>9) rc+=0x37; else rc+=0x30;
        uart_send(rc);
        if(rb==0) break;
    }
    uart_send(0x20);
}
Exemplo n.º 24
0
void serial_writestr(unsigned char *data)
{
	char i = 0, r;

	while ((r = data[i++]))
		uart_send(r);
}
Exemplo n.º 25
0
/* send answerback message */
void vt100_ENQ(void)
{
	for(uint8_t i=0; i < ANSWERBACK_SIZE; i++)
	{
		uart_send(parm_setting.answerback[i]);
	}
}
Exemplo n.º 26
0
int
arygon_reset_tama(nfc_device *pnd)
{
  const uint8_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' };
  uint8_t abtRx[10]; // Attempted response is 10 bytes long
  size_t szRx = sizeof(abtRx);
  int res;

  uart_send(DRIVER_DATA(pnd)->port, arygon_reset_tama_cmd, sizeof(arygon_reset_tama_cmd), 500);

  // Two reply are possible from ARYGON device: arygon_error_none (ie. in case the byte is well-sent)
  // or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted)
  res = uart_receive(DRIVER_DATA(pnd)->port, abtRx, szRx, 0, 1000);
  if (res != 0) {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "No reply to 'reset TAMA' command.");
    pnd->last_error = res;
    return pnd->last_error;
  }

  if (0 != memcmp(abtRx, arygon_error_none, sizeof(arygon_error_none) - 1)) {
    pnd->last_error = NFC_EIO;
    return pnd->last_error;
  }

  return NFC_SUCCESS;
}
Exemplo n.º 27
0
static int
pn532_uart_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
{
  int res = 0;
  // Before sending anything, we need to discard from any junk bytes
  uart_flush_input(DRIVER_DATA(pnd)->port);

  switch (CHIP_DATA(pnd)->power_mode) {
    case LOWVBAT: {
      /** PN532C106 wakeup. */
      if ((res = pn532_uart_wakeup(pnd)) < 0) {
        return res;
      }
      // According to PN532 application note, C106 appendix: to go out Low Vbat mode and enter in normal mode we need to send a SAMConfiguration command
      if ((res = pn532_SAMConfiguration(pnd, PSM_NORMAL, 1000)) < 0) {
        return res;
      }
    }
    break;
    case POWERDOWN: {
      if ((res = pn532_uart_wakeup(pnd)) < 0) {
        return res;
      }
    }
    break;
    case NORMAL:
      // Nothing to do :)
      break;
  };

  uint8_t  abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff };       // Every packet must start with "00 00 ff"
  size_t szFrame = 0;

  if ((res = pn53x_build_frame(abtFrame, &szFrame, pbtData, szData)) < 0) {
    pnd->last_error = res;
    return pnd->last_error;
  }

  res = uart_send(DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout);
  if (res != 0) {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
    pnd->last_error = res;
    return pnd->last_error;
  }

  uint8_t abtRxBuf[6];
  res = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 6, 0, timeout);
  if (res != 0) {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Unable to read ACK");
    pnd->last_error = res;
    return pnd->last_error;
  }

  if (pn53x_check_ack_frame(pnd, abtRxBuf, sizeof(abtRxBuf)) == 0) {
    // The PN53x is running the sent command
  } else {
    return pnd->last_error;
  }
  return NFC_SUCCESS;
}
Exemplo n.º 28
0
static void *uart_receiver(void *targ) {
  struct receiver_arg *arg = (struct receiver_arg*)targ;
  size_t rxlen;
  size_t cmd_count;
  
  while (arg->run) {
    rxlen = sizeof(UsbCommand);
    if (uart_receive(sp,prx,&rxlen)) {
      prx += rxlen;
      if (((prx-rx) % sizeof(UsbCommand)) != 0) {
        continue;
      }
      cmd_count = (prx-rx) / sizeof(UsbCommand);
      //      printf("received %d bytes, which represents %d commands\n",(prx-rx), cmd_count);
      for (size_t i=0; i<cmd_count; i++) {
        UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
      }
    }
    prx = rx;
    
    if(txcmd_pending) {
      if (!uart_send(sp,(byte_t*)&txcmd,sizeof(UsbCommand))) {
        PrintAndLog("Sending bytes to proxmark failed");
      }
      txcmd_pending = false;
    }
  }
  
  pthread_exit(NULL);
  return NULL;
}
Exemplo n.º 29
0
int main(void)
{
    char str[30];
    status_init();
    adc_init();
    
    status_set(false);
    
    uart_init(1);
    twi_init(0xC);
    twi_enable_interrupt();
    twi_register_get(get);
    
    measurement = 0;
    
    sei();
    
    while (1) {
        
        // VRef is 2.56V
        // at T = 0, VOut = 0V. VOut scales at 10mV / ºC
        // T = adc * (2.56 / 1024) * 100
        // T = adc * 256 / 1024
        // T = adc / 4
        uint16_t read = adc_read();
        measurement = read / 4;
        sprintf(str, "%dºC (raw = %d)", measurement, read);
        
        uart_send(str);
        _delay_ms(500);
    }
    
}
Exemplo n.º 30
0
/*
void uart_send_array(const uint8_t *arr, const uint8_t size)
{
	for(uint8_t i=0; i < size; i++)
	{
		uart_send(arr[i]);
	}
}
*/
void uart_send_string(const char *string)
{
	for(uint8_t i=0; string[i]; i++)
	{
		uart_send(string[i]);
	}
}