main.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2018 bzt (bztsrc@github)
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. */
  25. #include "uart.h"
  26. #include "mbox.h"
  27. void main()
  28. {
  29. // set up serial console
  30. uart_init();
  31. // get the board's unique serial number with a mailbox call
  32. mbox[0] = 8*4; // length of the message
  33. mbox[1] = MBOX_REQUEST; // this is a request message
  34. mbox[2] = MBOX_TAG_GETSERIAL; // get serial number command
  35. mbox[3] = 8; // buffer size
  36. mbox[4] = 8;
  37. mbox[5] = 0; // clear output buffer
  38. mbox[6] = 0;
  39. mbox[7] = MBOX_TAG_LAST;
  40. // send the message to the GPU and receive answer
  41. if (mbox_call(MBOX_CH_PROP)) {
  42. uart_puts("My serial number is: ");
  43. uart_hex(mbox[6]);
  44. uart_hex(mbox[5]);
  45. uart_puts("\n");
  46. } else {
  47. uart_puts("Unable to query serial!\n");
  48. }
  49. // echo everything back
  50. while(1) {
  51. uart_send(uart_getc());
  52. }
  53. }