cc2538_hal.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "hw_memmap.h"
  2. #include "hw_types.h"
  3. #include "hw_ioc.h"
  4. #include "gpio.h"
  5. #include "sys_ctrl.h"
  6. #include "uart.h"
  7. #include "gpio.h"
  8. #include "ioc.h"
  9. #include <stdint.h>
  10. #include <stdlib.h>
  11. //#define TRIG_PIN 0x07
  12. #define TRIG_PIN GPIO_PIN_2
  13. #define TRIG_PORT GPIO_B_BASE
  14. #define UART_RX_PIN GPIO_PIN_4
  15. #define UART_TX_PIN GPIO_PIN_5
  16. #define UART_PORT GPIO_B_BASE
  17. void platform_init(void)
  18. {
  19. SysCtrlClockSet(false, true, SYS_CTRL_SYSDIV_16MHZ); //32MHz ext clock
  20. SysCtrlIOClockSet(SYS_CTRL_SYSDIV_16MHZ); //io clk same as sys clk
  21. }
  22. void init_uart(void)
  23. {
  24. SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART1); //enable uart
  25. UARTDisable(UART1_BASE); //disable UART
  26. UARTIntDisable(UART1_BASE, 0x1FFF); //disable uart interrupts
  27. UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC); //IO clk as uart clock source
  28. IOCPinConfigPeriphOutput(UART_PORT, UART_TX_PIN, IOC_MUX_OUT_SEL_UART1_TXD); //PB5 as TX
  29. GPIOPinTypeUARTOutput(UART_PORT, UART_TX_PIN);
  30. IOCPinConfigPeriphInput(UART_PORT, UART_RX_PIN, IOC_UARTRXD_UART1); //PB4 as RX
  31. GPIOPinTypeUARTInput(UART_PORT, UART_RX_PIN);
  32. //UART 38400 baud 8-N-1 operation
  33. UARTConfigSetExpClk(UART1_BASE, SysCtrlClockGet(), 38400,
  34. (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
  35. UARTEnable(UART1_BASE);
  36. }
  37. void putch(char c)
  38. {
  39. UARTCharPut(UART1_BASE, c);
  40. }
  41. char getch(void)
  42. {
  43. char c = UARTCharGet(UART1_BASE);
  44. return c;
  45. }
  46. void trigger_setup(void)
  47. {
  48. GPIOPinTypeGPIOOutput(TRIG_PORT, TRIG_PIN); //let's try this
  49. GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_PIN_0);
  50. }
  51. void trigger_low(void)
  52. {
  53. GPIOPinWrite(TRIG_PORT, TRIG_PIN, 0); //should leave rest of pins alone
  54. GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_0, 0);
  55. }
  56. void trigger_high(void)
  57. {
  58. GPIOPinWrite(TRIG_PORT, TRIG_PIN, 0xFF); //should leave rest of pins alone
  59. GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_0, 1);
  60. }
  61. /*
  62. int main(void)
  63. {
  64. GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_PIN_0);
  65. GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_PIN_1);
  66. GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_0, 0);
  67. GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_1, 1);
  68. while(1) {
  69. volatile uint32_t a;
  70. for (a = 0; a < 500000; a++);
  71. GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_0, 0);
  72. for (a = 0; a < 500000; a++);
  73. GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_0, 1);
  74. }
  75. return 0;
  76. }*/