Exemplo n.º 1
0
void Jitter(void)   // prints jitter information (write this)
{
  char string[7], printInd[7];
  int i;
  OSuart_OutString(UART0_BASE,"Jitter Information:\n\r\n\r");
  OSuart_OutString(UART0_BASE,"Jitter for Periodic Task 1:\n\r");
  for(i = 0; i<JITTERSIZE; i++)
  {
    if(JitterHistogramA[i] != 0)
	  {
  	  Int2Str((i-32), printInd);
  	  Int2Str(JitterHistogramA[i], string);
  	  OSuart_OutString(UART0_BASE,printInd);
  	  OSuart_OutString(UART0_BASE,": ");
        OSuart_OutString(UART0_BASE,string);
  	  OSuart_OutString(UART0_BASE,"\n\r"); 
  	}
  }
  OSuart_OutString(UART0_BASE,"Jitter for Periodic Task 2:\n\r");
  for(i = 0; i<JITTERSIZE; i++)
  {
    if(JitterHistogramB[i] != 0)
  	{
  	  Int2Str((i-32), printInd);
  	  Int2Str(JitterHistogramB[i], string);
  	  OSuart_OutString(UART0_BASE,printInd);
   	  OSuart_OutString(UART0_BASE,": ");
      OSuart_OutString(UART0_BASE,string);
   	  OSuart_OutString(UART0_BASE,"\n\r"); 
  	}
  }
    
}
Exemplo n.º 2
0
void NEC_ReceiveInterrupt(NEC_FRAME f) {
	GPIO_ToggleBits(GPIOD, GPIO_Pin_7);
	char buf[12];
	USART_WriteString("NEC Frame was received : \r\nAddress : ");
	Int2Str(buf, f.Address);
	USART_WriteString(buf);
	USART_WriteString("\r\nCommand : ");
	Int2Str(buf, f.Command);
	USART_WriteString(buf);
	USART_WriteString("\r\n");

	switch (f.Command) {
	case 1:
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
		break;
	case 2:
		GPIO_ToggleBits(GPIOD, GPIO_Pin_13);
		break;
	case 3:
		GPIO_ToggleBits(GPIOD, GPIO_Pin_14);
		break;
	case 4:
		GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
		break;
	}
}
Exemplo n.º 3
0
/**
  * @brief  Download a file via serial port
  * @param  None
  * @retval None
  */
void SerialDownload(mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize)
{
  char Number[10] = "          ";
  int32_t Size = 0;

  printf("Waiting for the file to be sent ... (press 'a' to abort)\n\r");
  Size = Ymodem_Receive(&tab_1024[0], flash, flashdestination, maxRecvSize);
  if (Size > 0)
  {
    printf("\n\n\r Programming Successfully!\n\r\r\n Name: ");
    printf("%s", FileName);
    
    Int2Str((uint8_t *)Number, Size);
    printf("\n\r Size: ");
    printf("%s", Number);
    printf(" Bytes\r\n");
  }
  else if (Size == -1)
  {
    printf("\n\n\rThe image size is higher than memory!\n\r");
  }
  else if (Size == -2)
  {
    printf("\n\n\rVerification failed!\n\r");
  }
  else if (Size == -3)
  {
    printf("\r\n\nAborted by user.\n\r");
  }
  else
  {
    printf("\n\rFailed to receive file!\n\r");
  }
}
Exemplo n.º 4
0
/**
  * @brief  Download a file via serial port
  * @param  None
  * @retval None
  */
void SerialDownload(void)
{
    uint8_t Number[10] = "          ";
    int32_t Size = 0;

    SerialPutString("Waiting for the file to be sent ... (press 'a' to abort)\n\r");
    Size = Ymodem_Receive(&tab_1024[0]);
    if (Size > 0)
    {
        SerialPutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
        SerialPutString(file_name);
        Int2Str(Number, Size);
        SerialPutString("\n\r Size: ");
        SerialPutString(Number);
        SerialPutString(" Bytes\r\n");
        SerialPutString("-------------------\n");
    }
    else if (Size == -1)
    {
        SerialPutString("\n\n\rThe image size is higher than the allowed space memory!\n\r");
    }
    else if (Size == -2)
    {
        SerialPutString("\n\n\rVerification failed!\n\r");
    }
    else if (Size == -3)
    {
        SerialPutString("\r\n\nAborted by user.\n\r");
    }
    else
    {
        SerialPutString("\n\rFailed to receive the file!\n\r");
    }
}
Exemplo n.º 5
0
/**
  * @brief  Prepare the first block
  * @param  timeout
  *     0: end of transmission
  * @retval None
  */
void Ymodem_PrepareIntialPacket(uint8_t *data, const uint8_t* fileName, uint32_t *length)
{
    uint16_t i, j;
    uint8_t file_ptr[10];

    /* Make first three packet */
    data[0] = SOH;
    data[1] = 0x00;
    data[2] = 0xff;

    /* Filename packet has valid data */
    for (i = 0; (fileName[i] != '\0') && (i < FILE_NAME_LENGTH); i++)
    {
        data[i + PACKET_HEADER] = fileName[i];
    }

    data[i + PACKET_HEADER] = 0x00;

    Int2Str (file_ptr, *length);
    for (j =0, i = i + PACKET_HEADER + 1; file_ptr[j] != '\0' ; )
    {
        data[i++] = file_ptr[j++];
    }

    for (j = i; j < PACKET_SIZE + PACKET_HEADER; j++)
    {
        data[j] = 0;
    }
}
Exemplo n.º 6
0
/*******************************************************************************
  * @函数名称	 Ymodem_PrepareIntialPacket
  * @函数说明   准备第一个数据包
  * @输入参数   data:数据包
                 fileName :文件名
                 length :长度
  * @输出参数   无
  * @返回参数   无
*******************************************************************************/
void Ymodem_PrepareIntialPacket(uint8_t *data, const uint8_t* fileName, uint32_t *length)
{
    uint16_t i, j;
    uint8_t file_ptr[10];

    //制作头3个数据包
    data[0] = SOH;
    data[1] = 0x00;
    data[2] = 0xff;
    //文件名数据包有效数据
    for (i = 0; (fileName[i] != '\0') && (i < FILE_NAME_LENGTH); i++)
    {
        data[i + PACKET_HEADER] = fileName[i];		//PACKET_HEADER=3,此句表示从数据包的数据区开始
    }

    data[i + PACKET_HEADER] = 0x00;			//表示文件名以00结束

    Int2Str (file_ptr, *length);				//继续写入长度数据
    for (j =0, i = i + PACKET_HEADER + 1; file_ptr[j] != '\0' ; )
    {
        data[i++] = file_ptr[j++];
    }
		
		//表示数据区剩余字节填00
    for (j = i; j < PACKET_SIZE + PACKET_HEADER; j++)				//PACKET_SIZE=128,
    {
        data[j] = 0;
    }
}
Exemplo n.º 7
0
//----------------------------------------------------------------------------------------------
static void Ymodem_PrepareIntialPacket(uint8_t *data, const uint8_t* fileName, uint32_t *length)
{
  uint16_t i, j;
  uint8_t file_ptr[10];
  uint16_t tempCRC;
  
  // Make first three packet
  data[0] = SOH;
  data[1] = 0x00;
  data[2] = 0xff;
  
  // Filename packet has valid data
  for (i = 0; (fileName[i] != '\0') && (i <SPIFFS_OBJ_NAME_LEN);i++)
  {
     data[i + PACKET_HEADER] = fileName[i];
  }

  data[i + PACKET_HEADER] = 0x00;
  
  Int2Str (file_ptr, *length);
  for (j =0, i = i + PACKET_HEADER + 1; file_ptr[j] != '\0' ; )
  {
     data[i++] = file_ptr[j++];
  }
  data[i++] = 0x20;
  
  for (j = i; j < PACKET_SIZE + PACKET_HEADER; j++)
  {
    data[j] = 0;
  }
  tempCRC = Cal_CRC16(&data[PACKET_HEADER], PACKET_SIZE);
  data[PACKET_SIZE + PACKET_HEADER] = tempCRC >> 8;
  data[PACKET_SIZE + PACKET_HEADER + 1] = tempCRC & 0xFF;
}
Exemplo n.º 8
0
/**
  * @brief  Prepare the first block
  * @param  p_data:  output buffer
  * @param  p_file_name: name of the file to be sent
  * @param  length: length of the file to be sent in bytes
  * @retval None
  */
