⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mc_signal.c

📁 simulink real-time workshop for dragon12 development board from
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Function: process_RadioCommData_server ====================================================
 * Abstract:
 *  Attempts to read a telegram from the ring buffer of the radio module. If one is 
 *  found, it is copied to the appropriate buffer.
 *  This function simply returns if there are less than 4 bytes in the reception 
 *  buffer, otherwise it BLOCKS until the entire telegram has been received.
 */
void process_RadioCommData_server(uint16_T raw_data, uint8_T client) {

char_T    myBuf[4];
uint_T    i;

static myUsrBuf  *admin;        /* static, coz they may get used in subsequent calls to this function */
static uint16_T  size;          /* static, coz they may get used in subsequent calls to this function */
static uint8_T   *buf;          /* static, coz they may get used in subsequent calls to this function */


	/* check if we're dealing with formatted data or not (raw_data == 1) */
	if(raw_data) {

  		currentRFchannel = 0;   /* using channel '0' for raw data transmissions */
	  	admin            = radiocomTelBuf[5*client + currentRFchannel];
	  	size             = (uint16_T)admin->buf_size;
  		buf              = admin->buf;

	}

	/* beginning of telegram -- only relevant when receiving formatted data telegrams */
	if(currentRFchannel == -1) {
	  
		/* no header has previously been received -> try to fetch it */
		if(RadioServer_HasElements(client) >= 4) {
			
			/* read first 4 bytes from the RF input buffer */
  			for (i=0; i<4; i++) {
				/* fetch value from RF input buffer */
				myBuf[i] = RadioServer_InChar(client);
			}
		
	  		currentRFchannel = myBuf[1];
		  	admin            = radiocomTelBuf[5*client + currentRFchannel];
			size             = (uint16_T)admin->buf_size;
	  		buf              = admin->buf;
  		
		} /* header available */
    
	} /* currentRFchannel == -1 */
		

	/* remainder of telegram */
	if(currentRFchannel != -1) {
		
		/* a header has previously been received -> try to fetch remainder */
		
		/* read remainder of the telegram (if available) */
		if(RadioServer_HasElements(client) >= size) {
			
			/* at this stage, the entire remainder of the telegram is in the ring buffer */

			/* read remaining bytes from the ring buffer */
  			for (i=0; i<size; i++) {

				/* fetch value from RF input buffer */
				buf[i] = RadioServer_InChar(client);
				
  			}
		
    		/* indicate receipt of a telegram */
			admin->buffer_full = 1;
	    
			/* reset global variable 'currentFPchannel' */
			currentRFchannel = -1;
	    
		} /* remainder in buffer */
	  
	} /* currentRFchannel != -1 */

} /* End of process_RadioCommData_server */



/* Function: put_RFdata_server =======================================================
 * Abstract:
 *  Sends nbyte through the RF module
 */
void put_RFdata_server(uint8_T channel, uint8_T size, uint8_T dtype, uint8_T *src, uint8_T raw_data, uint8_T  client) {

uint_T    i;
uint8_T   myBuf[4];


  /* check if we need to send a header at all... (formatted telegrams) */
  if(!raw_data) {
	
	/* yes -> assemble header (size, channel, data_type_len, '0') */
	myBuf[0] = (uint8_T)(size + 4);
	myBuf[1] = channel;
	myBuf[2] = dtype;
	myBuf[3] = 0;
  
	/* send header */
	for (i = 0; i < 4; i++) {
	
		/* ensure that RF transmission buffer is not full */
		while(RadioServer_IsOutFull(client))  blinky(1000);
				
		/* write output data to output buffer */
		RadioServer_OutChar(client, myBuf[i]);
				
	}

  } /* raw_data == 0 */
	
  /* send remainder of the telegram (data) */
  for (i = 0; i < size; i++) {
	
	/* ensure that RF transmission buffer is not full */
	while(RadioServer_IsOutFull(client))  blinky(1000);
				
	/* write output data to output buffer */
	RadioServer_OutChar(client, src[i]);
				
  }

}  /* end of put_RFdata_server */


#endif /* HAS_RFCOMMS == 1 (server) */



// debug target in RT -> debug log through the vacant SCI0 (release mode)
#if (DEBUG2SCI0 > 0)


//-------------------------SCI0_OutChar------------------------
// Wait for buffer to be empty, output 8-bit to serial port
// busy-waiting synchronization
// Input: 8-bit data to be transferred
// Output: none
void SCI0_OutChar(char data) {
 
  while((SCI0SR1 & TDRE_mask) == 0){};
  SCI0DRL = data;
  
}

   
//-------------------------SCI0_OutString------------------------
// Output String (NULL termination), busy-waiting synchronization
// Input: pointer to a NULL-terminated string to be transferred
// Output: none
void SCI0_OutString(char *pt) {

  while(*pt) {
  
    SCI0_OutChar(*pt);
    pt++;
    
  }
  
}


//-----------------------SCI0_OutUDec-----------------------
// Output a 16-bit number in unsigned decimal format
// Input: 16-bit number to be transferred
// Output: none
// Variable format 1-5 digits with no space before or after
void SCI0_OutUDec(unsigned short n){
// This function uses recursion to convert decimal number
//   of unspecified length as an ASCII string 
  if(n >= 10){
    SCI0_OutUDec(n/10);
    n = n%10;
  }
  SCI0_OutChar(n+'0'); /* n is between 0 and 9 */
}

