![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
JGtoJR
Dependencies: MODSERIAL Watchdog
Revision 0:1c1c9f47b8ad, committed 2017-06-15
- Comitter:
- JavierGC
- Date:
- Thu Jun 15 12:01:36 2017 +0000
- Commit message:
- JG_to_JR
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GV/GV.h Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,8 @@ +#ifndef _GV_H +#define _GV_H + +struct GV { + float Variable1; +} ; + +#endif //_GV_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODSERIAL.lib Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/AjK/code/MODSERIAL/#ae0408ebdd68
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/PC.cpp Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,198 @@ +#include "PC.h" + +/***** Definitions *****/ + +//****************************************************************************** +PC::PC(GV *_pgv, PinName _led, PinName tx, PinName rx) : MODSERIAL( tx, rx, PCTxBufferSize, PCRxBufferSize, NULL ) +{ + pgv=_pgv; + iEvent=NULL; + led=NULL; + + MailNum=0; + LOG=false; + SendStatus=false; + mode=0; + + if(_led!=NC) led=new DigitalOut(_led); + baud(PCBaudRateDef); + format(8,SerialBase::None,1); + autoDetectChar('\r'); + this->attach(this,&PC::messageFrom, MODSERIAL::RxAutoDetect); +} + +void PC::start(void) +{ + thread.start(this,&PC::Paralell_thread); +} + +PC::PC(GV *_pgv, PinName _led, PinName tx, PinName rx, void (*iEventHandler)(int, char *)) : MODSERIAL( tx, rx, PCTxBufferSize, PCRxBufferSize, NULL ) +{ + pgv=_pgv; + iEvent=iEventHandler; + led=NULL; + + MailNum=0; + LOG=false; + SendStatus=false; + mode=0; + + if(_led!=NC) led=new DigitalOut(_led); + baud(PCBaudRateDef); + format(8,SerialBase::None,1); + autoDetectChar('\r'); + this->attach(this,&PC::messageFrom, MODSERIAL::RxAutoDetect); +} + +//****************************************************************************** +PC::~PC() +{ +} + +//****************************************************************************** + +void PC::messageFrom(MODSERIAL_IRQ_INFO *q) { + MODSERIAL *sys = q->serial; + int i=sys->move(messageBufferIncoming, PCTxBufferSize); + messageBufferIncoming[i]='\r'; + messageBufferIncoming[i+1]=0; + LoadMail(0,messageBufferIncoming); + + if(led!=NULL) + { + led->write(true); + wait_us(250); + led->write(false); + } + //sys->rxBufferFlush(); +} + +void PC::StatusToPC(void) +{ + if(SendStatus) + { + char tempMessPC[PCTxBufferSize]; + sprintf(tempMessPC,"%.1f\r",pgv->Variable1); + LoadMail(2,tempMessPC); + } +} + +void PC::Paralell_thread() +{ + while(true) + { + char mess[PCTxBufferSize]; + char Tstr[20]; + osEvent evt = mails.get(osWaitForever); + if (evt.status == osEventMail) + { + mail_t *mail = (mail_t*)evt.value.p; + switch (mail->command) + { + case 0: //request from PC + switch (mail->message[0]) + { + case '@': //command to PC + switch(mail->message[1]) + { + case 'L': + LOG=mail->message[2]=='1'; + break; + case 'S': + SendStatus=mail->message[2]=='1'; + if(SendStatus) TStatusToPC.attach(this,&PC::StatusToPC, Rate); + else TStatusToPC.detach(); + break; + case 'M': + char temp[20]; + temp[0]=mail->message[2]; + temp[1]=0; + mode=atoi(temp); + break; + case 'R'://Reboot + mbed_reset();//wd.Configure(2.0); + break; + case 'r'://Reboot + mbed_reset();//wd.Configure(2.0); + break; + case 'H': + time_t rawtime; + struct tm * timeinfo; + int year, month, day, hour, minute, second; + sscanf(&mail->message[2],"%02d%02d%02d%02d%02d%04d",&hour,&minute,&second,&day,&month,&year); + /* get current timeinfo and modify it to the user's choice */ + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + timeinfo->tm_year = year-1900; + timeinfo->tm_mon = month - 1; + timeinfo->tm_mday = day; + timeinfo->tm_hour = hour; + timeinfo->tm_min = minute; + timeinfo->tm_sec = second; + /* call mktime: timeinfo->tm_wday will be set */ + rawtime=mktime (timeinfo); + set_time(rawtime); + break; + default: + break; + } + break; + default: // + switch (mode) + { + default: + mode=0; + break; + } + break; + } + break; + case 1: //Send LOG to PC + TLogSTR(Tstr); + snprintf(mess,PCTxBufferSize,"LOG(%s):%s",Tstr ,mail->message); + Com_Write(mess); + break; + case 2: //Send to PC + Com_Write(mail->message); + break; + default: + break; + } + mails.free(mail); + MailNum--; + } + } +} + +void PC::TLogSTR(char *Tstr) +{ + time_t ctTime; + struct tm * timeinfo; + + ctTime = time(NULL); + timeinfo = localtime ( &ctTime ); + strftime (Tstr,PCTxBufferSize,"%H:%M:%S",timeinfo); +} + +void PC::LoadMail(char comm, char *mess) //para cargar mensajes de trabajo al proceso paralelo ComPC_thread_proc +{ + if(comm!=1 || LOG) + { + while(MailNum>=PCMaxMailElements) wait_us(PCWaitMess_us); + mail_t *pmail = mails.alloc(); + pmail->command = comm; + snprintf(pmail->message,PCTxBufferSize,"%s",mess); + mails.put(pmail); + MailNum++; + } + } + +int PC::Com_Write(char *mess) //sólo para usarse en ComPC_thread_proc +{ + int i=strlen(mess); + if(i>0) { + while((PCTxBufferSize-this->txBufferGetCount())<i) wait_us(PCWaitByte_us); + return this->printf(mess); + } + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/PC.h Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,71 @@ +#ifndef _PC_H_ +#define _PC_H_ + +#include "mbed.h" +#include "MODSERIAL.h" +#include "GV.h" + +#define PCTxBufferSize 250 +#define PCRxBufferSize 250 +#define PCMaxMailElements 10 +#define PCBaudRateDef 115200 +#define PCWaitByte_us (10000000/PCBaudRateDef) +#define PCWaitMess_us PCWaitByte_us*10 + +#define Rate 1 + +extern "C" void mbed_reset(); + +class PC : public MODSERIAL +{ + +public: + + + PC(GV * _pac, PinName _led, PinName tx, PinName rx); + PC(GV * _pac, PinName _led, PinName tx, PinName rx, void (*iEventHandler)(int, char *)); + ~PC(); + + void LoadMail(char comm, char *mess); //para cargar mensajes de trabajo al proceso paralelo ComPC_thread_proc + + void start(void); + + bool LOG; + bool SendStatus; + int mode; + + enum MyEventsLCD {eLOG}; + +private: + + GV *pgv; + + void (*iEvent)(int, char *); + + DigitalOut *led; + char messageBufferIncoming[PCRxBufferSize]; + char messageBufferOutgoing[PCTxBufferSize]; + + Thread thread; + + typedef struct { + char command; /* command to execute */ + char message[PCTxBufferSize]; /* arguments */ + } mail_t; + + Mail<mail_t, PCMaxMailElements> mails; + int MailNum; + + void TLogSTR(char *Tstr); + int Com_Write(char *mess); //sólo para usarse en ComPC_thread_proc + void messageFrom(MODSERIAL_IRQ_INFO *q); + void Paralell_thread(); + + Ticker TStatusToPC; + void StatusToPC(void); +}; + +#endif /* _PC_H_ */ + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,87 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Export the project to Keil MDK, and debug your application + +From the command-line, run the following command: + +``` +mbed export -m K64F -i uvision +``` + +To debug the application: + +1. Start uVision. +1. Import the uVision project generated earlier. +1. Compile your application, and generate an `.axf` file. +1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger). +1. Set breakpoints, and start a debug session. + +![Image of uVision](img/uvision.png) + +## Troubleshooting + +1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0` + + ``` + mbed --version + ``` + + If not, you can update it: + + ``` + pip install mbed-cli --upgrade + ``` + +2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size. \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Watchdog.lib Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/WiredHome/code/Watchdog/#e0f547e22dd5
Binary file img/uvision.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,99 @@ +#include "main.h" + +int main() +{ + pc.start(); + + if (wd.WatchdogCausedReset()) + pc.LoadMail(2,"Watchdog caused reset\r"); + + pc.LoadMail(2,"starting...\r"); + wait_ms(100); + + Setup(); + //set_time(0); + + while(true) { + wd.Service(); + wait_ms(10000); + } +} + + + +void GetConfig() +{ + #define CfgNumParam 3 + #define CfgSizeParam 50 + + /*ConfigFile cfg; + + int i; + char Value[CfgNumParam][CfgSizeParam]; + char CfgK[CfgNumParam][CfgSizeParam]= {"InitialMessage","LOGPC"}; +*/ + pc.LoadMail(2,"\r* * *\r* * *\r"); + wait_ms(100); + + /* if (!cfg.read("/local/config.cfg")) { + error("\rFailure to read a configuration file"); + } + + pc.LoadMail(2,"aqui\r"); + wait_ms(1000); + + char Tstr[10]; + for (i=0; i<CfgNumParam; i++) { + if (cfg.getValue(CfgK[i], &Value[i][0], sizeof(Value[i]))) { + //pc.TLogSTR(Tstr); + pc.printf("CFG_Param(%s): '%s'='%s'\r", Tstr,CfgK[i], Value[i]); + wait_ms(1000); + } else { + error("Failure Reading '%s'\r", CfgK[i]); + } + } + */ + strcpy(InitialMessage,"MBED Ready");//Value[0]); + pc.LOG=false;//(bool)atoi(Value[1]); + + pc.LoadMail(2,"* * *\r* * *\r"); +} + + +void Setup() +{ + GetConfig(); + + pc.LoadMail(2,"\r"); + pc.LoadMail(2,"\r"); + pc.LoadMail(2,"\r"); + pc.LoadMail(2,"************************************************"); + pc.LoadMail(2,InitialMessage); + pc.LoadMail(2,"************************************************"); + pc.LoadMail(2,"\r"); + pc.LoadMail(2,"\r"); + pc.LoadMail(2,"\r"); + + // ************ WD ************* + wd.WatchdogCausedReset(); + wd.Configure(20.0); + // ************ WD_end ********* + + DigitalOut(LED1,0); + DigitalOut(LED2,0); + DigitalOut(LED3,0); + DigitalOut(LED4,0); + } + + +void PCEventHandler(int e, char *data) +{ + switch(e) + { + case PC::eLOG: + pc.LoadMail(1,data); + break; + default: + break; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,29 @@ +#ifndef _main_H_ +#define _main_H_ + +#include "mbed.h" +#include "PC.h" +#include "GV.h" +#include "Watchdog.h" + +Watchdog wd; + +GV gv; + +void PCEventHandler(int e, char *data); +PC pc(&gv, NC, USBTX, USBRX, PCEventHandler); + +char InitialMessage[50]; + +void GetConfig(void); +void Setup(void); +void GetDate(void); + +//LocalFileSystem local("local"); + +#endif /* _main_H_ */ + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Jun 15 12:01:36 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#fc1836545dcc2fc86f03b01292b62bf2089f67c3