static void PrepareIntialPacket(uint8_t *p_data, const uint8_t *p_file_name, uint32_t length)
{
  uint32_t i, j = 0;
  uint8_t astring[10];

  /* first 3 bytes are constant */
  p_data[PACKET_START_INDEX] = SOH;
  p_data[PACKET_NUMBER_INDEX] = 0x00;
  p_data[PACKET_CNUMBER_INDEX] = 0xff;

  /* Filename written */
  for (i = 0; (p_file_name[i] != '\0') && (i < FILE_NAME_LENGTH); i++)
  {
    p_data[i + PACKET_DATA_INDEX] = p_file_name[i];
  }

  p_data[i + PACKET_DATA_INDEX] = 0x00;

  /* file size written */
  Int2Str (astring, length);
  i = i + PACKET_DATA_INDEX + 1;
  while (astring[j] != '\0')
  {
    p_data[i++] = astring[j++];
  }

  /* padding with zeros */
  for (j = i; j < PACKET_SIZE + PACKET_DATA_INDEX; j++)
  {
    p_data[j] = 0;
  }
}
Exemplo n.º 9
0
/**
  * @brief  Download a file via serial port
  * @param  None
  * @retval None
  */
void SerialDownload(void)
{
  uint8_t number[11] = {0};
  uint32_t size = 0;
  COM_StatusTypeDef result;

  Serial_PutString((uint8_t *)"Waiting for the file to be sent ... (press 'a' to abort)\n\r");
  result = Ymodem_Receive( &size );
  if (result == COM_OK)
  {
    Serial_PutString((uint8_t *)"\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
    Serial_PutString(aFileName);
    Int2Str(number, size);
    Serial_PutString((uint8_t *)"\n\r Size: ");
    Serial_PutString(number);
    Serial_PutString((uint8_t *)" Bytes\r\n");
    Serial_PutString((uint8_t *)"-------------------\n");
  }
  else if (result == COM_LIMIT)
  {
    Serial_PutString((uint8_t *)"\n\n\rThe image size is higher than the allowed space memory!\n\r");
  }
  else if (result == COM_DATA)
  {
    Serial_PutString((uint8_t *)"\n\n\rVerification failed!\n\r");
  }
  else if (result == COM_ABORT)
  {
    Serial_PutString((uint8_t *)"\r\n\nAborted by user.\n\r");
  }
  else
  {
    Serial_PutString((uint8_t *)"\n\rFailed to receive the file!\n\r");
  }
}
Exemplo n.º 10
0
int main0(void){  
  // "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers",
  // ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014, Volume 2, Program 11.2
  UINT8             IsDHCP = 0;
  _NetCfgIpV4Args_t ipV4;
  SlSockAddrIn_t    Addr;
  UINT16            AddrSize = 0;
  INT16             SockID = 0;
  UINT32            data;
  unsigned char     len = sizeof(_NetCfgIpV4Args_t);
  initClk();         // PLL 50 MHz, ADC needs PPL active          15
  ADC0_InitSWTriggerSeq3(7);  // Ain7 is on PD0                   16
  sl_Start(0, 0, 0); // Initializing the CC3100 device            17
  WlanConnect();     // connect to AP                             18
  sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,       // 19
               (unsigned char *)&ipV4);                        // 20
  Addr.sin_family = SL_AF_INET;                       //          21 
  Addr.sin_port = sl_Htons((UINT16)PORT_NUM);         //          22
  Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);   //          23
  AddrSize = sizeof(SlSockAddrIn_t);                  //          24
  SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);    //          25
  while(1){
    uBuf[0] = ATYPE;      // analog data type                     26
    uBuf[1] = '=';        //                                      27
    data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0            28
    Int2Str(data,(char*)&uBuf[2]); // 6 digit number              29
    sl_SendTo(SockID, uBuf, BUF_SIZE, 0,        //                30
                         (SlSockAddr_t *)&Addr, AddrSize); //     31
    ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25);  // 40ms          32
  }
}
Exemplo n.º 11
0
// 构建更新字符的表达式
bool COracleDB::BuildUpdate( const OracleSqlObj *obj, string &s )
{
	OracleSqlObj::CKVMap kv = obj->_kv;

	OracleSqlObj::CKVMap::iterator it;
	for ( it = kv.begin(); it != kv.end() ; ++ it ) {
		const string &skey = it->first;
		OracleSqlObj::_SqlVal &oval = it->second;
		if ( skey.empty() )
			continue;

		if ( ! s.empty() )
			s += ",";

		s += skey + "=";
		if ( oval._type == CSqlObj::TYPE_STRING ) {
			s += "'" + oval._sval + "'";
		} else if ( oval._type == CSqlObj::TYPE_VAR ) {
			s += oval._sval;
		} else if ( oval._type == CSqlObj::TYPE_INT ) {
			s += Int2Str( oval._nval );
		}
	}

	return ( ! s.empty() );
}
Exemplo n.º 12
0
void Int2Str_Test(){
    u8 str[10];
    int v;

    v=1234;
    Int2Str(str,v);
    printf("int:%d str:%s\n",v,str);

    v=123;
    Int2Str(str,v);
    printf("int:%d str:%s\n",v,str);

    v=54215198;
    Int2Str(str,v);
    printf("int:%d str:%s\n",v,str);
}
Exemplo n.º 13
0
void OutputThread(void){  // foreground thread
  char sigStr[7], waitStr[7];
  OSuart_OutString(UART0_BASE,"\n\rEE345M/EE380L, Lab 3 Preparation 4\n\r");
  while(SignalCount1+SignalCount2+SignalCount3<100*MAXCOUNT){
    OS_Sleep(1000);   // 1 second
    OSuart_OutString(UART0_BASE,".");
  }       
  OSuart_OutString(UART0_BASE," done\n\r");
  Int2Str(SignalCount1+SignalCount2+SignalCount3, sigStr);
  Int2Str(WaitCount1+WaitCount2+WaitCount3, waitStr);
  OSuart_OutString(UART0_BASE,"Signalled = ");
  OSuart_OutString(UART0_BASE,sigStr);
  OSuart_OutString(UART0_BASE,"Waited = ");
  OSuart_OutString(UART0_BASE,waitStr);

  OS_Kill();
}
Exemplo n.º 14
0
		static SequenceT Write(SlkTable const& table, std::string const& tag = "ID")
		{
			std::string head;
			std::string body;
			std::map<std::string, size_t> TagList;
			size_t cur_x, cur_y = 2;

			foreach (auto const& ObjectIt, table)
			{
				object_id const& Id = ObjectIt.first;
				SlkSingle const& Object = ObjectIt.second;

				body += "C;X1;Y" + Int2Str(cur_y++) + ";K\"" + Id.to_string() + "\"\n";

				foreach (auto const& KeyValueIt, Object)
				{
					std::string const& Key   = KeyValueIt.first;
					SlkValue const&    Value = KeyValueIt.second;

					auto const& It = TagList.find(Key);
					if (It == TagList.end())
					{
						cur_x = TagList.size() + 2;
						TagList[Key] = cur_x;
					}
					else
					{
						cur_x = It->second;
					}

					body += "C;X" + Int2Str(cur_x) + ";K";
					if (Value.is_str())
					{
						body += "\"";
						body += Value.to_string();
						body += "\"";
					}
					else
					{
						body += Value.to_string();
					}
					body += "\n";
				}
Exemplo n.º 15
0
//
//The implementation of FormString routine.
//This routine formats a string,and copy it into a buffer.
//It's function likes sprintf.
//
INT FormString(LPSTR lpszBuff,LPSTR lpszFmt,LPVOID* lppParam)
{
	DWORD        dwIndex        = 0;
	LPSTR        lpszTmp        = NULL;
	CHAR         Buff[12];

	if((NULL == lpszBuff) || (NULL == lpszBuff))
		return -1;

	lpszTmp = lpszBuff;
	while(*lpszFmt)
	{
		if('%' == *lpszFmt)    //Should process.
		{
			lpszFmt ++;        //Skip '%'.
			switch(*lpszFmt)
			{
			case 'd':    //Convert an integer to string.
				Int2Str(*((DWORD*)lppParam[dwIndex ++]),Buff);  //Convert to string.
				StrCpy(Buff,lpszTmp);
				lpszTmp += StrLen(Buff);
				lpszFmt ++;
				break;
			case 'c':    //Convert a character to string.
				*lpszTmp ++= *((BYTE*)lppParam[dwIndex ++]);
				lpszFmt ++;
				break;
			case 's':    //Append a string.
				StrCpy((LPSTR)lppParam[dwIndex],lpszTmp);
				lpszTmp += StrLen((LPSTR)lppParam[dwIndex ++]);
				lpszFmt ++;
				break;
			case 'x':    //Convert an integer to string in hex.
			case 'X':
				Hex2Str(*((DWORD*)lppParam[dwIndex ++]),Buff);  //Convert to string.
				StrCpy(Buff,lpszTmp);
				lpszTmp += StrLen(Buff);
				lpszFmt ++;
				break;
			default:     //Unsupported now.
				break;
			}
		}
		*lpszTmp = *lpszFmt;
		if(0 == *lpszTmp)    //Reach end.
			break;
		lpszTmp ++;
		lpszFmt ++;
	}

	*lpszTmp = 0;    //End sign.
	return (lpszTmp - lpszBuff);
}
Exemplo n.º 16
0
// return prop value in "read" json object if read success, else return err code in "err" object.
// NOTE: val is not used now.
OSStatus _property_read_create_response(struct mico_service_t *service_table, 
                                   const char *key, int val,
                                   json_object *out_read_obj, json_object *out_err_prop_obj)
{
  OSStatus err = kUnknownErr;
  int service_index = 0; 
  int property_index = 0;
  int iid = 0;
  int tmp_iid = 0;
  char iid_str[16] = {0};
  const char* pProertyType = NULL;
  
  require_action( service_table, exit, err = kParamErr);
  require_action( out_read_obj, exit, err = kParamErr);
  require_action( out_err_prop_obj, exit, err = kParamErr);
  
  Str2Int((uint8_t*)key, &iid);
  err = getIndexByIID(service_table, iid, &service_index, &property_index);
  require_noerr(err, exit);
  
  if( -1 == property_index){  // is a service
    tmp_iid = iid + 1;
    for(property_index = 0, pProertyType = service_table[service_index].properties[0].type; NULL != pProertyType;){
      // iid as response key
      memset(iid_str, '\0', sizeof(iid_str));
      Int2Str((uint8_t*)iid_str, tmp_iid);
      
      err = _property_read_create_response_by_index(service_table, iid_str, tmp_iid, 
                                               service_index, property_index, 
                                               out_read_obj, out_err_prop_obj);
      tmp_iid++;
      property_index++;
      pProertyType = service_table[service_index].properties[property_index].type;
    }
  }
  else{  // is a property
    err = _property_read_create_response_by_index(service_table, key, iid, 
                                             service_index, property_index, 
                                             out_read_obj, out_err_prop_obj);
  }
  
exit:
  if(kNotFoundErr == err){
    json_object_object_add(out_err_prop_obj, key, json_object_new_int(MICO_PROP_CODE_NOT_FOUND));
  }
  if(kParamErr == err){
    json_object_object_add(out_err_prop_obj, key, json_object_new_int(MICO_PROP_CODE_DATA_FORMAT_ERR));
  }
  return err;
}
Exemplo n.º 17
0
static CString Int2Str(int iNum)
{
    if (iNum == 0)
        return CString("0");
    if (iNum < 0)
        return CString("-")+Int2Str(-iNum);

    CString cString;
    char aString[] = {0,0};
    for (int iTmp=iNum; iTmp>0; iTmp/=10)
    {
        aString[0] = '0'+(iTmp%10);
        cString = CString(aString)+cString;
    }
    return cString;
}
Exemplo n.º 18
0
// 是否提交事务操作
bool COracleDB::Execute( const char *stable, const OracleSqlObj *obj, bool commit )
{
	OracleSqlObj::CKVMap kv = obj->_kv;

	if ( kv.empty() )
		return false;

	string sqlbuf = "insert into ";
	sqlbuf += stable;
	sqlbuf += "(";

	string key, val;
	OracleSqlObj::CKVMap::iterator it;
	for ( it = kv.begin(); it != kv.end() ; ++ it ) {
		const string &skey = it->first;
		OracleSqlObj::_SqlVal &oval = it->second;
		if ( skey.empty() )
			continue;

		if ( ! key.empty() ) {
			key += ",";
			val += ",";
		}

		key += skey;
		if ( oval._type == CSqlObj::TYPE_STRING ) {
			val += "'" + oval._sval + "'";
		} else if ( oval._type == CSqlObj::TYPE_VAR ) {
			val += oval._sval;
		} else if ( oval._type == CSqlObj::TYPE_INT ) {
			val += Int2Str( oval._nval );
		}else if ( oval._type == CSqlObj::TYPE_LONGLONG){
            val += ll2Str( oval._llval);
		}
	}

	sqlbuf += key + ")values(" + val + ")";

	int ret = oracle_exec( sqlbuf.c_str(), commit ) ;
	if ( ret != DB_ERR_SUCCESS ) {
		OUT_ERROR( NULL, 0, "Oracle", "Execute sql: %s, result %d", sqlbuf.c_str(), ret ) ;
		return false;
	}

	return true;
}
Exemplo n.º 19
0
void CDiagram::AddRow(int iNumOfValues,...)
{
    int  iNumOfSkipColumns = m_iNumOfColumns-iNumOfValues;
    int* pValuePerColumn   = (int*)&iNumOfValues+1;

    m_cPresentation += m_pRowDelimiters[iNumOfSkipColumns] + CString("|");
    for (int i=0; i<m_iNumOfColumns; i++)
    {
        CString cValue;
        if (i >= iNumOfSkipColumns)
            cValue = Int2Str(pValuePerColumn[i-iNumOfSkipColumns]);
        int iValueLength = cValue.GetLength();
        int iTitleLength = m_pColumnTitles[i].GetLength();
        while (iValueLength++ <= iTitleLength)
            cValue = CString(" ") + cValue;
        m_cPresentation += cValue + CString(" |");
    }
    m_cPresentation += CString("\n");
}
Exemplo n.º 20
0
DWORD Fibonacci(LPVOID lpParam)
{
    //LPSTR lpszParam = (LPSTR)lpParam;
	__CMD_PARA_OBJ* pCmdParaObj               = (__CMD_PARA_OBJ*)lpParam;
    __FIBONACCI_CONTROL_BLOCK ControlBlock[5] = {0};
    HANDLE hThread[5] = {NULL};
    CHAR Buffer[12];
    DWORD dwCounter;
    DWORD dwIndex,i;

	PrintLine("Fibonacci application running...");
	GotoHome();
	ChangeLine();

	if(NULL == pCmdParaObj || pCmdParaObj->byParameterNum < 2)
	{
		return 0;
	}

    dwCounter = 0;
    for(i = 0;i < 5;i ++)
    {     
        dwIndex = 0;
        while(pCmdParaObj->Parameter[1][dwCounter])
		{
			Buffer[dwIndex] =  pCmdParaObj->Parameter[1][dwCounter];
			dwIndex ++;
			dwCounter ++;
		}

        Buffer[dwIndex] = 0;
        Str2Hex(Buffer,&ControlBlock[i].dwInitNum);  //Convert the parameter to integer.

        if(pCmdParaObj->Parameter[1][dwCounter])
		{
			break;
		}
    }

	i = 5;
    for(i;i > 0;i --)
    {
        hThread[i - 1] = CreateKernelThread(
			0,    //Stack size,use default.
            KERNEL_THREAD_STATUS_READY,  //Status.
			PRIORITY_LEVEL_NORMAL,
			CalculateThread,  //Start routine.
			(LPVOID)&ControlBlock[i - 1],
            NULL,
			"FIBONACCI");

        if(NULL == hThread[i - 1])  //Failed to create kernel thread.
        {
            PrintLine("Create kernel thread failed.");
            break;
        }
    }

    //
    //Waiting for the kernel thread to over.
    //
    WaitForThisObject(hThread[0]);
    WaitForThisObject(hThread[1]);
    WaitForThisObject(hThread[2]);
    WaitForThisObject(hThread[3]);
    WaitForThisObject(hThread[4]);

    //
    //Now,we have calculated the fibonacci number,print them out.
    //
    for(i = 0;i < 5;i ++)
    {
        Int2Str(ControlBlock[i].dwInitNum,Buffer);
        PrintStr(Buffer);
        PrintStr("'s result is: ");
        Int2Str(ControlBlock[i].dwResult,Buffer);
        PrintStr(Buffer);
		GotoHome();
        ChangeLine();
    }

    //
    //Close the kernel thread.
    //
    DestroyKernelThread(hThread[0]);
    DestroyKernelThread(hThread[1]);
    DestroyKernelThread(hThread[2]);
    DestroyKernelThread(hThread[3]);
    DestroyKernelThread(hThread[4]);
    
    return 1L;
}
Exemplo n.º 21
0
void LCD_WriteInt(int val)
{
    LCD_WriteString(Int2Str(val));
}
Exemplo n.º 22
0
int main(void)
{
    UINT8  IsDHCP = 0;
    int32_t i32CommandStatus;
    _NetCfgIpV4Args_t ipV4;
		SlSockAddrIn_t    Addr; 
		UINT16            AddrSize = 0; 
		INT16             SockID = 0; 
		UINT32            data; 
		long x = 0; //counter
    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    int Status = 0;
    /* Stop WDT */
    stopWDT();
    /* Initialize the system clock of MCU */
    initClk();
		Board_Init();       // initialize LaunchPad I/O and PD1 LED
    ConfigureUART();    // Initialize the UART.
    UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
    UARTprintf("This application is configured to generate text\n");
    UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
		//added code from the powerpoint slide
    /* Initializing the CC3100 device */
    sl_Start(0, 0, 0);
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
    Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
    AddrSize = sizeof(SlSockAddrIn_t);
    SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
    // Loop forever waiting  for commands from PC...
    //
    while(1)
    {
        // Print prompt for user.
        UARTprintf("\n>");
        // Peek to see if a full command is ready for processing.
        while(UARTPeek('\r') == -1)
						LED_On();
            // Approximately 1 millisecond delay.
            ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000);

        }
        // A '\r' was detected so get the line of text from the receive buffer.
		while(Status >= 0){
      UARTprintf("\nSending a UDP packet ...\n");
		
			UARTgets(g_cInput,sizeof(g_cInput)); //this function receives the input from the Putty and places it in a string

			
			
			//DO NOT CHANGE ANYTHING ABOVE THIS COMMENT
			
			//WHAT WE NEED TO DO:
			//work with the g_cInput to get the array of letters typed into the Putty
			//then send that Array using UARTprintf
			uBuf[0] = ATYPE;   // defines this as an analog data type
			uBuf[1] = '='; 
			data = 1000;

			Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number
      UARTprintf(" %s ",uBuf); //this line sends a string to the receiver
      //the above 5 lines print out a = 1000;
			//everything below this is just error cases
			if( SockID < 0 ){
        UARTprintf("SockIDerror ");
        Status = -1; // error
      }else{
        LED_Toggle();
        Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0,
                           (SlSockAddr_t *)&Addr, AddrSize);
        if( Status <= 0 ){
          sl_Close(SockID);
          UARTprintf("SockIDerror %d ",Status);
        }else{
          UARTprintf("ok");
        }
      }
      ROM_SysCtlDelay(ROM_SysCtlClockGet() / 100); // 10ms
			LED_Off();
		}
   }
