aboutsummaryrefslogtreecommitdiff
path: root/cc3200/hal/cc3200_hal.c
diff options
context:
space:
mode:
authordanicampora2015-02-06 15:35:48 +0100
committerDamien George2015-02-06 22:10:11 +0000
commit8785645a952c03315dbf93667b5f7c7eec49762f (patch)
tree267e2d572d87e92bfc0bfabf83859231152a2162 /cc3200/hal/cc3200_hal.c
parent97f14606f528180d1482cffbe3571163a1dd9273 (diff)
cc3200: Add cc3200 port of MicroPython.
The port currently implements support for GPIO, RTC, ExtInt and the WiFi subsystem. A small file system is available in the serial flash. A bootloader which makes OTA updates possible, is also part of this initial implementation.
Diffstat (limited to 'cc3200/hal/cc3200_hal.c')
-rw-r--r--cc3200/hal/cc3200_hal.c165
1 files changed, 165 insertions, 0 deletions
diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c
new file mode 100644
index 000000000..8424065c5
--- /dev/null
+++ b/cc3200/hal/cc3200_hal.c
@@ -0,0 +1,165 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Daniel Campora
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+ /******************************************************************************
+ IMPORTS
+ ******************************************************************************/
+#include <stdio.h>
+#include <stdint.h>
+#include "inc/hw_types.h"
+#include "inc/hw_ints.h"
+#include "inc/hw_nvic.h"
+#include "hw_memmap.h"
+#include "mpconfig.h"
+#include MICROPY_HAL_H
+#include "rom_map.h"
+#include "interrupt.h"
+#include "systick.h"
+#include "prcm.h"
+#include "sdhost.h"
+#include "pin.h"
+#include "mpexception.h"
+
+#ifdef USE_FREERTOS
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+#endif
+
+
+/******************************************************************************
+ DECLARE CONSTANTS
+ ******************************************************************************/
+#define HAL_SDCARD_FREQUENCY_HZ 15000000 // 15MHz
+
+/******************************************************************************
+ DECLARE PRIVATE FUNCTIONS
+ ******************************************************************************/
+#ifndef USE_FREERTOS
+static void hal_TickInit (void);
+#endif
+#if MICROPY_HW_HAS_SDCARD
+static void hal_EnableSdCard (void);
+#endif
+
+/******************************************************************************
+ DECLARE LOCAL VARIABLES
+ ******************************************************************************/
+static volatile uint32_t HAL_tickCount;
+
+/******************************************************************************
+ DECLARE IMPORTED DATA
+ ******************************************************************************/
+extern void (* const g_pfnVectors[256])(void);
+
+/******************************************************************************
+ DEFINE PUBLIC FUNCTIONS
+ ******************************************************************************/
+
+void HAL_SystemInit (void) {
+ MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
+
+ // in the case of a release image, these steps are already performed by
+ // the bootloader so we can skip it and gain some code space
+#ifndef NDEBUG
+ MAP_IntMasterEnable();
+ PRCMCC3200MCUInit();
+#endif
+
+#ifndef USE_FREERTOS
+ hal_TickInit();
+#endif
+#if MICROPY_HW_HAS_SDCARD
+ hal_EnableSdCard();
+#endif
+}
+
+void HAL_SystemDeInit (void) {
+}
+
+void HAL_IncrementTick(void) {
+ HAL_tickCount++;
+}
+
+uint32_t HAL_GetTick(void) {
+ return HAL_tickCount;
+}
+
+void HAL_Delay(uint32_t delay) {
+#ifdef USE_FREERTOS
+ vTaskDelay (delay / portTICK_PERIOD_MS);
+#else
+ uint32_t start = HAL_tickCount;
+ // Wraparound of tick is taken care of by 2's complement arithmetic.
+ while (HAL_tickCount - start < delay) {
+ // Enter sleep mode, waiting for (at least) the SysTick interrupt.
+ __WFI();
+ }
+#endif
+}
+
+void mp_hal_set_interrupt_char (int c) {
+ mpexception_set_interrupt_char (c);
+}
+
+/******************************************************************************
+ DEFINE PRIVATE FUNCTIONS
+ ******************************************************************************/
+
+#ifndef USE_FREERTOS
+static void hal_TickInit (void) {
+ HAL_tickCount = 0;
+ MAP_SysTickIntRegister(HAL_IncrementTick);
+ MAP_IntEnable(FAULT_SYSTICK);
+ MAP_SysTickIntEnable();
+ MAP_SysTickPeriodSet(HAL_FCPU_HZ / HAL_SYSTICK_PERIOD_US);
+ // Force a reload of the SysTick counter register
+ HWREG(NVIC_ST_CURRENT) = 0;
+ MAP_SysTickEnable();
+}
+#endif
+
+#if MICROPY_HW_HAS_SDCARD
+static void hal_EnableSdCard (void) {
+ // Configure PIN_06 for SDHOST0 SDHost_D0
+ MAP_PinTypeSDHost(PIN_06, PIN_MODE_8);
+ // Configure PIN_07 for SDHOST0 SDHost_CLK
+ MAP_PinTypeSDHost(PIN_07, PIN_MODE_8);
+ // Configure PIN_08 for SDHOST0 SDHost_CMD
+ MAP_PinTypeSDHost(PIN_08, PIN_MODE_8);
+ // Set the SD card clock as an output pin
+ MAP_PinDirModeSet(PIN_07, PIN_DIR_MODE_OUT);
+ // Enable SD peripheral clock
+ MAP_PRCMPeripheralClkEnable(PRCM_SDHOST, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
+ // Reset MMCHS
+ MAP_PRCMPeripheralReset(PRCM_SDHOST);
+ // Configure MMCHS
+ MAP_SDHostInit(SDHOST_BASE);
+ // Configure the card clock
+ MAP_SDHostSetExpClk(SDHOST_BASE, MAP_PRCMPeripheralClockGet(PRCM_SDHOST), HAL_SDCARD_FREQUENCY_HZ);
+}
+#endif