Permalink
Browse files

Initial commit of G14 Code - beta firmware

Starting from sample code from gainspan, this is a first version of the
beta firmware
This project created using an IAR compiler 30 day trial - code size is
over the 16k kickstarter limit.
We need to refactor this code to work on CubeSuite+ with applilet3
  • Loading branch information...
1 parent fc0c731 commit 73b347f1b69e170f50476dc749336873a6e5a953 @CHIPkitReadonly CHIPkitReadonly committed Oct 4, 2012
Showing with 28,125 additions and 16,171 deletions.
  1. +355 −0 Apps/App_Common.c
  2. +133 −0 Apps/App_Connect.c
  3. +44 −0 Apps/App_ProgramMode.c
  4. +669 −0 Apps/App_Startup.c
  5. +466 −0 Apps/App_Swarm.c
  6. +82 −0 Apps/Apps.h
  7. +94 −0 Apps/NVSettings.c
  8. +52 −0 Apps/NVSettings.h
  9. +5,692 −0 CmdLib/AtCmdLib.c
  10. +801 −0 CmdLib/AtCmdLib.h
  11. +517 −0 CmdLib/GainSpan_SPI.c
  12. +50 −0 CmdLib/GainSpan_SPI.h
  13. +980 −0 YRDKRL78G14/ADKRenesasG14.dep
  14. +581 −0 YRDKRL78G14/ADKRenesasG14.ewd
  15. +2,257 −0 YRDKRL78G14/ADKRenesasG14.ewp
  16. +10 −0 YRDKRL78G14/ADKRenesasG14.eww
  17. +96 −0 YRDKRL78G14/HostApp.h
  18. +156 −142 {gen → YRDKRL78G14/applilet3_src}/r_cg_adc.c
  19. +219 −197 {gen → YRDKRL78G14/applilet3_src}/r_cg_adc.h
  20. +65 −69 gen/r_cg_port_user.c → YRDKRL78G14/applilet3_src/r_cg_adc_user.c
  21. +93 −91 {gen → YRDKRL78G14/applilet3_src}/r_cg_cgc.c
  22. +208 −188 {gen → YRDKRL78G14/applilet3_src}/r_cg_cgc.h
  23. +63 −69 {gen → YRDKRL78G14/applilet3_src}/r_cg_cgc_user.c
  24. +319 −0 YRDKRL78G14/applilet3_src/r_cg_intc.c
  25. +173 −159 {gen → YRDKRL78G14/applilet3_src}/r_cg_intc.h
  26. +183 −177 gen/r_cg_intc.c → YRDKRL78G14/applilet3_src/r_cg_intc_user.c
  27. +94 −101 {gen → YRDKRL78G14/applilet3_src}/r_cg_it.c
  28. +68 −68 {gen → YRDKRL78G14/applilet3_src}/r_cg_it.h
  29. +101 −76 {gen → YRDKRL78G14/applilet3_src}/r_cg_it_user.c
  30. +92 −90 {gen → YRDKRL78G14/applilet3_src}/r_cg_macrodriver.h
  31. +87 −83 gen/r_cg_wdt.c → YRDKRL78G14/applilet3_src/r_cg_pclbuz.c
  32. +80 −0 YRDKRL78G14/applilet3_src/r_cg_pclbuz.h
  33. +50 −59 gen/r_cg_wdt.h → YRDKRL78G14/applilet3_src/r_cg_pclbuz_user.c
  34. +100 −0 YRDKRL78G14/applilet3_src/r_cg_port.c
  35. +233 −215 {gen → YRDKRL78G14/applilet3_src}/r_cg_port.h
  36. +161 −79 gen/r_cg_port.c → YRDKRL78G14/applilet3_src/r_cg_port_user.c
  37. +864 −0 YRDKRL78G14/applilet3_src/r_cg_serial.c
  38. +451 −430 {gen → YRDKRL78G14/applilet3_src}/r_cg_serial.h
  39. +690 −0 YRDKRL78G14/applilet3_src/r_cg_serial_user.c
  40. +250 −0 YRDKRL78G14/applilet3_src/r_cg_timer.c
  41. +940 −0 YRDKRL78G14/applilet3_src/r_cg_timer.h
  42. +213 −133 gen/r_cg_intc_user.c → YRDKRL78G14/applilet3_src/r_cg_timer_user.c
  43. +43 −43 {gen → YRDKRL78G14/applilet3_src}/r_cg_userdefine.h
  44. +110 −83 gen/r_cg_adc_user.c → YRDKRL78G14/applilet3_src/r_main.c
  45. +102 −99 {gen → YRDKRL78G14/applilet3_src}/r_systeminit.c
  46. +106 −0 YRDKRL78G14/drv/ADC.c
  47. +167 −0 YRDKRL78G14/drv/ADC.h
  48. +80 −0 YRDKRL78G14/drv/Glyph/Drivers/ST7579_LCD.h
  49. +41 −0 YRDKRL78G14/drv/Glyph/Drivers/YRDKRL78_SPI.h
  50. BIN YRDKRL78G14/drv/Glyph/RL78GlyphLib_Debug.r87
  51. BIN YRDKRL78G14/drv/Glyph/RL78GlyphLib_Debug_old.r87
  52. +280 −0 YRDKRL78G14/drv/Glyph/glyph_api.h
  53. +55 −0 YRDKRL78G14/drv/Glyph/glyph_cfg.h
  54. +151 −0 YRDKRL78G14/drv/Glyph/glyph_register.c
  55. +47 −0 YRDKRL78G14/drv/Glyph/glyph_types.h
  56. +184 −0 YRDKRL78G14/drv/Glyph/lcd.c
  57. +91 −0 YRDKRL78G14/drv/Glyph/lcd.h
  58. +418 −0 YRDKRL78G14/drv/I2C.c
  59. +162 −0 YRDKRL78G14/drv/I2C.h
  60. +101 −0 YRDKRL78G14/drv/RDKRL78_spi.c
  61. +15 −0 YRDKRL78G14/drv/RDKRL78_spi.h
  62. +469 −0 YRDKRL78G14/drv/SAU.h
  63. +446 −0 YRDKRL78G14/drv/SPI _G14.c
  64. +431 −0 YRDKRL78G14/drv/SPI.c
  65. +48 −0 YRDKRL78G14/drv/SPI.h
  66. +431 −0 YRDKRL78G14/drv/SPI_G13.c
  67. +109 −0 YRDKRL78G14/drv/Timer.c
  68. +44 −0 YRDKRL78G14/drv/Timer.h
  69. +447 −0 YRDKRL78G14/drv/UART0.c
  70. +30 −0 YRDKRL78G14/drv/UART0.h
  71. +444 −0 YRDKRL78G14/drv/UART2.c
  72. +30 −0 YRDKRL78G14/drv/UART2.h
  73. +209 −0 YRDKRL78G14/drv/led.c
  74. +31 −0 YRDKRL78G14/drv/led.h
  75. +92 −0 YRDKRL78G14/drv/r_cg_macrodriver.h
  76. +151 −0 YRDKRL78G14/init/hwsetup.c
  77. +378 −0 YRDKRL78G14/init/hwsetup.h
  78. +265 −0 YRDKRL78G14/lnkr5f104pj.xcl
  79. +292 −0 YRDKRL78G14/main.c
  80. +24 −0 YRDKRL78G14/settings/ADKRenesasG14.cspy.bat
  81. +74 −0 YRDKRL78G14/settings/ADKRenesasG14.dbgdt
  82. +125 −0 YRDKRL78G14/settings/ADKRenesasG14.dni
  83. +72 −0 YRDKRL78G14/settings/ADKRenesasG14.wsdt
  84. +15 −0 YRDKRL78G14/settings/GainSpan_RL78G13_IAR.cspy.bat
  85. +79 −0 YRDKRL78G14/settings/GainSpan_RL78G13_IAR.dbgdt
  86. +102 −0 YRDKRL78G14/settings/GainSpan_RL78G13_IAR.dni
  87. +85 −0 YRDKRL78G14/settings/GainSpan_RL78G13_IAR.wsdt
  88. +288 −0 YRDKRL78G14/system/EEPROM.c
  89. +43 −0 YRDKRL78G14/system/EEPROM.h
  90. +79 −0 YRDKRL78G14/system/GainSpan_IO.c
  91. +19 −0 YRDKRL78G14/system/GainSpan_IO.h
  92. +62 −0 YRDKRL78G14/system/Switch.c
  93. +35 −0 YRDKRL78G14/system/Switch.h
  94. +27 −0 YRDKRL78G14/system/YRDKRL78G14.h
  95. +120 −0 YRDKRL78G14/system/console.c
  96. +32 −0 YRDKRL78G14/system/console.h
  97. +120 −0 YRDKRL78G14/system/mstimer.c
  98. +26 −0 YRDKRL78G14/system/mstimer.h
  99. +67 −0 YRDKRL78G14/system/platform.h
  100. +0 −419 board/YRDKRL78G13.c
  101. +0 −157 board/YRDKRL78G13.h
  102. +0 −2,000 bugswarm-renesas.Buglabs.mtud
  103. +0 −4,598 bugswarm-renesas.mtpj
  104. +0 −497 function.Html
  105. +0 −497 gen/function.Html
  106. +0 −198 gen/macro.Html
  107. +0 −554 gen/r_cg_serial.c
  108. +0 −457 gen/r_cg_serial_user.c
  109. +0 −89 gen/r_cg_wdt_user.c
  110. +0 −74 gen/r_lk.dr
  111. +0 −298 gen/r_main.c
  112. +5 −0 jsmn/.hg_archival.txt
  113. +20 −0 jsmn/LICENSE
  114. +26 −0 jsmn/Makefile
  115. +157 −0 jsmn/README
  116. +252 −0 jsmn/jsmn.c
  117. +67 −0 jsmn/jsmn.h
  118. +293 −0 jsmn/jsmn_test.c
  119. +0 −110 macro.Html
  120. +0 −74 r_lk.dr
  121. +0 −214 redpine/app_wifi_init.c
  122. +0 −29 redpine/design.txt
  123. +0 −157 redpine/rsi_at_command_processor.h
  124. +0 −46 redpine/rsi_config.h
  125. +0 −34 redpine/rsi_data_types.h
  126. +0 −119 redpine/rsi_demo_app.c
  127. +0 −45 redpine/rsi_demo_app.h
  128. +0 −199 redpine/rsi_global.h
  129. +0 −43 redpine/rsi_hal.h
  130. +0 −76 redpine/rsi_hal_api.h
  131. +0 −45 redpine/rsi_hal_init.c
  132. +0 −57 redpine/rsi_hal_timers.c
  133. +0 −82 redpine/rsi_hal_uart.c
  134. +0 −583 redpine/rsi_lib_api.c
  135. +0 −942 redpine/rsi_lib_at_cmd_processor.c
  136. +0 −232 redpine/rsi_lib_boot.c
  137. +0 −81 redpine/rsi_lib_init.c
  138. +0 −432 redpine/rsi_uart_api.h
  139. +0 −3 redpine/todo.txt
  140. +122 −0 sensors/Accelerometer.c
  141. +18 −0 sensors/Accelerometer.h
  142. +93 −0 sensors/LightSensor.c
  143. +19 −0 sensors/LightSensor.h
  144. +76 −0 sensors/Potentiometer.c
  145. +25 −0 sensors/Potentiometer.h
  146. +107 −0 sensors/Temperature.c
  147. +19 −0 sensors/Temperature.h
  148. +0 −69 swarmlibs/swarm.c
  149. +0 −10 swarmlibs/swarm.h