Exemplo n.º 23
0
/*******************************************************************************
  Calibrat : Calibrat routine
*******************************************************************************/
void Calibrat(u8 Channel)
{ 
  s8  Ma1[10], Mb1[10], Ma3[10], Mb3[10];
  u16 Ma2[10], Mb2[10], i, j;
  s16 TmpA, TmpB;
  u8  Range, n[10], k, m, Step;
  
  Key_Buffer = 0; 
  __Set(STANDBY, DN);                                   // 退出省电状态
  __Set(BACKLIGHT, 10*(Title[BK_LIGHT][CLASS].Value+1));
  __Clear_Screen(BLACK);                                // 清屏幕
  
  Interlace = 0;
  __Set(ADC_MODE, SEPARATE);                            // Set Separate mode
  __Set(ADC_CTRL, EN);       
  __Set(TRIGG_MODE, UNCONDITION);                       // 设任意触发
  _Status = RUN;
  __Set(BEEP_VOLUME, 5*(Title[VOLUME][CLASS].Value-1)); // Reload volume
  Beep_mS = 500;                                        // 蜂鸣器响500mS
  Range = 0;
  Step  = 0;
  m     = 0;
  
  __Set(T_BASE_PSC, X_Attr[_100uS].PSC);                // T_BASE = 100uS
  __Set(T_BASE_ARR, X_Attr[_100uS].ARR);

  __Set(CH_A_COUPLE, DC);
  __Set(CH_B_COUPLE, DC);
  
  for(j=0; j<220; j+=20){                               // 画表格  
    for(i=0; i<399; i++){
      __Point_SCR(i, j);
      __LCD_SetPixl(WHT);
    }
  }
  for(i=0; i<399; i++){
    __Point_SCR(i, 239);
    __LCD_SetPixl(WHT);
  }
  __Point_SCR(  0,  0);
  for(j= 0; j<239; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR( 44, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR( 88, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(132, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(200, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(244, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(288, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(332, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(398, 0);
  for(j= 0; j<239; j++)  __LCD_SetPixl(WHT); 
 
  Print_Str(  6, 185, 0x0005, PRN, "CH_A");              // 显示表格标题栏
  Print_Str( 49, 185, 0x0005, PRN, "ZERO");
  Print_Str( 93, 185, 0x0005, PRN, "DIFF");
  Print_Str(137, 185, 0x0005, PRN, "VOLTAGE");
  Print_Str(206, 185, 0x0105, PRN, "CH_B");
  Print_Str(249, 185, 0x0105, PRN, "ZERO");
  Print_Str(293, 185, 0x0105, PRN, "DIFF");
  Print_Str(338, 185, 0x0105, PRN, "VOLTAGE");
    
  for(i=0; i<=G_Attr[0].Yp_Max; i++){
    Print_Str(  6, 166-(i*20), 0x0005, PRN, Y_Attr[i].STR); // 显示量程
    Print_Str(206, 166-(i*20), 0x0105, PRN, Y_Attr[i].STR);
    Ma1[i] = Ka1[i];  Ma2[i] = Ka2[i];  Ma3[i] = Ka3[i];    // 备份校准前的参数
    Mb1[i] = Kb1[i];  Mb2[i] = Kb2[i];  Mb3[i] = Kb3[i];
  }

  while (1){
    if(PD_Cnt == 0){
      __Set(BACKLIGHT, 0);                               // 关闭背光
      __Set(STANDBY, EN);                                // 进入省电状态
      return;
    }
    __Set(CH_A_RANGE, Range);  __Set(CH_B_RANGE, Range);
    Delayms(20); 
    __Set(FIFO_CLR, W_PTR);
    Delayms(20); 
    a_Avg = 2048;  b_Avg = 2048;               
    for(i=0; i <4096; i++){
      DataBuf[i] = __Read_FIFO();         // 读入32位FIFO数据
      a_Avg += (DataBuf[i] & 0xFF );      // 累计直流平均值                
      b_Avg += ((DataBuf[i]>>8) & 0xFF );              
    }
    TmpA  = Ka1[Range] +(Ka2[Range]*(a_Avg/4096)+ 512)/1024;
    TmpB  = Kb1[Range] +(Kb2[Range]*(b_Avg/4096)+ 512)/1024;

    if(Blink){ 
      Blink = 0;
      switch (Step){  
      case 0:
        Range = 0;
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])*40 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])*40 + 512)/1024);
        Print_Str(   8, 216, 0x0305, PRN,   "        PLEASE CONNECT");
        Print_Str(29*8, 216, 0x0305, PRN,   "INPUT TO ");
        Print_Str(38*8, 216, 0x0405, PRN,   "GND      ");
        Print_Str(   8,   6, 0x0305, PRN,   "   PRESS   KEY TO CONFIRM THE INPUT VOLTAGE   ");
        Print_Str(10*8,   6, 0x0405, Twink, " ");
        if(Channel == TRACK1){
          Print_Str( 23*8, 216, 0x0005, PRN, " CH_A ");
          for(i=0; i<=G_Attr[0].Yp_Max; i++){
            Ka1[i] = 0; Ka2[i] = 1024; Ka3[i] = 0;         // 设置校准参数初值
          }
        }
        if(Channel == TRACK2){
          Print_Str( 23*8, 216, 0x0105, PRN, " CH_B ");
          for(i=0; i<=G_Attr[0].Yp_Max; i++){
            Kb1[i] = 0; Kb2[i] = 1024; Kb3[i] = 0;         // 设置校准参数初值
          }
        }
        break;
      case 1:
        Print_Str(   8,   6, 0x0305, PRN,   "   AUTOMATIC CALIBRATION IN PROGRESS...       ");
        if(Channel == TRACK1){
          s8ToPercen(n, TmpA - 40);
          Print_Str( 45, 166-(Range*20), 0x0005, INV, n);
          Ka1[Range] -= TmpA - 40; 
        } 
        if(Channel == TRACK2){
          s8ToPercen(n, TmpB - 40);
          Print_Str(245, 166-(Range*20), 0x0105, INV, n);
          Kb1[Range] -= TmpB - 40; 
        }
        Range++;
        if(Range > G_Attr[0].Yp_Max){ 
          Range = 0;  Step++;
        } 
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])*40 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])*40 + 512)/1024);
        k = 0;
        break;
      case 2:
        k++;
        if(k >= 8) k = 0;
        if(Channel == TRACK1){
          s8ToPercen(n, TmpA - 40);
          Print_Str( 45, 166-(Range*20), 0x0005, PRN, n);
          if(TmpA - 40 != 0)  Ka1[Range] -= TmpA - 40;
          else                k = 0;           
        } 
        if(Channel == TRACK2){
          s8ToPercen(n, TmpB - 40);
          Print_Str(245, 166-(Range*20), 0x0105, PRN, n);
          if(TmpB - 40 != 0)  Kb1[Range] -= TmpB - 40;
          else                k = 0; 
        }
        if(k == 0)  Range++;
        if(Range > G_Attr[0].Yp_Max){ 
          Range = 0;  Step++;
        } 
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])*40 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])*40 + 512)/1024);
        break;
      case 3:
        k++;
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])*160 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])*160 + 512)/1024);
        if((Channel == TRACK1)&&(TmpA > 140))  Step++;
        if((Channel == TRACK2)&&(TmpB > 140))  Step++;
        if(k > 20)  Step++;
        break;
      case 4:
        k = 0;
        if(Channel == TRACK1){
          s8ToPercen(n, TmpA - 160);
          Print_Str( 89, 166-(Range*20), 0x0005, INV, n);
          Ka3[Range] -= (1024*(TmpA-160)+80)/160;
        } 
        if(Channel == TRACK2){
          s8ToPercen(n, TmpB - 160);
          Print_Str(289, 166-(Range*20), 0x0105, INV, n);
          Kb3[Range] -= (1024*(TmpB-160)+80)/160;
        }
        Range++;
        if(Range > G_Attr[0].Yp_Max){ 
          Range = 0;  Step++;
        } 
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])* 160 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])* 160 + 512)/1024);
        break;
      case 5:
        k++;
        if(k >= 8) k = 0;
        if(Channel == TRACK1){
          s8ToPercen(n, TmpA - 160);
          Print_Str( 89, 166-(Range*20), 0x0005, PRN, n);
          if(TmpA - 160 != 0) Ka3[Range] -= (1024*(TmpA-160)+80)/160;
          else                k = 0;           
        } 
        if(Channel == TRACK2){
          s8ToPercen(n, TmpB - 160);
          Print_Str(289, 166-(Range*20), 0x0105, PRN, n);
          if(TmpB - 160 != 0) Kb3[Range] -= (1024*(TmpB-160)+80)/160;
          else                k = 0; 
        }
        if(k == 0)  Range++;
        if(Range > G_Attr[0].Yp_Max){ 
          Range = 0;  Step++;
        } 
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])* 160 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])* 160 + 512)/1024);
        break;
      case 6:
        k++;
        if(k > 20)  Step++;
        Range = 0;
        if(m < 2){
          __Set(CH_A_OFFSET, ((1024+Ka3[Range])*40 + 512)/1024);
          __Set(CH_B_OFFSET, ((1024+Kb3[Range])*40 + 512)/1024);
          if((Channel == TRACK1)&&(TmpA < 50)){
            Step = 1;
            m++;
          }
          if((Channel == TRACK2)&&(TmpB < 50)){
            Step = 1;
            m++;
          }
        } else {
          __Set(CH_A_OFFSET, ((1024+Ka3[Range])* 25 + 512)/1024);
          __Set(CH_B_OFFSET, ((1024+Kb3[Range])* 25 + 512)/1024);
          if((Channel == TRACK1)&&(TmpA < 55))  Step++;
          if((Channel == TRACK2)&&(TmpB < 55))  Step++;
        }
        break;
      case 7:
        Print_Str( 4*8, 216, 0x0305, PRN,   " INPUT ");
        Print_Str(11*8, 216, 0x0405, Twink, (u8*)VS_STR[Range]);
        Print_Str(20*8, 216, 0x0305, PRN,   " STANDARD VOLTAGE TO ");
        Print_Str(   8,   6, 0x0305, PRN,   "MODIFY VOLTAGE:   ...    ");
        Print_Str(18*8,   6, 0x0405, Twink, "-");
        Print_Str(22*8,   6, 0x0405, Twink, "+");
        Print_Str(27*8,   6, 0x0305, PRN,   "SELECT RANGE:   ---   ");
        Print_Str(42*8,   6, 0x0405, Twink, "<");
        Print_Str(46*8,   6, 0x0405, Twink, ">");
        if(Channel == TRACK1){
          if(TmpA > 35){
            Int2Str(n, (TmpA - 25)* Y_Attr[Range].SCALE, V_UNIT, 3, SIGN);
          } else {
            Int2Str(n, 0, V_UNIT, 3, SIGN);
          }
          Print_Str( 134, 166-(Range*20), 0x0005, Twink, n);
          Print_Str(41*8, 216,            0x0005, PRN,   "CH_A  ");
        } 
        if(Channel == TRACK2){
          if(TmpB > 35){
            Int2Str(n, (TmpB - 25)* Y_Attr[Range].SCALE, V_UNIT, 3, SIGN);
          } else {
            Int2Str(n, 0, V_UNIT, 3, SIGN);
          }
          Print_Str( 334, 166-(Range*20), 0x0105, Twink, n);
          Print_Str(41*8, 216,            0x0105, PRN,   "CH_B  ");
        }
        break;
      case 8:                             //"    PRESS   ---   TO SELECT THE NEXT OPERATION"
        m = 0;
        Print_Str(   8,   6, 0x0305, PRN,   "    PRESS   ---  ");
        Print_Str(12*8,   6, 0x0405, Twink, "<");
        Print_Str(16*8,   6, 0x0405, Twink, ">");
        Print_Str(17*8,   6, 0x0305, PRN,   " TO SELECT THE NEXT OPERATION   ");
        Print_Str(   8, 216, 0x0305, PRN,   "  PRESS   TO ");
        Print_Str(14*8, 216, 0x0405, PRN,   "CONFIRM THE RE-CALIBRATION ");
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        if(Channel == TRACK1)  Print_Str(41*8, 216, 0x0005, PRN, "CH_A "); 
        if(Channel == TRACK2)  Print_Str(41*8, 216, 0x0105, PRN, "CH_B ");
        break;                            //"  PRESS   TO CONFIRM THE RE-CALIBRATION CH_A  "
      case 9:                             //             "SELECT THE CALIBRATION CH_A      "
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        Print_Str(14*8, 216, 0x0405, PRN,   "SELECT THE CALIBRATION ");
        if(Channel == TRACK1)  Print_Str(37*8, 216, 0x0105, PRN, "CH_B     "); 
        if(Channel == TRACK2)  Print_Str(37*8, 216, 0x0005, PRN, "CH_A     ");
        break;
      case 10:                            //             "Exit WITHOUT SAVE RESULTS        "
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        Print_Str(14*8, 216, 0x0405, PRN,   "Exit WITHOUT SAVE RESULTS        ");
        break;
      case 11:                            //             "Exit AND SAVE CALIBRATION RESULTS"
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        Print_Str(14*8, 216, 0x0405, PRN,   "Exit AND SAVE CALIBRATION RESULTS");
        break;
      case 12:                            //             "Exit AND RESTORE SYSTEM DEFAULTS "
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        Print_Str(14*8, 216, 0x0405, PRN,   "Exit AND RESTORE SYSTEM DEFAULTS ");
        break;
      }
    }
    if(Key_Buffer){ 
      PD_Cnt = 600;                               // 重新设定等待时间600秒
      if((Range <= G_Attr[0].Yp_Max)&&(Step == 7)){
        if(Channel == TRACK1){
          Print_Str(134, 166-(Range*20), 0x0005, PRN, n);
        }
        if(Channel == TRACK2){
          Print_Str(334, 166-(Range*20), 0x0105, PRN, n);
        }
      } 
      switch (Key_Buffer){  
      case KEY2:
        if(Step == 0)  Step++;
        if((Step == 8)||(Step == 9)){
          if(Step == 9) Channel = 1 - Channel;
          for(i=0; i<=G_Attr[0].Yp_Max; i++){
            if(Channel == TRACK1){
              Print_Str( 45, 166-(i*20), 0x0005, PRN, "     ");   
              Print_Str( 89, 166-(i*20), 0x0005, PRN, "     ");   
              Print_Str(134, 166-(i*20), 0x0005, PRN, "       ");  
            }
            if(Channel == TRACK2){
              Print_Str(245, 166-(i*20), 0x0105, PRN, "     ");
              Print_Str(289, 166-(i*20), 0x0105, PRN, "     ");
              Print_Str(334, 166-(i*20), 0x0105, PRN, "       ");
            }
          }
          Step = 0;; 
        } 
        if(Step >= 10){
          if(Step == 10){
            for(i=0; i<=G_Attr[0].Yp_Max; i++){
              Ka1[i] = Ma1[i];  Ka2[i] = Ma2[i];  Ka3[i] = Ma3[i];
              Kb1[i] = Mb1[i];  Kb2[i] = Mb2[i];  Kb3[i] = Mb3[i];
            }
            Save_Param();                         // 不保存校正后的参数
            Print_Str( 8, 216, 0x0405, PRN, "                                                ");
          } 
          if(Step == 11){
            Save_Param();                         // 保存校正后的参数
            Print_Str( 8, 216, 0x0405, PRN, "          SAVING THE CALIBRATION DATA           ");
          }  
          if(Step == 12){ 
            for(i=0; i<=G_Attr[0].Yp_Max; i++){
              Ka1[i] = 0; Ka2[i] = 1024; Ka3[i] = 0;         // 设置校准参数初值
              Kb1[i] = 0; Kb2[i] = 1024; Kb3[i] = 0;
            }
            Save_Param();  // 清除校准参数,保存缺省值 
            Print_Str( 8, 216, 0x0405, PRN, "       RESTORE DEFAULTS CALIBRATION DATA        ");
          }
          Delayms(1000);                                      
          App_init();
          return;
        }
        break;
      case KEY3:
        break;
      case K_ITEM_DEC:
        if((Step == 7)&&(Range > 0)) Range--;  
        if( Step >= 9)               Step--;
        if( Step == 8)               Step = 12;
        break;
      case K_ITEM_INC:
        if(Step >= 8)  Step++;
        if(Step > 12)  Step = 8;
        if(Step == 7)  Range++;  
        if(Range  > G_Attr[0].Yp_Max){  
          Range = 0;        
          Step++;
        } 
        break;
      case K_INDEX_DEC:
        if(Step == 7){  
          if((Channel == TRACK1)&&(TmpA > 35))  Ka2[Range] -= 2;
          if((Channel == TRACK2)&&(TmpB > 35))  Kb2[Range] -= 2;
        }
        break;
      case K_INDEX_INC:
        if(Step == 7){  
          if((Channel == TRACK1)&&(TmpA > 35))  Ka2[Range] += 2;
          if((Channel == TRACK2)&&(TmpB > 35))  Kb2[Range] += 2;
        }
        break;
      }
      Key_Buffer = 0;
    }
  }
}
Exemplo n.º 24
0
/*******************************************************************************
* 函数名称: boot
* 输入参数: null
* 输出参数: printf information
* --返回值: null
* 函数功能: -- IAP  Ymodem 
* warning:  updata -- updata ing must in Flash high address (0x0001FF04)
*           updata_OK -- updata compelet must in Flash low address (0x00001004)
*******************************************************************************/
void boot(void)
{
    uint8_t j; 
    
    //SysTick_Config(SystemCoreClock/20); 
    __disable_irq();//关闭总中断
    
#ifdef  TEST    
    LED_IO_init(); 
    bFM3_GPIO_PDOR5_P5 = 1;     /* LED off */     
#endif
    
    /* read appointed address value 16 bit  */ 
    /* 0x80(128 byte) if frame isn't 128 byte compensation 0x1A*/
    updata = MFlash_Read16bit ((uint16_t*)0x0001FF84);    
    updata_OK = MFlash_Read16bit ((uint16_t*)0x0001FFA4);  

#ifdef  TEST    
    bFM3_GPIO_PDOR5_P5 = 0;   /* LED light */
#endif
    
//    Jump_To_app(); 
//    while (1);
    
    /* updata_OK == 0  updata == 0xFFFF stand for updata OK */
	if ( ((0xFFFF==updata) && (0u==updata_OK)) )  
	{
#ifdef  TEST
        bFM3_GPIO_PDOR5_P5 = 0;    /* LED4 light */
        Delay_ms(1000u); //test
        bFM3_GPIO_PDOR5_P5 = 1; 
        Delay_ms(1000u); //test
#endif          
        
        Jump_To_app();  /* updata image complete, jump application routine */
        
	}
	else  /* updata is not complete, need to updta image */
    {
        UART_Port_init();                        /* UART IO init */             
        UARTConfigMode(&tUARTModeConfigT);       /* UART setup */   
        UARTPollTX_string("\n\n\rbootloader begin!!!\r\n");
        
        while (1)
		{
			//UARTPollTX_string("Waiting for the file to be sent ... (press 'C' to abort)\r\n");
            UARTPollTX_string("1...\r\n");
            
            MFS_UARTEnableRX(InUseCh);
            MFS_UARTEnableTX(InUseCh);
            
            Size = Ymodem_Receive(&tab_128[0u]);
			if (Size > 0)
			{
				UARTPollTX_string("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
				UARTPollTX_string(FileName);
				Int2Str(Number, Size);
				UARTPollTX_string("\n\r Size: ");
				UARTPollTX_string(Number);
				UARTPollTX_string(" Bytes\r\n");
				UARTPollTX_string("--------------------------------\n");
                 
                //write appointed address value  updata OK flag
                MFlash_Write((uint16_t*) 0x0001FFA4,(uint32_t) 0x00000000);  /* 必须强制转换 写 32bit */

                
				NVIC_SystemReset();  /* system reset, also soft reset */
				while(1);            
			}
			else if (Size == -1)
			{
				UARTPollTX_string("\n\n\rThe image size is higher than the allowed space memory!\n\r");
                break;
			}
			else if (Size == -2)
			{
				UARTPollTX_string("\n\n\rVerification failed!\n\r");
                break;
			}
			else if (Size == -3)
			{
				UARTPollTX_string("\r\n\nAborted by user.\n\r");
                break;
			}
			else    /* SecureCRT  Ctrl + C  CAN , Size = 0 */
			{
				UARTPollTX_string("\n\rFailed to receive the file!\n\r");
                break;
			}
		}//end while
        
    }//end if 
    
#ifdef  TEST  
    for (j=0; j<5; j++)
    {
        bFM3_GPIO_PDOR5_P5 = 0;    /* LED4 light */
        Delay_ms(1000u); //test
        bFM3_GPIO_PDOR5_P5 = 1; 
        Delay_ms(1000u); //test
    }    
    
#endif    
    
    NVIC_SystemReset();          /* system reset, also soft reset */  /*  */
    
    while(1);                   /* routine fatal error */
}
Exemplo n.º 25
0
	BOOST_FOREACH(uint32 val, uList)
	{
		des += Int2Str(val);
		des += CONST_SEP;
	}
Exemplo n.º 26
0
/* property notify check
* description: check update of all properties in notify list, 
*              if notify list is not created, create is first from service_table.
* input: mico context;
*        service table
* output: json object contains properties updated, like {k:v, k:v}
*         if no update or error, return NULL
* return: kNoErr if succeed.
*/
OSStatus mico_properties_notify_check(mico_Context_t * const inContext, struct mico_service_t *service_table,
                                      json_object* notify_obj)
{
  OSStatus err = kNoErr;
  int s_idx = 0; 
  int p_idx = 0;
  int iid = 0;
  char iid_str[16] = {0};
  int ret = 0;
  mico_prop_notify_node_t *_notify_list = NULL;
  
  require_action(inContext, exit, err = kParamErr);
  require_action(service_table, exit, err = kParamErr);
  require_action(notify_obj, exit, err = kParamErr);
  
  //properties_log("properties update check...");
  
  // if notify list not created, create it the first time
  if(!notify_list_inited){
    if(NULL != g_notify_list){
      PropertyNotifyListClean(&g_notify_list);  // clean g_notify_list  
    }
    err = create_notify_list(service_table, &g_notify_list);
    require_noerr(err, exit);
    notify_list_inited = true;
  }
  
  _notify_list = g_notify_list;
  // search notify list
  while(getNextNotify(_notify_list, &iid, &s_idx, &p_idx, &_notify_list) == kNoErr){
    //properties_log("notify prop check: iid=%d, s_idx=%d, p_idx=%d.", iid, s_idx, p_idx);
    // get key string
    memset((void*)iid_str, '\0', sizeof(iid_str));
    Int2Str((uint8_t*)iid_str, iid);
    
    // add updated property to json object
    if((NULL != service_table[s_idx].properties[p_idx].event) &&
       (*(service_table[s_idx].properties[p_idx].event)) ){  // prop event enable
         // do prop update check && update prop value && len
         ret = service_table[s_idx].properties[p_idx].notify_check(&(service_table[s_idx].properties[p_idx]), 
                                                                   service_table[s_idx].properties[p_idx].arg, 
                                                                   service_table[s_idx].properties[p_idx].value, 
                                                                   service_table[s_idx].properties[p_idx].value_len);
         if(1 == ret){  // prop updated, add new value to notify json object
           switch(service_table[s_idx].properties[p_idx].format){
           case MICO_PROP_TYPE_INT:{
             json_object_object_add(notify_obj, iid_str, 
                                    json_object_new_int(*((int*)(service_table[s_idx].properties[p_idx].value))));
             break;
           }
           case MICO_PROP_TYPE_FLOAT:{
             json_object_object_add(notify_obj, iid_str, 
                                    json_object_new_double(*((float*)service_table[s_idx].properties[p_idx].value)));
             break;
           }
           case MICO_PROP_TYPE_STRING:{
             json_object_object_add(notify_obj, iid_str, 
                                    json_object_new_string((char*)service_table[s_idx].properties[p_idx].value));
             break;
           }
           case MICO_PROP_TYPE_BOOL:{
             json_object_object_add(notify_obj, iid_str, 
                                    json_object_new_boolean(*((bool*)service_table[s_idx].properties[p_idx].value)));
             break;
           }
           default:
             properties_log("ERROR: prop format unsupport!");
             break;
           }
         }
       }
  }
  
exit:
  return err;
}
Exemplo n.º 27
0
/*******************************************************************************
* 函数名称: refresh_flash
* 输入参数: 
* 输出参数: 
* --返回值: 
* 函数功能: --
*******************************************************************************/
static void refresh_flash(void)
{
    uint8_t Number[10] = "          ";
    int32_t Size = 0;
    
    MFS_UARTSWRst(UartUSBCh);  //reset UART
    UARTConfigMode(UartUSBCh, &tUARTModeConfigT);
    MFS_UARTEnableTX(UartUSBCh);
    MFS_UARTEnableRX(UartUSBCh);
    
    SerialPutString("Waiting for the file to be sent ...\n\r");
    Size = Ymodem_Receive(&tab_1024[0]);
    
//    MFS_UARTDisableRX(UartUSBCh);
//    MFS_UARTDisableTX(UartUSBCh);
    
    if (Size > 0)
    {
        SerialPutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
        SerialPutString(file_name);
        Int2Str(Number, Size);
        SerialPutString("\n\r Size: ");
        SerialPutString(Number);
        SerialPutString(" Bytes\r\n");
        SerialPutString("--------------------------------\r\n");
        
        //oneSound(10,0);
        
        /* read extern Flash(MX25L4006) verify image */
//#define  TEST_IMAGE
#ifdef   TEST_IMAGE     
        uint32_t i = 0;
        uint32_t j = ApplicationAddress; 
        memset(&tab_1024[0], 0, PACKET_SIZE);
        for (i=0u; i<1056; i++) /* (132*1024)/128 0-32 sector */
        {
            MX25L3206_Read((uint8_t *)tab_1024, j, PACKET_SIZE);
            j += PACKET_SIZE;
            printHex(tab_1024,PACKET_SIZE);
        }          
#endif        
        /* check CRC32 */
        //...
        /* updata image complete, jump application routine */
        //Jump_To_app();  
        //while (1);  
    }
    else if (Size == -1)
    {
        SerialPutString("\n\n\rThe image size is higher than the allowed space memory!\n\r");
    }
    else if (Size == -2)
    {
        SerialPutString("\n\n\rVerification failed!\n\r");
    }
    else if (Size == -3)
    {
        SerialPutString("\r\n\nAborted by user.\n\r");
    }
    else
    {
        SerialPutString("\n\rFailed to receive the file!\n\r");
    }/* end if (Size > 0) Ymodem Rev */
    
    if (Size > 0)
    {
        oneSound(10,0);
    }
    else
    {
        oneSound(10, 300);  /* BUZZER 201 error buzz */
    }    
    
    bFM3_GPIO_PDOR0_PD = 1u; /* LED 201 light off */
    bFM3_GPIO_PDOR0_PC = 1u; /* LED 202 light off */
}
Exemplo n.º 28
0
// add the following commands, leave other commands, if they make sense
// 1) print performance measures 
//    time-jitter, number of data points lost, number of calculations performed
//    i.e., NumSamples, NumCreated, MaxJitter-MinJitter, DataLost, FilterWork, PIDwork
//*****************************************************************************
//
// Interpret input from the terminal. Supported functions include
// addition, subtraction, division, and multiplication in the post-fix format.
//
// \param nextChar specifies the next character to be put in the global buffer
//
// \return none.
//
//*****************************************************************************
void
OS_Interpret(unsigned char nextChar)
{
  char operator = Buffer[BufferPt - 2];
  char * token;
  char * last;
  char string[10];
  int a;
  long total = 0;
  short first = 1;
  short command, equation = 0; 
  switch(nextChar)
  {
    case '\b':
     if(BufferPt != 0)
	 {
	   BufferPt--;
	   Buffer[BufferPt] = '\0';
	 }
     break;
    case '=':
     FirstSpace = 1;
     Buffer[BufferPt] = '=';
     equation = 1;
     break;
    case '\r':
     command = 1;
	 //Buffer[BufferPt] = ' ';
     break;
    default:
     Buffer[BufferPt] = nextChar;
     BufferPt++;
     break;
  }

  if(equation == 1)
  {  
    switch(operator)
    {
      case '+':
        for ( token = strtok_r(Buffer, " ", &last); token; token = strtok_r(NULL , " ", &last) )
        {
          total = total + atoi(token);
        }
        Int2Str(total, string);
        OSuart_OutString(UART0_BASE, string);
        OSuart_OutString(UART0_BASE, "\r\n");
        break;  
          
        case '-':
        for ( token = strtok_r(Buffer, " ", &last); token; token = strtok_r(NULL , " ", &last) )
        {
          if(first)
          {
            total = atoi(token);
            first = 0;
          }
          else
          {
            total = total - atoi(token);
          }
        }
        Int2Str(total, string);
		OSuart_OutString(UART0_BASE, string);
        OSuart_OutString(UART0_BASE, "\r\n");
        break;
      
      case '*':
        for ( token = strtok_r(Buffer, " ", &last); token; token = strtok_r(NULL , " ", &last) )
        {
          if(first)
          {
            total = atoi(token);
            first = 0;
          }
          else
          {
            if(atoi(token) != 0)
            {
              total = total * atoi(token);
            }
          }
        }
        Int2Str(total, string);
		OSuart_OutString(UART0_BASE, string);
        OSuart_OutString(UART0_BASE, "\r\n");
        break;
      
      case '/':
        for ( token = strtok_r(Buffer, " ", &last); token; token = strtok_r(NULL , " ", &last) )
        {
          if(first)
          {
            total = atoi(token);
            first = 0;
          }
          else
          {
            if(atoi(token) != 0)
            {
              total = total / atoi(token);
            }
          }
        }
        Int2Str(total, string);
        OSuart_OutString(UART0_BASE, string);
        OSuart_OutString(UART0_BASE, "\r\n");
        break;
      
      case 't':
        Int2Str(OS_Time(), string);
        OSuart_OutString(UART0_BASE, string);
        OSuart_OutString(UART0_BASE, "\r\n");
        break;

      case 'j':
	    break;
	      
      
      default:
        break;
        
    }
	equation = 0;
    BufferPt = 0;
	memset(Buffer,'\0',100);
  }
  if(command == 1)
  {
    // Interpret all of the commands in the line
	//    time-jitter, number of data points lost, number of calculations performed
    //    i.e., NumSamples, NumCreated, MaxJitter-MinJitter, DataLost, FilterWork, PIDwork
    for ( token = strtok_r(Buffer, " ", &last); token; token = strtok_r(NULL , " ", &last) )
    {
	   //strcat(token, "\");
	   //string = "PIDWork";
	   // Display the number of samples
	   /*a = strcasecmp(token, "PIDWork");
	   Int2Str(a, string);
	   OSuart_OutString(UART0_BASE, string);*/
	   if(strcasecmp(token, "NumSamples") == 0)
	   {	 
		 Int2Str(NumSamples, string);
		 OSuart_OutString(UART0_BASE, " ="); 
		 OSuart_OutString(UART0_BASE, string);	
	   }

	   // Display number of samples created
	   if(strcasecmp(token, "NumCreated") == 0)
	   {	 
		 Int2Str(NumCreated, string); 
		 OSuart_OutString(UART0_BASE, " =");
		 OSuart_OutString(UART0_BASE, string);	
	   }

	   // Displays delta jitter
	   if(strcasecmp(token, "MaxJitter-MinJitter") == 0)
	   {	 
		 Int2Str(MaxJitter-MinJitter, string);
		 OSuart_OutString(UART0_BASE, " =");
		 OSuart_OutString(UART0_BASE, string);	
	   }
	   
	   // Display the amount of data lost
	   if(strcasecmp(token, "DataLost") == 0)
	   {	 
		 Int2Str(DataLost, string);
		 OSuart_OutString(UART0_BASE, " =");
		 OSuart_OutString(UART0_BASE, string);	
	   }

	   // Display the variable FilterWork
	   if(strcasecmp(token, "FilterWork") == 0)
	   {	 
		 Int2Str(FilterWork, string);
		 OSuart_OutString(UART0_BASE, " =");
		 OSuart_OutString(UART0_BASE, string);	
	   }

	   // Display the variable PIDWork
	   if(strcasecmp(token, "PIDWork") == 0)
	   {	 
		 Int2Str(PIDWork, string);
		 OSuart_OutString(UART0_BASE, " =");
		 OSuart_OutString(UART0_BASE, string);	
	   } 
    }
	command = 0; 
  	BufferPt = 0;
	memset(Buffer,'\0',100);
    OSuart_OutString(UART0_BASE, "\r\n");
  }
}  
Exemplo n.º 29
0
int main1(void){
  UINT8             IsDHCP = 0;
  _NetCfgIpV4Args_t ipV4;
  SlSockAddrIn_t    Addr;
  UINT16            AddrSize = 0;
  INT16             SockID = 0;
  INT16             Status = 1;  // ok
  UINT32            data;
  unsigned char     len = sizeof(_NetCfgIpV4Args_t);
  stopWDT();        // Stop WDT 
  initClk();        // PLL 50 MHz, ADC needs PPL active
  Board_Init();     // initialize LaunchPad I/O 
  ConfigureUART();  // Initialize the UART.
  UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
#if ADC
  ADC0_InitSWTriggerSeq3(7);  // Ain7 is on PD0
  UARTprintf("This node is configured to measure signals from Ain7=PD0\n");
#endif
#if EKG
  UARTprintf("This node is configured to generate simulated EKG data\n");
#endif
  UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
  while(1){
    sl_Start(0, 0, 0);/* Initializing the CC3100 device */
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();   // connect to AP
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    while(Status > 0){
      Addr.sin_family = SL_AF_INET;
      Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
      Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
      AddrSize = sizeof(SlSockAddrIn_t);
      SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
      if( SockID < 0 ){
        UARTprintf("SockIDerror ");
        Status = -1; // error
      }else{
        while(Status>0){
          UARTprintf("\nSending a UDP packet ...");
          uBuf[0] = ATYPE;   // defines this as an analog data type
          uBuf[1] = '='; 
#if ADC
          data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0
#endif
#if EKG
          data = EKGbuf[EKGindex];
          EKGindex = (EKGindex+1)%EKGSIZE; // 100 Hz
#endif
          Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number
          UARTprintf(" %s ",uBuf);
          LED_Toggle();
          Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0,
                           (SlSockAddr_t *)&Addr, AddrSize);
          ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 80ms
          if( Status <= 0 ){
            UARTprintf("SockIDerror %d ",Status);
          }else{
           UARTprintf("ok");
          }     
        }
        sl_Close(SockID);
      }
    }
  }
}