Example #1
0
File: nRF905.c Project: ronicsu/fly
//=====================================================
// nRF905 的检测程序,首先写入地址,然后再读出地址,
// 如果读出来的值与原来的一样,那么就返回1 ,否则返回0
//=====================================================
u8 nRF905_Check(void)
{
	u8 i,AddressTemp[4]={0};
	CSN = 0;//SPI valid
	SpiWrite(WTA);//写地址
	for(i=0;i<4;i++)
	{
		SpiWrite(TxRxAddress[i]);
	}
	CSN = 1;
	delay_us(500);
	CSN = 0;
	SpiWrite(RTA);//读地址
	for(i=0;i<4;i++)
	{
		AddressTemp[i]=SpiRead();
	}
	CSN = 1;
	for(i=0;i<4;i++)
	{
		if(AddressTemp[i] != TxRxAddress[i])
		{
			break;
		}
	}
	if(i!=4) return 0;
	return 1;
}
Example #2
0
/****************************************************
 SpiTsWrite
****************************************************/
int SpiTsWrite(struct DibBridgeContext *pContext, unsigned int addr,unsigned char* buf, unsigned int size)
{
  unsigned char command[6];
  unsigned int commandsize;

  /****** Build Command ******
  - b31: 0     => Start Bit
  - b30: 1     => Write
  - b29-28:    => Transfer Size
  - b27:       => Auto Increment
  - b26-b0:    => Formatted Address
  - b15-b0:    => Transfer Size
  ***************************/
  command[0] = (addr & 0x3F000000) >> 24;
  command[1] = (addr & 0x00FF0000) >> 16;
  command[2] = (addr & 0x0000FF00) >> 8;
  command[3] = (addr & 0x000000FF) >> 0;
  command[0] |= 0x40; /* Write */

  commandsize = size;
  command[4] = (commandsize & 0xFF00) >> 8;
  command[5] = (commandsize & 0x00FF);

  /** Write Command **/
  SpiWrite(pContext,command,6);

  SpiWrite(pContext,buf,size);

  return 0;
}
Example #3
0
//*****************************************************************************
//
//!  hci_patch_send
//!
//!  @param  usOpcode      command operation code
//!  @param  pucBuff       pointer to the command's arguments buffer
//!  @param  patch         pointer to patch content buffer 
//!  @param  usDataLength  data length
//!
//!  @return              none
//!
//!  @brief               Prepeare HCI header and initiate an HCI patch write operation
//
//*****************************************************************************
void
hci_patch_send(unsigned char ucOpcode, unsigned char *pucBuff, char *patch, unsigned short usDataLength)
{ 
 	unsigned char *data_ptr = (pucBuff + SPI_HEADER_SIZE);
	unsigned short usTransLength;
	unsigned char *stream = (pucBuff + SPI_HEADER_SIZE);
	
	UINT8_TO_STREAM(stream, HCI_TYPE_PATCH);
	UINT8_TO_STREAM(stream, ucOpcode);
	stream = UINT16_TO_STREAM(stream, usDataLength + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE);
	
	if (usDataLength <= SL_PATCH_PORTION_SIZE)
	{
		UINT16_TO_STREAM(stream, usDataLength);
		stream = UINT16_TO_STREAM(stream, usDataLength);
		memcpy((pucBuff + SPI_HEADER_SIZE) + HCI_PATCH_HEADER_SIZE, patch, usDataLength);
		
		// Update the opcode of the event we will be waiting for
		SpiWrite(pucBuff, usDataLength + HCI_PATCH_HEADER_SIZE);
	}
	else
	{
		
		usTransLength = (usDataLength/SL_PATCH_PORTION_SIZE);
		UINT16_TO_STREAM(stream, usDataLength + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE + usTransLength*SIMPLE_LINK_HCI_PATCH_HEADER_SIZE);
		stream = UINT16_TO_STREAM(stream, SL_PATCH_PORTION_SIZE);
		memcpy(pucBuff + SPI_HEADER_SIZE + HCI_PATCH_HEADER_SIZE, patch, SL_PATCH_PORTION_SIZE);
		usDataLength -= SL_PATCH_PORTION_SIZE;
		patch += SL_PATCH_PORTION_SIZE;
		
		// Update the opcode of the event we will be waiting for
		SpiWrite(pucBuff, SL_PATCH_PORTION_SIZE + HCI_PATCH_HEADER_SIZE);
		
		while (usDataLength)
		{
			cc3k_int_poll();

			if (usDataLength <= SL_PATCH_PORTION_SIZE)
			{
				usTransLength = usDataLength;
				usDataLength = 0;
				
			}
			else
			{
				usTransLength = SL_PATCH_PORTION_SIZE;
				usDataLength -= usTransLength;
			}
			
			*(unsigned short *)data_ptr = usTransLength;
			memcpy(data_ptr + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE, patch, usTransLength);
			patch += usTransLength;
			
			// Update the opcode of the event we will be waiting for
			SpiWrite((unsigned char *)data_ptr, usTransLength + sizeof(usTransLength));
		}
	}
}
Example #4
0
void Config905(void)
{
	uchar i;					
	CSN=0;						// Spi enable for write a spi command
	SpiWrite(WC);				// Write config command写放配置命令
	for (i=0;i<RxTxConf.n;i++)	// Write configration words  写放配置字
	{
		SpiWrite(RxTxConf.buf[i]);
	}
	CSN=1;						// Disable Spi
}
Example #5
0
//*******************************
//this function to initial start address
//*******************************
static void SetPACA(unsigned char PA, unsigned char CA)
{
    // Set PA
    SpiWrite(0xB0 | PA);

    // Set CA MSB
    SpiWrite(0x10 | (CA >> 4) & 0xF);

    // Set CA LSB
    SpiWrite(0x00 | (CA & 0xF));
}
Example #6
0
void LCD_ClearScreen(void)
{
    int i = 0;
    /*CLEAR ALL PANNAL*/
    SetPACA(0x0, 0x0);

    for (i = 0; i < 132 *8; i++)
    {
        SpiWrite(0x100);
    }
    SpiWrite(0x10f);
}
void enc28j60WriteOp(unsigned char op, unsigned char address, unsigned char data)
{
    unsigned char dat = 0;
    
    ENC28J60_CSL();
    // issue write command
    dat = op | (address & ADDR_MASK);
    SpiWrite(dat);
    // write data
    dat = data;
    SpiWrite(dat);
    ENC28J60_CSH();
}
void enc28j60WriteBuffer(unsigned int len, unsigned char* data)
{
    ENC28J60_CSL();
    // issue write command
   SpiWrite(ENC28J60_WRITE_BUF_MEM);
    
    while(len)
    {
        len--;
        SpiWrite(*data);
        data++;
    }
    ENC28J60_CSH();
}
Example #9
0
//*****************************************************************************
//
//!  HCI data command builder.
//!
//!  \param  usOpcode    command operation code
//!  \param  ucPayload   pointer to the data buffer
//!  \param  usLength    buffer length
//!
//!  \return none
//!
//!  \brief              Initiate an HCI data write operation
//
//*****************************************************************************
long
hci_data_send(unsigned char ucOpcode, 
                           unsigned char *ucArgs,
                           unsigned short usArgsLength, 
                           unsigned short usDataLength,
                           const unsigned char *ucTail,
                           unsigned short usTailLength)
{
    hci_data_hdr_t *hci_data_hdr_ptr;
	



    hci_data_hdr_ptr = (hci_data_hdr_t *)((ucArgs) + SPI_HEADER_SIZE);
    

	//
	// Fill in the HCI header of data packet
	//
    hci_data_hdr_ptr->ucType = HCI_TYPE_DATA;
    hci_data_hdr_ptr->ucOpcode = ucOpcode;
    hci_data_hdr_ptr->ucArgsize = usArgsLength;
    hci_data_hdr_ptr->usLength = usArgsLength + usDataLength + usTailLength;

	//
	// Send the packet over the SPI
	//
    SpiWrite(ucArgs, sizeof(hci_data_hdr_t) + usArgsLength + usDataLength + usTailLength);

    return(ESUCCESS);
}
Example #10
0
void A7201_init(void)
{

	SPI_IO_Init();
    SPI_CE_L();	//pCE = 0;
    			//pTX_RX = 0;
   	//SPI_S_H(); //pSPIS = 1;           // SPI mode
    SPI_STB_L();
    SPI_CLK_L();

    Reg1_H = 0x77;
    Reg1_L = 0xA9;          // RX, FSK, HiBand, Clock out disable, Up side band, TX power max, AGC enable
    
	Reg1_L &= (~BAND_L);	//HI_BAND	// HI_BAND = 434MHz band, LO_BAND = 315MHz band
	Reg1_L |= FASK_L;	//FSK	//1:FSK or 0 ASK
	Reg1_L |= IFB0_L;	//IF filter bandwidth selection[mid. (ASK = 250KHz, FSK = 150KHz)]
	Reg1_H |= IFB1_H;

	SpiWrite ( 0xFA, 0x32 ); // For Power On(Initial)
   // initUart1();            // 8M/12/32 = 20.8K bps
/*
    while(1)
    {
        ReceiveData();
    }
	*/
}
Example #11
0
static void ShowChar(unsigned char x, unsigned char y, unsigned char ascii_word)
{
    int i = 0, k = 0;
    unsigned char temp;
    k = (ascii_word - 32) * 16;

    for (i = 0;i < 8;i++)
    {
        SetPACA((x*2), (129 - (y*8) - i));
        temp = Ascii[k+i];
        SpiWrite(0x100 | temp);
    }

    for (i = 0;i < 8;i++)
    {
        SetPACA((x*2) + 1, (129 - (y*8) - i));
        temp = Ascii[k+i+8];
        SpiWrite(0x100 | temp);
    }
}
Example #12
0
File: nRF905.c Project: ronicsu/fly
//=====================================================
//使用905发送数据
//
//=====================================================
void TxPacket(void)
{
    u16 i;
    CSN = 0;
    SpiWrite(WTP);
    for(i=0;i<32;i++)
    {
        SpiWrite(TxBuf[i]);
    }
    CSN = 1;
    delay_us(100);//
    CSN = 0;
    SpiWrite(WTA);
    for(i=0;i<4;i++)
    {
        SpiWrite(RxTxconf.buf[i+5]);
    }
    CSN = 1;
    TRX_CE  = 1;
    delay_us(100);//
    TRX_CE = 0;
}
Example #13
0
//*****************************************************************************
//
//!  hci_data_command_send
//!
//!  @param  usOpcode      command operation code
//!  @param  pucBuff       pointer to the data buffer
//!  @param  ucArgsLength  arguments length
//!  @param  ucDataLength  data length
//!
//!  @return none
//!
//!  @brief              Prepeare HCI header and initiate an HCI data write operation
//
//*****************************************************************************
void hci_data_command_send(UINT16 usOpcode, UINT8 *pucBuff, UINT8 ucArgsLength,UINT16 ucDataLength)
{ 
	UINT8 *stream = (pucBuff + SPI_HEADER_SIZE);

	UINT8_TO_STREAM(stream, HCI_TYPE_DATA);
	UINT8_TO_STREAM(stream, usOpcode);
	UINT8_TO_STREAM(stream, ucArgsLength);
	stream = UINT16_TO_STREAM(stream, ucArgsLength + ucDataLength);

	// Send the command over SPI on data channel
	SpiWrite(pucBuff, ucArgsLength + ucDataLength + SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE);

	return;
}
Example #14
0
File: nRF905.c Project: ronicsu/fly
//=====================================================
//主机通过SPI接口向905配置寄存器写入配置信息
//
//=====================================================
void Config905(void)
{
    unsigned char i;
    CSN = 0;
    SpiWrite(WC);
    for(i=0;i<RxTxconf.n;i++)
    {
        SpiWrite(RxTxconf.buf[i]);
    }
    CSN = 1;
    //===================
    
    delay_ms(100);
    /*CSN  = 0;
    SpiWrite(RC);
    for(i=0;i<RxTxconf.n;i++)
    {
        RxBuf[i] = SpiRead();
    }
    CSN = 1;
    */
    //===================
}
Example #15
0
File: nRF905.c Project: ronicsu/fly
//=====================================================
//使用905接收数据
//
//=====================================================
void RxPacket(void)
{
    unsigned char i;
    TRX_CE = 0;                      //设置905进入待机模式
    CSN = 0;
    SpiWrite(RRP);                 //准备读取接收到的数据
    for(i=0;i<32;i++)
    {
        RxBuf[i] = SpiRead();       //通过SPI口从905读取数据
    }
    CSN = 1;
    while(DR||AM);
    TRX_CE = 1;  
    
}
Example #16
0
void LCD_Init(void)
{
    /* Use SPI0 for LCD */
    SPI = SPI0;

    /* Initial SPI data format and SPI clock */    
    SPI->CNTRL   = SPI_CNTRL_CLK_IDLE_HIGH | SPI_CNTRL_TX_FALLING | 
                       SPI_CNTRL_RX_RISING | SPI_CNTRL_TX_BIT_LEN(9);
    SPI->DIVIDER = SPI_DIVIDER_DIV(4); /* SPI clock freq = system clock / 4 */
    SPI->SSR = SPI_SSR_HW_AUTO_ACTIVE_LOW;

    // Set BR
    SpiWrite(0xEB);

    // Set PM
    SpiWrite(0x81);
    SpiWrite(0xA0);

    SpiWrite(0xC0);

    // Set Display Enable
    SpiWrite(0xAF);

}
void enc28j60ReadBuffer(unsigned int len, unsigned char* data)
{
    ENC28J60_CSL();
    // issue read command
    SpiWrite(ENC28J60_READ_BUF_MEM);
    while(len)
    {
        len--;
        // read data
        *data = SpiRead();
        data++;
    }
    *data='\0';
    ENC28J60_CSH();
}
Example #18
0
//*****************************************************************************
//
//!  hci_command_send
//!
//!  @param  usOpcode     command operation code
//!  @param  pucBuff      pointer to the command's arguments buffer
//!  @param  ucArgsLength length of the arguments
//!
//!  @return              none
//!
//!  @brief               Initiate an HCI command.
//
//*****************************************************************************
UINT16 hci_command_send(UINT16 usOpcode, UINT8 *pucBuff, UINT8 ucArgsLength)
{ 
	UINT8 *stream;

	stream = (pucBuff + SPI_HEADER_SIZE);

	UINT8_TO_STREAM(stream, HCI_TYPE_CMND);
	stream = UINT16_TO_STREAM(stream, usOpcode);
	UINT8_TO_STREAM(stream, ucArgsLength);

	//Update the opcode of the event we will be waiting for
	SpiWrite(pucBuff, ucArgsLength + SIMPLE_LINK_HCI_CMND_HEADER_SIZE);

	return(0);
}
Example #19
0
void TxPacket(void)
{
	uchar i;
	//Config905();				
	CSN=0;						// Spi enable for write a spi command	
	SpiWrite(WTP);				// Write payload command
	for (i=0;i<32;i++)
	{
		SpiWrite(TxBuf[i]);		// Write 32 bytes Tx data
	}
	CSN=1;						// Spi disable						
	Delay(1);
	CSN=0;						// Spi enable for write a spi command	
	SpiWrite(WTA);				// Write address command
	for (i=0;i<4;i++)			// Write 4 bytes address
	{
		SpiWrite(RxTxConf.buf[i+5]);
	}	
	CSN=1;						// Spi disable

	TRX_CE=1;					// Set TRX_CE high,start Tx data transmission
	Delay(1);					// while (DR!=1);
	TRX_CE=0;					// Set TRX_CE low
}
unsigned char enc28j60ReadOp(unsigned char op, unsigned char address)
{
    unsigned char dat = 0;
    
    ENC28J60_CSL();
    
    SpiWrite(op | (address & ADDR_MASK));
    dat =SpiRead();
    // do dummy read if needed (for mac and mii, see datasheet page 29)
    if(address & 0x80)
    {
        dat =SpiRead();
    }
    // release CS
    ENC28J60_CSH();
    return dat;
}
Example #21
0
//*****************************************************************************
//
//!  hci_command_send
//!
//!  @param  usOpcode     command operation code
//!  @param  pucBuff      pointer to the command's arguments buffer
//!  @param  ucArgsLength length of the arguments
//!
//!  @return              none
//!
//!  @brief               Initiate an HCI command.
//
//*****************************************************************************
unsigned short 
hci_command_send(unsigned short usOpcode, unsigned char *pucBuff,
                     unsigned char ucArgsLength)
{ 
	unsigned char *stream;
	
	stream = (pucBuff + SPI_HEADER_SIZE);
	
	UINT8_TO_STREAM(stream, HCI_TYPE_CMND);
	stream = UINT16_TO_STREAM(stream, usOpcode);
	UINT8_TO_STREAM(stream, ucArgsLength);
//	TM_DEBUG("getting ready to send a buffer of data");
	//Update the opcode of the event we will be waiting for
	SpiWrite(pucBuff, ucArgsLength + SIMPLE_LINK_HCI_CMND_HEADER_SIZE);
//	TM_DEBUG("done sending a buffer of data");
	return(0);
}
Example #22
0
//*****************************************************************************
//
//!  HCI data command send.
//!
//!  \param  usOpcode    command operation code
//!  \param  ucPayload   pointer to the data buffer
//!  \param  usLength    buffer length
//!
//!  \return none
//!
//!  \brief              Initiate an HCI data write operation
//
//*****************************************************************************
void hci_data_command_send(unsigned short usOpcode, unsigned char *pucBuff,
                     unsigned char ucArgsLength,unsigned short ucDataLength)
{ 
 	unsigned char *stream = (pucBuff + SPI_HEADER_SIZE);

	UINT8_TO_STREAM(stream, HCI_TYPE_DATA);
	UINT8_TO_STREAM(stream, usOpcode);
	UINT8_TO_STREAM(stream, ucArgsLength);
	stream = UINT16_TO_STREAM(stream, ucArgsLength + ucDataLength);


    //
	// Send teh command over SPI on data channel
	//
    SpiWrite(pucBuff, ucArgsLength + ucDataLength + SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE);


    return;
}
Example #23
0
//*****************************************************************************
//
//!  HCI data command send.
//!
//!  \param  usOpcode    command operation code
//!  \param  ucPayload   pointer to the data buffer
//!  \param  usLength    buffer length
//!
//!  \return none
//!
//!  \brief              Initiate an HCI data write operation
//
//*****************************************************************************
void hci_data_command_send(unsigned short usOpcode, unsigned char *pucBuff,
                     unsigned char ucArgsLength,unsigned short ucDataLength)
{ 
    hci_data_cmd_hdr_t *hci_cmnd_hdr_ptr;
 
    hci_cmnd_hdr_ptr = (hci_data_cmd_hdr_t *)(pucBuff + SPI_HEADER_SIZE);

    hci_cmnd_hdr_ptr->ucType = HCI_TYPE_DATA;
    hci_cmnd_hdr_ptr->ucOpcode = usOpcode;
    hci_cmnd_hdr_ptr->ucArgLength = ucArgsLength;
	hci_cmnd_hdr_ptr->usTotalLength = ucArgsLength + ucDataLength;

    //
	// Send teh command over SPI on data channel
	//
    SpiWrite(pucBuff, ucArgsLength + ucDataLength + sizeof(hci_data_cmd_hdr_t));


    return;
}
Example #24
0
//*****************************************************************************
//
//!  Initiate an HCI cmnd.
//!
//!  \param  usOpcode     command operation code
//!  \param  ucArgs       pointer to the command's arguments buffer
//!  \param  ucArgsLength length of the arguments
//!
//!  \return              ESUCCESS if command transfer complete,EFAIL otherwise.
//!
//!  \brief               Initiate an HCI cmnd.
//
//*****************************************************************************
unsigned short 
hci_command_send(unsigned short usOpcode, unsigned char *pucBuff,
                     unsigned char ucArgsLength)
{ 
    hci_cmnd_hdr_t *hci_cmnd_hdr_ptr;
 
    hci_cmnd_hdr_ptr = (hci_cmnd_hdr_t *)(pucBuff + SPI_HEADER_SIZE);

    hci_cmnd_hdr_ptr->ucType = HCI_TYPE_CMND;
    hci_cmnd_hdr_ptr->usOpcode = usOpcode;
    hci_cmnd_hdr_ptr->ucLength = ucArgsLength;

    //
	// Update the opcode of the event we will be waiting for
	//
    SpiWrite(pucBuff, ucArgsLength + sizeof(hci_cmnd_hdr_t));


    return(0);
}
Example #25
0
DRESULT disk_write (
	BYTE drv,			/* Physical drive nmuber (0) */
	const BYTE *buff,	/* Pointer to the data to be written */
	DWORD sector,		/* Start sector number (LBA) */
	BYTE count			/* Sector count (1..255) */
)
{

	DRESULT  res;	
	uint32_t size;
	uint32_t scount;
	
	if (drv) {
		res = (DRESULT)STA_NOINIT;	
		return res;
	}	
	 
	if(count==0||count>=2)
	{	 
		res = (DRESULT)  STA_NOINIT;
		return res;
	}
	
	size=count*512;
	
	if(bUseSDCard)
		SpiWrite(sector, size,(uint8_t *)buff);
	else
	{
		scount = size / (4*1024);
		if ((size % (4*1024)) != 0)
			scount++;
		
		spiFlashSectorErase(sector*512, scount);
		spiFlashCheckBusy();
		spiFlashPageProgram(sector*512, size,(uint8_t *)buff);
	}
	res = RES_OK;

	return res;
}
Example #26
0
File: hci.c Project: Gabbeh/CHARM
//*****************************************************************************
//
//!  hci_data_send
//!
//!  @param  usOpcode        command operation code
//!	 @param  ucArgs					 pointer to the command's arguments buffer
//!  @param  usArgsLength    length of the arguments
//!  @param  ucTail          pointer to the data buffer
//!  @param  usTailLength    buffer length
//!
//!  @return none
//!
//!  @brief              Initiate an HCI data write operation
//
//*****************************************************************************
INT32 hci_data_send(UINT8 ucOpcode, 
	UINT8 *ucArgs,
	UINT16 usArgsLength, 
	UINT16 usDataLength,
	const UINT8 *ucTail,
	UINT16 usTailLength)
{
	UINT8 *stream;

	stream = ((ucArgs) + SPI_HEADER_SIZE);

	UINT8_TO_STREAM(stream, HCI_TYPE_DATA);
	UINT8_TO_STREAM(stream, ucOpcode);
	UINT8_TO_STREAM(stream, usArgsLength);
	stream = UINT16_TO_STREAM(stream, usArgsLength + usDataLength + usTailLength);

	// Send the packet over the SPI
	SpiWrite(ucArgs, SIMPLE_LINK_HCI_DATA_HEADER_SIZE + usArgsLength + usDataLength + usTailLength);

	return(ESUCCESS);
}
Example #27
0
void RxPacket(void)
{
	uchar i;	
	TRX_CE=0;					// Set nRF905 in standby mode	
	CSN=0;						// Spi enable for write a spi command
	SpiWrite(RRP);				// Read payload command	
	for (i=0;i<32;i++)
	{
		RxBuf[i]=SpiRead();		// Read data and save to buffer		
	}
	CSN=1;						// Disable spi
	while(DR||AM)               //等待... /////////////如果接收不到程序将停滞 数据准备就绪以及地址匹配
	;	                          //即如果没有匹配的905模块时,这一句需要注释掉
	  
	    TRX_CE=1;               //允许发生或接收 ??????????????????????????

        if(RxBuf[0] == 1) 
	    {	  
		 LED1 = 0 ;
	    }
      /* if(RxBuf[1] == 1) 
	   {
	   		 LED2 = 0 ;
		}
         if(RxBuf[2] == 1) 
	   {
	   		 LED3 = 0 ;
		}
		if(RxBuf[3] == 1) 
	   {
	   		 LED4 = 0 ;
		}*/
	  
	Delay(500);					// ...light led
      LED1 = 1 ;
	  LED2 = 1 ;
	   LED3 = 1 ;
	    LED4 = 1 ;
	  								
}
Example #28
0
//*****************************************************************************
//
//!  hci_data_send
//!
//!  @param  usOpcode        command operation code
//!	 @param  ucArgs					 pointer to the command's arguments buffer
//!  @param  usArgsLength    length of the arguments
//!  @param  ucTail          pointer to the data buffer
//!  @param  usTailLength    buffer length
//!
//!  @return none
//!
//!  @brief              Initiate an HCI data write operation
//
//*****************************************************************************
long
hci_data_send(unsigned char ucOpcode, 
							unsigned char *ucArgs,
							unsigned short usArgsLength, 
							unsigned short usDataLength,
							const unsigned char *ucTail,
							unsigned short usTailLength)
{
	unsigned char *stream;
	
	stream = ((ucArgs) + SPI_HEADER_SIZE);
	
	UINT8_TO_STREAM(stream, HCI_TYPE_DATA);
	UINT8_TO_STREAM(stream, ucOpcode);
	UINT8_TO_STREAM(stream, usArgsLength);
	stream = UINT16_TO_STREAM(stream, usArgsLength + usDataLength + usTailLength);
	
	// Send the packet over the SPI
	SpiWrite(ucArgs, SIMPLE_LINK_HCI_DATA_HEADER_SIZE + usArgsLength + usDataLength + usTailLength);
	
	return(ESUCCESS);
}
Example #29
0
//*****************************************************************************
//
//!  hci_command_send
//!
//!  @param  usOpcode     command operation code
//!  @param  pucBuff      pointer to the command's arguments buffer
//!  @param  ucArgsLength length of the arguments
//!
//!  @return              none
//!
//!  @brief               Initiate an HCI command.
//
//*****************************************************************************
unsigned short 
hci_command_send(unsigned short usOpcode, unsigned char *pucBuff,
                     unsigned char ucArgsLength)
{ 
	unsigned char *stream;
	
	stream = (pucBuff + SPI_HEADER_SIZE);
	
	UINT8_TO_STREAM(stream, HCI_TYPE_CMND);
	stream = UINT16_TO_STREAM(stream, usOpcode);
	UINT8_TO_STREAM(stream, ucArgsLength);

//PORTD |= (1 << PD7) | (1 << PD6);
//PORTB |= (1 << PB4);
	
	//Update the opcode of the event we will be waiting for
	SpiWrite(pucBuff, ucArgsLength + SIMPLE_LINK_HCI_CMND_HEADER_SIZE);
	
//PORTD &= ~((1 << PD6) | (1 << PD7));

	return(0);
}
Example #30
0
/****************************************************
 SpiTsInitMode
****************************************************/
static int SpiTsInitMode(struct DibBridgeContext *pContext)
{
  unsigned char initbuffer[20]; 

#if (DIBCTRL_ADDR == DIBCTRL_DEFAULT_ADDR)
    initbuffer[0]=0x10;
    initbuffer[1]=0x20;
#else
    initbuffer[0]=0x0F;
    initbuffer[1]=0xE0;
#endif

  initbuffer[2]=0x00;
  initbuffer[3]=0x2C;

  initbuffer[4]=0x16;
  initbuffer[5]=0x00;
  initbuffer[6]=0x00;
  initbuffer[7]=0x00;

  initbuffer[8]=0x00;
  initbuffer[9]=0x3F;
  initbuffer[10]=0x00;
  initbuffer[11]=0x00;

  initbuffer[12]=0x00;
  initbuffer[13]=0x00;
  initbuffer[14]=0x00;
  initbuffer[15]=0x03;

  initbuffer[16]=0xFF;
  initbuffer[17]=0xFF;
  initbuffer[18]=0xFF;
  initbuffer[19]=0xFF;

  SpiWrite(pContext,initbuffer, 20);
  return 0;
}