| Index: embios/trunk/init.c | 
| — | — | @@ -28,10 +28,10 @@ | 
| 29 | 29 | #include "lcdconsole.h" | 
| 30 | 30 | #include "interrupt.h" | 
| 31 | 31 | #include "i2c.h" | 
|  | 32 | +#include "pmu.h" | 
| 32 | 33 | #include "usb/usb.h" | 
| 33 | 34 |  | 
| 34 |  | -static const char welcomestring[] INITCONST_ATTR = "emBIOS v" VERSION "\n\nInitializing USB...";
 | 
| 35 |  | -static const char donestring[] INITCONST_ATTR =  " done\n";
 | 
|  | 35 | +static const char welcomestring[] INITCONST_ATTR = "emBIOS v" VERSION "\n\n"; | 
| 36 | 36 |  | 
| 37 | 37 | void init() INITCODE_ATTR; | 
| 38 | 38 | void init() | 
| — | — | @@ -41,8 +41,8 @@ | 
| 42 | 42 | lcd_init(); | 
| 43 | 43 | lcdconsole_init(); | 
| 44 | 44 | interrupt_init(); | 
|  | 45 | +    cputs(1, welcomestring); | 
| 45 | 46 | i2c_init(); | 
| 46 |  | -    cputs(1, welcomestring);
 | 
|  | 47 | +    pmu_init(); | 
| 47 | 48 | usb_init(); | 
| 48 |  | -    cputs(1, donestring);
 | 
| 49 | 49 | } | 
| \ No newline at end of file | 
| Index: embios/trunk/SOURCES | 
| — | — | @@ -6,6 +6,7 @@ | 
| 7 | 7 | target/ipodnano2g/timer.c | 
| 8 | 8 | target/ipodnano2g/i2c.c | 
| 9 | 9 | target/ipodnano2g/interrupt.c | 
|  | 10 | +target/ipodnano2g/pmu.c | 
| 10 | 11 | usb/synopsysotg.c | 
| 11 | 12 | #endif | 
| 12 | 13 |  | 
| — | — | @@ -32,3 +33,4 @@ | 
| 33 | 34 | ucl.S | 
| 34 | 35 | thread.c | 
| 35 | 36 | usb/usb.c | 
|  | 37 | +shutdown.c | 
| Index: embios/trunk/target/ipodnano2g/pmu.c | 
| — | — | @@ -0,0 +1,41 @@ | 
|  | 2 | +// | 
|  | 3 | +// | 
|  | 4 | +//    Copyright 2010 TheSeven | 
|  | 5 | +// | 
|  | 6 | +// | 
|  | 7 | +//    This file is part of emBIOS. | 
|  | 8 | +// | 
|  | 9 | +//    emBIOS is free software: you can redistribute it and/or | 
|  | 10 | +//    modify it under the terms of the GNU General Public License as | 
|  | 11 | +//    published by the Free Software Foundation, either version 2 of the | 
|  | 12 | +//    License, or (at your option) any later version. | 
|  | 13 | +// | 
|  | 14 | +//    emBIOS is distributed in the hope that it will be useful, | 
|  | 15 | +//    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 16 | +//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
|  | 17 | +//    See the GNU General Public License for more details. | 
|  | 18 | +// | 
|  | 19 | +//    You should have received a copy of the GNU General Public License along | 
|  | 20 | +//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>. | 
|  | 21 | +// | 
|  | 22 | +// | 
|  | 23 | + | 
|  | 24 | + | 
|  | 25 | +#include "global.h" | 
|  | 26 | +#include "i2c.h" | 
|  | 27 | +#include "pmu.h" | 
|  | 28 | +#include "thread.h" | 
|  | 29 | + | 
|  | 30 | + | 
|  | 31 | +static struct mutex pmumutex; | 
|  | 32 | + | 
|  | 33 | + | 
|  | 34 | +void pmu_init() | 
|  | 35 | +{ | 
|  | 36 | +    mutex_init(&pmumutex); | 
|  | 37 | +} | 
|  | 38 | + | 
|  | 39 | +void poweroff() | 
|  | 40 | +{ | 
|  | 41 | +    i2c_sendbyte(0, 0xe6, 0xc, 1); | 
|  | 42 | +} | 
| Index: embios/trunk/target/ipodnano2g/pmu.h | 
| — | — | @@ -0,0 +1,35 @@ | 
|  | 2 | +// | 
|  | 3 | +// | 
|  | 4 | +//    Copyright 2010 TheSeven | 
|  | 5 | +// | 
|  | 6 | +// | 
|  | 7 | +//    This file is part of emBIOS. | 
|  | 8 | +// | 
|  | 9 | +//    emBIOS is free software: you can redistribute it and/or | 
|  | 10 | +//    modify it under the terms of the GNU General Public License as | 
|  | 11 | +//    published by the Free Software Foundation, either version 2 of the | 
|  | 12 | +//    License, or (at your option) any later version. | 
|  | 13 | +// | 
|  | 14 | +//    emBIOS is distributed in the hope that it will be useful, | 
|  | 15 | +//    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 16 | +//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
|  | 17 | +//    See the GNU General Public License for more details. | 
|  | 18 | +// | 
|  | 19 | +//    You should have received a copy of the GNU General Public License along | 
|  | 20 | +//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>. | 
|  | 21 | +// | 
|  | 22 | +// | 
|  | 23 | + | 
|  | 24 | + | 
|  | 25 | +#ifndef __PMU_H__ | 
|  | 26 | +#define __PMU_H__ | 
|  | 27 | + | 
|  | 28 | + | 
|  | 29 | +#include "global.h" | 
|  | 30 | + | 
|  | 31 | + | 
|  | 32 | +void pmu_init(); | 
|  | 33 | +void poweroff(); | 
|  | 34 | + | 
|  | 35 | + | 
|  | 36 | +#endif | 
| Index: embios/trunk/usb/usb.c | 
| — | — | @@ -32,6 +32,8 @@ | 
| 33 | 33 | #include "i2c.h" | 
| 34 | 34 | #include "strlen.h" | 
| 35 | 35 | #include "contextswitch.h" | 
|  | 36 | +#include "pmu.h" | 
|  | 37 | +#include "shutdown.h" | 
| 36 | 38 |  | 
| 37 | 39 |  | 
| 38 | 40 | static uint8_t ctrlresp[2] CACHEALIGN_ATTR; | 
| — | — | @@ -45,7 +47,11 @@ | 
| 46 | 48 | DBGACTION_IDLE = 0, | 
| 47 | 49 | DBGACTION_I2CSEND, | 
| 48 | 50 | DBGACTION_I2CRECV, | 
| 49 |  | -    DBGACTION_POWEROFF
 | 
