コード例 #1
0
ファイル: bmac.cpp プロジェクト: ESE519/EVM-2013
int8_t bmac_tx_pkt(char *buf, uint8_t len)
{
    uint32_t mask;
    if(tx_data_ready==1) return NRK_ERROR;
	
// If reserve exists check it
#ifdef NRK_MAX_RESERVES
    if(tx_reserve!=-1)
    {
        if( nrk_reserve_consume(tx_reserve)==NRK_ERROR )
        {
					
            return NRK_ERROR;
        }
    }
#endif
		
    nrk_signal_register(bmac_tx_pkt_done_signal);
    tx_data_ready=1;
    bmac_rfTxInfo.pPayload=buf;
    bmac_rfTxInfo.length=len;
#ifdef DEBUG
    printf("Waiting for tx done signal\r\n");
#endif
    mask=nrk_event_wait (SIG(bmac_tx_pkt_done_signal));
    if(mask==0) printf("BMAC TX: Error calling event wait\r\n");
    if((mask&SIG(bmac_tx_pkt_done_signal))==0) printf("BMAC TX: Woke up on wrong signal\r\n");
    if(pkt_got_ack) {//printf("NRK OK \r\n"); 
			return NRK_OK;}
    
			return NRK_ERROR;
}
コード例 #2
0
ファイル: pcf_tdma.c プロジェクト: mlab-upenn/mrk
int8_t tdma_send (tdma_info * fd, uint8_t * buf, uint8_t len, uint8_t flags)
{
  uint32_t mask;
  uint8_t i;

  if (tx_data_ready == 1)
    return NRK_ERROR;
  if (len == 0)
    return NRK_ERROR;
  if (buf == NULL)
    return NRK_ERROR;
  if (fd == NULL)
    return NRK_ERROR;

// If reserve exists check it
#ifdef NRK_MAX_RESERVES
  if (tx_reserve != -1) {
    if (nrk_reserve_consume (tx_reserve) == NRK_ERROR) {
      return NRK_ERROR;
    }
  }
#endif
  if (flags == TDMA_BLOCKING)
    nrk_signal_register (tdma_tx_pkt_done_signal);

  tx_data_ready = 1;

  tdma_rfTxInfo.pPayload = tdma_tx_buf;
// Setup the header data
  tdma_rfTxInfo.pPayload[TDMA_SLOT_HIGH] = (fd->slot >> 8) & 0xff;
  tdma_rfTxInfo.pPayload[TDMA_SLOT_LOW] = (fd->slot & 0xff);
  tdma_rfTxInfo.pPayload[TDMA_DST_HIGH] = (fd->dst >> 8) & 0xff;
  tdma_rfTxInfo.pPayload[TDMA_DST_LOW] = (fd->dst & 0xff);
  tdma_rfTxInfo.pPayload[TDMA_SRC_HIGH] = (fd->src >> 8) & 0xff;
  tdma_rfTxInfo.pPayload[TDMA_SRC_LOW] = (tdma_my_mac & 0xff);
  tdma_rfTxInfo.pPayload[TDMA_SEQ_NUM_HIGH] = (tdma_my_mac >> 8) & 0xff;
  tdma_rfTxInfo.pPayload[TDMA_SEQ_NUM_LOW] = (fd->seq_num & 0xff);
  tdma_rfTxInfo.pPayload[TDMA_CYCLE_SIZE_HIGH] = (fd->cycle_size >> 8) & 0xff;
  tdma_rfTxInfo.pPayload[TDMA_CYCLE_SIZE_LOW] = (fd->cycle_size & 0xff);
// Copy the user payload to the back of the header
  for (i = 0; i < len; i++)
    tdma_rfTxInfo.pPayload[i + TDMA_PCF_HEADER] = buf[i];
// Set packet length with header
  tdma_rfTxInfo.length = len + TDMA_PCF_HEADER;
#ifdef DEBUG
  nrk_kprintf (PSTR ("Waiting for tx done signal\r\n"));
#endif

  if (flags == TDMA_BLOCKING) {
    mask = nrk_event_wait (SIG (tdma_tx_pkt_done_signal));
    if (mask == 0)
      nrk_kprintf (PSTR ("TDMA TX: Error calling event wait\r\n"));
    if ((mask & SIG (tdma_tx_pkt_done_signal)) == 0)
      nrk_kprintf (PSTR ("TDMA TX: Woke up on wrong signal\r\n"));
    return NRK_OK;
  }

  return NRK_OK;
}