Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Jan 10, 2018
2 parents dd610df + 328a9df commit d300fb0
Show file tree
Hide file tree
Showing 15 changed files with 432 additions and 29 deletions.
34 changes: 34 additions & 0 deletions demo/i2c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## ----------------------------------------------------------- ##
## Don't touch the next line unless you know what you're doing.##
## ----------------------------------------------------------- ##

# Name of the module
LOCAL_NAME := demo/i2c

# List of submodules which contain code we need to include in the final lib
LOCAL_API_DEPENDS := \

LOCAL_ADD_INCLUDE := include\
include/std_inc \
include/api_inc \


# Set this to any non-null string to signal a module which
# generates a binary (must contain a "main" entry point).
# If left null, only a library will be generated.
IS_ENTRY_POINT := no

## ------------------------------------ ##
## Add your custom flags here ##
## ------------------------------------ ##
MYCFLAGS +=

## ------------------------------------- ##
## List all your sources here ##
## ------------------------------------- ##
C_SRC := ${notdir ${wildcard src/*.c}}

## ------------------------------------- ##
## Do Not touch below this line ##
## ------------------------------------- ##
include ${SOFT_WORKDIR}/platform/compilation/cust_rules.mk
89 changes: 89 additions & 0 deletions demo/i2c/src/demo_i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

#include "stdbool.h"
#include "stdint.h"
#include "stdio.h"
#include "string.h"

#include "api_os.h"
#include "api_debug.h"
#include "api_event.h"
#include "api_hal_i2c.h"




#define MAIN_TASK_STACK_SIZE (2048 * 2)
#define MAIN_TASK_PRIORITY 0
#define MAIN_TASK_NAME "Main Test Task"

#define SECOND_TASK_STACK_SIZE (2048 * 2)
#define SECOND_TASK_PRIORITY 1
#define SECOND_TASK_NAME "Second Test Task"

static HANDLE mainTaskHandle = NULL;
static HANDLE secondTaskHandle = NULL;
#define I2C_ACC I2C2


void EventDispatch(API_Event_t* pEvent)
{
switch(pEvent->id)
{
case API_EVENT_ID_NO_SIMCARD:
Trace(10,"!!NO SIM CARD%d!!!!",pEvent->param1);
break;

case API_EVENT_ID_SYSTEM_READY:
Trace(1,"system initialize complete");
break;

case API_EVENT_ID_NETWORK_REGISTERED_HOME:
case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
Trace(2,"network register success");
break;

default:
break;
}
}
void SecondTask(void *pData)
{
uint8_t accId;
I2C_Config_t config;

config.freq = I2C_FREQ_100K;
I2C_Init(I2C_ACC, config);

while(1)
{
I2C_ReadByte(I2C_ACC, 0x19, 0x0f, &accId);
Trace(1,"accelerator id shold be 0x33, read:0X%02x",accId);
OS_Sleep(3000);
}
}

void MainTask(void *pData)
{
API_Event_t* event=NULL;

secondTaskHandle = OS_CreateTask(SecondTask,
NULL, NULL, SECOND_TASK_STACK_SIZE, SECOND_TASK_PRIORITY, 0, 0, SECOND_TASK_NAME);

while(1)
{
if(OS_WaitEvent(mainTaskHandle, (void**)&event, OS_TIME_OUT_WAIT_FOREVER))
{
EventDispatch(event);
OS_Free(event->pParam1);
OS_Free(event->pParam2);
OS_Free(event);
}
}
}

void i2c_Main(void)
{
mainTaskHandle = OS_CreateTask(MainTask,
NULL, NULL, MAIN_TASK_STACK_SIZE, MAIN_TASK_PRIORITY, 0, 0, MAIN_TASK_NAME);
OS_SetUserMainHandle(&mainTaskHandle);
}
83 changes: 69 additions & 14 deletions demo/sms/src/demo_sms.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////configuration//////////////////////////////////////////////////
#define TEST_PHONE_NUMBER "150****0062"
#define TEST_PHONE_NUMBER "13415840120"
const uint8_t unicodeMsg[] = {0x00, 0x61, 0x00, 0x61, 0x00, 0x61, 0x6d, 0x4b, 0x8b, 0xd5, 0x77, 0xed, 0x4f, 0xe1}; //unicode:aaa测试短信
const uint8_t gbkMsg[] = {0x62, 0x62, 0x62, 0xB0, 0xA1, 0xB0, 0xA1, 0xB0, 0xA1, 0xB0, 0xA1, 0x63, 0x63, 0x63 };//GBK :bbb啊啊啊啊ccc
const uint8_t utf8Msg[] = "utf-8测试短信";//Cause the encoding format of this file(sms.c) is UTF-8
Expand Down Expand Up @@ -47,6 +47,11 @@ void SMSInit()
Trace(1,"sms set parameter error");
return;
}
if(!SMS_SetNewMessageStorage(SMS_STORAGE_SIM_CARD))
{
Trace(1,"sms set message storage fail");
return;
}
}

void UartInit()
Expand Down Expand Up @@ -124,6 +129,29 @@ void SendSMS()
SendUtf8();
}

void ServerCenterTest()
{
uint8_t addr[32];
uint8_t temp;
SMS_Server_Center_Info_t sca;
sca.addr = addr;
SMS_GetServerCenterInfo(&sca);
Trace(1,"server center address:%s,type:%d",sca.addr,sca.addrType);
temp = sca.addr[strlen(sca.addr)-1];
sca.addr[strlen(sca.addr)-1] = '0';
if(!SMS_SetServerCenterInfo(&sca))
Trace(1,"SMS_SetServerCenterInfo fail");
else
Trace(1,"SMS_SetServerCenterInfo success");
SMS_GetServerCenterInfo(&sca);
Trace(1,"server center address:%s,type:%d",sca.addr,sca.addrType);
sca.addr[strlen(sca.addr)-1] = temp;
if(!SMS_SetServerCenterInfo(&sca))
Trace(1,"SMS_SetServerCenterInfo fail");
else
Trace(1,"SMS_SetServerCenterInfo success");
}

void EventDispatch(API_Event_t* pEvent)
{
switch(pEvent->id)
Expand All @@ -137,24 +165,24 @@ void EventDispatch(API_Event_t* pEvent)
break;
case API_EVENT_ID_NETWORK_REGISTERED_HOME:
case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
Trace(1,"network register success");
Trace(2,"network register success");
flag |= 2;
break;
case API_EVENT_ID_SMS_SENT:
Trace(1,"Send Message Success");
Trace(2,"Send Message Success");
break;
case API_EVENT_ID_SMS_RECEIVED:
Trace(1,"received message");
Trace(2,"received message");
SMS_Encode_Type_t encodeType = pEvent->param1;
uint32_t contentLength = pEvent->param2;
uint8_t* header = pEvent->pParam1;
uint8_t* content = pEvent->pParam2;

Trace(1,"message header:%s",header);
Trace(1,"message content length:%d",contentLength);
Trace(2,"message header:%s",header);
Trace(2,"message content length:%d",contentLength);
if(encodeType == SMS_ENCODE_TYPE_ASCII)
{
Trace(1,"message content:%s",content);
Trace(2,"message content:%s",content);
UART_Write(UART1,content,contentLength);
}
else
Expand All @@ -163,7 +191,7 @@ void EventDispatch(API_Event_t* pEvent)
memset(tmp,0,500);
for(int i=0;i<contentLength;i+=2)
sprintf(tmp+strlen(tmp),"\\u%02x%02x",content[i],content[i+1]);
Trace(1,"message content(unicode):%s",tmp);//you can copy this string to http://tool.chinaz.com/tools/unicode.aspx and display as Chinese
Trace(2,"message content(unicode):%s",tmp);//you can copy this string to http://tool.chinaz.com/tools/unicode.aspx and display as Chinese
uint8_t* gbk = NULL;
uint32_t gbkLen = 0;
if(!SMS_Unicode2LocalLanguage(content,contentLength,CHARSET_CP936,&gbk,&gbkLen))
Expand All @@ -173,12 +201,27 @@ void EventDispatch(API_Event_t* pEvent)
memset(tmp,0,500);
for(int i=0;i<gbkLen;i+=2)
sprintf(tmp+strlen(tmp),"%02x%02x ",gbk[i],gbk[i+1]);
Trace(1,"message content(GBK):%s",tmp);//you can copy this string to http://m.3158bbs.com/tool-54.html# and display as Chinese
UART_Write(UART1,gbk,gbkLen);
Trace(2,"message content(GBK):%s",tmp);//you can copy this string to http://m.3158bbs.com/tool-54.html# and display as Chinese
UART_Write(UART1,gbk,gbkLen);//use serial tool that support GBK decode if have Chinese, eg: https://github.com/Neutree/COMTool
}
OS_Free(gbk);
}
break;
case API_EVENT_ID_SMS_LIST_MESSAGE:
{
SMS_Message_Info_t* messageInfo = (SMS_Message_Info_t*)pEvent->pParam1;
Trace(1,"message header index:%d,status:%d,number type:%d,number:%s,time:\"%u/%02u/%02u,%02u:%02u:%02u+%02d\"", messageInfo->index, messageInfo->status,
messageInfo->phoneNumberType, messageInfo->phoneNumber,
messageInfo->time.year, messageInfo->time.month, messageInfo->time.day,
messageInfo->time.hour, messageInfo->time.minute, messageInfo->time.second,
messageInfo->time.timeZone);
Trace(1,"message content len:%d,data:%s",messageInfo->dataLen,messageInfo->data);
UART_Write(UART1, messageInfo->data, messageInfo->dataLen);//use serial tool that support GBK decode if have Chinese, eg: https://github.com/Neutree/COMTool
UART_Write(UART1,"\r\n\r\n",4);
//need to free data here
OS_Free(messageInfo->data);
break;
}
case API_EVENT_ID_SMS_ERROR:
Trace(10,"SMS error occured! cause:%d",pEvent->param1);
default:
Expand All @@ -188,17 +231,28 @@ void EventDispatch(API_Event_t* pEvent)
//system initialize complete and network register complete, now can send message
if(flag == 3)
{
SendSMS();
SMS_Storage_Info_t storageInfo;
// SendSMS();
ServerCenterTest();
SMS_GetStorageInfo(&storageInfo,SMS_STORAGE_SIM_CARD);
Trace(1,"sms storage sim card info, used:%d,total:%d",storageInfo.used,storageInfo.total);
SMS_GetStorageInfo(&storageInfo,SMS_STORAGE_FLASH);
Trace(1,"sms storage flash info, used:%d,total:%d",storageInfo.used,storageInfo.total);
if(!SMS_DeleteMessage(5,SMS_STATUS_ALL,SMS_STORAGE_SIM_CARD))
Trace(1,"delete sms fail");
else
Trace(1,"delete sms success");
SMS_ListMessageRequst(SMS_STATUS_ALL,SMS_STORAGE_SIM_CARD);
flag = 0;
}
}



void sms_MainTask(void* pData)
void SMSTest(void* pData)
{
API_Event_t* event=NULL;
flag = 0;

Init();

while(1)
Expand All @@ -212,9 +266,10 @@ void sms_MainTask(void* pData)
}
}
}

void sms_Main()
{
mainTaskHandle = OS_CreateTask(sms_MainTask,
mainTaskHandle = OS_CreateTask(SMSTest,
NULL, NULL, MAIN_TASK_STACK_SIZE, MAIN_TASK_PRIORITY, 0, 0, MAIN_TASK_NAME);
OS_SetUserMainHandle(&mainTaskHandle);
}
Expand Down
5 changes: 3 additions & 2 deletions demo/socket/src/demo_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void EventDispatch(API_Event_t* pEvent)
break;
}
case API_EVENT_ID_DNS_SUCCESS:
Trace(2,"DNS get ip address from domain success(event),domain:%s,ip:%s",pEvent->param2,pEvent->param1);
Trace(2,"DNS get ip address from domain success(event),domain:%s,ip:%s",pEvent->pParam1,pEvent->pParam2);
break;

case API_EVENT_ID_DNS_ERROR:
Expand Down Expand Up @@ -149,10 +149,11 @@ void socket_MainTask(void *pData)

while(1)
{
if(OS_WaitEvent(socketTaskHandle, &event, OS_TIME_OUT_WAIT_FOREVER))
if(OS_WaitEvent(socketTaskHandle, (void**)&event, OS_TIME_OUT_WAIT_FOREVER))
{
EventDispatch(event);
OS_Free(event->pParam1);
OS_Free(event->pParam2);
OS_Free(event);
}
}
Expand Down
85 changes: 85 additions & 0 deletions include/api_hal_i2c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef __API_HAL_I2C_H__
#define __API_HAL_I2C_H__

#include <sdk_init.h>


/// \brief bool I2C_Init(I2C_ID_t i2c, I2C_Config_t config);
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus
/// \param I2C_Bps_t Bpsx, the speed of I2C
/// \return BOOL
/// TRUE: init success
/// FALSE: init failed
/// \note when I2C1 is used, the i2c1 pin must be pulled up
#define I2C_Init CSDK_FUNC(I2C_Init)


/// \brief I2C_Error_t I2C_ReadByte(I2C_ID_t i2c, uint32_t slaveAddr, uint32_t memAddr, uint8_t* data);
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus
/// \param uint32_t slaveAddr, Address of the slave from which we read a byte
/// \param uint32_t memAddr, memAddr Address in the memory map where to get the byte.
/// \param uint8_t* pData, pData pointer to save one byte data
/// \return I2C_Error_t
#define I2C_ReadByte CSDK_FUNC(I2C_ReadByte)


/// \brief I2C_Error_t I2C_WriteByte(I2C_ID_t i2c, uint32_t slaveAddr, uint32_t memAddr, uint8_t data);
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus
/// \param uint32_t slaveAdd, Address of the slave to which we write a byte
/// \param uint8_t* pData, one byte data that you want to write
/// \return I2C_Error_t
#define I2C_WriteByte CSDK_FUNC(I2C_WriteByte)


/// \brief I2C_Error_t I2C_ReadBytes(I2C_ID_t i2c, uint32_t slaveAddr, uint32_t memAddr, uint8_t* pData, uint32_t length);
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus
/// \param uint32_t slaveAddr, Address of the slave from which we read data
/// \param uint32_t memAddr, memAddr Address in the memory map where to get data.
/// \param uint8_t* pData, buffer pointer to read the data
/// \param uint32_t length, length of the data that you want to read
/// \return I2C_Error_t
#define I2C_ReadBytes CSDK_FUNC(I2C_ReadBytes)


/// \brief I2C_Error_t I2C_WriteBytes(I2C_ID_t i2c, uint32_t slaveAddr, uint32_t memAddr, CONST uint8_t* pData, uint32_t length);
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus
/// \param uint32_t slaveAdd, Address of the slave to which we write a byte
/// \param uint8_t* pData, the pointer of buffer that you want to write
/// \param uint32_t length, length of the data that you want to write
/// \return I2C_Error_t
#define I2C_WriteBytes CSDK_FUNC(I2C_WriteBytes)


/// \brief I2C_Error_t I2C_ReadRawByte(I2C_ID_t i2c, uint32_t CmdMask);
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus
/// \param uint32_t CmdMask, can be I2C_MASTER_ACK|I2C_MASTER_RD|I2C_MASTER_STO|I2C_MASTER_WR|I2C_MASTER_STA
/// \return I2C_Error_t
/// \note This function completes the 2 phase read cycle as defined in the SCCB
/// spec. The actual commands for the I2C module must be: Stop, Read, and
/// NACK. (The SCCB requires a NACK at the end of the read byte)
#define I2C_ReadRawByte CSDK_FUNC(I2C_ReadRawByte)


/// \brief I2C_Error_t I2C_WriteRawByte(I2C_ID_t i2c, uint8_t SendByte, uint32_t CmdMask);
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus
/// \param uint8_t SendByte, one byte what you want to send
/// \param uint32_t CmdMask, this is the command associated with this byte. It must
/// be sent at the same time so the two actions (write to the data fifo and
/// issue the command) are done together, can be I2C_MASTER_ACK|I2C_MASTER_RD|
/// I2C_MASTER_STO|I2C_MASTER_WR|I2C_MASTER_STA
/// \return I2C_Error_t
/// \note This function sends a single byte on the I2C interface
/// It is not designed for use in the real I2C protocol, but allows access
/// for non-standard usages such as SCCB for the Omnivision Camera control
#define I2C_WriteRawByte CSDK_FUNC(I2C_WriteRawByte)


/// \brief bool I2C_Close(I2C_ID_t i2c);
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus
/// \return BOOL
/// TRUE: close success
/// FALSE: close failed
#define I2C_Close CSDK_FUNC(I2C_Close)


#endif
Loading

0 comments on commit d300fb0

Please sign in to comment.