main.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. ChibiOS - Copyright (C) 2016..2017 Theodore Ateba
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include "ch.h"
  14. #include "hal.h"
  15. #include "portab.h"
  16. static THD_WORKING_AREA(waThread1, 32);
  17. static THD_FUNCTION(Thread1, arg) {
  18. (void)arg;
  19. chRegSetThreadName("Blinker");
  20. while (true) {
  21. systime_t time = palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED ? 1000 :50;
  22. palToggleLine(PORTAB_LINE_LED1);
  23. palToggleLine(PORTAB_LINE_LED2);
  24. chThdSleepMilliseconds(time);
  25. }
  26. }
  27. /*
  28. * Application entry point.
  29. */
  30. int main(void) {
  31. /*
  32. * System initializations.
  33. * - HAL initialization, this also initializes the configured device drivers
  34. * and performs the board-specific initializations.
  35. * - Kernel initialization, the main() function becomes a thread and the
  36. * RTOS is active.
  37. */
  38. halInit();
  39. chSysInit();
  40. palSetPadMode(PAL_PORT(PORTAB_LINE_LED2),
  41. PAL_PAD(PORTAB_LINE_LED2),
  42. PAL_MODE_OUTPUT_PUSHPULL);
  43. /*
  44. * Starts the LED blinker thread.
  45. */
  46. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  47. while(TRUE) {
  48. chThdSleepMilliseconds(1000);
  49. }
  50. }