예제 #1
0
/* RT-Thread common device interface */
static rt_size_t _log_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
    char c;
    int level;
    rt_size_t head_len;
    const char *ptr = buffer;
    struct log_trace_session *session;

    head_len = _lg_parse_lvl(ptr, size, &level);
    head_len += _lg_parse_session(ptr+head_len, size-head_len, &session);

    /* filter by level */
    if (level > session->lvl)
        return size;

    if (_traceout_device != RT_NULL)
    {
        c = '[';
        rt_device_write(_traceout_device, -1, &c, 1);
        rt_device_write(_traceout_device, -1, session->id.name, _idname_len(session->id.num));
        c = ']';
        rt_device_write(_traceout_device, -1, &c, 1);
        rt_device_write(_traceout_device, -1, ((char*)buffer)+head_len, size - head_len);
    }

    return size;
}
예제 #2
0
void rt_can_thread_entry(void *parameter)
{
    struct rt_can_msg msg;
    struct can_app_struct *canpara = (struct can_app_struct *) parameter;
    rt_device_t candev;
    rt_uint32_t e;

    candev = rt_device_find(canpara->name);
    RT_ASSERT(candev);
    rt_event_init(&canpara->event, canpara->name, RT_IPC_FLAG_FIFO);
    rt_device_open(candev, (RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX));
    rt_device_control(candev, RT_CAN_CMD_SET_FILTER, canpara->filter);
    while (1)
    {
        if (
            rt_event_recv(&canpara->event,
                          ((1 << canpara->filter->items[0].hdr)  |
                           (1 << canpara->filter->items[1].hdr) |
                           (1 << canpara->filter->items[2].hdr) |
                           (1 << canpara->filter->items[3].hdr)),
                          canpara->eventopt,
                          RT_WAITING_FOREVER, &e) != RT_EOK
        )
        {
            continue;
        }
        if (e & (1 << canpara->filter->items[0].hdr))
        {
            msg.hdr = canpara->filter->items[0].hdr;
            while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg))
            {
                rt_device_write(candev, 0, &msg, sizeof(msg));
            }
        }
        if (e & (1 << canpara->filter->items[1].hdr))
        {
            msg.hdr = canpara->filter->items[1].hdr;
            while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg))
            {
                rt_device_write(candev, 0, &msg, sizeof(msg));
            }
        }
        if (e & (1 << canpara->filter->items[2].hdr))
        {
            msg.hdr = canpara->filter->items[2].hdr;
            while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg))
            {
                rt_device_write(candev, 0, &msg, sizeof(msg));
            }
        }
        if (e & (1 << canpara->filter->items[3].hdr))
        {
            msg.hdr = canpara->filter->items[3].hdr;
            while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg))
            {
                rt_device_write(candev, 0, &msg, sizeof(msg));
            }
        }
    }
}
예제 #3
0
/*********************************************************************************
*函数名称:u8 SMS_Rx_PDU(char *instr,u16 len)
*功能描述:接收到PDU格式的短信处理函数
*输    入:instr 原始短信数据,len接收到得信息长度,单位为字节
*输    出:none 
*返 回 值:	1:正常完成,
			0:表示失败
*作    者:白养民
*创建日期:2013-05-29
*---------------------------------------------------------------------------------
*修 改 人:
*修改日期:
*修改描述:
*********************************************************************************/
u8 SMS_Rx_PDU(char *instr,u16 len)
{
	char *pstrTemp;
	u8 ret=0;
	
	//////
	memset( SMS_Service.SMS_destNum, 0, sizeof( SMS_Service.SMS_destNum ) );
	pstrTemp=(char *)rt_malloc(200);	///短信解码后的完整内容,解码后汉子为GB码
	memset(pstrTemp,0,200);
	rt_kprintf( "\r\n 短信原始消息: " );
	rt_device_write( &dev_vuart, 0, GSM_rx, len );
	
	len=GsmDecodePdu(GSM_rx,len,&SMS_Service.Sms_Info,pstrTemp);
	GetPhoneNumFromPDU( SMS_Service.SMS_destNum,  SMS_Service.Sms_Info.TPA, sizeof(SMS_Service.Sms_Info.TPA));

	//memcpy( SMS_Service.SMS_destNum, SMS_Service.Sms_Info.TPA,sizeof( SMS_Service.SMS_destNum ) );
	rt_kprintf( "\r\n  短息来源号码:%s \r\n", SMS_Service.SMS_destNum );
	rt_kprintf( "\r\n 短信消息: " ); 
	rt_device_write( &dev_vuart, 0, pstrTemp, len );
	//rt_hw_console_output(GSM_rx);
	if( strncmp( (char*)pstrTemp, "TW703#", 6 ) == 0 )                                                //短信修改UDP的IP和端口
	{
		//-----------  自定义 短息设置修改 协议 ----------------------------------
		SMS_protocol( pstrTemp + 5, len - 5 ,SMS_ACK_msg);
		ret=1;
	}
	SMS_Service.SMS_read		= 0;
	SMS_Service.SMS_waitCounter = 3;
	SMS_Service.SMS_come		= 1;
	//SMS_Service.SMS_delALL		= 1;
	rt_free( pstrTemp );
	pstrTemp = RT_NULL;
	//////
	return ret;
}
예제 #4
0
static void _lg_fmtout(
        struct log_trace_session *session, const char *fmt, va_list argptr)
{
    /* 1 for ']' */
    static char _trace_buf[1+LOG_TRACE_BUFSZ];
    char *ptr;
    rt_size_t length;