//--------------------------SCI0_OutUHex----------------------------
// Output a 16 bit number in unsigned hexadecimal format
// Input: 16-bit number to be transferred
// Output: none
// Variable format 1 to 4 digits with no space before or after
void SCI0_OutUHex(unsigned short number){
// This function uses recursion to convert the number of 
//   unspecified length as an ASCII string
  if(number>=0x10)	{
    SCI0_OutUHex(number/0x10);
    SCI0_OutUHex(number%0x10);
  }
  else if(number<0xA){
    SCI0_OutChar(number+'0');
  }
  else{
    SCI0_OutChar((number-0x0A)+'A');
  }
}

#endif /* DEBUG2SCI0 */



#ifdef LCDUSE4ERRORS
/* ============================================================================================= */
/* 'display' unsigned integer on the LCD */
/* ============================================================================================= */
void dispLCD_uint(unsigned int n, const char *myText, int line) {

int			i, j, k, l;
static char   myLCDtxt[16] = "                ";
unsigned int  myOut[8];
   
     
  /* copy text to output buffer */
  i = 0;
  while(myText[i] != 0) myLCDtxt[i] = myText[i++];
  
  /* determine magnitude of number to be displayed */
  k = 10;
  while(n / k >= 10) k *= 10;
  
  /* determine all digits */
  j = 0;
  while(k >= 1) {
    
    myOut[j] = (unsigned int)(n/k);
    n = n - myOut[j++] * k;
    k /= 10;
    
  }
  
  /* display... */
  for(l=0; l<j; l++) myLCDtxt[i+l] = '0' + myOut[l];
  
  if(line == 0) LCD_blank1();
  else          LCD_blank2();
    
  writeLine(myLCDtxt, line);
  
}
/* ============================================================================================= */
#endif /* LCDUSE4ERRORS  */



/* ============================================================================================= */
/* flash on-board LED																			 */
/* ============================================================================================= */
void wait(void)
{
   ;							/* dummy function call; used to extend LED display duration */
}

void blinky(unsigned long i) {

unsigned long	k;

	#if TARGET_BOARD == 1
	/* Dragon-12 */
	PORTB |= 0x01;						/* LED on  */
	for(k = 0; k < i; k++) wait();		/* delay   */
	PORTB ^= 0x01;						/* LED off */
	for(k = 0; k < i; k++) wait();		/* delay   */
	#endif
	
  #if ((TARGET_BOARD == 2) | (TARGET_BOARD == 3))
  /* MiniDragon+ */
	PTH |= 0x01;          						/* first segment on  */
	for(k = 0; k < i; k++) wait();		/* delay   */
	PTH ^= 0x01;          						/* first segment off */
	for(k = 0; k < i; k++) wait();		/* delay   */
	#endif
	
}
/* ============================================================================================= */


/* ============================================================================================= */
/* display a digit (0 - 9) on the 7-segment display (MiniDragon+)																 */
/* ============================================================================================= */

#if ((TARGET_BOARD == 2) | (TARGET_BOARD == 3))
void displayDigit(int dig) {

  /* MiniDragon+ based targets only */
  switch(dig) {
    
    case 0:
      PTH = 0xbf;
      break;
    case 1:
      PTH = 0x06;
      break;
    case 2:
      PTH = 0xdb;
      break;
    case 3:
      PTH = 0xcf;
      break;
    case 4:
      PTH = 0xe6;
      break;
    case 5:
      PTH = 0xed;
      break;
    case 6:
      PTH = 0xfd;
      break;
    case 7:
      PTH = 0x07;
      break;
    case 8:
      PTH = 0xff;
      break;
    case 9:
      PTH = 0xe7;
      break;
  }
	
}
#endif /* TARGET_BOARD */
/* ============================================================================================= */


/* ============================================================================================= */
/* 'display' error number on the LED															 */
/* ============================================================================================= */
void sigLED(int ErrorNumber) {

unsigned long	k;
int			i, j;
static char    myLCDtxt[16] = "Error:          ";
   
   
  /* display ErrorNumber (LED) :    */
  /* long - (tens) - long - (ones)  */

  j = (int)(((float)(ErrorNumber)+0.5)/10.0);

  #ifdef LCDUSE4ERRORS
   myLCDtxt[7] = (char)('0' + j);
  #else
   blinky(150000);
   #if ((TARGET_BOARD == 2) | (TARGET_BOARD == 3))
     // MiniDragon+
     displayDigit(j);                     /* tens */
   #else
     for(i=0; i<j; i++) blinky(70000);		/* tens */
   #endif
   for(k = 0; k < 100000; k++) wait();
   blinky(150000);
  #endif

  j = (int)(ErrorNumber - j*10);

  #ifdef LCDUSE4ERRORS
   myLCDtxt[8] = (char)('0' + j);
   LCD_blank1();
   writeLine(myLCDtxt, 0);
  #else
   #if ((TARGET_BOARD == 2) | (TARGET_BOARD == 3))
     // MiniDragon+
     displayDigit(j);                     /* ones */
   #else
     for(i=0; i<j; i++) blinky(70000);		/* ones */
   #endif
   for(k = 0; k < 100000; k++) wait();
  #endif

  
}
/* ============================================================================================= */


/* ============================================================================================= */
/* terminate MC program and 'display' error number on the LED									 */
/* ============================================================================================= */
void abort_LED(int ErrorNumber) {

unsigned long	k;

  asm sei     						/* disable all interrupts     */

  /* display ErrorNumber (LED) */
  sigLED(ErrorNumber);

  /* dimmed light...           */
  while (1) {
	
	  blinky(100);
	  for(k = 0; k < 1000; k++) wait();
  
  }
  
}
/* ============================================================================================= */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -