lowlevel_init.S注解

本文详细介绍了SDRAM在ARM平台上的初始化过程,包括寄存器配置、时序参数设定及刷新机制等关键步骤,并针对特定型号的SDRAM芯片进行了具体实例说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <config.h>
#include <version.h>

 

/* some parameters for the board */
 
/*
 *
 * Taken from linux/arch/arm/boot/compressed/head-s3c2410.S
 *
 * Copyright (C) 2002 Samsung Electronics SW.LEE  < hitchcar@sec.samsung.com>
 *
 */
@我的开发板上的SDRAM为:HY57V561620FTP-H,4Mx16bitx4Banks,两片接成32bit,64MB,接在BANK6上,地址范围为:[0x30000000-0x33ffffff]
@(还没搞清楚SDRAM的结构,为什么要分成Banks,改天看下相关的文档研究一下)
@对于SDRAM的初始化是要配置13个寄存器,好像多采用循环方式。
 
#define BWSCON 0x48000000
@BWSCON寄存器地址,控制每个总线
 
/* BWSCON */
#define DW8   (0x0)
#define DW16   (0x1)
#define DW32   (0x2)
@将用来设置位宽的三个宏
#define WAIT   (0x1<<2)
#define UBLB   (0x1<<3)
@将用来设置wait和ublb的宏
 
#define B1_BWSCON  (DW32)
#define B2_BWSCON  (DW16)
#define B3_BWSCON  (DW16 + WAIT + UBLB)
#define B4_BWSCON  (DW16)
#define B5_BWSCON  (DW16)
@BANK2、BANK3、BANK4、BANK5为什么配成16bit总线宽度,而且BANK3还要加上WAIT和UBLB属性没有搞明白,感觉如果没用到的话可以配成默认值的吧?
#define B6_BWSCON  (DW32)
#define B7_BWSCON  (DW32)
@我板子的SDRAM接在BANK6,所以配成32bit位宽,BANK7按datasheet的要求配置的和BANK6相同
 
@分别配置每个BANK的BANKCON寄存器,这里应该根据SRAM的手册来配置相应的BANK,BANK0~5主要是配置一些时序参数
/* BANK0CON */
#define B0_Tacs   0x0 /*  0clk */
#define B0_Tcos   0x0 /*  0clk */
#define B0_Tacc   0x7 /* 14clk */
#define B0_Tcoh   0x0 /*  0clk */
#define B0_Tah   0x0 /*  0clk */
#define B0_Tacp   0x0
#define B0_PMC   0x0 /* normal */
 
/* BANK1CON */
#define B1_Tacs   0x0 /*  0clk */
#define B1_Tcos   0x0 /*  0clk */
#define B1_Tacc   0x7 /* 14clk */
#define B1_Tcoh   0x0 /*  0clk */
#define B1_Tah   0x0 /*  0clk */
#define B1_Tacp   0x0
#define B1_PMC   0x0
 
#define B2_Tacs   0x0
#define B2_Tcos   0x0
#define B2_Tacc   0x7
#define B2_Tcoh   0x0
#define B2_Tah   0x0
#define B2_Tacp   0x0
#define B2_PMC   0x0
 
@这里BANK3CON不为默认值,是因为在SMDK2410上BANK3上应该接了ROM
@根据我自己的板子,我把这里换成了默认值(根据vivi上的默认值修改的),不过要不是默认值的话应该也没有影响的吧?我的板子这里接了DM9000A

#define B3_Tacs   0x0 /*  0clk */
#define B3_Tcos   0x3 /*  4clk */
#define B3_Tacc   0x7 /* 14clk */
#define B3_Tcoh   0x1 /*  1clk */
#define B3_Tah   0x0 /*  0clk */
#define B3_Tacp   0x3     /*  6clk */
#define B3_PMC   0x0 /* normal */
 
#define B4_Tacs   0x0 /*  0clk */
#define B4_Tcos   0x0 /*  0clk */
#define B4_Tacc   0x7 /* 14clk */
#define B4_Tcoh   0x0 /*  0clk */
#define B4_Tah   0x0 /*  0clk */
#define B4_Tacp   0x0
#define B4_PMC   0x0 /* normal */
 
#define B5_Tacs   0x0 /*  0clk */
#define B5_Tcos   0x0 /*  0clk */
#define B5_Tacc   0x7 /* 14clk */
#define B5_Tcoh   0x0 /*  0clk */
#define B5_Tah   0x0 /*  0clk */
#define B5_Tacp   0x0
#define B5_PMC   0x0 /* normal */
 