    RT_ASSERT(session);
    RT_ASSERT(fmt);

    rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x][", rt_tick_get());
    if (_traceout_device != RT_NULL)
    {
        rt_device_write(_traceout_device, -1, _trace_buf, 11);
        rt_device_write(_traceout_device, -1,
                session->id.name, _idname_len(session->id.num));
    }

    _trace_buf[0] = ']';
    ptr = &_trace_buf[1];
    length = rt_vsnprintf(ptr, LOG_TRACE_BUFSZ, fmt, argptr);

    if (length >= LOG_TRACE_BUFSZ)
        length = LOG_TRACE_BUFSZ - 1;

    if (_traceout_device != RT_NULL)
    {
        rt_device_write(_traceout_device, -1, _trace_buf, length + 1);
    }
}
예제 #5
0
void Send_const485(u8  flag) 
{

  if(!TX_485const_Enable)
  	return;
 
  switch(CameraState.status)
  	{
       case enable:
                     rt_device_write(&Device_485,0,(char const*)Take_photo, 10);  // 发送拍照命令 
                    // rt_hw_485_Output_Data(Take_photo, 10);  // 发送拍照命令 
                    CameraState.OperateFlag=1;
					CameraState.create_Flag=1; // 需要创建新图片文件 
                    last_package=0; 
					 rt_kprintf("\r\n  Camera: %d  发送拍照命令\r\n",Camera_Number);
					 CameraState.timeoutCounter=0; // send clear
				    break; 
	   case  transfer:
	             	//----------_485_content_wr=0;
				  _485_RXstatus._485_receiveflag=IDLE_485;  
					// rt_kprintf("\r\n 发送图片读取命令\r\n"); 
                                  rt_device_write(&Device_485,0,(char const*)Fectch_photo, 10); // 发送取图命令
                            //   rt_hw_485_Output_Data(Fectch_photo, 10);  // 发送拍照命令   
                               CameraState.OperateFlag=1;
				   CameraState.timeoutCounter=0;// sendclear
					//rt_kprintf("\r\n  发送取图命令\r\n");					
		            break;
	   case  other	:
	   	
	   	            break;
	    default:    
	   	            break;
  	}  
   TX_485const_Enable=0;  // clear     
}
/**
 * write data
 *
 * @param fh - file handle
 * @param buf - data buffer
 * @param len - buffer length
 * @param mode - useless, for historical reasons
 * @return a positive number representing the number of characters not written.
 */
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
{
#ifdef RT_USING_DFS
    int size;
#endif
    
    if ((fh == STDOUT) || (fh == STDERR))
    {
#ifndef RT_USING_CONSOLE
        return 0;
#else
        rt_device_t console_device;
        extern rt_device_t rt_console_get_device(void);

        console_device = rt_console_get_device();
        if (console_device != 0) rt_device_write(console_device, 0, buf, len);
        return len;
#endif
    }

    if(fh == STDIN)
        return -1;

#ifndef RT_USING_DFS
    return 0;
#else
    size = write(fh - STDERR - 1, buf, len);
    if(size >= 0)
        return len - size;
    else
        return -1;
#endif
}
void gdb_uart_putc(char c)
{ 
#ifdef RT_GDB_DEBUG
    rt_kprintf("%c",c);
#endif
    rt_device_write(gdb_dev, 0, &c, 1);
}
예제 #8
0
파일: wav.c 프로젝트: Manish-cimcon/micro
void wav(const char* filename)
{
    int fd;
	rt_size_t block_size;

	block_size = sbuf_get_size();
	block_size = (block_size / 512) * 512;

    fd = open(filename, O_RDONLY, 0);
    if (fd >= 0)
    {
		rt_uint8_t* buf;
		rt_size_t 	len;
		rt_device_t device;

		/* open audio device and set tx done call back */
		device = rt_device_find("snd");
		rt_device_set_tx_complete(device, wav_tx_done);
		rt_device_open(device, RT_DEVICE_OFLAG_WRONLY);

		do
		{
			buf = sbuf_alloc();
			len = read(fd, (char*)buf, block_size);
			if (len > 0) rt_device_write(device, 0, buf, len);
			else sbuf_release(buf);
		} while (len != 0);

		/* close device and file */
		rt_device_close(device);
		close(fd);
    }
}
예제 #9
0
//串口数据处理线程
void uart3_deal_entry(void* parameter)
{
		rt_uint8_t buf[MAXLEN];
		rt_uint8_t len_send;
		rt_sem_take(sem, RT_WAITING_FOREVER);
    while(1)
    {
			rt_sem_take(sem, RT_WAITING_FOREVER);
			rt_kprintf("received a packet\r\n");
			if((recvcnt=dataunpack(uartbuff,uartrecvcnt,buf)) != 0)//对接收的数据进行解包放到buf中,解包后数据长度recvcnt
			{
				rt_uint8_t i;
				
				for(i=0;i<recvcnt;i++)
				{
						rt_kprintf("%02x ",buf[i]); 
				}
				
				len_send =	datapack(buf,2,uartbuff);//将要发送的buf中的2个数据进行打包后放到uartbuff中,打包后数据长度len_send
				rt_device_write(device,0,uartbuff,len_send);
			}
			uartrecvcnt = 0;
			uartbuff = uartcatch;
			curuartptr = uartcatch;
			uartstate = UART_IDLE;
			
    }
}
예제 #10
0
/*********************************************************************************
*函数名称:u8 SMS_Tx_Text(char *strDestNum,char *s)
*功能描述:发送TEXT格式的短信函数
*输    入:s 原始短信数据,strDestNum接收方号码
*输    出:none 
*返 回 值:	1:正常完成,
			0:表示失败
*作    者:白养民
*创建日期:2013-05-29
*---------------------------------------------------------------------------------
*修 改 人:
*修改日期:
*修改描述:
*********************************************************************************/
u8 SMS_Tx_Text(char *strDestNum,char *s) 
{
	u16 len;
	char *pstrTemp;
	
	memset(SMS_Service.SMSAtSend,0,sizeof(SMS_Service.SMSAtSend));
	strcpy( ( char * ) SMS_Service.SMSAtSend, "AT+CMGS=\"" ); 
	//strcat(SMS_Service.SMSAtSend,"8613820554863");// Debug
	strcat(SMS_Service.SMSAtSend,strDestNum);
	strcat(SMS_Service.SMSAtSend,"\"\r\n");

	rt_kprintf("\r\n%s",SMS_Service.SMSAtSend); 
	rt_hw_gsm_output( ( char * ) SMS_Service.SMSAtSend );

	rt_thread_delay(50);
	
	pstrTemp=rt_malloc(150);
	memset(pstrTemp,0,150);
	len=strlen(s);
	memcpy(pstrTemp,s,len);
	pstrTemp[len++]=0x1A;      // message  end  

	///发送调试信息
	rt_device_write( &dev_vuart, 0, pstrTemp, len);
	///发送到GSM模块
	rt_hw_gsm_output_Data(pstrTemp, len); 
	rt_free( pstrTemp );
	pstrTemp=RT_NULL; 
	return 1;
}
예제 #11
0
파일: remote.c 프로젝트: tcz717/TPDT.FC_407
static void send_value(uint16_t index,uint8_t id)
{
	send.value.head=head;
	send.value.index=index;
	send.value.type=TFCR_TYPE_VALUE;
	send.value.id=id;
	
	switch(id)
	{
		default:
		case 0:
			send.value.value1=ahrs.degree_pitch;
			send.value.value2=ahrs.degree_roll;
			send.value.value3=ahrs.degree_yaw;
			break;
		case 1:
			send.value.value1=ahrs.x;
			send.value.value2=ahrs.y;
			send.value.value3=ahrs.height;
		case 2:
			send.value.value1=recv.pack.angle_error;
			send.value.value2=recv.pack.middle_error;
			send.value.value3=recv.pack.linestate;
			break;
	}
	
	send.value.checksum=checksum(send.buf,sizeof(struct tfcr_value)-1);
	
	rt_device_write(uart,0,send.buf,sizeof(struct tfcr_value));
}
예제 #12
0
/*********************************************************************************
*函数名称:u8 SMS_Tx_PDU(char *strDestNum,char *s)
*功能描述:发送PDU格式的短信函数
*输    入:s 原始短信数据,strDestNum接收方号码
*输    出:none 
*返 回 值:	1:正常完成,
			0:表示失败
*作    者:白养民
*创建日期:2013-05-29
*---------------------------------------------------------------------------------
*修 改 人:
*修改日期:
*修改描述:
*********************************************************************************/
u8 SMS_Tx_PDU(char *strDestNum,char *s)
{
	u16 len;
	u16 i;
	char *pstrTemp;
	memset(SMS_Service.SMSAtSend,0,sizeof(SMS_Service.SMSAtSend));
	pstrTemp=rt_malloc(400);
	memset(pstrTemp,0,400);
	i=0;
	SetPhoneNumToPDU(SMS_Service.Sms_Info.TPA, strDestNum, sizeof(SMS_Service.Sms_Info.TPA));
	len=AnySmsEncode_NoCenter(SMS_Service.Sms_Info.TPA,GSM_UCS2,s,strlen(s),pstrTemp);
	//len=strlen(pstrTemp);
	pstrTemp[len++]=0x1A;      // message  end  	
	//////
	sprintf( ( char * ) SMS_Service.SMSAtSend, "AT+CMGS=%d\r\n", (len-2)/2); 
	rt_kprintf("%s",SMS_Service.SMSAtSend); 
	rt_hw_gsm_output( ( char * ) SMS_Service.SMSAtSend );
	rt_thread_delay(50);
	//////	
	rt_device_write( &dev_vuart, 0, pstrTemp, strlen(pstrTemp) );
	//rt_hw_console_output(pstrTemp);
	rt_hw_gsm_output_Data(pstrTemp, len); 
	rt_free( pstrTemp );
	pstrTemp=RT_NULL;
	return 1;
}
예제 #13
0
/*********************************************************************************
*函数名称:u8 SMS_Rx_Text(char *instr,char *strDestNum)
*功能描述:接收到TEXT格式的短信处理函数
*输    入:instr 原始短信数据,strDestNum接收到得信息的发送方号码
*输    出:none 
*返 回 值:	1:正常完成,
			0:表示失败
*作    者:白养民
*创建日期:2013-05-29
*---------------------------------------------------------------------------------
*修 改 人:
*修改日期:
*修改描述:
*********************************************************************************/
u8 SMS_Rx_Text(char *instr,char *strDestNum)
{
	u16 len;
	u8 ret=0;
	len=strlen(strDestNum);
	memset( SMS_Service.SMS_destNum, 0, sizeof( SMS_Service.SMS_destNum ) );
	if(len>sizeof( SMS_Service.SMS_destNum ))
		{
		len=sizeof( SMS_Service.SMS_destNum );
		}
	memcpy(SMS_Service.SMS_destNum,strDestNum,len);
	rt_kprintf( "\r\n  短息来源号码:%s", SMS_Service.SMS_destNum );
	
	len=strlen(instr);
	rt_kprintf( "\r\n 短信收到消息: " );
	rt_device_write( &dev_vuart, 0, instr, len);
	
	if( strncmp( (char*)instr, "TW703#", 6 ) == 0 )                                                //短信修改UDP的IP和端口
	{
		//-----------  自定义 短息设置修改 协议 ----------------------------------
		SMS_protocol( instr + 5, len - 5 ,SMS_ACK_msg);
		ret=1;
	}
	SMS_Service.SMS_read		= 0;
	SMS_Service.SMS_waitCounter = 0;
	SMS_Service.SMS_come		= 0;
	//SMS_Service.SMS_delALL		= 1;
	return ret;
}
예제 #14
0
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
static void rt_thread_entry_gps( void* parameter )
{
	rt_err_t	res;

      // 1.  init
       GPS_Abnormal_init();

	//2.  main while
	while( 1 )
	{
		res = rt_mq_recv( &mq_gps, (void*)&gps_rx, 124, RT_TICK_PER_SECOND / 20 ); //等待100ms,实际上就是变长的延时,最长100ms
		if( res == RT_EOK )                                                     //收到一包数据
		{
			if( flag_bd_upgrade_uart == 0 )
			{
				GPS_Rx_Process( gps_rx.body, gps_rx.wr );  
				GPS_Abnormal_process();//  GPS 模块异常检测 

			}else
			{
				if( gps_rx.body[0] == 0x40 )
				{
					rt_device_write( &dev_vuart, 0, gps_rx.body, gps_rx.wr);
				}
			} 
		}
		rt_thread_delay(6 ); 
	}
}
예제 #15
0
파일: RauAp.c 프로젝트: SH-WHJ/rau-platform
void hdp_client_log(const char *fmt, ...)
{
    va_list args;
    rt_size_t length;
    static char rt_log_buf[MAX_LOG_LEN]={0};

    rt_uint16_t old_flag = rcuDevice->flag;

    if(rcuDevice==NULL)
        return;

    va_start(args, fmt);
    /* the return value of vsnprintf is the number of bytes that would be
    * written to buffer had if the size of the buffer been sufficiently
    * large excluding the terminating null byte. If the output string
    * would be larger than the rt_log_buf, we have to adjust the output
    * length. */
    length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args);
    if (length > MAX_LOG_LEN - 1)
        length = MAX_LOG_LEN - 1;       

    rcuDevice->flag |= RT_DEVICE_FLAG_STREAM;
    rt_device_write(rcuDevice, 0, rt_log_buf, length);
    rcuDevice->flag = old_flag;

    va_end(args);
}
예제 #16
0
static enum rym_code _rym_echo_data(
        struct rym_ctx *ctx,
        rt_uint8_t *buf,
        rt_size_t len)
{
    rt_device_write(_odev, 0, buf, len);
    return RYM_CODE_ACK;
}
예제 #17
0
static void gsm_thread_entry(void* parameter)  
{
    rt_size_t  res=RT_ERROR;
    u8  linkNum=0;	
        //     finsh_init(&shell->parser);
	rt_kprintf("\r\n ---> gsm thread start !\r\n");
	 //	  	 
	 
	while (1)
	{
	
            // 1.  after power  on    get imsi code  	 	
              IMSIcode_Get(); 
            //  2. after get imsi   Comm   AT  initial   start 
              GSM_Module_TotalInitial();  
            // 3. Receivce & Process   Communication  Module   data ----
	       GSM_Buffer_Read_Process(); 
	           
             if(!SMS_send_stateQuery())
             	{
		       DataLink_Process();		
	             //------------------------------------------------
			    if (Send_DataFlag== 1) 
	               {
				   //  rt_kprintf("\r\n  gsm rx  app msgQue:   rxlen=%d  rx_content=%s\r\n",msgq_gsm.len,msgq_gsm.info); 	 
	                        //  Data_Send(GPRS_info,GPRS_infoWr_Tx); 
				   res=rt_device_control(&Device_GSM, query_online, NULL);
				    if(res==RT_EOK)
				     { 
				          linkNum=gsm_rx_app_infoStruct.link_num;  // IC  link  ==1  
				          rt_device_write(&Device_GSM, linkNum,( const void *)GPRS_info,(rt_size_t) GPRS_infoWr_Tx); 
				    }		  
				    Send_DataFlag=0;          
		
		         }    
			//---------  Step timer
			  Dial_step_Single_10ms_timer();    
			  	  //   TTS	
	                TTS_Data_Play(); 
			 
	                //   Get  CSQ value
		        // GSM_CSQ_Query();	 			  //   SMS Send
             	}
		else
			SMS_send_process();     //  相关短信处理
		 
                //   Get  CSQ value
	         GSM_CSQ_Query();	 
              
			  //	  Voice Record
			   VOC_REC_process();

			
	         rt_thread_delay(20);  	     
			   
	}
}
예제 #18
0
파일: jiguang.c 프로젝트: pigeon0411/eb06
u8 send_bytes_to_jiguang(u8 len,u8*databuff)
{
	
	rt_device_write(&serial3.parent, 0, databuff, len);


	return 1;

}
예제 #19
0
void zsend_line(rt_uint16_t c)
{
    rt_uint16_t ch;

	ch = (c & 0377);
    rt_device_write(zmodem.device,0,&ch,1);   

    return;
}
예제 #20
0
static void hm_ble_write(const char* str, rt_size_t size)
{
    rt_size_t writen = size;
    const char* ptr = str;

    while(writen) {
        if(writen < 20) {
            rt_device_write(tt_print_device, 0, ptr, writen);
            writen = 0;
        }
        else {
            rt_device_write(tt_print_device, 0, ptr, 20);
            writen -= 20;
            ptr += 20;
            rt_thread_delay(2);
        }
    }
}
예제 #21
0
파일: remote.c 프로젝트: tcz717/TPDT.FC_407
static void send_error(uint16_t index,uint8_t code)
{
	send.ack.head=head; 
	send.ack.index=index;
	send.ack.type=TFCR_TYPE_ACK;
	send.ack.code=code;
	send.ack.checksum=checksum(send.buf,sizeof(struct tfcr_ack)-1);
	
	rt_device_write(uart,0,send.buf,sizeof(struct tfcr_ack));
}
예제 #22
0
void spi_m74hc595_Poll(void)
{
    rt_size_t length = 3;
    //static char spi_MOSI_buf[3];
    rt_device_t spi_device;

    spi_device = rt_device_find("SPI1");
    rt_device_write(spi_device, 0, spi_MOSI_buf, length);
    
}
예제 #23
0
void ppp_trace(int level, const char *format, ...)
{
    va_list args;
    rt_size_t length;
    static char rt_log_buf[RT_CONSOLEBUF_SIZE];

    va_start(args, format);
    length = rt_vsprintf(rt_log_buf, format, args);
    rt_device_write((rt_device_t)rt_console_get_device(), 0, rt_log_buf, length);
    va_end(args);
}
예제 #24
0
void ANO_DT::Send_Data(u8 *dataToSend , u8 length)
{
	rt_device_write(uart_dev,0,dataToSend,length);
//#ifdef ANO_DT_USE_UART
//	Uart1_Put_Buf(data_to_send,length);
//#endif
	
#ifdef ANO_DT_USE_WIFI
	tcp_writebuf((char*)data_to_send,length);
#endif
}
예제 #25
0
파일: RauAp.c 프로젝트: SH-WHJ/rau-platform
int rcu_uart_write(char* buf, int bufLen)
{
	int ret=0;
	rt_uint16_t old_flag = rcuDevice->flag;
	if(rcuDevice==NULL)
		return ret;
	rcuDevice->flag |= RT_DEVICE_FLAG_STREAM;
	ret = rt_device_write(rcuDevice, 0,buf,bufLen);
	rcuDevice->flag = old_flag;
	return ret;
}
예제 #26
0
파일: dfs_elm.c 프로젝트: comrid1987/jb3500
/* Write Sector(s) */
DRESULT disk_write(BYTE drv, const BYTE *buff, DWORD sector, BYTE count)
{
	rt_size_t result;
	rt_device_t device = disk[drv];

	result = rt_device_write(device, sector, buff, count);
	if (result == count)
	{
		return RES_OK;
	}

	return RES_ERROR;
}
예제 #27
0
    static void oled_writeData(rt_uint8_t *data, rt_uint8_t size)
    {
        rt_uint8_t buf_ins[5];

        buf_ins[0] = 0;                                         /* Instruction length */
        *(rt_uint8_t **)(&buf_ins[1]) = data;                   /* Pointer to TX buffer */

        MINISTM32_OLED_CS_RESET;
        if (rt_device_write(spi_dev, BSP_NO_DATA, buf_ins, size) == 0)
        {
            oled_debug("OLED: Write data failed! (%d, %x, %x, %x)\n",
                    size, *data, *(data+1), *(data+2), *(data+3));
        }
        MINISTM32_OLED_CS_SET;
    }
