mac-rom-simm-programmer/external_mem.c
2011-11-27 23:06:02 -08:00

105 lines
2.1 KiB
C

/*
* external_mem.c
*
* Created on: Nov 25, 2011
* Author: Doug
*/
#include "external_mem.h"
#include "ports.h"
#include <avr/io.h>
#define HIGHEST_ADDRESS_LINE 20
// Allow this to be initialized more than once.
// In case we mess with the port settings,
// re-initializing ExternalMem should reset everything
// to sensible defaults.
void ExternalMem_Init(void)
{
// Initialize the ports connected to address/data/control lines
Ports_Init();
// Disable all pull-ups, on both the address and data lines. They aren't needed
// for normal operation.
Ports_AddressPullups_RMW(0, (1UL << (HIGHEST_ADDRESS_LINE + 1)) - 1);
Ports_DataPullups_RMW(0, 0xFFFFFFFFUL);
// Configure all address lines as outputs
Ports_SetAddressDDR((1UL << (HIGHEST_ADDRESS_LINE - 1)) - 1);
// Sensible defaults for address and data lines:
// Write out address zero
Ports_SetAddressOut(0);
// Set all data lines as inputs (with no pullups! we turned them off)
Ports_SetDataDDR(0);
// Control lines
Ports_SetCSDDR(1);
Ports_SetOEDDR(1);
Ports_SetWEDDR(1);
// Default all control lines to high (de-asserted)
ExternalMem_DeassertCS();
ExternalMem_DeassertOE();
ExternalMem_DeassertWE();
}
void ExternalMem_SetAddress(uint32_t address)
{
Ports_SetAddressOut(address);
}
void ExternalMem_SetData(uint32_t data)
{
Ports_SetDataDDR(0xFFFFFFFFUL);
Ports_SetDataOut(data);
}
void ExternalMem_SetAddressAndData(uint32_t address, uint32_t data)
{
ExternalMem_SetAddress(address);
ExternalMem_SetData(data);
}
void ExternalMem_SetDataAsInput(void)
{
Ports_SetDataDDR(0);
}
uint32_t ExternalMem_ReadData(void)
{
return Ports_ReadData();
}
void ExternalMem_AssertCS(void)
{
Ports_SetCSOut(0);
}
void ExternalMem_DeassertCS(void)
{
Ports_SetCSOut(1);
}
void ExternalMem_AssertWE(void)
{
Ports_SetWEOut(0);
}
void ExternalMem_DeassertWE(void)
{
Ports_SetWEOut(1);
}
void ExternalMem_AssertOE(void)
{
Ports_SetOEOut(0);
}
void ExternalMem_DeassertOE(void)
{
Ports_SetOEOut(1);
}