2011-11-26 07:10:30 +00:00
|
|
|
/*
|
|
|
|
* external_mem.h
|
|
|
|
*
|
|
|
|
* Created on: Nov 25, 2011
|
|
|
|
* Author: Doug
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EXTERNAL_MEM_H_
|
|
|
|
#define EXTERNAL_MEM_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2011-12-11 02:40:30 +00:00
|
|
|
// Holds info about the chip (retrieved with JEDEC standards)
|
|
|
|
struct ChipID
|
|
|
|
{
|
|
|
|
uint8_t manufacturerID;
|
|
|
|
uint8_t deviceID;
|
|
|
|
};
|
|
|
|
|
2011-12-11 21:28:32 +00:00
|
|
|
// Masks for functions that want a chip...
|
|
|
|
#define IC1 (1 << 3)
|
|
|
|
#define IC2 (1 << 2)
|
|
|
|
#define IC3 (1 << 1)
|
|
|
|
#define IC4 (1 << 0)
|
|
|
|
#define ALL_CHIPS (IC1 | IC2 | IC3 | IC4)
|
|
|
|
|
2011-12-12 05:48:26 +00:00
|
|
|
// I feel kind of sick making these available to the outside world, but
|
|
|
|
// I'm doing it for efficiency.
|
|
|
|
// These are the bits on port B corresponding to the control signals.
|
|
|
|
// Pass them to ExternalMem_Assert() or ExternalMem_Deassert().
|
|
|
|
#define SIMM_WE (1 << 6)
|
|
|
|
#define SIMM_OE (1 << 5)
|
|
|
|
#define SIMM_CS (1 << 4)
|
|
|
|
|
2011-11-26 07:10:30 +00:00
|
|
|
// Initializes the (bit-banged) external memory interface
|
|
|
|
void ExternalMem_Init(void);
|
|
|
|
|
|
|
|
// Sets the value outputted to the address lines
|
|
|
|
void ExternalMem_SetAddress(uint32_t address);
|
|
|
|
|
|
|
|
// Sets the value outputted to the data lines
|
|
|
|
void ExternalMem_SetData(uint32_t data);
|
|
|
|
|
|
|
|
// Sets the value outputted to the address and data lines
|
|
|
|
void ExternalMem_SetAddressAndData(uint32_t address, uint32_t data);
|
|
|
|
|
|
|
|
// Puts the data lines into input mode, for reading back stored data
|
|
|
|
void ExternalMem_SetDataAsInput(void);
|
|
|
|
|
|
|
|
// Reads back the value the chips are putting onto the data lines
|
|
|
|
uint32_t ExternalMem_ReadData(void);
|
|
|
|
|
2011-12-12 05:48:26 +00:00
|
|
|
/*// Sets the state of the chip select line
|
2011-11-26 07:10:30 +00:00
|
|
|
void ExternalMem_AssertCS(void);
|
|
|
|
void ExternalMem_DeassertCS(void);
|
|
|
|
|
|
|
|
// Sets the state of the write enable line
|
|
|
|
void ExternalMem_AssertWE(void);
|
|
|
|
void ExternalMem_DeassertWE(void);
|
|
|
|
|
|
|
|
// Sets the state of the output enable line
|
|
|
|
void ExternalMem_AssertOE(void);
|
2011-12-12 05:48:26 +00:00
|
|
|
void ExternalMem_DeassertOE(void);*/
|
|
|
|
|
|
|
|
// This is not the nicest-looking software engineering practice
|
|
|
|
// in the world, but it saves needlessly wasted CPU cycles
|
|
|
|
// that would be wasted in layers upon layers of abstraction
|
|
|
|
#define ExternalMem_Assert(assertMask) PORTB &= ~(assertMask);
|
|
|
|
#define ExternalMem_Deassert(assertMask) PORTB |= (assertMask);
|
2011-11-26 07:10:30 +00:00
|
|
|
|
2011-12-11 21:28:32 +00:00
|
|
|
// Reads a set of data from all 4 chips simultaneously
|
2011-12-10 21:53:43 +00:00
|
|
|
void ExternalMem_Read(uint32_t startAddress, uint32_t *buf, uint32_t len);
|
|
|
|
|
2011-12-11 21:28:32 +00:00
|
|
|
// Performs a single write cycle on all 4 chips simultaneously
|
2011-12-11 02:40:30 +00:00
|
|
|
void ExternalMem_WriteCycle(uint32_t address, uint32_t data);
|
|
|
|
|
2011-12-11 21:28:32 +00:00
|
|
|
// Performs a single read cycle on all 4 chips simultaneously
|
2011-12-11 18:12:22 +00:00
|
|
|
uint32_t ExternalMem_ReadCycle(uint32_t address);
|
|
|
|
|
2011-12-11 21:28:32 +00:00
|
|
|
// Does an unlock sequence on the chips requested
|
|
|
|
void ExternalMem_UnlockChips(uint8_t chipsMask);
|
2011-12-11 02:40:30 +00:00
|
|
|
|
|
|
|
// Identifies the chips that are currently in the SIMM
|
|
|
|
void ExternalMem_IdentifyChips(struct ChipID *chips);
|
|
|
|
|
2011-12-11 21:28:32 +00:00
|
|
|
// Erases the chips requested
|
|
|
|
void ExternalMem_EraseChips(uint8_t chipsMask);
|
|
|
|
|
|
|
|
// Writes a byte to the chips requested at the specified address
|
|
|
|
void ExternalMem_WriteByteToChips(uint32_t address, uint32_t data, uint8_t chipsMask);
|
|
|
|
|
|
|
|
// Writes a buffer to the requested chips simultaneously
|
|
|
|
// (each uint32_t contains an 8-bit portion for each chip,
|
|
|
|
// which is masked away if the chip is not requested)
|
|
|
|
void ExternalMem_Write(uint32_t startAddress, uint32_t *buf, uint32_t len, uint8_t chipsMask);
|
|
|
|
|
2011-11-26 07:10:30 +00:00
|
|
|
#endif /* EXTERNAL_MEM_H_ */
|