コード例 #1
0
ファイル: fd.c プロジェクト: huangrui/Thunix
/*
 *    reset the floppy.
 *
 *    The first thing that the driver needs to do is reset the controller.This 
 * will put it in a known state. To reset the primary floppy controller,(in C)
 *
 * 1.write 0x00 to the DIGITAL_OUTPUT_REG of the desired controller
 * 2.write 0x0C to the DIGITAL_OUTPUT_REG of the desired controller
 * 3.wait for an interrupt from the controller
 * 4.check interrupt status (this is function 0x08 of controllers)
 * 5.write 0x00 to the CONFIG_CONTROL_REG
 * 6.configure the drive desired on the controller (function 0x03 of controller)
 * 7.calibrate the drive (function 0x07 of controller)
 *
 */
static void reset( )
{
        //LOG("reset() called ...\n");

        /* stop the motor and disable IRQ/DMA */
        outb_p(0x0c,FD_DOR);

        /* program data rate (500K/s) */
        outb_p(0,FD_DCR);
        
        /* re-enable interrupts */
        outb_p(0x1c,FD_DOR);

        /* resetting triggered an interrupt - handle it */
        done = TRUE;
        wait_fdc(TRUE);

        /* specify drive timings (got these off the BIOS) */
        send_byte(FD_SPECIFY);
        send_byte(0xdf);      /* SRT = 3ms, HUT = 240ms */
        send_byte(0x06);      /* HLT = 16ms, ND = 0     */

        recalibrate();
}
コード例 #2
0
ファイル: main.c プロジェクト: en0/stm32f10x_FreeRTOS
void send_byte(uint8_t b) {

    switch(b) {
        case '\n':
            send_byte('\r');
            USART_SendData(USART3, '\n');
            while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
            break;

        default:
            USART_SendData(USART3, b);
            break;

    }
    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
}
コード例 #3
0
ファイル: ir_encode.c プロジェクト: tanhangbo/RaspberryIR
void send_data(unsigned char* data, int len)
{
    int i  = 0;

    output_38k();
    delay_us(NEC_HDR_MARK);
    output_38k_off();
    delay_us(NEC_HDR_MARK - PWM_DELAY);

    for (i = 0; i < len; i++)
        send_byte(data[i]);

    send_bit(1);
    delay_us(NEC_HDR_MARK- PWM_DELAY);

}
コード例 #4
0
int Radio::connect() {
// Used on the arduino
   _rec = 0;
   if (is_connected()) return 0;
   for (int i=0; i<_max_connect_tries; i++) {
      _rec = get_byte();
      if (_rec == WAITING){
         while(!send_byte(CONNECT));
         return 0;
      }
      else delay(_WAITING_delay);
   }
   // failure to connect
   DEBUG("Failure to connect");
   return 1;
}
コード例 #5
0
ファイル: uart.c プロジェクト: vishwa91/e_steth
// log_num is used for logging numbers.
void log_num(int num)
{
  if(num < 0)
  {
    num *= -1;
    send_byte('-');
  }
    send_byte('0' + num/10000);
    send_byte('0' + (num/1000)%10);
    send_byte('0' + (num/100)%10);
    send_byte('0' + (num/10)%10);
    send_byte('0' + num%10);
    send_byte('|');
}
コード例 #6
0
ファイル: graphlinkhle.cpp プロジェクト: Dagarman/mame
void graph_link_hle_device::rcv_complete()
{
	receive_register_extract();
	if (m_ready)
	{
		assert(m_empty);

		send_byte(get_received_char());
		m_ready = false;
	}
	else
	{
		m_buffer[m_head] = get_received_char();
		m_head = (m_head + 1) % BUFLEN;
		m_empty = false;
	}
}
コード例 #7
0
ファイル: LCDDriver.c プロジェクト: yiqixiaoxixi/test
void YADA_E7(U8 YY,U8 MM,U8 DD,U8 HH,U8 M,U8 SS)
{
    send_xy(0xaae7,0x55aa);
    send_word(0x5aa5);
    send_byte(YY);
    send_byte(MM);
    send_byte(DD);
    send_byte(HH);
    send_byte(M);
    send_byte(SS);
    send_end();
}
コード例 #8
0
ファイル: main.c プロジェクト: mexanick/msp-dev
void send_int(int a)
{
    int temp;
    int rev=0;
    int dummy =a;
     while (dummy)
       {
          rev = rev * 10;
          rev = rev + dummy%10;
          dummy = dummy/10;
       }
    while(rev)
    {
        temp=rev%10;
        send_byte(0x30+temp);
        rev /=10;
    }
}
コード例 #9
0
ファイル: i2c.cpp プロジェクト: hcmoder/gatePrj
int8_t I2C::wait_dev_busy(uint8_t slaveAddress)
{
	int8_t ret;
	uint8_t i = 0;
	do
	{
		start();
		ret = send_7bits_address(slaveAddress);
		send_ack();
		send_byte(slaveAddress);
		stop();
		if(i++==100)
		{
			return -1;
		}
	}while(ret != 0);//如果返回值不是0,继续等待
	return 0;
}
コード例 #10
0
ファイル: main.c プロジェクト: AgathaYang/stm32_p103_demos
void rs232_xmit_msg_task( void *pvParameters )
{
    serial_str_msg msg;
    int curr_char;

    while(1) {
        /* Read from the queue.  Keep trying until a message is received.  This
         * will block for a period of time (specified by portMAX_DELAY). */
        while(!xQueueReceive(serial_str_queue, &msg, portMAX_DELAY));

        /* Write each character of the message to the RS232 port. */
        curr_char = 0;
        while(msg.str[curr_char] != '\0') {
            send_byte(msg.str[curr_char]);
            curr_char++;
        }
    }
}
コード例 #11
0
irom i2c_error_t i2c_send(int address, int length, const uint8_t *bytes)
{
	int current;
	i2c_error_t error;
	bool_t ack;

	if(!i2c_flags.init_done)
		return(i2c_error_no_init);

	if(state != i2c_state_idle)
		return(i2c_error_invalid_state_not_idle);

	state = i2c_state_header_send;

	if((error = send_header(address, i2c_direction_send)) != i2c_error_ok)
		return(error);

	for(current = 0; current < length; current++)
	{
		state = i2c_state_data_send_data;

		if((error = send_byte(bytes[current])) != i2c_error_ok)
			return(error);

		state = i2c_state_data_send_ack_receive;

		if((error = receive_ack(&ack)) != i2c_error_ok)
			return(error);

		state = i2c_state_data_send_ack_received;

		if(!ack)
			return(i2c_error_data_nak);
	}

	state = i2c_state_stop_send;

	if((error = send_stop()) != i2c_error_ok)
		return(error);

	state = i2c_state_idle;

	return(i2c_error_ok);
}
コード例 #12
0
ファイル: common.c プロジェクト: cmoresid/dirapp
int send_string(int socketfd, const char* str)
{
	byte len;
	len = strlen(str);
	byte byte_str[len];

	// Send the length of the string
	if (send_byte(socketfd, len) != 1) {
		return -1;
	}

	// Now send the string itself
	strncpy(byte_str, str, len);
	if (send(socketfd, byte_str, len, 0) <= 0) {
		return -1;
	}

	return len;
}
コード例 #13
0
ファイル: HD7279.C プロジェクト: gaogaoxiasha/project
/**********************************************************
函数名:HD7279初始化函数	
功  能:初始化HD7279(管脚配置、HD7279复位)
输  入:无
返  回:无
备  注:使用先,选配置管脚的宏定义
*********************************************************/		
void init_7279(void)	
{
	unsigned int tmr;
	
	DR7279 |= cs7279;		         //cs7279定义为输出
	DR7279 |= clk7279;		         //clk7279定义为输出
	DR7279 |= dat7279;		         //dat7279定义为输出
	DR7279 &= ~(key7279);		     //key7279定义为输入
	
	WR7279 |= cs7279;		         //cs7279初始化为1
 	WR7279 |= clk7279;		         //clk7279初始化为1
 	WR7279 |= dat7279;		         //dat7279初始化为1
 	WR7279 |= key7279;		         //key7279初始化为有弱上拉 
 	
 	for(tmr=0;tmr<0xf000;tmr++);	 //上电延时
 		
	send_byte(CMD_RESET);		     //复位HD7279
 		 	 		
}  	 
コード例 #14
0
void printnum(uint32_t number)
{
	uint32_t temp = number;
	uint32_t max = 10;
	uint32_t counter = 0;
	do
	{
		temp /= 10;
		counter++;
	} while(temp > 0);
	for(temp = 0; temp < counter-1; temp++)
	{
		max *= 10;
	}
	for (; max > 1; max/=10)
	{
		send_byte((number%(max))/(max/10) + '0');
	}
}
コード例 #15
0
ファイル: sht11.cpp プロジェクト: herm/sht11
SHT11::SHT11(DigitalInOut const& data, DigitalOut const& sck)
    : data_(data), sck_(sck)
{
    data_.mode(OpenDrain);
    data_ = 1;
    sck_ = 0;
    SHT11_setup_delay();
    /* Interface reset */
    for (int i=0; i<9; i++)
    {
        sck_ = 1;
        SHT11_clock_delay();
        sck_ = 0;
        SHT11_clock_delay();
    }
    start();
    send_byte(SHT11_RESET);
    delay_ms(SHT11_RESET_TIME_MS);
}
コード例 #16
0
//Method to send data string
void RTTY::send(char *data) {

  char c;
  char chksum_str[6];

  //Call checksum routine
  unsigned int CHECKSUM = crc16_chksum(data);
  sprintf(chksum_str, "*%04X\n", CHECKSUM);
  //Concatinate data with checksum
  strcat(data, chksum_str);

  c = *data++;
  //While we haven't reached the end of the data string, keep sending bytes
  while (c != '\0') {
    send_byte(c);
    c = *data++;
  }

}
コード例 #17
0
ファイル: main.c プロジェクト: en0/stm32f10x_FreeRTOS
void send_memory(void* ptr, size_t len) {
    char* x = (char*)ptr;
    char buffer[100];
    char buffer2[50];
    int i;

    sprintf(buffer, "Dumping Memory at [0x%x]\n[ %08X ] ", (int)x, (int)x);
        send_string(buffer);

    for(i = 1; len > 0; len--, x++, i++) {
        sprintf(buffer, "%02X ", *x);
        if((i%16) == 0) {
            sprintf(buffer2, "\n[ %08X ] ", (int)x);
            strcat(buffer, buffer2);
        }
        else if((i%8) == 0) strcat(buffer, "- ");
        send_string(buffer);
    }
    send_byte('\n');
}
コード例 #18
0
static int uniphier_i2c_receive(struct uniphier_i2c_dev *dev, uint addr,
				uint len, u8 *buf, bool *stop)
{
	int ret;

	debug("%s: addr = %x, len = %d\n", __func__, addr, len);

	ret = send_byte(dev, I2C_DTRM_STA | I2C_DTRM_NACK |
			I2C_DTRM_RD | addr << 1, stop);
	if (ret < 0)
		goto fail;

	while (len--)
		*buf++ = send_and_recv_byte(dev, len ? 0 : I2C_DTRM_NACK);

fail:
	if (*stop)
		writel(I2C_DTRM_STO | I2C_DTRM_NACK, &dev->regs->dtrm);

	return ret;
}
コード例 #19
0
ファイル: HD7279.C プロジェクト: gaogaoxiasha/project
signed long get_data ( signed char dig_start,signed char dig_end )
{
	signed long temp_long = 0;
	signed char i,temp_char;	
	
	for( i = dig_start; i <= dig_end; i++ )
		write7279(UNDECODE + i,0x08);  //显示为'_'
		
	for( i = dig_end; i >= dig_start ; i-- )
	{
		temp_char = get_key7279();
		
		temp_long *= 10;
		temp_long += temp_char;
		
		write7279 ( DECODE1 + i , 0x80 +  temp_char); //1译码可以显示字母
	}
	delay10ms(5);
	send_byte(CMD_RESET);
		
	return temp_long;		
}
コード例 #20
0
void
fujitsu_control::poweroff()
{
  set_power(false);
  m_powermem = false;
  char bytes[7], i;
  bytes[0] = 0x14;
  bytes[1] = 0x63;
  bytes[2] = 0x00;
  bytes[3] = 0x10;
  bytes[4] = 0x10;
  bytes[5] = 0x02;
  bytes[6] = 0xFD;

  send_leader();

  for (i = 0; i < 7; ++i) {
    send_byte(bytes[i]);
  }

  send_trailer();
}
コード例 #21
0
ファイル: fio.c プロジェクト: Cheng-Chian-Lin/freertos
static ssize_t stdin_read(void * opaque, void * buf, size_t count) {
    int i = 0;
    char *ptrbuf = buf;
    int cmd_end_flag=0;

    while( (i < count) && (cmd_end_flag != 1) ){
        ptrbuf[i]=recv_byte();
        
        switch(ptrbuf[i]){
            case '\r':
            case '\n':
                ptrbuf[i] = '\0';
                cmd_end_flag = 1;
                break;
            default :
                cmd_end_flag = 0;
        }
        send_byte(ptrbuf[i]);
        ++i;
    }
    return i;
}
コード例 #22
0
ファイル: libfnordlicht.c プロジェクト: k4r573n/illuminord
/** ends a package to save the current color  */
void save_current(int addr, int slot, int step, int delay, int pause) {
	fprintf(stdout, "send Package SAVE_CURRENT \n");

  byte_index=0;//init new package

	//sendet die addresse (255 = broadcast)
	send_byte(addr,"addr");
	//send the command
	send_byte(0x05,"cmd save_current");
	//send slot
	send_byte( slot,"slot" );
	//send step
	send_byte(step,"step");
	//send delay
	send_byte(delay,"delay");
	//send pause (2 bytes) TODO: convert the int pause = 0 - 360; to two bytes
	send_byte(pause,"pause byte 1");
	send_byte(pause,"pause byte 2");
  int i;
	for (i=7; i<=14; i++) {
	 	//send some bytes to complete the pakege
		send_byte(0x00,"dosen't matter");
	}
}
コード例 #23
0
ファイル: packet_layer.c プロジェクト: FLYKingdom/libvlc
/* Description: Recieve a packet and send it.
 * Author: Albin Severinson
 * Date: 03/03/15
 */
