mirror of
git://projects.qi-hardware.com/iris.git
synced 2025-04-21 12:27:27 +03:00
move dbg_* to panic.ccp
This commit is contained in:
@@ -262,6 +262,10 @@ class Pwm:
|
||||
// TODO: make it really work as a pwm instead of a switch; check if pwm1 is connected to anything.
|
||||
|
||||
int main ():
|
||||
for unsigned i = 0; i < 10; ++i:
|
||||
schedule ()
|
||||
*(unsigned *)~3 = 0
|
||||
|
||||
map_gpio ()
|
||||
map_pwm0 ()
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ static void setup ():
|
||||
wait (&msg)
|
||||
switch msg.data[0]:
|
||||
case INIT_SET_GPIO_0:
|
||||
kdebug (0, 2)
|
||||
kdebug ("gpio 0")
|
||||
kbd = msg.cap[0]
|
||||
tp = msg.cap[1]
|
||||
poweroff = msg.cap[2]
|
||||
@@ -47,14 +47,14 @@ static void setup ():
|
||||
++state
|
||||
break
|
||||
case INIT_SET_GPIO_1:
|
||||
kdebug (1, 2)
|
||||
kdebug ("gpio 1")
|
||||
battery = msg.cap[0]
|
||||
lockleds = msg.cap[1]
|
||||
pwm = msg.cap[2]
|
||||
++state
|
||||
break
|
||||
case INIT_SET_LCD:
|
||||
kdebug (2, 2)
|
||||
kdebug ("lcd")
|
||||
lcd = msg.cap[0]
|
||||
++state
|
||||
break
|
||||
@@ -67,8 +67,10 @@ static void setup ():
|
||||
invoke_01 (pwm, 1)
|
||||
|
||||
int main ():
|
||||
for unsigned i = 0; i < 10; ++i:
|
||||
schedule ()
|
||||
setup ()
|
||||
kdebug (3, 2)
|
||||
kdebug ("start init")
|
||||
while true:
|
||||
Message msg
|
||||
wait (&msg)
|
||||
|
||||
@@ -24,10 +24,11 @@ __asm__ volatile (".globl charset\ncharset:\n.incbin \"boot-programs/charset.dat
|
||||
// I'm too lazy to do this right. The address of charset is really the address of the array.
|
||||
extern unsigned charset
|
||||
|
||||
#define assert(x) do { while (!(x)) kdebug (0, 0); } while (0)
|
||||
#define assert(x) do { while (!(x)) kdebug ("assertion failed " #x); } while (0)
|
||||
|
||||
enum types:
|
||||
LCD_EOF_CB = 32
|
||||
LCD_LOG
|
||||
|
||||
// For now, support only 16 bpp.
|
||||
// Screen is 800x480 tft.
|
||||
@@ -65,73 +66,20 @@ static void reset (unsigned physical_descriptor):
|
||||
|
||||
cpm_start_lcd ()
|
||||
|
||||
udelay (1000)
|
||||
LCD_DA0 = physical_descriptor
|
||||
lcd_set_ena ()
|
||||
lcd_enable_eof_intr ()
|
||||
|
||||
static void putchar (unsigned x, unsigned y, unsigned utf8, unsigned fg = 0xffff, unsigned bg = 0x0000):
|
||||
if utf8 < 32 || utf8 > 126:
|
||||
utf8 = 127
|
||||
unsigned idx = utf8 - 32
|
||||
unsigned char *c = &((unsigned char *)&charset)[idx * 6]
|
||||
static void putchar (unsigned x, unsigned y, unsigned ch, unsigned fg = 0xffff, unsigned bg = 0x0000):
|
||||
if ch < 32 || ch > 126:
|
||||
ch = 127
|
||||
ch -= 32
|
||||
unsigned char *c = &((unsigned char *)&charset)[ch * 6]
|
||||
unsigned lookup[2] = { bg, fg }
|
||||
for unsigned k = 0; k < 6; ++k:
|
||||
for unsigned r = 0; r < 8; ++r:
|
||||
LCD_FRAMEBUFFER_BASE[(y * 8 + r) * 800 + x * 6 + k] = lookup[c[k] & (1 << r) ? 1 : 0]
|
||||
|
||||
static unsigned read_rest (unsigned num, char const *&utf8):
|
||||
unsigned ret = 0
|
||||
while num--:
|
||||
if (*utf8 & 0xc0) != 0x80:
|
||||
return ~0
|
||||
ret <<= 6
|
||||
ret |= (*utf8++) & 0x3f
|
||||
return ret
|
||||
|
||||
static unsigned read_utf8 (char const *&utf8):
|
||||
unsigned c = *utf8++
|
||||
if !(c & 0x80):
|
||||
return c
|
||||
if !(c & 0x40):
|
||||
// Invalid character.
|
||||
return 0
|
||||
if !(c & 0x20):
|
||||
// 2-byte character.
|
||||
c &= 0x1f
|
||||
c <<= 6
|
||||
c |= read_rest (1, utf8)
|
||||
else if !(c & 0x10):
|
||||
// 3-byte character.
|
||||
c &= 0xf
|
||||
c <<= 12
|
||||
c |= read_rest (2, utf8)
|
||||
else if !(c & 0x8):
|
||||
// 4-byte character.
|
||||
c &= 0x7
|
||||
c <<= 18
|
||||
c |= read_rest (3, utf8)
|
||||
else if !(c & 0x4):
|
||||
// 5-byte character.
|
||||
c &= 0x3
|
||||
c <<= 24
|
||||
c |= read_rest (4, utf8)
|
||||
else if !(c & 0x2):
|
||||
// 6-byte character.
|
||||
c &= 0x1
|
||||
c <<= 30
|
||||
c |= read_rest (5, utf8)
|
||||
else
|
||||
// Invalid character.
|
||||
return 0
|
||||
if c == ~0:
|
||||
return 0
|
||||
return c
|
||||
|
||||
static void putstr (unsigned x, unsigned y, char const *utf8):
|
||||
while *utf8:
|
||||
putchar (x++, y, read_utf8 (utf8))
|
||||
|
||||
static unsigned log_x = 1, log_y = 1
|
||||
static void inc_logx ():
|
||||
if ++log_x >= 800 / 6:
|
||||
@@ -139,27 +87,45 @@ static void inc_logx ():
|
||||
if ++log_y >= 480 / 8:
|
||||
log_y = 1
|
||||
|
||||
static void log (char const *utf8):
|
||||
while *utf8:
|
||||
unsigned c = read_utf8 (utf8)
|
||||
switch c:
|
||||
case '\n':
|
||||
while log_x < 800 / 6:
|
||||
putchar (log_x++, log_y, ' ')
|
||||
inc_logx ()
|
||||
break
|
||||
default:
|
||||
putchar (log_x, log_y, c)
|
||||
inc_logx ()
|
||||
static void log_char (unsigned ch):
|
||||
switch ch:
|
||||
case '\n':
|
||||
while log_x < 800 / 6:
|
||||
putchar (log_x++, log_y, ' ')
|
||||
inc_logx ()
|
||||
break
|
||||
default:
|
||||
putchar (log_x, log_y, ch)
|
||||
inc_logx ()
|
||||
|
||||
static void log_str (char const *str):
|
||||
while *str:
|
||||
log_char (*str++)
|
||||
|
||||
static void log_num (unsigned n):
|
||||
char const *encode = "0123456789abcdef"
|
||||
log_char ('[')
|
||||
for unsigned i = 0; i < 8; ++i:
|
||||
log_char (encode[(n >> (7 - i)) & 0xf])
|
||||
log_char (']')
|
||||
|
||||
static void log_msg (Message *msg):
|
||||
log_str ("prot:")
|
||||
log_num (msg->protected_data)
|
||||
log_str ("data:")
|
||||
for unsigned i = 0; i < 4; ++i:
|
||||
log_num (msg->data[i])
|
||||
log_str ("cap:")
|
||||
for unsigned i = 0; i < 4; ++i:
|
||||
log_num (msg->cap[i])
|
||||
log_char ('\n')
|
||||
|
||||
int main ():
|
||||
// TODO: The descriptor takes an entire uncached page, because I don't know how to force a cache write-back. It's much better to do that instead.
|
||||
map_gpio ()
|
||||
map_pwm0 ()
|
||||
map_lcd ()
|
||||
map_cpm ()
|
||||
|
||||
unsigned pages = (frame_size + 16 + ~PAGE_MASK) >> PAGE_BITS
|
||||
Descriptor descriptor __attribute__ ((aligned (16)))
|
||||
unsigned pages = (frame_size + ~PAGE_MASK) >> PAGE_BITS
|
||||
assert (pages > CAPPAGE_SIZE && pages <= 2 * CAPPAGE_SIZE)
|
||||
unsigned physical = alloc_range (__my_memory, pages)
|
||||
assert (physical)
|
||||
@@ -195,15 +161,15 @@ int main ():
|
||||
ob = b
|
||||
b = 0x1f
|
||||
LCD_FRAMEBUFFER_BASE[y * 800 + x] = (r << 11) | (g << 5) | (b)
|
||||
log ("testing!\nIs dit een werkende console?\nLinks, rechts?\n")
|
||||
Descriptor *descriptor = (Descriptor *)((unsigned)LCD_FRAMEBUFFER_BASE + frame_size)
|
||||
unsigned physical_descriptor = physical + frame_size
|
||||
descriptor->next = physical_descriptor
|
||||
descriptor->frame = physical
|
||||
descriptor->id = 0xdeadbeef
|
||||
descriptor->cmd = LCD_CMD_EOFINT | ((frame_size / 4) << LCD_CMD_LEN_BIT)
|
||||
Capability page = memory_mapping (__my_memory, &descriptor)
|
||||
unsigned physical_descriptor = page_physical_address (page) + ((unsigned)&descriptor & ~PAGE_MASK)
|
||||
descriptor.next = physical_descriptor
|
||||
descriptor.frame = physical
|
||||
descriptor.id = 0xdeadbeef
|
||||
descriptor.cmd = LCD_CMD_EOFINT | ((frame_size / 4) << LCD_CMD_LEN_BIT)
|
||||
unsigned dptr = (unsigned)&descriptor
|
||||
__asm__ volatile ("lw $a0, %0\ncache 0x15, 0($a0)" :: "m"(dptr) : "memory", "a0")
|
||||
reset (physical_descriptor)
|
||||
register_interrupt (IRQ_LCD)
|
||||
|
||||
Capability eof_cb = 0
|
||||
|
||||
@@ -211,18 +177,27 @@ int main ():
|
||||
invoke_11 (__my_parent, cap, INIT_SET_LCD)
|
||||
drop (cap)
|
||||
|
||||
Capability logcap = receiver_create_capability (__my_receiver, LCD_LOG)
|
||||
__asm__ volatile ("li $a0, 1\nlw $a1, %0\nbreak" :: "m"(logcap) : "a0", "a1", "memory")
|
||||
|
||||
while true:
|
||||
Message msg
|
||||
wait (&msg)
|
||||
//log_msg (&msg)
|
||||
switch msg.protected_data:
|
||||
case IRQ_LCD:
|
||||
lcd_clr_eof ()
|
||||
register_interrupt (IRQ_LCD)
|
||||
if eof_cb:
|
||||
register_interrupt (IRQ_LCD)
|
||||
invoke_00 (eof_cb)
|
||||
break
|
||||
case LCD_EOF_CB:
|
||||
if eof_cb:
|
||||
drop (eof_cb)
|
||||
eof_cb = msg.cap[0]
|
||||
if eof_cb:
|
||||
register_interrupt (IRQ_LCD)
|
||||
break
|
||||
case LCD_LOG:
|
||||
log_char (msg.data[0])
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user