|  | 51 | +    DBGACTION_RESET, | 
|  | 52 | +    DBGACTION_POWEROFF, | 
|  | 53 | +    DBGACTION_CWRITE, | 
|  | 54 | +    DBGACTION_CREAD, | 
|  | 55 | +    DBGACTION_CFLUSH | 
| 50 | 56 | }; | 
| 51 | 57 |  | 
| 52 | 58 | static uint32_t dbgstack[0x100] STACK_ATTR; | 
| — | — | @@ -52,10 +58,12 @@ | 
| 53 | 59 | struct wakeup dbgwakeup IBSS_ATTR; | 
| 54 | 60 | extern struct scheduler_thread* scheduler_threads; | 
| 55 | 61 | static enum dbgaction_t dbgaction IBSS_ATTR; | 
| 56 |  | -static int dbgi2cbus IBSS_ATTR;
 | 
| 57 |  | -static int dbgi2cslave IBSS_ATTR;
 | 
| 58 |  | -static int dbgi2caddr IBSS_ATTR;
 | 
| 59 |  | -static int dbgi2clen IBSS_ATTR;
 | 
|  | 62 | +static int dbgi2cbus; | 
|  | 63 | +static int dbgi2cslave; | 
|  | 64 | +static int dbgactionaddr; | 
|  | 65 | +static int dbgactionlength; | 
|  | 66 | +static int dbgactionconsoles; | 
|  | 67 | +static int dbgactiontype; | 
| 60 | 68 | static char dbgconsendbuf[4096]; | 
| 61 | 69 | static char dbgconrecvbuf[1024]; | 
| 62 | 70 | static int dbgconsendreadidx IBSS_ATTR; | 
| — | — | @@ -281,12 +289,12 @@ | 
| 282 | 290 | } | 
| 283 | 291 | } | 
| 284 | 292 |  | 
| 285 |  | -bool set_dbgaction(enum dbgaction_t action)
 | 
