|
| 1 | +/* |
| 2 | +Copyright(c) 2017 Cedric Jimenez |
| 3 | +
|
| 4 | +This file is part of Nano-OS. |
| 5 | +
|
| 6 | +Nano-OS is free software: you can redistribute it and/or modify |
| 7 | +it under the terms of the GNU Lesser General Public License as published by |
| 8 | +the Free Software Foundation, either version 3 of the License, or |
| 9 | +(at your option) any later version. |
| 10 | +
|
| 11 | +Nano-OS is distributed in the hope that it will be useful, |
| 12 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +GNU Lesser General Public License for more details. |
| 15 | +
|
| 16 | +You should have received a copy of the GNU Lesser General Public License |
| 17 | +along with Nano-OS. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include "bsp.h" |
| 21 | +#include "chip_lpc43xx.h" |
| 22 | + |
| 23 | + |
| 24 | +/** \brief Get the SYSTICK input clock frequency in Hz */ |
| 25 | +uint32_t NANO_OS_PORT_USER_GetSystickInputClockFreq(void) |
| 26 | +{ |
| 27 | + /* 204 MHz */ |
| 28 | + return 204000000u; |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +/** \brief Initialize the board */ |
| 33 | +nano_os_error_t NANO_OS_BSP_Init(void) |
| 34 | +{ |
| 35 | + uint8_t i; |
| 36 | + nano_os_error_t ret = NOS_ERR_SUCCESS; |
| 37 | + |
| 38 | + /* Turn on power on GPIO */ |
| 39 | + LPC_CCU1->CLKCCU[CLK_MX_SCU].CFG = (1u << 0u); |
| 40 | + LPC_CCU1->CLKCCU[CLK_MX_GPIO].CFG = (1u << 0u); |
| 41 | + |
| 42 | + /* Leds 0,1,2 => |
| 43 | + * P6_9 : GPIO3[5] |
| 44 | + * P6_11 : GPIO3[7] |
| 45 | + * P2_7 : GPIO0[7] */ |
| 46 | + LPC_SCU->SFSP[3u][5u] = (1u << 7u); |
| 47 | + LPC_SCU->SFSP[3u][7u] = (1u << 7u); |
| 48 | + LPC_SCU->SFSP[0u][7u] = (1u << 7u); |
| 49 | + LPC_GPIO_PORT->DIR[3u] |= (1u << 5u) | (1u << 7u); |
| 50 | + LPC_GPIO_PORT->DIR[0u] |= (1u << 7u); |
| 51 | + |
| 52 | + /* Turn all leds off */ |
| 53 | + for (i = 0; i < 3u; i++) |
| 54 | + { |
| 55 | + NANO_OS_BSP_LedOff(i); |
| 56 | + } |
| 57 | + |
| 58 | + return ret; |
| 59 | +} |
| 60 | + |
| 61 | +/** \brief Get the number of LEDs available */ |
| 62 | +uint8_t NANO_OS_BSP_GetLedCount(void) |
| 63 | +{ |
| 64 | + return 3u; |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +/** \brief Turn ON the specified LED */ |
| 69 | +void NANO_OS_BSP_LedOn(const uint8_t led) |
| 70 | +{ |
| 71 | + switch(led) |
| 72 | + { |
| 73 | + case 0: |
| 74 | + LPC_GPIO_PORT->CLR[3u] = NANO_OS_CAST(uint32_t, (1u << 5u)); |
| 75 | + break; |
| 76 | + case 1: |
| 77 | + LPC_GPIO_PORT->CLR[3u] = NANO_OS_CAST(uint32_t, (1u << 7u)); |
| 78 | + break; |
| 79 | + case 2: |
| 80 | + LPC_GPIO_PORT->CLR[0u] = NANO_OS_CAST(uint32_t, (1u << 7u)); |
| 81 | + break; |
| 82 | + |
| 83 | + default: |
| 84 | + /* Do nothing */ |
| 85 | + break; |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +/** \brief Turn OFF the specified LED */ |
| 90 | +void NANO_OS_BSP_LedOff(const uint8_t led) |
| 91 | +{ |
| 92 | + switch(led) |
| 93 | + { |
| 94 | + case 0: |
| 95 | + LPC_GPIO_PORT->SET[3u] = NANO_OS_CAST(uint32_t, (1u << 5u)); |
| 96 | + break; |
| 97 | + case 1: |
| 98 | + LPC_GPIO_PORT->SET[3u] = NANO_OS_CAST(uint32_t, (1u << 7u)); |
| 99 | + break; |
| 100 | + case 2: |
| 101 | + LPC_GPIO_PORT->SET[0u] = NANO_OS_CAST(uint32_t, (1u << 7u)); |
| 102 | + break; |
| 103 | + |
| 104 | + default: |
| 105 | + /* Do nothing */ |
| 106 | + break; |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +/** \brief Get the LED I/O registers memory area description */ |
| 111 | +void NANO_OS_BSP_GetLedIoRegistersMem(uint32_t* const start_address, uint32_t* const size) |
| 112 | +{ |
| 113 | + /* Check parameters */ |
| 114 | + if ((start_address != NULL) && (size != NULL)) |
| 115 | + { |
| 116 | + (*start_address) = LPC_GPIO_PORT_BASE; |
| 117 | + (*size) = 0xC000u; |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +/** \brief Get the UART registers memory area description */ |
| 122 | +void NANO_OS_BSP_GetUartIoRegistersMem(uint32_t* const start_address, uint32_t* const size) |
| 123 | +{ |
| 124 | + /* Check parameters */ |
| 125 | + if ((start_address != NULL) && (size != NULL)) |
| 126 | + { |
| 127 | + (*start_address) = LPC_USART0_BASE; |
| 128 | + (*size) = 0x40000u; |
| 129 | + } |
| 130 | +} |
0 commit comments