application.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * mbr - FLASH ROM based application header
  3. *
  4. * Copyright (c) 2009 Openmoko Inc.
  5. *
  6. * Authors Christopher Hall <hsw@openmoko.com>
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #if !defined(_APPLICATION_H_)
  22. #define _APPLICATION_H_
  23. #include <inttypes.h>
  24. #include <stdlib.h>
  25. #include <stdbool.h>
  26. #include <regs.h>
  27. #include <samo.h>
  28. #include <delay.h>
  29. #include <print.h>
  30. #include <console.h>
  31. #ifndef ARRAY_SIZE
  32. #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
  33. #endif
  34. #if !defined(APPLICATION_TITLE)
  35. #error "APPLICATION_TITLE must be defined before including application.h"
  36. #endif
  37. // setup and configure run time environment
  38. // the very first line of main() after the '}'
  39. #define APPLICATION_INITIALISE() \
  40. do { \
  41. asm volatile ("\txld.w\t%r15, __dp\n" \
  42. "\txld.w\t%r10, __SIZE_bss\n" \
  43. "\tor\t%r10, %r10\n" \
  44. "\tjreq\tclear_bss_done\n" \
  45. "\txld.w\t%r9, __START_bss\n" \
  46. "\txor\t%r8, %r8\n" \
  47. "clear_bss_loop:\n" \
  48. "\tld.w\t[%r9]+, %r8\n" \
  49. "\tsub\t%r10, 4\n" \
  50. "\tjrgt\tclear_bss_loop\n" \
  51. "clear_bss_done:\n" \
  52. ); \
  53. init_pins(); \
  54. init_rs232_ch0(); \
  55. init_rs232_ch1(); \
  56. init_ram(); \
  57. } while (0)
  58. // the last line of main() before the final '}'
  59. // at present just returns the next_program number to
  60. #define APPLICATION_FINALISE(next_program, status) \
  61. do { \
  62. ReturnType rc = {next_program, status}; \
  63. return (rc); \
  64. } while (0)
  65. __attribute__ ((packed))
  66. typedef struct {
  67. unsigned int block;
  68. unsigned int status;
  69. } ReturnType;
  70. typedef ReturnType application(int block, int status);
  71. #endif