consistantly use bas_types.h instead of standard headers
This commit is contained in:
303
exe/basflash.c
303
exe/basflash.c
@@ -21,10 +21,9 @@
|
|||||||
* Author: Markus Fröschle
|
* Author: Markus Fröschle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include "bas_string.h"
|
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
|
#include "bas_string.h"
|
||||||
#include "diskio.h"
|
#include "diskio.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "s19reader.h"
|
#include "s19reader.h"
|
||||||
@@ -220,190 +219,190 @@ static const int num_flash_areas = sizeof(flash_areas) / sizeof(struct romram);
|
|||||||
*/
|
*/
|
||||||
void amd_flash_sector_erase(int n)
|
void amd_flash_sector_erase(int n)
|
||||||
{
|
{
|
||||||
volatile AMD_FLASH_CELL status;
|
volatile AMD_FLASH_CELL status;
|
||||||
|
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0x80);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0x80);
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[SADDR(n)] = AMD_FLASH_CMD_DATA(0x30);
|
pFlash[SADDR(n)] = AMD_FLASH_CMD_DATA(0x30);
|
||||||
|
|
||||||
do
|
do
|
||||||
status = pFlash[SADDR(n)];
|
status = pFlash[SADDR(n)];
|
||||||
while ((status & AMD_FLASH_CMD_DATA(0x80)) != AMD_FLASH_CMD_DATA(0x80));
|
while ((status & AMD_FLASH_CMD_DATA(0x80)) != AMD_FLASH_CMD_DATA(0x80));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place device in read mode
|
* Place device in read mode
|
||||||
*/
|
*/
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int amd_flash_erase(void *start, int bytes, void (*putchar)(int))
|
int amd_flash_erase(void *start, int bytes, void (*putchar)(int))
|
||||||
{
|
{
|
||||||
int i, ebytes = 0;
|
int i, ebytes = 0;
|
||||||
|
|
||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < AMD_FLASH_SECTORS; i++)
|
for (i = 0; i < AMD_FLASH_SECTORS; i++)
|
||||||
{
|
{
|
||||||
if (start >= (void *)((void *) pFlash + SOFFSET(i)) &&
|
if (start >= (void *)((void *) pFlash + SOFFSET(i)) &&
|
||||||
start <= (void *)((void *) pFlash + SOFFSET(i) + (SSIZE(i) - 1)))
|
start <= (void *)((void *) pFlash + SOFFSET(i) + (SSIZE(i) - 1)))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ebytes < bytes)
|
while (ebytes < bytes)
|
||||||
{
|
{
|
||||||
if (putchar != NULL)
|
if (putchar != NULL)
|
||||||
{
|
{
|
||||||
putchar('.');
|
putchar('.');
|
||||||
}
|
}
|
||||||
amd_flash_sector_erase(i);
|
amd_flash_sector_erase(i);
|
||||||
ebytes += SSIZE(i);
|
ebytes += SSIZE(i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (putchar != NULL)
|
if (putchar != NULL)
|
||||||
{
|
{
|
||||||
putchar(10); /* LF */
|
putchar(10); /* LF */
|
||||||
putchar(13); /* CR */
|
putchar(13); /* CR */
|
||||||
}
|
}
|
||||||
|
|
||||||
return ebytes;
|
return ebytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void amd_flash_program_cell(AMD_FLASH_CELL *dst, AMD_FLASH_CELL data)
|
void amd_flash_program_cell(AMD_FLASH_CELL *dst, AMD_FLASH_CELL data)
|
||||||
{
|
{
|
||||||
volatile AMD_FLASH_CELL status;
|
volatile AMD_FLASH_CELL status;
|
||||||
int retry;
|
int retry;
|
||||||
|
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xA0);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xA0);
|
||||||
*dst = data;
|
*dst = data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wait for program operation to finish
|
* Wait for program operation to finish
|
||||||
* (Data# Polling Algorithm)
|
* (Data# Polling Algorithm)
|
||||||
*/
|
*/
|
||||||
retry = 0;
|
retry = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
status = *dst;
|
status = *dst;
|
||||||
if ((status & AMD_FLASH_CMD_DATA(0x80)) ==
|
if ((status & AMD_FLASH_CMD_DATA(0x80)) ==
|
||||||
(data & AMD_FLASH_CMD_DATA(0x80)))
|
(data & AMD_FLASH_CMD_DATA(0x80)))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (status & AMD_FLASH_CMD_DATA(0x20))
|
if (status & AMD_FLASH_CMD_DATA(0x20))
|
||||||
{
|
{
|
||||||
status = *dst;
|
status = *dst;
|
||||||
if ((status & AMD_FLASH_CMD_DATA(0x80)) ==
|
if ((status & AMD_FLASH_CMD_DATA(0x80)) ==
|
||||||
(data & AMD_FLASH_CMD_DATA(0x80)))
|
(data & AMD_FLASH_CMD_DATA(0x80)))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (++retry > 1024)
|
if (++retry > 1024)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int amd_flash_program(void *dest, void *source, int bytes, int erase, void (*func)(void), void (*putchar)(int))
|
int amd_flash_program(void *dest, void *source, int bytes, int erase, void (*func)(void), void (*putchar)(int))
|
||||||
{
|
{
|
||||||
AMD_FLASH_CELL *src, *dst;
|
AMD_FLASH_CELL *src, *dst;
|
||||||
int hashi=1,hashj=0;
|
int hashi=1,hashj=0;
|
||||||
char hash[5];
|
char hash[5];
|
||||||
|
|
||||||
hash[0]=8; /* Backspace */
|
hash[0]=8; /* Backspace */
|
||||||
hash[1]=124;/* "|" */
|
hash[1]=124;/* "|" */
|
||||||
hash[2]=47; /* "/" */
|
hash[2]=47; /* "/" */
|
||||||
hash[3]=45; /* "-" */
|
hash[3]=45; /* "-" */
|
||||||
hash[4]=92; /* "\" */
|
hash[4]=92; /* "\" */
|
||||||
|
|
||||||
src = (AMD_FLASH_CELL *)source;
|
src = (AMD_FLASH_CELL *)source;
|
||||||
dst = (AMD_FLASH_CELL *)dest;
|
dst = (AMD_FLASH_CELL *)dest;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place device in read mode
|
* Place device in read mode
|
||||||
*/
|
*/
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Erase device if necessary
|
* Erase device if necessary
|
||||||
*/
|
*/
|
||||||
if (erase)
|
if (erase)
|
||||||
{
|
{
|
||||||
amd_flash_erase(dest, bytes, putchar);
|
amd_flash_erase(dest, bytes, putchar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Program device
|
* Program device
|
||||||
*/
|
*/
|
||||||
while (bytes > 0)
|
while (bytes > 0)
|
||||||
{
|
{
|
||||||
amd_flash_program_cell(dst,*src);
|
amd_flash_program_cell(dst,*src);
|
||||||
|
|
||||||
/* Verify Write */
|
/* Verify Write */
|
||||||
if (*dst == *src)
|
if (*dst == *src)
|
||||||
{
|
{
|
||||||
bytes -= AMD_FLASH_CELL_BYTES;
|
bytes -= AMD_FLASH_CELL_BYTES;
|
||||||
*dst++, *src++;
|
*dst++, *src++;
|
||||||
|
|
||||||
if ((putchar != NULL))
|
if ((putchar != NULL))
|
||||||
{
|
{
|
||||||
/* Hash marks to indicate progress */
|
/* Hash marks to indicate progress */
|
||||||
if (hashj == 0x1000)
|
if (hashj == 0x1000)
|
||||||
{
|
{
|
||||||
hashj = -1;
|
hashj = -1;
|
||||||
putchar(hash[0]);
|
putchar(hash[0]);
|
||||||
putchar(hash[hashi]);
|
putchar(hash[hashi]);
|
||||||
|
|
||||||
hashi++;
|
hashi++;
|
||||||
if (hashi == 5)
|
if (hashi == 5)
|
||||||
{
|
{
|
||||||
hashi=1;
|
hashi=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
hashj++;
|
hashj++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place device in read mode
|
* Place device in read mode
|
||||||
*/
|
*/
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
||||||
|
|
||||||
if (putchar != NULL)
|
if (putchar != NULL)
|
||||||
{
|
{
|
||||||
putchar(hash[0]);
|
putchar(hash[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a function was passed in, call it now
|
* If a function was passed in, call it now
|
||||||
*/
|
*/
|
||||||
if ((func != NULL))
|
if ((func != NULL))
|
||||||
{
|
{
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((int)src - (int)source);
|
return ((int)src - (int)source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -635,7 +634,7 @@ void basflash(void)
|
|||||||
if (strlen(fileinfo.fname) >= 4
|
if (strlen(fileinfo.fname) >= 4
|
||||||
&& strncmp(
|
&& strncmp(
|
||||||
&fileinfo.fname[strlen(fileinfo.fname)
|
&fileinfo.fname[strlen(fileinfo.fname)
|
||||||
- 4], srec_ext, 4) == 0) /* we have a .S19 file */
|
- 4], srec_ext, 4) == 0) /* we have a .S19 file */
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* build path + filename
|
* build path + filename
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
* Author: Markus Fröschle
|
* Author: Markus Fröschle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
|
|
||||||
static uint32_t ownstack[4096];
|
static uint32_t ownstack[4096];
|
||||||
static uint32_t *stackptr = &ownstack[4095];
|
static uint32_t *stackptr = &ownstack[4095];
|
||||||
|
|||||||
297
flash/flash.c
297
flash/flash.c
@@ -1,4 +1,3 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "bas_types.h"
|
#include "bas_types.h"
|
||||||
|
|
||||||
@@ -192,191 +191,191 @@ static const int num_flash_areas = sizeof(flash_areas) / sizeof(struct romram);
|
|||||||
*/
|
*/
|
||||||
void amd_flash_sector_erase(int n)
|
void amd_flash_sector_erase(int n)
|
||||||
{
|
{
|
||||||
volatile AMD_FLASH_CELL status;
|
volatile AMD_FLASH_CELL status;
|
||||||
|
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0x80);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0x80);
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[SADDR(n)] = AMD_FLASH_CMD_DATA(0x30);
|
pFlash[SADDR(n)] = AMD_FLASH_CMD_DATA(0x30);
|
||||||
|
|
||||||
do
|
do
|
||||||
status = pFlash[SADDR(n)];
|
status = pFlash[SADDR(n)];
|
||||||
while ((status & AMD_FLASH_CMD_DATA(0x80)) != AMD_FLASH_CMD_DATA(0x80));
|
while ((status & AMD_FLASH_CMD_DATA(0x80)) != AMD_FLASH_CMD_DATA(0x80));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place device in read mode
|
* Place device in read mode
|
||||||
*/
|
*/
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int amd_flash_erase(void *start, int bytes, void (*putchar)(int))
|
int amd_flash_erase(void *start, int bytes, void (*putchar)(int))
|
||||||
{
|
{
|
||||||
int i, ebytes = 0;
|
int i, ebytes = 0;
|
||||||
|
|
||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < AMD_FLASH_SECTORS; i++)
|
for (i = 0; i < AMD_FLASH_SECTORS; i++)
|
||||||
{
|
{
|
||||||
if (start >= (void *)((void *) pFlash + SOFFSET(i)) &&
|
if (start >= (void *)((void *) pFlash + SOFFSET(i)) &&
|
||||||
start <= (void *)((void *) pFlash + SOFFSET(i) + (SSIZE(i) - 1)))
|
start <= (void *)((void *) pFlash + SOFFSET(i) + (SSIZE(i) - 1)))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ebytes < bytes)
|
while (ebytes < bytes)
|
||||||
{
|
{
|
||||||
if (putchar != NULL)
|
if (putchar != NULL)
|
||||||
{
|
{
|
||||||
putchar('.');
|
putchar('.');
|
||||||
}
|
}
|
||||||
amd_flash_sector_erase(i);
|
amd_flash_sector_erase(i);
|
||||||
ebytes += SSIZE(i);
|
ebytes += SSIZE(i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (putchar != NULL)
|
if (putchar != NULL)
|
||||||
{
|
{
|
||||||
putchar(10); /* LF */
|
putchar(10); /* LF */
|
||||||
putchar(13); /* CR */
|
putchar(13); /* CR */
|
||||||
}
|
}
|
||||||
|
|
||||||
return ebytes;
|
return ebytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void amd_flash_program_cell(AMD_FLASH_CELL *dst, AMD_FLASH_CELL data)
|
void amd_flash_program_cell(AMD_FLASH_CELL *dst, AMD_FLASH_CELL data)
|
||||||
{
|
{
|
||||||
volatile AMD_FLASH_CELL status;
|
volatile AMD_FLASH_CELL status;
|
||||||
int retry;
|
int retry;
|
||||||
|
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0x2AA] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xA0);
|
pFlash[0x555] = AMD_FLASH_CMD_DATA(0xA0);
|
||||||
*dst = data;
|
*dst = data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wait for program operation to finish
|
* Wait for program operation to finish
|
||||||
* (Data# Polling Algorithm)
|
* (Data# Polling Algorithm)
|
||||||
*/
|
*/
|
||||||
retry = 0;
|
retry = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
status = *dst;
|
status = *dst;
|
||||||
if ((status & AMD_FLASH_CMD_DATA(0x80)) ==
|
if ((status & AMD_FLASH_CMD_DATA(0x80)) ==
|
||||||
(data & AMD_FLASH_CMD_DATA(0x80)))
|
(data & AMD_FLASH_CMD_DATA(0x80)))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (status & AMD_FLASH_CMD_DATA(0x20))
|
if (status & AMD_FLASH_CMD_DATA(0x20))
|
||||||
{
|
{
|
||||||
status = *dst;
|
status = *dst;
|
||||||
if ((status & AMD_FLASH_CMD_DATA(0x80)) ==
|
if ((status & AMD_FLASH_CMD_DATA(0x80)) ==
|
||||||
(data & AMD_FLASH_CMD_DATA(0x80)))
|
(data & AMD_FLASH_CMD_DATA(0x80)))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (++retry > 1024)
|
if (++retry > 1024)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int amd_flash_program(void *dest, void *source, int bytes, int erase, void (*func)(void), void (*putchar)(int))
|
int amd_flash_program(void *dest, void *source, int bytes, int erase, void (*func)(void), void (*putchar)(int))
|
||||||
{
|
{
|
||||||
AMD_FLASH_CELL *src;
|
AMD_FLASH_CELL *src;
|
||||||
AMD_FLASH_CELL *dst;
|
AMD_FLASH_CELL *dst;
|
||||||
int hashi = 1;
|
int hashi = 1;
|
||||||
int hashj = 0;
|
int hashj = 0;
|
||||||
char hash[5];
|
char hash[5];
|
||||||
|
|
||||||
hash[0] = 8; /* Backspace */
|
hash[0] = 8; /* Backspace */
|
||||||
hash[1] = 124;/* "|" */
|
hash[1] = 124;/* "|" */
|
||||||
hash[2] = 47; /* "/" */
|
hash[2] = 47; /* "/" */
|
||||||
hash[3] = 45; /* "-" */
|
hash[3] = 45; /* "-" */
|
||||||
hash[4] = 92; /* "\" */
|
hash[4] = 92; /* "\" */
|
||||||
|
|
||||||
src = (AMD_FLASH_CELL *)source;
|
src = (AMD_FLASH_CELL *)source;
|
||||||
dst = (AMD_FLASH_CELL *)dest;
|
dst = (AMD_FLASH_CELL *)dest;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place device in read mode
|
* Place device in read mode
|
||||||
*/
|
*/
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Erase device if necessary
|
* Erase device if necessary
|
||||||
*/
|
*/
|
||||||
if (erase)
|
if (erase)
|
||||||
{
|
{
|
||||||
amd_flash_erase(dest, bytes, putchar);
|
amd_flash_erase(dest, bytes, putchar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Program device
|
* Program device
|
||||||
*/
|
*/
|
||||||
while (bytes > 0)
|
while (bytes > 0)
|
||||||
{
|
{
|
||||||
amd_flash_program_cell(dst, *src);
|
amd_flash_program_cell(dst, *src);
|
||||||
|
|
||||||
/* Verify Write */
|
/* Verify Write */
|
||||||
if (*dst == *src)
|
if (*dst == *src)
|
||||||
{
|
{
|
||||||
bytes -= AMD_FLASH_CELL_BYTES;
|
bytes -= AMD_FLASH_CELL_BYTES;
|
||||||
*dst++, *src++;
|
*dst++, *src++;
|
||||||
|
|
||||||
if ((putchar != NULL))
|
if ((putchar != NULL))
|
||||||
{
|
{
|
||||||
/* Hash marks to indicate progress */
|
/* Hash marks to indicate progress */
|
||||||
if (hashj == 0x1000)
|
if (hashj == 0x1000)
|
||||||
{
|
{
|
||||||
hashj = -1;
|
hashj = -1;
|
||||||
putchar(hash[0]);
|
putchar(hash[0]);
|
||||||
putchar(hash[hashi]);
|
putchar(hash[hashi]);
|
||||||
|
|
||||||
hashi++;
|
hashi++;
|
||||||
if (hashi == 5)
|
if (hashi == 5)
|
||||||
{
|
{
|
||||||
hashi = 1;
|
hashi = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
hashj++;
|
hashj++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place device in read mode
|
* Place device in read mode
|
||||||
*/
|
*/
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xAA);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0x55);
|
||||||
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
pFlash[0] = AMD_FLASH_CMD_DATA(0xF0);
|
||||||
|
|
||||||
if (putchar != NULL)
|
if (putchar != NULL)
|
||||||
{
|
{
|
||||||
putchar(hash[0]);
|
putchar(hash[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a function was passed in, call it now
|
* If a function was passed in, call it now
|
||||||
*/
|
*/
|
||||||
if ((func != NULL))
|
if ((func != NULL))
|
||||||
{
|
{
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((int)src - (int)source);
|
return ((int)src - (int)source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,7 @@
|
|||||||
* Copyright 2012 M. Froeschle
|
* Copyright 2012 M. Froeschle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "bas_string.h"
|
#include "bas_string.h"
|
||||||
@@ -345,10 +344,10 @@ static err_t verify(uint8_t *dst, uint8_t *src, uint32_t length)
|
|||||||
*/
|
*/
|
||||||
static inline err_t srec_memcpy(uint8_t *dst, uint8_t *src, size_t n)
|
static inline err_t srec_memcpy(uint8_t *dst, uint8_t *src, size_t n)
|
||||||
{
|
{
|
||||||
err_t e = OK;
|
err_t e = OK;
|
||||||
|
|
||||||
memcpy((void *) dst, (void *) src, n);
|
memcpy((void *) dst, (void *) src, n);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
void srec_execute(char *flasher_filename)
|
void srec_execute(char *flasher_filename)
|
||||||
@@ -383,7 +382,7 @@ void srec_execute(char *flasher_filename)
|
|||||||
{
|
{
|
||||||
/* next pass: copy data to destination */
|
/* next pass: copy data to destination */
|
||||||
xprintf("OK.\r\ncopy/flash data: ");
|
xprintf("OK.\r\ncopy/flash data: ");
|
||||||
err = read_srecords(flasher_filename, &start_address, &length, srec_memcpy);
|
err = read_srecords(flasher_filename, &start_address, &length, srec_memcpy);
|
||||||
if (err == OK)
|
if (err == OK)
|
||||||
{
|
{
|
||||||
/* next pass: verify data */
|
/* next pass: verify data */
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ff.h>
|
#include <ff.h>
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
|
|
||||||
#if _CODE_PAGE == 437
|
#if _CODE_PAGE == 437
|
||||||
#define _TBLDEF 1
|
#define _TBLDEF 1
|
||||||
|
|||||||
20
fs/ff.c
20
fs/ff.c
@@ -95,7 +95,7 @@
|
|||||||
/ Changed option name _FS_SHARE to _FS_LOCK.
|
/ Changed option name _FS_SHARE to _FS_LOCK.
|
||||||
/---------------------------------------------------------------------------*/
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <ff.h> /* FatFs configurations and declarations */
|
#include <ff.h> /* FatFs configurations and declarations */
|
||||||
#include <diskio.h> /* Declarations of low level disk I/O functions */
|
#include <diskio.h> /* Declarations of low level disk I/O functions */
|
||||||
|
|
||||||
@@ -356,11 +356,11 @@ typedef struct {
|
|||||||
uint32_t get_fattime (void)
|
uint32_t get_fattime (void)
|
||||||
{
|
{
|
||||||
return ((uint32_t)(2012 - 1980) << 25) /* Year = 2012 */
|
return ((uint32_t)(2012 - 1980) << 25) /* Year = 2012 */
|
||||||
| ((uint32_t)1 << 21) /* Month = 1 */
|
| ((uint32_t)1 << 21) /* Month = 1 */
|
||||||
| ((uint32_t)1 << 16) /* Day_m = 1*/
|
| ((uint32_t)1 << 16) /* Day_m = 1*/
|
||||||
| ((uint32_t)0 << 11) /* Hour = 0 */
|
| ((uint32_t)0 << 11) /* Hour = 0 */
|
||||||
| ((uint32_t)0 << 5) /* Min = 0 */
|
| ((uint32_t)0 << 5) /* Min = 0 */
|
||||||
| ((uint32_t)0 >> 1); /* Sec = 0 */
|
| ((uint32_t)0 >> 1); /* Sec = 0 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Character code support macros */
|
/* Character code support macros */
|
||||||
@@ -970,7 +970,7 @@ FRESULT remove_chain (
|
|||||||
#if _USE_ERASE
|
#if _USE_ERASE
|
||||||
if (ecl + 1 == nxt) { /* Is next cluster contiguous? */
|
if (ecl + 1 == nxt) { /* Is next cluster contiguous? */
|
||||||
ecl = nxt;
|
ecl = nxt;
|
||||||
} else { /* End of contiguous clusters */
|
} else { /* End of contiguous clusters */
|
||||||
rt[0] = clust2sect(fs, scl); /* Start sector */
|
rt[0] = clust2sect(fs, scl); /* Start sector */
|
||||||
rt[1] = clust2sect(fs, ecl) + fs->csize - 1; /* End sector */
|
rt[1] = clust2sect(fs, ecl) + fs->csize - 1; /* End sector */
|
||||||
disk_ioctl(fs->drv, CTRL_ERASE_SECTOR, rt); /* Erase the block */
|
disk_ioctl(fs->drv, CTRL_ERASE_SECTOR, rt); /* Erase the block */
|
||||||
@@ -2190,7 +2190,7 @@ FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */
|
|||||||
|
|
||||||
/* Get fsinfo if available */
|
/* Get fsinfo if available */
|
||||||
if (fmt == FS_FAT32) {
|
if (fmt == FS_FAT32) {
|
||||||
fs->fsi_flag = 0;
|
fs->fsi_flag = 0;
|
||||||
fs->fsi_sector = bsect + LD_WORD(fs->win+BPB_FSInfo);
|
fs->fsi_sector = bsect + LD_WORD(fs->win+BPB_FSInfo);
|
||||||
if (disk_read(fs->drv, fs->win, fs->fsi_sector, 1) == RES_OK &&
|
if (disk_read(fs->drv, fs->win, fs->fsi_sector, 1) == RES_OK &&
|
||||||
LD_WORD(fs->win+BS_55AA) == 0xAA55 &&
|
LD_WORD(fs->win+BS_55AA) == 0xAA55 &&
|
||||||
@@ -2721,7 +2721,7 @@ FRESULT f_close (
|
|||||||
FATFS *fs = fp->fs;;
|
FATFS *fs = fp->fs;;
|
||||||
res = validate(fp);
|
res = validate(fp);
|
||||||
if (res == FR_OK) {
|
if (res == FR_OK) {
|
||||||
res = dec_lock(fp->lockid);
|
res = dec_lock(fp->lockid);
|
||||||
unlock_fs(fs, FR_OK);
|
unlock_fs(fs, FR_OK);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -2820,7 +2820,7 @@ FRESULT f_getcwd (
|
|||||||
res = dir_read(&dj);
|
res = dir_read(&dj);
|
||||||
if (res != FR_OK) break;
|
if (res != FR_OK) break;
|
||||||
if (ccl == ld_clust(dj.fs, dj.dir)) break; /* Found the entry */
|
if (ccl == ld_clust(dj.fs, dj.dir)) break; /* Found the entry */
|
||||||
res = dir_next(&dj, 0);
|
res = dir_next(&dj, 0);
|
||||||
} while (res == FR_OK);
|
} while (res == FR_OK);
|
||||||
if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */
|
if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */
|
||||||
if (res != FR_OK) break;
|
if (res != FR_OK) break;
|
||||||
|
|||||||
@@ -23,8 +23,7 @@
|
|||||||
* Author: Markus Fröschle
|
* Author: Markus Fröschle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "xhdi_sd.h"
|
#include "xhdi_sd.h"
|
||||||
#include "dma.h"
|
#include "dma.h"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
#ifndef __MCF5475_H__
|
#ifndef __MCF5475_H__
|
||||||
#define __MCF5475_H__
|
#define __MCF5475_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
/***
|
/***
|
||||||
* MCF5475 Derivative Memory map definitions from linker command files:
|
* MCF5475 Derivative Memory map definitions from linker command files:
|
||||||
* __MBAR, __MMUBAR, __RAMBAR0, __RAMBAR0_SIZE, __RAMBAR1, __RAMBAR1_SIZE
|
* __MBAR, __MMUBAR, __RAMBAR0, __RAMBAR0_SIZE, __RAMBAR1, __RAMBAR1_SIZE
|
||||||
|
|||||||
@@ -30,5 +30,6 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h> /* for sizeof() etc. */
|
||||||
|
|
||||||
#endif /* BAS_TYPES_H_ */
|
#endif /* BAS_TYPES_H_ */
|
||||||
|
|||||||
@@ -25,8 +25,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CACR Cache Control Register
|
* CACR Cache Control Register
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ extern "C" {
|
|||||||
#define _USE_WRITE 1 /* 1: Enable disk_write function */
|
#define _USE_WRITE 1 /* 1: Enable disk_write function */
|
||||||
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
|
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
|
|
||||||
|
|
||||||
/* Status of Disk Functions */
|
/* Status of Disk Functions */
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef _EXCEPTIONS_H_
|
#ifndef _EXCEPTIONS_H_
|
||||||
#define _EXCEPTIONS_H_
|
#define _EXCEPTIONS_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
|
|
||||||
static inline uint32_t set_ipl(uint32_t ipl)
|
static inline uint32_t set_ipl(uint32_t ipl)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <ffconf.h> /* FatFs configuration options */
|
#include <ffconf.h> /* FatFs configuration options */
|
||||||
|
|
||||||
#if _FATFS != _FFCONF
|
#if _FATFS != _FFCONF
|
||||||
|
|||||||
@@ -8,9 +8,7 @@
|
|||||||
#ifndef _TIMER_H_
|
#ifndef _TIMER_H_
|
||||||
#define _TIMER_H_
|
#define _TIMER_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
* Author: Markus Fröschle
|
* Author: Markus Fröschle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include "util.h" /* for swpX() */
|
#include "util.h" /* for swpX() */
|
||||||
|
|
||||||
#define PCI_MEMORY_OFFSET (0x80000000)
|
#define PCI_MEMORY_OFFSET (0x80000000)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#define _SD_CARD_H_
|
#define _SD_CARD_H_
|
||||||
|
|
||||||
#include <MCF5475.h>
|
#include <MCF5475.h>
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
|
|
||||||
extern void sd_card_init(void);
|
extern void sd_card_init(void);
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#ifndef UTIL_H_
|
#ifndef UTIL_H_
|
||||||
#define UTIL_H_
|
#define UTIL_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
|
|
||||||
#define NOP() __asm__ __volatile__("nop\n\t" : : : "memory")
|
#define NOP() __asm__ __volatile__("nop\n\t" : : : "memory")
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ static inline uint32_t swpl(uint32_t l)
|
|||||||
register uint32_t result asm("d0");
|
register uint32_t result asm("d0");
|
||||||
|
|
||||||
__asm__ __volatile__
|
__asm__ __volatile__
|
||||||
(
|
(
|
||||||
"lea %[input],a0\n\t" \
|
"lea %[input],a0\n\t" \
|
||||||
"mvz.b 3(a0),%[output]\n\t" \
|
"mvz.b 3(a0),%[output]\n\t" \
|
||||||
"lsl.l #8,%[output]\n\t" \
|
"lsl.l #8,%[output]\n\t" \
|
||||||
@@ -74,7 +74,7 @@ static inline uint32_t swpl(uint32_t l)
|
|||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WORD swpw2(ULONG val);
|
* WORD swpw2(ULONG val);
|
||||||
@@ -85,17 +85,17 @@ static inline uint32_t swpl(uint32_t l)
|
|||||||
#define swpw2(a) \
|
#define swpw2(a) \
|
||||||
__extension__ \
|
__extension__ \
|
||||||
({unsigned long _tmp; \
|
({unsigned long _tmp; \
|
||||||
__asm__ __volatile__ \
|
__asm__ __volatile__ \
|
||||||
("move.b (%1),%0\n\t" \
|
("move.b (%1),%0\n\t" \
|
||||||
"move.b 1(%1),(%1)\n\t" \
|
"move.b 1(%1),(%1)\n\t" \
|
||||||
"move.b %0,1(%1)\n\t" \
|
"move.b %0,1(%1)\n\t" \
|
||||||
"move.b 2(%1),%0\n\t" \
|
"move.b 2(%1),%0\n\t" \
|
||||||
"move.b 3(%1),2(%1)\n\t" \
|
"move.b 3(%1),2(%1)\n\t" \
|
||||||
"move.b %0,3(%1)" \
|
"move.b %0,3(%1)" \
|
||||||
: "=d"(_tmp) /* outputs */ \
|
: "=d"(_tmp) /* outputs */ \
|
||||||
: "a"(&a) /* inputs */ \
|
: "a"(&a) /* inputs */ \
|
||||||
: "cc", "memory" /* clobbered */ \
|
: "cc", "memory" /* clobbered */ \
|
||||||
); \
|
); \
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -144,10 +144,10 @@ __extension__ \
|
|||||||
#define regsafe_call(addr) \
|
#define regsafe_call(addr) \
|
||||||
__extension__ \
|
__extension__ \
|
||||||
({__asm__ volatile ("lea -60(sp),sp\n\t" \
|
({__asm__ volatile ("lea -60(sp),sp\n\t" \
|
||||||
"movem.l d0-d7/a0-a6,(sp)"); \
|
"movem.l d0-d7/a0-a6,(sp)"); \
|
||||||
((void (*) (void)) addr)(); \
|
((void (*) (void)) addr)(); \
|
||||||
__asm__ volatile ("movem.l (sp),d0-d7/a0-a6\n\t" \
|
__asm__ volatile ("movem.l (sp),d0-d7/a0-a6\n\t" \
|
||||||
"lea 60(sp),sp"); \
|
"lea 60(sp),sp"); \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#ifndef _VIDEO_H_
|
#ifndef _VIDEO_H_
|
||||||
#define _VIDEO_H_
|
#define _VIDEO_H_
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <bas_types.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
|
|
||||||
extern void video_init(void);
|
extern void video_init(void);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/* $XFree86: xc/extras/x86emu/src/x86emu/x86emu/debug.h,v 1.4 2000/11/21 23:10:27 tsi Exp $ */
|
/* $XFree86: xc/extras/x86emu/src/x86emu/x86emu/debug.h,v 1.4 2000/11/21 23:10:27 tsi Exp $ */
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -135,7 +135,7 @@
|
|||||||
|
|
||||||
#define SAVE_IP_CS(x,y) \
|
#define SAVE_IP_CS(x,y) \
|
||||||
if (DEBUG_DECODE() | DEBUG_TRACECALL() | DEBUG_BREAK() \
|
if (DEBUG_DECODE() | DEBUG_TRACECALL() | DEBUG_BREAK() \
|
||||||
| DEBUG_IO_TRACE() | DEBUG_SAVE_IP_CS()) { \
|
| DEBUG_IO_TRACE() | DEBUG_SAVE_IP_CS()) { \
|
||||||
M.x86.saved_cs = x; \
|
M.x86.saved_cs = x; \
|
||||||
M.x86.saved_ip = y; \
|
M.x86.saved_ip = y; \
|
||||||
}
|
}
|
||||||
|
|||||||
416
kbd/ikbd.c
416
kbd/ikbd.c
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "bas_string.h"
|
#include "bas_string.h"
|
||||||
|
|
||||||
@@ -42,298 +42,298 @@ static unsigned char wptr = 0, rptr = 0;
|
|||||||
// structure to keep track of ikbd state
|
// structure to keep track of ikbd state
|
||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
unsigned char cmd;
|
unsigned char cmd;
|
||||||
unsigned char state;
|
unsigned char state;
|
||||||
unsigned char expect;
|
unsigned char expect;
|
||||||
|
|
||||||
// joystick state
|
// joystick state
|
||||||
unsigned char joystick[2];
|
unsigned char joystick[2];
|
||||||
|
|
||||||
// mouse state
|
// mouse state
|
||||||
unsigned short mouse_pos_x, mouse_pos_y;
|
unsigned short mouse_pos_x, mouse_pos_y;
|
||||||
unsigned char mouse_buttons;
|
unsigned char mouse_buttons;
|
||||||
} ikbd;
|
} ikbd;
|
||||||
|
|
||||||
// #define IKBD_DEBUG
|
// #define IKBD_DEBUG
|
||||||
|
|
||||||
void ikbd_init()
|
void ikbd_init()
|
||||||
{
|
{
|
||||||
// reset ikbd state
|
// reset ikbd state
|
||||||
memset(&ikbd, 0, sizeof(ikbd));
|
memset(&ikbd, 0, sizeof(ikbd));
|
||||||
ikbd.state = IKBD_DEFAULT;
|
ikbd.state = IKBD_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enqueue(unsigned char b)
|
static void enqueue(unsigned char b)
|
||||||
{
|
{
|
||||||
if (((wptr + 1)&(QUEUE_LEN-1)) == rptr)
|
if (((wptr + 1)&(QUEUE_LEN-1)) == rptr)
|
||||||
{
|
{
|
||||||
xprintf("IKBD: !!!!!!! tx queue overflow !!!!!!!!!\n");
|
xprintf("IKBD: !!!!!!! tx queue overflow !!!!!!!!!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tx_queue[wptr] = b;
|
tx_queue[wptr] = b;
|
||||||
wptr = (wptr + 1) & (QUEUE_LEN - 1);
|
wptr = (wptr + 1) & (QUEUE_LEN - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert internal joystick format into atari ikbd format
|
// convert internal joystick format into atari ikbd format
|
||||||
static unsigned char joystick_map2ikbd(unsigned in)
|
static unsigned char joystick_map2ikbd(unsigned in)
|
||||||
{
|
{
|
||||||
unsigned char out = 0;
|
unsigned char out = 0;
|
||||||
|
|
||||||
if (in & JOY_UP) out |= 0x01;
|
if (in & JOY_UP) out |= 0x01;
|
||||||
if (in & JOY_DOWN) out |= 0x02;
|
if (in & JOY_DOWN) out |= 0x02;
|
||||||
if (in & JOY_LEFT) out |= 0x04;
|
if (in & JOY_LEFT) out |= 0x04;
|
||||||
if (in & JOY_RIGHT) out |= 0x08;
|
if (in & JOY_RIGHT) out |= 0x08;
|
||||||
if (in & JOY_BTN1) out |= 0x80;
|
if (in & JOY_BTN1) out |= 0x80;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// process inout from atari core into ikbd
|
// process inout from atari core into ikbd
|
||||||
void ikbd_handle_input(unsigned char cmd)
|
void ikbd_handle_input(unsigned char cmd)
|
||||||
{
|
{
|
||||||
// expecting a second byte for command
|
// expecting a second byte for command
|
||||||
if (ikbd.expect)
|
if (ikbd.expect)
|
||||||
{
|
{
|
||||||
ikbd.expect--;
|
ikbd.expect--;
|
||||||
|
|
||||||
// last byte of command received
|
// last byte of command received
|
||||||
if (!ikbd.expect)
|
if (!ikbd.expect)
|
||||||
{
|
{
|
||||||
switch(ikbd.cmd)
|
switch(ikbd.cmd)
|
||||||
{
|
{
|
||||||
case 0x07: // set mouse button action
|
case 0x07: // set mouse button action
|
||||||
xprintf("IKBD: mouse button action = %x\n", cmd);
|
xprintf("IKBD: mouse button action = %x\n", cmd);
|
||||||
|
|
||||||
// bit 2: Mouse buttons act like keys (LEFT=0x74 & RIGHT=0x75)
|
// bit 2: Mouse buttons act like keys (LEFT=0x74 & RIGHT=0x75)
|
||||||
if(cmd & 0x04) ikbd.state |= IKBD_STATE_MOUSE_BUTTON_AS_KEY;
|
if(cmd & 0x04) ikbd.state |= IKBD_STATE_MOUSE_BUTTON_AS_KEY;
|
||||||
else ikbd.state &= ~IKBD_STATE_MOUSE_BUTTON_AS_KEY;
|
else ikbd.state &= ~IKBD_STATE_MOUSE_BUTTON_AS_KEY;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x80: // ibkd reset
|
case 0x80: // ibkd reset
|
||||||
// reply "everything is ok"
|
// reply "everything is ok"
|
||||||
enqueue(0xf0);
|
enqueue(0xf0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ikbd.cmd = cmd;
|
ikbd.cmd = cmd;
|
||||||
|
|
||||||
switch(cmd)
|
switch(cmd)
|
||||||
{
|
{
|
||||||
case 0x07:
|
case 0x07:
|
||||||
xprintf("IKBD: Set mouse button action");
|
xprintf("IKBD: Set mouse button action");
|
||||||
ikbd.expect = 1;
|
ikbd.expect = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x08:
|
case 0x08:
|
||||||
xprintf("IKBD: Set relative mouse positioning");
|
xprintf("IKBD: Set relative mouse positioning");
|
||||||
ikbd.state &= ~IKBD_STATE_MOUSE_DISABLED;
|
ikbd.state &= ~IKBD_STATE_MOUSE_DISABLED;
|
||||||
ikbd.state &= ~IKBD_STATE_MOUSE_ABSOLUTE;
|
ikbd.state &= ~IKBD_STATE_MOUSE_ABSOLUTE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x09:
|
case 0x09:
|
||||||
xprintf("IKBD: Set absolute mouse positioning");
|
xprintf("IKBD: Set absolute mouse positioning");
|
||||||
ikbd.state &= ~IKBD_STATE_MOUSE_DISABLED;
|
ikbd.state &= ~IKBD_STATE_MOUSE_DISABLED;
|
||||||
ikbd.state |= IKBD_STATE_MOUSE_ABSOLUTE;
|
ikbd.state |= IKBD_STATE_MOUSE_ABSOLUTE;
|
||||||
ikbd.expect = 4;
|
ikbd.expect = 4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0b:
|
case 0x0b:
|
||||||
xprintf("IKBD: Set Mouse threshold");
|
xprintf("IKBD: Set Mouse threshold");
|
||||||
ikbd.expect = 2;
|
ikbd.expect = 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0f:
|
case 0x0f:
|
||||||
xprintf("IKBD: Set Y at bottom");
|
xprintf("IKBD: Set Y at bottom");
|
||||||
ikbd.state |= IKBD_STATE_MOUSE_Y_BOTTOM;
|
ikbd.state |= IKBD_STATE_MOUSE_Y_BOTTOM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x10:
|
case 0x10:
|
||||||
xprintf("IKBD: Set Y at top");
|
xprintf("IKBD: Set Y at top");
|
||||||
ikbd.state &= ~IKBD_STATE_MOUSE_Y_BOTTOM;
|
ikbd.state &= ~IKBD_STATE_MOUSE_Y_BOTTOM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x12:
|
case 0x12:
|
||||||
xprintf("IKBD: Disable mouse");
|
xprintf("IKBD: Disable mouse");
|
||||||
ikbd.state |= IKBD_STATE_MOUSE_DISABLED;
|
ikbd.state |= IKBD_STATE_MOUSE_DISABLED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x14:
|
case 0x14:
|
||||||
xprintf("IKBD: Set Joystick event reporting");
|
xprintf("IKBD: Set Joystick event reporting");
|
||||||
ikbd.state |= IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
ikbd.state |= IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x15:
|
case 0x15:
|
||||||
xprintf("IKBD: Set Joystick interrogation mode");
|
xprintf("IKBD: Set Joystick interrogation mode");
|
||||||
ikbd.state &= ~IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
ikbd.state &= ~IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x16: // interrogate joystick
|
case 0x16: // interrogate joystick
|
||||||
// send reply
|
// send reply
|
||||||
enqueue(0xfd);
|
enqueue(0xfd);
|
||||||
enqueue(joystick_map2ikbd(ikbd.joystick[0]));
|
enqueue(joystick_map2ikbd(ikbd.joystick[0]));
|
||||||
enqueue(joystick_map2ikbd(ikbd.joystick[1]));
|
enqueue(joystick_map2ikbd(ikbd.joystick[1]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1a:
|
case 0x1a:
|
||||||
xprintf("IKBD: Disable joysticks");
|
xprintf("IKBD: Disable joysticks");
|
||||||
ikbd.state &= ~IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
ikbd.state &= ~IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1c:
|
case 0x1c:
|
||||||
xprintf("IKBD: Interrogate time of day");
|
xprintf("IKBD: Interrogate time of day");
|
||||||
|
|
||||||
enqueue(0xfc);
|
enqueue(0xfc);
|
||||||
enqueue(0x13); // year bcd
|
enqueue(0x13); // year bcd
|
||||||
enqueue(0x03); // month bcd
|
enqueue(0x03); // month bcd
|
||||||
enqueue(0x07); // day bcd
|
enqueue(0x07); // day bcd
|
||||||
enqueue(0x20); // hour bcd
|
enqueue(0x20); // hour bcd
|
||||||
enqueue(0x58); // minute bcd
|
enqueue(0x58); // minute bcd
|
||||||
enqueue(0x00); // second bcd
|
enqueue(0x00); // second bcd
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 0x80:
|
case 0x80:
|
||||||
xprintf("IKBD: Reset");
|
xprintf("IKBD: Reset");
|
||||||
ikbd.expect = 1;
|
ikbd.expect = 1;
|
||||||
ikbd.state = IKBD_DEFAULT;
|
ikbd.state = IKBD_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
xprintf("IKBD: unknown command: %x\n", cmd);
|
xprintf("IKBD: unknown command: %x\n", cmd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikbd_poll(void) {
|
void ikbd_poll(void) {
|
||||||
static int mtimer = 0;
|
static int mtimer = 0;
|
||||||
if (CheckTimer(mtimer))
|
if (CheckTimer(mtimer))
|
||||||
{
|
{
|
||||||
mtimer = GetTimer(10);
|
mtimer = GetTimer(10);
|
||||||
|
|
||||||
// check for incoming ikbd data
|
// check for incoming ikbd data
|
||||||
EnableIO();
|
EnableIO();
|
||||||
SPI(UIO_IKBD_IN);
|
SPI(UIO_IKBD_IN);
|
||||||
|
|
||||||
while(SPI(0))
|
while(SPI(0))
|
||||||
ikbd_handle_input(SPI(0));
|
ikbd_handle_input(SPI(0));
|
||||||
|
|
||||||
DisableIO();
|
DisableIO();
|
||||||
}
|
}
|
||||||
|
|
||||||
// send data from queue if present
|
// send data from queue if present
|
||||||
if(rptr == wptr) return;
|
if(rptr == wptr) return;
|
||||||
|
|
||||||
// transmit data from queue
|
// transmit data from queue
|
||||||
EnableIO();
|
EnableIO();
|
||||||
SPI(UIO_IKBD_OUT);
|
SPI(UIO_IKBD_OUT);
|
||||||
SPI(tx_queue[rptr]);
|
SPI(tx_queue[rptr]);
|
||||||
DisableIO();
|
DisableIO();
|
||||||
|
|
||||||
rptr = (rptr + 1) & (QUEUE_LEN - 1);
|
rptr = (rptr + 1) & (QUEUE_LEN - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikbd_joystick(unsigned char joystick, unsigned char map)
|
void ikbd_joystick(unsigned char joystick, unsigned char map)
|
||||||
{
|
{
|
||||||
// todo: suppress events for joystick 0 as long as mouse
|
// todo: suppress events for joystick 0 as long as mouse
|
||||||
// is enabled?
|
// is enabled?
|
||||||
|
|
||||||
if (ikbd.state & IKBD_STATE_JOYSTICK_EVENT_REPORTING)
|
if (ikbd.state & IKBD_STATE_JOYSTICK_EVENT_REPORTING)
|
||||||
{
|
{
|
||||||
#ifdef IKBD_DEBUG
|
#ifdef IKBD_DEBUG
|
||||||
xprintf("IKBD: joy %d %x\n", joystick, map);
|
xprintf("IKBD: joy %d %x\n", joystick, map);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// only report joystick data for joystick 0 if the mouse is disabled
|
// only report joystick data for joystick 0 if the mouse is disabled
|
||||||
if ((ikbd.state & IKBD_STATE_MOUSE_DISABLED) || (joystick == 1))
|
if ((ikbd.state & IKBD_STATE_MOUSE_DISABLED) || (joystick == 1))
|
||||||
{
|
{
|
||||||
enqueue(0xfe + joystick);
|
enqueue(0xfe + joystick);
|
||||||
enqueue(joystick_map2ikbd(map));
|
enqueue(joystick_map2ikbd(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ikbd.state & IKBD_STATE_MOUSE_DISABLED))
|
if (!(ikbd.state & IKBD_STATE_MOUSE_DISABLED))
|
||||||
{
|
{
|
||||||
// the fire button also generates a mouse event if
|
// the fire button also generates a mouse event if
|
||||||
// mouse reporting is enabled
|
// mouse reporting is enabled
|
||||||
if ((map & JOY_BTN1) != (ikbd.joystick[joystick] & JOY_BTN1))
|
if ((map & JOY_BTN1) != (ikbd.joystick[joystick] & JOY_BTN1))
|
||||||
{
|
{
|
||||||
// generate mouse event (ikbd_joystick_buttons is evaluated inside
|
// generate mouse event (ikbd_joystick_buttons is evaluated inside
|
||||||
// user_io_mouse)
|
// user_io_mouse)
|
||||||
ikbd.joystick[joystick] = map;
|
ikbd.joystick[joystick] = map;
|
||||||
ikbd_mouse(0, 0, 0);
|
ikbd_mouse(0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef IKBD_DEBUG
|
#ifdef IKBD_DEBUG
|
||||||
else
|
else
|
||||||
xprintf("IKBD: no monitor, drop joy %d %x\n", joystick, map);
|
xprintf("IKBD: no monitor, drop joy %d %x\n", joystick, map);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// save state of joystick for interrogation mode
|
// save state of joystick for interrogation mode
|
||||||
ikbd.joystick[joystick] = map;
|
ikbd.joystick[joystick] = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikbd_keyboard(unsigned char code)
|
void ikbd_keyboard(unsigned char code)
|
||||||
{
|
{
|
||||||
#ifdef IKBD_DEBUG
|
#ifdef IKBD_DEBUG
|
||||||
xprintf("IKBD: send keycode %x%s\n", code&0x7f, (code&0x80)?" BREAK":"");
|
xprintf("IKBD: send keycode %x%s\n", code&0x7f, (code&0x80)?" BREAK":"");
|
||||||
#endif
|
#endif
|
||||||
enqueue(code);
|
enqueue(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikbd_mouse(uint8_t b, int8_t x, int8_t y)
|
void ikbd_mouse(uint8_t b, int8_t x, int8_t y)
|
||||||
{
|
{
|
||||||
if (ikbd.state & IKBD_STATE_MOUSE_DISABLED)
|
if (ikbd.state & IKBD_STATE_MOUSE_DISABLED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// joystick and mouse buttons are wired together in
|
// joystick and mouse buttons are wired together in
|
||||||
// atari st
|
// atari st
|
||||||
b |= (ikbd.joystick[0] & JOY_BTN1)?1:0;
|
b |= (ikbd.joystick[0] & JOY_BTN1)?1:0;
|
||||||
b |= (ikbd.joystick[1] & JOY_BTN1)?2:0;
|
b |= (ikbd.joystick[1] & JOY_BTN1)?2:0;
|
||||||
|
|
||||||
static unsigned char b_old = 0;
|
static unsigned char b_old = 0;
|
||||||
// monitor state of two mouse buttons
|
// monitor state of two mouse buttons
|
||||||
if (b != b_old)
|
if (b != b_old)
|
||||||
{
|
{
|
||||||
// check if mouse buttons are supposed to be treated like keys
|
// check if mouse buttons are supposed to be treated like keys
|
||||||
if (ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY)
|
if (ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY)
|
||||||
{
|
{
|
||||||
// Mouse buttons act like keys (LEFT=0x74 & RIGHT=0x75)
|
// Mouse buttons act like keys (LEFT=0x74 & RIGHT=0x75)
|
||||||
|
|
||||||
// handle left mouse button
|
// handle left mouse button
|
||||||
if((b ^ b_old) & 1) ikbd_keyboard(0x74 | ((b&1)?0x00:0x80));
|
if((b ^ b_old) & 1) ikbd_keyboard(0x74 | ((b&1)?0x00:0x80));
|
||||||
// handle right mouse button
|
// handle right mouse button
|
||||||
if((b ^ b_old) & 2) ikbd_keyboard(0x75 | ((b&2)?0x00:0x80));
|
if((b ^ b_old) & 2) ikbd_keyboard(0x75 | ((b&2)?0x00:0x80));
|
||||||
}
|
}
|
||||||
b_old = b;
|
b_old = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if(ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY)
|
if(ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY)
|
||||||
{
|
{
|
||||||
b = 0;
|
b = 0;
|
||||||
// if mouse position is 0/0 quit here
|
// if mouse position is 0/0 quit here
|
||||||
if(!x && !y) return;
|
if(!x && !y) return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE)
|
if (ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// atari has mouse button bits swapped
|
// atari has mouse button bits swapped
|
||||||
enqueue(0xf8|((b&1)?2:0)|((b&2)?1:0));
|
enqueue(0xf8|((b&1)?2:0)|((b&2)?1:0));
|
||||||
enqueue(x);
|
enqueue(x);
|
||||||
enqueue((ikbd.state & IKBD_STATE_MOUSE_Y_BOTTOM)?-y:y);
|
enqueue((ikbd.state & IKBD_STATE_MOUSE_Y_BOTTOM)?-y:y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
net/ip.c
25
net/ip.c
@@ -6,11 +6,10 @@
|
|||||||
*
|
*
|
||||||
* Modifications:
|
* Modifications:
|
||||||
*/
|
*/
|
||||||
|
#include <bas_types.h>
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "bas_string.h"
|
#include "bas_string.h"
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define IP_DEBUG
|
#define IP_DEBUG
|
||||||
@@ -44,7 +43,7 @@ uint8_t *ip_get_myip(IP_INFO *info)
|
|||||||
{
|
{
|
||||||
return (uint8_t *) &info->myip[0];
|
return (uint8_t *) &info->myip[0];
|
||||||
}
|
}
|
||||||
dbg("info is NULL!\n\t");
|
dbg("info is NULL!\n\t");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,9 +73,9 @@ uint8_t *ip_resolve_route(NIF *nif, IP_ADDR_P destip)
|
|||||||
|
|
||||||
info = nif_get_protocol_info(nif, ETH_FRM_IP);
|
info = nif_get_protocol_info(nif, ETH_FRM_IP);
|
||||||
|
|
||||||
if (memcmp(destip, bc, 4) == 0)
|
if (memcmp(destip, bc, 4) == 0)
|
||||||
{
|
{
|
||||||
dbg("destip is broadcast address, no gateway needed\r\n");
|
dbg("destip is broadcast address, no gateway needed\r\n");
|
||||||
return destip;
|
return destip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +169,7 @@ int ip_send(NIF *nif, uint8_t *dest, uint8_t *src, uint8_t protocol, NBUF *pNbuf
|
|||||||
route = ip_resolve_route(nif, dest);
|
route = ip_resolve_route(nif, dest);
|
||||||
if (route == NULL)
|
if (route == NULL)
|
||||||
{
|
{
|
||||||
dbg("Unable to locate %d.%d.%d.%d\r\n",
|
dbg("Unable to locate %d.%d.%d.%d\r\n",
|
||||||
dest[0], dest[1], dest[2], dest[3]);
|
dest[0], dest[1], dest[2], dest[3]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -178,9 +177,9 @@ int ip_send(NIF *nif, uint8_t *dest, uint8_t *src, uint8_t protocol, NBUF *pNbuf
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
route = bc;
|
route = bc;
|
||||||
dbg("route = broadcast\r\n");
|
dbg("route = broadcast\r\n");
|
||||||
dbg("nif = %p\r\n", nif);
|
dbg("nif = %p\r\n", nif);
|
||||||
dbg("nif->send = %p\r\n", nif->send);
|
dbg("nif->send = %p\r\n", nif->send);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nif->send(nif, route, &nif->hwa[0], ETH_FRM_IP, pNbuf);
|
return nif->send(nif, route, &nif->hwa[0], ETH_FRM_IP, pNbuf);
|
||||||
@@ -282,7 +281,7 @@ void ip_handler(NIF *nif, NBUF *pNbuf)
|
|||||||
*/
|
*/
|
||||||
ip_frame_hdr *ipframe;
|
ip_frame_hdr *ipframe;
|
||||||
|
|
||||||
dbg("packet received\r\n");
|
dbg("packet received\r\n");
|
||||||
|
|
||||||
ipframe = (ip_frame_hdr *) &pNbuf->data[pNbuf->offset];
|
ipframe = (ip_frame_hdr *) &pNbuf->data[pNbuf->offset];
|
||||||
|
|
||||||
@@ -291,8 +290,8 @@ void ip_handler(NIF *nif, NBUF *pNbuf)
|
|||||||
*/
|
*/
|
||||||
if (!validate_ip_hdr(nif, ipframe))
|
if (!validate_ip_hdr(nif, ipframe))
|
||||||
{
|
{
|
||||||
dbg("not a valid IP packet!\r\n");
|
dbg("not a valid IP packet!\r\n");
|
||||||
|
|
||||||
nbuf_free(pNbuf);
|
nbuf_free(pNbuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -312,7 +311,7 @@ void ip_handler(NIF *nif, NBUF *pNbuf)
|
|||||||
udp_handler(nif,pNbuf);
|
udp_handler(nif,pNbuf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dbg("no protocol handler registered for protocol %d\r\n",
|
dbg("no protocol handler registered for protocol %d\r\n",
|
||||||
__FUNCTION__, IP_PROTOCOL(ipframe));
|
__FUNCTION__, IP_PROTOCOL(ipframe));
|
||||||
nbuf_free(pNbuf);
|
nbuf_free(pNbuf);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -5,9 +5,8 @@
|
|||||||
*
|
*
|
||||||
* Notes:
|
* Notes:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "net_timer.h"
|
#include "net_timer.h"
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "MCF5475.h"
|
#include "MCF5475.h"
|
||||||
#include "interrupts.h"
|
#include "interrupts.h"
|
||||||
@@ -43,12 +42,12 @@ int timer_default_isr(void *not_used, NET_TIMER *t)
|
|||||||
{
|
{
|
||||||
(void) not_used;
|
(void) not_used;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clear the pending event
|
* Clear the pending event
|
||||||
*/
|
*/
|
||||||
MCF_GPT_GMS(t->ch) = 0;
|
MCF_GPT_GMS(t->ch) = 0;
|
||||||
|
|
||||||
dbg("timer isr called for timer channel %d\r\n");
|
dbg("timer isr called for timer channel %d\r\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clear the reference - the desired seconds have expired
|
* Clear the reference - the desired seconds have expired
|
||||||
@@ -90,8 +89,8 @@ bool timer_set_secs(uint8_t ch, uint32_t secs)
|
|||||||
*/
|
*/
|
||||||
MCF_GPT_GMS(ch) = 0;
|
MCF_GPT_GMS(ch) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the timeout in seconds
|
* Get the timeout in seconds
|
||||||
*/
|
*/
|
||||||
timeout = (uint16_t)(secs * net_timer[ch].cnt);
|
timeout = (uint16_t)(secs * net_timer[ch].cnt);
|
||||||
|
|
||||||
@@ -119,21 +118,21 @@ bool timer_set_secs(uint8_t ch, uint32_t secs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t timer_get_reference(uint8_t ch)
|
uint32_t timer_get_reference(uint8_t ch)
|
||||||
{
|
{
|
||||||
return (uint32_t) net_timer[ch].reference;
|
return (uint32_t) net_timer[ch].reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri)
|
bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Initialize the timer to expire after one second
|
* Initialize the timer to expire after one second
|
||||||
*
|
*
|
||||||
* This routine should only be called by the project (board) specific
|
* This routine should only be called by the project (board) specific
|
||||||
* initialization code.
|
* initialization code.
|
||||||
*/
|
*/
|
||||||
if (!((ch <= 3) && (lvl <= 7) && (lvl >= 1) && (pri <= 7)))
|
if (!((ch <= 3) && (lvl <= 7) && (lvl >= 1) && (pri <= 7)))
|
||||||
{
|
{
|
||||||
dbg("illegal parameters (ch=%d, lvl=%d, pri=%d)\r\n", ch, lvl, pri);
|
dbg("illegal parameters (ch=%d, lvl=%d, pri=%d)\r\n", ch, lvl, pri);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -143,7 +142,7 @@ bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri)
|
|||||||
*/
|
*/
|
||||||
MCF_GPT_GMS(ch) = 0;
|
MCF_GPT_GMS(ch) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save off the channel, and interrupt lvl/pri information
|
* Save off the channel, and interrupt lvl/pri information
|
||||||
*/
|
*/
|
||||||
net_timer[ch].ch = ch;
|
net_timer[ch].ch = ch;
|
||||||
@@ -153,16 +152,16 @@ bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri)
|
|||||||
/*
|
/*
|
||||||
* Register the timer interrupt handler
|
* Register the timer interrupt handler
|
||||||
*/
|
*/
|
||||||
if (!isr_register_handler(TIMER_VECTOR(ch),
|
if (!isr_register_handler(TIMER_VECTOR(ch),
|
||||||
(int (*)(void *,void *)) timer_default_isr,
|
(int (*)(void *,void *)) timer_default_isr,
|
||||||
NULL,
|
NULL,
|
||||||
(void *) &net_timer[ch])
|
(void *) &net_timer[ch])
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
dbg("could not register timer interrupt handler\r\n");
|
dbg("could not register timer interrupt handler\r\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dbg("timer handler registered\r\n", __FUNCTION__);
|
dbg("timer handler registered\r\n", __FUNCTION__);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate the require CNT value to get a 1 second timeout
|
* Calculate the require CNT value to get a 1 second timeout
|
||||||
@@ -172,9 +171,9 @@ bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri)
|
|||||||
* CNT = Clk Freq / PRE
|
* CNT = Clk Freq / PRE
|
||||||
*
|
*
|
||||||
* The system clock frequency is defined as SYSTEM_CLOCK and
|
* The system clock frequency is defined as SYSTEM_CLOCK and
|
||||||
* is given in MHz. We need to multiple it by 1000000 to get the
|
* is given in MHz. We need to multiple it by 1000000 to get the
|
||||||
* true value. If we assume PRE to be the maximum of 0xFFFF,
|
* true value. If we assume PRE to be the maximum of 0xFFFF,
|
||||||
* then the CNT value needed to achieve a 1 second timeout is
|
* then the CNT value needed to achieve a 1 second timeout is
|
||||||
* given by:
|
* given by:
|
||||||
*
|
*
|
||||||
* CNT = SYSTEM_CLOCK * (1000000/0xFFFF)
|
* CNT = SYSTEM_CLOCK * (1000000/0xFFFF)
|
||||||
@@ -182,10 +181,10 @@ bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri)
|
|||||||
net_timer[ch].pre = 0xFFFF;
|
net_timer[ch].pre = 0xFFFF;
|
||||||
net_timer[ch].cnt = (uint16_t) ((SYSCLK / 1000) * (1000000 / 0xFFFF));
|
net_timer[ch].cnt = (uint16_t) ((SYSCLK / 1000) * (1000000 / 0xFFFF));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save off the appropriate mode select register value
|
* Save off the appropriate mode select register value
|
||||||
*/
|
*/
|
||||||
net_timer[ch].gms = (0
|
net_timer[ch].gms = (0
|
||||||
| MCF_GPT_GMS_TMS_GPIO
|
| MCF_GPT_GMS_TMS_GPIO
|
||||||
| MCF_GPT_GMS_IEN
|
| MCF_GPT_GMS_IEN
|
||||||
| MCF_GPT_GMS_SC
|
| MCF_GPT_GMS_SC
|
||||||
|
|||||||
11
net/nif.c
11
net/nif.c
@@ -11,9 +11,6 @@
|
|||||||
#include "bas_types.h"
|
#include "bas_types.h"
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#define DBG_NIF
|
#define DBG_NIF
|
||||||
#ifdef DBG_NIF
|
#ifdef DBG_NIF
|
||||||
#define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0)
|
#define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0)
|
||||||
@@ -56,13 +53,13 @@ void nif_protocol_handler(NIF *nif, uint16_t protocol, NBUF *pNbuf)
|
|||||||
{
|
{
|
||||||
if (nif->protocol[index].protocol == protocol)
|
if (nif->protocol[index].protocol == protocol)
|
||||||
{
|
{
|
||||||
dbg("call protocol handler for protocol %d at %p\r\n", protocol,
|
dbg("call protocol handler for protocol %d at %p\r\n", protocol,
|
||||||
nif->protocol[index].handler);
|
nif->protocol[index].handler);
|
||||||
nif->protocol[index].handler(nif,pNbuf);
|
nif->protocol[index].handler(nif,pNbuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg("no protocol handler found for protocol %d\r\n", protocol);
|
dbg("no protocol handler found for protocol %d\r\n", protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *nif_get_protocol_info(NIF *nif, uint16_t protocol)
|
void *nif_get_protocol_info(NIF *nif, uint16_t protocol)
|
||||||
@@ -87,12 +84,12 @@ int nif_bind_protocol(NIF *nif, uint16_t protocol, void (*handler)(NIF *,NBUF *)
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* This function registers 'protocol' as a supported
|
* This function registers 'protocol' as a supported
|
||||||
* protocol in 'nif'.
|
* protocol in 'nif'.
|
||||||
*/
|
*/
|
||||||
if (nif->num_protocol < (MAX_SUP_PROTO - 1))
|
if (nif->num_protocol < (MAX_SUP_PROTO - 1))
|
||||||
{
|
{
|
||||||
nif->protocol[nif->num_protocol].protocol = protocol;
|
nif->protocol[nif->num_protocol].protocol = protocol;
|
||||||
nif->protocol[nif->num_protocol].handler = (void(*)(NIF *, NBUF *)) handler;
|
nif->protocol[nif->num_protocol].handler = (void(*)(NIF *, NBUF *)) handler;
|
||||||
nif->protocol[nif->num_protocol].info = info;
|
nif->protocol[nif->num_protocol].info = info;
|
||||||
++nif->num_protocol;
|
++nif->num_protocol;
|
||||||
|
|
||||||
|
|||||||
31
net/tftp.c
31
net/tftp.c
@@ -9,10 +9,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "bas_types.h"
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "bas_string.h"
|
#include "bas_string.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
@@ -103,7 +100,7 @@ static int tftp_ack(uint16_t blocknum)
|
|||||||
nbuf_free(pNbuf);
|
nbuf_free(pNbuf);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tftp_error(uint16_t error_code, uint16_t server_port)
|
static int tftp_error(uint16_t error_code, uint16_t server_port)
|
||||||
{
|
{
|
||||||
@@ -172,7 +169,7 @@ void tftp_handler(NIF *nif, NBUF *pNbuf)
|
|||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Check the server's transfer ID */
|
/* Check the server's transfer ID */
|
||||||
if (tcxn.server_port != UDP_SOURCE(udpframe))
|
if (tcxn.server_port != UDP_SOURCE(udpframe))
|
||||||
{
|
{
|
||||||
@@ -274,10 +271,10 @@ void tftp_handler(NIF *nif, NBUF *pNbuf)
|
|||||||
|
|
||||||
void tftp_end(int success)
|
void tftp_end(int success)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Following a successful transfer the caller should pass in
|
* Following a successful transfer the caller should pass in
|
||||||
* true, there should have been no ERROR packets received, and
|
* true, there should have been no ERROR packets received, and
|
||||||
* the connection should have been marked as closed by the
|
* the connection should have been marked as closed by the
|
||||||
* tftp_in_char() routine.
|
* tftp_in_char() routine.
|
||||||
*/
|
*/
|
||||||
if (success && !tcxn.error && (tcxn.open == false))
|
if (success && !tcxn.error && (tcxn.open == false))
|
||||||
@@ -411,10 +408,10 @@ int tftp_write(NIF *nif, char *fn, IP_ADDR_P server, uint32_t begin, uint32_t en
|
|||||||
/* Attempt to send the packet */
|
/* Attempt to send the packet */
|
||||||
for (i = 0; i < 3; ++i)
|
for (i = 0; i < 3; ++i)
|
||||||
{
|
{
|
||||||
result = udp_send(tcxn.nif,
|
result = udp_send(tcxn.nif,
|
||||||
tcxn.server_ip,
|
tcxn.server_ip,
|
||||||
tcxn.my_port,
|
tcxn.my_port,
|
||||||
tcxn.server_port,
|
tcxn.server_port,
|
||||||
pNbuf);
|
pNbuf);
|
||||||
|
|
||||||
if (result == 1)
|
if (result == 1)
|
||||||
@@ -552,8 +549,8 @@ int tftp_in_char(void)
|
|||||||
|
|
||||||
if (tcxn.next_char != NULL)
|
if (tcxn.next_char != NULL)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* A buffer is already being worked on - grab next
|
* A buffer is already being worked on - grab next
|
||||||
* byte from it
|
* byte from it
|
||||||
*/
|
*/
|
||||||
retval = *tcxn.next_char++;
|
retval = *tcxn.next_char++;
|
||||||
@@ -561,7 +558,7 @@ int tftp_in_char(void)
|
|||||||
{
|
{
|
||||||
/* The buffer is depleted; add it back to the free queue */
|
/* The buffer is depleted; add it back to the free queue */
|
||||||
pNbuf = (NBUF *)queue_remove(&tcxn.queue);
|
pNbuf = (NBUF *)queue_remove(&tcxn.queue);
|
||||||
|
|
||||||
nbuf_free(pNbuf);
|
nbuf_free(pNbuf);
|
||||||
tcxn.next_char = NULL;
|
tcxn.next_char = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
16
pci/pci.c
16
pci/pci.c
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include <MCF5475.h>
|
#include <MCF5475.h>
|
||||||
#include "pci.h"
|
#include "pci.h"
|
||||||
#include "stdint.h"
|
#include "bas_types.h"
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "bas_string.h"
|
#include "bas_string.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@@ -187,7 +187,7 @@ static int32_t pci_call_interrupt_chain(int32_t handle, int32_t data)
|
|||||||
void irq5_handler(void)
|
void irq5_handler(void)
|
||||||
{
|
{
|
||||||
int32_t handle;
|
int32_t handle;
|
||||||
int32_t value = 0;
|
int32_t value = 0;
|
||||||
int32_t newvalue;
|
int32_t newvalue;
|
||||||
|
|
||||||
MCF_EPORT_EPFR |= (1 << 5); /* clear interrupt from edge port */
|
MCF_EPORT_EPFR |= (1 << 5); /* clear interrupt from edge port */
|
||||||
@@ -209,7 +209,7 @@ void irq5_handler(void)
|
|||||||
void irq7_handler(void)
|
void irq7_handler(void)
|
||||||
{
|
{
|
||||||
int32_t handle;
|
int32_t handle;
|
||||||
int32_t value = 0;
|
int32_t value = 0;
|
||||||
int32_t newvalue;
|
int32_t newvalue;
|
||||||
|
|
||||||
MCF_EPORT_EPFR |= (1 << 7);
|
MCF_EPORT_EPFR |= (1 << 7);
|
||||||
@@ -776,11 +776,11 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function)
|
|||||||
static uint32_t io_address = PCI_IO_OFFSET;
|
static uint32_t io_address = PCI_IO_OFFSET;
|
||||||
uint16_t cr;
|
uint16_t cr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* should make compiler happy (these are used only in debug builds)
|
* should make compiler happy (these are used only in debug builds)
|
||||||
*/
|
*/
|
||||||
(void) value;
|
(void) value;
|
||||||
(void) il;
|
(void) il;
|
||||||
|
|
||||||
/* determine pci handle from bus, device + function number */
|
/* determine pci handle from bus, device + function number */
|
||||||
handle = PCI_HANDLE(bus, device, function);
|
handle = PCI_HANDLE(bus, device, function);
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
* Author: mfro
|
* Author: mfro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <bas_types.h>
|
#include <bas_types.h>
|
||||||
#include <MCF5475.h>
|
#include <MCF5475.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <bas_types.h>
|
#include <bas_types.h>
|
||||||
#include <sd_card.h>
|
#include <sd_card.h>
|
||||||
#include <bas_printf.h>
|
#include <bas_printf.h>
|
||||||
@@ -466,7 +465,7 @@ DSTATUS disk_initialize(uint8_t drv)
|
|||||||
{
|
{
|
||||||
uint8_t buff[16];
|
uint8_t buff[16];
|
||||||
res = disk_ioctl(0, MMC_GET_CSD, buff);
|
res = disk_ioctl(0, MMC_GET_CSD, buff);
|
||||||
|
|
||||||
if (res == RES_OK)
|
if (res == RES_OK)
|
||||||
{
|
{
|
||||||
debug_printf("CSD of card:\r\n");
|
debug_printf("CSD of card:\r\n");
|
||||||
|
|||||||
@@ -21,8 +21,7 @@
|
|||||||
* Copyright 2012 M. Froeschle
|
* Copyright 2012 M. Froeschle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "MCF5475.h"
|
#include "MCF5475.h"
|
||||||
#include "startcf.h"
|
#include "startcf.h"
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
* option any later version.
|
* option any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include "bas_string.h"
|
#include "bas_string.h"
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|||||||
@@ -23,8 +23,7 @@
|
|||||||
* Author: Markus Fröschle
|
* Author: Markus Fröschle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <bas_types.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include "MCF5475.h"
|
#include "MCF5475.h"
|
||||||
#include "bas_utils.h"
|
#include "bas_utils.h"
|
||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user