|  | 293 | +bool set_dbgaction(enum dbgaction_t action, int addsize) | 
| 286 | 294 | { | 
| 287 | 295 | if (dbgaction != DBGACTION_IDLE) | 
| 288 | 296 | { | 
| 289 | 297 | dbgsendbuf[0] = 3; | 
| 290 |  | -        usb_drv_send_nonblocking(dbgendpoints[1], dbgsendbuf, 16);
 | 
|  | 298 | +        usb_drv_send_nonblocking(dbgendpoints[1], dbgsendbuf, 16 + addsize); | 
| 291 | 299 | return true; | 
| 292 | 300 | } | 
| 293 | 301 | dbgaction = action; | 
| — | — | @@ -325,10 +333,19 @@ | 
| 326 | 334 | } | 
| 327 | 335 | break; | 
| 328 | 336 | case 2:  // RESET | 
| 329 |  | -            reset();
 | 
|  | 337 | +            if (dbgrecvbuf[1]) | 
|  | 338 | +            { | 
|  | 339 | +                if (set_dbgaction(DBGACTION_RESET, 0)) break; | 
|  | 340 | +                dbgsendbuf[0] = 1; | 
|  | 341 | +                size = 16; | 
|  | 342 | +            } | 
|  | 343 | +            else reset(); | 
| 330 | 344 | break; | 
| 331 | 345 | case 3:  // POWER OFF | 
| 332 |  | -            set_dbgaction(DBGACTION_POWEROFF);
 | 
|  | 346 | +            if (set_dbgaction(DBGACTION_POWEROFF, 0)) break; | 
|  | 347 | +            dbgactiontype = dbgrecvbuf[1]; | 
|  | 348 | +            dbgsendbuf[0] = 1; | 
|  | 349 | +            size = 16; | 
| 333 | 350 | break; | 
| 334 | 351 | case 4:  // READ MEMORY | 
| 335 | 352 | dbgsendbuf[0] = 1; | 
| — | — | @@ -351,19 +368,19 @@ | 
| 352 | 369 | usb_drv_recv(dbgendpoints[2], (void*)dbgrecvbuf[1], dbgrecvbuf[2]); | 
| 353 | 370 | break; | 
| 354 | 371 | case 8:  // READ I2C | 
| 355 |  | -            if (set_dbgaction(DBGACTION_I2CRECV)) break;
 | 
|  | 372 | +            if (set_dbgaction(DBGACTION_I2CRECV, dbgrecvbuf[1] >> 24)) break; | 
| 356 | 373 | dbgi2cbus = dbgrecvbuf[1] & 0xff; | 
| 357 | 374 | dbgi2cslave = (dbgrecvbuf[1] >> 8) & 0xff; | 
| 358 |  | -            dbgi2caddr = (dbgrecvbuf[1] >> 16) & 0xff;
 | 
| 359 |  | -            dbgi2clen = dbgrecvbuf[1] >> 24;
 | 
|  | 375 | +            dbgactionaddr = (dbgrecvbuf[1] >> 16) & 0xff; | 
|  | 376 | +            dbgactionlength = dbgrecvbuf[1] >> 24; | 
| 360 | 377 | break; | 
| 361 | 378 | case 9:  // WRITE I2C | 
| 362 |  | -            if (set_dbgaction(DBGACTION_I2CSEND)) break;
 | 
|  | 379 | +            if (set_dbgaction(DBGACTION_I2CSEND, 0)) break; | 
| 363 | 380 | dbgi2cbus = dbgrecvbuf[1] & 0xff; | 
| 364 | 381 | dbgi2cslave = (dbgrecvbuf[1] >> 8) & 0xff; | 
| 365 |  | -            dbgi2caddr = (dbgrecvbuf[1] >> 16) & 0xff;
 | 