@配置SDRAM的参数,BANK6和BANK7要配置成同样的值,需要查看SDRAM的datasheet
@当内存为ROM或SRAM时需要配置所有位,当为SDRAM时只要配置[0~3]
#define B6_MT   0x3 /* SDRAM */
@内存类型,默认为SDRAM
#define B6_Trcd   0x1
@RAS到CAS的延时
#define B6_SCAN   0x1 /* 9bit */
@列扫描数,在SDRAM手册上,有一句:C0~C8即为9列
 
#define B7_MT   0x3 /* SDRAM */
#define B7_Trcd   0x1 /* 3clk */
#define B7_SCAN   0x1 /* 9bit */
 
/* REFRESH parameter */
@SDRAM刷新参数,这个很重要,移植时要更改
#define REFEN   0x1 /* Refresh enable */
@默认为允许刷新
#define TREFMD   0x0 /* CBR(CAS before RAS)/Auto refresh */
@据说下面三个时间参数多是根据经验来设置
#define Trp   0x0 /* 2clk */
@RAS precharge Time
#define Trc   0x3 /* 7clk */
@根据S3C2440的datasheet为:Trc=Tsrc+Trp,但寄存器中要填入的是Tsrc,这里仿佛应该设为10个时钟才对?
#define Tchr   0x2 /* 3clk */
@SDRAM手册上没有找到这个时钟的定义
#define REFCNT   1113 /* period="15".6us, HCLK="60Mhz", (2048+1-15.6*60) */
@SDRAM刷新计数值,这个值比较重要,根据SDRAM的datasheet,(我使用的这款芯片在datasheet写着8192Refresh cycle/64ms,所以一个刷新周期为64ms/8192=7.8125us,取7.9的话REFCNT的值就为1259)
/**************************************/
 
_TEXT_BASE:
 .word TEXT_BASE
 
@这里开始lowlevel_init函数了,通过循环连续初始化13个寄存器
.globl lowlevel_init
lowlevel_init:
 /* memory control configuration */
 /* make r0 relative the current location so that it */
 /* reads SMRDATA out of FLASH rather than memory ! */
 ldr     r0, =SMRDATA
 ldr r1, _TEXT_BASE
@r1放代码段的开始位置
 sub r0, r0, r1
    //计算SMRDATA的相对地址保存到R0中
    //SMRDATA为虚拟地址,而TEXT_BASE为虚拟地址的起始地址
    //而现在Uboot的起始地址并不为虚拟地址
    //TEXT_BASE为0x33F8 0000,SMRDATA为0x33F8 06C8
    //而现在程序运行在起始地址为0x0000 0000的地方
    //所以需要计算以0x0000 0000为标准的相对地址
(参考uboot-1.3.0-rc3引导启动学习笔记,这一段确实要好好理解)
 ldr r1, =BWSCON /* Bus Width Status Controller */
 add     r2, r0, #13*4
@13个寄存器,每个寄存器占4个字节
@读取一个值存入寄存器中,然后循环,直到读完13个寄存器

0:
 ldr     r3, [r0], #4
 str     r3, [r1], #4
 cmp     r2, r0
 bne     0b
 
 /* everything is fine now */
 mov pc, lr
@程序返回到cpu_init_crit中
 
 .ltorg
/* the literal pools origin */
 
SMRDATA:
    .word (0+(B1_BWSCON<<4)+(B2_BWSCON<<8)+(B3_BWSCON<<12)+(B4_BWSCON<<16)+(B5_BWSCON<<20)+(B6_BWSCON<<24)+(B7_BWSCON<<28))
@设置每个BWSCON,注意BANK0由硬件连线决定了。
    .word ((B0_Tacs<<13)+(B0_Tcos<<11)+(B0_Tacc<<8)+(B0_Tcoh<<6)+(B0_Tah<<4)+(B0_Tacp<<2)+(B0_PMC))
    .word ((B1_Tacs<<13)+(B1_Tcos<<11)+(B1_Tacc<<8)+(B1_Tcoh<<6)+(B1_Tah<<4)+(B1_Tacp<<2)+(B1_PMC))
    .word ((B2_Tacs<<13)+(B2_Tcos<<11)+(B2_Tacc<<8)+(B2_Tcoh<<6)+(B2_Tah<<4)+(B2_Tacp<<2)+(B2_PMC))
    .word ((B3_Tacs<<13)+(B3_Tcos<<11)+(B3_Tacc<<8)+(B3_Tcoh<<6)+(B3_Tah<<4)+(B3_Tacp<<2)+(B3_PMC))
    .word ((B4_Tacs<<13)+(B4_Tcos<<11)+(B4_Tacc<<8)+(B4_Tcoh<<6)+(B4_Tah<<4)+(B4_Tacp<<2)+(B4_PMC))
    .word ((B5_Tacs<<13)+(B5_Tcos<<11)+(B5_Tacc<<8)+(B5_Tcoh<<6)+(B5_Tah<<4)+(B5_Tacp<<2)+(B5_PMC))
