/pinkos/pinkos.c

https://github.com/tobyjaffey/pinkos · C · 152 lines · 97 code · 19 blank · 36 comment · 5 complexity · 3cc4ea0d9404d603caf549d17eef122d MD5 · raw file

  1. /*
  2. * This file is part of PinkOS
  3. * Copyright (c) 2010, Joby Taffey <jrt@hodgepig.org>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the name of the <organization> nor the
  14. * names of its contributors may be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "common.h"
  29. #include "watchdog.h"
  30. #include "clock.h"
  31. #include "console.h"
  32. #include "led.h"
  33. #include "radio.h"
  34. #include "packet.h"
  35. #ifdef BOARD_IMME_HANDSET
  36. #include "key.h"
  37. #include "spi.h"
  38. #include "lcd.h"
  39. #include "lcdterm.h"
  40. #endif
  41. #ifdef BOARD_IMME_DONGLE
  42. #include "uart0.h"
  43. #endif
  44. static void banner(void)
  45. {
  46. led_on();
  47. clock_delayms(100);
  48. console_puts("PinkOS r");
  49. console_putdec(BUILD_VERSION);
  50. console_puts(" address 0x");
  51. console_puthex8(ADDR);
  52. console_newline();
  53. console_newline();
  54. led_off();
  55. clock_delayms(100);
  56. }
  57. int main(void)
  58. {
  59. watchdog_init();
  60. clock_init();
  61. led_init();
  62. #ifdef BOARD_IMME_DONGLE
  63. uart0_init();
  64. #endif
  65. #ifdef BOARD_IMME_HANDSET
  66. spi_init();
  67. key_init();
  68. lcdterm_init();
  69. #endif
  70. radio_init(DEVADDR);
  71. /* Enable global interrupts handled by bootloader */
  72. F1 = 1;
  73. EA = 1;
  74. console_init();
  75. banner();
  76. console_prompt();
  77. while(1)
  78. {
  79. #ifdef BOARD_IMME_HANDSET
  80. lcdterm_tick();
  81. #endif
  82. console_tick();
  83. radio_tick();
  84. }
  85. }
  86. /* handle incoming radio packet */
  87. void packet_rx_callback(uint8_t srcAddr, uint8_t seq, uint8_t type, const data uint8_t *buf, uint8_t len)
  88. {
  89. switch(type)
  90. {
  91. case PACKET_TYPE_ACK:
  92. console_puts("ACK 0x");
  93. console_puthex8(seq);
  94. console_puts(" from 0x");
  95. console_puthex8(srcAddr);
  96. console_newline();
  97. break;
  98. case PACKET_TYPE_PUTS:
  99. while(len--)
  100. console_putc(*buf++);
  101. console_newline();
  102. break;
  103. case PACKET_TYPE_LED:
  104. if (*buf)
  105. led_on();
  106. else
  107. led_off();
  108. break;
  109. #ifdef BOARD_IMME_HANDSET
  110. case PACKET_TYPE_GFXINIT:
  111. lcdterm_stop();
  112. break;
  113. case PACKET_TYPE_GFXPLOTLINE:
  114. lcd_cs(1);
  115. lcd_setNormalReverse(1);
  116. lcd_setPos(buf[0], buf[1]);
  117. len -= 2; /* x,y */
  118. buf += 2;
  119. while(len--)
  120. lcd_txData(*buf++);
  121. lcd_cs(0);
  122. break;
  123. #endif
  124. }
  125. }
  126. /*
  127. * "If you have multiple source fles in your project,
  128. * interrupt service routines can be present in any of them, but a
  129. * prototype of the isr MUST be present or included in the file that
  130. * contains the function main."
  131. * http://sdcc.sourceforge.net/doc/sdccman.pdf
  132. */
  133. #include "isr.c"