| 366 |  | -            dbgi2clen = dbgrecvbuf[1] >> 24;
 | 
| 367 |  | -            memcpy(dbgasyncsendbuf, &dbgsendbuf[4], dbgi2clen);
 | 
|  | 382 | +            dbgactionaddr = (dbgrecvbuf[1] >> 16) & 0xff; | 
|  | 383 | +            dbgactionlength = dbgrecvbuf[1] >> 24; | 
|  | 384 | +            memcpy(dbgasyncsendbuf, &dbgsendbuf[4], dbgactionlength); | 
| 368 | 385 | break; | 
| 369 | 386 | case 10:  // READ CONSOLE | 
| 370 | 387 | dbgconsoleattached = true; | 
| — | — | @@ -419,6 +436,21 @@ | 
| 420 | 437 | dbgsendbuf[3] = dbgconrecvreadidx - dbgconrecvwriteidx - 1; | 
| 421 | 438 | size = 16; | 
| 422 | 439 | break; | 
|  | 440 | +        case 12:  // CWRITE | 
|  | 441 | +            if (set_dbgaction(DBGACTION_CWRITE, 0)) break; | 
|  | 442 | +            dbgactionconsoles = dbgrecvbuf[1]; | 
|  | 443 | +            dbgactionlength = dbgrecvbuf[2]; | 
|  | 444 | +            memcpy(dbgasyncsendbuf, &dbgrecvbuf[4], dbgactionlength); | 
|  | 445 | +            break; | 
|  | 446 | +        case 13:  // CREAD | 
|  | 447 | +            if (set_dbgaction(DBGACTION_CREAD, dbgrecvbuf[2])) break; | 
|  | 448 | +            dbgactionconsoles = dbgrecvbuf[1]; | 
|  | 449 | +            dbgactionlength = dbgrecvbuf[2]; | 
|  | 450 | +            break; | 
|  | 451 | +        case 14:  // CFLUSH | 
|  | 452 | +            if (set_dbgaction(DBGACTION_CFLUSH, 0)) break; | 
|  | 453 | +            dbgactionconsoles = dbgrecvbuf[1]; | 
|  | 454 | +            break; | 
| 423 | 455 | default: | 
| 424 | 456 | dbgsendbuf[0] = 2; | 
| 425 | 457 | size = 16; | 
| — | — | @@ -461,18 +493,40 @@ | 
| 462 | 494 | switch (dbgaction) | 
| 463 | 495 | { | 
| 464 | 496 | case DBGACTION_I2CSEND: | 
| 465 |  | -                i2c_send(dbgi2cbus, dbgi2cslave, dbgi2caddr, (uint8_t*)dbgasyncsendbuf, dbgi2clen);
 | 
|  | 497 | +                i2c_send(dbgi2cbus, dbgi2cslave, dbgactionaddr, | 
|  | 498 | +                         (uint8_t*)dbgasyncsendbuf, dbgactionlength); | 
| 466 | 499 | dbgasyncsendbuf[0] = 1; | 
| 467 | 500 | usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16); | 
| 468 | 501 | break; | 
| 469 | 502 | case DBGACTION_I2CRECV: | 
| 470 |  | -                i2c_recv(dbgi2cbus, dbgi2cslave, dbgi2caddr,
 | 
| 471 |  | -                         (uint8_t*)(&dbgasyncsendbuf[4]), dbgi2clen);
 | 
|  | 503 | +                i2c_recv(dbgi2cbus, dbgi2cslave, dbgactionaddr, | 
|  | 504 | +                         (uint8_t*)(&dbgasyncsendbuf[4]), dbgactionlength); | 
| 472 | 505 | dbgasyncsendbuf[0] = 1; | 
| 473 |  | -                usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16 + dbgi2clen);
 | 
