nios ii 中 ‘ALT_CPU_FREQ‘ could not be resolved的分析和解决办法

在altera fpga中使用逻辑搭建的nios ii系统中,编写uart的时候出现如下错误:

Description Resource Path Location Type

Symbol 'ALT_CPU_FREQ' could not be resolved Uart.c /F31/BaseModule/Src line 85 Semantic Error

**分析:**报错是 Symbol 'ALT_CPU_FREQ' could not be resolved,说明编译器找不到标识符 ALT_CPU_FREQ 的定义 / 声明,简单说就是编译器不认识这个符号。

在header.h文件中添加 #include "Uart.h"

将头文件 header.h文件放到Uart.c的顶部,报错问题自动消失

下边是Uart的代码,有需要的可以自取

/*

  • Uart.c
  • Created on: 2022-5-12
复制代码
   Author: luo

*/

#include "Uart.h"

//#include "header.h"

//函数:发送一个字节

unsigned char UartTxByte(UART_ST * TARGET_UART, unsigned char l_u8ToTxByte)

{

unsigned int l_u32TimeWait;

复制代码
TARGET_UART->TXDATA.BITS.TRANSMIT_DATA = l_u8ToTxByte;

l_u32TimeWait = 0;
while(TARGET_UART->STATUS.BITS.TRDY == 0)
{
	l_u32TimeWait++;
	if(l_u32TimeWait >= 100000)
	{
		return 1;
	}
}

return 0;

}

//函数:发送多个字节

unsigned char UartTxBuf(UART_ST * TARGET_UART, unsigned int l_u32ToTxLen, unsigned char *p_u8ToTxBuf)

{

unsigned char l_u8Ret;

unsigned int i;

复制代码
if(l_u32ToTxLen == 0)
{
	return 1;
}

for(i=0; i<l_u32ToTxLen; i++)
{
	l_u8Ret = UartTxByte(TARGET_UART, p_u8ToTxBuf[i]);
	if(l_u8Ret != 0)
	{
		return l_u8Ret;
	}
}

return 0;

}

//设置接收中断状态

unsigned char UartSetRxIrqState(UART_ST * TARGET_UART, unsigned char l_u8State)

{

if((l_u8State != UART_RX_IRQ_DISABLE) && (l_u8State != UART_RX_IRQ_ENABLE))

{

return 1;

}

复制代码
TARGET_UART->CONTROL.BITS.IRRDY = l_u8State;

return 0;

}

//读取接收字节

unsigned char UartGetRxData(UART_ST * TARGET_UART)

{

return (TARGET_UART->RXDATA.BITS.RECEIVE_DATA);

}

//函数:设置波特率

unsigned char UartSetBaudrate(UART_ST * TARGET_UART, unsigned int l_u32BaudRate)

{

if(l_u32BaudRate < 9600)

{

return 1;

}

复制代码
//根据手册设置
TARGET_UART->DIVISOR.BITS.BAUD_RATE_DIVISOR = (unsigned int)(ALT_CPU_FREQ/l_u32BaudRate+0.5);

return 0;

}

相关推荐
LDR00613 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
坏孩子的诺亚方舟13 天前
FPGA系统架构设计实践15_高云Arora V系列时钟体系
fpga开发·系统架构
Luminous.13 天前
C语言--day30
c语言·开发语言
玖玥拾13 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
謓泽13 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言
不会C语言的男孩13 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言
2601_9516438813 天前
C语言长文整理,关键字和数据类型
c语言·数据类型·关键字·嵌入式开发·格式化输出
m0_5474866613 天前
《C#语言程序设计与实践》 全套PPT课件
c语言·c#·c语言程序设计
✎ ﹏梦醒͜ღ҉繁华落℘13 天前
编程基础 --高内聚,低耦合
c语言·单片机
FPGA小徐13 天前
入门 CNN 结构全解析|从流程图理论到 FPGA Verilog 硬件实现(含习题带讲解)
fpga开发