예제 #28
0
int dfs_device_fs_write(struct dfs_fd* file, const void *buf, rt_size_t count)
{
    int result;
    rt_device_t dev_id;

    RT_ASSERT(file != RT_NULL);

    /* get device handler */
    dev_id = (rt_device_t)file->data;
    RT_ASSERT(dev_id != RT_NULL);

    /* read device data */
    result = rt_device_write(dev_id, file->pos, buf, count);
    file->pos += result;

    return result;
}
예제 #29
0
rt_err_t rs485_send_data(u8* data,u16 len)
{
	rt_mutex_take(rs485_send_mut,RT_WAITING_FOREVER);
	
	RS485_TX_ENABLE;
	if(uart1_dev_my->device == RT_NULL)	
	{
		uart1_rs485_set_device();
	}
	
	rt_device_write(uart1_dev_my->device, 0, data, len);

	rt_thread_delay (80);
	RS485_RX_ENABLE;

	rt_mutex_release(rs485_send_mut);
	return RT_EOK;
}
예제 #30
0
void rt_can_thread_entry(void* parameter)
{
    struct rt_can_msg msg;
    struct can_app_struct* canpara = (struct can_app_struct*) parameter;
    rt_device_t candev;

    candev = rt_device_find(canpara->name);
    RT_ASSERT(candev);
    rt_sem_init(&canpara->sem, canpara->name, 0, RT_IPC_FLAG_FIFO);
    rt_device_open(candev, (RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX));
    rt_device_control(candev,RT_CAN_CMD_SET_FILTER,canpara->filter);
    rt_device_set_rx_indicate(candev, lpccanind);
    while(1) {
        rt_sem_take(&canpara->sem, RT_WAITING_FOREVER);
        while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) {
            rt_device_write(candev, 0, &msg, sizeof(msg));
        }
    }
}