|  | 506 | +                usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16 + dbgactionlength); | 
| 474 | 507 | break; | 
| 475 | 508 | case DBGACTION_POWEROFF: | 
|  | 509 | +                if (dbgactiontype) shutdown(); | 
|  | 510 | +                poweroff(); | 
| 476 | 511 | break; | 
|  | 512 | +            case DBGACTION_RESET: | 
|  | 513 | +                shutdown(); | 
|  | 514 | +                reset(); | 
|  | 515 | +                break; | 
|  | 516 | +            case DBGACTION_CWRITE: | 
|  | 517 | +                cwrite(dbgactionconsoles, (const char*)dbgasyncsendbuf, dbgactionlength); | 
|  | 518 | +                dbgasyncsendbuf[0] = 1; | 
|  | 519 | +                usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16); | 
|  | 520 | +                break; | 
|  | 521 | +            case DBGACTION_CREAD: | 
|  | 522 | +                cread(dbgactionconsoles, (char*)&dbgasyncsendbuf[4], dbgactionlength, 0); | 
|  | 523 | +                dbgasyncsendbuf[0] = 1; | 
|  | 524 | +                usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16); | 
|  | 525 | +                break; | 
|  | 526 | +            case DBGACTION_CFLUSH: | 
|  | 527 | +                cflush(dbgactionconsoles); | 
|  | 528 | +                dbgasyncsendbuf[0] = 1; | 
|  | 529 | +                usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16); | 
|  | 530 | +                break; | 
| 477 | 531 | } | 
| 478 | 532 | dbgaction = DBGACTION_IDLE; | 
| 479 | 533 | } | 
| Index: embios/trunk/shutdown.c | 
| — | — | @@ -0,0 +1,29 @@ | 
|  | 2 | +// | 
|  | 3 | +// | 
|  | 4 | +//    Copyright 2010 TheSeven | 
|  | 5 | +// | 
|  | 6 | +// | 
|  | 7 | +//    This file is part of emBIOS. | 
|  | 8 | +// | 
|  | 9 | +//    emBIOS is free software: you can redistribute it and/or | 
|  | 10 | +//    modify it under the terms of the GNU General Public License as | 
|  | 11 | +//    published by the Free Software Foundation, either version 2 of the | 
|  | 12 | +//    License, or (at your option) any later version. | 
|  | 13 | +// | 
|  | 14 | +//    emBIOS is distributed in the hope that it will be useful, | 
|  | 15 | +//    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 16 | +//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
|  | 17 | +//    See the GNU General Public License for more details. | 
|  | 18 | +// | 
|  | 19 | +//    You should have received a copy of the GNU General Public License along | 
|  | 20 | +//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>. | 
|  | 21 | +// | 
|  | 22 | +// | 
|  | 23 | + | 
|  | 24 | + | 
|  | 25 | +#include "global.h" | 
|  | 26 | + | 
|  | 27 | + | 
|  | 28 | +void shutdown() | 
|  | 29 | +{ | 
|  | 30 | +} | 
| Index: embios/trunk/shutdown.h | 
| — | — | @@ -0,0 +1,34 @@ | 
|  | 2 | +// | 
|  | 3 | +// | 
|  | 4 | +//    Copyright 2010 TheSeven | 
|  | 5 | +// | 
|  | 6 | +// | 
|  | 7 | +//    This file is part of emBIOS. | 
|  | 8 | +// | 
|  | 9 | +//    emBIOS is free software: you can redistribute it and/or | 
|  | 10 | +//    modify it under the terms of the GNU General Public License as | 
|  | 11 | +//    published by the Free Software Foundation, either version 2 of the | 
|  | 12 | +//    License, or (at your option) any later version. | 
|  | 13 | +// | 
|  | 14 | +//    emBIOS is distributed in the hope that it will be useful, | 
|  | 15 | +//    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 16 | +//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
|  | 17 | +//    See the GNU General Public License for more details. | 
|  | 18 | +// | 
|  | 19 | +//    You should have received a copy of the GNU General Public License along | 
|  | 20 | +//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>. | 
|  | 21 | +// | 
|  | 22 | +// | 
|  | 23 | + | 
|  | 24 | + | 
|  | 25 | +#ifndef __SHUTDOWN_H__ | 
|  | 26 | +#define __SHUTDOWN_H__ | 
|  | 27 | + | 
|  | 28 | + | 
|  | 29 | +#include "global.h" | 
|  | 30 | + | 
|  | 31 | + | 
|  | 32 | +void shutdown(); | 
|  | 33 | + | 
|  | 34 | + | 
|  | 35 | +#endif |