2013년 6월 2일 일요일

Working with Flash Memory

플레시 메모리를 가지고 개발하기에 관해, Programming Embedded Systems in C and C++ 라는 책에 나온 부분을 소개하고자 한다.  

지금 내가 개발중인 디바이스는, 그 용도가 우리 회사에서 주로 양산, 공급하고 있는 데이터 로거에서 모아 놓은 데이터를 무선으로 collecting하기 위한 디바이스다.  무선 기능을 위해서는 GPRS module을 쓰고 있는데, 비용이 저렴해서다.  GPRS 망이 결국에는 몇년뒤에 사라지겠지만,  비용면에서 가장 싸기 때문에 아직도 쓰이고 있고 제품도 나오고 있다.

타겟 디바이스의 먼저번 버전에서 데이터를 쌓아두는 내부 메모리로 EEPROM을 썼었는데, 새로운 버전에서는 이것보다 가격이 싸고 데이터 사이즈가 큰 Flash Memory 로 교체하였다. 

flash memory가 싸고 사이즈가 커서 좋은 면은 있겠으나, 접근하여 쓰고 읽고 하다보니 EEPROM보다 뭐 이리 복잡하고 귀찮은지..

다른 것때문에 이 책의 일부분을 뒤지다가 flash memory에 대해, 장단점언급한걸보고, 마자 마자를 연발하다가 여기에 함 정리해 두려한다.

-------------------------------------------
From the programmer's viewpoint, Flash is arguably the most complicated memory device
ever invented. 
프로그래머의 관점에서 보면, 플래시는 지금까지 발명된 메모리 디바이스 중 단연 복잡하다고 말할 수 있다. (물론 논란의 여지는 있겠으나)

The hardware interface has improved somewhat since the original devices were
introduced in 1988, but there is still a long way to go. Reading from Flash memory is fast and
easy, as it should be. 
하드웨어 인터페이스는 처음 이것이 개발된 1988년 이후, 다소 개선되었지만서도,
그러나 여전히 갈길이 멀다. 플레시 메모리에서 읽기작업은 빠르고 쉽다. 

In fact, reading data from a Flash is not all that different from reading
from any other memory device.
사실, 플레시에서 데이터를 읽는 것은 여느 다른 메모리 디바이스에서 데이터를 읽는 것과
전혀 다를 바 없다. 또한 그래야 하고.

The processor simply provides the address, and the memory device returns the data stored at that location. 
프로세서는 단순히 주소(위치)를 알려주고, 메모리 디바이스는 해당 위치에 저장된 데이터를 되돌려준다.

Most Flash devices enter this type of "read" mode automatically whenever the system is reset; no special initialization sequence is required to enable reading.
대부분의 플레시 디바이스는 시스템이 리셋될때면 언제나 자동적으로 이런 형태의 "읽기" 모드로 진입한다.  읽기 작업을 활성화하는 특별한 초기화 과정이 필요하지 않다. 

Writing data to a Flash is much harder. Three factors make writes difficult. 
플레시에 쓰기 작업은 이보다 훨씬 어렵다.  어렵게하는 요인은 세가지다.

First, each memory location must be erased before it can be rewritten. If the old data is not erased, the
result of the write operation will be some logical combination of the old and new values, and
the stored value will usually be something other than what you intended.
첫번째로, 각 메모리 위치에 뭔가를 쓰려면 그전에 반드시 그 위치에 있던 데이터가 먼저 삭제되야 한다.  만일 쓰기전 먼저 삭제를 하지 않는다면, 쓰기 연산은, (해당위치에 쓰여있던) 기존 데이터와 (쓰려고 하는)새로운 데이터의 어떤 논리적 조합으로 수행되기 때문에 저장된 값은 대개 우리가 의도했던 것과는 다른 값으로 저장될 것이다.

The second thing that makes writes to a Flash difficult is that only one sector, or block, of the
device can be erased at a time; it is impossible to erase a single byte. The size of an individual
sector varies by device, but it is usually on the order of several thousand bytes. For example,
the Flash device on the Arcom board-an AMD 29F010-has eight sectors, each containing 16
kilobytes.
플래시 메모리에 쓰기 작업이 어려운 두번째 이유는, 오직 하나의 섹터, 또는 블럭 단위로 삭제가 되기 때문이다.  한 바이트는 삭제가 안된다는 얘기다.  각 섹터의 크기는 디바이스 마다 다른데, 보통 몇 천 바이트이다. 예를 들어, Arcom 보드에 AMD 29F010의 플레시 디바이스는 8개의 섹터로 되어 있고, 각 섹터는 16 킬로바이트로 구성되어 있다.

Finally, the process of erasing the old data and writing the new varies from one manufacturer
to another and is usually rather complicated. These device programming interfaces are so
awkward that it is usually best to add a layer of software to make the Flash memory easier to
use. If implemented, this hardware-specific layer of software is usually called the Flash
driver.
마지막으로,  예전 데이터를 삭제하고 새 데이터를 쓰는 과정은 제조사 마다 다르나, 대개의 경우 꽤나 복잡하다. 이러한 디바이스 프로그래밍 인터페이스는 아주 어색하여(awkward - 자연스럽지 않다는 의미) 플래시 메모리를 쉽게 쓸 수 있도록 도와주는 소프트웨어 계층을 하나 끼워넣는것이 최선이다.  만일 구현된다면, 이런 하드웨어에 따라 다른 계층을 대개 플래시 드라이버(flash driver)라고 부른다. 

잔디 3주차

 잔디 심기. 3주차에 접어들었음. 사진. 아래가 1일차 사진. 다음이 3주차.