View
@@ -0,0 +1,355 @@
+/*-------------------------------------------------------------------------*
+ * File: App_Common.c
+ *-------------------------------------------------------------------------*
+ * Description:
+ * Common routines used by all the Apps.
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <HostApp.h>
+#include <HostApp.h>
+#include <system/console.h>
+#include <system/platform.h>
+#include <CmdLib/AtCmdLib.h>
+#include <CmdLib/GainSpan_SPI.h>
+#include <sensors/Temperature.h>
+#include <sensors/Potentiometer.h>
+#include <sensors/LightSensor.h>
+#include <sensors/Accelerometer.h>
+#include <system/mstimer.h>
+#include <drv/Glyph/lcd.h>
+#include "Apps.h"
+#include "HostApp.h"
+#ifndef APP_MAX_RECEIVED_DATA
+ #error "APP_MAX_RECEIVED_DATA must be defined in platform.h"
+#endif
+
+/*-------------------------------------------------------------------------*
+ * Globals:
+ *-------------------------------------------------------------------------*/
+uint8_t G_received[APP_MAX_RECEIVED_DATA + 1];
+unsigned int G_receivedCount = 0;
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_Write
+ *---------------------------------------------------------------------------*
+ * Description:
+ * ATCmdLib callback to write a string of characters to the module.
+ * Inputs:
+ * const uint8_t *txData -- string of bytes
+ * uint32_t dataLength -- Number of bytes to transfer
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_Write(const void *txData, uint16_t dataLength)
+{
+ const uint8_t *tx = (uint8_t *)txData;
+#ifdef ATLIBGS_INTERFACE_SPI
+ while (dataLength--) {
+ /* Keep trying to send this data until it goes */
+ while (!GainSpan_SPI_SendByte(*tx)) {
+ /* Process any incoming data as well */
+ GainSpan_SPI_Update(GAINSPAN_SPI_CHANNEL);
+ }
+
+ tx++;
+ }
+#else
+ while (dataLength--) {
+ /* Keep trying to send this data until it goes */
+ while (!GainSpan_UART_SendByte(*tx)) {
+ }
+ tx++;
+ }
+#endif
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_Read
+ *---------------------------------------------------------------------------*
+ * Description:
+ * ATCmdLib callback to read a string of characters from the module.
+ * This routine can block if needed until the data arrives.
+ * Inputs:
+ * uint8_t *rxData -- Pointer to a place to store a string of bytes
+ * uint16_t dataLength -- Number of bytes to transfer
+ * uint8_t blockFlag -- true/non-zero to wait for bytes, else false/zero.
+ * Outputs:
+ * bool -- true if character received, else false
+ *---------------------------------------------------------------------------*/
+bool App_Read(uint8_t *rxData, uint16_t dataLength, uint8_t blockFlag)
+{
+#ifdef ATLIBGS_INTERFACE_SPI
+ bool got_data = false;
+
+ /* Keep getting data if we have a number of bytes to fetch */
+ while (dataLength) {
+ /* Try to get a byte */
+ if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, rxData)) {
+ /* Got a byte, move up to the next position */
+ rxData++;
+ dataLength--;
+ got_data = true;
+ } else {
+ /* Did not get a byte, are we block? If not, stop here */
+ if (!blockFlag)
+ break;
+ }
+ }
+
+ return got_data;
+#else
+ bool got_data = false;
+
+ /* Keep getting data if we have a number of bytes to fetch */
+ while (dataLength) {
+ /* Try to get a byte */
+ if (GainSpan_UART_ReceiveByte(rxData)) {
+ /* Got a byte, move up to the next position */
+ rxData++;
+ dataLength--;
+ got_data = true;
+ } else {
+ /* Did not get a byte, are we block? If not, stop here */
+ if (!blockFlag)
+ break;
+ }
+ }
+
+ return got_data;
+#endif
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_RSSIReading
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Take a reading of the RSSI level with the WiFi and show it on
+ * the LCD display.
+ * Inputs:
+ * bool updateLCD (if true, LCD is updated)
+ * Outputs:
+ * int16_t rssi (return value)
+ *---------------------------------------------------------------------------*/
+int16_t App_RSSIReading(int16_t * rssi, bool updateLCD)
+{
+ char line[20];
+ int rssiFound = 0;
+
+ if (AtLibGs_IsNodeAssociated()) {
+ if (AtLibGs_GetRssi() == ATLIBGS_MSG_ID_OK) {
+ if (AtLibGs_ParseRssiResponse(rssi)) {
+ sprintf(line, "RSSI: %d", (*rssi));
+ DisplayLCD(LCD_LINE6, (const uint8_t *)line);
+ rssiFound = 1;
+ }
+ }
+ }
+ if (!rssiFound) {
+ DisplayLCD(LCD_LINE5, "RSSI: ----");
+ rssi = 0;
+ }
+ return *rssi;
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_TemperatureReadingUpdate
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Take a reading of a temperature and show it on the LCD display.
+ * Inputs:
+ * bool updateLCD (if true, LCD is updated), pointer to 2 member uint16_t
+ * array to update values in
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_TemperatureReadingUpdate(uint16_t * G_temp_int, bool updateLCD)
+{
+ char lcd_buffer[20];
+
+ // Temperature sensor reading
+ int16_t temp;
+ temp = Temperature_Get();
+ // Get the temperature and show it on the LCD
+ G_temp_int[0] = (int16_t)temp / 16;
+ G_temp_int[1] = (int16_t)((temp & 0x000F) * 10) / 16;
+
+ if(updateLCD)
+ {
+ // Display the contents of lcd_buffer onto the debug LCD
+ sprintf((char *)lcd_buffer, "TEMP: %d.%d C", G_temp_int[0], G_temp_int[1]);
+ DisplayLCD(LCD_LINE3, (const uint8_t *)lcd_buffer);
+ }
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_PotentiometerUpdate
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Take a reading of the potentiometer and show it on the LCD display.
+ * Inputs:
+ * bool updateLCD (if true, LCD is updated), pointer to 2 member uint16_t
+ * array to update values in
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_PotentiometerUpdate(int16_t * G_adc_int, bool updateLCD)
+{
+ char lcd_buffer[20];
+
+ // Potentiometer sensor reading
+ int32_t percent;
+ percent = Potentiometer_Get();
+ G_adc_int[0] = (int16_t)(percent / 10);
+ G_adc_int[1] = (int16_t)(percent % 10);
+
+ if(updateLCD)
+ {
+ sprintf((char *)lcd_buffer, " POT: %d.%d %%", G_adc_int[0], G_adc_int[1]);
+ /* Display the contents of lcd_buffer onto the debug LCD */
+ DisplayLCD(LCD_LINE4, (const uint8_t *)lcd_buffer);
+ }
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_LightSensorReadingUpdate
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Take a reading of a lightSensor and show it on the LCD display.
+ * Inputs:
+ * bool updateLCD (if true, LCD is updated), pointer to 2 member uint16_t
+ * array to update values in
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_LightSensorReadingUpdate(uint16_t * G_light_int, bool updateLCD)
+{
+ char lcd_buffer[20];
+
+ // Temperature sensor reading
+ *G_light_int = LightSensor_Get();
+
+ if(updateLCD)
+ {
+ // Display the contents of lcd_buffer onto the debug LCD
+ sprintf((char *)lcd_buffer, "Light: %d ", *G_light_int);
+ DisplayLCD(LCD_LINE5, (const uint8_t *)lcd_buffer);
+ }
+}
+
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_PrepareIncomingData
+ *---------------------------------------------------------------------------*
+ * Description:
+ * ATCmdLib callback to reset the incoming data state.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_PrepareIncomingData(void)
+{
+ G_receivedCount = 0;
+ G_received[0] = '\0';
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_ProcessIncomingData
+ *---------------------------------------------------------------------------*
+ * Description:
+ * ATCmdLib callback that is called when a byte has come in for a
+ * specific connection.
+ * Inputs:
+ * uint8_t rxData -- Byte received
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_ProcessIncomingData(uint8_t rxData)
+{
+ if (G_receivedCount < APP_MAX_RECEIVED_DATA) {
+ G_received[G_receivedCount++] = rxData;
+ G_received[G_receivedCount] = '\0';
+ }
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_Update
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Allow the AtLibGs to update its state when nothing is happening
+ * in the application.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_Update(void)
+{
+#ifdef ATLIBGS_INTERFACE_SPI
+ GainSpan_SPI_Update(GAINSPAN_SPI_CHANNEL);
+#else
+#endif
+}
+
+void readSensor(APP_STATE_E state){
+ char temp_char[2]; uint16_t temp; float ftemp; float gTemp_F;
+ char LCDString[30]; uint16_t gAmbientLight; extern int16_t gAccData[3];
+ extern int16_t *Accelerometer_Get(void);
+ ConsolePrintf("Reading sensor %d: ",state);
+ switch(state)
+ {
+ case UPDATE_TEMPERATURE:
+ // Temperature sensor reading
+ temp = Temperature_Get();
+ #if 0
+ // Get the temperature and show it on the LCD
+ temp_char[0] = (int16_t)temp / 16;
+ temp_char[1] = (int16_t)((temp & 0x000F) * 10) / 16;
+ #endif
+ temp_char[1] = (temp & 0xFF00)>>8;
+ temp_char[0] = temp & 0xFF;
+
+ ftemp = *(uint16_t *)temp_char;
+
+ gTemp_F = ((ftemp/5)*9)/128 + 22;
+
+ // Display the contents of lcd_buffer onto the debug LCD
+ //sprintf((char *)LCDString, "TEMP: %d.%d C", temp_char[0], temp_char[1]);
+ sprintf((char *)LCDString, "TEMP: %.1fF", gTemp_F);
+ ConsolePrintf("%s\r\n",LCDString);
+ DisplayLCD(LCD_LINE6, (const uint8_t *)LCDString);
+ state = UPDATE_LIGHT;
+ break;
+
+ case UPDATE_LIGHT:
+ // Light sensor reading
+ gAmbientLight = LightSensor_Get();
+ // Display the contents of lcd_buffer onto the debug LCD
+ sprintf((char *)LCDString, "Light: %d ", gAmbientLight);
+ ConsolePrintf("%s\r\n",LCDString);
+ DisplayLCD(LCD_LINE7, (const uint8_t *)LCDString);
+ state = UPDATE_ACCELEROMETER;
+ break;
+
+ case UPDATE_ACCELEROMETER:
+ // 3-axis accelerometer reading
+ Accelerometer_Get();
+ sprintf((char *)LCDString, "x%2d y%2d z%2d", gAccData[0], gAccData[1], gAccData[2]);
+ ConsolePrintf("%s\r\n",LCDString);
+ DisplayLCD(LCD_LINE8, (const uint8_t *)LCDString);
+ state = UPDATE_TEMPERATURE;
+ break;
+ }
+}
+
+
+/*-------------------------------------------------------------------------*
+ * End of File: App_Common.c
+ *-------------------------------------------------------------------------*/
Oops, something went wrong.

0 comments on commit 73b347f

Please sign in to comment.