@设置BANKCON0~BANKCON5
    .word ((B6_MT<<15)+(B6_Trcd<<2)+(B6_SCAN))
    .word ((B7_MT<<15)+(B7_Trcd<<2)+(B7_SCAN))
@设置BANKCON6~BANKCON7
    .word ((REFEN<<23)+(TREFMD<<22)+(Trp<<20)+(Trc<<18)+(Tchr<<16)+REFCNT)
@设置REFRESH,在S3C2440中11~17位是保留的,也即(Tchr<<16)无意义
    .word 0x32
@设置BANKSIZE,对于容量可以设置大写,多出来的空内存会被自动检测出来。没有搞明白突发模式操作是什么意思!
    .word 0x30
@设置MRSRB6
    .word 0x30
@设置MRSRB7
我应该做的是在E:\AI_System\agent\conscious_system新建conscious_layer.py,写上你给我的内容:“# conscious_layer.py from conscious_framework import ConsciousFramework class ConsciousLayer: def __init__(self, preconscious, memory_system): self.preconscious = preconscious self.memory_system = memory_system self.framework = ConsciousFramework() # 核心认知处理引擎 def process_input(self, stimulus, biological_state): """处理提升到意识层的刺激""" # 使用框架处理输入 result = self.framework.process(stimulus, biological_state) # 将结果存入长期记忆 self.memory_system.store_memory( content=result, category="conscious_processing", associations=stimulus.get("keywords", []) ) return result def deliberate_recall(self, keyword): """主动回忆""" # 使用框架的工作记忆功能 return self.framework.get_working_memory_state() def get_state_report(self): """获取状态报告""" return { "framework": self.framework.get_cognitive_state_report(), "metacognition": self.framework.get_metacognition_report() } def shutdown(self): """安全关闭""" return self.framework.shutdown() ”,然后更改conscious_framework.py写上:“# conscious_framework.py import logging import time import threading from collections import deque from typing import Dict, List, Any, Optional logger = logging.getLogger('ConsciousFramework') class ConsciousFramework: """意识架构 - 高级认知处理层""" def __init__(self, memory_capacity: int = 10, metacognition_interval: float = 5.0): """ 初始化意识框架 参数: memory_capacity: 工作记忆容量 metacognition_interval: 元认知监控间隔(秒) """ # 工作记忆系统 self.working_memory = deque(maxlen=memory_capacity) self.memory_capacity = memory_capacity # 元认知系统 self.metacognition = { "monitoring": False, "interval": metacognition_interval, "last_monitor_time": time.time(), "insights": [] } # 认知状态 self.cognitive_state = { "focus_level": 0.7, # 0.0-1.0 "processing_mode": "analytical", # analytical/intuitive "confidence": 0.8 # 0.0-1.0 } # 启动元认知监控线程 self._start_metacognition_monitor() logger.info(f"意识框架初始化完成,工作记忆容量: {memory_capacity}") def _start_metacognition_monitor(self): """启动元认知监控线程""" self.metacognition["monitoring"] = True self.monitor_thread = threading.Thread(target=self._metacognition_loop, daemon=True) self.monitor_thread.start() logger.info("元认知监控已启动") def _metacognition_loop(self): """元认知监控循环""" while self.metacognition["monitoring"]: current_time = time.time() if current_time - self.metacognition["last_monitor_time"] >= self.metacognition["interval"]: self._perform_metacognition() self.metacognition["last_monitor_time"] = current_time # 检查间隔 time.sleep(0.5) def _perform_metacognition(self): """执行元认知监控""" logger.debug("执行元认知监控...") # 1. 检查工作记忆负荷 memory_load = len(self.working_memory) / self.memory_capacity if memory_load > 0.8: insight = "工作记忆接近饱和,建议优先处理高显著性项目" self.metacognition["insights"].append(insight) logger.warning(insight) # 2. 分析认知状态 if self.cognitive_state["focus_level"] < 0.4: insight = "注意力水平较低,建议调整环境或休息" self.metacognition["insights"].append(insight) logger.warning(insight) # 3. 检查处理模式 if self.cognitive_state["processing_mode"] == "analytical" and self.cognitive_state["confidence"] < 0.5: insight = "分析模式信心不足,建议切换到直觉模式" self.metacognition["insights"].append(insight) logger.info(insight) # 4. 长期监控趋势 if len(self.metacognition["insights"]) > 5: frequent_issue = max(set(self.metacognition["insights"]), key=self.metacognition["insights"].count) logger.info(f"频繁出现的元认知问题: {frequent_issue}") def process(self, input_data: Dict, biological_state: Dict) -> Dict: """ 认知处理流程 参数: input_data: 输入数据字典 biological_state: 生物状态字典 返回: 处理结果字典 """ # 更新认知状态(基于生物状态) self._update_cognitive_state(biological_state) # 认知处理阶段 perception = self._perceive(input_data, biological_state) thought = self._think(perception) action_plan = self._plan_action(thought) # 添加到工作记忆 memory_item = { "perception": perception, "thought": thought, "action_plan": action_plan, "timestamp": time.time(), "salience": perception["salience"] } self._add_to_working_memory(memory_item) # 返回处理结果 return { "perception": perception, "thought": thought, "action_plan": action_plan, "working_memory": self.get_working_memory_state(), "metacognition": self.get_metacognition_report() } def _update_cognitive_state(self, biological_state: Dict): """根据生物状态更新认知状态""" # 感官敏锐度影响注意力 sensor_acuity = biological_state.get("sensor_acuity", 0.7) self.cognitive_state["focus_level"] = min(1.0, sensor_acuity * 1.2) # 疲劳度影响处理模式 fatigue = biological_state.get("fatigue", 0.3) if fatigue > 0.6: self.cognitive_state["processing_mode"] = "intuitive" else: self.cognitive_state["processing_mode"] = "analytical" # 觉醒水平影响信心 arousal = biological_state.get("arousal_level", 0.5) self.cognitive_state["confidence"] = arousal * 0.8 def _perceive(self, input_data: Dict, biological_state: Dict) -> Dict: """ 感知阶段 - 处理输入数据 参数: input_data: 输入数据字典 biological_state: 生物状态字典 返回: 感知结果字典 """ acuity = biological_state.get("sensor_acuity", 1.0) emotional_state = biological_state.get("emotional_state", "neutral") # 计算显著性(基于生物状态) salience = self._calculate_salience(input_data, biological_state) return { "content": input_data, "acuity": acuity, "salience": salience, "emotional_context": emotional_state, "timestamp": time.time() } def _calculate_salience(self, input_data: Dict, biological_state: Dict) -> float: """计算输入数据的显著性""" # 基础显著性 base_salience = input_data.get("salience", 0.5) # 生物状态影响 arousal = biological_state.get("arousal_level", 0.5) stress = biological_state.get("stress", 0.3) # 情绪影响 emotional_state = biological_state.get("emotional_state", "neutral") if emotional_state == "fear": base_salience *= 1.3 elif emotional_state == "joy": base_salience *= 1.1 # 相关性增强 related_memories = self._check_related_memories(input_data) if related_memories: base_salience *= 1.2 # 限制在0.0-1.0之间 return max(0.0, min(1.0, base_salience * (0.8 + arousal * 0.4 - stress * 0.2))) def _check_related_memories(self, input_data: Dict) -> List: """检查相关工作记忆""" keyword = input_data.get("keyword", "") if not keyword: return [] return [item for item in self.working_memory if keyword in item.get("perception", {}).get("content", "")] def _think(self, perception: Dict) -> Dict: """ 思考阶段 - 推理和处理感知信息 参数: perception: 感知结果字典 返回: 思考结果字典 """ # 根据处理模式选择推理策略 if self.cognitive_state["processing_mode"] == "analytical": return self._analytical_thinking(perception) else: return self._intuitive_thinking(perception) def _analytical_thinking(self, perception: Dict) -> Dict: """分析性思考""" # 简化实现 - 实际中应包含复杂的推理逻辑 content = perception.get("content", {}) salience = perception.get("salience", 0.5) # 生成假设 hypotheses = [] if salience > 0.7: hypotheses.append("高显著性事件,需要立即关注") if "danger" in content.get("keywords", []): hypotheses.append("检测到危险信号") # 评估证据 evidence = {} if "data" in content: evidence["data_consistency"] = 0.8 evidence["data_reliability"] = 0.7 return { "type": "analytical", "hypotheses": hypotheses, "evidence": evidence, "confidence": self.cognitive_state["confidence"] * 0.9 } def _intuitive_thinking(self, perception: Dict) -> Dict: """直觉性思考""" # 基于模式和经验的快速判断 content = perception.get("content", {}) emotional_context = perception.get("emotional_context", "neutral") # 生成直觉判断 judgment = "无特别发现" if emotional_context == "fear": judgment = "可能存在威胁,建议谨慎处理" elif "opportunity" in content.get("keywords", []): judgment = "发现潜在机会" return { "type": "intuitive", "judgment": judgment, "confidence": self.cognitive_state["confidence"] * 0.7, "basis": "模式识别与经验" } def _plan_action(self, thought: Dict) -> Dict: """ 行动计划阶段 - 基于思考结果制定行动计划 参数: thought: 思考结果字典 返回: 行动计划字典 """ # 根据思考类型制定计划 if thought["type"] == "analytical": return self._plan_analytical_action(thought) else: return self._plan_intuitive_action(thought) def _plan_analytical_action(self, thought: Dict) -> Dict: """制定分析性行动计划""" actions = [] priority = "medium" # 根据假设制定行动 for hypothesis in thought.get("hypotheses", []): if "立即关注" in hypothesis: actions.append("启动紧急响应协议") priority = "high" elif "危险信号" in hypothesis: actions.append("进行风险评估") actions.append("准备应急预案") priority = "high" # 如果没有高优先级行动 if not actions: actions.append("收集更多数据") actions.append("进行深入分析") priority = "medium" return { "actions": actions, "priority": priority, "estimated_time": 15.0, # 分钟 "resources_required": ["认知资源", "数据访问权限"] } def _plan_intuitive_action(self, thought: Dict) -> Dict: """制定直觉性行动计划""" judgment = thought.get("judgment", "") if "威胁" in judgment: return { "actions": ["采取防御姿态", "评估风险", "寻求更多信息"], "priority": "high", "estimated_time": 5.0, "resources_required": ["快速响应能力"] } elif "机会" in judgment: return { "actions": ["探索机会", "制定初步方案", "评估可行性"], "priority": "medium", "estimated_time": 10.0, "resources_required": ["创造力", "灵活性"] } else: return { "actions": ["维持现状", "监控环境"], "priority": "low", "estimated_time": 2.0, "resources_required": [] } def _add_to_working_memory(self, item: Dict): """添加项目到工作记忆""" # 检查是否已存在类似项目 existing_items = [i for i in self.working_memory if i["perception"]["content"] == item["perception"]["content"]] if existing_items: # 更新现有项目 existing_items[0].update(item) logger.debug(f"更新工作记忆项目: {item['perception']['content'][:20]}...") else: # 添加新项目 self.working_memory.append(item) logger.debug(f"添加到工作记忆: {item['perception']['content'][:20]}...") def get_working_memory_state(self, max_items: int = 5) -> List[Dict]: """ 获取工作记忆状态 参数: max_items: 最大返回项目数 返回: 工作记忆项目列表 """ # 按显著性排序 sorted_memory = sorted(self.working_memory, key=lambda x: x["salience"], reverse=True) return sorted_memory[:max_items] def get_metacognition_report(self) -> Dict: """ 获取元认知报告 返回: 元认知状态字典 """ return { "monitoring_active": self.metacognition["monitoring"], "last_insight": self.metacognition["insights"][-1] if self.metacognition["insights"] else None, "insight_count": len(self.metacognition["insights"]), "common_insights": self._get_common_insights(), "next_monitor_in": self.metacognition["interval"] - (time.time() - self.metacognition["last_monitor_time"]) } def _get_common_insights(self) -> List[str]: """获取最常见的元认知洞察""" if not self.metacognition["insights"]: return [] # 统计洞察频率 insight_counts = {} for insight in self.metacognition["insights"]: insight_counts[insight] = insight_counts.get(insight, 0) + 1 # 按频率排序 sorted_insights = sorted(insight_counts.items(), key=lambda x: x[1], reverse=True) return [insight[0] for insight in sorted_insights[:3]] def get_cognitive_state_report(self) -> Dict: """ 获取认知状态报告 返回: 认知状态字典 """ return self.cognitive_state.copy() def shutdown(self): """安全关闭意识框架""" self.metacognition["monitoring"] = False if self.monitor_thread.is_alive(): self.monitor_thread.join(timeout=2.0) logger.info("意识框架已安全关闭") return { "final_state": { "working_memory": list(self.working_memory), "metacognition": self.metacognition, "cognitive_state": self.cognitive_state }, "timestamp": time.time() } ”,文件位置都是在意识系统里 不需要放在子文件 也不用新建文件夹 我的理解对吗?这两个代码 还需要优化吗?
最新发布
08-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值