int send_packet(bstring packet)
{
  int rc = 0;
  int i = 0;
  int j = 0;
  char byte = 0;

  debug("[SENDING]: %s", bdata(packet));

  //Store packet size
  int data_size = blength(packet);

  for(j = 0;j < MAX_PACKET_RESEND;j++){
    debug("[SENDING PACKET] size: %d try: %d", data_size, j);

    //Transmit one byte at a time
    for(i = 0;i < data_size;i++){
      byte = bchar(packet, i);
      send_byte(byte);
      //debug("Sent [%d = %d]", i, byte);
    }

    //Wait for ACK frame
    if(data_size != 1){
      rc = get_ack();
      
      //Return if we got the ACK
      if(rc == 0){
        bdestroy(packet);
        return 0;
      }
    }
  }

  bdestroy(packet);
  return -1;
}
コード例 #24
0
ファイル: main.c プロジェクト: james54068/imu_binary_comm
int main(void)
{
	int16_t buff[6];
	uint8_t bin_buff[13];
	comm_package imu_comm;
	imu_comm.header = (uint8_t)'I';
	init_led();
	init_usart1();
	MPU6050_I2C_Init();
	MPU6050_Initialize();
	init_tim2();
	if( MPU6050_TestConnection() == TRUE)
	{
	   puts("connection success\r\n");
	}else {
	   puts("connection failed\r\n");
	}
	imu_calibration();

	while (1) {
		//puts("running now\r\n");
		MPU6050_GetRawAccelGyro(buff);
		imu_comm.acc_x = buff[0]-ACC_X_OFFSET;
		imu_comm.acc_y = buff[1]-ACC_Y_OFFSET;
		imu_comm.acc_z = buff[2]-ACC_Z_OFFSET;
		imu_comm.gyro_x = buff[3]-GYRO_X_OFFSET;
		imu_comm.gyro_y = buff[4]-GYRO_Y_OFFSET;
		imu_comm.gyro_z = buff[5]-GYRO_Z_OFFSET;
		generate_package( &imu_comm, &bin_buff[0]);
		for (int i = 0 ; i<13 ; i++)
			send_byte( bin_buff[i] );
		gpio_toggle(GPIOA, GPIO_Pin_0);
		gpio_toggle(GPIOA, GPIO_Pin_1);
		delay_ms(10);

	}
}
コード例 #25
0
ファイル: clib.c プロジェクト: Jakgn/freertos-plus
size_t fio_printf(int fd, const char *format, ...){
	int i,count=0;

	va_list(v1);
	va_start(v1, format);

	int tmpint;
	char *tmpcharp;

	for(i=0; format[i]; ++i){
		if(format[i]=='%'){
			switch(format[i+1]){
				case '%':
					send_byte('%'); break;
				case 'd':
					tmpint = va_arg(v1, int);
					tmpcharp = itoa(format[i+1]=='x'?"0123456789abcdef":"0123456789ABCDEF", tmpint, format[i+1]=='d'?10: 16);
					fio_write(fd, tmpcharp, strlen(tmpcharp));
					break;

				case 'x':
				case 'X':
					tmpint = va_arg(v1, int);
					tmpcharp = utoa(format[i+1]=='x'?"0123456789abcdef":"0123456789ABCDEF", tmpint, format[i+1]=='d'?10: 16);
					fio_write(fd, tmpcharp, strlen(tmpcharp));
					break;
				case 's':
					tmpcharp = va_arg(v1, char *);
					fio_write(fd, tmpcharp, strlen(tmpcharp));
					break;
			}
			/* Skip the next character */
			++i;
		}else
			fio_write(fd, format+i, 1);
	}
コード例 #26
0
ファイル: scs_310.c プロジェクト: wuchen1106/DAQ
void user_init(unsigned char init)
{
   P0MDOUT = 0x01;              // P0.0: TX = Push Pull
   P1MDOUT = 0x00;              // P1: LPT
   P2MDOUT = 0x00;              // P2: LPT
   P3MDOUT = 0xE0;              // P3.5,6,7: Optocouplers

   /* set initial state of lines */
   GPIB_DATA = 0xFF;
   GPIB_EOI = 1;
   GPIB_DAV = 1;
   GPIB_NRFD = 1;
   GPIB_NDAC = 1;
   GPIB_IFC = 1;
   GPIB_SRQ = 1;
   GPIB_ATN = 1;
   GPIB_REM = 1;

   /* initialize GPIB */
   GPIB_IFC = 0;
   delay_ms(1);
   GPIB_IFC = 1;

   GPIB_ATN = 0;
   send_byte(0x14);             // DCL
   GPIB_ATN = 1;

   output_flag = 0;
   control_flag = 0;

   if (init) {
      user_data.gpib_adr = 16;
      user_data.control = 0;
      user_data.srq = 0;
   }
}
コード例 #27
0
ファイル: diskio.c プロジェクト: AlonsoKJ/cow_bell_repo
BYTE send_cmd(BYTE cmd, DWORD arg, BYTE crc)
{
	unsigned char i;
	BYTE received;

	union {
		BYTE	sep_arg[4];
		DWORD	full_arg;
	} separate;

	//Check for app command, if so, send APP_CMD first
	if(cmd == ACMD_41 || cmd == SET_WR_BLOCK_ERASE_COUNT){
		send_cmd(APP_CMD, 0x00, 0x00); //little bit o' recursion, may take this out later
	}

	separate.full_arg = arg; //Divide 32-bit arg into 4 "separated args" - see union above

	send_byte(cmd | CMD); //send byte with the command flag (0x40)

	send_byte(separate.sep_arg[3]); //send each of the 4-bytes stored in the sep_arg array
	send_byte(separate.sep_arg[2]);
	send_byte(separate.sep_arg[1]);
	send_byte(separate.sep_arg[0]);

	send_byte(crc | 0x01); //last byte in the command is the CRC with end bit

	//The following loop waits for a response from the card
	//it times out after 10 cycles
	for(i = 0; i < 10; i++){
		received = rec_byte();
		if(!(received & 0x80)) //break on r1 response
			break;
	}

	return received;

}//End send_cmd
コード例 #28
0
unsigned int lpt_windows::escritura(unsigned char data){   /* escritura de un byte de datos */
unsigned int result = 0;

    result = send_byte(LPT_CONTROL, 0x04);

    delayN(80);
    if (!result)
        result = send_byte(LPT_DATA, data);
    delayN(40);
    if (!result)
        result = send_byte(LPT_CONTROL, 0x05);
    delayN(60);
    if (!result)
        result = send_byte(LPT_CONTROL, 0x0d);

    delayN(40);
    if (!result)
        result = send_byte(LPT_CONTROL, 0x05);
    delayN(40);
    if (!result)
        result = send_byte(LPT_CONTROL, 0x04);
    delayN(40);
    return result;
}
コード例 #29
0
ファイル: SAMPLING.CPP プロジェクト: wizest/wingwing
void show_sampl_value()
{
	int i;

	send_string("\n");
	send_string("         SS_L0   SS_R0  SS_L45  SS_R45  SS_L90  SS_R90 \n");
	send_string("-------------------------------------------------------\n");
	send_string(" sL3      ");
		for(i=0;i<6;i++)	{send_byte(sL3[i]);send_string("     ");} send_string("\n");
	send_string(" sL2	  ");
		for(i=0;i<6;i++)	{send_byte(sL2[i]);send_string("     ");} send_string("\n");
	send_string(" sL1	  ");
		for(i=0;i<6;i++)	{send_byte(sL1[i]);send_string("     ");} send_string("\n");
	send_string(" sC1	  ");
		for(i=0;i<6;i++)	{send_byte(sC1[i]);send_string("     ");} send_string("\n");
	send_string(" sR1	  ");
		for(i=0;i<6;i++)	{send_byte(sR1[i]);send_string("     ");} send_string("\n");
	send_string(" sR2	  ");
		for(i=0;i<6;i++)	{send_byte(sR2[i]);send_string("     ");} send_string("\n");
	send_string(" sR3	  ");
		for(i=0;i<6;i++)	{send_byte(sR3[i]);send_string("     ");} send_string("\n");
	send_string(" L0 : ");send_byte(threshold_L0);
	send_string(" 		R0 : ");send_byte(threshold_R0);send_char('\n');
	send_string(" L0_A : ");send_byte(threshold_L0_A);
	send_string(" 		R0_A : ");send_byte(threshold_R0_A);send_char('\n');
	send_string(" L45: ");send_byte(threshold_L45);
	send_string(" 		R45: ");send_byte(threshold_R45);send_char('\n');
	send_string(" L45_L: ");send_byte(threshold_L45_LOW);
	send_string(" 		R45_L: ");send_byte(threshold_R45_LOW);send_char('\n');
	send_string(" L45_D: ");send_byte(threshold_L45_D);
	send_string(" 		R45_D: ");send_byte(threshold_R45_D);send_char('\n');
	send_string(" L45_DL: ");send_byte(threshold_L45_DL);
	send_string(" 		R45_DL: ");send_byte(threshold_R45_DL);send_char('\n');
	send_string(" L45_BR: ");send_byte(threshold_L45_BR);
	send_string(" 		R45_BR: ");send_byte(threshold_R45_BR);send_char('\n');
	send_string(" L45_BRL: ");send_byte(threshold_L45_BRL);
	send_string(" 		R45_BRL: ");send_byte(threshold_R45_BRL);send_char('\n');
	send_string(" L90: ");send_byte(threshold_L90);
	send_string(" 		R90: ");send_byte(threshold_R90);send_char('\n');
	send_string(" L90_L: ");send_byte(threshold_L90_LOW);
	send_string(" 		R90_L: ");send_byte(threshold_R90_LOW);send_char('\n');

	/*
	send_string("\n> hit me to view vertical sampling values\n");
	wait_key();
	for(i=0;i<SAMPL_VSTEP;i++)
	{
		send_string("L / ");send_word(i);send_string(" : ");send_byte(sFL0[i]);
		send_string("    ");
		send_string("R / ");send_word(i);send_string(" : ");send_byte(sFR0[i]);
		send_string("\n");
		sys_delay(1);
	}

	send_string("\n> hit me to view pos by ssv\n");
	wait_key();
	send_string("> pos_L0 :  ");show_tbl(pos_L0);
	wait_key();
	send_string("> pos_R0 :  ");show_tbl(pos_R0);
	wait_key();
	send_string("> pos_L45 : ");show_tbl(pos_L45);
	wait_key();
	send_string("> pos_R45 : ");show_tbl(pos_R45);
	wait_key();
	send_string("> pos_L90 : ");show_tbl(pos_L90);
	wait_key();
	send_string("> pos_R90 : ");show_tbl(pos_R90);

	send_string("\n> hit me to view ssv by pos\n");
	wait_key();
	send_string("> ssv_L0 :  ");show_tbl(ssv_L0);
	wait_key();
	send_string("> ssv_R0 :  ");show_tbl(ssv_R0);
	wait_key();
	send_string("> ssv_L45 : ");show_tbl(ssv_L45);
	wait_key();
	send_string("> ssv_R45 : ");show_tbl(ssv_R45);
	wait_key();
	send_string("> ssv_L90 : ");show_tbl(ssv_L90);
	wait_key();
	send_string("> ssv_R90 : ");show_tbl(ssv_R90);
	*/
}
コード例 #30
0
ファイル: ISO7816_Main.c プロジェクト: 12019/YCOS
//	Main process
void ISO7816_main(void)
{
	//register uint16 i=0;
	//register uint16 len;
	uint16 sw;
	while(1) {
		switch(_iso7816_state) {
		 	case ISO7816_DORMANT: 
				VDCON = 0x00;						//	VD closed
				FDCON = 0X00;						//	FD closed
				IoInit(0x11);						//	H/W initial	 
				//rP0 = 0x00;							//	disable output, low voltage level
				Tx_n_Bytes(1, ATR);		   			//kirim 3B	 (ask for T=0 protocol)	
				Initialize_Hardware();							  
				Initialize_Operating_System();	 	 
				Send_ATR();	//	Send ATR
				_iso7816_state = ISO7816_RECEIVE_CMD;
				Sleep_Mode();
				break;
			case ISO7816_WAIT_PPS:

				break;
			case ISO7816_READY:		
				//Sleep_Mode();			//	Power down mode after thread has been executed
				/*_iso7816_cla = iso7816_buffer[0] = receive_byte();		//CLA
				_iso7816_ins = iso7816_buffer[1] = receive_byte();		//INS
				iso7816_buffer[2] = receive_byte();		//P1
				iso7816_buffer[3] = receive_byte();		//P2
				iso7816_buffer[4] = receive_byte();		//P3
				len = (5 + iso7816_buffer[4]);
				
				if(len > 5) {
					//if(iso7816_buffer[1] == 0xA4) {
					send_byte(iso7816_buffer[1]);
					//send_byte(0);
					for(i=5;i<len;i++) {
						iso7816_buffer[i] = receive_byte();
					} 
					//}
				}
				//iso7816_buffer[5] = receive_byte();
				//iso7816_buffer[6] = receive_byte();
				_iso7816_state = ISO7816_RUNNING;  */
				break;
			case ISO7816_RECEIVE_CMD:
				/*if(_os_config.os_state & YGG_ST_LOAD_APP) {	   //load app into user program space
					//Sleep_Mode();	
					Load_User_App();
					_os_config.os_state &= ~(YGG_ST_LOAD_APP);
					Save_State();
				}
				if(_os_config.os_state & YGG_ST_SLEEP) {		   //sleep MCU
					Sleep_Mode();
					_os_config.os_state &= ~(YGG_ST_SLEEP);
				} */
				//do nothing
				break;
			case ISO7816_SEND_ACK:
				send_byte(iso7816_buffer[1]);			//send acknowledgement in order to and wait for data
				_iso7816_state = YGG_RECEIVE_DATA;
				break;
			case ISO7816_RECEIVE_DATA:
				//do nothing
				break;
			case ISO7816_WAIT_LE:		//wait for at least 1 etu 
				break;
			case ISO7816_RUNNING:
				switch(iso7816_buffer[0]) {
					case 0xff:	 						//default iso7816 system class
						PPS_Handler(iso7816_buffer);
						break;
					default:
						TX_NULL_BYTE_ON(8000)
						StartTimeoutSequence();
						//if(iso7816_buffer[1] == 0xC0 && iso7816_buffer[0] == _iso7816_cla) {									//get response
							/*if(iso7816_buffer[4] > get_resp_length) {				//check for response length	  
								//return (APDU_WRONG_LENGTH | get_resp_length); 	//wrong length .OR. requested length
								sw = (APDU_WRONG_LENGTH | get_resp_length); 	//wrong length .OR. requested length
							} else {
								get_resp_length = iso7816_buffer[4];
								//Set_Response(command->bytes, get_resp_length); 
								_iso7816_ins = iso7816_buffer[1];
								memcopy(iso7816_buffer, iso7816_buffer + 5, 0, get_resp_length);
								response_length = get_resp_length;
								get_resp_length = 0;
								sw = APDU_SUCCESS;
							}*/
						//} else {
						_iso7816_cla = iso7816_buffer[0];
						_iso7816_ins = iso7816_buffer[1];
						sw = Yggdrasil_Decode((apdu_command *)iso7816_buffer);
						//}
						
						if(_os_config.os_state & YGG_ST_LOAD_APP) {
							if(Load_User_App() == APDU_SUCCESS) {
								_os_config.os_state	&= ~YGG_ST_LOAD_APP;
								Save_State();
							}
						}
						EndTimeoutSequence();
						TX_NULL_BYTE_OFF(8000)
						ioman_transmit(response_length, _iso7816_ins, iso7816_buffer, sw);
						//Response();
						//TxStatus(SWptr);					//	Tx SW
						break;
				}
				_iso7816_state = ISO7816_RECEIVE_CMD;
				Sleep_Mode();
				break;
			case ISO7816_STOP:			//if the operation didn't response within 2 sec then cancel all pending operation
				EndTimeoutSequence();
				TX_NULL_BYTE_OFF(8000)
				ioman_transmit(0, _iso7816_ins, iso7816_buffer, APDU_FATAL_ERROR);
				_iso7816_state = ISO7816_RECEIVE_CMD;
				Initialize_Operating_System();
				break;
		}
	}
	/*if(ISO7816_Time == 0)
	{
		IoInit(0x11);						//	H/W initial
		Send_ATR();							//	Send ATR
		PPSFlag = 0;  						//	Enable PPS
		ISO7816_Time ++;
		return;								//	Return to the main process after sending ATR	
	}
	if(RcvAPDU())							//	Rcv APDU,include PPS
	{	
		Foffset = (P1 << 8) + P2;			//	Start address of flash reading/writing
		SWptr = SUCCESS;					//	9000

		TX_NULL_BYTE_ON(8000)
		CMMD_Handle();
		TX_NULL_BYTE_OFF(8000)
		
		Response();
		TxStatus(SWptr);					//	Tx SW
	} */
}