00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include PLATFORM_HEADER
00020 #include BOARD_HEADER
00021 #ifdef EMBERZNET_HAL
00022 #include "stack/include/ember.h"
00023 #include "stack/include/error.h"
00024 #include "hal/hal.h"
00025 #define PORTA (0 << 3)
00026 #define PORTB (1 << 3)
00027 #define PORTC (2 << 3)
00028 #else
00029 #include "error.h"
00030 #include "hal/hal.h"
00031 #include "hal/micro/cortexm3/mfg-token.h"
00032 #endif
00033 #include <string.h>
00034
00035 const LedResourceType LedsMB851A[] = {
00036 {
00037 "D1",
00038 PORTB,
00039 6
00040 },
00041 {
00042 "D3",
00043 PORTB,
00044 5
00045 }
00046 };
00047
00048 const InfraRedLedResourceType infraRedLedMB851A = {
00049 "D5",
00050 PORTB,
00051 4
00052 };
00053
00054
00055 const LedResourceType LedsMB954A[] = {
00056 {
00057 "D1",
00058 PORTA,
00059 5
00060 },
00061 {
00062 "D3",
00063 PORTA,
00064 0
00065 }
00066 };
00067
00068 const ButtonResourceType ButtonsMB851A[] = {
00069 {
00070 "S1",
00071 PORTA,
00072 7
00073 }
00074 };
00075
00076 const ButtonResourceType ButtonsMB954A[] = {
00077 {
00078 "S1",
00079 PORTB,
00080 3
00081 }
00082 };
00083
00084 const ButtonResourceType ButtonsMB950A[] = {
00085 {
00086 "S1",
00087 PORTB,
00088 3
00089 },
00090 {
00091 "S2",
00092 PORTA,
00093 7
00094 },
00095 {
00096 "S3",
00097 PORTB,
00098 7
00099 },
00100 {
00101 "S4",
00102 PORTB,
00103 0
00104 },
00105 {
00106 "S5",
00107 PORTB,
00108 6
00109 }
00110 };
00111
00112 const TempSensorResourceType tempSensorMB851A = {
00113 "STLM20",
00114 PORTB,
00115 7,
00116 FALSE
00117 };
00118
00119 const TempSensorResourceType tempSensorMB954A = {
00120 "STLM20",
00121 PORTA,
00122 4,
00123 TRUE
00124 };
00125
00126 const MemsResourceType memsSensor = {
00127 "LIS302",
00128 0
00129 };
00130
00131 const BoardIOType ioMB851A = {
00132 LedsMB851A,
00133 ButtonsMB851A,
00134 };
00135
00136 const BoardIOType ioMB954A = {
00137 LedsMB954A,
00138 ButtonsMB954A,
00139 };
00140
00141 const BoardIOType ioMB950A = {
00142 LedsMB954A,
00143 ButtonsMB950A,
00144 };
00145
00146 const BoardResourcesType MB851A = {
00147 "MB851 A",
00148 (BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI),
00149 BUTTONS_MB851A,
00150 LEDS_MB851A,
00151 &ioMB851A,
00152 &infraRedLedMB851A,
00153 &memsSensor,
00154 &tempSensorMB851A,
00155 };
00156
00157 const BoardResourcesType MB851B = {
00158 "MB851 B",
00159 (BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI),
00160 BUTTONS_MB851B,
00161 LEDS_MB851B,
00162 &ioMB851A,
00163 &infraRedLedMB851A,
00164 &memsSensor,
00165 &tempSensorMB851A,
00166 };
00167
00168 const BoardResourcesType MB851C = {
00169 "MB851 C",
00170 (BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F | BOARD_HAS_EEPROM),
00171 BUTTONS_MB851C,
00172 LEDS_MB851C,
00173 &ioMB954A,
00174 &infraRedLedMB851A,
00175 &memsSensor,
00176 &tempSensorMB954A,
00177 };
00178
00179 const BoardResourcesType MB954A = {
00180 "MB954 A",
00181 (BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI | BOARD_HAS_PA),
00182 BUTTONS_MB954A,
00183 LEDS_MB954A,
00184 &ioMB954A,
00185 &infraRedLedMB851A,
00186 &memsSensor,
00187 &tempSensorMB954A,
00188 };
00189
00190 const BoardResourcesType MB954B = {
00191 "MB954 B",
00192 (BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F | BOARD_HAS_EEPROM | BOARD_HAS_PA),
00193 BUTTONS_MB954B,
00194 LEDS_MB954B,
00195 &ioMB954A,
00196 &infraRedLedMB851A,
00197 &memsSensor,
00198 &tempSensorMB954A,
00199 };
00200
00201 const BoardResourcesType MB950A = {
00202 "MB950 A",
00203 (BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F),
00204 BUTTONS_MB950A,
00205 LEDS_MB950A,
00206 &ioMB950A,
00207 &infraRedLedMB851A,
00208 &memsSensor,
00209 &tempSensorMB954A,
00210 };
00211
00212 const BoardResourcesType MB951A = {
00213 "MB951 A",
00214 (BOARD_HAS_STM32F),
00215 BUTTONS_MB951A,
00216 LEDS_MB951A,
00217 &ioMB954A,
00218 NULL,
00219 NULL,
00220 NULL,
00221 };
00222
00223 static const BoardResourcesType *boardList [] = {
00224 &MB851A,
00225 &MB851B,
00226 &MB851C,
00227 &MB954A,
00228 &MB954B,
00229 &MB950A,
00230 &MB951A
00231 };
00232
00233 BoardResourcesType const *boardDescription = NULL;
00234
00235 #define PORT_NAME(x) ((x == PORTA) ? "A": ((x == PORTB) ? "B" : ((x == PORTC) ? "C": "?")))
00236
00237 void halBoardInit(void)
00238 {
00239 char boardName[16];
00240 int8s i;
00241 boardDescription = NULL;
00242 #ifdef EMBERZNET_HAL
00243 halCommonGetToken(boardName, TOKEN_MFG_BOARD_NAME);
00244 #else
00245 halCommonGetMfgToken(boardName, TOKEN_MFG_BOARD_NAME);
00246 #endif
00247
00248 i = 15;
00249 while ((i >= 0) && (boardName[i] == 0xFF)) {
00250 boardName[i] = 0;
00251 i--;
00252 }
00253
00254 for (i = 0; i < (sizeof(boardList)/4) ; i++)
00255 if (strcmp(boardName, (boardList[i])->name) == 0) {
00256 boardDescription = (BoardResourcesType *) boardList[i];
00257 break;
00258 }
00259
00260 if (boardDescription == NULL) {
00261
00262 boardDescription = (BoardResourcesType *) &MB851A;
00263 }
00264 return;
00265 }
00266 BoardResourcesType const *halBoardGetDescription(void)
00267 {
00268 return boardDescription;
00269 }
00270
00271 void halBoardPowerDown(void)
00272 {
00273
00274 GPIO_PACFGL = (GPIOCFG_IN <<PA0_CFG_BIT)|
00275 (GPIOCFG_IN <<PA1_CFG_BIT)|
00276 (GPIOCFG_IN <<PA2_CFG_BIT)|
00277 (GPIOCFG_IN <<PA3_CFG_BIT);
00278 GPIO_PACFGH = (GPIOCFG_IN <<PA4_CFG_BIT)|
00279 (GPIOCFG_IN <<PA5_CFG_BIT)|
00280 (GPIOCFG_IN <<PA6_CFG_BIT)|
00281 (GPIOCFG_IN <<PA7_CFG_BIT);
00282 GPIO_PBCFGL = (GPIOCFG_IN <<PB0_CFG_BIT)|
00283 (GPIOCFG_IN <<PB1_CFG_BIT)|
00284 (GPIOCFG_IN <<PB2_CFG_BIT)|
00285 (GPIOCFG_IN <<PB3_CFG_BIT);
00286 GPIO_PBCFGH = (GPIOCFG_IN <<PB4_CFG_BIT)|
00287 (GPIOCFG_IN <<PB5_CFG_BIT)|
00288 (GPIOCFG_IN <<PB6_CFG_BIT)|
00289 (GPIOCFG_IN <<PB7_CFG_BIT);
00290 GPIO_PCCFGL = (GPIOCFG_IN <<PC0_CFG_BIT)|
00291 (GPIOCFG_IN <<PC1_CFG_BIT)|
00292 (GPIOCFG_IN <<PC2_CFG_BIT)|
00293 (GPIOCFG_IN <<PC3_CFG_BIT);
00294 GPIO_PCCFGH = (GPIOCFG_IN <<PC4_CFG_BIT)|
00295 (GPIOCFG_IN <<PC5_CFG_BIT)|
00296 #ifdef EMBERZNET_HAL
00297 (CFG_C6 <<PC6_CFG_BIT)|
00298 (CFG_C7 <<PC7_CFG_BIT);
00299 #else
00300 (GPIOCFG_IN <<PC6_CFG_BIT)|
00301 (GPIOCFG_IN <<PC7_CFG_BIT);
00302 #endif
00303
00304 #ifdef EMBERZNET_HAL
00305
00306 {
00307 ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
00308 int8u i;
00309 for (i = 0; i < boardDescription->buttons; i++) {
00310 halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
00311 halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
00312 }
00313 }
00314 #endif
00315
00316 if (boardDescription->flags & BOARD_HAS_PA) {
00317
00318 halGpioConfig(PORTB_PIN(6), GPIOCFG_OUT);
00319 halGpioSet(PORTB_PIN(6), 0);
00320 }
00321
00322 }
00323 void halBoardPowerUp(void)
00324 {
00325
00326 GPIO_PACFGL = (GPIOCFG_IN <<PA0_CFG_BIT)|
00327 (GPIOCFG_IN <<PA1_CFG_BIT)|
00328 (GPIOCFG_IN <<PA2_CFG_BIT)|
00329 (GPIOCFG_IN <<PA3_CFG_BIT);
00330 GPIO_PACFGH = (GPIOCFG_IN <<PA4_CFG_BIT)|
00331 (GPIOCFG_IN <<PA5_CFG_BIT)|
00332 (GPIOCFG_IN <<PA6_CFG_BIT)|
00333 (GPIOCFG_IN <<PA7_CFG_BIT);
00334 GPIO_PBCFGL = (GPIOCFG_IN <<PB0_CFG_BIT)|
00335 (GPIOCFG_OUT_ALT <<PB1_CFG_BIT)|
00336 (GPIOCFG_IN <<PB2_CFG_BIT)|
00337 (GPIOCFG_IN <<PB3_CFG_BIT);
00338 GPIO_PBCFGH = (GPIOCFG_IN <<PB4_CFG_BIT)|
00339 (GPIOCFG_IN <<PB5_CFG_BIT)|
00340 (GPIOCFG_IN <<PB6_CFG_BIT)|
00341 (GPIOCFG_IN <<PB7_CFG_BIT);
00342 GPIO_PCCFGL = (GPIOCFG_IN <<PC0_CFG_BIT)|
00343 (GPIOCFG_IN <<PC1_CFG_BIT)|
00344 (GPIOCFG_IN <<PC2_CFG_BIT)|
00345 (GPIOCFG_IN <<PC3_CFG_BIT);
00346 GPIO_PCCFGH = (GPIOCFG_IN <<PC4_CFG_BIT)|
00347 (GPIOCFG_IN <<PC5_CFG_BIT)|
00348 #ifdef EMBERZNET_HAL
00349 (CFG_C6 <<PC6_CFG_BIT)|
00350 (CFG_C7 <<PC7_CFG_BIT);
00351 #else
00352 (GPIOCFG_IN <<PC6_CFG_BIT)|
00353 (GPIOCFG_IN <<PC7_CFG_BIT);
00354 #endif
00355
00356
00357 if ((boardDescription->flags & BOARD_HAS_MEMS) || (boardDescription->flags & BOARD_HAS_EEPROM)) {
00358 halGpioConfig(PORTA_PIN(1), GPIOCFG_OUT_ALT_OD);
00359 halGpioConfig(PORTA_PIN(2), GPIOCFG_OUT_ALT_OD);
00360 }
00361
00362 if (boardDescription->flags & BOARD_HAS_TEMP_SENSOR) {
00363 halGpioConfig(PORTx_PIN(boardDescription->temperatureSensor->gpioPort,
00364 boardDescription->temperatureSensor->gpioPin),
00365 GPIOCFG_ANALOG);
00366 }
00367
00368 {
00369 LedResourceType *leds = (LedResourceType *) boardDescription->io->leds;
00370 int8u i;
00371 for (i = 0; i < boardDescription->leds; i++) {
00372
00373 halGpioConfig(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), GPIOCFG_OUT);
00374 halGpioSet(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), 1);
00375 }
00376 }
00377
00378 {
00379 ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
00380 int8u i;
00381 for (i = 0; i < boardDescription->buttons; i++) {
00382 halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
00383 halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
00384 }
00385 }
00386
00387
00388 if (boardDescription->flags & BOARD_HAS_PA) {
00389
00390 halGpioConfig(PORTB_PIN(5), GPIOCFG_OUT);
00391 halGpioSet(PORTB_PIN(5), 1);
00392
00393 halGpioConfig(PORTB_PIN(6), GPIOCFG_OUT);
00394 halGpioSet(PORTB_PIN(6), 1);
00395
00396 halGpioConfig(PORTB_PIN(7), GPIOCFG_OUT);
00397 halGpioSet(PORTB_PIN(7), 0);
00398
00399 halGpioConfig(PORTC_PIN(5), GPIOCFG_OUT_ALT);
00400 }
00401
00402 }
00403
00404 #ifdef TEST_COMMANDS
00405 #include <stdio.h>
00406 void printLeds (LedResourceType *leds)
00407 {
00408 while (leds->name != NULL) {
00409 printf ("Led %s (port:%s, bit:%d)\r\n", leds->name, PORT_NAME(leds->gpioPort), leds->gpioPin);
00410 leds++;
00411 }
00412 }
00413
00414 void printButtons (ButtonResourceType *buttons)
00415 {
00416 while (buttons->name != NULL) {
00417 printf ("Button %s (port:%s, bit:%d)\r\n", buttons->name, PORT_NAME(buttons->gpioPort), buttons->gpioPin);
00418 buttons++;
00419 }
00420 }
00421
00422 void boardPrintStringDescription(void)
00423 {
00424 int8u i = 0;
00425
00426 while (boardList[i] != NULL) {
00427 if ((boardDescription == boardList[i]) || (boardDescription == NULL)) {
00428 BoardResourcesType *ptr = boardList[i];
00429 printf ("*************************************\r\n");
00430 printf ("Board name = %s\r\n", ptr->name);
00431 printf ("*************************************\r\n");
00432 printLeds(ptr->leds);
00433 printButtons(ptr->buttons);
00434 if (ptr->mems) {
00435 printf ("MEMS = %s\r\n", ptr->mems->name);
00436 }
00437 if (ptr->temperatureSensor) {
00438 printf ("Temp sensor = %s, port:%s, pin:%d, adcFix:%s\r\n",
00439 ptr->temperatureSensor->name,
00440 PORT_NAME(ptr->temperatureSensor->gpioPort),
00441 ptr->temperatureSensor->gpioPin,
00442 ptr->temperatureSensor->adcFix ? "Yes" : "No"
00443 );
00444 }
00445 printf ("EEProm:%s\r\n", ptr->EEProm ? "Yes" : "No");
00446 printf ("PC i/f:%s\r\n", ptr->FTDInotSTM32 ? "FTDI" : "STM32F");
00447 printf ("Power Amplifier:%s\r\n", ptr->PowerAmplifier ? "Yes" : "No");
00448 }
00449 i++;
00450 }
00451 return NULL;
00452 }
00453 #endif